You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/06/03 00:53:18 UTC

[servicecomb-java-chassis] 01/03: [SCB-1957]local and service-center Discovery and Registration must enabled together

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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit 2832658f088fb176470b0f7cb24a9208507c7088
Author: liubao <bi...@qq.com>
AuthorDate: Tue Jun 2 15:12:39 2020 +0800

    [SCB-1957]local and service-center Discovery and Registration must enabled together
---
 .../core/definition/ServiceRegistryListener.java   |  1 -
 .../apache/servicecomb/localregistry/Const.java    | 24 ++++++++++++++++++++++
 .../servicecomb/localregistry/LocalDiscovery.java  |  6 ++----
 .../localregistry/LocalRegistration.java           |  8 +++-----
 .../localregistry/LocalRegistryStore.java          |  8 ++++++++
 .../apache/servicecomb/schemadiscovery/Const.java  | 24 ++++++++++++++++++++++
 .../schemadiscovery/SchemaDiscovery.java           |  6 ++----
 .../serviceregistry/ServiceCenterDiscovery.java    |  7 +++----
 .../serviceregistry/ServiceCenterRegistration.java |  7 +++----
 .../servicecomb/serviceregistry/api/Const.java     |  5 ++---
 10 files changed, 71 insertions(+), 25 deletions(-)

