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 2018/03/16 01:54:11 UTC

[incubator-servicecomb-java-chassis] 01/03: [SCB-394] framework version support SC which earlier than 1.0.0

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/incubator-servicecomb-java-chassis.git

commit cee58b7ee47fda6450c6da09930dfedc157ede53
Author: weichao666 <we...@huawei.com>
AuthorDate: Mon Mar 12 17:40:03 2018 +0800

    [SCB-394] framework version support SC which earlier than 1.0.0
---
 .../servicecomb/serviceregistry/api/Const.java     |   8 +
 .../api/registry/FrameworkVersions.java            |  17 ++
 .../api/registry/MicroserviceFactory.java          |   9 -
 .../api/registry/ServiceCenterConfig.java          | 200 +++++++++++++++++++++
 .../api/registry/ServiceCenterInfo.java            |  70 ++++++++
 .../client/LocalServiceRegistryClientImpl.java     |  12 ++
 .../client/ServiceRegistryClient.java              |   6 +
 .../client/http/ServiceRegistryClientImpl.java     |  22 +++
 .../registry/AbstractServiceRegistry.java          |  14 ++
 .../servicecomb/serviceregistry/TestRegistry.java  |  11 ++
 .../api/registry/TestFrameworkVersions.java        |  23 +++
 .../api/registry/TestServiceCenterConfig.java      |  91 ++++++++++
 .../api/registry/TestServiceCenterInfo.java        |  53 ++++++
 .../client/LocalServiceRegistryClientImplTest.java |   7 +
 .../client/http/TestServiceRegistryClientImpl.java |  46 +++++
 .../registry/TestLocalServiceRegistry.java         |  25 +++
 .../registry/TestRemoteServiceRegistry.java        |  16 ++
 17 files changed, 621 insertions(+), 9 deletions(-)

diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index c9f7e84..5f3173a 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -137,6 +137,14 @@ public final class Const {
       }
     }
 
+    public static final String SERVICECENTER_VERSION;
+    static {
+      if (VERSION_V3.equals(CURRENT_VERSION)) {
+        SERVICECENTER_VERSION = "/version";
+      } else {
+        SERVICECENTER_VERSION = V4_PREFIX + "/version";
+      }
+    }
   }
 
   public static final String REGISTRY_APP_ID = "default";
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/FrameworkVersions.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/FrameworkVersions.java
index 5c87855..a9dce0f 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/FrameworkVersions.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/FrameworkVersions.java
@@ -22,12 +22,29 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.ServiceLoader;
 
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.api.Versions;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class FrameworkVersions {
+  private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkVersions.class);
   private static final ServiceLoader<Versions> frameworkVersions = ServiceLoader.load(Versions.class);
 
   public static String allVersions() {
+    ServiceRegistryClient client = RegistryUtils.getServiceRegistryClient();
+    ServiceCenterInfo serviceCenterInfo = client.getServiceCenterInfo();
+    if (serviceCenterInfo == null) {
+      LOGGER.error("query servicecenter version info failed.");
+    }
+    String scVersion = serviceCenterInfo.getVersion();
+    //old scVersion which earlier than 1.0.0 not report frameworkVersion, e.g. 0.5.0
+    String oldScVersion = "0.[0-5].0+";
+    if (scVersion.matches(oldScVersion)) {
+      return "";
+    }
+
     Map<String, String> versions = new HashMap<>();
     Entry<String, String> entry;
     StringBuffer sb = new StringBuffer();
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java
index 4e40aa1..beba2d9 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceFactory.java
@@ -17,8 +17,6 @@
 package org.apache.servicecomb.serviceregistry.api.registry;
 
 import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_APPLICATION_ID_KEY;
-import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_DEFAULT_REGISTER_BY;
-import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_FRAMEWORK_DEFAULT_NAME;
 import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY;
 import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY;
 import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_ROLE_KEY;
@@ -70,13 +68,6 @@ public class MicroserviceFactory {
           microservice.getServiceName()));
     }
 
