You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/12/24 08:25:49 UTC

[servicecomb-java-chassis] branch master updated: [SCB-1083]specify initial instance status when register

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3f550c3  [SCB-1083]specify initial instance status when register
3f550c3 is described below

commit 3f550c35dc8f7780130a0307f81ebbd961462f5d
Author: liubao <ba...@huawei.com>
AuthorDate: Sat Dec 22 16:16:12 2018 +0800

    [SCB-1083]specify initial instance status when register
---
 .../serviceregistry/api/registry/MicroserviceInstance.java         | 7 ++++++-
 .../serviceregistry/api/registry/MicroserviceInstanceStatus.java   | 7 ++++---
 .../servicecomb/serviceregistry/definition/DefinitionConst.java    | 6 ++++++
 .../serviceregistry/registry/TestRemoteServiceRegistry.java        | 5 +++++
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
index 8d4d7f7..4665078 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
@@ -18,7 +18,9 @@
 package org.apache.servicecomb.serviceregistry.api.registry;
 
 import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.CONFIG_QUALIFIED_INSTANCE_ENVIRONMENT_KEY;
+import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.CONFIG_QUALIFIED_INSTANCE_INITIAL_STATUS;
 import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_INSTANCE_ENVIRONMENT;
+import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_INSTANCE_INITIAL_STATUS;
 import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_STAGE;
 
 import java.util.ArrayList;
@@ -168,6 +170,8 @@ public class MicroserviceInstance {
     microserviceInstance
         .setEnvironment(
             configuration.getString(CONFIG_QUALIFIED_INSTANCE_ENVIRONMENT_KEY, DEFAULT_INSTANCE_ENVIRONMENT));
+    microserviceInstance.setStatus(MicroserviceInstanceStatus
+        .valueOf(configuration.getString(CONFIG_QUALIFIED_INSTANCE_INITIAL_STATUS, DEFAULT_INSTANCE_INITIAL_STATUS)));
     HealthCheck healthCheck = new HealthCheck();
     healthCheck.setMode(HealthCheckMode.HEARTBEAT);
     microserviceInstance.setHealthCheck(healthCheck);
@@ -189,7 +193,8 @@ public class MicroserviceInstance {
       DataCenterInfo dataCenterInfo = new DataCenterInfo();
       dataCenterInfo.setName(dataCenterName);
       dataCenterInfo
-          .setRegion(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.datacenter.region", null).get());
+          .setRegion(
+              DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.datacenter.region", null).get());
       dataCenterInfo.setAvailableZone(
           DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.datacenter.availableZone", null).get());
       microserviceInstance.setDataCenterInfo(dataCenterInfo);
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstanceStatus.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstanceStatus.java
index 58b3642..27c56ce 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstanceStatus.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstanceStatus.java
@@ -21,9 +21,10 @@ package org.apache.servicecomb.serviceregistry.api.registry;
  * Created by   on 2016/12/5.
  */
 public enum MicroserviceInstanceStatus {
-  UNKNOWN,
+  STARTING,
+  TESTING,
   UP,
+  OUTOFSERVICE,
   DOWN,
-  STARTING,
-  OUTOFSERVICE
+  UNKNOWN
 }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
index a51e307..0ad54a9 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
@@ -17,10 +17,14 @@
 
 package org.apache.servicecomb.serviceregistry.definition;
 
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
+
 public interface DefinitionConst {
 
   String CONFIG_QUALIFIED_INSTANCE_ENVIRONMENT_KEY = "instance_description.environment";
 
+  String CONFIG_QUALIFIED_INSTANCE_INITIAL_STATUS = "instance_description.initialStatus";
+
   String CONFIG_ALLOW_CROSS_APP_KEY = "allowCrossApp";
 
   String DEFAULT_APPLICATION_ID = "default";
@@ -31,6 +35,8 @@ public interface DefinitionConst {
 
   String DEFAULT_INSTANCE_ENVIRONMENT = "production";
 
+  String DEFAULT_INSTANCE_INITIAL_STATUS = MicroserviceInstanceStatus.UP.name();
+
   String VERSION_RULE_LATEST = "latest";
 
   String VERSION_RULE_ALL = "0.0.0+";
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
index 718e649..2a2447d 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
@@ -17,6 +17,8 @@
 package org.apache.servicecomb.serviceregistry.registry;
 
 import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY;
+import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.CONFIG_QUALIFIED_INSTANCE_INITIAL_STATUS;
+import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_INSTANCE_INITIAL_STATUS;
 import static org.apache.servicecomb.serviceregistry.definition.DefinitionConst.DEFAULT_MICROSERVICE_VERSION;
 
 import java.util.ArrayList;
@@ -32,6 +34,7 @@ import org.apache.servicecomb.foundation.common.net.IpPort;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
 import org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl;
 import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
@@ -153,6 +156,8 @@ public class TestRemoteServiceRegistry {
         configuration.getString(CONFIG_QUALIFIED_MICROSERVICE_VERSION_KEY,
             DEFAULT_MICROSERVICE_VERSION);
         result = "1.0.0";
+        configuration.getString(CONFIG_QUALIFIED_INSTANCE_INITIAL_STATUS, DEFAULT_INSTANCE_INITIAL_STATUS);
+        result = MicroserviceInstanceStatus.UP.name();
       }
     };