WillemJiang closed pull request #569: SCB-210 remove extra useless config item
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/569
 
 
   

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/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
 
b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
index 4dc193186..0093c80c2 100644
--- 
a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
+++ 
b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
@@ -49,11 +49,22 @@
 
   private List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
 
+  private static final String APOLLO_CONFIG_URL_KEY = 
"apollo.config.serverUri";
+
   public ApolloConfigurationSourceImpl() {
   }
 
   private final UpdateHandler updateHandler = new UpdateHandler();
 
+  @Override
+  public boolean isValidSource(Configuration localConfiguration) {
+    if (localConfiguration.getProperty(APOLLO_CONFIG_URL_KEY) == null){
+      LOGGER.warn("Apollo configuration source is not configured!");
+      return false;
+    }
+    return true;
+  }
+
   @Override
   public void init(Configuration localConfiguration) {
     ApolloConfig.setConcurrentCompositeConfiguration(localConfiguration);
diff --git a/dynamic-config/config-apollo/src/test/resources/microservice.yaml 
b/dynamic-config/config-apollo/src/test/resources/microservice.yaml
index f050218a5..6c8b496fa 100644
--- a/dynamic-config/config-apollo/src/test/resources/microservice.yaml
+++ b/dynamic-config/config-apollo/src/test/resources/microservice.yaml
@@ -16,7 +16,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-APPLICATION_ID: pojotest
+APPLICATION_ID: apollotest
 service_description:
   name: apollo-test
   version: 1.0.1
@@ -33,9 +33,6 @@ apollo:
     firstRefreshInterval: 0
 
 cse:
-  config:
-    client:
-      serverUri: http://127.0.0.1:8070
   service:
     registry:
       address: http://127.0.0.1:30100
diff --git 
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
index 74a7d90a2..d4392994f 100644
--- 
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
+++ 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigCenterConfigurationSourceImpl.java
@@ -49,9 +49,20 @@
 
   private UpdateHandler updateHandler = new UpdateHandler();
 
+  private static final String CONFIG_CENTER_URL_KEY = 
"cse.config.client.serverUri";
+
   public ConfigCenterConfigurationSourceImpl() {
   }
 
+  @Override
+  public boolean isValidSource(Configuration localConfiguration) {
+    if (localConfiguration.getProperty(CONFIG_CENTER_URL_KEY) == null) {
+      LOGGER.warn("Config Center configuration source is not configured!");
+      return false;
+    }
+    return true;
+  }
+
   private void init() {
     ConfigCenterClient configCenterClient = new 
ConfigCenterClient(updateHandler);
     configCenterClient.connectServer();
diff --git 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index 28e285512..fbef8a9a1 100644
--- 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -50,8 +50,6 @@
 public final class ConfigUtil {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(ConfigUtil.class);
 
-  protected static final String configCenterUrlKey = 
"cse.config.client.serverUri";
-
   private static final String MICROSERVICE_CONFIG_LOADER_KEY = 
"cse-microservice-config-loader";
 
   private ConfigUtil() {
@@ -150,11 +148,6 @@ private static void 
duplicateServiceCombConfigToCse(ConcurrentCompositeConfigura
   }
 
   public static DynamicWatchedConfiguration 
createConfigFromConfigCenter(Configuration localConfiguration) {
-    if (localConfiguration.getProperty(configCenterUrlKey) == null) {
-      LOGGER.info("config center URL is missing, skip to load configuration 
from config center");
-      return null;
-    }
-
     ConfigCenterConfigurationSource configCenterConfigurationSource =
         
SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
     if (null == configCenterConfigurationSource) {
@@ -163,6 +156,11 @@ public static DynamicWatchedConfiguration 
createConfigFromConfigCenter(Configura
       return null;
     }
 
+    if (!configCenterConfigurationSource.isValidSource(localConfiguration)) {
+      LOGGER.info("Config Source serverUri is not correctly configured.");
+      return null;
+    }
+
     configCenterConfigurationSource.init(localConfiguration);
     return new DynamicWatchedConfiguration(configCenterConfigurationSource);
   }
diff --git 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
index 68a2d4970..5b9a817f7 100644
--- 
a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
+++ 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
@@ -22,5 +22,6 @@
 import com.netflix.config.WatchedConfigurationSource;
 
 public interface ConfigCenterConfigurationSource extends 
WatchedConfigurationSource {
+  boolean isValidSource(Configuration localConfiguration);
   void init(Configuration localConfiguration);
 }
diff --git 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
index 18bb2371b..5f08c8a89 100644
--- 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
+++ 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
@@ -39,6 +39,14 @@
     properties.put("servicecomb.abc.key", "xyz");
   }
 
+  @Override
+  public boolean isValidSource(Configuration localConfiguration) {
+    if (localConfiguration.getProperty("cse.config.client.serverUri") == null) 
{
+      return false;
+    }
+    return true;
+  }
+
   @Override
   public void init(Configuration localConfiguration) {
 
diff --git a/samples/config-apollo-sample/src/main/resources/microservice.yaml 
b/samples/config-apollo-sample/src/main/resources/microservice.yaml
index fe4b1f18a..47ef10974 100644
--- a/samples/config-apollo-sample/src/main/resources/microservice.yaml
+++ b/samples/config-apollo-sample/src/main/resources/microservice.yaml
@@ -16,7 +16,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-APPLICATION_ID: pojotest
+APPLICATION_ID: apollotest
 service_description:
   name: apollo-test
   version: 1.0.1
@@ -30,9 +30,6 @@ apollo:
     namespace: application
     token: #get token from Apollo web pages
 cse:
-  config:
-    client:
-      serverUri: http://127.0.0.1:8070
   service:
     registry:
       address: http://127.0.0.1:30100


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to