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

jianglongtao 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 9462a447262 Add BroadcastImportRuleConfigurationProvider (#30460)
9462a447262 is described below

commit 9462a44726244abd6f3830735fd474c70dca6997
Author: yx9o <[email protected]>
AuthorDate: Tue Mar 12 14:50:41 2024 +0800

    Add BroadcastImportRuleConfigurationProvider (#30460)
---
 .../BroadcastImportRuleConfigurationProvider.java  | 53 ++++++++++++++++++++++
 ...le.spi.database.ImportRuleConfigurationProvider | 18 ++++++++
 .../YamlDatabaseConfigurationImportExecutor.java   | 14 +-----
 3 files changed, 72 insertions(+), 13 deletions(-)

diff --git 
a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java
 
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java
new file mode 100644
index 00000000000..e11ab484b9f
--- /dev/null
+++ 
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.broadcast.distsql.handler.provider;
+
+import 
org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import 
org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
+
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+/**
+ * Broadcast import rule configuration provider.
+ */
+public final class BroadcastImportRuleConfigurationProvider implements 
ImportRuleConfigurationProvider {
+    
+    @Override
+    public void check(final ShardingSphereDatabase database, final 
RuleConfiguration ruleConfig) {
+    }
+    
+    @Override
+    public DatabaseRule build(final ShardingSphereDatabase database, final 
RuleConfiguration ruleConfig, final InstanceContext instanceContext) {
+        return new BroadcastRule((BroadcastRuleConfiguration) ruleConfig, 
database.getName(),
+                
database.getResourceMetaData().getStorageUnits().entrySet().stream()
+                        .collect(Collectors.toMap(Entry::getKey, entry -> 
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, 
LinkedHashMap::new)),
+                database.getRuleMetaData().getRules());
+    }
+    
+    @Override
+    public Class<? extends RuleConfiguration> getType() {
+        return BroadcastRuleConfiguration.class;
+    }
+}
diff --git 
a/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider
 
b/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider
new file mode 100644
index 00000000000..cd1fe6c6ae3
--- /dev/null
+++ 
b/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.broadcast.distsql.handler.provider.BroadcastImportRuleConfigurationProvider
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 509322df912..7720a2984dd 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -17,8 +17,6 @@
 
 package org.apache.shardingsphere.proxy.backend.util;
 
-import 
org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
-import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
 import 
org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider;
 import 
org.apache.shardingsphere.distsql.handler.exception.datasource.MissingRequiredDataSourcesException;
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.InvalidStorageUnitsException;
@@ -141,9 +139,7 @@ public final class YamlDatabaseConfigurationImportExecutor {
     }
     
     private void addRule(final Collection<RuleConfiguration> ruleConfigs, 
final RuleConfiguration ruleConfig, final ShardingSphereDatabase database) {
-        if (ruleConfig instanceof BroadcastRuleConfiguration) {
-            addBroadcastRuleConfiguration((BroadcastRuleConfiguration) 
ruleConfig, ruleConfigs, database);
-        } else if (ruleConfig instanceof SingleRuleConfiguration) {
+        if (ruleConfig instanceof SingleRuleConfiguration) {
             addSingleRuleConfiguration((SingleRuleConfiguration) ruleConfig, 
ruleConfigs, database);
         } else {
             ImportRuleConfigurationProvider provider = 
TypedSPILoader.getService(ImportRuleConfigurationProvider.class, 
ruleConfig.getClass());
@@ -164,14 +160,6 @@ public final class YamlDatabaseConfigurationImportExecutor 
{
         return result;
     }
     
-    private void addBroadcastRuleConfiguration(final 
BroadcastRuleConfiguration ruleConfig, final Collection<RuleConfiguration> 
ruleConfigs, final ShardingSphereDatabase database) {
-        ruleConfigs.add(ruleConfig);
-        database.getRuleMetaData().getRules().add(new 
BroadcastRule(ruleConfig, database.getName(),
-                
database.getResourceMetaData().getStorageUnits().entrySet().stream()
-                        .collect(Collectors.toMap(Entry::getKey, entry -> 
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, 
LinkedHashMap::new)),
-                database.getRuleMetaData().getRules()));
-    }
-    
     private void addSingleRuleConfiguration(final SingleRuleConfiguration 
ruleConfig, final Collection<RuleConfiguration> ruleConfigs, final 
ShardingSphereDatabase database) {
         ruleConfigs.add(ruleConfig);
         database.getRuleMetaData().getRules().add(

Reply via email to