-    // use default values, we can add configure item in future.
-    Framework framework = new Framework();
-    framework.setName(CONFIG_FRAMEWORK_DEFAULT_NAME);
-    framework.setVersion(FrameworkVersions.allVersions());
-    microservice.setFramework(framework);
-    microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
-
     return microservice;
   }
 
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterConfig.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterConfig.java
new file mode 100644
index 0000000..26049e1
--- /dev/null
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterConfig.java
@@ -0,0 +1,200 @@
+/*
+ * 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.serviceregistry.api.registry;
+
+public class ServiceCenterConfig {
+  private int maxHeaderBytes;
+
+  private int maxBodyBytes;
+
+  private String readHeaderTimeout;
+
+  private String readTimeout;
+
+  private String idleTimeout;
+
+  private String writeTimeout;
+
+  private String limitTTLUnit;
+
+  private int limitConnections;
+
+  private String limitIPLookup;
+
+  private String sslEnabled;
+
+  private String sslMinVersion;
+
+  private String sslVerifyPeer;
+
+  private String sslCiphers;
+
+  private String autoSyncInterval;
+
+  private int compactIndexDelta;
+
+  private String compactInterval;
+
+  private int logRotateSize;
+
+  private int logBackupCount;
+
+  public int getMaxHeaderBytes() {
+    return maxHeaderBytes;
+  }
+
+  public void setMaxHeaderBytes(int maxHeaderBytes) {
+    this.maxHeaderBytes = maxHeaderBytes;
+  }
+
+  public int getMaxBodyBytes() {
+    return maxBodyBytes;
+  }
+
+  public void setMaxBodyBytes(int maxBodyBytes) {
+    this.maxBodyBytes = maxBodyBytes;
+  }
+
+  public String getReadHeaderTimeout() {
+    return readHeaderTimeout;
+  }
+
+  public void setReadHeaderTimeout(String readHeaderTimeout) {
+    this.readHeaderTimeout = readHeaderTimeout;
+  }
+
+  public String getReadTimeout() {
+    return readTimeout;
+  }
+
+  public void setReadTimeout(String readTimeout) {
+    this.readTimeout = readTimeout;
+  }
+
+  public String getIdleTimeout() {
+    return idleTimeout;
+  }
+
+  public void setIdleTimeout(String idleTimeout) {
+    this.idleTimeout = idleTimeout;
+  }
+
+  public String getWriteTimeout() {
+    return writeTimeout;
+  }
+
+  public void setWriteTimeout(String writeTimeout) {
+    this.writeTimeout = writeTimeout;
+  }
+
+  public String getLimitTTLUnit() {
+    return limitTTLUnit;
+  }
+
+  public void setLimitTTLUnit(String limitTTLUnit) {
+    this.limitTTLUnit = limitTTLUnit;
+  }
+
+  public int getLimitConnections() {
+    return limitConnections;
+  }
+
+  public void setLimitConnections(int limitConnections) {
+    this.limitConnections = limitConnections;
+  }
+
+  public String getLimitIPLookup() {
+    return limitIPLookup;
+  }
+
+  public void setLimitIPLookup(String limitIPLookup) {
+    this.limitIPLookup = limitIPLookup;
+  }
+
+  public String getSslEnabled() {
+    return sslEnabled;
+  }
+
+  public void setSslEnabled(String sslEnabled) {
+    this.sslEnabled = sslEnabled;
+  }
+
+  public String getSslMinVersion() {
+    return sslMinVersion;
+  }
+
+  public void setSslMinVersion(String sslMinVersion) {
+    this.sslMinVersion = sslMinVersion;
+  }
+
+  public String getSslVerifyPeer() {
+    return sslVerifyPeer;
+  }
+
+  public void setSslVerifyPeer(String sslVerifyPeer) {
+    this.sslVerifyPeer = sslVerifyPeer;
+  }
+
+  public String getSslCiphers() {
+    return sslCiphers;
+  }
+
+  public void setSslCiphers(String sslCiphers) {
+    this.sslCiphers = sslCiphers;
+  }
+
+  public String getAutoSyncInterval() {
+    return autoSyncInterval;
+  }
+
+  public void setAutoSyncInterval(String autoSyncInterval) {
+    this.autoSyncInterval = autoSyncInterval;
+  }
+
+  public int getCompactIndexDelta() {
+    return compactIndexDelta;
+  }
+
+  public void setCompactIndexDelta(int compactIndexDelta) {
+    this.compactIndexDelta = compactIndexDelta;
+  }
+
+  public String getCompactInterval() {
+    return compactInterval;
+  }
+
+  public void setCompactInterval(String compactInterval) {
+    this.compactInterval = compactInterval;
+  }
+
+  public int getLogRotateSize() {
+    return logRotateSize;
+  }
+
+  public void setLogRotateSize(int logRotateSize) {
+    this.logRotateSize = logRotateSize;
+  }
+
+  public int getLogBackupCount() {
+    return logBackupCount;
+  }
+
+  public void setLogBackupCount(int logBackupCount) {
+    this.logBackupCount = logBackupCount;
+  }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterInfo.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterInfo.java
new file mode 100644
index 0000000..65dca2b
--- /dev/null
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/ServiceCenterInfo.java
@@ -0,0 +1,70 @@
+/*
+ * 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.serviceregistry.api.registry;
+
+public class ServiceCenterInfo {
+  private String version;
+
+  private String buildTag;
+
+  private String runMode;
+
+  private String apiVersion;
+
+  private ServiceCenterConfig config;
+
+  public String getVersion() {
+    return version;
+  }
+
+  public void setVersion(String version) {
+    this.version = version;
+  }
+
+  public String getBuildTag() {
+    return buildTag;
+  }
+
+  public void setBuildTag(String buildTag) {
+    this.buildTag = buildTag;
+  }
+
+  public String getRunMode() {
+    return runMode;
+  }
+
+  public void setRunMode(String runMode) {
+    this.runMode = runMode;
+  }
+
+  public String getApiVersion() {
+    return apiVersion;
+  }
+
+  public void setApiVersion(String apiVersion) {
+    this.apiVersion = apiVersion;
+  }
+
+  public ServiceCenterConfig getConfig() {
+    return config;
+  }
+
+  public void setConfig(ServiceCenterConfig config) {
+    this.config = config;
+  }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
index 663cde3..2cb228f 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
@@ -34,6 +34,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterConfig;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse;
 import org.apache.servicecomb.serviceregistry.api.response.HeartbeatResponse;
 import org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
@@ -371,5 +373,15 @@ public class LocalServiceRegistryClientImpl implements ServiceRegistryClient {
     return instances.get(instanceId);
   }
 
+  @Override
+  public ServiceCenterInfo getServiceCenterInfo() {
+    ServiceCenterInfo info = new ServiceCenterInfo();
+    info.setVersion("1.0.0");
+    info.setBuildTag("20180312");
+    info.setRunMode("dev");
+    info.setApiVersion("4.0.0");
+    info.setConfig(new ServiceCenterConfig());
+    return info;
+  }
 
 }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
index 6167824..2cf20b9 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.api.response.HeartbeatResponse;
 import org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
 import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
@@ -140,4 +141,9 @@ public interface ServiceRegistryClient {
    * @return MicroserviceInstance
    */
   MicroserviceInstance findServiceInstance(String serviceId, String instanceId);
