This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit c1ea3b2b78e786a5c6fcd3ec7a4a5f19dba87aab
Author: liubao <[email protected]>
AuthorDate: Wed Jan 6 16:38:37 2021 +0800

    [SCB-2116]add dynamic change support
---
 .../pom.xml                                        |  5 +-
 .../src/main/resources/application.yml             |  8 +++-
 .../org/apache/servicecomb/config/ConfigUtil.java  |  4 ++
 .../config}/event/ConfigurationChangedEvent.java   | 16 +++----
 .../event/ConfigurationChangedEvent.java           |  8 ++--
 .../governance/GovernancePropertiesTest.java       |  8 ++--
 .../ServiceCombConfigurationEventAdapter.java      | 54 ++++++++++++++++++++++
 7 files changed, 85 insertions(+), 18 deletions(-)

diff --git 
a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
 
b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
index 0f154b1..f82b9b4 100644
--- 
a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
+++ 
b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
@@ -56,7 +56,10 @@
       <groupId>org.apache.servicecomb.demo</groupId>
       <artifactId>demo-schema</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>config-cc</artifactId>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
diff --git 
a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
 
b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
index 3d8453f..87df014 100644
--- 
a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
+++ 
b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
@@ -27,7 +27,13 @@ service_description:
 servicecomb:
   rest:
     address: 0.0.0.0:8082
-
+  config:
+    client:
+      # for testing dynamic configuration
+      # serverUri: http://127.0.0.1:30113
+      refreshMode: 0
+      # refresh_interval: 5000
+      # refreshPort: 30114
   handler:
     chain:
       Consumer:
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 69cdd86..7b76fc4 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
@@ -44,8 +44,10 @@ import 
org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingSchedul
 import org.apache.servicecomb.config.archaius.sources.ConfigModel;
 import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
 import 
org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource;
+import org.apache.servicecomb.config.event.ConfigurationChangedEvent;
 import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
 import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSourceLoader;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -309,6 +311,8 @@ public final class ConfigUtil {
           }
         }
       }
+
+      EventManager.post(new ConfigurationChangedEvent(watchedUpdateResult));
     }
   }
 
diff --git 
a/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/ConfigurationChangedEvent.java
similarity index 71%
copy from 
governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
copy to 
foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/ConfigurationChangedEvent.java
index 1436540..e7e8584 100644
--- 
a/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
+++ 
b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/ConfigurationChangedEvent.java
@@ -15,18 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.governance.event;
+package org.apache.servicecomb.config.event;
 
