You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/03/16 11:47:28 UTC
[shardingsphere] branch master updated: HA renamed to db discovery
(#9689)
This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 a6e248c HA renamed to db discovery (#9689)
a6e248c is described below
commit a6e248ca9b141ca7b418ee85fbfafe8802b80d0b
Author: xiaoyu <54...@qq.com>
AuthorDate: Tue Mar 16 19:46:46 2021 +0800
HA renamed to db discovery (#9689)
---
shardingsphere-features/pom.xml | 2 +-
.../pom.xml | 12 +-
.../shardingsphere-db-discovery-api}/pom.xml | 4 +-
.../DatabaseDiscoveryRuleConfiguration.java} | 14 +-
...abaseDiscoveryDataSourceRuleConfiguration.java} | 10 +-
.../db/discovery/spi/DatabaseDiscoveryType.java} | 12 +-
.../shardingsphere-db-discovery-common}/pom.xml | 8 +-
...rovidedDatabaseDiscoveryRuleConfiguration.java} | 16 +-
.../common/constant/DatabaseDiscoveryOrder.java} | 14 +-
.../rule/DatabaseDiscoveryDataSourceRule.java} | 20 +--
.../common/rule/DatabaseDiscoveryRule.java | 170 +++++++++++++++++++++
...rithmProvidedDatabaseDiscoveryRuleBuilder.java} | 24 +--
.../biulder/DatabaseDiscoveryRuleBuilder.java} | 28 ++--
.../YamlDatabaseDiscoveryRuleConfiguration.java} | 20 +--
...abaseDiscoveryDataSourceRuleConfiguration.java} | 10 +-
...eAlgorithmProviderConfigurationYamlSwapper.java | 83 ++++++++++
...abaseDiscoveryRuleConfigurationYamlSwapper.java | 94 ++++++++++++
...re.infra.rule.builder.ShardingSphereRuleBuilder | 4 +-
...infra.yaml.swapper.YamlRuleConfigurationSwapper | 4 +-
.../fixture/TestDatabaseDiscoveryTypeFixture.java} | 13 +-
.../rule/DatabaseDiscoveryDataSourceRuleTest.java} | 38 ++---
.../common/rule/DatabaseDiscoveryRuleTest.java} | 50 +++---
...mProvidedDatabaseDiscoveryRuleBuilderTest.java} | 20 +--
.../biulder/DatabaseDiscoveryRuleBuilderTest.java} | 22 +--
...rithmProviderConfigurationYamlSwapperTest.java} | 38 ++---
...eDiscoveryRuleConfigurationYamlSwapperTest.java | 118 ++++++++++++++
...amlDatabaseDiscoveryRuleConfigurationTest.java} | 22 +--
...gsphere.db.discovery.spi.DatabaseDiscoveryType} | 2 +-
.../src/test/resources/logback-test.xml | 0
.../test/resources/yaml/db-discovery-rule.yaml} | 8 +-
.../shardingsphere-db-discovery-provider}/pom.xml | 6 +-
.../shardingsphere-db-discovery-mgr}/pom.xml | 6 +-
.../discovery/mgr/MGRDatabaseDiscoveryType.java} | 12 +-
.../db/discovery}/mgr/MGRHeartbeatJob.java | 12 +-
...ngsphere.db.discovery.spi.DatabaseDiscoveryType | 35 +++++
.../mgr/MGRDatabaseDiscoveryTypeTest.java} | 12 +-
.../shardingsphere-db-discovery-route}/pom.xml | 6 +-
.../route/DatabaseDiscoverySQLRouter.java} | 32 ++--
.../impl/DatabaseDiscoveryDataSourceRouter.java} | 12 +-
...org.apache.shardingsphere.infra.route.SQLRouter | 2 +-
.../engine/DatabaseDiscoverySQLRouterTest.java} | 35 +++--
.../TestRouteDatabaseDiscoveryTypeFixture.java} | 13 +-
...gsphere.db.discovery.spi.DatabaseDiscoveryType} | 2 +-
.../shardingsphere-db-discovery-spring}/pom.xml | 8 +-
.../pom.xml | 6 +-
...tabaseDiscoveryRuleSpringbootConfiguration.java | 55 +++++++
.../DatabaseDiscoverySpringBootCondition.java} | 12 +-
...abaseDiscoveryRuleSpringBootConfiguration.java} | 12 +-
.../src/main/resources/META-INF/spring.factories | 2 +-
.../src/main/resources/META-INF/spring.provides | 2 +-
.../DatabaseDiscoverySpringBootStarterTest.java} | 18 +--
.../DatabaseDiscoverySpringBootConditionTest.java} | 12 +-
.../application-database-discovery.properties} | 4 +-
.../src/test/resources/logback-test.xml | 0
.../pom.xml | 6 +-
.../DatabaseDiscoveryNamespaceHandler.java} | 14 +-
...DatabaseDiscoveryRuleBeanDefinitionParser.java} | 22 +--
.../DatabaseDiscoveryRuleBeanDefinitionTag.java} | 10 +-
.../META-INF/namespace/database-discovery.xsd} | 1 -
.../src/main/resources/META-INF/spring.handlers | 2 +-
.../src/main/resources/META-INF/spring.schemas | 2 +-
.../org/apache/shardingsphere/ha/rule/HARule.java | 169 --------------------
...eAlgorithmProviderConfigurationYamlSwapper.java | 83 ----------
.../swapper/HARuleConfigurationYamlSwapper.java | 94 ------------
.../org.apache.shardingsphere.ha.spi.HAType | 18 ---
.../HARuleConfigurationYamlSwapperTest.java | 118 --------------
.../spring/boot/HARuleSpringbootConfiguration.java | 55 -------
.../rule/single/SingleTableRuleLoader.java | 2 +-
.../shardingsphere-governance-core/pom.xml | 2 +-
...DatabaseDiscoveryRuleConfigurationChecker.java} | 10 +-
.../checker/RuleConfigurationCheckerFactory.java | 6 +-
.../core/registry/RegistryCenterTest.java | 26 ++--
.../RuleConfigurationCheckerFactoryTest.java | 8 +-
.../{ha-rule.yaml => database-discovery-rule.yaml} | 6 +-
...rule.yaml => data-database-discovery-rule.yaml} | 6 +-
.../shardingsphere-proxy-backend/pom.xml | 2 +-
...nfig-ha.yaml => config-database-discovery.yaml} | 12 +-
.../shardingsphere-proxy-common/pom.xml | 2 +-
78 files changed, 943 insertions(+), 929 deletions(-)
diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/pom.xml
index b45f295..c3e0567 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/pom.xml
@@ -32,7 +32,7 @@
<modules>
<module>shardingsphere-sharding</module>
<module>shardingsphere-read-write-splitting</module>
- <module>shardingsphere-ha</module>
+ <module>shardingsphere-db-discovery</module>
<module>shardingsphere-encrypt</module>
<module>shardingsphere-shadow</module>
</modules>
diff --git a/shardingsphere-features/shardingsphere-ha/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/pom.xml
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/pom.xml
index d118049..04a90a7 100644
--- a/shardingsphere-features/shardingsphere-ha/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/pom.xml
@@ -25,15 +25,15 @@
<artifactId>shardingsphere-features</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<name>${project.artifactId}</name>
<packaging>pom</packaging>
<modules>
- <module>shardingsphere-ha-api</module>
- <module>shardingsphere-ha-common</module>
- <module>shardingsphere-ha-provider</module>
- <module>shardingsphere-ha-route</module>
- <module>shardingsphere-ha-spring</module>
+ <module>shardingsphere-db-discovery-api</module>
+ <module>shardingsphere-db-discovery-common</module>
+ <module>shardingsphere-db-discovery-provider</module>
+ <module>shardingsphere-db-discovery-route</module>
+ <module>shardingsphere-db-discovery-spring</module>
</modules>
</project>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/pom.xml
similarity index 92%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/pom.xml
index bba4c41..cf45940 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/pom.xml
@@ -22,10 +22,10 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-api</artifactId>
+ <artifactId>shardingsphere-db-discovery-api</artifactId>
<name>${project.artifactId}</name>
<dependencies>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/HARuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/DatabaseDiscoveryRuleConfiguration.java
similarity index 74%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/HARuleConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/DatabaseDiscoveryRuleConfiguration.java
index c8c0c21..21ef99d 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/HARuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/DatabaseDiscoveryRuleConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,25 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.api.config;
+package org.apache.shardingsphere.db.discovery.api.config;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
import java.util.Collection;
import java.util.Map;
/**
- * HA rule configuration.
+ * Data base discovery rule configuration.
*/
@RequiredArgsConstructor
@Getter
-public final class HARuleConfiguration implements RuleConfiguration {
+public final class DatabaseDiscoveryRuleConfiguration implements RuleConfiguration {
- private final Collection<HADataSourceRuleConfiguration> dataSources;
+ private final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources;
- private final Map<String, ShardingSphereAlgorithmConfiguration> haTypes;
+ private final Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes;
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/rule/HADataSourceRuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java
similarity index 81%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/rule/HADataSourceRuleConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java
index 06d4330..3f89a0c 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/api/config/rule/HADataSourceRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.api.config.rule;
+package org.apache.shardingsphere.db.discovery.api.config.rule;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -23,15 +23,15 @@ import lombok.RequiredArgsConstructor;
import java.util.List;
/**
- * HA data source rule configuration.
+ * Data base discovery data source rule configuration.
*/
@RequiredArgsConstructor
@Getter
-public final class HADataSourceRuleConfiguration {
+public final class DatabaseDiscoveryDataSourceRuleConfiguration {
private final String name;
private final List<String> dataSourceNames;
- private final String haTypeName;
+ private final String discoveryTypeName;
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/spi/HAType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/spi/DatabaseDiscoveryType.java
similarity index 89%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/spi/HAType.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/spi/DatabaseDiscoveryType.java
index c3c536d..050ef08 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-api/src/main/java/org/apache/shardingsphere/ha/spi/HAType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/db/discovery/spi/DatabaseDiscoveryType.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spi;
+package org.apache.shardingsphere.db.discovery.spi;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
@@ -25,18 +25,18 @@ import java.util.Collection;
import java.util.Map;
/**
- * HA type.
+ * Data base discovery type.
*/
-public interface HAType extends ShardingSphereAlgorithm {
+public interface DatabaseDiscoveryType extends ShardingSphereAlgorithm {
/**
- * Check HA config.
+ * Check data base discovery config.
*
* @param dataSourceMap data source map
* @param schemaName schema name
* @throws SQLException SQL Exception
*/
- void checkHAConfig(Map<String, DataSource> dataSourceMap, String schemaName) throws SQLException;
+ void checkDatabaseDiscoveryConfig(Map<String, DataSource> dataSourceMap, String schemaName) throws SQLException;
/**
* Update primary data source.
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/pom.xml
similarity index 87%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/pom.xml
index 8f774f4..864b51a 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/pom.xml
@@ -22,21 +22,21 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-api</artifactId>
+ <artifactId>shardingsphere-db-discovery-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-mgr</artifactId>
+ <artifactId>shardingsphere-db-discovery-mgr</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/algorithm/config/AlgorithmProvidedHARuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/algorithm/config/AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.java
similarity index 65%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/algorithm/config/AlgorithmProvidedHARuleConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/algorithm/config/AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.java
index 8cfd180..92b906e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/algorithm/config/AlgorithmProvidedHARuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/algorithm/config/AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.algorithm.config;
+package org.apache.shardingsphere.db.discovery.common.algorithm.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import java.util.Collection;
@@ -31,15 +31,15 @@ import java.util.LinkedList;
import java.util.Map;
/**
- * Algorithm provided HA rule configuration.
+ * Algorithm provided data base discovery rule configuration.
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
-public final class AlgorithmProvidedHARuleConfiguration implements RuleConfiguration {
+public final class AlgorithmProvidedDatabaseDiscoveryRuleConfiguration implements RuleConfiguration {
- private Collection<HADataSourceRuleConfiguration> dataSources = new LinkedList<>();
+ private Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources = new LinkedList<>();
- private Map<String, HAType> haTypes = new LinkedHashMap<>();
+ private Map<String, DatabaseDiscoveryType> discoveryTypes = new LinkedHashMap<>();
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/constant/DatabaseDiscoveryOrder.java
similarity index 76%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/constant/DatabaseDiscoveryOrder.java
index d15d355..363d1de 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/constant/HAOrder.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/constant/DatabaseDiscoveryOrder.java
@@ -5,7 +5,7 @@
* 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
@@ -15,24 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.constant;
+package org.apache.shardingsphere.db.discovery.common.constant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
- * HA order.
+ * Data base discovery order.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class HAOrder {
+public final class DatabaseDiscoveryOrder {
/**
- * HA order.
+ * Data base discovery order.
*/
public static final int ORDER = 2;
/**
- * Algorithm provider HA order.
+ * Algorithm provider data base discovery order.
*/
- public static final int ALGORITHM_PROVIDER_HA_ORDER = 3;
+ public static final int ALGORITHM_PROVIDER_DB_DISCOVERY_ORDER = 3;
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HADataSourceRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRule.java
similarity index 81%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HADataSourceRule.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRule.java
index 3f13514..bbf970e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HADataSourceRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRule.java
@@ -5,7 +5,7 @@
* 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
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule;
+package org.apache.shardingsphere.db.discovery.common.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import java.util.Collection;
import java.util.HashMap;
@@ -33,30 +33,30 @@ import java.util.Map;
import java.util.stream.Collectors;
/**
- * HA data source rule.
+ * Data base discovery data source rule.
*/
@Getter
@Slf4j
-public final class HADataSourceRule {
+public final class DatabaseDiscoveryDataSourceRule {
private final String name;
private final List<String> dataSourceNames;
- private final HAType haType;
+ private final DatabaseDiscoveryType databaseDiscoveryType;
private final Collection<String> disabledDataSourceNames = new HashSet<>();
private String primaryDataSourceName;
- public HADataSourceRule(final HADataSourceRuleConfiguration config, final HAType haType) {
+ public DatabaseDiscoveryDataSourceRule(final DatabaseDiscoveryDataSourceRuleConfiguration config, final DatabaseDiscoveryType databaseDiscoveryType) {
checkConfiguration(config);
name = config.getName();
dataSourceNames = config.getDataSourceNames();
- this.haType = haType;
+ this.databaseDiscoveryType = databaseDiscoveryType;
}
- private void checkConfiguration(final HADataSourceRuleConfiguration config) {
+ private void checkConfiguration(final DatabaseDiscoveryDataSourceRuleConfiguration config) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getName()), "Name is required.");
Preconditions.checkArgument(null != config.getDataSourceNames() && !config.getDataSourceNames().isEmpty(), "Data source names are required.");
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
new file mode 100644
index 0000000..77a0ccb
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
@@ -0,0 +1,170 @@
+/*
+ * 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.db.discovery.common.rule;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
+import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
+import org.apache.shardingsphere.infra.rule.type.StatusContainedRule;
+import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
+import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+/**
+ * Data base discovery rule.
+ */
+public final class DatabaseDiscoveryRule implements DataSourceContainedRule, StatusContainedRule {
+
+ static {
+ ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
+ }
+
+ private final Map<String, DatabaseDiscoveryType> discoveryTypes = new LinkedHashMap<>();
+
+ private final Map<String, DatabaseDiscoveryDataSourceRule> dataSourceRules;
+
+ public DatabaseDiscoveryRule(final DatabaseDiscoveryRuleConfiguration config, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final String schemaName) {
+ Preconditions.checkArgument(!config.getDataSources().isEmpty(), "HA data source rules can not be empty.");
+ Preconditions.checkArgument(null != dataSourceMap && !dataSourceMap.isEmpty(), "Data sources cannot be empty.");
+ Preconditions.checkArgument(null != databaseType, "Database type cannot be null.");
+ config.getDiscoveryTypes().forEach((key, value) -> discoveryTypes.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, DatabaseDiscoveryType.class)));
+ dataSourceRules = new HashMap<>(config.getDataSources().size(), 1);
+ for (DatabaseDiscoveryDataSourceRuleConfiguration each : config.getDataSources()) {
+ DatabaseDiscoveryType databaseDiscoveryType = Strings.isNullOrEmpty(each.getDiscoveryTypeName()) || !discoveryTypes.containsKey(each.getDiscoveryTypeName())
+ ? TypedSPIRegistry.getRegisteredService(DatabaseDiscoveryType.class) : discoveryTypes.get(each.getDiscoveryTypeName());
+ dataSourceRules.put(each.getName(), new DatabaseDiscoveryDataSourceRule(each, databaseDiscoveryType));
+ }
+ for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
+ String groupName = entry.getKey();
+ DatabaseDiscoveryDataSourceRule databaseDiscoveryDataSourceRule = entry.getValue();
+ DatabaseDiscoveryType databaseDiscoveryType = databaseDiscoveryDataSourceRule.getDatabaseDiscoveryType();
+ Map<String, DataSource> originalDataSourceMap = new HashMap<>(dataSourceMap);
+ Collection<String> disabledDataSourceNames = databaseDiscoveryDataSourceRule.getDisabledDataSourceNames();
+ String primaryDataSourceName = databaseDiscoveryDataSourceRule.getPrimaryDataSourceName();
+ databaseDiscoveryType.updatePrimaryDataSource(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
+ databaseDiscoveryDataSourceRule.updatePrimaryDataSourceName(databaseDiscoveryType.getPrimaryDataSource());
+ databaseDiscoveryType.updateMemberState(originalDataSourceMap, schemaName, disabledDataSourceNames);
+ try {
+ databaseDiscoveryType.checkDatabaseDiscoveryConfig(dataSourceMap, schemaName);
+ databaseDiscoveryType.startPeriodicalUpdate(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
+ } catch (final SQLException ex) {
+ throw new ShardingSphereException(ex);
+ }
+ }
+ }
+
+ public DatabaseDiscoveryRule(final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config, final DatabaseType databaseType,
+ final Map<String, DataSource> dataSourceMap, final String schemaName) {
+ Preconditions.checkArgument(!config.getDataSources().isEmpty(), "HA data source rules can not be empty.");
+ Preconditions.checkArgument(null != dataSourceMap && !dataSourceMap.isEmpty(), "Data sources cannot be empty.");
+ Preconditions.checkArgument(null != databaseType, "Database type cannot be null.");
+ dataSourceRules = new HashMap<>(config.getDataSources().size(), 1);
+ for (DatabaseDiscoveryDataSourceRuleConfiguration each : config.getDataSources()) {
+ DatabaseDiscoveryType databaseDiscoveryType = Strings.isNullOrEmpty(each.getDiscoveryTypeName()) || !discoveryTypes.containsKey(each.getDiscoveryTypeName())
+ ? TypedSPIRegistry.getRegisteredService(DatabaseDiscoveryType.class) : discoveryTypes.get(each.getDiscoveryTypeName());
+ dataSourceRules.put(each.getName(), new DatabaseDiscoveryDataSourceRule(each, databaseDiscoveryType));
+ }
+ for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
+ String groupName = entry.getKey();
+ DatabaseDiscoveryDataSourceRule databaseDiscoveryDataSourceRule = entry.getValue();
+ DatabaseDiscoveryType databaseDiscoveryType = databaseDiscoveryDataSourceRule.getDatabaseDiscoveryType();
+ Map<String, DataSource> originalDataSourceMap = new HashMap<>(dataSourceMap);
+ Collection<String> disabledDataSourceNames = databaseDiscoveryDataSourceRule.getDisabledDataSourceNames();
+ String primaryDataSourceName = databaseDiscoveryDataSourceRule.getPrimaryDataSourceName();
+ databaseDiscoveryType.updatePrimaryDataSource(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
+ databaseDiscoveryDataSourceRule.updatePrimaryDataSourceName(databaseDiscoveryType.getPrimaryDataSource());
+ databaseDiscoveryType.updateMemberState(originalDataSourceMap, schemaName, disabledDataSourceNames);
+ try {
+ databaseDiscoveryType.checkDatabaseDiscoveryConfig(dataSourceMap, schemaName);
+ databaseDiscoveryType.startPeriodicalUpdate(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
+ } catch (final SQLException ex) {
+ throw new ShardingSphereException(ex);
+ }
+ }
+ }
+
+ /**
+ * Get all logic data source names.
+ *
+ * @return all logic data source names
+ */
+ public Collection<String> getAllLogicDataSourceNames() {
+ return dataSourceRules.keySet();
+ }
+
+ /**
+ * Get single data source rule.
+ *
+ * @return HA data source rule
+ */
+ public DatabaseDiscoveryDataSourceRule getSingleDataSourceRule() {
+ return dataSourceRules.values().iterator().next();
+ }
+
+ /**
+ * Find data source rule.
+ *
+ * @param dataSourceName data source name
+ * @return HA data source rule
+ */
+ public Optional<DatabaseDiscoveryDataSourceRule> findDataSourceRule(final String dataSourceName) {
+ return Optional.ofNullable(dataSourceRules.get(dataSourceName));
+ }
+
+ @Override
+ public Map<String, Collection<String>> getDataSourceMapper() {
+ Map<String, Collection<String>> result = new HashMap<>();
+ for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
+ result.putAll(entry.getValue().getDataSourceMapper());
+ }
+ return result;
+ }
+
+ @Override
+ public void updateRuleStatus(final RuleChangedEvent event) {
+ if (event instanceof DataSourceNameDisabledEvent) {
+ for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
+ entry.getValue().updateDisabledDataSourceNames(((DataSourceNameDisabledEvent) event).getDataSourceName(), ((DataSourceNameDisabledEvent) event).isDisabled());
+ }
+ } else if (event instanceof PrimaryDataSourceEvent) {
+ for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
+ if (entry.getValue().getName().equals(((PrimaryDataSourceEvent) event).getGroupName())) {
+ entry.getValue().updatePrimaryDataSourceName(((PrimaryDataSourceEvent) event).getDataSourceName());
+ }
+ }
+ }
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilder.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
similarity index 56%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilder.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
index ac19a25..a6df9f3 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilder.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
@@ -5,7 +5,7 @@
* 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
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule.biulder;
+package org.apache.shardingsphere.db.discovery.common.rule.biulder;
import lombok.Setter;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.aware.ResourceAware;
@@ -29,10 +29,10 @@ import javax.sql.DataSource;
import java.util.Map;
/**
- * Algorithm provided HA rule builder.
+ * Algorithm provided data base discovery rule builder.
*/
@Setter
-public final class AlgorithmProvidedHARuleBuilder implements ShardingSphereRuleBuilder<HARule, AlgorithmProvidedHARuleConfiguration>, ResourceAware {
+public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilder implements ShardingSphereRuleBuilder<DatabaseDiscoveryRule, AlgorithmProvidedDatabaseDiscoveryRuleConfiguration>, ResourceAware {
private DatabaseType databaseType;
@@ -41,17 +41,17 @@ public final class AlgorithmProvidedHARuleBuilder implements ShardingSphereRuleB
private String schemaName;
@Override
- public HARule build(final AlgorithmProvidedHARuleConfiguration ruleConfig) {
- return new HARule(ruleConfig, databaseType, dataSourceMap, schemaName);
+ public DatabaseDiscoveryRule build(final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration ruleConfig) {
+ return new DatabaseDiscoveryRule(ruleConfig, databaseType, dataSourceMap, schemaName);
}
@Override
public int getOrder() {
- return HAOrder.ORDER + 1;
+ return DatabaseDiscoveryOrder.ORDER + 1;
}
@Override
- public Class<AlgorithmProvidedHARuleConfiguration> getTypeClass() {
- return AlgorithmProvidedHARuleConfiguration.class;
+ public Class<AlgorithmProvidedDatabaseDiscoveryRuleConfiguration> getTypeClass() {
+ return AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class;
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilder.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilder.java
similarity index 59%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilder.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilder.java
index 7835978..76b1228 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilder.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilder.java
@@ -5,7 +5,7 @@
* 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
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule.biulder;
+package org.apache.shardingsphere.db.discovery.common.rule.biulder;
import lombok.Setter;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.aware.ResourceAware;
@@ -32,10 +32,10 @@ import java.util.Map;
import java.util.Set;
/**
- * HA rule builder.
+ * Data base discovery rule builder.
*/
@Setter
-public final class HARuleBuilder implements ShardingSphereRuleBuilder<HARule, HARuleConfiguration>, ResourceAware {
+public final class DatabaseDiscoveryRuleBuilder implements ShardingSphereRuleBuilder<DatabaseDiscoveryRule, DatabaseDiscoveryRuleConfiguration>, ResourceAware {
private DatabaseType databaseType;
@@ -44,22 +44,22 @@ public final class HARuleBuilder implements ShardingSphereRuleBuilder<HARule, HA
private String schemaName;
@Override
- public HARule build(final HARuleConfiguration ruleConfig) {
+ public DatabaseDiscoveryRule build(final DatabaseDiscoveryRuleConfiguration ruleConfig) {
Set<String> dataSourceSet = new HashSet<>(128, 1);
- for (HADataSourceRuleConfiguration each : ruleConfig.getDataSources()) {
+ for (DatabaseDiscoveryDataSourceRuleConfiguration each : ruleConfig.getDataSources()) {
dataSourceSet.addAll(each.getDataSourceNames());
}
dataSourceMap.entrySet().removeIf(entry -> !dataSourceSet.contains(entry.getKey()));
- return new HARule(ruleConfig, databaseType, dataSourceMap, schemaName);
+ return new DatabaseDiscoveryRule(ruleConfig, databaseType, dataSourceMap, schemaName);
}
@Override
public int getOrder() {
- return HAOrder.ORDER;
+ return DatabaseDiscoveryOrder.ORDER;
}
@Override
- public Class<HARuleConfiguration> getTypeClass() {
- return HARuleConfiguration.class;
+ public Class<DatabaseDiscoveryRuleConfiguration> getTypeClass() {
+ return DatabaseDiscoveryRuleConfiguration.class;
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/YamlHARuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java
similarity index 62%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/YamlHARuleConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java
index 9bcf14c..3abb83d 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/YamlHARuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.yaml.config;
+package org.apache.shardingsphere.db.discovery.common.yaml.config;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.yaml.config.rule.YamlHADataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
@@ -28,18 +28,18 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
- * HA rule configuration for YAML.
+ * Data base discovery rule configuration for YAML.
*/
@Getter
@Setter
-public final class YamlHARuleConfiguration implements YamlRuleConfiguration {
+public final class YamlDatabaseDiscoveryRuleConfiguration implements YamlRuleConfiguration {
- private Map<String, YamlHADataSourceRuleConfiguration> dataSources = new LinkedHashMap<>();
+ private Map<String, YamlDatabaseDiscoveryDataSourceRuleConfiguration> dataSources = new LinkedHashMap<>();
- private Map<String, YamlShardingSphereAlgorithmConfiguration> haTypes = new LinkedHashMap<>();
+ private Map<String, YamlShardingSphereAlgorithmConfiguration> discoveryTypes = new LinkedHashMap<>();
@Override
- public Class<HARuleConfiguration> getRuleConfigurationType() {
- return HARuleConfiguration.class;
+ public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationType() {
+ return DatabaseDiscoveryRuleConfiguration.class;
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/rule/YamlHADataSourceRuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/rule/YamlHADataSourceRuleConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java
index 217b40e..9ac89d9 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/config/rule/YamlHADataSourceRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.yaml.config.rule;
+package org.apache.shardingsphere.db.discovery.common.yaml.config.rule;
import lombok.Getter;
import lombok.Setter;
@@ -26,17 +26,17 @@ import java.util.List;
import java.util.Properties;
/**
- * HA data source rule configuration for YAML.
+ * Data base discovery data source rule configuration for YAML.
*/
@Getter
@Setter
-public final class YamlHADataSourceRuleConfiguration implements YamlConfiguration {
+public final class YamlDatabaseDiscoveryDataSourceRuleConfiguration implements YamlConfiguration {
private String name;
private List<String> dataSourceNames = new ArrayList<>();
- private String haTypeName;
+ private String discoveryTypeName;
private Properties props = new Properties();
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java
new file mode 100644
index 0000000..a4349c9
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -0,0 +1,83 @@
+/*
+ * 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.db.discovery.common.yaml.swapper;
+
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+/**
+ * Data base discovery rule configuration YAML swapper.
+ */
+public final class DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper
+ implements YamlRuleConfigurationSwapper<YamlDatabaseDiscoveryRuleConfiguration, AlgorithmProvidedDatabaseDiscoveryRuleConfiguration> {
+
+ @Override
+ public YamlDatabaseDiscoveryRuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration data) {
+ YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration();
+ result.setDataSources(data.getDataSources().stream().collect(
+ Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
+ return result;
+ }
+
+ private YamlDatabaseDiscoveryDataSourceRuleConfiguration swapToYamlConfiguration(final DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig) {
+ YamlDatabaseDiscoveryDataSourceRuleConfiguration result = new YamlDatabaseDiscoveryDataSourceRuleConfiguration();
+ result.setName(dataSourceRuleConfig.getName());
+ result.setDataSourceNames(dataSourceRuleConfig.getDataSourceNames());
+ return result;
+ }
+
+ @Override
+ public AlgorithmProvidedDatabaseDiscoveryRuleConfiguration swapToObject(final YamlDatabaseDiscoveryRuleConfiguration yamlConfig) {
+ Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources = new LinkedList<>();
+ for (Entry<String, YamlDatabaseDiscoveryDataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) {
+ dataSources.add(swapToObject(entry.getKey(), entry.getValue()));
+ }
+ AlgorithmProvidedDatabaseDiscoveryRuleConfiguration ruleConfig = new AlgorithmProvidedDatabaseDiscoveryRuleConfiguration();
+ ruleConfig.setDataSources(dataSources);
+ return ruleConfig;
+ }
+
+ private DatabaseDiscoveryDataSourceRuleConfiguration swapToObject(final String name, final YamlDatabaseDiscoveryDataSourceRuleConfiguration yamlDataSourceRuleConfig) {
+ return new DatabaseDiscoveryDataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getDataSourceNames(), yamlDataSourceRuleConfig.getDiscoveryTypeName());
+ }
+
+ @Override
+ public Class<AlgorithmProvidedDatabaseDiscoveryRuleConfiguration> getTypeClass() {
+ return AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "DB_DISCOVERY";
+ }
+
+ @Override
+ public int getOrder() {
+ return DatabaseDiscoveryOrder.ALGORITHM_PROVIDER_DB_DISCOVERY_ORDER;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java
new file mode 100644
index 0000000..835eee7
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java
@@ -0,0 +1,94 @@
+/*
+ * 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.db.discovery.common.yaml.swapper;
+
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.infra.yaml.swapper.algorithm.ShardingSphereAlgorithmConfigurationYamlSwapper;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+/**
+ * Data base discovery rule configuration YAML swapper.
+ */
+public final class DatabaseDiscoveryRuleConfigurationYamlSwapper
+ implements YamlRuleConfigurationSwapper<YamlDatabaseDiscoveryRuleConfiguration, DatabaseDiscoveryRuleConfiguration> {
+
+ private final ShardingSphereAlgorithmConfigurationYamlSwapper algorithmSwapper = new ShardingSphereAlgorithmConfigurationYamlSwapper();
+
+ @Override
+ public YamlDatabaseDiscoveryRuleConfiguration swapToYamlConfiguration(final DatabaseDiscoveryRuleConfiguration data) {
+ YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration();
+ result.setDataSources(data.getDataSources().stream().collect(
+ Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
+ if (null != data.getDiscoveryTypes()) {
+ data.getDiscoveryTypes().forEach((key, value) -> result.getDiscoveryTypes().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
+ }
+ return result;
+ }
+
+ private YamlDatabaseDiscoveryDataSourceRuleConfiguration swapToYamlConfiguration(final DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig) {
+ YamlDatabaseDiscoveryDataSourceRuleConfiguration result = new YamlDatabaseDiscoveryDataSourceRuleConfiguration();
+ result.setName(dataSourceRuleConfig.getName());
+ result.setDataSourceNames(dataSourceRuleConfig.getDataSourceNames());
+ result.setDiscoveryTypeName(dataSourceRuleConfig.getDiscoveryTypeName());
+ return result;
+ }
+
+ @Override
+ public DatabaseDiscoveryRuleConfiguration swapToObject(final YamlDatabaseDiscoveryRuleConfiguration yamlConfig) {
+ Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources = new LinkedList<>();
+ for (Entry<String, YamlDatabaseDiscoveryDataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) {
+ dataSources.add(swapToObject(entry.getKey(), entry.getValue()));
+ }
+ Map<String, ShardingSphereAlgorithmConfiguration> haTypes = new LinkedHashMap<>(yamlConfig.getDiscoveryTypes().entrySet().size(), 1);
+ if (null != yamlConfig.getDiscoveryTypes()) {
+ yamlConfig.getDiscoveryTypes().forEach((key, value) -> haTypes.put(key, algorithmSwapper.swapToObject(value)));
+ }
+ return new DatabaseDiscoveryRuleConfiguration(dataSources, haTypes);
+ }
+
+ private DatabaseDiscoveryDataSourceRuleConfiguration swapToObject(final String name, final YamlDatabaseDiscoveryDataSourceRuleConfiguration yamlDataSourceRuleConfig) {
+ return new DatabaseDiscoveryDataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getDataSourceNames(), yamlDataSourceRuleConfig.getDiscoveryTypeName());
+ }
+
+ @Override
+ public Class<DatabaseDiscoveryRuleConfiguration> getTypeClass() {
+ return DatabaseDiscoveryRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "DB_DISCOVERY";
+ }
+
+ @Override
+ public int getOrder() {
+ return DatabaseDiscoveryOrder.ORDER;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
index c60ffcc..1873d9f 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.ha.rule.biulder.HARuleBuilder
-org.apache.shardingsphere.ha.rule.biulder.AlgorithmProvidedHARuleBuilder
+org.apache.shardingsphere.db.discovery.common.rule.biulder.DatabaseDiscoveryRuleBuilder
+org.apache.shardingsphere.db.discovery.common.rule.biulder.AlgorithmProvidedDatabaseDiscoveryRuleBuilder
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
similarity index 77%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
index efbf562..db624ee 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.ha.yaml.swapper.HARuleAlgorithmProviderConfigurationYamlSwapper
-org.apache.shardingsphere.ha.yaml.swapper.HARuleConfigurationYamlSwapper
+org.apache.shardingsphere.db.discovery.common.yaml.swapper.DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper
+org.apache.shardingsphere.db.discovery.common.yaml.swapper.DatabaseDiscoveryRuleConfigurationYamlSwapper
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/fixture/TestHATypeFixture.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/fixture/TestDatabaseDiscoveryTypeFixture.java
similarity index 84%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/fixture/TestHATypeFixture.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/fixture/TestDatabaseDiscoveryTypeFixture.java
index 91d419c..d56b1e4 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/fixture/TestHATypeFixture.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/fixture/TestDatabaseDiscoveryTypeFixture.java
@@ -5,7 +5,7 @@
* 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
@@ -15,21 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.fixture;
+package org.apache.shardingsphere.db.discovery.common.fixture;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
-/**
- * Test HA type.
- */
-public final class TestHATypeFixture implements HAType {
+public final class TestDatabaseDiscoveryTypeFixture implements DatabaseDiscoveryType {
@Override
- public void checkHAConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) {
+ public void checkDatabaseDiscoveryConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) {
}
@Override
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRuleTest.java
similarity index 50%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRuleTest.java
index 57dbb16..965571e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HADataSourceRuleTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryDataSourceRuleTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule;
+package org.apache.shardingsphere.db.discovery.common.rule;
import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.mgr.MGRHAType;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.mgr.MGRDatabaseDiscoveryType;
import org.junit.Test;
import java.util.Arrays;
@@ -30,53 +30,53 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public final class HADataSourceRuleTest {
+public final class DatabaseDiscoveryDataSourceRuleTest {
- private final HADataSourceRule haDataSourceRule = new HADataSourceRule(
- new HADataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "haTypeName"), new MGRHAType());
+ private final DatabaseDiscoveryDataSourceRule databaseDiscoveryDataSourceRule = new DatabaseDiscoveryDataSourceRule(
+ new DatabaseDiscoveryDataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "discoveryTypeName"), new MGRDatabaseDiscoveryType());
@Test(expected = IllegalArgumentException.class)
public void assertNewHADataSourceRuleWithoutName() {
- new HADataSourceRule(new HADataSourceRuleConfiguration("", Arrays.asList("ds_0", "ds_1"), "haTypeName"), new MGRHAType());
+ new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration("", Arrays.asList("ds_0", "ds_1"), "discoveryTypeName"), new MGRDatabaseDiscoveryType());
}
@Test(expected = IllegalArgumentException.class)
public void assertNewHADataSourceRuleWithNullDataSourceName() {
- new HADataSourceRule(new HADataSourceRuleConfiguration("ds", null, "haTypeName"), new MGRHAType());
+ new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration("ds", null, "discoveryTypeName"), new MGRDatabaseDiscoveryType());
}
@Test(expected = IllegalArgumentException.class)
public void assertNewHADataSourceRuleWithEmptyDataSourceName() {
- new HADataSourceRule(new HADataSourceRuleConfiguration("ds", Collections.emptyList(), "haTypeName"), new MGRHAType());
+ new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.emptyList(), "discoveryTypeName"), new MGRDatabaseDiscoveryType());
}
@Test
public void assertGetDataSourceNamesWithoutDisabledDataSourceNames() {
- assertThat(haDataSourceRule.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
+ assertThat(databaseDiscoveryDataSourceRule.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
}
@Test
public void assertGetDataSourceNamesWithDisabledDataSourceNames() {
- haDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
- assertThat(haDataSourceRule.getDataSourceNames(), is(Collections.singletonList("ds_1")));
+ databaseDiscoveryDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
+ assertThat(databaseDiscoveryDataSourceRule.getDataSourceNames(), is(Collections.singletonList("ds_1")));
}
@Test
public void assertUpdateDisabledDataSourceNamesForDisabled() {
- haDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
- assertThat(haDataSourceRule.getDataSourceNames(), is(Collections.singletonList("ds_1")));
+ databaseDiscoveryDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
+ assertThat(databaseDiscoveryDataSourceRule.getDataSourceNames(), is(Collections.singletonList("ds_1")));
}
@Test
public void assertUpdateDisabledDataSourceNamesForEnabled() {
- haDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
- haDataSourceRule.updateDisabledDataSourceNames("ds_0", false);
- assertThat(haDataSourceRule.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
+ databaseDiscoveryDataSourceRule.updateDisabledDataSourceNames("ds_0", true);
+ databaseDiscoveryDataSourceRule.updateDisabledDataSourceNames("ds_0", false);
+ assertThat(databaseDiscoveryDataSourceRule.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
}
@Test
public void assertGetDataSourceMapper() {
- Map<String, Collection<String>> actual = haDataSourceRule.getDataSourceMapper();
+ Map<String, Collection<String>> actual = databaseDiscoveryDataSourceRule.getDataSourceMapper();
Map<String, Collection<String>> expected = ImmutableMap.of("test_pr", Arrays.asList("ds_0", "ds_1"));
assertThat(actual, is(expected));
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HARuleTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRuleTest.java
similarity index 55%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HARuleTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRuleTest.java
index 83a81dc..8bcfb94 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/HARuleTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRuleTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule;
+package org.apache.shardingsphere.db.discovery.common.rule;
import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
@@ -38,18 +38,18 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-public final class HARuleTest {
+public final class DatabaseDiscoveryRuleTest {
private final Map<String, DataSource> dataSourceMap = Collections.singletonMap("ds", mock(DataSource.class));
@Test(expected = IllegalArgumentException.class)
public void assertNewWithEmptyDataSourceRule() {
- new HARule(new HARuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(DatabaseType.class), dataSourceMap, "ha_db");
+ new DatabaseDiscoveryRule(new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap()), mock(DatabaseType.class), dataSourceMap, "ha_db");
}
@Test
public void assertFindDataSourceRule() {
- Optional<HADataSourceRule> actual = createHARule().findDataSourceRule("test_pr");
+ Optional<DatabaseDiscoveryDataSourceRule> actual = createHARule().findDataSourceRule("test_pr");
assertTrue(actual.isPresent());
assertDataSourceRule(actual.get());
}
@@ -59,46 +59,46 @@ public final class HARuleTest {
assertDataSourceRule(createHARule().getSingleDataSourceRule());
}
- private HARule createHARule() {
- HADataSourceRuleConfiguration config =
- new HADataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "haTypeName");
- return new HARule(new HARuleConfiguration(
+ private DatabaseDiscoveryRule createHARule() {
+ DatabaseDiscoveryDataSourceRuleConfiguration config =
+ new DatabaseDiscoveryDataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "discoveryTypeName");
+ return new DatabaseDiscoveryRule(new DatabaseDiscoveryRuleConfiguration(
Collections.singleton(config), ImmutableMap.of("mgr", new ShardingSphereAlgorithmConfiguration("MGR", new Properties()))),
mock(DatabaseType.class), dataSourceMap, "ha_db");
}
- private void assertDataSourceRule(final HADataSourceRule actual) {
+ private void assertDataSourceRule(final DatabaseDiscoveryDataSourceRule actual) {
assertThat(actual.getName(), is("test_pr"));
assertThat(actual.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
}
@Test
public void assertUpdateRuleStatusWithNotExistDataSource() {
- HARule haRule = createHARule();
- haRule.updateRuleStatus(new DataSourceNameDisabledEvent("db", true));
- assertThat(haRule.getSingleDataSourceRule().getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
+ DatabaseDiscoveryRule databaseDiscoveryRule = createHARule();
+ databaseDiscoveryRule.updateRuleStatus(new DataSourceNameDisabledEvent("db", true));
+ assertThat(databaseDiscoveryRule.getSingleDataSourceRule().getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
}
@Test
public void assertUpdateRuleStatus() {
- HARule haRule = createHARule();
- haRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", true));
- assertThat(haRule.getSingleDataSourceRule().getDataSourceNames(), is(Collections.singletonList("ds_1")));
+ DatabaseDiscoveryRule databaseDiscoveryRule = createHARule();
+ databaseDiscoveryRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", true));
+ assertThat(databaseDiscoveryRule.getSingleDataSourceRule().getDataSourceNames(), is(Collections.singletonList("ds_1")));
}
@Test
public void assertUpdateRuleStatusWithEnable() {
- HARule haRule = createHARule();
- haRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", true));
- assertThat(haRule.getSingleDataSourceRule().getDataSourceNames(), is(Collections.singletonList("ds_1")));
- haRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", false));
- assertThat(haRule.getSingleDataSourceRule().getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
+ DatabaseDiscoveryRule databaseDiscoveryRule = createHARule();
+ databaseDiscoveryRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", true));
+ assertThat(databaseDiscoveryRule.getSingleDataSourceRule().getDataSourceNames(), is(Collections.singletonList("ds_1")));
+ databaseDiscoveryRule.updateRuleStatus(new DataSourceNameDisabledEvent("ds_0", false));
+ assertThat(databaseDiscoveryRule.getSingleDataSourceRule().getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
}
@Test
public void assertGetDataSourceMapper() {
- HARule haRule = createHARule();
- Map<String, Collection<String>> actual = haRule.getDataSourceMapper();
+ DatabaseDiscoveryRule databaseDiscoveryRule = createHARule();
+ Map<String, Collection<String>> actual = databaseDiscoveryRule.getDataSourceMapper();
Map<String, Collection<String>> expected = ImmutableMap.of("test_pr", Arrays.asList("ds_0", "ds_1"));
assertThat(actual, is(expected));
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
similarity index 69%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
index e364663..1eaae12 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/AlgorithmProvidedHARuleBuilderTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule.biulder;
+package org.apache.shardingsphere.db.discovery.common.rule.biulder;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
import org.junit.Test;
import java.util.Collections;
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class AlgorithmProvidedHARuleBuilderTest {
+public final class AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
static {
ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
@@ -41,12 +41,12 @@ public final class AlgorithmProvidedHARuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test(expected = IllegalArgumentException.class)
public void assertBuild() {
- AlgorithmProvidedHARuleConfiguration algorithmProvidedRuleConfig = mock(AlgorithmProvidedHARuleConfiguration.class);
- HADataSourceRuleConfiguration ruleConfig = new HADataSourceRuleConfiguration(
- "name", Collections.singletonList("name"), "haTypeName");
+ AlgorithmProvidedDatabaseDiscoveryRuleConfiguration algorithmProvidedRuleConfig = mock(AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class);
+ DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(
+ "name", Collections.singletonList("name"), "discoveryTypeName");
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(
Collections.singletonList(algorithmProvidedRuleConfig), ShardingSphereRuleBuilder.class).get(algorithmProvidedRuleConfig);
- assertThat(builder.build(algorithmProvidedRuleConfig), instanceOf(HARule.class));
+ assertThat(builder.build(algorithmProvidedRuleConfig), instanceOf(DatabaseDiscoveryRule.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilderTest.java
similarity index 69%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilderTest.java
index 87e278c..73f0d1e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/rule/biulder/HARuleBuilderTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/rule/biulder/DatabaseDiscoveryRuleBuilderTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.rule.biulder;
+package org.apache.shardingsphere.db.discovery.common.rule.biulder;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class HARuleBuilderTest {
+public final class DatabaseDiscoveryRuleBuilderTest {
static {
ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
@@ -44,14 +44,14 @@ public final class HARuleBuilderTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test(expected = IllegalArgumentException.class)
public void assertBuild() {
- HARuleConfiguration ruleConfig = mock(HARuleConfiguration.class);
- HADataSourceRuleConfiguration dataSourceRuleConfig = new HADataSourceRuleConfiguration(
- "name", Collections.singletonList("name"), "haTypeName");
+ DatabaseDiscoveryRuleConfiguration ruleConfig = mock(DatabaseDiscoveryRuleConfiguration.class);
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(
+ "name", Collections.singletonList("name"), "discoveryTypeName");
when(ruleConfig.getDataSources()).thenReturn(Collections.singletonList(dataSourceRuleConfig));
ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), ShardingSphereRuleBuilder.class).get(ruleConfig);
Map<String, DataSource> dataSourceMap = new HashMap<>();
dataSourceMap.put("primaryDataSourceName", mock(DataSource.class));
- ((HARuleBuilder) builder).setDataSourceMap(dataSourceMap);
- assertThat(builder.build(ruleConfig), instanceOf(HARule.class));
+ ((DatabaseDiscoveryRuleBuilder) builder).setDataSourceMap(dataSourceMap);
+ assertThat(builder.build(ruleConfig), instanceOf(DatabaseDiscoveryRule.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java
similarity index 52%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java
index 6274951..50582cb 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapperTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.yaml.swapper;
+package org.apache.shardingsphere.db.discovery.common.yaml.swapper;
import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.mgr.MGRHAType;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.mgr.MGRDatabaseDiscoveryType;
import org.junit.Test;
import java.util.Collections;
@@ -33,13 +33,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public final class HARuleAlgorithmProviderConfigurationYamlSwapperTest {
+public final class DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest {
- private final HARuleAlgorithmProviderConfigurationYamlSwapper swapper = new HARuleAlgorithmProviderConfigurationYamlSwapper();
+ private final DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper swapper = new DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper();
@Test
public void assertSwapToYamlConfiguration() {
- YamlHARuleConfiguration actual = createYamlHARuleConfiguration();
+ YamlDatabaseDiscoveryRuleConfiguration actual = createYamlHARuleConfiguration();
assertNotNull(actual);
assertNotNull(actual.getDataSources());
assertThat(actual.getDataSources().keySet(), is(Collections.singleton("name")));
@@ -48,34 +48,34 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapperTest {
@Test
public void assertSwapToObject() {
- AlgorithmProvidedHARuleConfiguration actual = swapper.swapToObject(createYamlHARuleConfiguration());
+ AlgorithmProvidedDatabaseDiscoveryRuleConfiguration actual = swapper.swapToObject(createYamlHARuleConfiguration());
assertNotNull(actual);
assertNotNull(actual.getDataSources());
assertTrue(actual.getDataSources().iterator().hasNext());
- HADataSourceRuleConfiguration ruleConfig = actual.getDataSources().iterator().next();
+ DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = actual.getDataSources().iterator().next();
assertNotNull(ruleConfig);
assertThat(ruleConfig.getName(), is("name"));
}
@Test
public void assertGetTypeClass() {
- assertThat(swapper.getTypeClass(), equalTo(AlgorithmProvidedHARuleConfiguration.class));
+ assertThat(swapper.getTypeClass(), equalTo(AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class));
}
@Test
public void assertGetRuleTagName() {
- assertThat(swapper.getRuleTagName(), is("HA"));
+ assertThat(swapper.getRuleTagName(), is("DB_DISCOVERY"));
}
@Test
public void assertGetOrder() {
- assertThat(swapper.getOrder(), is(HAOrder.ALGORITHM_PROVIDER_HA_ORDER));
+ assertThat(swapper.getOrder(), is(DatabaseDiscoveryOrder.ALGORITHM_PROVIDER_DB_DISCOVERY_ORDER));
}
- private YamlHARuleConfiguration createYamlHARuleConfiguration() {
- HADataSourceRuleConfiguration ruleConfig = new HADataSourceRuleConfiguration("name",
- Collections.singletonList("dataSourceNames"), "haTypeName");
+ private YamlDatabaseDiscoveryRuleConfiguration createYamlHARuleConfiguration() {
+ DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("name",
+ Collections.singletonList("dataSourceNames"), "discoveryTypeName");
return swapper.swapToYamlConfiguration(
- new AlgorithmProvidedHARuleConfiguration(Collections.singletonList(ruleConfig), ImmutableMap.of("mgr", new MGRHAType())));
+ new AlgorithmProvidedDatabaseDiscoveryRuleConfiguration(Collections.singletonList(ruleConfig), ImmutableMap.of("mgr", new MGRDatabaseDiscoveryType())));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java
new file mode 100644
index 0000000..0e577b8
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.db.discovery.common.yaml.swapper;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class DatabaseDiscoveryRuleConfigurationYamlSwapperTest {
+
+ private final Collection<YamlRuleConfigurationSwapper> collection = ShardingSphereServiceLoader.newServiceInstances(YamlRuleConfigurationSwapper.class);
+
+ static {
+ ShardingSphereServiceLoader.register(YamlRuleConfigurationSwapper.class);
+ }
+
+ @Test
+ public void assertSwapToYamlWithLoadBalanceAlgorithm() {
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig =
+ new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"), "discoveryTypeName");
+ YamlDatabaseDiscoveryRuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToYamlConfiguration(new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig),
+ ImmutableMap.of("mgr", new ShardingSphereAlgorithmConfiguration("MGR", new Properties()))));
+ assertThat(actual.getDataSources().get("ds").getName(), is("ds"));
+ assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
+ }
+
+ @Test
+ public void assertSwapToYamlWithoutLoadBalanceAlgorithm() {
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"), "discoveryTypeName");
+ YamlDatabaseDiscoveryRuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToYamlConfiguration(
+ new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig), Collections.emptyMap()));
+ assertThat(actual.getDataSources().get("ds").getName(), is("ds"));
+ assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
+ }
+
+ @Test
+ public void assertSwapToObjectWithLoadBalanceAlgorithmType() {
+ YamlDatabaseDiscoveryRuleConfiguration yamlConfig = createYamlHARuleConfiguration();
+ DatabaseDiscoveryRuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToObject(yamlConfig);
+ assertHARuleConfiguration(actual);
+ }
+
+ @Test
+ public void assertSwapToObjectWithoutLoadBalanceAlgorithm() {
+ YamlDatabaseDiscoveryRuleConfiguration yamlConfig = createYamlHARuleConfiguration();
+ DatabaseDiscoveryRuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToObject(yamlConfig);
+ assertHARuleConfiguration(actual);
+ }
+
+ private YamlDatabaseDiscoveryRuleConfiguration createYamlHARuleConfiguration() {
+ YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration();
+ result.getDataSources().put("ha_ds", new YamlDatabaseDiscoveryDataSourceRuleConfiguration());
+ result.getDataSources().get("ha_ds").setName("ha_ds");
+ result.getDataSources().get("ha_ds").setDataSourceNames(Arrays.asList("ds_0", "ds_1"));
+ return result;
+ }
+
+ private void assertHARuleConfiguration(final DatabaseDiscoveryRuleConfiguration actual) {
+ DatabaseDiscoveryDataSourceRuleConfiguration group = actual.getDataSources().iterator().next();
+ assertThat(group.getName(), is("ha_ds"));
+ assertThat(group.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
+ }
+
+ @Test
+ public void assertGetTypeClass() {
+ DatabaseDiscoveryRuleConfigurationYamlSwapper swapper = getHARuleConfigurationYamlSwapper();
+ Class<DatabaseDiscoveryRuleConfiguration> actual = swapper.getTypeClass();
+ assertTrue(actual.isAssignableFrom(DatabaseDiscoveryRuleConfiguration.class));
+ }
+
+ @Test
+ public void assertGetOrder() {
+ DatabaseDiscoveryRuleConfigurationYamlSwapper swapper = getHARuleConfigurationYamlSwapper();
+ int actual = swapper.getOrder();
+ assertThat(actual, is(DatabaseDiscoveryOrder.ORDER));
+ }
+
+ private DatabaseDiscoveryRuleConfigurationYamlSwapper getHARuleConfigurationYamlSwapper() {
+ Optional<DatabaseDiscoveryRuleConfigurationYamlSwapper> optional = collection.stream()
+ .filter(swapper -> swapper instanceof DatabaseDiscoveryRuleConfigurationYamlSwapper)
+ .map(swapper -> (DatabaseDiscoveryRuleConfigurationYamlSwapper) swapper)
+ .findFirst();
+ assertTrue(optional.isPresent());
+ return optional.get();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/YamlRootRuleConfigurationsForYamlHARuleConfigurationTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java
similarity index 78%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/YamlRootRuleConfigurationsForYamlHARuleConfigurationTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java
index 9be5754..901d64e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/YamlRootRuleConfigurationsForYamlHARuleConfigurationTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/java/org/apache/shardingsphere/db/discovery/common/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.yaml.swapper;
+package org.apache.shardingsphere.db.discovery.common.yaml.swapper;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
import org.junit.Test;
import java.io.BufferedReader;
@@ -33,20 +33,20 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-public final class YamlRootRuleConfigurationsForYamlHARuleConfigurationTest {
+public final class YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest {
@Test
public void assertUnmarshalWithYamlFile() throws IOException {
- URL url = getClass().getClassLoader().getResource("yaml/ha-rule.yaml");
+ URL url = getClass().getClassLoader().getResource("yaml/db-discovery-rule.yaml");
assertNotNull(url);
YamlRootRuleConfigurations rootRuleConfigs = YamlEngine.unmarshal(new File(url.getFile()), YamlRootRuleConfigurations.class);
assertThat(rootRuleConfigs.getRules().size(), is(1));
- assertHARule((YamlHARuleConfiguration) rootRuleConfigs.getRules().iterator().next());
+ assertHARule((YamlDatabaseDiscoveryRuleConfiguration) rootRuleConfigs.getRules().iterator().next());
}
@Test
public void assertUnmarshalWithYamlBytes() throws IOException {
- URL url = getClass().getClassLoader().getResource("yaml/ha-rule.yaml");
+ URL url = getClass().getClassLoader().getResource("yaml/db-discovery-rule.yaml");
assertNotNull(url);
StringBuilder yamlContent = new StringBuilder();
try (
@@ -59,20 +59,20 @@ public final class YamlRootRuleConfigurationsForYamlHARuleConfigurationTest {
}
YamlRootRuleConfigurations rootRuleConfigs = YamlEngine.unmarshal(yamlContent.toString().getBytes(), YamlRootRuleConfigurations.class);
assertThat(rootRuleConfigs.getRules().size(), is(1));
- assertHARule((YamlHARuleConfiguration) rootRuleConfigs.getRules().iterator().next());
+ assertHARule((YamlDatabaseDiscoveryRuleConfiguration) rootRuleConfigs.getRules().iterator().next());
}
- private void assertHARule(final YamlHARuleConfiguration actual) {
+ private void assertHARule(final YamlDatabaseDiscoveryRuleConfiguration actual) {
assertThat(actual.getDataSources().size(), is(2));
assertHARuleForDs0(actual);
assertHARuleForDs1(actual);
}
- private void assertHARuleForDs0(final YamlHARuleConfiguration actual) {
+ private void assertHARuleForDs0(final YamlDatabaseDiscoveryRuleConfiguration actual) {
assertThat(actual.getDataSources().get("ds_0").getDataSourceNames(), is(Arrays.asList("primary_ds_0_replica_0", "primary_ds_0_replica_1")));
}
- private void assertHARuleForDs1(final YamlHARuleConfiguration actual) {
+ private void assertHARuleForDs1(final YamlDatabaseDiscoveryRuleConfiguration actual) {
assertThat(actual.getDataSources().get("ds_1").getDataSourceNames(), is(Arrays.asList("primary_ds_1_replica_0", "primary_ds_1_replica_1")));
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
similarity index 90%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
index 15e71e6..1195bf3 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.ha.fixture.TestHATypeFixture
+org.apache.shardingsphere.db.discovery.common.fixture.TestDatabaseDiscoveryTypeFixture
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/logback-test.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/logback-test.xml
similarity index 100%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/logback-test.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/logback-test.xml
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/yaml/db-discovery-rule.yaml
similarity index 96%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/yaml/db-discovery-rule.yaml
index e45f03b..1a23ef7 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/yaml/ha-rule.yaml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/test/resources/yaml/db-discovery-rule.yaml
@@ -54,19 +54,19 @@ dataSources:
password:
rules:
-- !HA
+- !DB_DISCOVERY
dataSources:
ds_0:
dataSourceNames:
- primary_ds_0_replica_0
- primary_ds_0_replica_1
- haTypeName: mgr
+ discoveryTypeName: mgr
ds_1:
dataSourceNames:
- primary_ds_1_replica_0
- primary_ds_1_replica_1
- haTypeName: mgr
- haTypes:
+ discoveryTypeName: mgr
+ discoveryTypes:
mgr:
type: MGR
props:
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/pom.xml
similarity index 88%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/pom.xml
index 8854633..658b9e8 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/pom.xml
@@ -22,14 +22,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-provider</artifactId>
+ <artifactId>shardingsphere-db-discovery-provider</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
- <module>shardingsphere-ha-mgr</module>
+ <module>shardingsphere-db-discovery-mgr</module>
</modules>
</project>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
similarity index 90%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
index ab05241..36776a1 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
@@ -22,16 +22,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-provider</artifactId>
+ <artifactId>shardingsphere-db-discovery-provider</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-mgr</artifactId>
+ <artifactId>shardingsphere-db-discovery-mgr</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-api</artifactId>
+ <artifactId>shardingsphere-db-discovery-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHAType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryType.java
similarity index 97%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHAType.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryType.java
index 3bd82cc..5e0ba09 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHAType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryType.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.mgr;
+package org.apache.shardingsphere.db.discovery.mgr;
import lombok.Getter;
import lombok.Setter;
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobB
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
@@ -45,10 +45,10 @@ import java.util.Map.Entry;
import java.util.Properties;
/**
- * MGR HA type.
+ * MGR data base discovery type.
*/
@Slf4j
-public final class MGRHAType implements HAType {
+public final class MGRDatabaseDiscoveryType implements DatabaseDiscoveryType {
private static final String PLUGIN_STATUS = "SELECT * FROM information_schema.PLUGINS WHERE PLUGIN_NAME='group_replication'";
@@ -71,7 +71,7 @@ public final class MGRHAType implements HAType {
private Properties props = new Properties();
@Override
- public void checkHAConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) throws SQLException {
+ public void checkDatabaseDiscoveryConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) throws SQLException {
try (Connection connection = dataSourceMap.get(oldPrimaryDataSource).getConnection();
Statement statement = connection.createStatement()) {
checkPluginIsActive(statement);
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHeartbeatJob.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRHeartbeatJob.java
similarity index 78%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHeartbeatJob.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRHeartbeatJob.java
index 9c6ec7d..7011fb1 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/main/java/org/apache/shardingsphere/ha/mgr/MGRHeartbeatJob.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/db/discovery/mgr/MGRHeartbeatJob.java
@@ -5,7 +5,7 @@
* 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
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.mgr;
+package org.apache.shardingsphere.db.discovery.mgr;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import javax.sql.DataSource;
import java.util.Collection;
@@ -34,7 +34,7 @@ import java.util.Map;
@Slf4j
public final class MGRHeartbeatJob implements SimpleJob {
- private final HAType haType;
+ private final DatabaseDiscoveryType databaseDiscoveryType;
private final Map<String, DataSource> dataSourceMap;
@@ -48,7 +48,7 @@ public final class MGRHeartbeatJob implements SimpleJob {
@Override
public void execute(final ShardingContext shardingContext) {
- haType.updatePrimaryDataSource(dataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
- haType.updateMemberState(dataSourceMap, schemaName, disabledDataSourceNames);
+ databaseDiscoveryType.updatePrimaryDataSource(dataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
+ databaseDiscoveryType.updateMemberState(dataSourceMap, schemaName, disabledDataSourceNames);
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
new file mode 100644
index 0000000..b02fe45
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+#
+# 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.db.discovery.mgr.MGRDatabaseDiscoveryType
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/test/java/org/apache/shardingsphere/ha/mgr/MGRHATypeTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/test/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryTypeTest.java
similarity index 93%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/test/java/org/apache/shardingsphere/ha/mgr/MGRHATypeTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/test/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryTypeTest.java
index 2f909c0..1d31e26 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-provider/shardingsphere-ha-mgr/src/test/java/org/apache/shardingsphere/ha/mgr/MGRHATypeTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/test/java/org/apache/shardingsphere/db/discovery/mgr/MGRDatabaseDiscoveryTypeTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.mgr;
+package org.apache.shardingsphere.db.discovery.mgr;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.junit.Test;
@@ -37,7 +37,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class MGRHATypeTest {
+public final class MGRDatabaseDiscoveryTypeTest {
private static final String PLUGIN_STATUS = "SELECT * FROM information_schema.PLUGINS WHERE PLUGIN_NAME='group_replication'";
@@ -47,7 +47,7 @@ public final class MGRHATypeTest {
private static final String SINGLE_PRIMARY = "SELECT * FROM performance_schema.global_variables WHERE VARIABLE_NAME='group_replication_single_primary_mode'";
- private final MGRHAType mgrHaType = new MGRHAType();
+ private final MGRDatabaseDiscoveryType mgrHaType = new MGRDatabaseDiscoveryType();
@Test
public void checkHAConfig() {
@@ -73,7 +73,7 @@ public final class MGRHATypeTest {
when(dataSourceMap.get(null)).thenReturn(dataSource);
try {
mgrHaType.getProps().setProperty("groupName", "group_name");
- mgrHaType.checkHAConfig(dataSourceMap, "ha_db");
+ mgrHaType.checkDatabaseDiscoveryConfig(dataSourceMap, "discovery_db");
} catch (final SQLException ex) {
throw new ShardingSphereException(ex);
}
@@ -114,7 +114,7 @@ public final class MGRHATypeTest {
dataSourceMap.put(String.format("ds_%s", i), dataSources.get(i));
}
mgrHaType.getProps().setProperty("groupName", "group_name");
- mgrHaType.updatePrimaryDataSource(dataSourceMap, "ha_db", Collections.emptySet(), "group_name", null);
+ mgrHaType.updatePrimaryDataSource(dataSourceMap, "discovery_db", Collections.emptySet(), "group_name", null);
assertThat(mgrHaType.getPrimaryDataSource(), is("ds_2"));
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/pom.xml
similarity index 89%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/pom.xml
index dcfa33e..a3ddf63 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/pom.xml
@@ -22,10 +22,10 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-route</artifactId>
+ <artifactId>shardingsphere-db-discovery-route</artifactId>
<name>${project.artifactId}</name>
<dependencies>
@@ -36,7 +36,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/HASQLRouter.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/DatabaseDiscoverySQLRouter.java
similarity index 68%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/HASQLRouter.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/DatabaseDiscoverySQLRouter.java
index be21016..ab0e287 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/HASQLRouter.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/DatabaseDiscoverySQLRouter.java
@@ -5,7 +5,7 @@
* 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
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.route.engine;
+package org.apache.shardingsphere.db.discovery.route;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
+import org.apache.shardingsphere.db.discovery.route.impl.DatabaseDiscoveryDataSourceRouter;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -26,9 +27,8 @@ import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.binder.LogicSQL;
-import org.apache.shardingsphere.ha.route.engine.impl.HADataSourceRouter;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.rule.HADataSourceRule;
+import org.apache.shardingsphere.db.discovery.common.constant.DatabaseDiscoveryOrder;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryDataSourceRule;
import java.util.Collection;
import java.util.Collections;
@@ -36,29 +36,29 @@ import java.util.LinkedList;
import java.util.Optional;
/**
- * HA SQL router.
+ * Data base discovery SQL router.
*/
-public final class HASQLRouter implements SQLRouter<HARule> {
+public final class DatabaseDiscoverySQLRouter implements SQLRouter<DatabaseDiscoveryRule> {
@Override
- public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final HARule rule, final ConfigurationProperties props) {
+ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
RouteContext result = new RouteContext();
- String dataSourceName = new HADataSourceRouter(rule.getSingleDataSourceRule()).route();
+ String dataSourceName = new DatabaseDiscoveryDataSourceRouter(rule.getSingleDataSourceRule()).route();
result.getRouteUnits().add(new RouteUnit(new RouteMapper(DefaultSchema.LOGIC_NAME, dataSourceName), Collections.emptyList()));
return result;
}
@Override
public void decorateRouteContext(final RouteContext routeContext,
- final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final HARule rule, final ConfigurationProperties props) {
+ final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
Collection<RouteUnit> toBeRemoved = new LinkedList<>();
Collection<RouteUnit> toBeAdded = new LinkedList<>();
for (RouteUnit each : routeContext.getRouteUnits()) {
String dataSourceName = each.getDataSourceMapper().getLogicName();
- Optional<HADataSourceRule> dataSourceRule = rule.findDataSourceRule(dataSourceName);
+ Optional<DatabaseDiscoveryDataSourceRule> dataSourceRule = rule.findDataSourceRule(dataSourceName);
if (dataSourceRule.isPresent() && dataSourceRule.get().getName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) {
toBeRemoved.add(each);
- String actualDataSourceName = new HADataSourceRouter(dataSourceRule.get()).route();
+ String actualDataSourceName = new DatabaseDiscoveryDataSourceRouter(dataSourceRule.get()).route();
toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers()));
}
}
@@ -68,11 +68,11 @@ public final class HASQLRouter implements SQLRouter<HARule> {
@Override
public int getOrder() {
- return HAOrder.ORDER;
+ return DatabaseDiscoveryOrder.ORDER;
}
@Override
- public Class<HARule> getTypeClass() {
- return HARule.class;
+ public Class<DatabaseDiscoveryRule> getTypeClass() {
+ return DatabaseDiscoveryRule.class;
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/impl/HADataSourceRouter.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/impl/DatabaseDiscoveryDataSourceRouter.java
similarity index 76%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/impl/HADataSourceRouter.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/impl/DatabaseDiscoveryDataSourceRouter.java
index a71c41b..2718304 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/java/org/apache/shardingsphere/ha/route/engine/impl/HADataSourceRouter.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/java/org/apache/shardingsphere/db/discovery/route/impl/DatabaseDiscoveryDataSourceRouter.java
@@ -5,7 +5,7 @@
* 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
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.route.engine.impl;
+package org.apache.shardingsphere.db.discovery.route.impl;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.ha.rule.HADataSourceRule;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryDataSourceRule;
/**
- * Data source router for HA.
+ * Data source router for Data base discovery.
*/
@RequiredArgsConstructor
-public final class HADataSourceRouter {
+public final class DatabaseDiscoveryDataSourceRouter {
- private final HADataSourceRule rule;
+ private final DatabaseDiscoveryDataSourceRule rule;
/**
* Route.
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
similarity index 91%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
index 9291141..a57ea99 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.ha.route.engine.HASQLRouter
+org.apache.shardingsphere.db.discovery.route.DatabaseDiscoverySQLRouter
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/engine/DatabaseDiscoverySQLRouterTest.java
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/engine/DatabaseDiscoverySQLRouterTest.java
index e80bfb0..1cf3a49 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/engine/HASQLRouterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/engine/DatabaseDiscoverySQLRouterTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.route.engine;
+package org.apache.shardingsphere.db.discovery.route.engine;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.rule.HARule;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.rule.DatabaseDiscoveryRule;
+import org.apache.shardingsphere.db.discovery.route.DatabaseDiscoverySQLRouter;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
@@ -52,20 +53,20 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@RunWith(MockitoJUnitRunner.class)
-public final class HASQLRouterTest {
+public final class DatabaseDiscoverySQLRouterTest {
private static final String DATASOURCE_NAME = "ds";
- private static final String NONE_HA_DATASOURCE_NAME = "noneHADatasource";
+ private static final String NONE_DB_DISCOVERY_DATASOURCE_NAME = "noneDatabaseDiscoveryDatasource";
private static final String PRIMARY_DATASOURCE = "primary";
- private HARule rule;
+ private DatabaseDiscoveryRule rule;
@Mock
private SQLStatementContext<SQLStatement> sqlStatementContext;
- private HASQLRouter sqlRouter;
+ private DatabaseDiscoverySQLRouter sqlRouter;
static {
ShardingSphereServiceLoader.register(SQLRouter.class);
@@ -73,10 +74,12 @@ public final class HASQLRouterTest {
@Before
public void setUp() {
- HADataSourceRuleConfiguration haDataSourceRuleConfiguration = new HADataSourceRuleConfiguration(DATASOURCE_NAME, Collections.singletonList(PRIMARY_DATASOURCE), "haTypeName");
- HARuleConfiguration haRuleConfiguration = new HARuleConfiguration(Collections.singleton(haDataSourceRuleConfiguration), Collections.emptyMap());
- rule = new HARule(haRuleConfiguration, mock(DatabaseType.class), Collections.singletonMap("ds", mock(DataSource.class)), "ha_db");
- sqlRouter = (HASQLRouter) OrderedSPIRegistry.getRegisteredServices(Collections.singleton(rule), SQLRouter.class).get(rule);
+ DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfiguration
+ = new DatabaseDiscoveryDataSourceRuleConfiguration(DATASOURCE_NAME, Collections.singletonList(PRIMARY_DATASOURCE), "discoveryTypeName");
+ DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration
+ = new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration), Collections.emptyMap());
+ rule = new DatabaseDiscoveryRule(databaseDiscoveryRuleConfiguration, mock(DatabaseType.class), Collections.singletonMap("ds", mock(DataSource.class)), "ha_db");
+ sqlRouter = (DatabaseDiscoverySQLRouter) OrderedSPIRegistry.getRegisteredServices(Collections.singleton(rule), SQLRouter.class).get(rule);
}
@Test
@@ -97,7 +100,7 @@ public final class HASQLRouterTest {
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
+ assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATASOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
}
@@ -119,7 +122,7 @@ public final class HASQLRouterTest {
mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), mock(ShardingSphereSchema.class));
sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(NONE_HA_DATASOURCE_NAME));
+ assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATASOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATASOURCE));
}
@@ -137,7 +140,7 @@ public final class HASQLRouterTest {
RouteContext result = new RouteContext();
RouteUnit routeUnit = new RouteUnit(new RouteMapper(DATASOURCE_NAME, DATASOURCE_NAME), Collections.singletonList(new RouteMapper("table", "table_0")));
result.getRouteUnits().add(routeUnit);
- result.getRouteUnits().add(new RouteUnit(new RouteMapper(NONE_HA_DATASOURCE_NAME, NONE_HA_DATASOURCE_NAME), Collections.emptyList()));
+ result.getRouteUnits().add(new RouteUnit(new RouteMapper(NONE_DB_DISCOVERY_DATASOURCE_NAME, NONE_DB_DISCOVERY_DATASOURCE_NAME), Collections.emptyList()));
return result;
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/fixture/TestRouteHATypeFixture.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/fixture/TestRouteDatabaseDiscoveryTypeFixture.java
similarity index 84%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/fixture/TestRouteHATypeFixture.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/fixture/TestRouteDatabaseDiscoveryTypeFixture.java
index b418ac2..623ff46 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/java/org/apache/shardingsphere/ha/route/fixture/TestRouteHATypeFixture.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/java/org/apache/shardingsphere/db/discovery/route/fixture/TestRouteDatabaseDiscoveryTypeFixture.java
@@ -5,7 +5,7 @@
* 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
@@ -15,21 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.route.fixture;
+package org.apache.shardingsphere.db.discovery.route.fixture;
-import org.apache.shardingsphere.ha.spi.HAType;
+import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
-/**
- * Test HA type.
- */
-public final class TestRouteHATypeFixture implements HAType {
+public final class TestRouteDatabaseDiscoveryTypeFixture implements DatabaseDiscoveryType {
@Override
- public void checkHAConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) {
+ public void checkDatabaseDiscoveryConfig(final Map<String, DataSource> dataSourceMap, final String schemaName) {
}
@Override
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
similarity index 89%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
index a0e7a7f..74977d1 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-route/src/test/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-route/src/test/resources/META-INF/services/org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.ha.route.fixture.TestRouteHATypeFixture
+org.apache.shardingsphere.db.discovery.route.fixture.TestRouteDatabaseDiscoveryTypeFixture
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/pom.xml
similarity index 83%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/pom.xml
index f525085..f430d3e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/pom.xml
@@ -22,15 +22,15 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha</artifactId>
+ <artifactId>shardingsphere-db-discovery</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-spring</artifactId>
+ <artifactId>shardingsphere-db-discovery-spring</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
- <module>shardingsphere-ha-spring-namespace</module>
- <module>shardingsphere-ha-spring-boot-starter</module>
+ <module>shardingsphere-db-discovery-spring-namespace</module>
+ <module>shardingsphere-db-discovery-spring-boot-starter</module>
</modules>
</project>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/pom.xml
similarity index 91%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/pom.xml
index 888c46a..cbd7c76 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/pom.xml
@@ -22,16 +22,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-spring</artifactId>
+ <artifactId>shardingsphere-db-discovery-spring</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-spring-boot-starter</artifactId>
+ <artifactId>shardingsphere-db-discovery-spring-boot-starter</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoveryRuleSpringbootConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoveryRuleSpringb [...]
new file mode 100644
index 0000000..31949ee
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoveryRuleSpringbootConfiguration.java
@@ -0,0 +1,55 @@
+/*
+ * 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.db.discovery.spring.boot;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.db.discovery.spring.boot.rule.YamlDatabaseDiscoveryRuleSpringBootConfiguration;
+import org.apache.shardingsphere.db.discovery.spring.boot.condition.DatabaseDiscoverySpringBootCondition;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.swapper.DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Rule spring boot configuration for data base discovery.
+ */
+@Configuration
+@EnableConfigurationProperties(YamlDatabaseDiscoveryRuleSpringBootConfiguration.class)
+@ConditionalOnClass(YamlDatabaseDiscoveryRuleConfiguration.class)
+@Conditional(DatabaseDiscoverySpringBootCondition.class)
+@RequiredArgsConstructor
+public class DatabaseDiscoveryRuleSpringbootConfiguration {
+
+ private final DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper swapper = new DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper();
+
+ private final YamlDatabaseDiscoveryRuleSpringBootConfiguration yamlConfig;
+
+ /**
+ * Data base discovery rule configuration for spring boot.
+ *
+ * @return data base discovery rule configuration
+ */
+ @Bean
+ public RuleConfiguration databaseDiscoveryRuleConfiguration() {
+ return swapper.swapToObject(yamlConfig.getDatabaseDiscovery());
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootCondition.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootCondition.java
similarity index 82%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootCondition.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootCondition.java
index 09e818e..923bec7 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootCondition.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootCondition.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.boot.condition;
+package org.apache.shardingsphere.db.discovery.spring.boot.condition;
import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -24,15 +24,15 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
- * Spring boot condition for HA.
+ * Spring boot condition for Data base discovery.
*/
-public final class HASpringBootCondition extends SpringBootCondition {
+public final class DatabaseDiscoverySpringBootCondition extends SpringBootCondition {
- private static final String PREFIX = "spring.shardingsphere.rules.ha";
+ private static final String PREFIX = "spring.shardingsphere.rules.database-discovery";
@Override
public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata) {
return PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(), PREFIX)
- ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere ha rule configuration in local file.");
+ ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere database-discovery rule configuration in local file.");
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/rule/YamlHARuleSpringBootConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/rule/YamlDatabaseDiscoveryRuleSpringBootConfiguration.java
similarity index 73%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/rule/YamlHARuleSpringBootConfiguration.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/rule/YamlDatabaseDiscoveryRuleSpringBootConfiguration.java
index b480507..7bff225 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/rule/YamlHARuleSpringBootConfiguration.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/java/org/apache/shardingsphere/db/discovery/spring/boot/rule/YamlDatabaseDiscoveryRuleSpringBootConfiguration.java
@@ -5,7 +5,7 @@
* 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
@@ -15,20 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.boot.rule;
+package org.apache.shardingsphere.db.discovery.spring.boot.rule;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- * YAML HA rule spring boot configuration.
+ * YAML data base discovery rule spring boot configuration.
*/
@ConfigurationProperties(prefix = "spring.shardingsphere.rules")
@Getter
@Setter
-public final class YamlHARuleSpringBootConfiguration {
+public final class YamlDatabaseDiscoveryRuleSpringBootConfiguration {
- private YamlHARuleConfiguration ha;
+ private YamlDatabaseDiscoveryRuleConfiguration databaseDiscovery;
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.factories b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.factories
similarity index 89%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.factories
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.factories
index c89f8ba..ed2bfbe 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.factories
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,4 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.shardingsphere.ha.spring.boot.HARuleSpringbootConfiguration
+org.apache.shardingsphere.db.discovery.spring.boot.DatabaseDiscoveryRuleSpringbootConfiguration
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.provides b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.provides
similarity index 93%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.provides
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.provides
index 2ac9961..c7b790e 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/resources/META-INF/spring.provides
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/main/resources/META-INF/spring.provides
@@ -15,4 +15,4 @@
# limitations under the License.
#
-provides: shardingsphere-ha-spring-boot-starter
+provides: shardingsphere-db-discovery-spring-boot-starter
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/HASpringBootStarterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java
similarity index 73%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/HASpringBootStarterTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java
index b6a4179..b6afa80 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/HASpringBootStarterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.boot;
+package org.apache.shardingsphere.db.discovery.spring.boot;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -33,19 +33,19 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = HASpringBootStarterTest.class)
+@SpringBootTest(classes = DatabaseDiscoverySpringBootStarterTest.class)
@SpringBootApplication
-@ActiveProfiles("ha")
-public class HASpringBootStarterTest {
+@ActiveProfiles("database-discovery")
+public class DatabaseDiscoverySpringBootStarterTest {
@Resource
- private AlgorithmProvidedHARuleConfiguration config;
+ private AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config;
@Test
public void assertHARuleConfiguration() {
assertThat(config.getDataSources().size(), is(1));
assertTrue(config.getDataSources().stream().findFirst().isPresent());
- HADataSourceRuleConfiguration dataSourceRuleConfig = config.getDataSources().stream().findFirst().get();
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = config.getDataSources().stream().findFirst().get();
assertThat(dataSourceRuleConfig.getName(), is("pr_ds"));
assertThat(dataSourceRuleConfig.getDataSourceNames().size(), is(2));
assertTrue(config.getDataSources().contains(dataSourceRuleConfig));
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootConditionTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootConditionTest.java
similarity index 85%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootConditionTest.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootConditionTest.java
index ef03082..ef0685a 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/java/org/apache/shardingsphere/ha/spring/boot/condition/HASpringBootConditionTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/db/discovery/spring/boot/condition/DatabaseDiscoverySpringBootConditionTest.java
@@ -5,7 +5,7 @@
* 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
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.boot.condition;
+package org.apache.shardingsphere.db.discovery.spring.boot.condition;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public final class HASpringBootConditionTest {
+public final class DatabaseDiscoverySpringBootConditionTest {
@Test
public void assertNotMatch() {
@@ -41,7 +41,7 @@ public final class HASpringBootConditionTest {
ConditionContext context = mock(ConditionContext.class);
AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
when(context.getEnvironment()).thenReturn(mockEnvironment);
- HASpringBootCondition condition = new HASpringBootCondition();
+ DatabaseDiscoverySpringBootCondition condition = new DatabaseDiscoverySpringBootCondition();
ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata);
assertFalse(matchOutcome.isMatch());
}
@@ -49,11 +49,11 @@ public final class HASpringBootConditionTest {
@Test
public void assertMatch() {
MockEnvironment mockEnvironment = new MockEnvironment();
- mockEnvironment.setProperty("spring.shardingsphere.rules.ha.data-sources.pr_ds.primary-data-source-name", "primary_ds");
+ mockEnvironment.setProperty("spring.shardingsphere.rules.database-discovery.data-sources.pr_ds.primary-data-source-name", "primary_ds");
ConditionContext context = mock(ConditionContext.class);
AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
when(context.getEnvironment()).thenReturn(mockEnvironment);
- HASpringBootCondition condition = new HASpringBootCondition();
+ DatabaseDiscoverySpringBootCondition condition = new DatabaseDiscoverySpringBootCondition();
ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata);
assertTrue(matchOutcome.isMatch());
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/application-ha.properties b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/resources/application-database-discovery.properties
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/application-ha.properties
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/resources/application-database-discovery.properties
index 09b1e4f..e3044af 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/test/resources/application-ha.properties
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/resources/application-database-discovery.properties
@@ -15,6 +15,6 @@
# limitations under the License.
#
-spring.shardingsphere.rules.ha.data-sources.pr_ds.primary-data-source-name=primary_ds
-spring.shardingsphere.rules.ha.data-sources.pr_ds.data-source-names=ds_0,ds_1
+spring.shardingsphere.rules.database-discovery.data-sources.pr_ds.primary-data-source-name=primary_ds
+spring.shardingsphere.rules.database-discovery.data-sources.pr_ds.data-source-names=ds_0,ds_1
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/logback-test.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/resources/logback-test.xml
similarity index 100%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/resources/logback-test.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/resources/logback-test.xml
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/pom.xml
similarity index 90%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/pom.xml
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/pom.xml
index 7c1658a..63bf892 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/pom.xml
@@ -22,16 +22,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-spring</artifactId>
+ <artifactId>shardingsphere-db-discovery-spring</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-ha-spring-namespace</artifactId>
+ <artifactId>shardingsphere-db-discovery-spring-namespace</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/handler/HANamespaceHandler.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/handler/DatabaseDiscoveryNamespaceHandler.java
similarity index 61%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/handler/HANamespaceHandler.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/handler/DatabaseDiscoveryNamespaceHandler.java
index d05e0ea..91125f7 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/handler/HANamespaceHandler.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/handler/DatabaseDiscoveryNamespaceHandler.java
@@ -5,7 +5,7 @@
* 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
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.namespace.handler;
+package org.apache.shardingsphere.db.discovery.spring.namespace.handler;
-import org.apache.shardingsphere.ha.spring.namespace.parser.HARuleBeanDefinitionParser;
-import org.apache.shardingsphere.ha.spring.namespace.tag.HARuleBeanDefinitionTag;
+import org.apache.shardingsphere.db.discovery.spring.namespace.parser.DatabaseDiscoveryRuleBeanDefinitionParser;
+import org.apache.shardingsphere.db.discovery.spring.namespace.tag.DatabaseDiscoveryRuleBeanDefinitionTag;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
- * Spring namespace handler for HA.
+ * Spring namespace handler for data base discovery.
*/
-public final class HANamespaceHandler extends NamespaceHandlerSupport {
+public final class DatabaseDiscoveryNamespaceHandler extends NamespaceHandlerSupport {
@Override
public void init() {
- registerBeanDefinitionParser(HARuleBeanDefinitionTag.ROOT_TAG, new HARuleBeanDefinitionParser());
+ registerBeanDefinitionParser(DatabaseDiscoveryRuleBeanDefinitionTag.ROOT_TAG, new DatabaseDiscoveryRuleBeanDefinitionParser());
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/parser/HARuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/parser/DatabaseDiscoveryRuleBeanDefinitionParser.java
similarity index 70%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/parser/HARuleBeanDefinitionParser.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/parser/DatabaseDiscoveryRuleBeanDefinitionParser.java
index 2b7687f..2dad87b 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/parser/HARuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/parser/DatabaseDiscoveryRuleBeanDefinitionParser.java
@@ -5,7 +5,7 @@
* 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
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.namespace.parser;
+package org.apache.shardingsphere.db.discovery.spring.namespace.parser;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.spring.namespace.tag.HARuleBeanDefinitionTag;
+import org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.db.discovery.spring.namespace.tag.DatabaseDiscoveryRuleBeanDefinitionTag;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -32,19 +32,19 @@ import org.w3c.dom.Element;
import java.util.List;
/**
- * HA rule bean definition parser.
+ * Data base discovery rule bean definition parser.
*/
-public final class HARuleBeanDefinitionParser extends AbstractBeanDefinitionParser {
+public final class DatabaseDiscoveryRuleBeanDefinitionParser extends AbstractBeanDefinitionParser {
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedHARuleConfiguration.class);
+ BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class);
factory.addConstructorArgValue(parseHADataSourceRuleConfigurations(element));
return factory.getBeanDefinition();
}
private List<BeanDefinition> parseHADataSourceRuleConfigurations(final Element element) {
- List<Element> dataSourceElements = DomUtils.getChildElementsByTagName(element, HARuleBeanDefinitionTag.DATA_SOURCE_TAG);
+ List<Element> dataSourceElements = DomUtils.getChildElementsByTagName(element, DatabaseDiscoveryRuleBeanDefinitionTag.DATA_SOURCE_TAG);
List<BeanDefinition> result = new ManagedList<>(dataSourceElements.size());
for (Element each : dataSourceElements) {
result.add(parseHADataSourceRuleConfiguration(each));
@@ -53,8 +53,8 @@ public final class HARuleBeanDefinitionParser extends AbstractBeanDefinitionPars
}
private BeanDefinition parseHADataSourceRuleConfiguration(final Element element) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(HADataSourceRuleConfiguration.class);
- factory.addConstructorArgValue(element.getAttribute(HARuleBeanDefinitionTag.HA_DATA_SOURCE_ID_ATTRIBUTE));
+ BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(DatabaseDiscoveryDataSourceRuleConfiguration.class);
+ factory.addConstructorArgValue(element.getAttribute(DatabaseDiscoveryRuleBeanDefinitionTag.DB_DISCOVERY_DATA_SOURCE_ID_ATTRIBUTE));
return factory.getBeanDefinition();
}
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/tag/DatabaseDiscoveryRuleBeanDefinitionTag.java
similarity index 80%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/tag/DatabaseDiscoveryRuleBeanDefinitionTag.java
index ee63708..50a76c0 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/java/org/apache/shardingsphere/ha/spring/namespace/tag/HARuleBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/java/org/apache/shardingsphere/db/discovery/spring/namespace/tag/DatabaseDiscoveryRuleBeanDefinitionTag.java
@@ -5,7 +5,7 @@
* 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
@@ -15,20 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.ha.spring.namespace.tag;
+package org.apache.shardingsphere.db.discovery.spring.namespace.tag;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
- * HA rule bean definition tag.
+ * Data base discovery rule bean definition tag.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class HARuleBeanDefinitionTag {
+public final class DatabaseDiscoveryRuleBeanDefinitionTag {
public static final String ROOT_TAG = "rule";
public static final String DATA_SOURCE_TAG = "data-source-rule";
- public static final String HA_DATA_SOURCE_ID_ATTRIBUTE = "id";
+ public static final String DB_DISCOVERY_DATA_SOURCE_ID_ATTRIBUTE = "id";
}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/namespace/ha.xsd b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/namespace/database-discovery.xsd
similarity index 96%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/namespace/ha.xsd
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/namespace/database-discovery.xsd
index 3b1795d..34d5a77 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/namespace/ha.xsd
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/namespace/database-discovery.xsd
@@ -18,7 +18,6 @@
<xsd:schema xmlns="http://shardingsphere.apache.org/schema/shardingsphere/ha"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:beans="http://www.springframework.org/schema/beans"
targetNamespace="http://shardingsphere.apache.org/schema/shardingsphere/ha"
elementFormDefault="qualified">
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd" />
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.handlers b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.handlers
similarity index 81%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.handlers
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.handlers
index 2fd20e1..cca32fe 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.handlers
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.handlers
@@ -15,4 +15,4 @@
# limitations under the License.
#
-http\://shardingsphere.apache.org/schema/shardingsphere/ha=org.apache.shardingsphere.ha.spring.namespace.handler.HANamespaceHandler
+http\://shardingsphere.apache.org/schema/shardingsphere/database-discovery=org.apache.shardingsphere.db.discovery.spring.namespace.handler.DatabaseDiscoveryNamespaceHandler
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.schemas b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.schemas
similarity index 84%
rename from shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.schemas
rename to shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.schemas
index d724afc..d743202 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-namespace/src/main/resources/META-INF/spring.schemas
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-namespace/src/main/resources/META-INF/spring.schemas
@@ -15,4 +15,4 @@
# limitations under the License.
#
-http\://shardingsphere.apache.org/schema/shardingsphere/ha/ha.xsd=META-INF/namespace/ha.xsd
+http\://shardingsphere.apache.org/schema/shardingsphere/database-discovery/database-discovery.xsd=META-INF/namespace/database-discovery.xsd
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HARule.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HARule.java
deleted file mode 100644
index 8ed2ac8..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/rule/HARule.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.ha.rule;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.ha.spi.HAType;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
-import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
-import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.type.StatusContainedRule;
-import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
-import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-
-/**
- * HA rule.
- */
-public final class HARule implements DataSourceContainedRule, StatusContainedRule {
-
- static {
- ShardingSphereServiceLoader.register(HAType.class);
- }
-
- private final Map<String, HAType> haTypes = new LinkedHashMap<>();
-
- private final Map<String, HADataSourceRule> dataSourceRules;
-
- public HARule(final HARuleConfiguration config, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final String schemaName) {
- Preconditions.checkArgument(!config.getDataSources().isEmpty(), "HA data source rules can not be empty.");
- Preconditions.checkArgument(null != dataSourceMap && !dataSourceMap.isEmpty(), "Data sources cannot be empty.");
- Preconditions.checkArgument(null != databaseType, "Database type cannot be null.");
- config.getHaTypes().forEach((key, value) -> haTypes.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, HAType.class)));
- dataSourceRules = new HashMap<>(config.getDataSources().size(), 1);
- for (HADataSourceRuleConfiguration each : config.getDataSources()) {
- HAType haType = Strings.isNullOrEmpty(each.getHaTypeName()) || !haTypes.containsKey(each.getHaTypeName())
- ? TypedSPIRegistry.getRegisteredService(HAType.class) : haTypes.get(each.getHaTypeName());
- dataSourceRules.put(each.getName(), new HADataSourceRule(each, haType));
- }
- for (Entry<String, HADataSourceRule> entry : dataSourceRules.entrySet()) {
- String groupName = entry.getKey();
- HADataSourceRule haDataSourceRule = entry.getValue();
- HAType haType = haDataSourceRule.getHaType();
- Map<String, DataSource> originalDataSourceMap = new HashMap<>(dataSourceMap);
- Collection<String> disabledDataSourceNames = haDataSourceRule.getDisabledDataSourceNames();
- String primaryDataSourceName = haDataSourceRule.getPrimaryDataSourceName();
- haType.updatePrimaryDataSource(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
- haDataSourceRule.updatePrimaryDataSourceName(haType.getPrimaryDataSource());
- haType.updateMemberState(originalDataSourceMap, schemaName, disabledDataSourceNames);
- try {
- haType.checkHAConfig(dataSourceMap, schemaName);
- haType.startPeriodicalUpdate(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
- } catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
- }
- }
- }
-
- public HARule(final AlgorithmProvidedHARuleConfiguration config, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final String schemaName) {
- Preconditions.checkArgument(!config.getDataSources().isEmpty(), "HA data source rules can not be empty.");
- Preconditions.checkArgument(null != dataSourceMap && !dataSourceMap.isEmpty(), "Data sources cannot be empty.");
- Preconditions.checkArgument(null != databaseType, "Database type cannot be null.");
- dataSourceRules = new HashMap<>(config.getDataSources().size(), 1);
- for (HADataSourceRuleConfiguration each : config.getDataSources()) {
- HAType haType = Strings.isNullOrEmpty(each.getHaTypeName()) || !haTypes.containsKey(each.getHaTypeName())
- ? TypedSPIRegistry.getRegisteredService(HAType.class) : haTypes.get(each.getHaTypeName());
- dataSourceRules.put(each.getName(), new HADataSourceRule(each, haType));
- }
- for (Entry<String, HADataSourceRule> entry : dataSourceRules.entrySet()) {
- String groupName = entry.getKey();
- HADataSourceRule haDataSourceRule = entry.getValue();
- HAType haType = haDataSourceRule.getHaType();
- Map<String, DataSource> originalDataSourceMap = new HashMap<>(dataSourceMap);
- Collection<String> disabledDataSourceNames = haDataSourceRule.getDisabledDataSourceNames();
- String primaryDataSourceName = haDataSourceRule.getPrimaryDataSourceName();
- haType.updatePrimaryDataSource(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
- haDataSourceRule.updatePrimaryDataSourceName(haType.getPrimaryDataSource());
- haType.updateMemberState(originalDataSourceMap, schemaName, disabledDataSourceNames);
- try {
- haType.checkHAConfig(dataSourceMap, schemaName);
- haType.startPeriodicalUpdate(originalDataSourceMap, schemaName, disabledDataSourceNames, groupName, primaryDataSourceName);
- } catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
- }
- }
- }
-
- /**
- * Get all logic data source names.
- *
- * @return all logic data source names
- */
- public Collection<String> getAllLogicDataSourceNames() {
- return dataSourceRules.keySet();
- }
-
- /**
- * Get single data source rule.
- *
- * @return HA data source rule
- */
- public HADataSourceRule getSingleDataSourceRule() {
- return dataSourceRules.values().iterator().next();
- }
-
- /**
- * Find data source rule.
- *
- * @param dataSourceName data source name
- * @return HA data source rule
- */
- public Optional<HADataSourceRule> findDataSourceRule(final String dataSourceName) {
- return Optional.ofNullable(dataSourceRules.get(dataSourceName));
- }
-
- @Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>();
- for (Entry<String, HADataSourceRule> entry : dataSourceRules.entrySet()) {
- result.putAll(entry.getValue().getDataSourceMapper());
- }
- return result;
- }
-
- @Override
- public void updateRuleStatus(final RuleChangedEvent event) {
- if (event instanceof DataSourceNameDisabledEvent) {
- for (Entry<String, HADataSourceRule> entry : dataSourceRules.entrySet()) {
- entry.getValue().updateDisabledDataSourceNames(((DataSourceNameDisabledEvent) event).getDataSourceName(), ((DataSourceNameDisabledEvent) event).isDisabled());
- }
- } else if (event instanceof PrimaryDataSourceEvent) {
- for (Entry<String, HADataSourceRule> entry : dataSourceRules.entrySet()) {
- if (entry.getValue().getName().equals(((PrimaryDataSourceEvent) event).getGroupName())) {
- entry.getValue().updatePrimaryDataSourceName(((PrimaryDataSourceEvent) event).getDataSourceName());
- }
- }
- }
- }
-}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
deleted file mode 100644
index 082df76..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.ha.yaml.swapper;
-
-import org.apache.shardingsphere.ha.algorithm.config.AlgorithmProvidedHARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
-import org.apache.shardingsphere.ha.yaml.config.rule.YamlHADataSourceRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-/**
- * HA rule configuration YAML swapper.
- */
-public final class HARuleAlgorithmProviderConfigurationYamlSwapper
- implements YamlRuleConfigurationSwapper<YamlHARuleConfiguration, AlgorithmProvidedHARuleConfiguration> {
-
- @Override
- public YamlHARuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedHARuleConfiguration data) {
- YamlHARuleConfiguration result = new YamlHARuleConfiguration();
- result.setDataSources(data.getDataSources().stream().collect(
- Collectors.toMap(HADataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
- return result;
- }
-
- private YamlHADataSourceRuleConfiguration swapToYamlConfiguration(final HADataSourceRuleConfiguration dataSourceRuleConfig) {
- YamlHADataSourceRuleConfiguration result = new YamlHADataSourceRuleConfiguration();
- result.setName(dataSourceRuleConfig.getName());
- result.setDataSourceNames(dataSourceRuleConfig.getDataSourceNames());
- return result;
- }
-
- @Override
- public AlgorithmProvidedHARuleConfiguration swapToObject(final YamlHARuleConfiguration yamlConfig) {
- Collection<HADataSourceRuleConfiguration> dataSources = new LinkedList<>();
- for (Entry<String, YamlHADataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) {
- dataSources.add(swapToObject(entry.getKey(), entry.getValue()));
- }
- AlgorithmProvidedHARuleConfiguration ruleConfig = new AlgorithmProvidedHARuleConfiguration();
- ruleConfig.setDataSources(dataSources);
- return ruleConfig;
- }
-
- private HADataSourceRuleConfiguration swapToObject(final String name, final YamlHADataSourceRuleConfiguration yamlDataSourceRuleConfig) {
- return new HADataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getDataSourceNames(), yamlDataSourceRuleConfig.getHaTypeName());
- }
-
- @Override
- public Class<AlgorithmProvidedHARuleConfiguration> getTypeClass() {
- return AlgorithmProvidedHARuleConfiguration.class;
- }
-
- @Override
- public String getRuleTagName() {
- return "HA";
- }
-
- @Override
- public int getOrder() {
- return HAOrder.ALGORITHM_PROVIDER_HA_ORDER;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java
deleted file mode 100644
index 02ab8aa..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapper.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.ha.yaml.swapper;
-
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.yaml.swapper.algorithm.ShardingSphereAlgorithmConfigurationYamlSwapper;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
-import org.apache.shardingsphere.ha.yaml.config.rule.YamlHADataSourceRuleConfiguration;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-/**
- * HA rule configuration YAML swapper.
- */
-public final class HARuleConfigurationYamlSwapper
- implements YamlRuleConfigurationSwapper<YamlHARuleConfiguration, HARuleConfiguration> {
-
- private final ShardingSphereAlgorithmConfigurationYamlSwapper algorithmSwapper = new ShardingSphereAlgorithmConfigurationYamlSwapper();
-
- @Override
- public YamlHARuleConfiguration swapToYamlConfiguration(final HARuleConfiguration data) {
- YamlHARuleConfiguration result = new YamlHARuleConfiguration();
- result.setDataSources(data.getDataSources().stream().collect(
- Collectors.toMap(HADataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
- if (null != data.getHaTypes()) {
- data.getHaTypes().forEach((key, value) -> result.getHaTypes().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
- }
- return result;
- }
-
- private YamlHADataSourceRuleConfiguration swapToYamlConfiguration(final HADataSourceRuleConfiguration dataSourceRuleConfig) {
- YamlHADataSourceRuleConfiguration result = new YamlHADataSourceRuleConfiguration();
- result.setName(dataSourceRuleConfig.getName());
- result.setDataSourceNames(dataSourceRuleConfig.getDataSourceNames());
- result.setHaTypeName(dataSourceRuleConfig.getHaTypeName());
- return result;
- }
-
- @Override
- public HARuleConfiguration swapToObject(final YamlHARuleConfiguration yamlConfig) {
- Collection<HADataSourceRuleConfiguration> dataSources = new LinkedList<>();
- for (Entry<String, YamlHADataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) {
- dataSources.add(swapToObject(entry.getKey(), entry.getValue()));
- }
- Map<String, ShardingSphereAlgorithmConfiguration> haTypes = new LinkedHashMap<>(yamlConfig.getHaTypes().entrySet().size(), 1);
- if (null != yamlConfig.getHaTypes()) {
- yamlConfig.getHaTypes().forEach((key, value) -> haTypes.put(key, algorithmSwapper.swapToObject(value)));
- }
- return new HARuleConfiguration(dataSources, haTypes);
- }
-
- private HADataSourceRuleConfiguration swapToObject(final String name, final YamlHADataSourceRuleConfiguration yamlDataSourceRuleConfig) {
- return new HADataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getDataSourceNames(), yamlDataSourceRuleConfig.getHaTypeName());
- }
-
- @Override
- public Class<HARuleConfiguration> getTypeClass() {
- return HARuleConfiguration.class;
- }
-
- @Override
- public String getRuleTagName() {
- return "HA";
- }
-
- @Override
- public int getOrder() {
- return HAOrder.ORDER;
- }
-}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
deleted file mode 100644
index 9d6b034..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/resources/META-INF/services/org.apache.shardingsphere.ha.spi.HAType
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.ha.mgr.MGRHAType
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java
deleted file mode 100644
index 67cb8df..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/test/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleConfigurationYamlSwapperTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.ha.yaml.swapper;
-
-import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
-import org.apache.shardingsphere.ha.api.config.rule.HADataSourceRuleConfiguration;
-import org.apache.shardingsphere.ha.constant.HAOrder;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
-import org.apache.shardingsphere.ha.yaml.config.rule.YamlHADataSourceRuleConfiguration;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class HARuleConfigurationYamlSwapperTest {
-
- private final Collection<YamlRuleConfigurationSwapper> collection = ShardingSphereServiceLoader.newServiceInstances(YamlRuleConfigurationSwapper.class);
-
- static {
- ShardingSphereServiceLoader.register(YamlRuleConfigurationSwapper.class);
- }
-
- @Test
- public void assertSwapToYamlWithLoadBalanceAlgorithm() {
- HADataSourceRuleConfiguration dataSourceConfig =
- new HADataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"), "haTypeName");
- YamlHARuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToYamlConfiguration(new HARuleConfiguration(Collections.singleton(dataSourceConfig),
- ImmutableMap.of("mgr", new ShardingSphereAlgorithmConfiguration("MGR", new Properties()))));
- assertThat(actual.getDataSources().get("ds").getName(), is("ds"));
- assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
- }
-
- @Test
- public void assertSwapToYamlWithoutLoadBalanceAlgorithm() {
- HADataSourceRuleConfiguration dataSourceConfig = new HADataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"), "haTypeName");
- YamlHARuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToYamlConfiguration(
- new HARuleConfiguration(Collections.singleton(dataSourceConfig), Collections.emptyMap()));
- assertThat(actual.getDataSources().get("ds").getName(), is("ds"));
- assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
- }
-
- @Test
- public void assertSwapToObjectWithLoadBalanceAlgorithmType() {
- YamlHARuleConfiguration yamlConfig = createYamlHARuleConfiguration();
- HARuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToObject(yamlConfig);
- assertHARuleConfiguration(actual);
- }
-
- @Test
- public void assertSwapToObjectWithoutLoadBalanceAlgorithm() {
- YamlHARuleConfiguration yamlConfig = createYamlHARuleConfiguration();
- HARuleConfiguration actual = getHARuleConfigurationYamlSwapper().swapToObject(yamlConfig);
- assertHARuleConfiguration(actual);
- }
-
- private YamlHARuleConfiguration createYamlHARuleConfiguration() {
- YamlHARuleConfiguration result = new YamlHARuleConfiguration();
- result.getDataSources().put("ha_ds", new YamlHADataSourceRuleConfiguration());
- result.getDataSources().get("ha_ds").setName("ha_ds");
- result.getDataSources().get("ha_ds").setDataSourceNames(Arrays.asList("ds_0", "ds_1"));
- return result;
- }
-
- private void assertHARuleConfiguration(final HARuleConfiguration actual) {
- HADataSourceRuleConfiguration group = actual.getDataSources().iterator().next();
- assertThat(group.getName(), is("ha_ds"));
- assertThat(group.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
- }
-
- @Test
- public void assertGetTypeClass() {
- HARuleConfigurationYamlSwapper swapper = getHARuleConfigurationYamlSwapper();
- Class<HARuleConfiguration> actual = swapper.getTypeClass();
- assertTrue(actual.isAssignableFrom(HARuleConfiguration.class));
- }
-
- @Test
- public void assertGetOrder() {
- HARuleConfigurationYamlSwapper swapper = getHARuleConfigurationYamlSwapper();
- int actual = swapper.getOrder();
- assertThat(actual, is(HAOrder.ORDER));
- }
-
- private HARuleConfigurationYamlSwapper getHARuleConfigurationYamlSwapper() {
- Optional<HARuleConfigurationYamlSwapper> optional = collection.stream()
- .filter(swapper -> swapper instanceof HARuleConfigurationYamlSwapper)
- .map(swapper -> (HARuleConfigurationYamlSwapper) swapper)
- .findFirst();
- assertTrue(optional.isPresent());
- return optional.get();
- }
-}
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/HARuleSpringbootConfiguration.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/HARuleSpringbootConfiguration.java
deleted file mode 100644
index 54e2e80..0000000
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-spring/shardingsphere-ha-spring-boot-starter/src/main/java/org/apache/shardingsphere/ha/spring/boot/HARuleSpringbootConfiguration.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.ha.spring.boot;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.ha.spring.boot.condition.HASpringBootCondition;
-import org.apache.shardingsphere.ha.spring.boot.rule.YamlHARuleSpringBootConfiguration;
-import org.apache.shardingsphere.ha.yaml.config.YamlHARuleConfiguration;
-import org.apache.shardingsphere.ha.yaml.swapper.HARuleAlgorithmProviderConfigurationYamlSwapper;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Rule spring boot configuration for HA.
- */
-@Configuration
-@EnableConfigurationProperties(YamlHARuleSpringBootConfiguration.class)
-@ConditionalOnClass(YamlHARuleConfiguration.class)
-@Conditional(HASpringBootCondition.class)
-@RequiredArgsConstructor
-public class HARuleSpringbootConfiguration {
-
- private final HARuleAlgorithmProviderConfigurationYamlSwapper swapper = new HARuleAlgorithmProviderConfigurationYamlSwapper();
-
- private final YamlHARuleSpringBootConfiguration yamlConfig;
-
- /**
- * HA rule configuration for spring boot.
- *
- * @return HA rule configuration
- */
- @Bean
- public RuleConfiguration haRuleConfiguration() {
- return swapper.swapToObject(yamlConfig.getHa());
- }
-}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/single/SingleTableRuleLoader.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/single/SingleTableRuleLoader.java
index 44452d5..3c0b5b5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/single/SingleTableRuleLoader.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/single/SingleTableRuleLoader.java
@@ -49,7 +49,7 @@ public final class SingleTableRuleLoader {
Map<String, SingleTableRule> result = new HashMap<>();
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
Map<String, SingleTableRule> singleTableRules = load(databaseType, entry.getKey(), entry.getValue(), excludedTables);
- // TODO recover check single table must be unique. Current situation cannot recognize replica query rule or ha rule for single table duplicate.
+ // TODO recover check single table must be unique. Current situation cannot recognize replica query rule or databaseDiscovery rule for single table duplicate.
// singleTableRules.keySet().forEach(each -> Preconditions.checkState(!result.containsKey(each), "Single table conflict, there are multiple tables `%s` existed.", each));
result.putAll(singleTableRules);
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/pom.xml b/shardingsphere-governance/shardingsphere-governance-core/pom.xml
index 5c6efa8..773a805 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/pom.xml
+++ b/shardingsphere-governance/shardingsphere-governance-core/pom.xml
@@ -54,7 +54,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/HARuleConfigurationChecker.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/DatabaseDiscoveryRuleConfigurationChecker.java
similarity index 65%
rename from shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/HARuleConfigurationChecker.java
rename to shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/DatabaseDiscoveryRuleConfigurationChecker.java
index dfca3c5..bcf4aa1 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/HARuleConfigurationChecker.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/DatabaseDiscoveryRuleConfigurationChecker.java
@@ -18,16 +18,16 @@
package org.apache.shardingsphere.governance.core.registry.checker;
import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
/**
- * HA rule configuration checker.
+ * Data base discovery rule configuration checker.
*/
-public final class HARuleConfigurationChecker implements RuleConfigurationChecker<HARuleConfiguration> {
+public final class DatabaseDiscoveryRuleConfigurationChecker implements RuleConfigurationChecker<DatabaseDiscoveryRuleConfiguration> {
@Override
- public void check(final String schemaName, final HARuleConfiguration ruleConfiguration) {
+ public void check(final String schemaName, final DatabaseDiscoveryRuleConfiguration ruleConfiguration) {
ruleConfiguration.getDataSources().forEach(each -> Preconditions.checkState(
- !each.getHaTypeName().isEmpty(), "No available HA rule configuration in `%s` for governance.", schemaName));
+ !each.getDiscoveryTypeName().isEmpty(), "No available DatabaseDiscovery rule configuration in `%s` for governance.", schemaName));
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactory.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactory.java
index 366d263..65a4ba7 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactory.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactory.java
@@ -19,12 +19,12 @@ package org.apache.shardingsphere.governance.core.registry.checker;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
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.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwrite.splitting.api.ReadWriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -47,7 +47,7 @@ public final class RuleConfigurationCheckerFactory {
REGISTRY.put(EncryptRuleConfiguration.class, new EncryptRuleConfigurationChecker());
REGISTRY.put(AlgorithmProvidedEncryptRuleConfiguration.class, new AlgorithmProvidedEncryptRuleConfigurationChecker());
REGISTRY.put(ShadowRuleConfiguration.class, new ShadowRuleConfigurationChecker());
- REGISTRY.put(HARuleConfiguration.class, new HARuleConfigurationChecker());
+ REGISTRY.put(DatabaseDiscoveryRuleConfiguration.class, new DatabaseDiscoveryRuleConfigurationChecker());
}
/**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index 837421a..240fd1d 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.governance.core.registry;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceAddedEvent;
import org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceAlteredEvent;
@@ -30,7 +31,6 @@ import org.apache.shardingsphere.governance.core.yaml.config.YamlRuleConfigurati
import org.apache.shardingsphere.governance.core.yaml.config.schema.YamlSchema;
import org.apache.shardingsphere.governance.core.yaml.swapper.SchemaYamlSwapper;
import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
-import org.apache.shardingsphere.ha.api.config.HARuleConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
@@ -96,7 +96,7 @@ public final class RegistryCenterTest {
private static final String READ_WRITE_SPLITTING_RULE_YAML = "yaml/registryCenter/data-read-write-splitting-rule.yaml";
- private static final String HA_RULE_YAML = "yaml/registryCenter/data-ha-rule.yaml";
+ private static final String DB_DISCOVERY_RULE_YAML = "yaml/registryCenter/data-database-discovery-rule.yaml";
private static final String ENCRYPT_RULE_YAML = "yaml/registryCenter/data-encrypt-rule.yaml";
@@ -234,11 +234,11 @@ public final class RegistryCenterTest {
}
@Test
- public void assertPersistConfigurationForHARuleWithoutAuthenticationAndIsOverwrite() {
+ public void assertPersistConfigurationForDatabaseDiscoveryRuleWithoutAuthenticationAndIsOverwrite() {
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
- registryCenter.persistConfigurations("sharding_db", createDataSourceConfigurations(), createHARuleConfiguration(), true);
+ registryCenter.persistConfigurations("sharding_db", createDataSourceConfigurations(), createDatabaseDiscoveryRuleConfiguration(), true);
verify(registryRepository).persist(eq("/metadata/sharding_db/datasource"), ArgumentMatchers.any());
- verify(registryRepository, times(0)).persist("/metadata/sharding_db/rule", readYAML(HA_RULE_YAML));
+ verify(registryRepository, times(0)).persist("/metadata/sharding_db/rule", readYAML(DB_DISCOVERY_RULE_YAML));
}
@Test
@@ -290,11 +290,11 @@ public final class RegistryCenterTest {
}
@Test
- public void assertPersistConfigurationForHARuleWithAuthenticationAndIsOverwrite() {
+ public void assertPersistConfigurationForDatabaseDiscoveryRuleWithAuthenticationAndIsOverwrite() {
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
- registryCenter.persistConfigurations("sharding_db", createDataSourceConfigurations(), createHARuleConfiguration(), true);
+ registryCenter.persistConfigurations("sharding_db", createDataSourceConfigurations(), createDatabaseDiscoveryRuleConfiguration(), true);
verify(registryRepository).persist(eq("/metadata/sharding_db/datasource"), ArgumentMatchers.any());
- verify(registryRepository, times(0)).persist("/metadata/sharding_db/rule", readYAML(HA_RULE_YAML));
+ verify(registryRepository, times(0)).persist("/metadata/sharding_db/rule", readYAML(DB_DISCOVERY_RULE_YAML));
}
@Test
@@ -360,8 +360,8 @@ public final class RegistryCenterTest {
return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(readYAML(READ_WRITE_SPLITTING_RULE_YAML), YamlRootRuleConfigurations.class).getRules());
}
- private Collection<RuleConfiguration> createHARuleConfiguration() {
- return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(readYAML(HA_RULE_YAML), YamlRootRuleConfigurations.class).getRules());
+ private Collection<RuleConfiguration> createDatabaseDiscoveryRuleConfiguration() {
+ return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(readYAML(DB_DISCOVERY_RULE_YAML), YamlRootRuleConfigurations.class).getRules());
}
private Collection<RuleConfiguration> createEncryptRuleConfiguration() {
@@ -457,11 +457,11 @@ public final class RegistryCenterTest {
}
@Test
- public void assertLoadHARuleConfiguration() {
- when(registryRepository.get("/metadata/sharding_db/rule")).thenReturn(readYAML(HA_RULE_YAML));
+ public void assertLoadDatabaseDiscoveryRuleConfiguration() {
+ when(registryRepository.get("/metadata/sharding_db/rule")).thenReturn(readYAML(DB_DISCOVERY_RULE_YAML));
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
Collection<RuleConfiguration> actual = registryCenter.loadRuleConfigurations("sharding_db");
- HARuleConfiguration config = (HARuleConfiguration) actual.iterator().next();
+ DatabaseDiscoveryRuleConfiguration config = (DatabaseDiscoveryRuleConfiguration) actual.iterator().next();
assertThat(config.getDataSources().size(), is(1));
assertThat(config.getDataSources().iterator().next().getDataSourceNames().size(), is(3));
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactoryTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactoryTest.java
index c9e5024..9b19d7f 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactoryTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/checker/RuleConfigurationCheckerFactoryTest.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.governance.core.registry.checker;
+import org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
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.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwrite.splitting.api.ReadWriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -71,7 +71,7 @@ public final class RuleConfigurationCheckerFactoryTest {
}
@Test
- public void assertHARuleConfigurationChecker() {
- assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(HARuleConfiguration.class)).isPresent());
+ public void assertDatabaseDiscoveryRuleConfigurationChecker() {
+ assertTrue(RuleConfigurationCheckerFactory.newInstance(mock(DatabaseDiscoveryRuleConfiguration.class)).isPresent());
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/ha-rule.yaml b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/database-discovery-rule.yaml
similarity index 94%
rename from shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/ha-rule.yaml
rename to shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/database-discovery-rule.yaml
index 7072f50..866e857 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/ha-rule.yaml
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/database-discovery-rule.yaml
@@ -16,7 +16,7 @@
#
rules:
- - !HA
+ - !DB_DISCOVERY
dataSources:
pr_ds:
name: pr_ds
@@ -24,8 +24,8 @@ rules:
- ds_0
- ds_1
- ds_2
- haTypeName: mgr
- haTypes:
+ discoveryTypeName: mgr
+ discoveryTypes:
mgr:
type: MGR
props:
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-ha-rule.yaml b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-database-discovery-rule.yaml
similarity index 94%
rename from shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-ha-rule.yaml
rename to shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-database-discovery-rule.yaml
index 7072f50..866e857 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-ha-rule.yaml
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-database-discovery-rule.yaml
@@ -16,7 +16,7 @@
#
rules:
- - !HA
+ - !DB_DISCOVERY
dataSources:
pr_ds:
name: pr_ds
@@ -24,8 +24,8 @@ rules:
- ds_0
- ds_1
- ds_2
- haTypeName: mgr
- haTypes:
+ discoveryTypeName: mgr
+ discoveryTypes:
mgr:
type: MGR
props:
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index 0c6b3b6..9210129 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -79,7 +79,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-route</artifactId>
+ <artifactId>shardingsphere-db-discovery-route</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-database-discovery.yaml
similarity index 96%
rename from shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
rename to shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-database-discovery.yaml
index 89b6f5e56..acf68d6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-ha.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-database-discovery.yaml
@@ -22,7 +22,7 @@
#
######################################################################################################
#
-#schemaName: ha_db
+#schemaName: database_discovery_db
#
#dataSources:
# primary_ds:
@@ -57,7 +57,7 @@
# maintenanceIntervalMilliseconds: 30000
#
#rules:
-#- !HA
+#- !DB_DISCOVERY
# dataSources:
# pr_ds:
# name: pr_ds
@@ -72,7 +72,7 @@
#
######################################################################################################
-#schemaName: ha_db
+#schemaName: database_discovery_db
#
#dataSources:
# ds_0:
@@ -107,7 +107,7 @@
# maintenanceIntervalMilliseconds: 30000
#
#rules:
-# - !HA
+# - !DB_DISCOVERY
# dataSources:
# pr_ds:
# name: pr_ds
@@ -116,8 +116,8 @@
# - ds_1
# - ds_2
# replicaQuery: false
-# haTypeName: mgr
-# haTypes:
+# discoveryTypeName: mgr
+# discoveryTypes:
# mgr:
# type: MGR
# props:
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
index c502f2c..ce0c548 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
@@ -54,7 +54,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-ha-common</artifactId>
+ <artifactId>shardingsphere-db-discovery-common</artifactId>
<version>${project.version}</version>
</dependency>