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

[GitHub] liubao68 closed pull request #588: [SCB-394] framework version support SC which earlier than 1.0.0

liubao68 closed pull request #588: [SCB-394] framework version support SC which earlier than 1.0.0
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/588
 
 
   

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/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 c9f7e84c1..8166bec46 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 @@ private 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";
@@ -150,4 +158,6 @@ private Const() {
   public static final String URL_PREFIX = "urlPrefix";
 
   public static final String INSTANCE_PUBKEY_PRO = "publickey";
+
+  public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
 }
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 5c0c9735c..01423ab8d 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;
@@ -67,13 +65,6 @@ private Microservice createMicroserviceFromDefinition(Configuration configuratio
           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 000000000..26049e149
--- /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 000000000..65dca2b07
--- /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 663cde3c0..2cb228f9b 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 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 MicroserviceInstance findServiceInstance(String serviceId, String instanc
     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 6167824a0..2cf20b93e 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 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 @@ MicroserviceInstances findServiceInstances(String consumerId, String appId, Stri
    * @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 d48d0bc07..ab7f59751 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.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 MicroserviceInstance findServiceInstance(String serviceId, String instanc
       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 9b67ed54f..e30bf6fbd 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,9 +28,12 @@
 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;
+import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
 import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
 import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManagerNew;
 import org.apache.servicecomb.serviceregistry.client.IpPortManager;
@@ -40,6 +46,8 @@
 import org.apache.servicecomb.serviceregistry.task.MicroserviceServiceCenterTask;
 import org.apache.servicecomb.serviceregistry.task.ServiceCenterTask;
 import org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent;
+import org.apache.servicecomb.serviceregistry.version.Version;
+import org.apache.servicecomb.serviceregistry.version.VersionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,6 +78,8 @@
 
   protected ServiceCenterTask serviceCenterTask;
 
+  protected ServiceCenterInfo serviceCenterInfo;
+
   public AbstractServiceRegistry(EventBus eventBus, ServiceRegistryConfig serviceRegistryConfig,
       MicroserviceDefinition microserviceDefinition) {
     this.eventBus = eventBus;
@@ -93,6 +103,8 @@ public void init() {
       srClient = createServiceRegistryClient();
     }
 
+    serviceCenterInfo = srClient.getServiceCenterInfo();
+
     createServiceCenterTask();
 
     eventBus.register(this);
@@ -162,11 +174,39 @@ public InstanceCacheManager getInstanceCacheManager() {
   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);
+
+    if (needSetFrameworkVersion()) {
+      framework.setVersion(FrameworkVersions.allVersions());
+    }
+    microservice.setFramework(framework);
+    microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
+  }
+
+  private boolean needSetFrameworkVersion() {
+    if (serviceCenterInfo == null) {
+      LOGGER.warn("Server startup when service center not started and cannot retrieve version info, assume latest.");
+      return true;
+    } else {
+      Version scVersion = VersionUtils.getOrCreate(serviceCenterInfo.getVersion());
+      Version frameworkVersion = VersionUtils.getOrCreate(Const.SERVICECENTER_FRAMEWORK_VERSION);
+
+      if (scVersion.compareTo(frameworkVersion) >= 0) {
+        return true;
+      } else {
+        return false;
+      }
+    }
+  }
+
   private void loadStaticConfiguration() {
     // TODO 如果yaml定义了paths规则属性,替换默认值,现需要DynamicPropertyFactory支持数组获取
     List<BasePath> paths = microservice.getPaths();
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 d02bd55fc..e0dde1a98 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
@@ -21,7 +21,6 @@
 import org.junit.Test;
 
 public class TestFrameworkVersions {
-
   @Test
   public void testFrameworkVersions() {
     Assert.assertEquals("ServiceComb:null", FrameworkVersions.allVersions());
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 000000000..101385a4a
--- /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 000000000..50c4bb048
--- /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 b4eee3804..c841f259c 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 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 void testFindServiceInstance() {
     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 56af6d2bc..23bdf94fc 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.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 @@ IpPort getAvailableAddress() {
 
     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 b422d59f2..6332995e4 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
@@ -25,6 +25,7 @@
 import org.junit.Test;
 
 public class TestLocalServiceRegistry {
+
   @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 d46ef932f..5e8e6e7ba 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
@@ -37,7 +37,6 @@
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-
 import com.google.common.eventbus.EventBus;
 
 import mockit.Deencapsulation;


 

----------------------------------------------------------------
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