You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/07/18 09:53:20 UTC

[GitHub] heyile closed pull request #818: [SCB-755] 755 Duplicate copy cse config to Servicecomb config

heyile closed pull request #818: [SCB-755] 755 Duplicate copy cse config to Servicecomb config
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/818
 
 
   

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/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 21f22426d..3d8ffe537 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
@@ -53,6 +53,7 @@
   private static final Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
 
   private static final String MICROSERVICE_CONFIG_LOADER_KEY = "cse-microservice-config-loader";
+  private static String DEFAULT_SOURCE_NAME = "CSE-DEFAULT-NAME";
 
   private static Map<String, Object> localConfig = new HashMap<>();
 
@@ -161,23 +162,29 @@ public static AbstractConfiguration convertEnvVariable(AbstractConfiguration sou
     return source;
   }
 
-  //inject a copy of servicecomb.xxx for cse.xxx
+  //主要是为了兼容老的版本
   private static void duplicateCseConfigToServicecomb(AbstractConfiguration source) {
-    Iterator<String> keys = source.getKeys();
-    while (keys.hasNext()) {
-      String key = keys.next();
-      if (!key.startsWith(CONFIG_CSE_PREFIX)) {
-        continue;
-      }
+    duplicateCseConfigToServicecombWithSourceName(source, DEFAULT_SOURCE_NAME);
+  }
+
 
-      String servicecombKey = CONFIG_SERVICECOMB_PREFIX + key.substring(key.indexOf(".") + 1);
-      if (!source.containsKey(servicecombKey)) {
-        source.addProperty(servicecombKey, source.getProperty(key));
-      } else {
-        LOGGER
-            .warn(
-                "Key {} with an ambiguous item {} exists, it's recommended to use only one of them.",
-                key, servicecombKey);
+  //inject a copy of servicecomb.xxx for cse.xxx
+  private static void duplicateCseConfigToServicecombWithSourceName(AbstractConfiguration source,String sourceName) {
+    if (sourceName.equals(DEFAULT_SOURCE_NAME)) {
+      Iterator<String> keys = source.getKeys();
+      while (keys.hasNext()) {
+        String key = keys.next();
+        if (!key.startsWith(CONFIG_CSE_PREFIX)) {
+          continue;
+        }
+
+        String servicecombKey = CONFIG_SERVICECOMB_PREFIX + key.substring(key.indexOf(".") + 1);
+        if (!source.containsKey(servicecombKey)) {
+          source.addProperty(servicecombKey, source.getProperty(key));
+        } else {
+          LOGGER.warn("Key {} with an ambiguous item {} exists, it's recommended to use only one of them.",
+                  key, servicecombKey);
+        }
       }
     }
   }
@@ -185,7 +192,12 @@ private static void duplicateCseConfigToServicecomb(AbstractConfiguration source
   private static void duplicateCseConfigToServicecomb(ConcurrentCompositeConfiguration compositeConfiguration,
       AbstractConfiguration source,
       String sourceName) {
-    duplicateCseConfigToServicecomb(source);
+
+    if (sourceName.equals("configFromYamlFile")) {
+      duplicateCseConfigToServicecombWithSourceName(source, sourceName);
+    } else {
+      duplicateCseConfigToServicecomb(source);
+    }
 
     compositeConfiguration.addConfiguration(source, sourceName);
   }


 

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