[ 
https://issues.apache.org/jira/browse/SCB-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16439165#comment-16439165
 ] 

ASF GitHub Bot commented on SCB-456:
------------------------------------

liubao68 closed pull request #632: [SCB-456]Provider a way to input 
configuration from a Map
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/632
 
 
   

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 fbef8a9a1..076caaf67 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
@@ -21,6 +21,7 @@
 import static 
org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER;
 import static 
org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_SERVICECOMB_PREFIX;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -52,9 +53,19 @@
 
   private static final String MICROSERVICE_CONFIG_LOADER_KEY = 
"cse-microservice-config-loader";
 
+  private static Map<String, Object> localConfig = new HashMap<>();
+
   private ConfigUtil() {
   }
 
+  public static void setConfigs(Map<String, Object> config) {
+    localConfig = config;
+  }
+
+  public static void addConfig(String key, Object value) {
+    localConfig.put(key, value);
+  }
+
   public static Object getProperty(String key) {
     Object config = DynamicPropertyFactory.getBackingConfigurationSource();
     return getProperty(config, key);
@@ -83,6 +94,11 @@ public static MicroserviceConfigLoader 
getMicroserviceConfigLoader(Configuration
   public static ConcurrentCompositeConfiguration createLocalConfig() {
     MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
     loader.loadAndSort();
+    if (localConfig.size() > 0) {
+      ConfigModel model = new ConfigModel();
+      model.setConfig(localConfig);
+      loader.getConfigModels().add(model);
+    }
 
     LOGGER.info("create local config:");
     for (ConfigModel configModel : loader.getConfigModels()) {
@@ -94,6 +110,8 @@ public static ConcurrentCompositeConfiguration 
createLocalConfig() {
     return config;
   }
 
+
+
   public static ConcurrentCompositeConfiguration 
createLocalConfig(List<ConfigModel> configModelList) {
     ConcurrentCompositeConfiguration config = new 
ConcurrentCompositeConfiguration();
 
diff --git 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
index 27fe3586d..a61555a0e 100644
--- 
a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
+++ 
b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
@@ -27,7 +27,9 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
+import com.netflix.config.*;
 import org.apache.commons.configuration.AbstractConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.servicecomb.config.archaius.sources.ConfigModel;
@@ -40,11 +42,6 @@
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicWatchedConfiguration;
-
 import mockit.Deencapsulation;
 import mockit.Expectations;
 import mockit.Mocked;
@@ -80,6 +77,20 @@ public static void tearDown() throws Exception {
     ArchaiusUtils.resetConfig();
   }
 
+  @Test
+  public void testAddConfig() {
+    Map config = new HashMap<String, Object>();
+    config.put("service_description.name", "service_name_test");
+    ConfigUtil.setConfigs(config);
+    ConfigUtil.addConfig("service_description.version", "1.0.2");
+    ConfigUtil.addConfig("cse.test.enabled", true);
+    ConfigUtil.addConfig("cse.test.num", 10);
+    AbstractConfiguration configuration = ConfigUtil.createDynamicConfig();
+    Assert.assertEquals(configuration.getString("service_description.name"), 
"service_name_test");
+    Assert.assertEquals(configuration.getBoolean("cse.test.enabled"), true);
+    Assert.assertEquals(configuration.getInt("cse.test.num"), 10);
+  }
+
   @Test
   public void testCreateConfigFromConfigCenterNoUrl(@Mocked Configuration 
localConfiguration) {
     AbstractConfiguration configFromConfigCenter = 
ConfigUtil.createConfigFromConfigCenter(localConfiguration);


 

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


> Provider a way to input configuration from a Map, instead of  
> micreservice.yaml
> -------------------------------------------------------------------------------
>
>                 Key: SCB-456
>                 URL: https://issues.apache.org/jira/browse/SCB-456
>             Project: Apache ServiceComb
>          Issue Type: Task
>            Reporter: Minzhi Yan
>            Assignee: Minzhi Yan
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to