This is an automated email from the ASF dual-hosted git repository.

asifdxtreme pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new a9637a4  SCB-127 Bug fix: Can not discovery the same domain service 
instances. (#234)
a9637a4 is described below

commit a9637a4c5c8b3b976eba26e70aa351e3795638a6
Author: little-cui <[email protected]>
AuthorDate: Thu Dec 28 16:22:27 2017 +0800

    SCB-127 Bug fix: Can not discovery the same domain service instances. (#234)
    
    * SCB-127 Bug fix: Can not discovery the same domain service instances.
    
    * SCB-127 Bug fix: Can not discovery the same domain service instances.
---
 pkg/util/util.go                           | 18 +++++++-----------
 server/service/event/rule_event_handler.go |  6 +++---
 server/service/instances.go                | 13 +++++++------
 3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/pkg/util/util.go b/pkg/util/util.go
index eea2da3..fc950a4 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -150,11 +150,7 @@ func ParseDomainProject(ctx context.Context) string {
 }
 
 func ParseTargetDomainProject(ctx context.Context) string {
-       domain := ParseTargetDomain(ctx)
-       if len(domain) == 0 {
-               return ParseDomainProject(ctx)
-       }
-       return domain + "/" + ParseTargetProject(ctx)
+       return ParseTargetDomain(ctx) + "/" + ParseTargetProject(ctx)
 }
 
 func ParseDomain(ctx context.Context) string {
@@ -166,9 +162,9 @@ func ParseDomain(ctx context.Context) string {
 }
 
 func ParseTargetDomain(ctx context.Context) string {
-       v, ok := FromContext(ctx, "target-domain").(string)
-       if !ok {
-               return ""
+       v, _ := FromContext(ctx, "target-domain").(string)
+       if len(v) == 0 {
+               return ParseDomain(ctx)
        }
        return v
 }
@@ -182,9 +178,9 @@ func ParseProject(ctx context.Context) string {
 }
 
 func ParseTargetProject(ctx context.Context) string {
-       v, ok := FromContext(ctx, "target-project").(string)
-       if !ok {
-               return ""
+       v, _ := FromContext(ctx, "target-project").(string)
+       if len(v) == 0 {
+               return ParseProject(ctx)
        }
        return v
 }
diff --git a/server/service/event/rule_event_handler.go 
b/server/service/event/rule_event_handler.go
index 42c956c..a2d2650 100644
--- a/server/service/event/rule_event_handler.go
+++ b/server/service/event/rule_event_handler.go
@@ -53,14 +53,14 @@ func (apt *RulesChangedAsyncTask) Err() error {
 func (apt *RulesChangedAsyncTask) publish(ctx context.Context, domainProject, 
providerId string, rev int64) error {
        provider, err := serviceUtil.GetService(ctx, domainProject, providerId)
        if err != nil {
-               util.Logger().Errorf(err, "get service %s file failed", 
providerId)
+               util.Logger().Errorf(err, "get provider %s service file 
failed", providerId)
                return err
        }
        if provider == nil {
                tmpProvider, found := serviceUtil.MsCache().Get(providerId)
                if !found {
-                       util.Logger().Errorf(nil, "service not exist, %s", 
providerId)
-                       return fmt.Errorf("service not exist, %s", providerId)
+                       util.Logger().Errorf(nil, "provider %s does not exist", 
providerId)
+                       return fmt.Errorf("provider %s does not exist", 
providerId)
                }
                provider = tmpProvider.(*pb.MicroService)
        }
diff --git a/server/service/instances.go b/server/service/instances.go
index e850bc4..8160f7e 100644
--- a/server/service/instances.go
+++ b/server/service/instances.go
@@ -563,9 +563,8 @@ func (s *InstanceService) Find(ctx context.Context, in 
*pb.FindInstancesRequest)
                }, nil
        }
 
-       targetDomainProject := util.ParseTargetDomainProject(ctx)
        provider := &pb.MicroServiceKey{
-               Tenant:      targetDomainProject,
+               Tenant:      util.ParseTargetDomainProject(ctx),
                Environment: service.Environment,
                AppId:       in.AppId,
                ServiceName: in.ServiceName,
@@ -576,9 +575,11 @@ func (s *InstanceService) Find(ctx context.Context, in 
*pb.FindInstancesRequest)
                provider.Environment = apt.Service.Environment
                findFlag += "(shared services in " + provider.Environment + " 
environment)"
        } else {
+               // provider is not a shared micro-service,
                // only allow shared micro-service instances found in different 
domains.
-               targetDomainProject = domainProject
-               provider.Tenant = domainProject
+               util.SetContext(ctx, "target-domain", util.ParseDomain(ctx))
+               util.SetContext(ctx, "target-project", util.ParseProject(ctx))
+               provider.Tenant = util.ParseTargetDomainProject(ctx)
                findFlag += "(" + provider.Environment + " services of the same 
domain)"
        }
 
@@ -616,7 +617,7 @@ func (s *InstanceService) Find(ctx context.Context, in 
*pb.FindInstancesRequest)
        }
 
        //维护version的规则,servicename 可能是别名,所以重新获取
-       providerService, err := serviceUtil.GetService(ctx, 
targetDomainProject, ids[0])
+       providerService, err := serviceUtil.GetService(ctx, provider.Tenant, 
ids[0])
        if providerService == nil {
                util.Logger().Errorf(err, "find instance failed, %s: no 
provider matched.", findFlag)
                return &pb.FindInstancesResponse{
@@ -624,7 +625,7 @@ func (s *InstanceService) Find(ctx context.Context, in 
*pb.FindInstancesRequest)
                }, nil
        }
 
-       provider = pb.MicroServiceToKey(targetDomainProject, providerService)
+       provider = pb.MicroServiceToKey(provider.Tenant, providerService)
        provider.Version = in.VersionRule
 
        err = serviceUtil.AddServiceVersionRule(ctx, domainProject, service, 
provider)

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to