+
+  /**
+   * get ServiceCenterVersionInfo
+   */
+  ServiceCenterInfo getServiceCenterInfo();
 }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
index d48d0bc..ab7f597 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
@@ -35,6 +35,7 @@ import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
 import org.apache.servicecomb.serviceregistry.api.Const;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.api.request.CreateSchemaRequest;
 import org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest;
 import org.apache.servicecomb.serviceregistry.api.request.RegisterInstanceRequest;
@@ -735,4 +736,25 @@ public final class ServiceRegistryClientImpl implements ServiceRegistryClient {
       return null;
     }
   }
+
+  @Override
+  public ServiceCenterInfo getServiceCenterInfo() {
+    Holder<ServiceCenterInfo> holder = new Holder<>();
+    IpPort ipPort = ipPortManager.getAvailableAddress();
+
+    CountDownLatch countDownLatch = new CountDownLatch(1);
+    RestUtils.get(ipPort,
+        Const.REGISTRY_API.SERVICECENTER_VERSION,
+        new RequestParam(),
+        syncHandler(countDownLatch, ServiceCenterInfo.class, holder));
+    try {
+      countDownLatch.await();
+      if (holder.value != null) {
+        return holder.value;
+      }
+    } catch (Exception e) {
+      LOGGER.error("query servicecenter version info failed.", e);
+    }
+    return null;
+  }
 }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index 9b67ed5..6ad86bf 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -16,6 +16,9 @@
  */
 package org.apache.servicecomb.serviceregistry.registry;
 
