diff --git a/config/config_loader.go b/config/config_loader.go index 34763846060e1685687611432cb1a67cbd7b4834..f8d340e702adeb20205156159d37e36efd6e81a5 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -239,12 +239,12 @@ func GetApplicationConfig() *ApplicationConfig { // GetProviderConfig find the provider config // if not found, create new one -func GetProviderConfig() ProviderConfig { +func GetProviderConfig() *ProviderConfig { if providerConfig == nil { logger.Warnf("providerConfig is nil!") - return ProviderConfig{} + return &ProviderConfig{} } - return *providerConfig + return providerConfig } // GetConsumerConfig find the consumer config diff --git a/config/config_loader_test.go b/config/config_loader_test.go index c4cb3efe4b04dcfc7dad997d9535bd6d50289bd5..652701537313e67e4448962e2ca79ead791dd053 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -18,6 +18,7 @@ package config import ( + "go.uber.org/atomic" "path/filepath" "testing" ) @@ -90,7 +91,7 @@ func TestLoad(t *testing.T) { func TestLoadWithSingleReg(t *testing.T) { doInitConsumerWithSingleRegistry() - MockInitProviderWithSingleRegistry() + mockInitProviderWithSingleRegistry() ms := &MockService{} SetConsumerService(ms) @@ -233,3 +234,55 @@ func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) { assert.Equal(t, "mock://127.0.0.1:2182", consumerConfig.Registries[constant.DEFAULT_KEY].Address) } + +// mockInitProviderWithSingleRegistry will init a mocked providerConfig +func mockInitProviderWithSingleRegistry() { + providerConfig = &ProviderConfig{ + ApplicationConfig: &ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registry: &RegistryConfig{ + Address: "mock://127.0.0.1:2181", + Username: "user1", + Password: "pwd1", + }, + Registries: map[string]*RegistryConfig{}, + Services: map[string]*ServiceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: "3", + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + Name: "GetUser", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + { + Name: "GetUser1", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + }, + exported: new(atomic.Bool), + }, + }, + Protocols: map[string]*ProtocolConfig{ + "mock": { + Name: "mock", + Ip: "127.0.0.1", + Port: "20000", + }, + }, + } +} diff --git a/config/service_config.go b/config/service_config.go index 53e6526da4ca5c24c56deecd0489885e7bea3516..8a548dfe0fb5c38bff562a2cc1640b301f5c1c1f 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -109,6 +109,11 @@ func NewServiceConfig(id string, context context.Context) *ServiceConfig { } } +// InitExported will set exported as false atom bool +func (c *ServiceConfig) InitExported() { + c.exported = atomic.NewBool(false) +} + // IsExport will return whether the service config is exported or not func (c *ServiceConfig) IsExport() bool { return c.exported.Load() @@ -288,55 +293,3 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL { } return nil } - -// MockInitProviderWithSingleRegistry will init a mocked providerConfig -func MockInitProviderWithSingleRegistry() { - providerConfig = &ProviderConfig{ - ApplicationConfig: &ApplicationConfig{ - Organization: "dubbo_org", - Name: "dubbo", - Module: "module", - Version: "2.6.0", - Owner: "dubbo", - Environment: "test"}, - Registry: &RegistryConfig{ - Address: "mock://127.0.0.1:2181", - Username: "user1", - Password: "pwd1", - }, - Registries: map[string]*RegistryConfig{}, - Services: map[string]*ServiceConfig{ - "MockService": { - InterfaceName: "com.MockService", - Protocol: "mock", - Cluster: "failover", - Loadbalance: "random", - Retries: "3", - Group: "huadong_idc", - Version: "1.0.0", - Methods: []*MethodConfig{ - { - Name: "GetUser", - Retries: "2", - Loadbalance: "random", - Weight: 200, - }, - { - Name: "GetUser1", - Retries: "2", - Loadbalance: "random", - Weight: 200, - }, - }, - exported: new(atomic.Bool), - }, - }, - Protocols: map[string]*ProtocolConfig{ - "mock": { - Name: "mock", - Ip: "127.0.0.1", - Port: "20000", - }, - }, - } -} diff --git a/metadata/service/exporter/configurable/exporter_test.go b/metadata/service/exporter/configurable/exporter_test.go index 0975f07213c7094d8ee6ce5b5f76bffaf3c89908..89e326a822e950c5ba381a695acb108d4a4fc31d 100644 --- a/metadata/service/exporter/configurable/exporter_test.go +++ b/metadata/service/exporter/configurable/exporter_test.go @@ -52,7 +52,7 @@ func TestConfigurableExporter(t *testing.T) { MaxMsgLen: 10240000000, SessionName: "server", }}) - config.MockInitProviderWithSingleRegistry() + mockInitProviderWithSingleRegistry() metadataService := inmemory.NewMetadataService() exported := NewMetadataServiceExporter(metadataService) assert.Equal(t, false, exported.IsExported()) @@ -62,3 +62,57 @@ func TestConfigurableExporter(t *testing.T) { exported.Unexport() assert.Equal(t, false, exported.IsExported()) } + +// mockInitProviderWithSingleRegistry will init a mocked providerConfig +func mockInitProviderWithSingleRegistry() { + providerConfig := &config.ProviderConfig{ + ApplicationConfig: &config.ApplicationConfig{ + Organization: "dubbo_org", + Name: "dubbo", + Module: "module", + Version: "2.6.0", + Owner: "dubbo", + Environment: "test"}, + Registry: &config.RegistryConfig{ + Address: "mock://127.0.0.1:2181", + Username: "user1", + Password: "pwd1", + }, + Registries: map[string]*config.RegistryConfig{}, + Services: map[string]*config.ServiceConfig{ + "MockService": { + InterfaceName: "com.MockService", + Protocol: "mock", + Cluster: "failover", + Loadbalance: "random", + Retries: "3", + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*config.MethodConfig{ + { + Name: "GetUser", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + { + Name: "GetUser1", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + }, + }, + }, + Protocols: map[string]*config.ProtocolConfig{ + "mock": { + Name: "mock", + Ip: "127.0.0.1", + Port: "20000", + }, + }, + } + providerConfig.Services["MockService"].InitExported() + config.SetProviderConfig(*providerConfig) + +} diff --git a/metadata/service/service.go b/metadata/service/service.go index e3c6f21c58a77beca76e47105a86935ffa84e05e..276e3945b829439c04526102209cad8d003e0566 100644 --- a/metadata/service/service.go +++ b/metadata/service/service.go @@ -28,18 +28,27 @@ import ( // Metadataservice is used to define meta data related behaviors type MetadataService interface { + // ServiceName will get the service's name in meta service , which is application name ServiceName() (string, error) + // ExportURL will store the exported url in metadata ExportURL(url common.URL) (bool, error) + // UnexportURL will delete the exported url in metadata UnexportURL(url common.URL) error - //RefreshMetadata(exportedRevision string, subscribedRevision string) bool + // SubscribeURL will store the subscribed url in metadata SubscribeURL(url common.URL) (bool, error) + // UnsubscribeURL will delete the subscribed url in metadata UnsubscribeURL(url common.URL) error + // PublishServiceDefinition will generate the target url's code info PublishServiceDefinition(url common.URL) error - + // GetExportedURLs will get the target exported url in metadata GetExportedURLs(serviceInterface string, group string, version string, protocol string) (sets.Set, error) + // GetExportedURLs will get the target subscribed url in metadata GetSubscribedURLs() (sets.Set, error) + // GetServiceDefinition will get the target service info store in metadata GetServiceDefinition(interfaceName string, group string, version string) (string, error) + // GetServiceDefinition will get the target service info store in metadata by service key GetServiceDefinitionByServiceKey(serviceKey string) (string, error) + // Version will return the metadata service version Version() string common.RPCService }