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 a8a63eed6ae Add ShadowImportRuleConfigurationProvider (#30427)
a8a63eed6ae is described below
commit a8a63eed6aedc043563fda5fbcca5f1b4ce8dc4e
Author: yx9o <[email protected]>
AuthorDate: Fri Mar 8 15:10:59 2024 +0800
Add ShadowImportRuleConfigurationProvider (#30427)
---
.../ShadowImportRuleConfigurationProvider.java | 39 ++++++++++++++--------
...le.spi.database.ImportRuleConfigurationProvider | 18 ++++++++++
.../YamlDatabaseConfigurationImportExecutor.java | 19 ++---------
3 files changed, 45 insertions(+), 31 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java
similarity index 76%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
rename to
features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java
index ece5ed37318..28104c8967f 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java
@@ -15,16 +15,21 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
+package org.apache.shardingsphere.shadow.distsql.handler.provider;
+import
org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
@@ -33,24 +38,25 @@ import java.util.Map.Entry;
import java.util.stream.Collectors;
/**
- * Shadow rule configuration import checker.
+ * Shadow import rule configuration provider.
*/
-public final class ShadowRuleConfigurationImportChecker {
+public final class ShadowImportRuleConfigurationProvider implements
ImportRuleConfigurationProvider {
- /**
- * Check shadow rule configuration.
- *
- * @param database database
- * @param currentRuleConfig current rule configuration
- */
- public void check(final ShardingSphereDatabase database, final
ShadowRuleConfiguration currentRuleConfig) {
- if (null == database || null == currentRuleConfig) {
+ @Override
+ public void check(final ShardingSphereDatabase database, final
RuleConfiguration ruleConfig) {
+ if (null == database || null == ruleConfig) {
return;
}
+ ShadowRuleConfiguration shadowRuleConfig = (ShadowRuleConfiguration)
ruleConfig;
String databaseName = database.getName();
- checkDataSources(databaseName, database, currentRuleConfig);
- checkTables(currentRuleConfig, databaseName);
- checkShadowAlgorithms(currentRuleConfig);
+ checkDataSources(databaseName, database, shadowRuleConfig);
+ checkTables(shadowRuleConfig, databaseName);
+ checkShadowAlgorithms(shadowRuleConfig);
+ }
+
+ @Override
+ public DatabaseRule build(final ShardingSphereDatabase database, final
RuleConfiguration ruleConfig, final InstanceContext instanceContext) {
+ return new ShadowRule((ShadowRuleConfiguration) ruleConfig);
}
private void checkDataSources(final String databaseName, final
ShardingSphereDatabase database, final ShadowRuleConfiguration
currentRuleConfig) {
@@ -92,4 +98,9 @@ public final class ShadowRuleConfigurationImportChecker {
private void checkShadowAlgorithms(final ShadowRuleConfiguration
currentRuleConfig) {
currentRuleConfig.getShadowAlgorithms().values().forEach(each ->
TypedSPILoader.checkService(ShadowAlgorithm.class, each.getType(),
each.getProps()));
}
+
+ @Override
+ public Class<? extends RuleConfiguration> getType() {
+ return ShadowRuleConfiguration.class;
+ }
}
diff --git
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.update.ral.rule.spi.database.ImportRuleConfigurationProvider
b/features/shadow/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..0347c538e71
--- /dev/null
+++
b/features/shadow/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.shadow.distsql.handler.provider.ShadowImportRuleConfigurationProvider
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 a662289c03a..dc3363f5026 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
@@ -33,7 +33,6 @@ import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePo
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -52,9 +51,6 @@ import
org.apache.shardingsphere.proxy.backend.config.yaml.swapper.YamlProxyData
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.exception.MissingDatabaseNameException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker.MaskRuleConfigurationImportChecker;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker.ShadowRuleConfigurationImportChecker;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.rule.SingleRule;
@@ -74,8 +70,6 @@ import java.util.stream.Collectors;
*/
public final class YamlDatabaseConfigurationImportExecutor {
- private final ShadowRuleConfigurationImportChecker
shadowRuleConfigImportChecker = new ShadowRuleConfigurationImportChecker();
-
private final MaskRuleConfigurationImportChecker
maskRuleConfigImportChecker = new MaskRuleConfigurationImportChecker();
private final YamlProxyDataSourceConfigurationSwapper
dataSourceConfigSwapper = new YamlProxyDataSourceConfigurationSwapper();
@@ -152,10 +146,7 @@ public final class YamlDatabaseConfigurationImportExecutor
{
}
private void addRule(final Collection<RuleConfiguration> ruleConfigs,
final RuleConfiguration ruleConfig, final ShardingSphereDatabase database) {
- InstanceContext instanceContext =
ProxyContext.getInstance().getContextManager().getInstanceContext();
- if (ruleConfig instanceof ShadowRuleConfiguration) {
- addShadowRuleConfiguration((ShadowRuleConfiguration) ruleConfig,
ruleConfigs, database);
- } else if (ruleConfig instanceof MaskRuleConfiguration) {
+ if (ruleConfig instanceof MaskRuleConfiguration) {
addMaskRuleConfiguration((MaskRuleConfiguration) ruleConfig,
ruleConfigs, database);
} else if (ruleConfig instanceof BroadcastRuleConfiguration) {
addBroadcastRuleConfiguration((BroadcastRuleConfiguration)
ruleConfig, ruleConfigs, database);
@@ -165,7 +156,7 @@ public final class YamlDatabaseConfigurationImportExecutor {
ImportRuleConfigurationProvider provider =
TypedSPILoader.getService(ImportRuleConfigurationProvider.class,
ruleConfig.getClass());
provider.check(database, ruleConfig);
ruleConfigs.add(ruleConfig);
- database.getRuleMetaData().getRules().add(provider.build(database,
ruleConfig, instanceContext));
+ database.getRuleMetaData().getRules().add(provider.build(database,
ruleConfig,
ProxyContext.getInstance().getContextManager().getInstanceContext()));
}
}
@@ -180,12 +171,6 @@ public final class YamlDatabaseConfigurationImportExecutor
{
return result;
}
- private void addShadowRuleConfiguration(final ShadowRuleConfiguration
shadowRuleConfig, final Collection<RuleConfiguration> allRuleConfigs, final
ShardingSphereDatabase database) {
- shadowRuleConfigImportChecker.check(database, shadowRuleConfig);
- allRuleConfigs.add(shadowRuleConfig);
- database.getRuleMetaData().getRules().add(new
ShadowRule(shadowRuleConfig));
- }
-
private void addMaskRuleConfiguration(final MaskRuleConfiguration
ruleConfig, final Collection<RuleConfiguration> ruleConfigs, final
ShardingSphereDatabase database) {
maskRuleConfigImportChecker.check(database, ruleConfig);
ruleConfigs.add(ruleConfig);