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

dongzonglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7e64fa1  Orchestration support add new schema (#6754)
7e64fa1 is described below

commit 7e64fa1c81c43fd8449a6a86e801b6ce73f5820a
Author: Juan Pan(Trista) <[email protected]>
AuthorDate: Mon Aug 10 17:38:48 2020 +0800

    Orchestration support add new schema (#6754)
---
 .../orchestration/core/config/ConfigCenter.java    |  5 +++--
 .../listener/ConfigurationListenerManager.java     |  2 +-
 .../config/listener/SchemaChangedListener.java     | 24 +++++++++++++---------
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
index b01d51d..9c41eeb 100644
--- 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
+++ 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
@@ -103,9 +103,10 @@ public final class ConfigCenter {
     }
     
     private void persistDataSourceConfiguration(final String schemaName, final 
Map<String, DataSourceConfiguration> dataSourceConfigurations, final boolean 
isOverwrite) {
-        if (isOverwrite) {
-            persistDataSourceConfiguration(schemaName, 
dataSourceConfigurations);
+        if (dataSourceConfigurations.isEmpty() || !isOverwrite) {
+            return;
         }
+        persistDataSourceConfiguration(schemaName, dataSourceConfigurations);
     }
     
     private void persistDataSourceConfiguration(final String schemaName, final 
Map<String, DataSourceConfiguration> dataSourceConfigurations) {
diff --git 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/ConfigurationListenerManager.java
 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/ConfigurationListenerManager.java
index 3b2c49f..5a16956 100644
--- 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/ConfigurationListenerManager.java
+++ 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/ConfigurationListenerManager.java
@@ -49,7 +49,7 @@ public final class ConfigurationListenerManager {
      * Initialize all configuration changed listeners.
      */
     public void initListeners() {
-        schemaChangedListener.watch(ChangedType.UPDATED, ChangedType.DELETED);
+        schemaChangedListener.watch(ChangedType.UPDATED, ChangedType.DELETED, 
ChangedType.ADDED);
         propertiesChangedListener.watch(ChangedType.UPDATED);
         authenticationChangedListener.watch(ChangedType.UPDATED);
         metricsConfigurationChangedListener.watch(ChangedType.UPDATED);
diff --git 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
index bc96c29..461cc72 100644
--- 
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
+++ 
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/listener/SchemaChangedListener.java
@@ -75,6 +75,9 @@ public final class SchemaChangedListener extends 
PostOrchestrationRepositoryEven
         if (Strings.isNullOrEmpty(shardingSchemaName) || 
!isValidNodeChangedEvent(shardingSchemaName, event.getKey())) {
             return new IgnoredOrchestrationEvent();
         }
+        if (ChangedType.ADDED == event.getChangedType()) {
+            return createAddedEvent(shardingSchemaName);
+        }
         if (ChangedType.UPDATED == event.getChangedType()) {
             return createUpdatedEvent(shardingSchemaName, event);
         }
@@ -88,7 +91,7 @@ public final class SchemaChangedListener extends 
PostOrchestrationRepositoryEven
         Collection<String> persistShardingSchemaNames = 
configurationNode.splitSchemaName(shardingSchemaNames);
         Set<String> addedSchemaNames = SetUtils.difference(new 
HashSet<>(persistShardingSchemaNames), new HashSet<>(existedSchemaNames));
         if (!addedSchemaNames.isEmpty()) {
-            return 
createUpdatedEventForNewSchema(addedSchemaNames.iterator().next());
+            return createAddedEvent(addedSchemaNames.iterator().next());
         }
         Set<String> deletedSchemaNames = SetUtils.difference(new 
HashSet<>(existedSchemaNames), new HashSet<>(persistShardingSchemaNames));
         if (!deletedSchemaNames.isEmpty()) {
@@ -101,8 +104,17 @@ public final class SchemaChangedListener extends 
PostOrchestrationRepositoryEven
         return 
configurationNode.getDataSourcePath(shardingSchemaName).equals(nodeFullPath) || 
configurationNode.getRulePath(shardingSchemaName).equals(nodeFullPath);
     }
     
+    private OrchestrationEvent createAddedEvent(final String 
shardingSchemaName) {
+        existedSchemaNames.add(shardingSchemaName);
+        if (!isOwnCompleteConfigurations(shardingSchemaName)) {
+            return new SchemaAddedEvent(shardingSchemaName, 
Collections.emptyMap(), Collections.emptyList());
+        }
+        return new SchemaAddedEvent(shardingSchemaName, 
configurationService.loadDataSourceConfigurations(shardingSchemaName), 
createRuleConfigurations(shardingSchemaName));
+    }
+    
     private OrchestrationEvent createUpdatedEvent(final String 
shardingSchemaName, final DataChangedEvent event) {
-        return existedSchemaNames.contains(shardingSchemaName) ? 
createUpdatedEventForExistedSchema(event, shardingSchemaName) : 
createUpdatedEventForNewSchema(shardingSchemaName);
+        // TODO Consider remove judgement.
+        return existedSchemaNames.contains(shardingSchemaName) ? 
createUpdatedEventForExistedSchema(event, shardingSchemaName) : 
createAddedEvent(shardingSchemaName);
     }
     
     private OrchestrationEvent createUpdatedEventForExistedSchema(final 
DataChangedEvent event, final String shardingSchemaName) {
@@ -125,14 +137,6 @@ public final class SchemaChangedListener extends 
PostOrchestrationRepositoryEven
                 shardingSchemaName, new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(configurations.getRules()));
     }
     
-    private OrchestrationEvent createUpdatedEventForNewSchema(final String 
shardingSchemaName) {
-        existedSchemaNames.add(shardingSchemaName);
-        if (!isOwnCompleteConfigurations(shardingSchemaName)) {
-            return new SchemaAddedEvent(shardingSchemaName, 
Collections.emptyMap(), Collections.emptyList());
-        }
-        return new SchemaAddedEvent(shardingSchemaName, 
configurationService.loadDataSourceConfigurations(shardingSchemaName), 
createRuleConfigurations(shardingSchemaName));
-    }
-    
     private boolean isOwnCompleteConfigurations(final String 
shardingSchemaName) {
         return 
configurationService.hasDataSourceConfiguration(shardingSchemaName) && 
configurationService.hasRuleConfiguration(shardingSchemaName);
     }

Reply via email to