This is an automated email from the ASF dual-hosted git repository.
xiaoyu 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 622265c Refactor check rule configuration for config center (#8915)
622265c is described below
commit 622265cb3df49ece9dfb692e364a409bc2f96047
Author: Haoran Meng <[email protected]>
AuthorDate: Wed Jan 6 18:19:16 2021 +0800
Refactor check rule configuration for config center (#8915)
---
.../governance/core/config/ConfigCenter.java | 62 ++---------------
.../AbstractEncryptRuleConfigurationChecker.java | 38 +++++++++++
...stractReplicaQueryRuleConfigurationChecker.java | 37 +++++++++++
.../AbstractShardingRuleConfigurationChecker.java | 38 +++++++++++
...thmProvidedEncryptRuleConfigurationChecker.java | 32 +++++++++
...ovidedReplicaQueryRuleConfigurationChecker.java | 31 +++++++++
...hmProvidedShardingRuleConfigurationChecker.java | 33 ++++++++++
.../checker/EncryptRuleConfigurationChecker.java | 32 +++++++++
.../config/checker/HARuleConfigurationChecker.java | 32 +++++++++
.../ReplicaQueryRuleConfigurationChecker.java | 31 +++++++++
.../config/checker/RuleConfigurationChecker.java | 36 ++++++++++
.../checker/RuleConfigurationCheckerFactory.java | 62 +++++++++++++++++
.../checker/ShadowRuleConfigurationChecker.java | 33 ++++++++++
.../checker/ShardingRuleConfigurationChecker.java | 33 ++++++++++
.../RuleConfigurationCheckerFactoryTest.java | 77 ++++++++++++++++++++++
15 files changed, 550 insertions(+), 57 deletions(-)
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
index 40fc17d..68ab38a 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/ConfigCenter.java
@@ -18,12 +18,11 @@
package org.apache.shardingsphere.governance.core.config;
import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.eventbus.Subscribe;
-import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import
org.apache.shardingsphere.governance.core.config.checker.RuleConfigurationChecker;
+import
org.apache.shardingsphere.governance.core.config.checker.RuleConfigurationCheckerFactory;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourcePersistEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsAlteredEvent;
import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsPersistEvent;
@@ -36,7 +35,6 @@ import
org.apache.shardingsphere.governance.core.yaml.config.schema.YamlSchema;
import
org.apache.shardingsphere.governance.core.yaml.swapper.DataSourceConfigurationYamlSwapper;
import
org.apache.shardingsphere.governance.core.yaml.swapper.SchemaYamlSwapper;
import
org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import
org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlAuthenticationConfiguration;
import
org.apache.shardingsphere.infra.auth.builtin.yaml.swapper.AuthenticationYamlSwapper;
@@ -47,12 +45,6 @@ import
org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import
org.apache.shardingsphere.replicaquery.algorithm.config.AlgorithmProvidedReplicaQueryRuleConfiguration;
-import
org.apache.shardingsphere.replicaquery.api.config.ReplicaQueryRuleConfiguration;
-import
org.apache.shardingsphere.replicaquery.api.config.rule.ReplicaQueryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import java.util.ArrayList;
import java.util.Collection;
@@ -218,48 +210,12 @@ public final class ConfigCenter {
ShardingSphereEventBus.getInstance().post(event);
}
- private void checkDataSources(final String schemaName, final
Collection<ReplicaQueryDataSourceRuleConfiguration> dataSources) {
- dataSources.forEach(each -> Preconditions.checkState(
- !each.getPrimaryDataSourceName().isEmpty(), "No available
replica-query rule configuration in `%s` for governance.", schemaName));
- }
-
private YamlRootRuleConfigurations createYamlRootRuleConfigurations(final
String schemaName, final Collection<RuleConfiguration> ruleConfigurations) {
Collection<RuleConfiguration> configs = new LinkedList<>();
for (RuleConfiguration each : ruleConfigurations) {
- if (each instanceof ShardingRuleConfiguration) {
- ShardingRuleConfiguration config = (ShardingRuleConfiguration)
each;
-
Preconditions.checkState(hasAvailableTableConfigurations(config),
- "No available rule configs in `%s` for governance.",
schemaName);
- configs.add(each);
- } else if (each instanceof
AlgorithmProvidedShardingRuleConfiguration) {
- AlgorithmProvidedShardingRuleConfiguration config =
(AlgorithmProvidedShardingRuleConfiguration) each;
-
Preconditions.checkState(hasAvailableTableConfigurations(config),
- "No available rule configs in `%s` for governance.",
schemaName);
- configs.add(each);
- } else if (each instanceof
AlgorithmProvidedReplicaQueryRuleConfiguration) {
- AlgorithmProvidedReplicaQueryRuleConfiguration config =
(AlgorithmProvidedReplicaQueryRuleConfiguration) each;
- checkDataSources(schemaName, config.getDataSources());
- configs.add(each);
- } else if (each instanceof
AlgorithmProvidedEncryptRuleConfiguration) {
- AlgorithmProvidedEncryptRuleConfiguration config =
(AlgorithmProvidedEncryptRuleConfiguration) each;
- Preconditions.checkState(!config.getEncryptors().isEmpty(),
"No available encrypt rule configuration in `%s` for governance.", schemaName);
- configs.add(each);
- } else if (each instanceof ReplicaQueryRuleConfiguration) {
- ReplicaQueryRuleConfiguration config =
(ReplicaQueryRuleConfiguration) each;
- checkDataSources(schemaName, config.getDataSources());
- configs.add(each);
- } else if (each instanceof EncryptRuleConfiguration) {
- EncryptRuleConfiguration config = (EncryptRuleConfiguration)
each;
- Preconditions.checkState(!config.getEncryptors().isEmpty(),
"No available encrypt rule configuration in `%s` for governance.", schemaName);
- configs.add(each);
- } else if (each instanceof ShadowRuleConfiguration) {
- ShadowRuleConfiguration config = (ShadowRuleConfiguration)
each;
- boolean isShadow = !config.getColumn().isEmpty() && null !=
config.getSourceDataSourceNames() && null != config.getShadowDataSourceNames();
- Preconditions.checkState(isShadow, "No available shadow rule
configuration in `%s` for governance.", schemaName);
- configs.add(each);
- } else if (each instanceof HARuleConfiguration) {
- HARuleConfiguration config = (HARuleConfiguration) each;
-
Preconditions.checkState(!config.getHaConfiguration().getType().isEmpty(), "No
available HA rule configuration in `%s` for governance.", schemaName);
+ Optional<RuleConfigurationChecker> checker =
RuleConfigurationCheckerFactory.newInstance(each);
+ if (checker.isPresent()) {
+ checker.get().check(schemaName, each);
configs.add(each);
}
}
@@ -268,14 +224,6 @@ public final class ConfigCenter {
return result;
}
- private boolean hasAvailableTableConfigurations(final
ShardingRuleConfiguration config) {
- return !config.getTables().isEmpty() || null !=
config.getDefaultTableShardingStrategy() || !config.getAutoTables().isEmpty();
- }
-
- private boolean hasAvailableTableConfigurations(final
AlgorithmProvidedShardingRuleConfiguration config) {
- return !config.getTables().isEmpty() || null !=
config.getDefaultTableShardingStrategy() || !config.getAutoTables().isEmpty();
- }
-
private void persistAuthentication(final DefaultAuthentication
authentication, final boolean isOverwrite) {
if (null != authentication && (isOverwrite || !hasAuthentication())) {
repository.persist(node.getAuthenticationPath(),
YamlEngine.marshal(new
AuthenticationYamlSwapper().swapToYamlConfiguration(authentication)));
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractEncryptRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractEncryptRuleConfigurationChecker.java
new file mode 100644
index 0000000..2e0d6b7
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractEncryptRuleConfigurationChecker.java
@@ -0,0 +1,38 @@
+/*
+ * 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.governance.core.config.checker;
+
+import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+
+/**
+ * Abstract encrypt rule configuration checker.
+ *
+ * @param <T> rule configuration
+ */
+public abstract class AbstractEncryptRuleConfigurationChecker<T extends
RuleConfiguration> implements RuleConfigurationChecker<T> {
+
+ protected boolean checkEncryptorsNotEmpty(final EncryptRuleConfiguration
ruleConfiguration) {
+ return !ruleConfiguration.getEncryptors().isEmpty();
+ }
+
+ protected boolean checkEncryptorsNotEmpty(final
AlgorithmProvidedEncryptRuleConfiguration ruleConfiguration) {
+ return !ruleConfiguration.getEncryptors().isEmpty();
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractReplicaQueryRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractReplicaQueryRuleConfigurationChecker.java
new file mode 100644
index 0000000..b9a550e
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractReplicaQueryRuleConfigurationChecker.java
@@ -0,0 +1,37 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import
org.apache.shardingsphere.replicaquery.api.config.rule.ReplicaQueryDataSourceRuleConfiguration;
+
+import java.util.Collection;
+
+/**
+ * Abstract replica query rule configuration checker.
+ *
+ * @param <T> rule configuration
+ */
+public abstract class AbstractReplicaQueryRuleConfigurationChecker<T extends
RuleConfiguration> implements RuleConfigurationChecker<T> {
+
+ protected void checkDataSources(final String schemaName, final
Collection<ReplicaQueryDataSourceRuleConfiguration> dataSources) {
+ dataSources.forEach(each -> Preconditions.checkState(
+ !each.getPrimaryDataSourceName().isEmpty(), "No available
replica-query rule configuration in `%s` for governance.", schemaName));
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractShardingRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractShardingRuleConfigurationChecker.java
new file mode 100644
index 0000000..5fe4d5c
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AbstractShardingRuleConfigurationChecker.java
@@ -0,0 +1,38 @@
+/*
+ * 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.governance.core.config.checker;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+
+/**
+ * Abstract sharding rule configuration checker.
+ *
+ * @param <T> rule configuration
+ */
+public abstract class AbstractShardingRuleConfigurationChecker<T extends
RuleConfiguration> implements RuleConfigurationChecker<T> {
+
+ protected boolean hasAvailableTableConfigurations(final
AlgorithmProvidedShardingRuleConfiguration config) {
+ return !config.getTables().isEmpty() || null !=
config.getDefaultTableShardingStrategy() || !config.getAutoTables().isEmpty();
+ }
+
+ protected boolean hasAvailableTableConfigurations(final
ShardingRuleConfiguration config) {
+ return !config.getTables().isEmpty() || null !=
config.getDefaultTableShardingStrategy() || !config.getAutoTables().isEmpty();
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
new file mode 100644
index 0000000..3a10e30
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
@@ -0,0 +1,32 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+
+/**
+ * Algorithm provided encrypt rule configuration checker.
+ */
+public final class AlgorithmProvidedEncryptRuleConfigurationChecker extends
AbstractEncryptRuleConfigurationChecker<AlgorithmProvidedEncryptRuleConfiguration>
{
+
+ @Override
+ public void check(final String schemaName, final
AlgorithmProvidedEncryptRuleConfiguration ruleConfiguration) {
+ Preconditions.checkState(checkEncryptorsNotEmpty(ruleConfiguration),
"No available encrypt rule configuration in `%s` for governance.", schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedReplicaQueryRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedReplicaQueryRuleConfigurationChecker.java
new file mode 100644
index 0000000..656d978
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedReplicaQueryRuleConfigurationChecker.java
@@ -0,0 +1,31 @@
+/*
+ * 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.governance.core.config.checker;
+
+import
org.apache.shardingsphere.replicaquery.algorithm.config.AlgorithmProvidedReplicaQueryRuleConfiguration;
+
+/**
+ * Algorithm provided replica query ruleConfiguration checker.
+ */
+public final class AlgorithmProvidedReplicaQueryRuleConfigurationChecker
extends
AbstractReplicaQueryRuleConfigurationChecker<AlgorithmProvidedReplicaQueryRuleConfiguration>
{
+
+ @Override
+ public void check(final String schemaName, final
AlgorithmProvidedReplicaQueryRuleConfiguration ruleConfiguration) {
+ checkDataSources(schemaName, ruleConfiguration.getDataSources());
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedShardingRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedShardingRuleConfigurationChecker.java
new file mode 100644
index 0000000..2c0a46b
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/AlgorithmProvidedShardingRuleConfigurationChecker.java
@@ -0,0 +1,33 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+
+/**
+ * Algorithm provided sharding ruleConfiguration checker.
+ */
+public final class AlgorithmProvidedShardingRuleConfigurationChecker extends
AbstractShardingRuleConfigurationChecker<AlgorithmProvidedShardingRuleConfiguration>
{
+
+ @Override
+ public void check(final String schemaName, final
AlgorithmProvidedShardingRuleConfiguration ruleConfiguration) {
+
Preconditions.checkState(hasAvailableTableConfigurations(ruleConfiguration),
+ "No available rule configs in `%s` for governance.",
schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/EncryptRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/EncryptRuleConfigurationChecker.java
new file mode 100644
index 0000000..90b2146
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/EncryptRuleConfigurationChecker.java
@@ -0,0 +1,32 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+
+/**
+ * Encrypt rule configuration checker.
+ */
+public final class EncryptRuleConfigurationChecker extends
AbstractEncryptRuleConfigurationChecker<EncryptRuleConfiguration> {
+
+ @Override
+ public void check(final String schemaName, final EncryptRuleConfiguration
ruleConfiguration) {
+ Preconditions.checkState(checkEncryptorsNotEmpty(ruleConfiguration),
"No available encrypt rule configuration in `%s` for governance.", schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/HARuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/HARuleConfigurationChecker.java
new file mode 100644
index 0000000..d3c0ea7
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/HARuleConfigurationChecker.java
@@ -0,0 +1,32 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
+
+/**
+ * HA rule configuration checker.
+ */
+public final class HARuleConfigurationChecker implements
RuleConfigurationChecker<HARuleConfiguration> {
+
+ @Override
+ public void check(final String schemaName, final HARuleConfiguration
ruleConfiguration) {
+
Preconditions.checkState(!ruleConfiguration.getHaConfiguration().getType().isEmpty(),
"No available HA rule configuration in `%s` for governance.", schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ReplicaQueryRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ReplicaQueryRuleConfigurationChecker.java
new file mode 100644
index 0000000..b38e174
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ReplicaQueryRuleConfigurationChecker.java
@@ -0,0 +1,31 @@
+/*
+ * 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.governance.core.config.checker;
+
+import
org.apache.shardingsphere.replicaquery.api.config.ReplicaQueryRuleConfiguration;
+
+/**
+ * Replica query rule configuration checker.
+ */
+public final class ReplicaQueryRuleConfigurationChecker extends
AbstractReplicaQueryRuleConfigurationChecker<ReplicaQueryRuleConfiguration> {
+
+ @Override
+ public void check(final String schemaName, final
ReplicaQueryRuleConfiguration ruleConfiguration) {
+ checkDataSources(schemaName, ruleConfiguration.getDataSources());
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationChecker.java
new file mode 100644
index 0000000..1aee05e
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationChecker.java
@@ -0,0 +1,36 @@
+/*
+ * 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.governance.core.config.checker;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+
+/**
+ * Rule configuration checker.
+ *
+ * @param <T> type of rule configuration
+ */
+public interface RuleConfigurationChecker<T extends RuleConfiguration> {
+
+ /**
+ * Check rule configuration.
+ *
+ * @param schemaName schema name
+ * @param ruleConfiguration rule configuration
+ */
+ void check(String schemaName, T ruleConfiguration);
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactory.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactory.java
new file mode 100644
index 0000000..1ad935c
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactory.java
@@ -0,0 +1,62 @@
+/*
+ * 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.governance.core.config.checker;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import
org.apache.shardingsphere.replicaquery.algorithm.config.AlgorithmProvidedReplicaQueryRuleConfiguration;
+import
org.apache.shardingsphere.replicaquery.api.config.ReplicaQueryRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RuleConfigurationCheckerFactory {
+
+ private static final Map<Class<? extends RuleConfiguration>,
RuleConfigurationChecker<?>> REGISTRY = new HashMap<>();
+
+ static {
+ REGISTRY.put(ShardingRuleConfiguration.class, new
ShardingRuleConfigurationChecker());
+ REGISTRY.put(AlgorithmProvidedShardingRuleConfiguration.class, new
AlgorithmProvidedShardingRuleConfigurationChecker());
+ REGISTRY.put(ReplicaQueryRuleConfiguration.class, new
ReplicaQueryRuleConfigurationChecker());
+ REGISTRY.put(AlgorithmProvidedReplicaQueryRuleConfiguration.class, new
AlgorithmProvidedReplicaQueryRuleConfigurationChecker());
+ REGISTRY.put(EncryptRuleConfiguration.class, new
EncryptRuleConfigurationChecker());
+ REGISTRY.put(AlgorithmProvidedEncryptRuleConfiguration.class, new
AlgorithmProvidedEncryptRuleConfigurationChecker());
+ REGISTRY.put(ShadowRuleConfiguration.class, new
ShadowRuleConfigurationChecker());
+ REGISTRY.put(HARuleConfiguration.class, new
HARuleConfigurationChecker());
+ }
+
+ /**
+ * Get rule configuration checker.
+ *
+ * @param ruleConfiguration rule configuration
+ * @return rule configuration checker
+ */
+ public static Optional<RuleConfigurationChecker> newInstance(final
RuleConfiguration ruleConfiguration) {
+ return REGISTRY.entrySet().stream().filter(entry ->
entry.getKey().isAssignableFrom(ruleConfiguration.getClass())).findFirst().map(Entry::getValue);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShadowRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShadowRuleConfigurationChecker.java
new file mode 100644
index 0000000..675d8ea
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShadowRuleConfigurationChecker.java
@@ -0,0 +1,33 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+
+/**
+ * Shadow rule configuration checker.
+ */
+public final class ShadowRuleConfigurationChecker implements
RuleConfigurationChecker<ShadowRuleConfiguration> {
+
+ @Override
+ public void check(final String schemaName, final ShadowRuleConfiguration
ruleConfiguration) {
+ boolean isShadow = !ruleConfiguration.getColumn().isEmpty() && null !=
ruleConfiguration.getSourceDataSourceNames() && null !=
ruleConfiguration.getShadowDataSourceNames();
+ Preconditions.checkState(isShadow, "No available shadow rule
configuration in `%s` for governance.", schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShardingRuleConfigurationChecker.java
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShardingRuleConfigurationChecker.java
new file mode 100644
index 0000000..2083158
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/config/checker/ShardingRuleConfigurationChecker.java
@@ -0,0 +1,33 @@
+/*
+ * 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.governance.core.config.checker;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+
+/**
+ * Sharding rule configuration checker.
+ */
+public final class ShardingRuleConfigurationChecker extends
AbstractShardingRuleConfigurationChecker<ShardingRuleConfiguration> {
+
+ @Override
+ public void check(final String schemaName, final ShardingRuleConfiguration
ruleConfiguration) {
+
Preconditions.checkState(hasAvailableTableConfigurations(ruleConfiguration),
+ "No available rule configs in `%s` for governance.",
schemaName);
+ }
+}
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactoryTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactoryTest.java
new file mode 100644
index 0000000..8296d77
--- /dev/null
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/config/checker/RuleConfigurationCheckerFactoryTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.governance.core.config.checker;
+
+import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
+import
org.apache.shardingsphere.replicaquery.algorithm.config.AlgorithmProvidedReplicaQueryRuleConfiguration;
+import
org.apache.shardingsphere.replicaquery.api.config.ReplicaQueryRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import
org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class RuleConfigurationCheckerFactoryTest {
+
+ @Test
+ public void assertShardingRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(ShardingRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertAlgorithmProvidedShardingRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(AlgorithmProvidedShardingRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertEncryptRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(ReplicaQueryRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertAlgorithmProvidedEncryptRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(AlgorithmProvidedReplicaQueryRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertReplicaQueryRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(EncryptRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertAlgorithmProvidedReplicaQueryRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(AlgorithmProvidedEncryptRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertShadowRuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(ShadowRuleConfiguration.class)).isPresent());
+ }
+
+ @Test
+ public void assertHARuleConfigurationChecker() {
+
assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(HARuleConfiguration.class)).isPresent());
+ }
+}