liubao68 closed pull request #617: [SCB-424] get configuration interface to add 
header:x-environment
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/617
 
 
   

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-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
index 02684913a..4407c1488 100644
--- 
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
+++ 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
@@ -100,6 +100,8 @@
 
   private String serviceName = CONFIG_CENTER_CONFIG.getServiceName();
 
+  private String environment = CONFIG_CENTER_CONFIG.getEnvironment();
+
   private MemberDiscovery memberDiscovery = new 
MemberDiscovery(CONFIG_CENTER_CONFIG.getServerUri());
 
   private ConfigCenterConfigurationSourceImpl.UpdateHandler updateHandler;
@@ -240,6 +242,7 @@ public void doWatch(String configCenter)
       if (ConfigCenterConfig.INSTANCE.getToken() != null) {
         headers.put("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
       }
+      headers.put("x-environment", environment);
 
       HttpClientWithContext vertxHttpClient = 
clientMgr.findThreadBindClientPool();
       vertxHttpClient.runOnContext(client -> {
@@ -341,6 +344,7 @@ public void refreshConfig(String configcenter) {
         if (ConfigCenterConfig.INSTANCE.getToken() != null) {
           headers.put("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
         }
+        headers.put("x-environment", environment);
         request.headers().addAll(headers);
         authHeaderProviders.forEach(provider -> request.headers()
             
.addAll(provider.getSignAuthHeaders(createSignRequest(request.method().toString(),
diff --git 
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
index 70d4971a0..c38f252ce 100644
--- 
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
+++ 
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterConfig.java
@@ -17,6 +17,9 @@
 
 package org.apache.servicecomb.config.client;
 
+import static 
org.apache.servicecomb.foundation.common.base.ServiceCombConstants.DEFAULT_SERVICECOMB_ENV;
+import static 
org.apache.servicecomb.foundation.common.base.ServiceCombConstants.SERVICECOMB_ENV;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -184,4 +187,8 @@ public boolean getAutoDiscoveryEnabled() {
   public int getConnectionTimeout() {
     return finalConfig.getInt("cse.config.client.timeout.connection", 
DEFAULT_TIMEOUT_IN_MS);
   }
+
+  public String getEnvironment() {
+    return finalConfig.getString(SERVICECOMB_ENV, DEFAULT_SERVICECOMB_ENV);
+  }
 }
diff --git 
a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
 
b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
index 74237d19c..1624f5af8 100644
--- 
a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
+++ 
b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/client/TestConfigCenterConfig.java
@@ -36,4 +36,12 @@ public void getServerUri() {
     Assert.assertEquals("https://172.16.8.7:30103";, servers.get(0));
     Assert.assertEquals("https://172.16.8.7:30103";, servers.get(1));
   }
+
+  @Test
+  public void getEnvironment() {
+    Assert.assertEquals("testing", 
ConfigCenterConfig.INSTANCE.getEnvironment());
+    System.setProperty("SERVICECOMB_ENV", "development");
+    
ConfigCenterConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
+    Assert.assertEquals("development", 
ConfigCenterConfig.INSTANCE.getEnvironment());
+  }
 }
diff --git a/dynamic-config/config-cc/src/test/resources/microservice.yaml 
b/dynamic-config/config-cc/src/test/resources/microservice.yaml
index 76360cdbe..445cfa6ea 100644
--- a/dynamic-config/config-cc/src/test/resources/microservice.yaml
+++ b/dynamic-config/config-cc/src/test/resources/microservice.yaml
@@ -55,3 +55,4 @@ cse:
       autodiscovery: true
 service_description:
   name: testDemo
+  environment: testing


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to