diff --git a/core/src/main/java/org/apache/servicecomb/core/definition/ServiceRegistryListener.java b/core/src/main/java/org/apache/servicecomb/core/definition/ServiceRegistryListener.java
index c10f0a5..659921e 100644
--- a/core/src/main/java/org/apache/servicecomb/core/definition/ServiceRegistryListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/definition/ServiceRegistryListener.java
@@ -85,7 +85,6 @@ public class ServiceRegistryListener {
     // do not load service center schemas, because service center did not provide swagger,but can get schema ids....
     // service center better to resolve the problem.
     if (!isServiceCenter) {
-      // TODO: get schemas from instance
       for (String schemaId : microservice.getSchemas()) {
         Swagger swagger = scbEngine.getSwaggerLoader().loadSwagger(microservice, microserviceVersion.getInstances(),
             schemaId);
diff --git a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/Const.java b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/Const.java
new file mode 100644
index 0000000..b4ffe36
--- /dev/null
+++ b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/Const.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.localregistry;
+
+public class Const {
+  public static final String LOCAL_ENABLED = "servicecomb.local.registry.enabled";
+
+  public static final int LOCAL_ORDER = 0;
+}
diff --git a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalDiscovery.java b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalDiscovery.java
index 5338ab3..366606f 100644
--- a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalDiscovery.java
+++ b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalDiscovery.java
@@ -30,8 +30,6 @@ import com.netflix.config.DynamicPropertyFactory;
 public class LocalDiscovery implements Discovery {
   public static final String NAME = "local discovery";
 
-  public static final String ENABLED = "servicecomb.local.registry.discovery.enabled";
-
   private LocalRegistryStore localDiscoveryStore = LocalRegistryStore.INSTANCE;
 
   private String revision;
@@ -53,7 +51,7 @@ public class LocalDiscovery implements Discovery {
 
   @Override
   public int getOrder() {
-    return 100;
+    return Const.LOCAL_ORDER;
   }
 
   @Override
@@ -99,6 +97,6 @@ public class LocalDiscovery implements Discovery {
   @Override
   public boolean enabled() {
     return DynamicPropertyFactory.getInstance()
-        .getBooleanProperty(ENABLED, true).get();
+        .getBooleanProperty(Const.LOCAL_ENABLED, true).get();
   }
 }
diff --git a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistration.java b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistration.java
index 7dca24a..77b758f 100644
--- a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistration.java
+++ b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistration.java
@@ -21,19 +21,17 @@ import java.util.Collection;
 
 import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.registry.api.Registration;
+import org.apache.servicecomb.registry.api.event.MicroserviceInstanceRegisteredEvent;
 import org.apache.servicecomb.registry.api.registry.BasePath;
 import org.apache.servicecomb.registry.api.registry.Microservice;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstanceStatus;
-import org.apache.servicecomb.registry.api.event.MicroserviceInstanceRegisteredEvent;
 
 import com.netflix.config.DynamicPropertyFactory;
 
 public class LocalRegistration implements Registration {
   public static final String NAME = "local registration";
 
-  public static final String ENABLED = "servicecomb.local.registry.registration.enabled";
-
   private LocalRegistryStore localRegistrationStore = LocalRegistryStore.INSTANCE;
 
   @Override
@@ -54,7 +52,7 @@ public class LocalRegistration implements Registration {
 
   @Override
   public int getOrder() {
-    return 100;
+    return Const.LOCAL_ORDER;
   }
 
   @Override
@@ -101,6 +99,6 @@ public class LocalRegistration implements Registration {
   @Override
   public boolean enabled() {
     return DynamicPropertyFactory.getInstance()
-        .getBooleanProperty(ENABLED, true).get();
+        .getBooleanProperty(Const.LOCAL_ENABLED, true).get();
   }
 }
diff --git a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
index 1d0856f..6e22f18 100644
--- a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
+++ b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
@@ -212,10 +212,18 @@ public class LocalRegistryStore {
   }
 
   public String getSchema(String microserviceId, String schemaId) {
+    Microservice microservice = microserviceMap.get(microserviceId);
+    if (microservice == null) {
+      return null;
+    }
     return microserviceMap.get(microserviceId).getSchemaMap().get(schemaId);
   }
 
   public MicroserviceInstance findMicroserviceInstance(String serviceId, String instanceId) {
+    Map<String, MicroserviceInstance> microserviceInstance = microserviceInstanceMap.get(serviceId);
+    if (microserviceInstance == null) {
+      return null;
+    }
     return microserviceInstanceMap.get(serviceId).get(instanceId);
   }
 
diff --git a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/Const.java b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/Const.java
new file mode 100644
index 0000000..ad5dd11
--- /dev/null
+++ b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/Const.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.schemadiscovery;
+
+public class Const {
+  public static final int SCHEMA_DISCOVERY_ORDER = 200;
+
+  public static final String SCHEMA_DISCOVERY_ENABLED = "servicecomb.schema.discovery.enabled";
+}
diff --git a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
index d8fd12b..fd4cf00 100644
--- a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
+++ b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
@@ -39,8 +39,6 @@ public class SchemaDiscovery implements Discovery {
 
   public static final String NAME = "schema discovery";
 
-  public static final String ENABLED = "servicecomb.schema.registry.discovery.enabled";
-
   private SchemaDiscoveryService schemaDiscoveryService = null;
 
   @Override
@@ -134,7 +132,7 @@ public class SchemaDiscovery implements Discovery {
   @Override
   public boolean enabled() {
     return DynamicPropertyFactory.getInstance()
-        .getBooleanProperty(ENABLED, true).get();
+        .getBooleanProperty(Const.SCHEMA_DISCOVERY_ENABLED, true).get();
   }
 
   @Override
@@ -154,6 +152,6 @@ public class SchemaDiscovery implements Discovery {
 
   @Override
   public int getOrder() {
-    return 1000;
+    return Const.SCHEMA_DISCOVERY_ORDER;
   }
 }
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterDiscovery.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterDiscovery.java
index 80f091c..bdb6a05 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterDiscovery.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterDiscovery.java
@@ -24,14 +24,13 @@ import org.apache.servicecomb.registry.api.Discovery;
 import org.apache.servicecomb.registry.api.registry.Microservice;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
+import org.apache.servicecomb.serviceregistry.api.Const;
 
 import com.netflix.config.DynamicPropertyFactory;
 
 public class ServiceCenterDiscovery implements Discovery {
   public static final String NAME = "service center discovery";
 
-  public static final String ENABLED = "servicecomb.service.registry.discovery.enabled";
-
   private String revision;
 
   @Override
@@ -51,7 +50,7 @@ public class ServiceCenterDiscovery implements Discovery {
 
   @Override
   public int getOrder() {
-    return 0;
+    return Const.SERVICE_CENTER_ORDER;
   }
 
   @Override
@@ -102,6 +101,6 @@ public class ServiceCenterDiscovery implements Discovery {
   @Override
   public boolean enabled() {
     return DynamicPropertyFactory.getInstance()
-        .getBooleanProperty(ENABLED, true).get();
+        .getBooleanProperty(Const.SERVICE_CENTER_ENABLED, true).get();
   }
 }
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterRegistration.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterRegistration.java
index 5015aef..12cc45f 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterRegistration.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/ServiceCenterRegistration.java
@@ -25,14 +25,13 @@ import org.apache.servicecomb.registry.api.registry.BasePath;
 import org.apache.servicecomb.registry.api.registry.Microservice;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstanceStatus;
+import org.apache.servicecomb.serviceregistry.api.Const;
 
 import com.netflix.config.DynamicPropertyFactory;
 
 public class ServiceCenterRegistration implements Registration {
   public static final String NAME = "service center registration";
 
-  public static final String ENABLED = "servicecomb.service.registry.registration.enabled";
-
   @Override
   public void init() {
     RegistryUtils.init();
@@ -50,7 +49,7 @@ public class ServiceCenterRegistration implements Registration {
 
   @Override
   public int getOrder() {
-    return 0;
+    return Const.SERVICE_CENTER_ORDER;
   }
 
   @Override
@@ -110,6 +109,6 @@ public class ServiceCenterRegistration implements Registration {
   @Override
   public boolean enabled() {
     return DynamicPropertyFactory.getInstance()
-        .getBooleanProperty(ENABLED, true).get();
+        .getBooleanProperty(Const.SERVICE_CENTER_ENABLED, true).get();
   }
 }
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index 26ac8ee..55c68cc 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -177,7 +177,6 @@ public final class Const {
         MICROSERVICE_INSTANCE_STATUS = V4_PREFIX + "/microservices/%s/instances/%s/status";
       }
     }
-
   }
 
   public static final String REGISTRY_APP_ID = "default";
@@ -187,9 +186,9 @@ public final class Const {
 
   public static final String PATH_CHECKSESSION = "checksession";
 
-
+  public static final int SERVICE_CENTER_ORDER = 100;
 
   public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
 
-
+  public static final String SERVICE_CENTER_ENABLED = "servicecomb.service.registry.enabled";
 }