You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2017/12/28 08:22:31 UTC

[GitHub] asifdxtreme closed pull request #234: SCB-127 Bug fix: Can not discovery the same domain service instances.

asifdxtreme closed pull request #234: SCB-127 Bug fix: Can not discovery the same domain service instances.
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/234
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services