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 2018/01/22 11:36:45 UTC
[GitHub] little-cui closed pull request #255: SCB-259 Can not discovery default APP services in Shared service mode
little-cui closed pull request #255: SCB-259 Can not discovery default APP services in Shared service mode
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/255
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/server/core/microservice.go b/server/core/microservice.go
index c357f54c..0ae21f73 100644
--- a/server/core/microservice.go
+++ b/server/core/microservice.go
@@ -20,15 +20,15 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
"github.com/apache/incubator-servicecomb-service-center/version"
- "github.com/astaxie/beego"
"golang.org/x/net/context"
+ "os"
"strings"
)
var (
- Service *pb.MicroService
- Instance *pb.MicroServiceInstance
- isShared bool
+ Service *pb.MicroService
+ Instance *pb.MicroServiceInstance
+ sharedServiceNames map[string]struct{}
)
const (
@@ -45,8 +45,12 @@ const (
)
func init() {
- SetSharedMode(len(strings.TrimSpace(beego.AppConfig.String("auth_plugin"))) > 0)
+ prepareSelfRegistration()
+ SetSharedMode()
+}
+
+func prepareSelfRegistration() {
Service = &pb.MicroService{
Environment: pb.ENV_PROD,
AppId: REGISTRY_APP_ID,
@@ -86,19 +90,20 @@ func IsDefaultDomainProject(domainProject string) bool {
return domainProject == util.StringJoin([]string{REGISTRY_DOMAIN, REGISTRY_PROJECT}, "/")
}
-func SetSharedMode(b bool) {
- isShared = b
+func SetSharedMode() {
+ sharedServiceNames = util.ListToMap(strings.Split(os.Getenv("CSE_SHARED_SERVICES"), ","))
+ sharedServiceNames[Service.ServiceName] = struct{}{}
}
func IsShared(key *pb.MicroServiceKey) bool {
- if !isShared {
- // shared micro-service only can be registered in auth mode.
+ if !IsDefaultDomainProject(key.Tenant) {
return false
}
- if !IsDefaultDomainProject(key.Tenant) {
+ if key.AppId != REGISTRY_APP_ID {
return false
}
- return key.AppId == Service.AppId
+ _, ok := sharedServiceNames[key.ServiceName]
+ return ok
}
func IsSCKey(key *pb.MicroServiceKey) bool {
diff --git a/server/service/instances_test.go b/server/service/instances_test.go
index 3e3750b0..355a6153 100644
--- a/server/service/instances_test.go
+++ b/server/service/instances_test.go
@@ -26,6 +26,7 @@ import (
. "github.com/onsi/gomega"
"golang.org/x/net/context"
"google.golang.org/grpc"
+ "os"
)
type grpcWatchServer struct {
@@ -598,6 +599,7 @@ var _ = Describe("'Instance' service", func() {
serviceId4 string
serviceId5 string
serviceId6 string
+ serviceId7 string
instanceId1 string
instanceId2 string
instanceId4 string
@@ -675,10 +677,23 @@ var _ = Describe("'Instance' service", func() {
Expect(respCreate.Response.Code).To(Equal(pb.Response_SUCCESS))
serviceId5 = respCreate.ServiceId
+ respCreate, err = serviceResource.Create(getContext(), &pb.CreateServiceRequest{
+ Service: &pb.MicroService{
+ AppId: "default",
+ ServiceName: "query_instance_shared_consumer",
+ Version: "1.0.0",
+ Level: "FRONT",
+ Status: pb.MS_UP,
+ },
+ })
+ Expect(err).To(BeNil())
+ Expect(respCreate.Response.Code).To(Equal(pb.Response_SUCCESS))
+ serviceId7 = respCreate.ServiceId
+
respCreate, err = serviceResource.Create(util.SetDomainProject(context.Background(), "user", "user"),
&pb.CreateServiceRequest{
Service: &pb.MicroService{
- AppId: "query_instance_diff_domain",
+ AppId: "default",
ServiceName: "query_instance_diff_domain_consumer",
Version: "1.0.0",
Level: "FRONT",
@@ -888,8 +903,10 @@ var _ = Describe("'Instance' service", func() {
Expect(len(respFind.Instances)).To(Equal(0))
By("shared service discovery")
- core.SetSharedMode(true)
+ os.Setenv("CSE_SHARED_SERVICES", "query_instance_shared_provider")
+ core.SetSharedMode()
core.Service.Environment = pb.ENV_PROD
+
respFind, err = instanceResource.Find(
util.SetTargetDomainProject(
util.SetDomainProject(context.Background(), "user", "user"),
@@ -906,7 +923,7 @@ var _ = Describe("'Instance' service", func() {
Expect(respFind.Instances[0].InstanceId).To(Equal(instanceId5))
respFind, err = instanceResource.Find(getContext(), &pb.FindInstancesRequest{
- ConsumerServiceId: serviceId4,
+ ConsumerServiceId: serviceId7,
AppId: "default",
ServiceName: "query_instance_shared_provider",
VersionRule: "1.0.0",
@@ -915,8 +932,8 @@ var _ = Describe("'Instance' service", func() {
Expect(respFind.Response.Code).To(Equal(pb.Response_SUCCESS))
Expect(len(respFind.Instances)).To(Equal(1))
Expect(respFind.Instances[0].InstanceId).To(Equal(instanceId5))
+
core.Service.Environment = pb.ENV_DEV
- core.SetSharedMode(false)
})
})
----------------------------------------------------------------
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