This is an automated email from the ASF dual-hosted git repository. littlecui 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 74cd79c SCB-619 find instance ,when consumer's provider rule more exist,then … (#356) 74cd79c is described below commit 74cd79c0eae2d1d39eee9c3014f895eaed2c04ff Author: aseTo2016 <1473442...@qq.com> AuthorDate: Tue May 29 09:47:00 2018 +0800 SCB-619 find instance ,when consumer's provider rule more exist,then … (#356) * SCB-619 find instance ,when consumer's provider rule more exist,then return * SCB-619 find instance ,when consumer's provider rule more exist,then return * SCB-619 find instance ,when consumer's provider rule more exist,then return --- server/service/util/dependency.go | 21 ++++++++++++++++----- server/service/util/dependency_test.go | 11 +++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/server/service/util/dependency.go b/server/service/util/dependency.go index 330473a..3263841 100644 --- a/server/service/util/dependency.go +++ b/server/service/util/dependency.go @@ -160,18 +160,29 @@ func GetProviderIdsByConsumer(ctx context.Context, domainProject string, service return providerIds[:allowIdx], providerIds[denyIdx:], nil } -func ProviderDependencyRuleExist(ctx context.Context, provider *pb.MicroServiceKey, consumer *pb.MicroServiceKey) (bool, error) { +func DependencyRuleExist(ctx context.Context, provider *pb.MicroServiceKey, consumer *pb.MicroServiceKey) (bool, error) { targetDomainProject := provider.Tenant if len(targetDomainProject) == 0 { targetDomainProject = consumer.Tenant } + + consumerKey := apt.GenerateConsumerDependencyRuleKey(targetDomainProject, consumer) + existed, err := dependencyRuleExistUtil(ctx, consumerKey, provider) + if err != nil || existed { + return existed, err + } + providerKey := apt.GenerateProviderDependencyRuleKey(targetDomainProject, provider) - consumers, err := TransferToMicroServiceDependency(ctx, providerKey) + return dependencyRuleExistUtil(ctx, providerKey, consumer) +} + +func dependencyRuleExistUtil(ctx context.Context, key string, target *pb.MicroServiceKey) (bool, error) { + compareData, err := TransferToMicroServiceDependency(ctx, key) if err != nil { return false, err } - if len(consumers.Dependency) != 0 { - isEqual, err := containServiceDependency(consumers.Dependency, consumer) + if len(compareData.Dependency) != 0 { + isEqual, err := containServiceDependency(compareData.Dependency, target) if err != nil { return false, err } @@ -186,7 +197,7 @@ func ProviderDependencyRuleExist(ctx context.Context, provider *pb.MicroServiceK func AddServiceVersionRule(ctx context.Context, domainProject string, consumer *pb.MicroService, provider *pb.MicroServiceKey) error { //创建依赖一致 consumerKey := pb.MicroServiceToKey(domainProject, consumer) - exist, err := ProviderDependencyRuleExist(ctx, provider, consumerKey) + exist, err := DependencyRuleExist(ctx, provider, consumerKey) if exist || err != nil { return err } diff --git a/server/service/util/dependency_test.go b/server/service/util/dependency_test.go index d28b0f1..d328190 100644 --- a/server/service/util/dependency_test.go +++ b/server/service/util/dependency_test.go @@ -218,6 +218,13 @@ func TestBadParamsResponse(t *testing.T) { } } +func TestDependencyRuleExistUtil(t *testing.T) { + _, err := dependencyRuleExistUtil(context.Background(), "", &proto.MicroServiceKey{}) + if err == nil { + t.Fatalf(`dependencyRuleExistUtil failed`) + } +} + func TestParamsChecker(t *testing.T) { p := ParamsChecker(nil, nil) if p == nil || p.Response.Code == proto.Response_SUCCESS { @@ -269,12 +276,12 @@ func TestParamsChecker(t *testing.T) { } func TestServiceDependencyRuleExist(t *testing.T) { - _, err := ProviderDependencyRuleExist(util.SetContext(context.Background(), "cacheOnly", "1"), &proto.MicroServiceKey{}, &proto.MicroServiceKey{}) + _, err := DependencyRuleExist(util.SetContext(context.Background(), "cacheOnly", "1"), &proto.MicroServiceKey{}, &proto.MicroServiceKey{}) if err != nil { t.Fatalf(`ServiceDependencyRuleExist WithCacheOnly failed`) } - _, err = ProviderDependencyRuleExist(context.Background(), &proto.MicroServiceKey{}, &proto.MicroServiceKey{}) + _, err = DependencyRuleExist(context.Background(), &proto.MicroServiceKey{}, &proto.MicroServiceKey{}) if err == nil { t.Fatalf(`ServiceDependencyRuleExist failed`) } -- To stop receiving notification emails like this one, please contact little...@apache.org.