+import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_DEFAULT_REGISTER_BY;
+import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_FRAMEWORK_DEFAULT_NAME;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -25,6 +28,8 @@ import org.apache.servicecomb.serviceregistry.Features;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
 import org.apache.servicecomb.serviceregistry.api.Const;
 import org.apache.servicecomb.serviceregistry.api.registry.BasePath;
+import org.apache.servicecomb.serviceregistry.api.registry.Framework;
+import org.apache.servicecomb.serviceregistry.api.registry.FrameworkVersions;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
@@ -162,11 +167,20 @@ public abstract class AbstractServiceRegistry implements ServiceRegistry {
   public void run() {
     loadStaticConfiguration();
 
+    loadFrameworkVersions();
     // try register
     // if failed, then retry in thread
     serviceCenterTask.init();
   }
 
+  private void loadFrameworkVersions() {
+    Framework framework = new Framework();
+    framework.setName(CONFIG_FRAMEWORK_DEFAULT_NAME);
+    framework.setVersion(FrameworkVersions.allVersions());
+    microservice.setFramework(framework);
+    microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
+  }
+
   private void loadStaticConfiguration() {
     // TODO 如果yaml定义了paths规则属性,替换默认值,现需要DynamicPropertyFactory支持数组获取
     List<BasePath> paths = microservice.getPaths();
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
index 8237ef4..f4e9382 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/TestRegistry.java
@@ -34,6 +34,8 @@ import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.foundation.common.net.NetUtils;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
 import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
 import org.junit.AfterClass;
@@ -55,6 +57,9 @@ import mockit.Mocked;
 
 public class TestRegistry {
   private static final AbstractConfiguration inMemoryConfig = new ConcurrentMapConfiguration();
+  private static ServiceRegistryClient registryClient = Mockito.mock(ServiceRegistryClient.class);
+  private static ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
+  private static ServiceCenterInfo serviceCenterInfo = Mockito.mock(ServiceCenterInfo.class);
 
   @BeforeClass
   public static void initSetup() throws Exception {
@@ -64,6 +69,11 @@ public class TestRegistry {
     configuration.addConfiguration(inMemoryConfig);
 
     ConfigurationManager.install(configuration);
+
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", serviceRegistry);
+    Mockito.when(serviceRegistry.getServiceRegistryClient()).thenReturn(registryClient);
+    Mockito.when(registryClient.getServiceCenterInfo()).thenReturn(serviceCenterInfo);
+    Mockito.when(serviceCenterInfo.getVersion()).thenReturn("1.0.0");
   }
 
   @AfterClass
@@ -72,6 +82,7 @@ public class TestRegistry {
     Deencapsulation.setField(ConfigurationManager.class, "customConfigurationInstalled", false);
     Deencapsulation.setField(DynamicPropertyFactory.class, "config", null);
     RegistryUtils.setServiceRegistry(null);
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", null);
   }
 
   @Before
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestFrameworkVersions.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestFrameworkVersions.java
index d02bd55..5d16727 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestFrameworkVersions.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestFrameworkVersions.java
@@ -17,10 +17,33 @@
 
 package org.apache.servicecomb.serviceregistry.api.registry;
 
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.ServiceRegistry;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mockito.Mockito;
+import mockit.Deencapsulation;
 
 public class TestFrameworkVersions {
+  private static ServiceRegistryClient registryClient = Mockito.mock(ServiceRegistryClient.class);
+  private static ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
+  private static ServiceCenterInfo serviceCenterInfo = Mockito.mock(ServiceCenterInfo.class);
+
+  @BeforeClass
+  public static void init() {
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", serviceRegistry);
+    Mockito.when(serviceRegistry.getServiceRegistryClient()).thenReturn(registryClient);
+    Mockito.when(registryClient.getServiceCenterInfo()).thenReturn(serviceCenterInfo);
+    Mockito.when(serviceCenterInfo.getVersion()).thenReturn("1.0.0");
+  }
+
+  @AfterClass
+  public static void teardown() {
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", null);
+  }
 
   @Test
   public void testFrameworkVersions() {
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterConfig.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterConfig.java
new file mode 100644
index 0000000..101385a
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterConfig.java
@@ -0,0 +1,91 @@
+/*
+ * 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.serviceregistry.api.registry;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestServiceCenterConfig {
+  ServiceCenterConfig config = new ServiceCenterConfig();
+
+  @Test
+  public void testDefaultValues() {
+    Assert.assertEquals(0, config.getMaxHeaderBytes());
+    Assert.assertEquals(0, config.getMaxBodyBytes());
+    Assert.assertNull(config.getReadHeaderTimeout());
+    Assert.assertNull(config.getReadTimeout());
+    Assert.assertNull(config.getIdleTimeout());
+    Assert.assertNull(config.getWriteTimeout());
+    Assert.assertNull(config.getLimitTTLUnit());
+    Assert.assertEquals(0, config.getLimitConnections());
+    Assert.assertNull(config.getLimitIPLookup());
+    Assert.assertNull(config.getSslEnabled());
+    Assert.assertNull(config.getSslMinVersion());
+    Assert.assertNull(config.getSslVerifyPeer());
+    Assert.assertNull(config.getSslCiphers());
+    Assert.assertNull(config.getAutoSyncInterval());
+    Assert.assertEquals(0, config.getCompactIndexDelta());
+    Assert.assertNull(config.getCompactInterval());
+    Assert.assertEquals(0, config.getLogRotateSize());
+    Assert.assertEquals(0, config.getLogBackupCount());
+  }
+
+  @Test
+  public void testInitializedValues() {
+    initMicroservice(); //Initialize the Object
+    Assert.assertEquals(10, config.getMaxHeaderBytes());
+    Assert.assertEquals(10, config.getMaxBodyBytes());
+    Assert.assertEquals("60s", config.getReadHeaderTimeout());
+    Assert.assertEquals("60s", config.getReadTimeout());
+    Assert.assertEquals("60s", config.getIdleTimeout());
+    Assert.assertEquals("60s", config.getWriteTimeout());
+    Assert.assertEquals("s", config.getLimitTTLUnit());
+    Assert.assertEquals(0, config.getLimitConnections());
+    Assert.assertEquals("xxx", config.getLimitIPLookup());
+    Assert.assertEquals("false", config.getSslEnabled());
+    Assert.assertEquals("xxx", config.getSslMinVersion());
+    Assert.assertEquals("true", config.getSslVerifyPeer());
+    Assert.assertEquals("xxx", config.getSslCiphers());
+    Assert.assertEquals("30s", config.getAutoSyncInterval());
+    Assert.assertEquals(100, config.getCompactIndexDelta());
+    Assert.assertEquals("100", config.getCompactInterval());
+    Assert.assertEquals(20, config.getLogRotateSize());
+    Assert.assertEquals(50, config.getLogBackupCount());
+  }
+
+  private void initMicroservice() {
+    config.setMaxHeaderBytes(10);
+    config.setMaxBodyBytes(10);
+    config.setReadHeaderTimeout("60s");
+    config.setReadTimeout("60s");
+    config.setIdleTimeout("60s");
+    config.setWriteTimeout("60s");
+    config.setLimitTTLUnit("s");
+    config.setLimitConnections(0);
+    config.setLimitIPLookup("xxx");
+    config.setSslEnabled("false");
+    config.setSslMinVersion("xxx");
+    config.setSslVerifyPeer("true");
+    config.setSslCiphers("xxx");
+    config.setAutoSyncInterval("30s");
+    config.setCompactIndexDelta(100);
+    config.setCompactInterval("100");
+    config.setLogRotateSize(20);
+    config.setLogBackupCount(50);
+  }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterInfo.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterInfo.java
new file mode 100644
index 0000000..50c4bb0
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestServiceCenterInfo.java
@@ -0,0 +1,53 @@
+/*
+ * 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.serviceregistry.api.registry;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestServiceCenterInfo {
+  ServiceCenterInfo info = new ServiceCenterInfo();
+  ServiceCenterConfig config = new ServiceCenterConfig();
+
+  @Test
+  public void testDefaultValues() {
+    Assert.assertNull(info.getVersion());
+    Assert.assertNull(info.getBuildTag());
+    Assert.assertNull(info.getRunMode());
+    Assert.assertNull(info.getApiVersion());
+    Assert.assertNull(info.getConfig());
+  }
+
+  @Test
+  public void testInitializedValues() {
+    initMicroservice(); //Initialize the Object
+    Assert.assertEquals("x.x.x", info.getVersion());
+    Assert.assertEquals("xxx", info.getBuildTag());
+    Assert.assertEquals("dev", info.getRunMode());
+    Assert.assertEquals("x.x.x", info.getApiVersion());
+    Assert.assertNotNull(info.getConfig());
+  }
+
+  private void initMicroservice() {
+    info.setVersion("x.x.x");
+    info.setBuildTag("xxx");
+    info.setRunMode("dev");
+    info.setApiVersion("x.x.x");
+    info.setConfig(config);
+  }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
index b4eee38..c841f25 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
 import org.hamcrest.Matchers;
@@ -172,4 +173,10 @@ public class LocalServiceRegistryClientImplTest {
     String instanceId = registryClient.registerMicroserviceInstance(instance);
     Assert.assertNotNull(registryClient.findServiceInstance(microservice.getServiceId(), instanceId));
   }
+
+  @Test
+  public void testGetServiceCenterInfo() {
+    ServiceCenterInfo serviceCenterInfo = registryClient.getServiceCenterInfo();
+    Assert.assertEquals("1.0.0", serviceCenterInfo.getVersion());
+  }
 }
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
index 56af6d2..23bdf94 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
@@ -32,6 +32,8 @@ import org.apache.log4j.spi.LoggingEvent;
 import org.apache.servicecomb.foundation.common.net.IpPort;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterConfig;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse;
 import org.apache.servicecomb.serviceregistry.client.ClientException;
 import org.apache.servicecomb.serviceregistry.client.IpPortManager;
@@ -321,4 +323,48 @@ public class TestServiceRegistryClientImpl {
 
     Assert.assertNull(oClient.findServiceInstance(null, "appId", "serviceName", "1.0.0+"));
   }
+
+  @Test
+  public void testGetServiceCenterInfoSuccess() {
+    ServiceCenterInfo serviceCenterInfo = new ServiceCenterInfo();
+    serviceCenterInfo.setVersion("x.x.x");
+    serviceCenterInfo.setBuildTag("xxx");
+    serviceCenterInfo.setRunMode("dev");
+    serviceCenterInfo.setApiVersion("x.x.x");
+    serviceCenterInfo.setConfig(new ServiceCenterConfig());
+
+    new MockUp<RestUtils>() {
+      @Mock
+      void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
+        Holder<ServiceCenterInfo> holder = Deencapsulation.getField(responseHandler, "arg$4");
+        holder.value = serviceCenterInfo;
+      }
+    };
+    ServiceCenterInfo info = oClient.getServiceCenterInfo();
+    Assert.assertEquals("x.x.x", info.getVersion());
+    Assert.assertEquals("xxx", info.getBuildTag());
+    Assert.assertEquals("dev", info.getRunMode());
+    Assert.assertNotNull(info.getConfig());
+  }
+
+  @Test
+  public void testGetServiceCenterInfoException() {
+    InterruptedException e = new InterruptedException();
+    new MockUp<CountDownLatch>() {
+      @Mock
+      public void await() throws InterruptedException {
+        throw e;
+      }
+    };
+
+    new RegisterSchemaTester() {
+      void doRun(java.util.List<LoggingEvent> events) {
+        oClient.getServiceCenterInfo();
+        Assert.assertEquals(
+            "query servicecenter version info failed.",
+            events.get(0).getMessage());
+        Assert.assertEquals(e, events.get(0).getThrowableInformation().getThrowable());
+      }
+    }.run();
+  }
 }
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestLocalServiceRegistry.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestLocalServiceRegistry.java
index b422d59..cbdcc73 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestLocalServiceRegistry.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestLocalServiceRegistry.java
@@ -19,12 +19,37 @@ package org.apache.servicecomb.serviceregistry.registry;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
+import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mockito.Mockito;
+
+import mockit.Deencapsulation;
 
 public class TestLocalServiceRegistry {
+  private static ServiceRegistryClient registryClient = Mockito.mock(ServiceRegistryClient.class);
+  private static ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
+  private static ServiceCenterInfo serviceCenterInfo = Mockito.mock(ServiceCenterInfo.class);
+
+  @BeforeClass
+  public static void init() {
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", serviceRegistry);
+    Mockito.when(serviceRegistry.getServiceRegistryClient()).thenReturn(registryClient);
+    Mockito.when(registryClient.getServiceCenterInfo()).thenReturn(serviceCenterInfo);
+    Mockito.when(serviceCenterInfo.getVersion()).thenReturn("1.0.0");
+  }
+
+  @AfterClass
+  public static void teardown() {
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", null);
+  }
+
   @Test
   public void testLifeCycle() {
     ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
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 d46ef93..8b21c34 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
@@ -25,6 +25,7 @@ import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.foundation.common.net.IpPort;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.ServiceRegistry;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl;
 import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
@@ -33,10 +34,12 @@ import org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition;
 import org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent;
 import org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent;
 import org.hamcrest.Matchers;
+import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
 
 import com.google.common.eventbus.EventBus;
 
@@ -48,6 +51,10 @@ import mockit.MockUp;
 import mockit.Mocked;
 
 public class TestRemoteServiceRegistry {
+  private static ServiceRegistryClient registryClient = Mockito.mock(ServiceRegistryClient.class);
+  private static ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
+  private static ServiceCenterInfo serviceCenterInfo = Mockito.mock(ServiceCenterInfo.class);
+
   class TestingRemoteServiceRegistry extends RemoteServiceRegistry {
     public TestingRemoteServiceRegistry(EventBus eventBus, ServiceRegistryConfig serviceRegistryConfig,
         MicroserviceDefinition microserviceDefinition) {
@@ -94,6 +101,10 @@ public class TestRemoteServiceRegistry {
     EventBus bus = new EventBus();
     RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
     remote.init();
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", serviceRegistry);
+    Mockito.when(serviceRegistry.getServiceRegistryClient()).thenReturn(registryClient);
+    Mockito.when(registryClient.getServiceCenterInfo()).thenReturn(serviceCenterInfo);
+    Mockito.when(serviceCenterInfo.getVersion()).thenReturn("1.0.0");
     remote.run();
     Assert.assertTrue(2 <= remote.getTaskPool().getTaskCount()); // includes complete tasks
 
@@ -134,4 +145,9 @@ public class TestRemoteServiceRegistry {
     Deencapsulation.setField(remote, "taskPool", taskPool);
     bus.post(event);
   }
+
+  @AfterClass
+  public static void teardown() {
+    Deencapsulation.setField(RegistryUtils.class, "serviceRegistry", null);
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
liubao@apache.org.