diff --git a/common/proxy/proxy_factory/default.go b/common/proxy/proxy_factory/default.go index 067c077294..ff3d7955a0 100644 --- a/common/proxy/proxy_factory/default.go +++ b/common/proxy/proxy_factory/default.go @@ -97,7 +97,7 @@ func (pi *ProxyInvoker) Invoke(ctx context.Context, invocation protocol.Invocati args := invocation.Arguments() // get service - svc := common.ServiceMap.GetService(proto, path) + svc := common.ServiceMap.GetServiceByServiceKey(proto, url.ServiceKey()) if svc == nil { logger.Errorf("cannot find service [%s] in %s", path, proto) result.SetError(perrors.Errorf("cannot find service [%s] in %s", path, proto)) diff --git a/common/rpc_service.go b/common/rpc_service.go index 5ed4df6d71..572fc71701 100644 --- a/common/rpc_service.go +++ b/common/rpc_service.go @@ -157,11 +157,17 @@ type serviceMap struct { } // GetService gets a service defination by protocol and name -func (sm *serviceMap) GetService(protocol, name string) *Service { +func (sm *serviceMap) GetService(protocol, interfaceName, group, version string) *Service { + serviceKey := ServiceKey(interfaceName, group, version) + return sm.GetServiceByServiceKey(protocol, serviceKey) +} + +// GetService gets a service defination by protocol and service key +func (sm *serviceMap) GetServiceByServiceKey(protocol, serviceKey string) *Service { sm.mutex.RLock() defer sm.mutex.RUnlock() if s, ok := sm.serviceMap[protocol]; ok { - if srv, ok := s[name]; ok { + if srv, ok := s[serviceKey]; ok { return srv } return nil @@ -180,7 +186,7 @@ func (sm *serviceMap) GetInterface(interfaceName string) []*Service { } // Register registers a service by @interfaceName and @protocol -func (sm *serviceMap) Register(interfaceName, protocol string, rcvr RPCService) (string, error) { +func (sm *serviceMap) Register(interfaceName, protocol, group, version string, rcvr RPCService) (string, error) { if sm.serviceMap[protocol] == nil { sm.serviceMap[protocol] = make(map[string]*Service) } @@ -203,8 +209,8 @@ func (sm *serviceMap) Register(interfaceName, protocol string, rcvr RPCService) return "", perrors.New(s) } - sname = rcvr.Reference() - if server := sm.GetService(protocol, sname); server != nil { + sname = ServiceKey(interfaceName, group, version) + if server := sm.GetService(protocol, interfaceName, group, version); server != nil { return "", perrors.New("service already defined: " + sname) } s.name = sname @@ -228,9 +234,9 @@ func (sm *serviceMap) Register(interfaceName, protocol string, rcvr RPCService) } // UnRegister cancels a service by @interfaceName, @protocol and @serviceId -func (sm *serviceMap) UnRegister(interfaceName, protocol, serviceId string) error { - if protocol == "" || serviceId == "" { - return perrors.New("protocol or serviceName is nil") +func (sm *serviceMap) UnRegister(interfaceName, protocol, serviceKey string) error { + if protocol == "" || serviceKey == "" { + return perrors.New("protocol or serviceKey is nil") } var ( @@ -248,9 +254,9 @@ func (sm *serviceMap) UnRegister(interfaceName, protocol, serviceId string) erro if !ok { return perrors.New("no services for " + protocol) } - s, ok := svcs[serviceId] + s, ok := svcs[serviceKey] if !ok { - return perrors.New("no service for " + serviceId) + return perrors.New("no service for " + serviceKey) } svrs, ok = sm.interfaceMap[interfaceName] if !ok { @@ -276,7 +282,7 @@ func (sm *serviceMap) UnRegister(interfaceName, protocol, serviceId string) erro sm.interfaceMap[interfaceName] = append(sm.interfaceMap[interfaceName], svrs[i]) } } - delete(svcs, serviceId) + delete(svcs, serviceKey) if len(sm.serviceMap[protocol]) == 0 { delete(sm.serviceMap, protocol) } diff --git a/common/rpc_service_test.go b/common/rpc_service_test.go index 7c4eb421d7..b50d8d962c 100644 --- a/common/rpc_service_test.go +++ b/common/rpc_service_test.go @@ -85,23 +85,23 @@ func TestServiceMapRegister(t *testing.T) { // lowercase s0 := &testService{} // methods, err := ServiceMap.Register("testporotocol", s0) - _, err := ServiceMap.Register(testInterfaceName, "testporotocol", s0) + _, err := ServiceMap.Register(testInterfaceName, "testporotocol", "", "v0", s0) assert.EqualError(t, err, "type testService is not exported") // succ s := &TestService{} - methods, err := ServiceMap.Register(testInterfaceName, "testporotocol", s) + methods, err := ServiceMap.Register(testInterfaceName, "testporotocol", "", "v1", s) assert.NoError(t, err) assert.Equal(t, "MethodOne,MethodThree,methodTwo", methods) // repeat - _, err = ServiceMap.Register(testInterfaceName, "testporotocol", s) - assert.EqualError(t, err, "service already defined: com.test.Path") + _, err = ServiceMap.Register(testInterfaceName, "testporotocol", "", "v1", s) + assert.EqualError(t, err, "service already defined: testService:v1") // no method s1 := &TestService1{} - _, err = ServiceMap.Register(testInterfaceName, "testporotocol", s1) - assert.EqualError(t, err, "type com.test.Path1 has no exported methods of suitable type") + _, err = ServiceMap.Register(testInterfaceName, "testporotocol", "", "v2", s1) + assert.EqualError(t, err, "type testService:v2 has no exported methods of suitable type") ServiceMap = &serviceMap{ serviceMap: make(map[string]map[string]*Service), @@ -111,22 +111,22 @@ func TestServiceMapRegister(t *testing.T) { func TestServiceMapUnRegister(t *testing.T) { s := &TestService{} - _, err := ServiceMap.Register("TestService", testProtocol, s) + _, err := ServiceMap.Register("TestService", testProtocol, "", "v1", s) assert.NoError(t, err) - assert.NotNil(t, ServiceMap.GetService(testProtocol, referenceTestPath)) + assert.NotNil(t, ServiceMap.GetService(testProtocol, "TestService", "", "v1")) assert.Equal(t, 1, len(ServiceMap.GetInterface("TestService"))) - err = ServiceMap.UnRegister("", "", referenceTestPath) - assert.EqualError(t, err, "protocol or serviceName is nil") + err = ServiceMap.UnRegister("", "", ServiceKey("TestService", "", "v1")) + assert.EqualError(t, err, "protocol or serviceKey is nil") - err = ServiceMap.UnRegister("", "protocol", referenceTestPath) + err = ServiceMap.UnRegister("", "protocol", ServiceKey("TestService", "", "v1")) assert.EqualError(t, err, "no services for protocol") - err = ServiceMap.UnRegister("", testProtocol, referenceTestPathDistinct) - assert.EqualError(t, err, "no service for com.test.Path1") + err = ServiceMap.UnRegister("", testProtocol, ServiceKey("TestService", "", "v0")) + assert.EqualError(t, err, "no service for TestService:v0") // succ - err = ServiceMap.UnRegister("TestService", testProtocol, referenceTestPath) + err = ServiceMap.UnRegister("TestService", testProtocol, ServiceKey("TestService", "", "v1")) assert.NoError(t, err) } diff --git a/common/url.go b/common/url.go index d8f096bb48..81f076043e 100644 --- a/common/url.go +++ b/common/url.go @@ -109,7 +109,7 @@ type URL struct { noCopy noCopy baseUrl - Path string // like /com.ikurento.dubbo.UserProvider3 + Path string // like /com.ikurento.dubbo.UserProvider Username string Password string Methods []string @@ -317,6 +317,8 @@ func isMatchCategory(category1 string, category2 string) bool { } func (c *URL) String() string { + c.paramsLock.Lock() + defer c.paramsLock.Unlock() var buf strings.Builder if len(c.Username) == 0 && len(c.Password) == 0 { buf.WriteString(fmt.Sprintf("%s://%s:%s%s?", c.Protocol, c.Ip, c.Port, c.Path)) diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 9b253030ff..c3c3eb9352 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -104,7 +104,7 @@ func TestLoad(t *testing.T) { conServices = map[string]common.RPCService{} proServices = map[string]common.RPCService{} - err := common.ServiceMap.UnRegister("com.MockService", "mock", "MockService") + err := common.ServiceMap.UnRegister("com.MockService", "mock", common.ServiceKey("com.MockService", "huadong_idc", "1.0.0")) assert.Nil(t, err) consumerConfig = nil providerConfig = nil @@ -143,7 +143,7 @@ func TestLoadWithSingleReg(t *testing.T) { conServices = map[string]common.RPCService{} proServices = map[string]common.RPCService{} - common.ServiceMap.UnRegister("com.MockService", "mock", "MockService") + common.ServiceMap.UnRegister("com.MockService", "mock", common.ServiceKey("com.MockService", "huadong_idc", "1.0.0")) consumerConfig = nil providerConfig = nil } @@ -182,7 +182,7 @@ func TestWithNoRegLoad(t *testing.T) { conServices = map[string]common.RPCService{} proServices = map[string]common.RPCService{} - common.ServiceMap.UnRegister("com.MockService", "mock", "MockService") + common.ServiceMap.UnRegister("com.MockService", "mock", common.ServiceKey("com.MockService", "huadong_idc", "1.0.0")) consumerConfig = nil providerConfig = nil } diff --git a/config/reference_config.go b/config/reference_config.go index 2e914ac9a7..e616a3595b 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -96,7 +96,7 @@ func (c *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error // Refer ... func (c *ReferenceConfig) Refer(_ interface{}) { cfgURL := common.NewURLWithOptions( - common.WithPath(c.id), + common.WithPath(c.InterfaceName), common.WithProtocol(c.Protocol), common.WithParams(c.getUrlMap()), common.WithParamsValue(constant.BEAN_NAME_KEY, c.id), @@ -117,7 +117,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) { c.urls = append(c.urls, serviceUrl) } else { if serviceUrl.Path == "" { - serviceUrl.Path = "/" + c.id + serviceUrl.Path = "/" + c.InterfaceName } // merge url need to do newUrl := common.MergeUrl(serviceUrl, cfgURL) diff --git a/config/service_config.go b/config/service_config.go index b3febc68d6..32104f03dd 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -171,7 +171,7 @@ func (c *ServiceConfig) Export() error { proxyFactory := extension.GetProxyFactory(providerConfig.ProxyFactory) for _, proto := range protocolConfigs { // registry the service reflect - methods, err := common.ServiceMap.Register(c.InterfaceName, proto.Name, c.rpcService) + methods, err := common.ServiceMap.Register(c.InterfaceName, proto.Name, c.Group, c.Version, c.rpcService) if err != nil { formatErr := perrors.Errorf("The service %v export the protocol %v error! Error message is %v.", c.InterfaceName, proto.Name, err.Error()) logger.Errorf(formatErr.Error()) @@ -184,7 +184,7 @@ func (c *ServiceConfig) Export() error { nextPort = nextPort.Next() } ivkURL := common.NewURLWithOptions( - common.WithPath(c.id), + common.WithPath(c.InterfaceName), common.WithProtocol(proto.Name), common.WithIp(proto.Ip), common.WithPort(port), diff --git a/filter/filter_impl/access_log_filter.go b/filter/filter_impl/access_log_filter.go index 6eaf9cb00b..167b5edd80 100644 --- a/filter/filter_impl/access_log_filter.go +++ b/filter/filter_impl/access_log_filter.go @@ -105,8 +105,12 @@ func (ef *AccessLogFilter) logIntoChannel(accessLogData AccessLogData) { func (ef *AccessLogFilter) buildAccessLogData(_ protocol.Invoker, invocation protocol.Invocation) map[string]string { dataMap := make(map[string]string, 16) attachments := invocation.Attachments() - if v, ok := attachments[constant.INTERFACE_KEY]; ok && v != nil { - dataMap[constant.INTERFACE_KEY] = v.(string) + itf := attachments[constant.INTERFACE_KEY] + if itf == nil || len(itf.(string)) == 0 { + itf = attachments[constant.PATH_KEY] + } + if itf != nil { + dataMap[constant.INTERFACE_KEY] = itf.(string) } if v, ok := attachments[constant.METHOD_KEY]; ok && v != nil { dataMap[constant.METHOD_KEY] = v.(string) diff --git a/filter/filter_impl/generic_service_filter.go b/filter/filter_impl/generic_service_filter.go index 3711e68cce..89b009b8d1 100644 --- a/filter/filter_impl/generic_service_filter.go +++ b/filter/filter_impl/generic_service_filter.go @@ -20,7 +20,6 @@ package filter_impl import ( "context" "reflect" - "strings" ) import ( @@ -75,7 +74,7 @@ func (ef *GenericServiceFilter) Invoke(ctx context.Context, invoker protocol.Inv url := invoker.GetUrl() methodName = invocation.Arguments()[0].(string) // get service - svc := common.ServiceMap.GetService(url.Protocol, strings.TrimPrefix(url.Path, "/")) + svc := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) // get method method := svc.Method()[methodName] if method == nil { diff --git a/filter/filter_impl/generic_service_filter_test.go b/filter/filter_impl/generic_service_filter_test.go index 67819717cf..8b2fb549c2 100644 --- a/filter/filter_impl/generic_service_filter_test.go +++ b/filter/filter_impl/generic_service_filter_test.go @@ -96,7 +96,7 @@ func TestGenericServiceFilterInvoke(t *testing.T) { hessian.Object("222")}, } s := &TestService{} - _, _ = common.ServiceMap.Register("TestService", "testprotocol", s) + _, _ = common.ServiceMap.Register("com.test.Path", "testprotocol", "", "", s) rpcInvocation := invocation.NewRPCInvocation(methodName, aurguments, nil) filter := GetGenericServiceFilter() url, _ := common.NewURL("testprotocol://127.0.0.1:20000/com.test.Path") diff --git a/metadata/definition/definition_test.go b/metadata/definition/definition_test.go index 958f9324d0..389159239b 100644 --- a/metadata/definition/definition_test.go +++ b/metadata/definition/definition_test.go @@ -28,7 +28,6 @@ import ( import ( "github.com/apache/dubbo-go/common" - "github.com/apache/dubbo-go/common/constant" ) func TestBuildServiceDefinition(t *testing.T) { @@ -44,9 +43,9 @@ func TestBuildServiceDefinition(t *testing.T) { "owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000×tamp=1556509797245&group=%v&version=%v&bean.name=%v", protocol, serviceName, group, version, beanName)) assert.NoError(t, err) - _, err = common.ServiceMap.Register(serviceName, protocol, &UserProvider{}) + _, err = common.ServiceMap.Register(serviceName, protocol, group, version, &UserProvider{}) assert.NoError(t, err) - service := common.ServiceMap.GetService(url.Protocol, url.GetParam(constant.BEAN_NAME_KEY, url.Service())) + service := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) sd := BuildServiceDefinition(*service, url) assert.Equal(t, "{canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", sd.String()) } diff --git a/metadata/report/delegate/delegate_report_test.go b/metadata/report/delegate/delegate_report_test.go index 3dfca577ba..9c30ed9ffd 100644 --- a/metadata/report/delegate/delegate_report_test.go +++ b/metadata/report/delegate/delegate_report_test.go @@ -116,8 +116,8 @@ func getMockDefinition(id *identifier.MetadataIdentifier, t *testing.T) *definit "owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000×tamp=1556509797245&group=%v&version=%v&bean.name=%v", protocol, id.ServiceInterface, id.Group, id.Version, beanName)) assert.NoError(t, err) - _, err = common.ServiceMap.Register(id.ServiceInterface, protocol, &definition.UserProvider{}) + _, err = common.ServiceMap.Register(id.ServiceInterface, protocol, id.Group, id.Version, &definition.UserProvider{}) assert.NoError(t, err) - service := common.ServiceMap.GetService(url.Protocol, url.GetParam(constant.BEAN_NAME_KEY, url.Service())) + service := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) return definition.BuildServiceDefinition(*service, url) } diff --git a/metadata/service/exporter/configurable/exporter_test.go b/metadata/service/exporter/configurable/exporter_test.go index 2a5e646acd..7c2baa2728 100644 --- a/metadata/service/exporter/configurable/exporter_test.go +++ b/metadata/service/exporter/configurable/exporter_test.go @@ -69,7 +69,7 @@ func TestConfigurableExporter(t *testing.T) { assert.Equal(t, false, exported.IsExported()) assert.NoError(t, exported.Export(registryURL)) assert.Equal(t, true, exported.IsExported()) - assert.Regexp(t, "dubbo://:20003/MetadataService*", exported.GetExportedURLs()[0].String()) + assert.Regexp(t, "dubbo://:20003/org.apache.dubbo.metadata.MetadataService*", exported.GetExportedURLs()[0].String()) exported.Unexport() assert.Equal(t, false, exported.IsExported()) }) diff --git a/metadata/service/inmemory/service.go b/metadata/service/inmemory/service.go index d9cbd54305..8da78c3420 100644 --- a/metadata/service/inmemory/service.go +++ b/metadata/service/inmemory/service.go @@ -124,7 +124,7 @@ func (mts *MetadataService) getAllService(services *sync.Map) []*common.URL { urls := value.(*skip.SkipList) for i := uint64(0); i < urls.Len(); i++ { url := urls.ByPosition(i).(*common.URL) - if url.GetParam(constant.INTERFACE_KEY, url.Path) != constant.METADATA_SERVICE_NAME { + if url.Service() != constant.METADATA_SERVICE_NAME { res = append(res, url) } } @@ -178,7 +178,7 @@ func (mts *MetadataService) PublishServiceDefinition(url *common.URL) error { interfaceName := url.GetParam(constant.INTERFACE_KEY, "") isGeneric := url.GetParamBool(constant.GENERIC_KEY, false) if len(interfaceName) > 0 && !isGeneric { - tmpService := common.ServiceMap.GetService(url.Protocol, url.GetParam(constant.BEAN_NAME_KEY, url.Service())) + tmpService := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) sd := definition.BuildServiceDefinition(*tmpService, url) data, err := sd.ToBytes() if err != nil { diff --git a/metadata/service/inmemory/service_test.go b/metadata/service/inmemory/service_test.go index 048c286fdf..256412c291 100644 --- a/metadata/service/inmemory/service_test.go +++ b/metadata/service/inmemory/service_test.go @@ -82,7 +82,7 @@ func TestMetadataService(t *testing.T) { assert.Equal(t, 0, len(list4)) userProvider := &definition.UserProvider{} - common.ServiceMap.Register(serviceName, protocol, userProvider) + common.ServiceMap.Register(serviceName, protocol, group, version, userProvider) mts.PublishServiceDefinition(u) expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," + "\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," + diff --git a/metadata/service/remote/service.go b/metadata/service/remote/service.go index d1b17e8cd6..efd16bdc6d 100644 --- a/metadata/service/remote/service.go +++ b/metadata/service/remote/service.go @@ -115,7 +115,7 @@ func (mts *MetadataService) PublishServiceDefinition(url *common.URL) error { interfaceName := url.GetParam(constant.INTERFACE_KEY, "") isGeneric := url.GetParamBool(constant.GENERIC_KEY, false) if len(interfaceName) > 0 && !isGeneric { - sv := common.ServiceMap.GetService(url.Protocol, url.GetParam(constant.BEAN_NAME_KEY, url.Service())) + sv := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) sd := definition.BuildServiceDefinition(*sv, url) id := &identifier.MetadataIdentifier{ BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{ diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go index 1cbe5eec0f..71586cc1dc 100644 --- a/metadata/service/remote/service_test.go +++ b/metadata/service/remote/service_test.go @@ -126,7 +126,7 @@ func mockInmemoryProc(t *testing.T) *inmemory.MetadataService { _, err = mts.SubscribeURL(u) assert.NoError(t, err) - _, err = common.ServiceMap.Register(serviceName, protocol, userProvider) + _, err = common.ServiceMap.Register(serviceName, protocol, group, version, userProvider) assert.NoError(t, err) err = mts.PublishServiceDefinition(u) assert.NoError(t, err) diff --git a/protocol/dubbo/dubbo_exporter.go b/protocol/dubbo/dubbo_exporter.go index dd80937c5b..1873a63fe1 100644 --- a/protocol/dubbo/dubbo_exporter.go +++ b/protocol/dubbo/dubbo_exporter.go @@ -42,10 +42,9 @@ func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Ma // Unexport unexport dubbo service exporter. func (de *DubboExporter) Unexport() { - serviceId := de.GetInvoker().GetUrl().GetParam(constant.BEAN_NAME_KEY, "") interfaceName := de.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "") de.BaseExporter.Unexport() - err := common.ServiceMap.UnRegister(interfaceName, DUBBO, serviceId) + err := common.ServiceMap.UnRegister(interfaceName, DUBBO, de.GetInvoker().GetUrl().ServiceKey()) if err != nil { logger.Errorf("[DubboExporter.Unexport] error: %v", err) } diff --git a/protocol/dubbo/dubbo_invoker_test.go b/protocol/dubbo/dubbo_invoker_test.go index 49d853ee2d..c7a9a26975 100644 --- a/protocol/dubbo/dubbo_invoker_test.go +++ b/protocol/dubbo/dubbo_invoker_test.go @@ -97,7 +97,7 @@ func InitTest(t *testing.T) (protocol.Protocol, *common.URL) { hessian.RegisterPOJO(&User{}) - methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "dubbo", &UserProvider{}) + methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "dubbo", "", "", &UserProvider{}) assert.NoError(t, err) assert.Equal(t, "GetBigPkg,GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4,GetUser5,GetUser6", methods) diff --git a/protocol/dubbo/impl/hessian.go b/protocol/dubbo/impl/hessian.go index 9f23d365e0..5fa1f2ece3 100644 --- a/protocol/dubbo/impl/hessian.go +++ b/protocol/dubbo/impl/hessian.go @@ -383,7 +383,7 @@ func buildServerSidePackageBody(pkg *DubboPackage) { "dubboVersion": dubboVersion, "argsTypes": argsTypes, "args": args, - "service": common.ServiceMap.GetService(DUBBO, svc.Path), // path as a key + "service": common.ServiceMap.GetService(DUBBO, svc.Interface, svc.Group, svc.Version), // path as a key "attachments": attachments, }) } diff --git a/protocol/grpc/grpc_exporter.go b/protocol/grpc/grpc_exporter.go index 0dc764854d..5beb4fedb1 100644 --- a/protocol/grpc/grpc_exporter.go +++ b/protocol/grpc/grpc_exporter.go @@ -42,10 +42,9 @@ func NewGrpcExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map // Unexport and unregister gRPC service from registry and memory. func (gg *GrpcExporter) Unexport() { - serviceId := gg.GetInvoker().GetUrl().GetParam(constant.BEAN_NAME_KEY, "") interfaceName := gg.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "") gg.BaseExporter.Unexport() - err := common.ServiceMap.UnRegister(interfaceName, GRPC, serviceId) + err := common.ServiceMap.UnRegister(interfaceName, GRPC, gg.GetInvoker().GetUrl().ServiceKey()) if err != nil { logger.Errorf("[GrpcExporter.Unexport] error: %v", err) } diff --git a/protocol/jsonrpc/http_test.go b/protocol/jsonrpc/http_test.go index 4a9645e828..c4801c8db8 100644 --- a/protocol/jsonrpc/http_test.go +++ b/protocol/jsonrpc/http_test.go @@ -49,7 +49,7 @@ type ( ) const ( - mockJsonCommonUrl = "jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" + + mockJsonCommonUrl = "jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + @@ -58,7 +58,7 @@ const ( func TestHTTPClientCall(t *testing.T) { - methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", &UserProvider{}) + methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", "", "", &UserProvider{}) assert.NoError(t, err) assert.Equal(t, "GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4", methods) diff --git a/protocol/jsonrpc/jsonrpc_exporter.go b/protocol/jsonrpc/jsonrpc_exporter.go index 6f75f6aeae..6b91d266a7 100644 --- a/protocol/jsonrpc/jsonrpc_exporter.go +++ b/protocol/jsonrpc/jsonrpc_exporter.go @@ -42,10 +42,9 @@ func NewJsonrpcExporter(key string, invoker protocol.Invoker, exporterMap *sync. // Unexport exported JSON RPC service. func (je *JsonrpcExporter) Unexport() { - serviceId := je.GetInvoker().GetUrl().GetParam(constant.BEAN_NAME_KEY, "") interfaceName := je.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "") je.BaseExporter.Unexport() - err := common.ServiceMap.UnRegister(interfaceName, JSONRPC, serviceId) + err := common.ServiceMap.UnRegister(interfaceName, JSONRPC, je.GetInvoker().GetUrl().ServiceKey()) if err != nil { logger.Errorf("[JsonrpcExporter.Unexport] error: %v", err) } diff --git a/protocol/jsonrpc/jsonrpc_invoker_test.go b/protocol/jsonrpc/jsonrpc_invoker_test.go index d7124ca07c..12a57052eb 100644 --- a/protocol/jsonrpc/jsonrpc_invoker_test.go +++ b/protocol/jsonrpc/jsonrpc_invoker_test.go @@ -36,13 +36,13 @@ import ( func TestJsonrpcInvokerInvoke(t *testing.T) { - methods, err := common.ServiceMap.Register("UserProvider", "jsonrpc", &UserProvider{}) + methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", "", "", &UserProvider{}) assert.NoError(t, err) assert.Equal(t, "GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4", methods) // Export proto := GetProtocol() - url, err := common.NewURL("jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" + + url, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + diff --git a/protocol/rest/rest_exporter.go b/protocol/rest/rest_exporter.go index 359506a842..7a49a20635 100644 --- a/protocol/rest/rest_exporter.go +++ b/protocol/rest/rest_exporter.go @@ -42,10 +42,9 @@ func NewRestExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map // Unexport unexport the RestExporter func (re *RestExporter) Unexport() { - serviceId := re.GetInvoker().GetUrl().GetParam(constant.BEAN_NAME_KEY, "") interfaceName := re.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "") re.BaseExporter.Unexport() - err := common.ServiceMap.UnRegister(interfaceName, REST, serviceId) + err := common.ServiceMap.UnRegister(interfaceName, REST, re.GetInvoker().GetUrl().ServiceKey()) if err != nil { logger.Errorf("[RestExporter.Unexport] error: %v", err) } diff --git a/protocol/rest/rest_invoker_test.go b/protocol/rest/rest_invoker_test.go index 9df97a211e..18843d2ae4 100644 --- a/protocol/rest/rest_invoker_test.go +++ b/protocol/rest/rest_invoker_test.go @@ -65,7 +65,7 @@ func TestRestInvokerInvoke(t *testing.T) { url, err := common.NewURL(mockRestCommonUrl) assert.NoError(t, err) - _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) + _, err = common.ServiceMap.Register(url.Service(), url.Protocol, "", "", &UserProvider{}) assert.NoError(t, err) con := config.ProviderConfig{} config.SetProviderConfig(con) @@ -210,6 +210,6 @@ func TestRestInvokerInvoke(t *testing.T) { assert.Error(t, res.Error(), "test error") assert.Equal(t, filterNum, 12) - err = common.ServiceMap.UnRegister("UserProvider", url.Protocol, "com.ikurento.user.UserProvider") + err = common.ServiceMap.UnRegister(url.Service(), url.Protocol, url.ServiceKey()) assert.NoError(t, err) } diff --git a/protocol/rest/rest_protocol_test.go b/protocol/rest/rest_protocol_test.go index 9ff4e7df7f..580fc61fd6 100644 --- a/protocol/rest/rest_protocol_test.go +++ b/protocol/rest/rest_protocol_test.go @@ -72,7 +72,7 @@ func TestRestProtocolExport(t *testing.T) { proto := GetRestProtocol() url, err := common.NewURL(mockRestCommonUrl) assert.NoError(t, err) - _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) + _, err = common.ServiceMap.Register(url.Service(), url.Protocol, "", "", &UserProvider{}) assert.NoError(t, err) con := config.ProviderConfig{} config.SetProviderConfig(con) @@ -120,8 +120,6 @@ func TestRestProtocolExport(t *testing.T) { proto.Destroy() _, ok = proto.(*RestProtocol).serverMap[url.Location] assert.False(t, ok) - err = common.ServiceMap.UnRegister("UserProvider", url.Protocol, "com.ikurento.user.UserProvider") - assert.NoError(t, err) } type UserProvider struct { diff --git a/protocol/rest/server/rest_server.go b/protocol/rest/server/rest_server.go index 5ef04ff336..3a1cb19396 100644 --- a/protocol/rest/server/rest_server.go +++ b/protocol/rest/server/rest_server.go @@ -23,7 +23,6 @@ import ( "net/http" "reflect" "strconv" - "strings" ) import ( @@ -90,7 +89,7 @@ func GetRouteFunc(invoker protocol.Invoker, methodConfig *rest_config.RestMethod err error args []interface{} ) - svc := common.ServiceMap.GetService(invoker.GetUrl().Protocol, strings.TrimPrefix(invoker.GetUrl().Path, "/")) + svc := common.ServiceMap.GetServiceByServiceKey(invoker.GetUrl().Protocol, invoker.GetUrl().ServiceKey()) // get method method := svc.Method()[methodConfig.MethodName] argsTypes := method.ArgsType() diff --git a/remoting/getty/getty_client_test.go b/remoting/getty/getty_client_test.go index d49be5030a..0b18e973cd 100644 --- a/remoting/getty/getty_client_test.go +++ b/remoting/getty/getty_client_test.go @@ -211,7 +211,9 @@ func testGetUser3(t *testing.T, c *Client) { request := remoting.NewRequest("2.0.2") invocation := createInvocation("GetUser3", nil, nil, []interface{}{}, []reflect.Value{}) - attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"} + attachment := map[string]string{ + INTERFACE_KEY: "com.ikurento.user.UserProvider", + } setAttachment(invocation, attachment) request.Data = invocation request.Event = false @@ -341,7 +343,7 @@ func InitTest(t *testing.T) (*Server, *common.URL) { hessian.RegisterPOJO(&User{}) remoting.RegistryCodec("dubbo", &DubboTestCodec{}) - methods, err := common.ServiceMap.Register("", "dubbo", &UserProvider{}) + methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "dubbo", "", "", &UserProvider{}) assert.NoError(t, err) assert.Equal(t, "GetBigPkg,GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4,GetUser5,GetUser6", methods) @@ -387,14 +389,14 @@ func InitTest(t *testing.T) (*Server, *common.URL) { }}) assert.NoError(t, srvConf.CheckValidity()) - url, err := common.NewURL("dubbo://127.0.0.1:20060/UserProvider?anyhost=true&" + + url, err := common.NewURL("dubbo://127.0.0.1:20060/com.ikurento.user.UserProvider?anyhost=true&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=127.0.0.1&methods=GetUser%2C&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + "side=provider&timeout=3000×tamp=1556509797245&bean.name=UserProvider") // init server userProvider := &UserProvider{} - common.ServiceMap.Register("", url.Protocol, userProvider) + common.ServiceMap.Register("", url.Protocol, "", "0.0.1", userProvider) invoker := &proxy_factory.ProxyInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), }