-import java.util.List;
+import com.netflix.config.WatchedUpdateResult;
 
 public class ConfigurationChangedEvent {
-  private List<String> changedConfigurations;
+  private final WatchedUpdateResult event;
 
-  public ConfigurationChangedEvent(List<String> changedConfigurations) {
-    this.changedConfigurations = changedConfigurations;
+  public ConfigurationChangedEvent(WatchedUpdateResult event) {
+    this.event = event;
   }
 
-  public List<String> getChangedConfigurations() {
-    return changedConfigurations;
+  public WatchedUpdateResult getEvent() {
+    return this.event;
   }
-}
\ No newline at end of file
+}
diff --git 
a/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
 
b/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
index 1436540..b7efbab 100644
--- 
a/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
+++ 
b/governance/src/main/java/org/apache/servicecomb/governance/event/ConfigurationChangedEvent.java
@@ -17,16 +17,16 @@
 
 package org.apache.servicecomb.governance.event;
 
-import java.util.List;
+import java.util.Set;
 
 public class ConfigurationChangedEvent {
-  private List<String> changedConfigurations;
+  private Set<String> changedConfigurations;
 
-  public ConfigurationChangedEvent(List<String> changedConfigurations) {
+  public ConfigurationChangedEvent(Set<String> changedConfigurations) {
     this.changedConfigurations = changedConfigurations;
   }
 
-  public List<String> getChangedConfigurations() {
+  public Set<String> getChangedConfigurations() {
     return changedConfigurations;
   }
 }
\ No newline at end of file
diff --git 
a/governance/src/test/java/org/apache/servicecomb/governance/GovernancePropertiesTest.java
 
b/governance/src/test/java/org/apache/servicecomb/governance/GovernancePropertiesTest.java
index 971a09d..fd0569c 100644
--- 
a/governance/src/test/java/org/apache/servicecomb/governance/GovernancePropertiesTest.java
+++ 
b/governance/src/test/java/org/apache/servicecomb/governance/GovernancePropertiesTest.java
@@ -17,8 +17,8 @@
 
 package org.apache.servicecomb.governance;
 
-import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -104,7 +104,7 @@ public class GovernancePropertiesTest {
   public void tearDown() {
     Set<String> keys = dynamicValues.keySet();
     keys.forEach(k -> dynamicValues.put(k, null));
-    EventManager.post(new ConfigurationChangedEvent(new 
ArrayList<>(dynamicValues.keySet())));
+    EventManager.post(new ConfigurationChangedEvent(new 
HashSet<>(dynamicValues.keySet())));
   }
 
   @Test
@@ -135,7 +135,7 @@ public class GovernancePropertiesTest {
         + "      exact: \"/hello2\"\n"
         + "    name: match0");
 
-    EventManager.post(new ConfigurationChangedEvent(new 
ArrayList<>(dynamicValues.keySet())));
+    EventManager.post(new ConfigurationChangedEvent(new 
HashSet<>(dynamicValues.keySet())));
 
     Map<String, TrafficMarker> markers = matchProperties.getParsedEntity();
     Assert.assertEquals(5, markers.size());
@@ -167,7 +167,7 @@ public class GovernancePropertiesTest {
         + "maxConcurrentCalls: 3\n"
         + "maxWaitDuration: 3000");
 
-    EventManager.post(new ConfigurationChangedEvent(new 
ArrayList<>(dynamicValues.keySet())));
+    EventManager.post(new ConfigurationChangedEvent(new 
HashSet<>(dynamicValues.keySet())));
 
     Map<String, BulkheadPolicy> policies = 
bulkheadProperties.getParsedEntity();
     Assert.assertEquals(2, policies.size());
diff --git 
a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ServiceCombConfigurationEventAdapter.java
 
b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ServiceCombConfigurationEventAdapter.java
new file mode 100644
index 0000000..3a8b375
--- /dev/null
+++ 
b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ServiceCombConfigurationEventAdapter.java
@@ -0,0 +1,54 @@
+/*
+ * 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.handler.governance;
+
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.servicecomb.config.event.ConfigurationChangedEvent;
+import org.apache.servicecomb.foundation.common.event.EventManager;
+import org.springframework.stereotype.Component;
+
+import com.google.common.eventbus.Subscribe;
+
+@Component
+public class ServiceCombConfigurationEventAdapter {
+  public ServiceCombConfigurationEventAdapter() {
+    EventManager.register(this);
+  }
+
+  @Subscribe
+  public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+    Set<String> changedKeys = new HashSet<>();
+    addMap(changedKeys, event.getEvent().getAdded());
+    addMap(changedKeys, event.getEvent().getDeleted());
+    addMap(changedKeys, event.getEvent().getChanged());
+    addMap(changedKeys, event.getEvent().getComplete());
+    org.apache.servicecomb.governance.event.ConfigurationChangedEvent newEvent 
=
+        new 
org.apache.servicecomb.governance.event.ConfigurationChangedEvent(changedKeys);
+    org.apache.servicecomb.governance.event.EventManager.post(newEvent);
+  }
+
+  private void addMap(Set<String> keys, Map<String, Object> changed) {
+    if (changed != null) {
+      keys.addAll(changed.keySet());
+    }
+  }
+}

Reply via email to