You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2023/04/01 11:22:47 UTC
[shardingsphere] branch master updated: Remove db-discovery feature (#24906)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 5d744d67f1f Remove db-discovery feature (#24906)
5d744d67f1f is described below
commit 5d744d67f1fde31141765f4ff1cf6e9fa4c239c5
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Apr 1 19:22:31 2023 +0800
Remove db-discovery feature (#24906)
---
.github/workflows/e2e-discovery.yml | 94 ---------
.../template/jdbc/java/config/Configuration.ftl | 9 -
.../template/jdbc/java/config/db-discovery.ftl | 42 ----
.../template/proxy/feature/db-discovery.ftl | 39 ----
features/db-discovery/api/pom.xml | 37 ----
.../config/DatabaseDiscoveryRuleConfiguration.java | 43 ----
...tabaseDiscoveryDataSourceRuleConfiguration.java | 39 ----
.../DatabaseDiscoveryHeartBeatConfiguration.java | 33 ---
.../exception/DBDiscoveryProviderException.java | 35 ----
.../dbdiscovery/spi/DatabaseDiscoveryProvider.java | 64 ------
.../dbdiscovery/spi/ReplicaDataSourceStatus.java | 33 ---
features/db-discovery/core/pom.xml | 69 ------
.../algorithm/DatabaseDiscoveryEngine.java | 133 ------------
.../DatabaseDiscoveryRuleConfigurationChecker.java | 51 -----
.../constant/DatabaseDiscoveryOrder.java | 33 ---
.../datanode/DatabaseDiscoveryDataNodeBuilder.java | 52 -----
...DBDiscoveryDataSourceRuleNotFoundException.java | 32 ---
.../exception/DBDiscoverySQLException.java | 35 ----
...gRequiredDBDiscoveryConfigurationException.java | 32 ---
...uiredDataSourceNamesConfigurationException.java | 32 ---
...ingRequiredGroupNameConfigurationException.java | 32 ---
.../dbdiscovery/heartbeat/HeartbeatJob.java | 56 -----
.../route/DatabaseDiscoverySQLRouter.java | 82 --------
.../impl/DatabaseDiscoveryDataSourceRouter.java | 39 ----
.../rule/DatabaseDiscoveryDataSourceRule.java | 148 -------------
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 233 ---------------------
.../rule/builder/DatabaseDiscoveryRuleBuilder.java | 59 ------
.../YamlDatabaseDiscoveryRuleConfiguration.java | 48 -----
...tabaseDiscoveryDataSourceRuleConfiguration.java | 39 ----
...amlDatabaseDiscoveryHeartBeatConfiguration.java | 34 ---
...lDatabaseDiscoveryRuleConfigurationSwapper.java | 114 ----------
...ra.config.rule.checker.RuleConfigurationChecker | 18 --
...e.shardingsphere.infra.datanode.DataNodeBuilder | 18 --
...org.apache.shardingsphere.infra.route.SQLRouter | 18 --
...infra.rule.builder.database.DatabaseRuleBuilder | 18 --
...onfig.swapper.rule.YamlRuleConfigurationSwapper | 18 --
...abaseDiscoveryRuleConfigurationCheckerTest.java | 66 ------
.../CoreDatabaseDiscoveryProviderFixture.java | 52 -----
.../route/DatabaseDiscoverySQLRouterTest.java | 154 --------------
.../rule/DatabaseDiscoveryDataSourceRuleTest.java | 75 -------
.../rule/DatabaseDiscoveryRuleTest.java | 100 ---------
.../builder/DatabaseDiscoveryRuleBuilderTest.java | 59 ------
...abaseDiscoveryRuleConfigurationSwapperTest.java | 96 ---------
...YamlDatabaseDiscoveryRuleConfigurationTest.java | 79 -------
...phere.dbdiscovery.spi.DatabaseDiscoveryProvider | 18 --
.../core/src/test/resources/logback-test.xml | 33 ---
.../src/test/resources/yaml/db-discovery-rule.yaml | 55 -----
features/db-discovery/distsql/handler/pom.xml | 64 ------
.../DatabaseDiscoveryRuleStatementConverter.java | 71 -------
.../query/CountDatabaseDiscoveryRuleExecutor.java | 83 --------
.../ShowDatabaseDiscoveryHeartbeatExecutor.java | 61 ------
.../query/ShowDatabaseDiscoveryRuleExecutor.java | 94 ---------
.../query/ShowDatabaseDiscoveryTypeExecutor.java | 60 ------
...AlterDatabaseDiscoveryRuleStatementUpdater.java | 132 ------------
...reateDatabaseDiscoveryRuleStatementUpdater.java | 122 -----------
...DatabaseDiscoveryHeartbeatStatementUpdater.java | 92 --------
.../DropDatabaseDiscoveryRuleStatementUpdater.java | 126 -----------
.../DropDatabaseDiscoveryTypeStatementUpdater.java | 98 ---------
...hardingsphere.distsql.handler.query.RQLExecutor | 21 --
...re.distsql.handler.update.RuleDefinitionUpdater | 22 --
...atabaseDiscoveryRuleStatementConverterTest.java | 59 ------
.../DistSQLDatabaseDiscoveryProviderFixture.java | 52 -----
.../CountDatabaseDiscoveryRuleExecutorTest.java | 83 --------
...ShowDatabaseDiscoveryHeartbeatExecutorTest.java | 80 -------
.../ShowDatabaseDiscoveryRuleExecutorTest.java | 106 ----------
.../ShowDatabaseDiscoveryTypeExecutorTest.java | 81 -------
...rDatabaseDiscoveryRuleStatementUpdaterTest.java | 132 ------------
...eDatabaseDiscoveryRuleStatementUpdaterTest.java | 165 ---------------
...baseDiscoveryHeartbeatStatementUpdaterTest.java | 102 ---------
...abaseDiscoveryProviderStatementUpdaterTest.java | 102 ---------
...pDatabaseDiscoveryRuleStatementUpdaterTest.java | 161 --------------
...phere.dbdiscovery.spi.DatabaseDiscoveryProvider | 18 --
features/db-discovery/distsql/parser/pom.xml | 110 ----------
.../main/antlr4/imports/db-discovery/Alphabet.g4 | 48 -----
.../main/antlr4/imports/db-discovery/BaseRule.g4 | 50 -----
.../main/antlr4/imports/db-discovery/Keyword.g4 | 120 -----------
.../main/antlr4/imports/db-discovery/Literals.g4 | 50 -----
.../antlr4/imports/db-discovery/RDLStatement.g4 | 76 -------
.../antlr4/imports/db-discovery/RQLStatement.g4 | 44 ----
.../src/main/antlr4/imports/db-discovery/Symbol.g4 | 61 ------
.../autogen/DatabaseDiscoveryDistSQLStatement.g4 | 33 ---
.../parser/core/DatabaseDiscoveryDistSQLLexer.java | 32 ---
.../core/DatabaseDiscoveryDistSQLParser.java | 40 ----
.../DatabaseDiscoveryDistSQLStatementVisitor.java | 144 -------------
...abaseDiscoveryDistSQLStatementParserFacade.java | 52 -----
...engine.spi.FeaturedDistSQLStatementParserFacade | 18 --
features/db-discovery/distsql/pom.xml | 36 ----
features/db-discovery/distsql/statement/pom.xml | 37 ----
.../segment/DatabaseDiscoveryHeartbeatSegment.java | 36 ----
.../segment/DatabaseDiscoveryProviderSegment.java | 35 ----
.../segment/DatabaseDiscoveryRuleSegment.java | 43 ----
.../AlterDatabaseDiscoveryRuleStatement.java | 35 ----
.../CountDatabaseDiscoveryRuleStatement.java | 31 ---
.../CreateDatabaseDiscoveryRuleStatement.java | 38 ----
.../DropDatabaseDiscoveryHeartbeatStatement.java | 37 ----
.../DropDatabaseDiscoveryRuleStatement.java | 39 ----
.../DropDatabaseDiscoveryTypeStatement.java | 37 ----
.../ShowDatabaseDiscoveryHeartbeatsStatement.java | 31 ---
.../ShowDatabaseDiscoveryRulesStatement.java | 36 ----
.../ShowDatabaseDiscoveryTypesStatement.java | 31 ---
features/db-discovery/pom.xml | 37 ----
features/db-discovery/provider/mysql/pom.xml | 55 -----
.../InvalidMGRGroupNameConfigurationException.java | 33 ---
.../exception/mgr/InvalidMGRModeException.java | 33 ---
.../exception/mgr/InvalidMGRPluginException.java | 33 ---
.../InvalidMGRReplicationGroupMemberException.java | 33 ---
.../DuplicatePrimaryDataSourceException.java | 33 ---
.../PrimaryDataSourceNotFoundException.java | 33 ---
.../type/MGRMySQLDatabaseDiscoveryProvider.java | 170 ---------------
...NormalReplicationDatabaseDiscoveryProvider.java | 150 -------------
...phere.dbdiscovery.spi.DatabaseDiscoveryProvider | 19 --
.../type/MGRDatabaseDiscoveryProviderTest.java | 89 --------
...alReplicationDatabaseDiscoveryProviderTest.java | 102 ---------
features/db-discovery/provider/opengauss/pom.xml | 37 ----
...NormalReplicationDatabaseDiscoveryProvider.java | 84 --------
...phere.dbdiscovery.spi.DatabaseDiscoveryProvider | 18 --
...alReplicationDatabaseDiscoveryProviderTest.java | 48 -----
features/db-discovery/provider/pom.xml | 35 ----
features/pom.xml | 1 -
...dwriteSplittingDataSourceRuleConfiguration.java | 8 +-
...micReadwriteSplittingStrategyConfiguration.java | 31 ---
...ReadwriteSplittingRuleConfigurationChecker.java | 33 +--
...ngRequiredAutoAwareDataSourceNameException.java | 33 ---
.../filter/DisabledReadDataSourcesFilter.java | 4 -
.../rule/ReadwriteSplittingDataSourceRule.java | 12 +-
.../rule/ReadwriteSplittingRule.java | 47 +----
.../ReadwriteSplittingStrategyFactory.java | 61 ------
.../type/DynamicReadwriteSplittingStrategy.java | 57 -----
...ReadwriteSplittingRuleConfigurationSwapper.java | 11 +-
...writeSplittingStrategyConfigurationSwapper.java | 42 ----
...writeSplittingRuleConfigurationCheckerTest.java | 19 --
.../filter/DisabledReadDataSourcesFilterTest.java | 75 -------
...teSplittingDataSourceRuleConfigurationTest.java | 12 --
.../rule/ReadwriteSplittingDataSourceRuleTest.java | 5 +-
.../DynamicReadwriteSplittingStrategyTest.java | 39 ----
...writeSplittingRuleConfigurationSwapperTest.java | 5 +-
.../ReadwriteSplittingRuleStatementConverter.java | 13 +-
.../query/ShowReadwriteSplittingRuleExecutor.java | 12 +-
...adwriteSplittingRuleStatementConverterTest.java | 54 +----
.../ShowReadwriteSplittingRuleExecutorTest.java | 68 ++----
...ReadwriteSplittingRuleStatementUpdaterTest.java | 5 +-
.../imports/readwrite-splitting/RDLStatement.g4 | 6 +-
.../ReadwriteSplittingDistSQLStatementVisitor.java | 4 -
.../infra/metadata/ShardingSphereMetaData.java | 2 -
.../type/DynamicDataSourceContainedRule.java | 71 -------
jdbc/core/pom.xml | 5 -
.../storage/PrimaryDataSourceChangedEvent.java | 33 ---
.../mode/event/storage/StorageNodeDataSource.java | 6 -
.../storage/event/PrimaryStateChangedEvent.java | 33 ---
.../subscriber/StorageNodeStatusSubscriber.java | 15 --
.../watcher/StorageNodeStateChangedWatcher.java | 5 -
.../yaml/YamlStorageNodeDataSourceSwapper.java | 3 +-
.../subscriber/StateChangedSubscriber.java | 26 ---
.../StorageNodeStatusSubscriberTest.java | 12 --
.../StorageNodeStateChangedWatcherTest.java | 12 --
.../subscriber/StateChangedSubscriberTest.java | 19 --
proxy/backend/core/pom.xml | 5 -
...aseDiscoveryRuleConfigurationImportChecker.java | 74 -------
...iteSplittingRuleConfigurationImportChecker.java | 26 +--
.../ConvertYamlConfigurationExecutor.java | 50 -----
...wStatusFromReadwriteSplittingRulesExecutor.java | 3 +-
.../rdl/rule/RuleDefinitionBackendHandler.java | 7 -
.../rql/rule/ShowRulesUsedStorageUnitExecutor.java | 14 --
.../proxy/backend/util/ExportUtils.java | 3 -
.../YamlDatabaseConfigurationImportExecutor.java | 12 --
...iscoveryRuleConfigurationImportCheckerTest.java | 111 ----------
...plittingRuleConfigurationImportCheckerTest.java | 5 +-
.../ConvertYamlConfigurationExecutorTest.java | 5 -
...tusFromReadwriteSplittingRulesExecutorTest.java | 9 +-
.../ImportDatabaseConfigurationUpdaterTest.java | 5 -
.../rule/ShowRulesUsedStorageUnitExecutorTest.java | 18 +-
.../conf/convert/config-database-discovery.yaml | 67 ------
.../test/resources/conf/convert/config-mix.yaml | 33 +--
.../expected/convert-database-discovery.yaml | 41 ----
.../src/test/resources/expected/convert-mix.yaml | 18 +-
test/e2e/operation/discovery/pom.xml | 85 --------
.../e2e/discovery/build/DiscoveryRuleBuilder.java | 92 --------
.../cases/DatabaseClusterEnvironment.java | 34 ---
.../cases/DatabaseClusterEnvironmentFactory.java | 49 -----
.../cases/DiscoveryContainerComposer.java | 51 -----
.../e2e/discovery/cases/DiscoveryTestAction.java | 196 -----------------
.../cases/mysql/MySQLMGRDiscoveryE2EIT.java | 65 ------
.../cases/mysql/env/MySQLMGREnvironment.java | 116 ----------
.../discovery/command/DiscoveryDistSQLCommand.java | 61 ------
.../command/MGRPrimaryReplicaCommand.java | 40 ----
.../discovery/env/DiscoveryE2ETestEnvironment.java | 86 --------
.../env/enums/DiscoveryE2EEnvTypeEnum.java | 23 --
.../container/compose/BaseContainerComposer.java | 65 ------
.../container/compose/DockerContainerComposer.java | 95 ---------
.../config/MySQLContainerConfigurationFactory.java | 77 -------
.../ProxyClusterContainerConfigurationFactory.java | 51 -----
.../parameter/DiscoveryTestParameter.java | 35 ----
.../e2e/discovery/pojo/DistSQLCommandPOJO.java | 40 ----
.../discovery/util/DiscoveryContainerUtils.java | 60 ------
.../resources/env/common/discovery-command.xml | 121 -----------
.../env/common/mgr-primary-replica-command.xml | 34 ---
.../src/test/resources/env/it-env.properties | 22 --
.../src/test/resources/env/mysql/01-initdb.sql | 21 --
.../env/scenario/mgr_discovery/mysql_1/my.cnf | 43 ----
.../env/scenario/mgr_discovery/mysql_2/my.cnf | 42 ----
.../env/scenario/mgr_discovery/mysql_3/my.cnf | 42 ----
.../env/scenario/mgr_discovery/mysql_4/my.cnf | 43 ----
.../env/scenario/mgr_discovery/proxy/server.yaml | 43 ----
.../discovery/src/test/resources/logback-test.xml | 33 ---
test/e2e/operation/pom.xml | 1 -
.../resources/cases/ral/ral-integration-set.xml | 1 -
.../alter_readwrite_splitting_rules.xml | 3 +-
.../create_readwrite_splitting_rules.xml | 3 +-
.../drop_readwrite_splitting_rules.xml | 1 -
.../count_database_rules.xml | 1 -
.../show_readwrite_splitting_rules.xml | 21 +-
.../count_database_rules.xml | 1 -
.../show_readwrite_splitting_rules.xml | 21 +-
.../rql/dataset/encrypt/count_database_rules.xml | 1 -
.../count_database_rules.xml | 1 -
.../show_readwrite_splitting_rules.xml | 3 +-
.../readwrite_splitting/count_database_rules.xml | 1 -
.../show_readwrite_splitting_rules.xml | 3 +-
.../sharding_and_encrypt/count_database_rules.xml | 1 -
.../mysql/count_database_rules.xml | 1 -
.../cases/rql/dataset/tbl/count_database_rules.xml | 1 -
.../resources/cases/rql/rql-integration-count.xml | 4 -
.../resources/cases/rql/rql-integration-show.xml | 14 +-
test/it/parser/pom.xml | 5 -
.../rdl/alter/AlterRuleStatementAssert.java | 7 +-
.../AlterDatabaseDiscoveryRuleStatementAssert.java | 73 -------
.../rdl/create/CreateRuleStatementAssert.java | 7 +-
...CreateDatabaseDiscoveryRuleStatementAssert.java | 75 -------
.../rdl/drop/DropRuleStatementAssert.java | 17 +-
...pDatabaseDiscoveryHeartbeatStatementAssert.java | 49 -----
.../DropDatabaseDiscoveryRuleStatementAssert.java | 48 -----
.../DropDatabaseDiscoveryTypeStatementAssert.java | 49 -----
.../cases/parser/jaxb/RootSQLParserTestCases.java | 28 ---
.../rdl/ExpectedDatabaseDiscoveryHeartbeat.java | 42 ----
.../distsql/rdl/ExpectedDatabaseDiscoveryRule.java | 46 ----
.../distsql/rdl/ExpectedDatabaseDiscoveryType.java | 40 ----
...lterDatabaseDiscoveryRuleStatementTestCase.java | 36 ----
...eateDatabaseDiscoveryRuleStatementTestCase.java | 40 ----
...atabaseDiscoveryHeartbeatStatementTestCase.java | 41 ----
...DropDatabaseDiscoveryRuleStatementTestCase.java | 41 ----
...DropDatabaseDiscoveryTypeStatementTestCase.java | 41 ----
...ountDatabaseDiscoveryRuleStatementTestCase.java | 26 ---
...howDatabaseDiscoveryRulesStatementTestCase.java | 26 ---
.../parser/src/main/resources/case/rdl/alter.xml | 19 --
.../parser/src/main/resources/case/rdl/create.xml | 68 ------
.../it/parser/src/main/resources/case/rdl/drop.xml | 30 ---
.../it/parser/src/main/resources/case/rql/show.xml | 16 --
.../src/main/resources/sql/supported/rdl/alter.xml | 2 -
.../main/resources/sql/supported/rdl/create.xml | 5 -
.../src/main/resources/sql/supported/rdl/drop.xml | 6 -
.../src/main/resources/sql/supported/rql/show.xml | 4 -
251 files changed, 105 insertions(+), 11342 deletions(-)
diff --git a/.github/workflows/e2e-discovery.yml b/.github/workflows/e2e-discovery.yml
deleted file mode 100644
index 6061c031c79..00000000000
--- a/.github/workflows/e2e-discovery.yml
+++ /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.
-#
-
-name: E2E - Database Discovery
-
-on:
- push:
- branches: [ master, dev ]
- paths:
- - '.github/workflows/e2e-discovery.yml'
- - 'infra/common/src/main/**'
- - 'features/db-discovery/**/src/main/**'
- - 'features/readwrite-splitting/**/src/main/**'
- - 'proxy/**/src/main/**'
- - 'jdbc/core/src/main/**'
- - '!test/**'
- - 'test/pom.xml'
- - 'test/e2e/fixture/**'
- - 'test/e2e/env/**'
- - 'test/e2e/operation/discovery/**'
- - '!*.md'
- pull_request:
- branches: [ master ]
- paths:
- - '.github/workflows/e2e-discovery.yml'
- - 'infra/common/src/main/**'
- - 'features/db-discovery/**/src/main/**'
- - 'features/readwrite-splitting/**/src/main/**'
- - 'proxy/**/src/main/**'
- - 'jdbc/core/src/main/**'
- - '!test/**'
- - 'test/pom.xml'
- - 'test/e2e/fixture/**'
- - 'test/e2e/env/**'
- - 'test/e2e/operation/discovery/**'
- - '!*.md'
- workflow_dispatch:
-
-concurrency:
- group: e2e-db-discovery-${{ github.workflow }}-${{ github.ref }}
- cancel-in-progress: true
-
-env:
- MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true -Dspotless.apply.skip=true -Djacoco.skip=true -Drat.skip=true -Dfailsafe.skipAfterFailureCount=1 -Dio.netty.leakDetectionLevel=advanced
- REPOSITORY_NAME: shardingsphere
-
-jobs:
- db-discovery:
- name: E2E - Database Discovery
- runs-on: ubuntu-latest
- env:
- mysql_version: 5.7
- timeout-minutes: 15
- strategy:
- matrix:
- mode: [ Cluster ]
- steps:
- - uses: actions/checkout@v3
- - name: Cache Maven Repos
- uses: actions/cache@v3
- with:
- path: ~/.m2/repository
- key: ${{ env.REPOSITORY_NAME }}-maven-third-party-e2e-cache${{ github.sha }}
- restore-keys: |
- ${{ env.REPOSITORY_NAME }}-maven-third-party-e2e-cache
- ${{ env.REPOSITORY_NAME }}-maven-third-party-
- - name: Set up JDK 11
- uses: actions/setup-java@v3
- with:
- distribution: 'temurin'
- java-version: 11
- - name: Build Database Discovery E2E image
- run: ./mvnw -B clean install -am -pl test/e2e/operation/discovery -Pit.env.docker -DskipTests
- - name: Setup JDK 8 for Test
- uses: actions/setup-java@v3
- with:
- distribution: 'temurin'
- java-version: 8
- - name: Run MySQL Database Discovery E2E Test
- run: ./mvnw -nsu -B install -f test/e2e/operation/discovery/pom.xml -Dit.env.type=docker -Dit.docker.mysql.version=mysql:5.7
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
index 318b86c809b..0bbec07e3ab 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
@@ -55,12 +55,6 @@ import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
</#if>
-<#if feature?contains("db-discovery")>
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-</#if>
<#if feature?contains("mask")>
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
@@ -133,9 +127,6 @@ public final class Configuration {
<#if transaction!="local">
result.add(createTransactionRuleConfiguration());
</#if>
- <#if feature?contains("db-discovery")>
- result.add(createDatabaseDiscoveryRuleConfiguration());
- </#if>
<#if feature?contains("encrypt")>
result.add(createEncryptRuleConfiguration());
</#if>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/db-discovery.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/db-discovery.ftl
deleted file mode 100644
index b18bb68735a..00000000000
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/db-discovery.ftl
+++ /dev/null
@@ -1,42 +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.
- -->
-
- private DatabaseDiscoveryRuleConfiguration createDatabaseDiscoveryRuleConfiguration() {
- return new DatabaseDiscoveryRuleConfiguration(createDataSources(), createDiscoveryHeartbeats(), createDiscoveryTypes());
- }
-
- private Collection<DatabaseDiscoveryDataSourceRuleConfiguration> createDataSources() {
- DatabaseDiscoveryDataSourceRuleConfiguration result = new DatabaseDiscoveryDataSourceRuleConfiguration("rule", Arrays.asList("ds_0", "ds_1", "ds_2"), "mgr-heartbeat", "mgr");
- return Collections.singleton(result);
- }
-
- private Map<String, DatabaseDiscoveryHeartBeatConfiguration> createDiscoveryHeartbeats() {
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> result = new LinkedHashMap<>();
- Properties props = new Properties();
- props.put("keep-alive-cron", "0/5 * * * * ?");
- result.put("mgr-heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(props));
- return result;
- }
-
- private Map<String, AlgorithmConfiguration> createDiscoveryTypes() {
- Map<String, AlgorithmConfiguration> result = new LinkedHashMap<>();
- Properties props = new Properties();
- props.put("keep-alive-cron", "0/5 * * * * ?");
- props.put("group-name", "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
- result.put("mgr", new AlgorithmConfiguration("MySQL.MGR", props));
- return result;
- }
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/proxy/feature/db-discovery.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/proxy/feature/db-discovery.ftl
deleted file mode 100644
index 21e62102c0d..00000000000
--- a/examples/shardingsphere-example-generator/src/main/resources/template/proxy/feature/db-discovery.ftl
+++ /dev/null
@@ -1,39 +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.
- -->
- - !DB_DISCOVERY
- dataSources:
- ds_0:
- dataSourceNames:
- - primary_ds_0_replica_0
- - primary_ds_0_replica_1
- discoveryHeartbeatName: mgr-heartbeat
- discoveryTypeName: mgr
- ds_1:
- dataSourceNames:
- - primary_ds_1_replica_0
- - primary_ds_1_replica_1
- discoveryHeartbeatName: mgr-heartbeat
- discoveryTypeName: mgr
- discoveryHeartbeats:
- mgr-heartbeat:
- props:
- keep-alive-cron: '0/5 * * * * ?'
- discoveryTypes:
- mgr:
- type: MGR
- props:
- group-name: 92504d5b-6dec-11e8-91ea-246e9612aaf1
diff --git a/features/db-discovery/api/pom.xml b/features/db-discovery/api/pom.xml
deleted file mode 100644
index c7e46a2055e..00000000000
--- a/features/db-discovery/api/pom.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-api</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/DatabaseDiscoveryRuleConfiguration.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/DatabaseDiscoveryRuleConfiguration.java
deleted file mode 100644
index dea234c422e..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/DatabaseDiscoveryRuleConfiguration.java
+++ /dev/null
@@ -1,43 +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.dbdiscovery.api.config;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
-import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Database discovery rule configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration {
-
- private final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources;
-
- private final Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeats;
-
- private final Map<String, AlgorithmConfiguration> discoveryTypes;
-}
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java
deleted file mode 100644
index edf21d8575a..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java
+++ /dev/null
@@ -1,39 +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.dbdiscovery.api.config.rule;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.List;
-
-/**
- * Database discovery data source rule configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryDataSourceRuleConfiguration {
-
- private final String groupName;
-
- private final List<String> dataSourceNames;
-
- private final String discoveryHeartbeatName;
-
- private final String discoveryTypeName;
-}
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryHeartBeatConfiguration.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryHeartBeatConfiguration.java
deleted file mode 100644
index 11225b8856a..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryHeartBeatConfiguration.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.api.config.rule;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.Properties;
-
-/**
- * Database discovery heartbeat config.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryHeartBeatConfiguration {
-
- private final Properties props;
-}
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java
deleted file mode 100644
index 9a8bae8738b..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java
+++ /dev/null
@@ -1,35 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.SQLState;
-import org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
-
-/**
- * Database discovery provider exception.
- */
-public abstract class DBDiscoveryProviderException extends FeatureSQLException {
-
- private static final long serialVersionUID = 2693931450412858590L;
-
- private static final int FEATURE_CODE = 3;
-
- public DBDiscoveryProviderException(final SQLState sqlState, final int errorCode, final String reason, final Object... messageArgs) {
- super(sqlState, FEATURE_CODE, errorCode, reason, messageArgs);
- }
-}
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryProvider.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryProvider.java
deleted file mode 100644
index 3673385a9f8..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryProvider.java
+++ /dev/null
@@ -1,64 +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.dbdiscovery.spi;
-
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Database discovery provider.
- */
-public interface DatabaseDiscoveryProvider extends TypedSPI {
-
- /**
- * Check environment.
- *
- * @param databaseName database name
- * @param dataSources data sources
- */
- void checkEnvironment(String databaseName, Collection<DataSource> dataSources);
-
- /**
- * Judge whether database instance is primary.
- *
- * @param dataSource data source to be judged
- * @return is primary database instance or not
- * @throws SQLException SQL exception
- */
- boolean isPrimaryInstance(DataSource dataSource) throws SQLException;
-
- /**
- * Load replica data source status.
- *
- * @param replicaDataSource to be loaded replica data source
- * @return replica data source status
- * @throws SQLException SQL exception
- */
- ReplicaDataSourceStatus loadReplicaStatus(DataSource replicaDataSource) throws SQLException;
-
- /**
- * Get min enabled replicas.
- *
- * @return min enabled replicas
- */
- Optional<Integer> getMinEnabledReplicas();
-}
diff --git a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/ReplicaDataSourceStatus.java b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/ReplicaDataSourceStatus.java
deleted file mode 100644
index 417630d047d..00000000000
--- a/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/ReplicaDataSourceStatus.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.spi;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Replica data source status.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ReplicaDataSourceStatus {
-
- private final boolean online;
-
- private final long replicationDelayMilliseconds;
-}
diff --git a/features/db-discovery/core/pom.xml b/features/db-discovery/core/pom.xml
deleted file mode 100644
index 673625c92d4..00000000000
--- a/features/db-discovery/core/pom.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-core</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-mysql</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-opengauss</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-route</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-mode-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-schedule-core</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-test-fixture-jdbc</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java
deleted file mode 100644
index 653990d50af..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java
+++ /dev/null
@@ -1,133 +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.dbdiscovery.algorithm;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
-import org.apache.shardingsphere.mode.event.storage.DataSourceDisabledEvent;
-import org.apache.shardingsphere.mode.event.storage.PrimaryDataSourceChangedEvent;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-
-/**
- * Database discovery engine.
- */
-@RequiredArgsConstructor
-@Slf4j
-public final class DatabaseDiscoveryEngine {
-
- private final DatabaseDiscoveryProvider provider;
-
- private final InstanceContext instanceContext;
-
- /**
- * Check environment of database cluster.
- *
- * @param databaseName database name
- * @param dataSourceMap data source map
- */
- public void checkEnvironment(final String databaseName, final Map<String, DataSource> dataSourceMap) {
- provider.checkEnvironment(databaseName, dataSourceMap.values());
- }
-
- /**
- * Change primary data source.
- *
- * @param databaseName database name
- * @param groupName group name
- * @param originalPrimaryDataSourceName original primary data source name
- * @param dataSourceMap data source map
- * @param disabledDataSourceNames disabled data source names
- * @return changed primary data source name
- */
- public String changePrimaryDataSource(final String databaseName, final String groupName, final String originalPrimaryDataSourceName,
- final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames) {
- Optional<String> newPrimaryDataSourceName = findPrimaryDataSourceName(dataSourceMap);
- newPrimaryDataSourceName.ifPresent(optional -> postPrimaryChangedEvent(databaseName, groupName, originalPrimaryDataSourceName, optional));
- Map<String, DataSource> replicaDataSourceMap = new HashMap<>(dataSourceMap);
- newPrimaryDataSourceName.ifPresent(replicaDataSourceMap::remove);
- postReplicaDisabledEvent(databaseName, groupName, replicaDataSourceMap, disabledDataSourceNames);
- return newPrimaryDataSourceName.orElse("");
- }
-
- private Optional<String> findPrimaryDataSourceName(final Map<String, DataSource> dataSourceMap) {
- for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
- try {
- if (provider.isPrimaryInstance(entry.getValue())) {
- return Optional.of(entry.getKey());
- }
- } catch (final SQLException ex) {
- log.error("An exception occurred while judge primary data source: ", ex);
- }
- }
- return Optional.empty();
- }
-
- private void postPrimaryChangedEvent(final String databaseName, final String groupName, final String originalPrimaryDataSourceName, final String newPrimaryDataSourceName) {
- if (!newPrimaryDataSourceName.equals(originalPrimaryDataSourceName)) {
- instanceContext.getEventBusContext().post(new PrimaryDataSourceChangedEvent(new QualifiedDatabase(databaseName, groupName, newPrimaryDataSourceName)));
- }
- }
-
- private void postReplicaDisabledEvent(final String databaseName, final String groupName,
- final Map<String, DataSource> replicaDataSourceMap, final Collection<String> disabledDataSourceNames) {
- int enabledReplicasCount = replicaDataSourceMap.size() - disabledDataSourceNames.size() - 1;
- for (Entry<String, DataSource> entry : replicaDataSourceMap.entrySet()) {
- StorageNodeDataSource replicaStorageNode = createReplicaStorageNode(loadReplicaStatus(entry.getValue()));
- if (DataSourceState.ENABLED == replicaStorageNode.getStatus()) {
- enabledReplicasCount += disabledDataSourceNames.contains(entry.getKey()) ? 1 : 0;
- instanceContext.getEventBusContext().post(new DataSourceDisabledEvent(databaseName, groupName, entry.getKey(), replicaStorageNode));
- continue;
- }
- if (provider.getMinEnabledReplicas().isPresent() && 0 == provider.getMinEnabledReplicas().get()) {
- instanceContext.getEventBusContext().post(new DataSourceDisabledEvent(databaseName, groupName, entry.getKey(), replicaStorageNode));
- continue;
- }
- if (enabledReplicasCount > provider.getMinEnabledReplicas().get()) {
- enabledReplicasCount -= disabledDataSourceNames.contains(entry.getKey()) ? 0 : 1;
- instanceContext.getEventBusContext().post(new DataSourceDisabledEvent(databaseName, groupName, entry.getKey(), replicaStorageNode));
- }
- }
- }
-
- private StorageNodeDataSource createReplicaStorageNode(final ReplicaDataSourceStatus replicaStatus) {
- return new StorageNodeDataSource(StorageNodeRole.MEMBER, replicaStatus.isOnline() ? DataSourceState.ENABLED : DataSourceState.DISABLED, replicaStatus.getReplicationDelayMilliseconds());
- }
-
- private ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) {
- try {
- return provider.loadReplicaStatus(replicaDataSource);
- } catch (final SQLException ex) {
- log.error("Load data source replica status error: ", ex);
- return new ReplicaDataSourceStatus(false, 0L);
- }
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
deleted file mode 100644
index 5092c66e1df..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
+++ /dev/null
@@ -1,51 +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.dbdiscovery.checker;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
-import org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDBDiscoveryConfigurationException;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Database discovery rule configuration checker.
- */
-public final class DatabaseDiscoveryRuleConfigurationChecker implements RuleConfigurationChecker<DatabaseDiscoveryRuleConfiguration> {
-
- @Override
- public void check(final String databaseName, final DatabaseDiscoveryRuleConfiguration config, final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) {
- config.getDataSources().forEach(each -> ShardingSpherePreconditions.checkState(!each.getDiscoveryTypeName().isEmpty(),
- () -> new MissingRequiredDBDiscoveryConfigurationException(databaseName)));
- }
-
- @Override
- public int getOrder() {
- return DatabaseDiscoveryOrder.ORDER;
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getTypeClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java
deleted file mode 100644
index 37bbc7a6809..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.constant;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Database discovery order.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseDiscoveryOrder {
-
- /**
- * Database discovery order.
- */
- public static final int ORDER = 50;
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/datanode/DatabaseDiscoveryDataNodeBuilder.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/datanode/DatabaseDiscoveryDataNodeBuilder.java
deleted file mode 100644
index b3130a3d4dd..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/datanode/DatabaseDiscoveryDataNodeBuilder.java
+++ /dev/null
@@ -1,52 +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.dbdiscovery.datanode;
-
-import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.infra.datanode.DataNode;
-import org.apache.shardingsphere.infra.datanode.DataNodeBuilder;
-import org.apache.shardingsphere.infra.datanode.DataNodeUtils;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * Database discovery data node builder.
- */
-public final class DatabaseDiscoveryDataNodeBuilder implements DataNodeBuilder<DatabaseDiscoveryRule> {
-
- @Override
- public Collection<DataNode> build(final Collection<DataNode> dataNodes, final DatabaseDiscoveryRule rule) {
- Collection<DataNode> result = new LinkedList<>();
- for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each, rule.getDataSourceMapper()));
- }
- return result;
- }
-
- @Override
- public int getOrder() {
- return DatabaseDiscoveryOrder.ORDER;
- }
-
- @Override
- public Class<DatabaseDiscoveryRule> getTypeClass() {
- return DatabaseDiscoveryRule.class;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java
deleted file mode 100644
index 3067e0ec815..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java
+++ /dev/null
@@ -1,32 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Database discovery data source rule not found exception.
- */
-public final class DBDiscoveryDataSourceRuleNotFoundException extends DBDiscoverySQLException {
-
- private static final long serialVersionUID = -851752979377324961L;
-
- public DBDiscoveryDataSourceRuleNotFoundException(final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "Can not found database discovery data source rule in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java
deleted file mode 100644
index 4a748df5ddd..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java
+++ /dev/null
@@ -1,35 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.SQLState;
-import org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
-
-/**
- * Database discovery SQL exception.
- */
-public abstract class DBDiscoverySQLException extends FeatureSQLException {
-
- private static final long serialVersionUID = 5210719217645611897L;
-
- private static final int FEATURE_CODE = 3;
-
- public DBDiscoverySQLException(final SQLState sqlState, final int errorCode, final String reason, final Object... messageArgs) {
- super(sqlState, FEATURE_CODE, errorCode, reason, messageArgs);
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java
deleted file mode 100644
index e373844d334..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java
+++ /dev/null
@@ -1,32 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Missing required database discovery configuration exception.
- */
-public final class MissingRequiredDBDiscoveryConfigurationException extends DBDiscoverySQLException {
-
- private static final long serialVersionUID = -7743963772524386090L;
-
- public MissingRequiredDBDiscoveryConfigurationException(final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "No available database discovery rule configuration in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java
deleted file mode 100644
index bd99c39624b..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java
+++ /dev/null
@@ -1,32 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Missing required data source names configuration exception.
- */
-public final class MissingRequiredDataSourceNamesConfigurationException extends DBDiscoverySQLException {
-
- private static final long serialVersionUID = -3591914080387845399L;
-
- public MissingRequiredDataSourceNamesConfigurationException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "Data source names are required.");
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java
deleted file mode 100644
index d6dfe87e900..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java
+++ /dev/null
@@ -1,32 +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.dbdiscovery.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Missing required group name configuration exception.
- */
-public final class MissingRequiredGroupNameConfigurationException extends DBDiscoverySQLException {
-
- private static final long serialVersionUID = -3591914080387845399L;
-
- public MissingRequiredGroupNameConfigurationException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "Group name is required.");
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java
deleted file mode 100644
index 67ac474b253..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java
+++ /dev/null
@@ -1,56 +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.dbdiscovery.heartbeat;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.algorithm.DatabaseDiscoveryEngine;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.elasticjob.api.ShardingContext;
-import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Heartbeat job.
- */
-@RequiredArgsConstructor
-public final class HeartbeatJob implements SimpleJob {
-
- private final String databaseName;
-
- private final String groupName;
-
- private final String originalPrimaryDataSourceName;
-
- private final Map<String, DataSource> dataSourceMap;
-
- private final DatabaseDiscoveryProvider databaseDiscoveryProvider;
-
- private final Collection<String> disabledDataSourceNames;
-
- private final InstanceContext instanceContext;
-
- @Override
- public void execute(final ShardingContext shardingContext) {
- new DatabaseDiscoveryEngine(databaseDiscoveryProvider, instanceContext).changePrimaryDataSource(databaseName, groupName, originalPrimaryDataSourceName,
- dataSourceMap, disabledDataSourceNames);
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
deleted file mode 100644
index dccaf7b83f9..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
+++ /dev/null
@@ -1,82 +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.dbdiscovery.route;
-
-import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
-import org.apache.shardingsphere.dbdiscovery.route.impl.DatabaseDiscoveryDataSourceRouter;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryDataSourceRule;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.infra.binder.QueryContext;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.context.ConnectionContext;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.route.SQLRouter;
-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 java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Optional;
-
-/**
- * Database discovery SQL router.
- */
-public final class DatabaseDiscoverySQLRouter implements SQLRouter<DatabaseDiscoveryRule> {
-
- @Override
- public RouteContext createRouteContext(final QueryContext queryContext, final ShardingSphereRuleMetaData globalRuleMetaData, final ShardingSphereDatabase database,
- final DatabaseDiscoveryRule rule, final ConfigurationProperties props, final ConnectionContext connectionContext) {
- RouteContext result = new RouteContext();
- DatabaseDiscoveryDataSourceRule singleDataSourceRule = rule.getSingleDataSourceRule();
- String dataSourceName = new DatabaseDiscoveryDataSourceRouter(singleDataSourceRule).route();
- result.getRouteUnits().add(new RouteUnit(new RouteMapper(singleDataSourceRule.getGroupName(), dataSourceName), Collections.emptyList()));
- return result;
- }
-
- @Override
- public void decorateRouteContext(final RouteContext routeContext,
- final QueryContext queryContext, final ShardingSphereDatabase database, final DatabaseDiscoveryRule rule,
- final ConfigurationProperties props, final ConnectionContext connectionContext) {
- Collection<RouteUnit> toBeRemoved = new LinkedList<>();
- Collection<RouteUnit> toBeAdded = new LinkedList<>();
- for (RouteUnit each : routeContext.getRouteUnits()) {
- String dataSourceName = each.getDataSourceMapper().getLogicName();
- Optional<DatabaseDiscoveryDataSourceRule> dataSourceRule = rule.findDataSourceRule(dataSourceName);
- if (dataSourceRule.isPresent() && dataSourceRule.get().getGroupName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) {
- toBeRemoved.add(each);
- String actualDataSourceName = new DatabaseDiscoveryDataSourceRouter(dataSourceRule.get()).route();
- toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers()));
- }
- }
- routeContext.getRouteUnits().removeAll(toBeRemoved);
- routeContext.getRouteUnits().addAll(toBeAdded);
- }
-
- @Override
- public int getOrder() {
- return DatabaseDiscoveryOrder.ORDER;
- }
-
- @Override
- public Class<DatabaseDiscoveryRule> getTypeClass() {
- return DatabaseDiscoveryRule.class;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/impl/DatabaseDiscoveryDataSourceRouter.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/impl/DatabaseDiscoveryDataSourceRouter.java
deleted file mode 100644
index 39f464d3353..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/impl/DatabaseDiscoveryDataSourceRouter.java
+++ /dev/null
@@ -1,39 +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.dbdiscovery.route.impl;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryDataSourceRule;
-
-/**
- * Data source router for database discovery.
- */
-@RequiredArgsConstructor
-public final class DatabaseDiscoveryDataSourceRouter {
-
- private final DatabaseDiscoveryDataSourceRule rule;
-
- /**
- * Route.
- *
- * @return data source name
- */
- public String route() {
- return rule.getPrimaryDataSourceName();
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
deleted file mode 100644
index cf32aa48388..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
+++ /dev/null
@@ -1,148 +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.dbdiscovery.rule;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.Getter;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
-import org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredGroupNameConfigurationException;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
-/**
- * Database discovery data source rule.
- */
-@Getter
-public final class DatabaseDiscoveryDataSourceRule {
-
- private final String groupName;
-
- private final List<String> dataSourceNames;
-
- private final Properties heartbeatProps;
-
- private final DatabaseDiscoveryProvider provider;
-
- private final Collection<String> disabledDataSourceNames = new HashSet<>();
-
- private volatile String primaryDataSourceName;
-
- public DatabaseDiscoveryDataSourceRule(final DatabaseDiscoveryDataSourceRuleConfiguration config,
- final Properties props, final DatabaseDiscoveryProvider provider) {
- checkConfiguration(config);
- groupName = config.getGroupName();
- dataSourceNames = config.getDataSourceNames();
- this.heartbeatProps = props;
- this.provider = provider;
- }
-
- private void checkConfiguration(final DatabaseDiscoveryDataSourceRuleConfiguration config) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getGroupName()), "Group name is required.");
- ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(config.getGroupName()), MissingRequiredGroupNameConfigurationException::new);
- ShardingSpherePreconditions.checkState(null != config.getDataSourceNames()
- && !config.getDataSourceNames().isEmpty(), MissingRequiredDataSourceNamesConfigurationException::new);
- }
-
- /**
- * Get replica data source names.
- *
- * @return available replica data source names
- */
- public List<String> getReplicaDataSourceNames() {
- return dataSourceNames.stream().filter(each -> !disabledDataSourceNames.contains(each) && !primaryDataSourceName.equals(each)).collect(Collectors.toList());
- }
-
- /**
- * Disable data source.
- *
- * @param dataSourceName data source name to be disabled
- */
- public void disableDataSource(final String dataSourceName) {
- disabledDataSourceNames.add(dataSourceName);
- }
-
- /**
- * Enable data source.
- *
- * @param dataSourceName data source name to be enabled
- */
- public void enableDataSource(final String dataSourceName) {
- disabledDataSourceNames.remove(dataSourceName);
- }
-
- /**
- * Change primary data source name.
- *
- * @param primaryDataSourceName to be changed primary data source name
- */
- public void changePrimaryDataSourceName(final String primaryDataSourceName) {
- this.primaryDataSourceName = primaryDataSourceName;
- }
-
- /**
- * Get data source.
- *
- * @param dataSourceMap data source map
- * @return data source
- */
- public Map<String, DataSource> getDataSourceGroup(final Map<String, DataSource> dataSourceMap) {
- Map<String, DataSource> result = new HashMap<>(dataSourceMap.size(), 1);
- for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
- if (dataSourceNames.contains(entry.getKey())) {
- result.put(entry.getKey(), entry.getValue());
- }
- }
- return result;
- }
-
- /**
- * Get data source mapper.
- *
- * @return data source mapper
- */
- public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
- return Collections.singletonMap(groupName, getActualDataSourceNames());
- }
-
- private Collection<DataSourceRoleInfo> getActualDataSourceNames() {
- Collection<DataSourceRoleInfo> result = new LinkedHashSet<>();
- result.add(new DataSourceRoleInfo(primaryDataSourceName, DataSourceRole.PRIMARY));
- dataSourceNames.forEach(each -> {
- if (!primaryDataSourceName.equals(each)) {
- result.add(new DataSourceRoleInfo(each, DataSourceRole.MEMBER));
- }
- });
- return result;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
deleted file mode 100644
index 19900def0f0..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ /dev/null
@@ -1,233 +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.dbdiscovery.rule;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.Getter;
-import org.apache.shardingsphere.dbdiscovery.algorithm.DatabaseDiscoveryEngine;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryDataSourceRuleNotFoundException;
-import org.apache.shardingsphere.dbdiscovery.heartbeat.HeartbeatJob;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
-import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.schedule.CronJob;
-import org.apache.shardingsphere.infra.schedule.ScheduleContext;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.mode.event.storage.PrimaryDataSourceChangedEvent;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent;
-import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Properties;
-
-/**
- * Database discovery rule.
- */
-public final class DatabaseDiscoveryRule implements DatabaseRule, DataSourceContainedRule, DynamicDataSourceContainedRule, ExportableRule {
-
- @Getter
- private final RuleConfiguration configuration;
-
- private final String databaseName;
-
- private final Map<String, DataSource> dataSourceMap;
-
- private final Map<String, DatabaseDiscoveryProvider> providerTypes;
-
- @Getter
- private final Map<String, DatabaseDiscoveryDataSourceRule> dataSourceRules;
-
- private final InstanceContext instanceContext;
-
- private final ScheduleContext scheduleContext;
-
- public DatabaseDiscoveryRule(final String databaseName, final Map<String, DataSource> dataSourceMap, final DatabaseDiscoveryRuleConfiguration ruleConfig, final InstanceContext instanceContext) {
- configuration = ruleConfig;
- this.databaseName = databaseName;
- this.dataSourceMap = dataSourceMap;
- this.instanceContext = instanceContext;
- this.scheduleContext = ScheduleContextFactory.newInstance(instanceContext.getModeConfiguration());
- providerTypes = getDiscoveryProviders(ruleConfig.getDiscoveryTypes());
- dataSourceRules = getDataSourceRules(ruleConfig.getDataSources(), ruleConfig.getDiscoveryHeartbeats());
- findPrimaryReplicaRelationship(databaseName, dataSourceMap);
- initHeartBeatJobs();
- }
-
- private static Map<String, DatabaseDiscoveryProvider> getDiscoveryProviders(final Map<String, AlgorithmConfiguration> discoveryTypesConfig) {
- Map<String, DatabaseDiscoveryProvider> result = new LinkedHashMap<>(discoveryTypesConfig.size(), 1);
- for (Entry<String, AlgorithmConfiguration> entry : discoveryTypesConfig.entrySet()) {
- result.put(entry.getKey(), TypedSPILoader.getService(DatabaseDiscoveryProvider.class, entry.getValue().getType(), entry.getValue().getProps()));
- }
- return result;
- }
-
- private Map<String, DatabaseDiscoveryDataSourceRule> getDataSourceRules(final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources,
- final Map<String, DatabaseDiscoveryHeartBeatConfiguration> heartbeatConfig) {
- Map<String, DatabaseDiscoveryDataSourceRule> result = new HashMap<>(dataSources.size(), 1);
- for (DatabaseDiscoveryDataSourceRuleConfiguration each : dataSources) {
- result.put(each.getGroupName(), new DatabaseDiscoveryDataSourceRule(each, Strings.isNullOrEmpty(each.getDiscoveryHeartbeatName()) ? new Properties()
- : heartbeatConfig.get(each.getDiscoveryHeartbeatName()).getProps(), providerTypes.get(each.getDiscoveryTypeName())));
- }
- return result;
- }
-
- private void findPrimaryReplicaRelationship(final String databaseName, final Map<String, DataSource> dataSourceMap) {
- for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
- String groupName = entry.getKey();
- DatabaseDiscoveryDataSourceRule dataSourceRule = entry.getValue();
- Map<String, DataSource> originalDataSourceMap = dataSourceRule.getDataSourceGroup(dataSourceMap);
- DatabaseDiscoveryEngine engine = new DatabaseDiscoveryEngine(dataSourceRule.getProvider(), instanceContext);
- engine.checkEnvironment(databaseName, originalDataSourceMap);
- dataSourceRule.changePrimaryDataSourceName(engine.changePrimaryDataSource(
- databaseName, groupName, entry.getValue().getPrimaryDataSourceName(), originalDataSourceMap, dataSourceRule.getDisabledDataSourceNames()));
- }
- }
-
- private void initHeartBeatJobs() {
- for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
- DatabaseDiscoveryDataSourceRule rule = entry.getValue();
- String jobName = rule.getProvider().getType() + "-" + databaseName + "-" + rule.getGroupName();
- CronJob job = new CronJob(jobName, each -> new HeartbeatJob(databaseName, rule.getGroupName(), rule.getPrimaryDataSourceName(), rule.getDataSourceGroup(dataSourceMap),
- rule.getProvider(), rule.getDisabledDataSourceNames(), instanceContext).execute(null),
- rule.getHeartbeatProps().getProperty("keep-alive-cron"));
- scheduleContext.startSchedule(job);
- }
- }
-
- /**
- * Get single data source rule.
- *
- * @return data source rule
- */
- public DatabaseDiscoveryDataSourceRule getSingleDataSourceRule() {
- return dataSourceRules.values().iterator().next();
- }
-
- /**
- * Find data source rule.
- *
- * @param dataSourceName data source name
- * @return found data source rule
- */
- public Optional<DatabaseDiscoveryDataSourceRule> findDataSourceRule(final String dataSourceName) {
- return Optional.ofNullable(dataSourceRules.get(dataSourceName));
- }
-
- @Override
- public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
- Map<String, Collection<DataSourceRoleInfo>> result = new LinkedHashMap<>();
- for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
- result.putAll(entry.getValue().getDataSourceMapper());
- }
- return result;
- }
-
- @Override
- public void restartHeartBeatJob(final DataSourceStatusChangedEvent event) {
- PrimaryDataSourceChangedEvent dataSourceEvent = (PrimaryDataSourceChangedEvent) event;
- QualifiedDatabase qualifiedDatabase = dataSourceEvent.getQualifiedDatabase();
- DatabaseDiscoveryDataSourceRule dataSourceRule = dataSourceRules.get(qualifiedDatabase.getGroupName());
- ShardingSpherePreconditions.checkNotNull(dataSourceRule, () -> new DBDiscoveryDataSourceRuleNotFoundException(databaseName));
- dataSourceRule.changePrimaryDataSourceName(qualifiedDatabase.getDataSourceName());
- initHeartBeatJobs();
- }
-
- @Override
- public void closeSingleHeartBeatJob(final String groupName) {
- DatabaseDiscoveryDataSourceRule dataSourceRule = dataSourceRules.get(groupName);
- ShardingSpherePreconditions.checkNotNull(dataSourceRule, () -> new DBDiscoveryDataSourceRuleNotFoundException(databaseName));
- scheduleContext.closeSchedule(dataSourceRule.getProvider().getType() + "-" + databaseName + "-" + dataSourceRule.getGroupName());
- deleteStorageNodeDataSources(dataSourceRule);
- }
-
- private void deleteStorageNodeDataSources(final DatabaseDiscoveryDataSourceRule dataSourceRule) {
- for (String each : dataSourceRule.getDataSourceNames()) {
- instanceContext.getEventBusContext().post(new StorageNodeDataSourceDeletedEvent(new QualifiedDatabase(databaseName, dataSourceRule.getGroupName(), each)));
- }
- }
-
- @Override
- public void closeAllHeartBeatJob() {
- for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
- DatabaseDiscoveryDataSourceRule rule = entry.getValue();
- scheduleContext.closeSchedule(rule.getProvider().getType() + "-" + databaseName + "-" + rule.getGroupName());
- deleteStorageNodeDataSources(rule);
- }
- }
-
- @Override
- public String getPrimaryDataSourceName(final String dataSourceName) {
- return dataSourceRules.get(dataSourceName).getPrimaryDataSourceName();
- }
-
- @Override
- public Collection<String> getReplicaDataSourceNames(final String dataSourceName) {
- return dataSourceRules.get(dataSourceName).getReplicaDataSourceNames();
- }
-
- @Override
- public void updateStatus(final DataSourceStatusChangedEvent event) {
- StorageNodeDataSourceChangedEvent dataSourceChangedEvent = (StorageNodeDataSourceChangedEvent) event;
- DatabaseDiscoveryDataSourceRule dataSourceRule = dataSourceRules.get(dataSourceChangedEvent.getQualifiedDatabase().getGroupName());
- Preconditions.checkNotNull(dataSourceRule, "Can not find database discovery data source rule in database `%s`", databaseName);
- if (DataSourceState.DISABLED == dataSourceChangedEvent.getDataSource().getStatus()) {
- dataSourceRule.disableDataSource(dataSourceChangedEvent.getQualifiedDatabase().getDataSourceName());
- } else {
- dataSourceRule.enableDataSource(dataSourceChangedEvent.getQualifiedDatabase().getDataSourceName());
- }
- }
-
- @Override
- public Map<String, Object> getExportData() {
- return Collections.singletonMap(ExportableConstants.EXPORT_DB_DISCOVERY_PRIMARY_DATA_SOURCES, exportPrimaryDataSourceMap());
- }
-
- private Map<String, String> exportPrimaryDataSourceMap() {
- Map<String, String> result = new HashMap<>(dataSourceRules.size(), 1);
- dataSourceRules.forEach((name, dataSourceRule) -> result.put(dataSourceRule.getGroupName(), dataSourceRule.getPrimaryDataSourceName()));
- return result;
- }
-
- @Override
- public String getType() {
- return DatabaseDiscoveryRule.class.getSimpleName();
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
deleted file mode 100644
index 498768e73b9..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
+++ /dev/null
@@ -1,59 +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.dbdiscovery.rule.builder;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Database discovery rule builder.
- */
-public final class DatabaseDiscoveryRuleBuilder implements DatabaseRuleBuilder<DatabaseDiscoveryRuleConfiguration> {
-
- @Override
- public DatabaseDiscoveryRule build(final DatabaseDiscoveryRuleConfiguration config, final String databaseName,
- final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> builtRules, final InstanceContext instanceContext) {
- Map<String, DataSource> realDataSourceMap = new HashMap<>();
- for (DatabaseDiscoveryDataSourceRuleConfiguration each : config.getDataSources()) {
- for (String datasourceName : each.getDataSourceNames()) {
- realDataSourceMap.put(datasourceName, dataSources.get(datasourceName));
- }
- }
- return new DatabaseDiscoveryRule(databaseName, realDataSourceMap, config, instanceContext);
- }
-
- @Override
- public int getOrder() {
- return DatabaseDiscoveryOrder.ORDER;
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getTypeClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java
deleted file mode 100644
index 4d16704121f..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/YamlDatabaseDiscoveryRuleConfiguration.java
+++ /dev/null
@@ -1,48 +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.dbdiscovery.yaml.config;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Database discovery rule configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlDatabaseDiscoveryRuleConfiguration implements YamlRuleConfiguration {
-
- private Map<String, YamlDatabaseDiscoveryDataSourceRuleConfiguration> dataSources = new LinkedHashMap<>();
-
- private Map<String, YamlDatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeats = new LinkedHashMap<>();
-
- private Map<String, YamlAlgorithmConfiguration> discoveryTypes = new LinkedHashMap<>();
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationType() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java
deleted file mode 100644
index 5495a009b63..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryDataSourceRuleConfiguration.java
+++ /dev/null
@@ -1,39 +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.dbdiscovery.yaml.config.rule;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Database discovery data source rule configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlDatabaseDiscoveryDataSourceRuleConfiguration implements YamlConfiguration {
-
- private List<String> dataSourceNames = new ArrayList<>();
-
- private String discoveryHeartbeatName;
-
- private String discoveryTypeName;
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryHeartBeatConfiguration.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryHeartBeatConfiguration.java
deleted file mode 100644
index b9f2c1ade64..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/config/rule/YamlDatabaseDiscoveryHeartBeatConfiguration.java
+++ /dev/null
@@ -1,34 +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.dbdiscovery.yaml.config.rule;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-import java.util.Properties;
-
-/**
- * Database discovery heart beat configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlDatabaseDiscoveryHeartBeatConfiguration implements YamlConfiguration {
-
- private Properties props = new Properties();
-}
diff --git a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapper.java b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapper.java
deleted file mode 100644
index 86f7b8904d4..00000000000
--- a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapper.java
+++ /dev/null
@@ -1,114 +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.dbdiscovery.yaml.swapper;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.yaml.config.swapper.algorithm.YamlAlgorithmConfigurationSwapper;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-
-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;
-
-/**
- * YAML database discovery rule configuration swapper.
- */
-public final class YamlDatabaseDiscoveryRuleConfigurationSwapper implements YamlRuleConfigurationSwapper<YamlDatabaseDiscoveryRuleConfiguration, DatabaseDiscoveryRuleConfiguration> {
-
- private final YamlAlgorithmConfigurationSwapper algorithmSwapper = new YamlAlgorithmConfigurationSwapper();
-
- @Override
- public YamlDatabaseDiscoveryRuleConfiguration swapToYamlConfiguration(final DatabaseDiscoveryRuleConfiguration data) {
- YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration();
- result.setDataSources(data.getDataSources().stream().collect(
- Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
- if (null != data.getDiscoveryHeartbeats()) {
- data.getDiscoveryHeartbeats().forEach((key, value) -> result.getDiscoveryHeartbeats().put(key, swapToYamlConfiguration(value)));
- }
- 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.setDataSourceNames(dataSourceRuleConfig.getDataSourceNames());
- result.setDiscoveryHeartbeatName(dataSourceRuleConfig.getDiscoveryHeartbeatName());
- result.setDiscoveryTypeName(dataSourceRuleConfig.getDiscoveryTypeName());
- return result;
- }
-
- private YamlDatabaseDiscoveryHeartBeatConfiguration swapToYamlConfiguration(final DatabaseDiscoveryHeartBeatConfiguration heartBeatRuleConfig) {
- YamlDatabaseDiscoveryHeartBeatConfiguration result = new YamlDatabaseDiscoveryHeartBeatConfiguration();
- result.setProps(heartBeatRuleConfig.getProps());
- 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, DatabaseDiscoveryHeartBeatConfiguration> heartBeats = new LinkedHashMap<>(yamlConfig.getDiscoveryHeartbeats().entrySet().size(), 1);
- if (null != yamlConfig.getDiscoveryHeartbeats()) {
- yamlConfig.getDiscoveryHeartbeats().forEach((key, value) -> heartBeats.put(key, swapToObject(value)));
- }
- Map<String, AlgorithmConfiguration> 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, heartBeats, haTypes);
- }
-
- private DatabaseDiscoveryDataSourceRuleConfiguration swapToObject(final String name, final YamlDatabaseDiscoveryDataSourceRuleConfiguration yamlDataSourceRuleConfig) {
- return new DatabaseDiscoveryDataSourceRuleConfiguration(name, yamlDataSourceRuleConfig.getDataSourceNames(), yamlDataSourceRuleConfig.getDiscoveryHeartbeatName(),
- yamlDataSourceRuleConfig.getDiscoveryTypeName());
- }
-
- private DatabaseDiscoveryHeartBeatConfiguration swapToObject(final YamlDatabaseDiscoveryHeartBeatConfiguration yamlHeartbeatRuleConfig) {
- return new DatabaseDiscoveryHeartBeatConfiguration(yamlHeartbeatRuleConfig.getProps());
- }
-
- @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/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker b/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker
deleted file mode 100644
index f8b226bba59..00000000000
--- a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker
+++ /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.dbdiscovery.checker.DatabaseDiscoveryRuleConfigurationChecker
diff --git a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder b/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder
deleted file mode 100644
index 8a5bbae4e89..00000000000
--- a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder
+++ /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.dbdiscovery.datanode.DatabaseDiscoveryDataNodeBuilder
diff --git a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter b/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
deleted file mode 100644
index ce7774e1dae..00000000000
--- a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.SQLRouter
+++ /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.dbdiscovery.route.DatabaseDiscoverySQLRouter
diff --git a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder b/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder
deleted file mode 100644
index e1857f55e0f..00000000000
--- a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder
+++ /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.dbdiscovery.rule.builder.DatabaseDiscoveryRuleBuilder
diff --git a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper b/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
deleted file mode 100644
index 19dd3f7918c..00000000000
--- a/features/db-discovery/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
+++ /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.dbdiscovery.yaml.swapper.YamlDatabaseDiscoveryRuleConfigurationSwapper
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
deleted file mode 100644
index 38e1c2a5f22..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
+++ /dev/null
@@ -1,66 +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.dbdiscovery.checker;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDBDiscoveryConfigurationException;
-import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPILoader;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class DatabaseDiscoveryRuleConfigurationCheckerTest {
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test
- void assertValidCheck() {
- DatabaseDiscoveryRuleConfiguration config = getValidConfiguration();
- RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
- checker.check("test", config, Collections.emptyMap(), Collections.emptyList());
- }
-
- private DatabaseDiscoveryRuleConfiguration getValidConfiguration() {
- DatabaseDiscoveryRuleConfiguration result = mock(DatabaseDiscoveryRuleConfiguration.class);
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = mock(DatabaseDiscoveryDataSourceRuleConfiguration.class);
- when(dataSourceRuleConfig.getDiscoveryTypeName()).thenReturn("jdbc");
- when(result.getDataSources()).thenReturn(Collections.singleton(dataSourceRuleConfig));
- return result;
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test
- void assertInvalidCheck() {
- DatabaseDiscoveryRuleConfiguration config = getInvalidConfiguration();
- RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
- assertThrows(MissingRequiredDBDiscoveryConfigurationException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
- }
-
- private DatabaseDiscoveryRuleConfiguration getInvalidConfiguration() {
- DatabaseDiscoveryRuleConfiguration result = mock(DatabaseDiscoveryRuleConfiguration.class);
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = mock(DatabaseDiscoveryDataSourceRuleConfiguration.class);
- when(dataSourceRuleConfig.getDiscoveryTypeName()).thenReturn("");
- when(result.getDataSources()).thenReturn(Collections.singleton(dataSourceRuleConfig));
- return result;
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/CoreDatabaseDiscoveryProviderFixture.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/CoreDatabaseDiscoveryProviderFixture.java
deleted file mode 100644
index fc13e830add..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/CoreDatabaseDiscoveryProviderFixture.java
+++ /dev/null
@@ -1,52 +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.dbdiscovery.fixture;
-
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Optional;
-
-public final class CoreDatabaseDiscoveryProviderFixture implements DatabaseDiscoveryProvider {
-
- @Override
- public void checkEnvironment(final String databaseName, final Collection<DataSource> dataSource) {
- }
-
- @Override
- public boolean isPrimaryInstance(final DataSource dataSource) {
- return true;
- }
-
- @Override
- public ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) {
- return new ReplicaDataSourceStatus(true, 0L);
- }
-
- @Override
- public Optional<Integer> getMinEnabledReplicas() {
- return Optional.empty();
- }
-
- @Override
- public String getType() {
- return "CORE.FIXTURE";
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
deleted file mode 100644
index 28405aa1aa5..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
+++ /dev/null
@@ -1,154 +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.dbdiscovery.route;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.infra.binder.QueryContext;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.context.ConnectionContext;
-import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.route.SQLRouter;
-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.util.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-
-@ExtendWith(MockitoExtension.class)
-class DatabaseDiscoverySQLRouterTest {
-
- private static final String DATA_SOURCE_NAME = "ds";
-
- private static final String NONE_DB_DISCOVERY_DATA_SOURCE_NAME = "noneDatabaseDiscoveryDataSource";
-
- private static final String PRIMARY_DATA_SOURCE = "primary";
-
- private DatabaseDiscoveryRule rule;
-
- @Mock
- private SQLStatementContext<SQLStatement> sqlStatementContext;
-
- private DatabaseDiscoverySQLRouter sqlRouter;
-
- @BeforeEach
- void setUp() {
- ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class)));
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(
- DATA_SOURCE_NAME, Collections.singletonList(PRIMARY_DATA_SOURCE), "", "CORE.FIXTURE");
- AlgorithmConfiguration algorithmConfig = new AlgorithmConfiguration("CORE.FIXTURE", new Properties());
- DatabaseDiscoveryRuleConfiguration config = new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig),
- Collections.singletonMap("ha_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
- Collections.singletonMap("CORE.FIXTURE", algorithmConfig));
- InstanceContext instanceContext = mock(InstanceContext.class, RETURNS_DEEP_STUBS);
- rule = new DatabaseDiscoveryRule(DATA_SOURCE_NAME, Collections.singletonMap(PRIMARY_DATA_SOURCE, new MockedDataSource()), config, instanceContext);
- sqlRouter = (DatabaseDiscoverySQLRouter) OrderedSPILoader.getServices(SQLRouter.class, Collections.singleton(rule)).get(rule);
- }
-
- @Test
- void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
- QueryContext queryContext = new QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS),
- new ShardingSphereRuleMetaData(Collections.singleton(rule)), Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext,
- mock(ShardingSphereRuleMetaData.class), database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
- }
-
- @Test
- void assertDecorateRouteContextToPrimaryDataSource() {
- RouteContext actual = mockRouteContext();
- QueryContext queryContext = new QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS),
- new ShardingSphereRuleMetaData(Collections.singleton(rule)), Collections.emptyMap());
- sqlRouter.decorateRouteContext(actual, queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME));
- assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
- }
-
- @Test
- void assertCreateRouteContextToPrimaryDataSourceWithLock() {
- QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS),
- new ShardingSphereRuleMetaData(Collections.singleton(rule)), Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext,
- mock(ShardingSphereRuleMetaData.class), database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
- }
-
- @Test
- void assertDecorateRouteContextToPrimaryDataSourceWithLock() {
- RouteContext actual = mockRouteContext();
- QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS),
- new ShardingSphereRuleMetaData(Collections.singleton(rule)), Collections.emptyMap());
- sqlRouter.decorateRouteContext(actual, queryContext, database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME));
- assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
- }
-
- @Test
- void assertCreateRouteContextToPrimaryDataSource() {
- QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS),
- new ShardingSphereRuleMetaData(Collections.singleton(rule)), Collections.emptyMap());
- RouteContext actual = sqlRouter.createRouteContext(queryContext,
- mock(ShardingSphereRuleMetaData.class), database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext());
- Iterator<String> routedDataSourceNames = actual.getActualDataSourceNames().iterator();
- assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
- }
-
- private RouteContext mockRouteContext() {
- RouteContext result = new RouteContext();
- RouteUnit routeUnit = new RouteUnit(new RouteMapper(DATA_SOURCE_NAME, DATA_SOURCE_NAME), Collections.singletonList(new RouteMapper("table", "table_0")));
- result.getRouteUnits().add(routeUnit);
- result.getRouteUnits().add(new RouteUnit(new RouteMapper(NONE_DB_DISCOVERY_DATA_SOURCE_NAME, NONE_DB_DISCOVERY_DATA_SOURCE_NAME), Collections.emptyList()));
- return result;
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
deleted file mode 100644
index 0721c1ba57e..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
+++ /dev/null
@@ -1,75 +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.dbdiscovery.rule;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
-import org.apache.shardingsphere.dbdiscovery.mysql.type.MGRMySQLDatabaseDiscoveryProvider;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class DatabaseDiscoveryDataSourceRuleTest {
-
- private final DatabaseDiscoveryDataSourceRule databaseDiscoveryDataSourceRule = new DatabaseDiscoveryDataSourceRule(
- new DatabaseDiscoveryDataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "ha_heartbeat", "discoveryTypeName"), new Properties(),
- new MGRMySQLDatabaseDiscoveryProvider());
-
- @Test
- void assertNewHADataSourceRuleWithoutName() {
- assertThrows(IllegalArgumentException.class,
- () -> new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration("", Arrays.asList("ds_0", "ds_1"), "ha_heartbeat", "discoveryTypeName"),
- new Properties(), new MGRMySQLDatabaseDiscoveryProvider()));
- }
-
- @Test
- void assertNewHADataSourceRuleWithNullDataSourceName() {
- assertThrows(MissingRequiredDataSourceNamesConfigurationException.class,
- () -> new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration(
- "ds", null, "ha_heartbeat", "discoveryTypeName"), new Properties(), new MGRMySQLDatabaseDiscoveryProvider()));
- }
-
- @Test
- void assertNewHADataSourceRuleWithEmptyDataSourceName() {
- assertThrows(MissingRequiredDataSourceNamesConfigurationException.class,
- () -> new DatabaseDiscoveryDataSourceRule(new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.emptyList(), "ha_heartbeat", "discoveryTypeName"),
- new Properties(), new MGRMySQLDatabaseDiscoveryProvider()));
- }
-
- @Test
- void assertGetDataSourceNamesWithoutDisabledDataSourceNames() {
- assertThat(databaseDiscoveryDataSourceRule.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
- }
-
- @Test
- void assertGetDataSourceMapper() {
- databaseDiscoveryDataSourceRule.changePrimaryDataSourceName("ds_1");
- assertThat(databaseDiscoveryDataSourceRule.getDataSourceMapper(),
- is(Collections.singletonMap("test_pr",
- new LinkedHashSet<>(Arrays.asList(new DataSourceRoleInfo("ds_1", DataSourceRole.PRIMARY), new DataSourceRoleInfo("ds_0", DataSourceRole.MEMBER))))));
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
deleted file mode 100644
index e5a27e24e0a..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++ /dev/null
@@ -1,100 +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.dbdiscovery.rule;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import javax.sql.DataSource;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class DatabaseDiscoveryRuleTest {
-
- private final Map<String, DataSource> dataSourceMap = Collections.singletonMap("primary_ds", new MockedDataSource());
-
- @BeforeAll
- static void setUp() {
- ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class)));
- }
-
- @Test
- void assertFindDataSourceRule() {
- Optional<DatabaseDiscoveryDataSourceRule> actual = createRule().findDataSourceRule("replica_ds");
- assertTrue(actual.isPresent());
- assertDataSourceRule(actual.get());
- }
-
- @Test
- void assertGetSingleDataSourceRule() {
- assertDataSourceRule(createRule().getSingleDataSourceRule());
- }
-
- private void assertDataSourceRule(final DatabaseDiscoveryDataSourceRule actual) {
- assertThat(actual.getGroupName(), is("replica_ds"));
- assertThat(actual.getDataSourceNames(), is(Arrays.asList("primary_ds", "replica_ds_0", "replica_ds_1")));
- }
-
- @Test
- void assertGetDataSourceMapper() {
- DatabaseDiscoveryRule databaseDiscoveryRule = createRule();
- Map<String, Collection<DataSourceRoleInfo>> actual = databaseDiscoveryRule.getDataSourceMapper();
- assertThat(actual, is(Collections.singletonMap("replica_ds", new LinkedHashSet<>(Arrays.asList(new DataSourceRoleInfo("primary_ds", DataSourceRole.PRIMARY),
- new DataSourceRoleInfo("replica_ds_0", DataSourceRole.MEMBER), new DataSourceRoleInfo("replica_ds_1", DataSourceRole.MEMBER))))));
- }
-
- @Test
- void assertGetExportedMethods() {
- DatabaseDiscoveryRule databaseDiscoveryRule = createRule();
- assertThat(databaseDiscoveryRule.getExportData().get(ExportableConstants.EXPORT_DB_DISCOVERY_PRIMARY_DATA_SOURCES), is(Collections.singletonMap("replica_ds", "primary_ds")));
- }
-
- private DatabaseDiscoveryRule createRule() {
- DatabaseDiscoveryDataSourceRuleConfiguration config =
- new DatabaseDiscoveryDataSourceRuleConfiguration("replica_ds", Arrays.asList("primary_ds", "replica_ds_0", "replica_ds_1"), "", "CORE.FIXTURE");
- InstanceContext instanceContext = mock(InstanceContext.class, RETURNS_DEEP_STUBS);
- when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
- return new DatabaseDiscoveryRule("db_discovery", dataSourceMap, new DatabaseDiscoveryRuleConfiguration(
- Collections.singleton(config), Collections.singletonMap("discovery_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
- Collections.singletonMap("CORE.FIXTURE", new AlgorithmConfiguration("CORE.FIXTURE", new Properties()))), instanceContext);
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
deleted file mode 100644
index 0db87ce4ecd..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilderTest.java
+++ /dev/null
@@ -1,59 +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.dbdiscovery.rule.builder;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
-import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class DatabaseDiscoveryRuleBuilderTest {
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test
- void assertBuild() {
- ScheduleContextFactory.newInstance(new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class)));
- DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(
- Collections.singleton(new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.singletonList("name"), "", "CORE.FIXTURE")),
- Collections.singletonMap("ha_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
- Collections.singletonMap("CORE.FIXTURE", new AlgorithmConfiguration("CORE.FIXTURE", new Properties())));
- DatabaseRuleBuilder builder = OrderedSPILoader.getServices(DatabaseRuleBuilder.class, Collections.singletonList(ruleConfig)).get(ruleConfig);
- InstanceContext instanceContext = mock(InstanceContext.class, RETURNS_DEEP_STUBS);
- when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
- assertThat(builder.build(ruleConfig, "test_schema",
- Collections.singletonMap("name", new MockedDataSource()), Collections.emptyList(), instanceContext), instanceOf(DatabaseDiscoveryRule.class));
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java
deleted file mode 100644
index 689b3289c70..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlDatabaseDiscoveryRuleConfigurationSwapperTest.java
+++ /dev/null
@@ -1,96 +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.dbdiscovery.yaml.swapper;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.yaml.config.rule.YamlDatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class YamlDatabaseDiscoveryRuleConfigurationSwapperTest {
-
- @Test
- void assertSwapToYamlWithLoadBalanceAlgorithm() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig =
- new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"), "ha_heartbeat", "discoveryTypeName");
- YamlDatabaseDiscoveryRuleConfiguration actual = getYamlDatabaseDiscoveryRuleConfigurationSwapper().swapToYamlConfiguration(
- new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig),
- Collections.emptyMap(), Collections.singletonMap("mgr", new AlgorithmConfiguration("MySQL.MGR", new Properties()))));
- assertThat(actual.getDataSources().keySet(), is(Collections.singleton("ds")));
- assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
- }
-
- @Test
- void assertSwapToYamlWithoutLoadBalanceAlgorithm() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.singletonList("dataSourceName"),
- "ha_heartbeat", "discoveryTypeName");
- YamlDatabaseDiscoveryRuleConfiguration actual = getYamlDatabaseDiscoveryRuleConfigurationSwapper().swapToYamlConfiguration(
- new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig), Collections.emptyMap(), Collections.emptyMap()));
- assertThat(actual.getDataSources().keySet(), is(Collections.singleton("ds")));
- assertThat(actual.getDataSources().get("ds").getDataSourceNames(), is(Collections.singletonList("dataSourceName")));
- }
-
- @Test
- void assertSwapToObjectWithLoadBalanceAlgorithmType() {
- YamlDatabaseDiscoveryRuleConfiguration yamlConfig = createYamlDatabaseDiscoveryRuleConfiguration();
- DatabaseDiscoveryRuleConfiguration actual = getYamlDatabaseDiscoveryRuleConfigurationSwapper().swapToObject(yamlConfig);
- assertDatabaseDiscoveryDataSourceRuleConfiguration(actual);
- }
-
- @Test
- void assertSwapToObjectWithoutLoadBalanceAlgorithm() {
- YamlDatabaseDiscoveryRuleConfiguration yamlConfig = createYamlDatabaseDiscoveryRuleConfiguration();
- DatabaseDiscoveryRuleConfiguration actual = getYamlDatabaseDiscoveryRuleConfigurationSwapper().swapToObject(yamlConfig);
- assertDatabaseDiscoveryDataSourceRuleConfiguration(actual);
- }
-
- private YamlDatabaseDiscoveryRuleConfiguration createYamlDatabaseDiscoveryRuleConfiguration() {
- YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration();
- result.getDataSources().put("ha_ds", new YamlDatabaseDiscoveryDataSourceRuleConfiguration());
- result.getDataSources().get("ha_ds").setDataSourceNames(Arrays.asList("ds_0", "ds_1"));
- return result;
- }
-
- private void assertDatabaseDiscoveryDataSourceRuleConfiguration(final DatabaseDiscoveryRuleConfiguration actual) {
- DatabaseDiscoveryDataSourceRuleConfiguration group = actual.getDataSources().iterator().next();
- assertThat(group.getGroupName(), is("ha_ds"));
- assertThat(group.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1")));
- }
-
- private YamlDatabaseDiscoveryRuleConfigurationSwapper getYamlDatabaseDiscoveryRuleConfigurationSwapper() {
- Optional<YamlDatabaseDiscoveryRuleConfigurationSwapper> result = ShardingSphereServiceLoader.getServiceInstances(YamlRuleConfigurationSwapper.class).stream()
- .filter(each -> each instanceof YamlDatabaseDiscoveryRuleConfigurationSwapper)
- .map(each -> (YamlDatabaseDiscoveryRuleConfigurationSwapper) each)
- .findFirst();
- assertTrue(result.isPresent());
- return result.get();
- }
-}
diff --git a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java
deleted file mode 100644
index b83cc05883b..00000000000
--- a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest.java
+++ /dev/null
@@ -1,79 +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.dbdiscovery.yaml.swapper;
-
-import org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.junit.jupiter.api.Test;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-class YamlRootRuleConfigurationsForYamlDatabaseDiscoveryRuleConfigurationTest {
-
- @Test
- void assertUnmarshalWithYamlFile() throws IOException {
- URL url = getClass().getClassLoader().getResource("yaml/db-discovery-rule.yaml");
- assertNotNull(url);
- YamlRootConfiguration rootConfig = YamlEngine.unmarshal(new File(url.getFile()), YamlRootConfiguration.class);
- assertThat(rootConfig.getRules().size(), is(1));
- assertDatabaseDiscoveryRule((YamlDatabaseDiscoveryRuleConfiguration) rootConfig.getRules().iterator().next());
- }
-
- @Test
- void assertUnmarshalWithYamlBytes() throws IOException {
- URL url = getClass().getClassLoader().getResource("yaml/db-discovery-rule.yaml");
- assertNotNull(url);
- StringBuilder yamlContent = new StringBuilder();
- try (
- FileReader fileReader = new FileReader(url.getFile());
- BufferedReader reader = new BufferedReader(fileReader)) {
- String line;
- while (null != (line = reader.readLine())) {
- yamlContent.append(line).append(System.lineSeparator());
- }
- }
- YamlRootConfiguration rootConfig = YamlEngine.unmarshal(yamlContent.toString().getBytes(), YamlRootConfiguration.class);
- assertThat(rootConfig.getRules().size(), is(1));
- assertDatabaseDiscoveryRule((YamlDatabaseDiscoveryRuleConfiguration) rootConfig.getRules().iterator().next());
- }
-
- private void assertDatabaseDiscoveryRule(final YamlDatabaseDiscoveryRuleConfiguration actual) {
- assertThat(actual.getDataSources().size(), is(2));
- assertThat(actual.getDiscoveryHeartbeats().size(), is(1));
- assertDatabaseDiscoveryRuleForDs0(actual);
- assertDatabaseDiscoveryRuleForDs1(actual);
- }
-
- private void assertDatabaseDiscoveryRuleForDs0(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 assertDatabaseDiscoveryRuleForDs1(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/features/db-discovery/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider b/features/db-discovery/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
deleted file mode 100644
index dd379eaceea..00000000000
--- a/features/db-discovery/core/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
+++ /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.dbdiscovery.fixture.CoreDatabaseDiscoveryProviderFixture
diff --git a/features/db-discovery/core/src/test/resources/logback-test.xml b/features/db-discovery/core/src/test/resources/logback-test.xml
deleted file mode 100644
index d90fc4a7156..00000000000
--- a/features/db-discovery/core/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.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.
- -->
-
-<configuration>
- <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
- </encoder>
- </appender>
- <logger name="org.apache.shardingsphere" level="warn" additivity="false">
- <appender-ref ref="console" />
- </logger>
-
- <root>
- <level value="error" />
- <appender-ref ref="console" />
- </root>
-</configuration>
diff --git a/features/db-discovery/core/src/test/resources/yaml/db-discovery-rule.yaml b/features/db-discovery/core/src/test/resources/yaml/db-discovery-rule.yaml
deleted file mode 100644
index 3002943739d..00000000000
--- a/features/db-discovery/core/src/test/resources/yaml/db-discovery-rule.yaml
+++ /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.
-#
-
-dataSources:
- primary_ds_0:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
- primary_ds_0_replica_0:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
- primary_ds_0_replica_1:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
- primary_ds_1:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
- primary_ds_1_replica_0:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
- primary_ds_1_replica_1:
- dataSourceClassName: org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource
-
-rules:
-- !DB_DISCOVERY
- dataSources:
- ds_0:
- dataSourceNames:
- - primary_ds_0_replica_0
- - primary_ds_0_replica_1
- discoveryHeartbeatName: mgr-heartbeat
- discoveryTypeName: mgr
- ds_1:
- dataSourceNames:
- - primary_ds_1_replica_0
- - primary_ds_1_replica_1
- discoveryHeartbeatName: mgr-heartbeat
- discoveryTypeName: mgr
- discoveryHeartbeats:
- mgr-heartbeat:
- props:
- keepAliveCron: '0/5 * * * * ?'
- discoveryTypes:
- mgr:
- type: MGR
- props:
- group-name: 92504d5b-6dec-11e8-91ea-246e9612aaf1
diff --git a/features/db-discovery/distsql/handler/pom.xml b/features/db-discovery/distsql/handler/pom.xml
deleted file mode 100644
index bf0ecdb39ab..00000000000
--- a/features/db-discovery/distsql/handler/pom.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-distsql-handler</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-distsql-handler</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql-statement</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql-parser</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-test-util</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java
deleted file mode 100644
index e192f69b137..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverter.java
+++ /dev/null
@@ -1,71 +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.dbdiscovery.distsql.handler.converter;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Database discovery rule statement converter.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseDiscoveryRuleStatementConverter {
-
- /**
- * Convert database discovery rule segment to database discovery rule configuration.
- *
- * @param ruleSegments database discovery rule segments
- * @return database discovery rule configuration
- */
- public static DatabaseDiscoveryRuleConfiguration convert(final Collection<DatabaseDiscoveryRuleSegment> ruleSegments) {
- Map<String, List<DatabaseDiscoveryRuleSegment>> segmentMap = ruleSegments.stream().collect(Collectors.groupingBy(each -> each.getClass().getSimpleName()));
- DatabaseDiscoveryRuleConfiguration result = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>());
- segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(), Collections.emptyList())
- .forEach(each -> addRuleConfiguration(result, each));
- return result;
- }
-
- private static void addRuleConfiguration(final DatabaseDiscoveryRuleConfiguration ruleConfig, final DatabaseDiscoveryRuleSegment segment) {
- String discoveryTypeName = getName(segment.getName(), segment.getDiscoveryType().getName());
- AlgorithmConfiguration discoveryType = new AlgorithmConfiguration(segment.getDiscoveryType().getName(), segment.getDiscoveryType().getProps());
- String heartbeatName = getName(segment.getName(), "heartbeat");
- DatabaseDiscoveryHeartBeatConfiguration heartbeatConfig = new DatabaseDiscoveryHeartBeatConfiguration(segment.getDiscoveryHeartbeat());
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig =
- new DatabaseDiscoveryDataSourceRuleConfiguration(segment.getName(), new LinkedList<>(segment.getDataSources()), heartbeatName, discoveryTypeName);
- ruleConfig.getDataSources().add(dataSourceRuleConfig);
- ruleConfig.getDiscoveryTypes().put(discoveryTypeName, discoveryType);
- ruleConfig.getDiscoveryHeartbeats().put(heartbeatName, heartbeatConfig);
- }
-
- private static String getName(final String ruleName, final String type) {
- return String.format("%s_%s", ruleName, type.replace(".", "_").toLowerCase());
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutor.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutor.java
deleted file mode 100644
index a6e3aacefdc..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutor.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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CountDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.function.Supplier;
-
-/**
- * Count database discovery rule executor.
- */
-public final class CountDatabaseDiscoveryRuleExecutor implements RQLExecutor<CountDatabaseDiscoveryRuleStatement> {
-
- private static final String DB_DISCOVERY = "db_discovery";
-
- @Override
- public Collection<String> getColumnNames() {
- return Arrays.asList("rule_name", "database", "count");
- }
-
- @Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final CountDatabaseDiscoveryRuleStatement sqlStatement) {
- Optional<DatabaseDiscoveryRule> rule = database.getRuleMetaData().findSingleRule(DatabaseDiscoveryRule.class);
- Map<String, LinkedList<Object>> rowMap = new LinkedHashMap<>();
- rule.ifPresent(optional -> addDBDiscoveryData(rowMap, database.getName(), rule.get()));
- Iterator<Entry<String, LinkedList<Object>>> data = rowMap.entrySet().iterator();
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (data.hasNext()) {
- Entry<String, LinkedList<Object>> entry = data.next();
- entry.getValue().addFirst(entry.getKey());
- result.add(new LocalDataQueryResultRow(entry.getValue()));
- }
- return result;
- }
-
- private void addDBDiscoveryData(final Map<String, LinkedList<Object>> rowMap, final String databaseName, final DatabaseDiscoveryRule rule) {
- addData(rowMap, DB_DISCOVERY, databaseName, () -> rule.getDataSourceMapper().size());
- }
-
- private void addData(final Map<String, LinkedList<Object>> rowMap, final String dataKey, final String databaseName, final Supplier<Integer> apply) {
- rowMap.compute(dataKey, (key, value) -> buildRow(value, databaseName, apply.get()));
- }
-
- private LinkedList<Object> buildRow(final LinkedList<Object> value, final String databaseName, final int count) {
- if (null == value) {
- return new LinkedList<>(Arrays.asList(databaseName, count));
- }
- value.set(1, (Integer) value.get(1) + count);
- return value;
- }
-
- @Override
- public String getType() {
- return CountDatabaseDiscoveryRuleStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutor.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutor.java
deleted file mode 100644
index 47cc9199575..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutor.java
+++ /dev/null
@@ -1,61 +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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-
-/**
- * Show database discovery heartbeat executor.
- */
-public final class ShowDatabaseDiscoveryHeartbeatExecutor implements RQLExecutor<ShowDatabaseDiscoveryHeartbeatsStatement> {
-
- @Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDatabaseDiscoveryHeartbeatsStatement sqlStatement) {
- DatabaseDiscoveryRule rule = database.getRuleMetaData().getSingleRule(DatabaseDiscoveryRule.class);
- DatabaseDiscoveryRuleConfiguration ruleConfig = (DatabaseDiscoveryRuleConfiguration) rule.getConfiguration();
- Iterator<Entry<String, DatabaseDiscoveryHeartBeatConfiguration>> data = ruleConfig.getDiscoveryHeartbeats().entrySet().iterator();
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (data.hasNext()) {
- Entry<String, DatabaseDiscoveryHeartBeatConfiguration> entry = data.next();
- result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getProps().toString()));
- }
- return result;
- }
-
- @Override
- public Collection<String> getColumnNames() {
- return Arrays.asList("name", "props");
- }
-
- @Override
- public String getType() {
- return ShowDatabaseDiscoveryHeartbeatsStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutor.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutor.java
deleted file mode 100644
index 0055cfa139e..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutor.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.dbdiscovery.distsql.handler.query;
-
-import com.google.gson.Gson;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Show database discovery rule executor.
- */
-public final class ShowDatabaseDiscoveryRuleExecutor implements RQLExecutor<ShowDatabaseDiscoveryRulesStatement> {
-
- private static final String NAME = "name";
-
- @Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDatabaseDiscoveryRulesStatement sqlStatement) {
- Optional<DatabaseDiscoveryRule> rule = database.getRuleMetaData().findSingleRule(DatabaseDiscoveryRule.class);
- Iterator<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRules;
- if (!rule.isPresent()) {
- return Collections.emptyList();
- }
- DatabaseDiscoveryRuleConfiguration ruleConfig = (DatabaseDiscoveryRuleConfiguration) rule.get().getConfiguration();
- dataSourceRules = ruleConfig.getDataSources().iterator();
- Map<String, AlgorithmConfiguration> discoveryTypes = ruleConfig.getDiscoveryTypes();
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeats = ruleConfig.getDiscoveryHeartbeats();
- Map<String, String> primaryDataSources = rule.get().getDataSourceRules().entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getPrimaryDataSourceName(), (a, b) -> b));
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (dataSourceRules.hasNext()) {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = dataSourceRules.next();
- Map<String, String> typeMap = new LinkedHashMap<>();
- typeMap.put(NAME, dataSourceRuleConfig.getDiscoveryTypeName());
- typeMap.putAll(convertToMap(discoveryTypes.get(dataSourceRuleConfig.getDiscoveryTypeName())));
- Map<String, String> heartbeatMap = new LinkedHashMap<>();
- heartbeatMap.put(NAME, dataSourceRuleConfig.getDiscoveryHeartbeatName());
- heartbeatMap.putAll(convertToMap(discoveryHeartbeats.get(dataSourceRuleConfig.getDiscoveryHeartbeatName())));
- String groupName = dataSourceRuleConfig.getGroupName();
- String primaryDataSourceName = null == primaryDataSources.get(groupName) ? "" : primaryDataSources.get(groupName);
- if (null == sqlStatement.getRuleName() || sqlStatement.getRuleName().equalsIgnoreCase(groupName)) {
- result.add(new LocalDataQueryResultRow(groupName, String.join(",", dataSourceRuleConfig.getDataSourceNames()), primaryDataSourceName, typeMap, heartbeatMap));
- }
- }
- return result;
- }
-
- @Override
- public Collection<String> getColumnNames() {
- return Arrays.asList("group_name", "data_source_names", "primary_data_source_name", "discovery_type", "discovery_heartbeat");
- }
-
- @SuppressWarnings("unchecked")
- private Map<String, String> convertToMap(final Object obj) {
- return null == obj ? Collections.emptyMap() : new Gson().fromJson(new Gson().toJson(obj), LinkedHashMap.class);
- }
-
- @Override
- public String getType() {
- return ShowDatabaseDiscoveryRulesStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutor.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutor.java
deleted file mode 100644
index ddb6b47ad1e..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutor.java
+++ /dev/null
@@ -1,60 +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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-
-/**
- * Show database discovery type executor.
- */
-public final class ShowDatabaseDiscoveryTypeExecutor implements RQLExecutor<ShowDatabaseDiscoveryTypesStatement> {
-
- @Override
- public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase database, final ShowDatabaseDiscoveryTypesStatement sqlStatement) {
- DatabaseDiscoveryRule rule = database.getRuleMetaData().getSingleRule(DatabaseDiscoveryRule.class);
- Iterator<Entry<String, AlgorithmConfiguration>> data = ((DatabaseDiscoveryRuleConfiguration) rule.getConfiguration()).getDiscoveryTypes().entrySet().iterator();
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (data.hasNext()) {
- Entry<String, AlgorithmConfiguration> entry = data.next();
- result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps()));
- }
- return result;
- }
-
- @Override
- public Collection<String> getColumnNames() {
- return Arrays.asList("name", "type", "props");
- }
-
- @Override
- public String getType() {
- return ShowDatabaseDiscoveryTypesStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
deleted file mode 100644
index 07e524324bc..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++ /dev/null
@@ -1,132 +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.dbdiscovery.distsql.handler.update;
-
-import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseDiscoveryRuleStatementConverter;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Alter database discovery rule statement updater.
- */
-public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDefinitionAlterUpdater<AlterDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database,
- final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- String databaseName = database.getName();
- checkCurrentRuleConfiguration(databaseName, currentRuleConfig);
- checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig);
- checkToBeAlteredDataSources(databaseName, sqlStatement, database.getResourceMetaData());
- checkDiscoverTypeAndHeartbeat(sqlStatement);
- }
-
- private void checkCurrentRuleConfiguration(final String databaseName, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException("database discovery", databaseName));
- }
-
- private void checkToBeAlteredRules(final String databaseName,
- final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toSet());
- Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(), () -> new MissingRequiredRuleException("database discovery", databaseName, notExistedRuleNames));
- }
-
- private Collection<String> getToBeAlteredRuleNames(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).collect(Collectors.toList());
- }
-
- private void checkToBeAlteredDataSources(final String databaseName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResourceMetaData resourceMetaData) {
- Collection<String> notExistedDataSources = resourceMetaData.getNotExistedDataSources(getToBeAlteredDataSourceNames(sqlStatement));
- ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () -> new MissingRequiredStorageUnitsException(databaseName, notExistedDataSources));
- }
-
- private Collection<String> getToBeAlteredDataSourceNames(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> result = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> result.addAll(each.getDataSources()));
- return result;
- }
-
- private void checkDiscoverTypeAndHeartbeat(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- Map<String, List<DatabaseDiscoveryRuleSegment>> segmentMap = sqlStatement.getRules().stream().collect(Collectors.groupingBy(each -> each.getClass().getSimpleName()));
- segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(), Collections.emptyList()).stream()
- .map(DatabaseDiscoveryRuleSegment::getDiscoveryType)
- .forEach(each -> TypedSPILoader.checkService(DatabaseDiscoveryProvider.class, each.getName(), each.getProps()));
- }
-
- @Override
- public RuleConfiguration buildToBeAlteredRuleConfiguration(final AlterDatabaseDiscoveryRuleStatement sqlStatement) {
- return DatabaseDiscoveryRuleStatementConverter.convert(sqlStatement.getRules());
- }
-
- @Override
- public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) {
- dropRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
- addRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
- // TODO DistSQL update rule config need to sync scheduler module cron.
- }
-
- private void dropRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) {
- for (DatabaseDiscoveryDataSourceRuleConfiguration each : toBeAlteredRuleConfig.getDataSources()) {
- dropDataSourceRuleConfiguration(currentRuleConfig, each.getGroupName());
- }
- }
-
- private void dropDataSourceRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String toBeDroppedRuleNames) {
- Optional<DatabaseDiscoveryDataSourceRuleConfiguration> toBeDroppedDataSourceRuleConfig = currentRuleConfig.getDataSources().stream()
- .filter(each -> each.getGroupName().equals(toBeDroppedRuleNames)).findAny();
- Preconditions.checkState(toBeDroppedDataSourceRuleConfig.isPresent());
- currentRuleConfig.getDataSources().remove(toBeDroppedDataSourceRuleConfig.get());
- }
-
- private void addRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) {
- currentRuleConfig.getDataSources().addAll(toBeAlteredRuleConfig.getDataSources());
- currentRuleConfig.getDiscoveryTypes().putAll(toBeAlteredRuleConfig.getDiscoveryTypes());
- currentRuleConfig.getDiscoveryHeartbeats().putAll(toBeAlteredRuleConfig.getDiscoveryHeartbeats());
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return AlterDatabaseDiscoveryRuleStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
deleted file mode 100644
index 53a15f9ec47..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
+++ /dev/null
@@ -1,122 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseDiscoveryRuleStatementConverter;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-/**
- * Create database discovery rule statement updater.
- */
-public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDefinitionCreateUpdater<CreateDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- String databaseName = database.getName();
- checkDuplicatedRuleNames(databaseName, sqlStatement, currentRuleConfig);
- checkDataSources(databaseName, sqlStatement, database.getResourceMetaData());
- checkDiscoverTypeAndHeartbeat(sqlStatement);
- }
-
- @Override
- public DatabaseDiscoveryRuleConfiguration buildToBeCreatedRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<DatabaseDiscoveryRuleSegment> segments = sqlStatement.getRules();
- if (sqlStatement.isIfNotExists()) {
- Collection<String> duplicatedRuleNames = getDuplicatedRuleNames(sqlStatement, currentRuleConfig);
- segments.removeIf(each -> duplicatedRuleNames.contains(each.getName()));
- }
- return DatabaseDiscoveryRuleStatementConverter.convert(segments);
- }
-
- @Override
- public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeCreatedRuleConfig) {
- currentRuleConfig.getDataSources().addAll(toBeCreatedRuleConfig.getDataSources());
- currentRuleConfig.getDiscoveryTypes().putAll(toBeCreatedRuleConfig.getDiscoveryTypes());
- currentRuleConfig.getDiscoveryHeartbeats().putAll(toBeCreatedRuleConfig.getDiscoveryHeartbeats());
- }
-
- private void checkDuplicatedRuleNames(final String databaseName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- checkDuplicatedRuleNamesWithSelf(databaseName, sqlStatement);
- if (!sqlStatement.isIfNotExists()) {
- checkDuplicatedRuleNamesWithRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
- }
- }
-
- private void checkDuplicatedRuleNamesWithSelf(final String databaseName, final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- Collection<String> duplicatedRuleNames = sqlStatement.getRules().stream().collect(Collectors.toMap(DatabaseDiscoveryRuleSegment::getName, each -> 1, Integer::sum))
- .entrySet().stream().filter(entry -> entry.getValue() > 1).map(Entry::getKey).collect(Collectors.toSet());
- ShardingSpherePreconditions.checkState(duplicatedRuleNames.isEmpty(), () -> new DuplicateRuleException("database discovery", databaseName, duplicatedRuleNames));
- }
-
- private void checkDuplicatedRuleNamesWithRuleConfiguration(final String databaseName, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
- final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> duplicatedRuleNames = getDuplicatedRuleNames(sqlStatement, currentRuleConfig);
- ShardingSpherePreconditions.checkState(duplicatedRuleNames.isEmpty(), () -> new DuplicateRuleException("database discovery", databaseName, duplicatedRuleNames));
- }
-
- private Collection<String> getDuplicatedRuleNames(final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> currentRuleNames = new LinkedHashSet<>();
- if (null != currentRuleConfig) {
- currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toSet());
- }
- return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).filter(currentRuleNames::contains).collect(Collectors.toSet());
- }
-
- private void checkDataSources(final String databaseName, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResourceMetaData resourceMetaData) {
- Collection<String> dataSources = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each -> dataSources.addAll(each.getDataSources()));
- Collection<String> notExistedDataSources = resourceMetaData.getNotExistedDataSources(dataSources);
- ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () -> new MissingRequiredStorageUnitsException(databaseName, notExistedDataSources));
- }
-
- private void checkDiscoverTypeAndHeartbeat(final CreateDatabaseDiscoveryRuleStatement sqlStatement) {
- Map<String, List<DatabaseDiscoveryRuleSegment>> segmentMap = sqlStatement.getRules().stream().collect(Collectors.groupingBy(each -> each.getClass().getSimpleName()));
- segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(), Collections.emptyList()).stream()
- .map(DatabaseDiscoveryRuleSegment::getDiscoveryType)
- .forEach(each -> TypedSPILoader.checkService(DatabaseDiscoveryProvider.class, each.getName(), each.getProps()));
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return CreateDatabaseDiscoveryRuleStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java
deleted file mode 100644
index 21d173b1e44..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java
+++ /dev/null
@@ -1,92 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryHeartbeatStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
-
-/**
- * Drop database discovery heartbeat statement updater.
- */
-public final class DropDatabaseDiscoveryHeartbeatStatementUpdater implements RuleDefinitionDropUpdater<DropDatabaseDiscoveryHeartbeatStatement, DatabaseDiscoveryRuleConfiguration> {
-
- private static final String RULE_TYPE = "Database discovery";
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- String databaseName = database.getName();
- checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
- checkIsInUse(databaseName, sqlStatement, currentRuleConfig);
- }
-
- private void checkCurrentRuleConfiguration(final String databaseName, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (sqlStatement.isIfExists()) {
- return;
- }
- ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException(RULE_TYPE, databaseName));
- checkIsExist(databaseName, sqlStatement, currentRuleConfig);
- }
-
- private void checkIsExist(final String databaseName, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> currentRuleNames = currentRuleConfig.getDiscoveryHeartbeats().keySet();
- Collection<String> notExistedRuleNames = sqlStatement.getNames().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(), () -> new MissingRequiredRuleException(RULE_TYPE, databaseName, notExistedRuleNames));
- }
-
- private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> heartbeatInUse = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getDiscoveryHeartbeatName).collect(Collectors.toSet());
- Collection<String> invalid = sqlStatement.getNames().stream().filter(heartbeatInUse::contains).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalid.isEmpty(), () -> new RuleInUsedException(RULE_TYPE, databaseName, invalid));
- }
-
- @Override
- public boolean updateCurrentRuleConfiguration(final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- for (String each : sqlStatement.getNames()) {
- dropRule(currentRuleConfig, each);
- }
- return false;
- }
-
- private void dropRule(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String heartbeatName) {
- currentRuleConfig.getDiscoveryHeartbeats().remove(heartbeatName);
- }
-
- @Override
- public boolean hasAnyOneToBeDropped(final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(currentRuleConfig.getDiscoveryHeartbeats().keySet(), sqlStatement.getNames()).isEmpty();
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return DropDatabaseDiscoveryHeartbeatStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
deleted file mode 100644
index feb538fd2c4..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
+++ /dev/null
@@ -1,126 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.RuleExportEngine;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Drop database discovery rule statement updater.
- */
-public final class DropDatabaseDiscoveryRuleStatementUpdater implements RuleDefinitionDropUpdater<DropDatabaseDiscoveryRuleStatement, DatabaseDiscoveryRuleConfiguration> {
-
- private static final String RULE_TYPE = "Database discovery";
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- String databaseName = database.getName();
- checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
- checkIsInUse(databaseName, sqlStatement, database);
- }
-
- private void checkCurrentRuleConfiguration(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (sqlStatement.isIfExists()) {
- return;
- }
- ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException(RULE_TYPE, databaseName));
- checkIsExist(databaseName, sqlStatement, currentRuleConfig);
- }
-
- private void checkIsExist(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toList());
- Collection<String> notExistedRuleNames = sqlStatement.getNames().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(), () -> new MissingRequiredRuleException(RULE_TYPE, databaseName));
- }
-
- private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereDatabase database) {
- Optional<ExportableRule> exportableRule = database.getRuleMetaData().findRules(ExportableRule.class).stream()
- .filter(each -> new RuleExportEngine(each).containExportableKey(Collections.singletonList(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE))).findFirst();
- Collection<String> rulesInUse = new LinkedList<>();
- exportableRule.ifPresent(optional -> {
- Map<String, Map<String, String>> readwriteRuleMap = new RuleExportEngine(optional).export(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE)
- .map(each -> (Map<String, Map<String, String>>) each).orElse(Collections.emptyMap());
- readwriteRuleMap.values().stream().map(each -> each.get(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME)).forEach(rulesInUse::add);
- });
- Collection<String> invalid = sqlStatement.getNames().stream().filter(rulesInUse::contains).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalid.isEmpty(), () -> new RuleInUsedException(RULE_TYPE, databaseName, invalid));
- }
-
- @Override
- public boolean updateCurrentRuleConfiguration(final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- sqlStatement.getNames().forEach(each -> dropRule(currentRuleConfig, each));
- dropUnusedType(currentRuleConfig);
- dropUnusedHeartbeat(currentRuleConfig);
- return currentRuleConfig.getDataSources().isEmpty();
- }
-
- private void dropRule(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String ruleName) {
- Optional<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(each -> each.getGroupName().equals(ruleName)).findAny();
- dataSourceRuleConfig.ifPresent(optional -> currentRuleConfig.getDataSources().remove(dataSourceRuleConfig.get()));
- }
-
- private void dropUnusedType(final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> inUsedDiscoveryTypes = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getDiscoveryTypeName).filter(Objects::nonNull)
- .collect(Collectors.toSet());
- Collection<String> unusedDiscoveryTypes = currentRuleConfig.getDiscoveryTypes().keySet().stream().filter(each -> !inUsedDiscoveryTypes.contains(each)).collect(Collectors.toSet());
- unusedDiscoveryTypes.forEach(each -> currentRuleConfig.getDiscoveryTypes().remove(each));
- }
-
- private void dropUnusedHeartbeat(final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> inUsedDiscoveryHeartbeats = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getDiscoveryHeartbeatName)
- .filter(Objects::nonNull).collect(Collectors.toSet());
- Collection<String> unusedDiscoveryHeartbeats = currentRuleConfig.getDiscoveryHeartbeats().keySet().stream().filter(each -> !inUsedDiscoveryHeartbeats.contains(each))
- .collect(Collectors.toSet());
- unusedDiscoveryHeartbeats.forEach(each -> currentRuleConfig.getDiscoveryHeartbeats().remove(each));
- }
-
- @Override
- public boolean hasAnyOneToBeDropped(final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- return isExistRuleConfig(currentRuleConfig)
- && !getIdenticalData(currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toSet()),
- sqlStatement.getNames()).isEmpty();
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return DropDatabaseDiscoveryRuleStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java
deleted file mode 100644
index 39689f7decb..00000000000
--- a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java
+++ /dev/null
@@ -1,98 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryTypeStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
-
-/**
- * Drop database discovery type statement updater.
- */
-public final class DropDatabaseDiscoveryTypeStatementUpdater implements RuleDefinitionDropUpdater<DropDatabaseDiscoveryTypeStatement, DatabaseDiscoveryRuleConfiguration> {
-
- private static final String RULE_TYPE = "Database discovery";
-
- @Override
- public void checkSQLStatement(final ShardingSphereDatabase database, final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- String databaseName = database.getName();
- checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
- checkIsInUse(databaseName, sqlStatement, currentRuleConfig);
- }
-
- private void checkCurrentRuleConfiguration(final String databaseName, final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- if (sqlStatement.isIfExists()) {
- return;
- }
- ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException(RULE_TYPE, databaseName));
- checkIsExist(databaseName, sqlStatement, currentRuleConfig);
- }
-
- private void checkIsExist(final String databaseName, final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> currentRuleNames = currentRuleConfig.getDiscoveryTypes().keySet();
- Collection<String> notExistedRuleNames = sqlStatement.getTypes().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedRuleNames.isEmpty(), () -> new MissingRequiredRuleException(RULE_TYPE, databaseName, notExistedRuleNames));
- }
-
- private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> heartbeatInUse = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getDiscoveryTypeName).collect(Collectors.toSet());
- Collection<String> invalid = sqlStatement.getTypes().stream().filter(heartbeatInUse::contains).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalid.isEmpty(), () -> new RuleInUsedException(RULE_TYPE, databaseName, invalid));
- }
-
- @Override
- public boolean updateCurrentRuleConfiguration(final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- for (String each : sqlStatement.getTypes()) {
- dropRule(currentRuleConfig, each);
- }
- return false;
- }
-
- private void dropRule(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String typeName) {
- if (isNotInUse(currentRuleConfig, typeName)) {
- currentRuleConfig.getDiscoveryTypes().remove(typeName);
- }
- }
-
- @Override
- public boolean hasAnyOneToBeDropped(final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(currentRuleConfig.getDiscoveryTypes().keySet(), sqlStatement.getTypes()).isEmpty();
- }
-
- private boolean isNotInUse(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String toBeDroppedDiscoveryTypeName) {
- return currentRuleConfig.getDataSources().stream().noneMatch(each -> each.getDiscoveryTypeName().equals(toBeDroppedDiscoveryTypeName));
- }
-
- @Override
- public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
- return DatabaseDiscoveryRuleConfiguration.class;
- }
-
- @Override
- public String getType() {
- return DropDatabaseDiscoveryTypeStatement.class.getName();
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor b/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
deleted file mode 100644
index 8d925b400c6..00000000000
--- a/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
+++ /dev/null
@@ -1,21 +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.dbdiscovery.distsql.handler.query.ShowDatabaseDiscoveryRuleExecutor
-org.apache.shardingsphere.dbdiscovery.distsql.handler.query.ShowDatabaseDiscoveryTypeExecutor
-org.apache.shardingsphere.dbdiscovery.distsql.handler.query.ShowDatabaseDiscoveryHeartbeatExecutor
-org.apache.shardingsphere.dbdiscovery.distsql.handler.query.CountDatabaseDiscoveryRuleExecutor
diff --git a/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater b/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
deleted file mode 100644
index 7b060263f54..00000000000
--- a/features/db-discovery/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
+++ /dev/null
@@ -1,22 +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.dbdiscovery.distsql.handler.update.CreateDatabaseDiscoveryRuleStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.AlterDatabaseDiscoveryRuleStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.DropDatabaseDiscoveryRuleStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.DropDatabaseDiscoveryHeartbeatStatementUpdater
-org.apache.shardingsphere.dbdiscovery.distsql.handler.update.DropDatabaseDiscoveryTypeStatementUpdater
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java
deleted file mode 100644
index d09965f19ed..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java
+++ /dev/null
@@ -1,59 +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.dbdiscovery.distsql.handler.converter;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class DatabaseDiscoveryRuleStatementConverterTest {
-
- @Test
- void assertConvert() {
- DatabaseDiscoveryRuleConfiguration ruleConfig = DatabaseDiscoveryRuleStatementConverter.convert(createDatabaseDiscoveryRuleSegments());
- assertTrue(ruleConfig.getDiscoveryTypes().containsKey("definition_mysql_mgr"));
- assertTrue(ruleConfig.getDiscoveryHeartbeats().containsKey("definition_heartbeat"));
- Iterator<DatabaseDiscoveryDataSourceRuleConfiguration> iterator = ruleConfig.getDataSources().iterator();
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = iterator.next();
- assertThat(dataSourceRuleConfig.getDataSourceNames(), is(Arrays.asList("resource0", "resource1")));
- assertThat(dataSourceRuleConfig.getGroupName(), is("definition"));
- assertThat(dataSourceRuleConfig.getDiscoveryTypeName(), is("definition_mysql_mgr"));
- assertThat(dataSourceRuleConfig.getDiscoveryHeartbeatName(), is("definition_heartbeat"));
- }
-
- private Collection<DatabaseDiscoveryRuleSegment> createDatabaseDiscoveryRuleSegments() {
- Properties props = PropertiesBuilder.build(new Property("key", "value"));
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment(
- "definition", Arrays.asList("resource0", "resource1"), new AlgorithmSegment("MySQL.MGR", props), props);
- return Collections.singletonList(databaseDiscoveryRuleSegment);
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/DistSQLDatabaseDiscoveryProviderFixture.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/DistSQLDatabaseDiscoveryProviderFixture.java
deleted file mode 100644
index ba81c9f514d..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/DistSQLDatabaseDiscoveryProviderFixture.java
+++ /dev/null
@@ -1,52 +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.dbdiscovery.distsql.handler.fixture;
-
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.Optional;
-
-public final class DistSQLDatabaseDiscoveryProviderFixture implements DatabaseDiscoveryProvider {
-
- @Override
- public void checkEnvironment(final String databaseName, final Collection<DataSource> dataSource) {
- }
-
- @Override
- public boolean isPrimaryInstance(final DataSource dataSource) {
- return false;
- }
-
- @Override
- public ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) {
- return new ReplicaDataSourceStatus(true, 0L);
- }
-
- @Override
- public Optional<Integer> getMinEnabledReplicas() {
- return Optional.empty();
- }
-
- @Override
- public String getType() {
- return "DISTSQL.FIXTURE";
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java
deleted file mode 100644
index 632829c52f2..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CountDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class CountDatabaseDiscoveryRuleExecutorTest {
-
- @Test
- void assertGetRowData() {
- RQLExecutor<CountDatabaseDiscoveryRuleStatement> executor = new CountDatabaseDiscoveryRuleExecutor();
- Collection<LocalDataQueryResultRow> actual = executor.getRows(mockDatabase(), mock(CountDatabaseDiscoveryRuleStatement.class));
- assertThat(actual.size(), is(1));
- Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
- LocalDataQueryResultRow row = iterator.next();
- assertThat(row.getCell(1), is("db_discovery"));
- assertThat(row.getCell(2), is("db_1"));
- assertThat(row.getCell(3), is(2));
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<CountDatabaseDiscoveryRuleStatement> executor = new CountDatabaseDiscoveryRuleExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("rule_name"));
- assertThat(iterator.next(), is("database"));
- assertThat(iterator.next(), is("count"));
- }
-
- private ShardingSphereDatabase mockDatabase() {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(result.getName()).thenReturn("db_1");
- DatabaseDiscoveryRule databaseDiscoveryRule = mockDatabaseDiscoveryRule();
- when(result.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(databaseDiscoveryRule)));
- return result;
- }
-
- private DatabaseDiscoveryRule mockDatabaseDiscoveryRule() {
- DatabaseDiscoveryRule result = mock(DatabaseDiscoveryRule.class);
- Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper = new LinkedHashMap<>();
- dataSourceMapper.put("ds_0", Collections.singletonList(new DataSourceRoleInfo("ds_0", DataSourceRole.PRIMARY)));
- dataSourceMapper.put("ds_1", Collections.singletonList(new DataSourceRoleInfo("ds_1", DataSourceRole.MEMBER)));
- when(result.getDataSourceMapper()).thenReturn(dataSourceMapper);
- return result;
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutorTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutorTest.java
deleted file mode 100644
index 11cf0a7be76..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryHeartbeatExecutorTest.java
+++ /dev/null
@@ -1,80 +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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShowDatabaseDiscoveryHeartbeatExecutorTest {
-
- @Test
- void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DatabaseDiscoveryRule rule = mock(DatabaseDiscoveryRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(rule)));
- RQLExecutor<ShowDatabaseDiscoveryHeartbeatsStatement> executor = new ShowDatabaseDiscoveryHeartbeatExecutor();
- Collection<LocalDataQueryResultRow> actual = executor.getRows(database, mock(ShowDatabaseDiscoveryHeartbeatsStatement.class));
- assertThat(actual.size(), is(1));
- Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
- LocalDataQueryResultRow row = iterator.next();
- assertThat(row.getCell(1), is("test_name"));
- assertThat(row.getCell(2), is("{type_key=type_value}"));
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowDatabaseDiscoveryHeartbeatsStatement> executor = new ShowDatabaseDiscoveryHeartbeatExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("props"));
- }
-
- private RuleConfiguration createRuleConfiguration() {
- DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ms_group", Arrays.asList("ds_0", "ds_1"),
- "ms-heartbeat", "test");
- DatabaseDiscoveryHeartBeatConfiguration shardingSphereAlgorithmConfig = new DatabaseDiscoveryHeartBeatConfiguration(PropertiesBuilder.build(new Property("type_key", "type_value")));
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoverHeartbeat = Collections.singletonMap("test_name", shardingSphereAlgorithmConfig);
- return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig), discoverHeartbeat, Collections.emptyMap());
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutorTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutorTest.java
deleted file mode 100644
index 355c31df534..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryRuleExecutorTest.java
+++ /dev/null
@@ -1,106 +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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryDataSourceRule;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.junit.jupiter.api.Test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShowDatabaseDiscoveryRuleExecutorTest {
-
- @Test
- void assertGetRows() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DatabaseDiscoveryRule rule = mock(DatabaseDiscoveryRule.class, RETURNS_DEEP_STUBS);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- DatabaseDiscoveryDataSourceRule dataSourceRule = mock(DatabaseDiscoveryDataSourceRule.class);
- when(dataSourceRule.getPrimaryDataSourceName()).thenReturn("ds_0");
- when(rule.getDataSourceRules()).thenReturn(Collections.singletonMap("ms_group", dataSourceRule));
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(rule)));
- RQLExecutor<ShowDatabaseDiscoveryRulesStatement> executor = new ShowDatabaseDiscoveryRuleExecutor();
- assertColumns(executor.getColumnNames());
- assertRowData(new ArrayList<>(executor.getRows(database, mock(ShowDatabaseDiscoveryRulesStatement.class))));
- }
-
- @Test
- void assertGetRowsWithSpecifiedRuleName() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DatabaseDiscoveryRule rule = mock(DatabaseDiscoveryRule.class, RETURNS_DEEP_STUBS);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- DatabaseDiscoveryDataSourceRule dataSourceRule = mock(DatabaseDiscoveryDataSourceRule.class);
- when(dataSourceRule.getPrimaryDataSourceName()).thenReturn("ds_0");
- when(rule.getDataSourceRules()).thenReturn(Collections.singletonMap("ms_group", dataSourceRule));
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(rule)));
- RQLExecutor<ShowDatabaseDiscoveryRulesStatement> executor = new ShowDatabaseDiscoveryRuleExecutor();
- assertColumns(executor.getColumnNames());
- assertRowData(new ArrayList<>(executor.getRows(database, new ShowDatabaseDiscoveryRulesStatement("ms_group", null))));
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowDatabaseDiscoveryRulesStatement> executor = new ShowDatabaseDiscoveryRuleExecutor();
- assertColumns(executor.getColumnNames());
- }
-
- private DatabaseDiscoveryRuleConfiguration createRuleConfiguration() {
- DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(
- "ms_group", Arrays.asList("ds_0", "ds_1"), "heartbeat_test", "type_test");
- AlgorithmConfiguration shardingSphereAlgorithmConfig = new AlgorithmConfiguration("MySQL.MGR", new Properties());
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeat = Collections.singletonMap("heartbeat_test", new DatabaseDiscoveryHeartBeatConfiguration(new Properties()));
- Map<String, AlgorithmConfiguration> discoverTypes = Collections.singletonMap("type_test", shardingSphereAlgorithmConfig);
- return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig), discoveryHeartbeat, discoverTypes);
- }
-
- private void assertColumns(final Collection<String> actual) {
- assertThat(actual.size(), is(5));
- assertTrue(actual.containsAll(Arrays.asList("group_name", "data_source_names", "primary_data_source_name", "discovery_type", "discovery_heartbeat")));
- }
-
- private void assertRowData(final Collection<LocalDataQueryResultRow> actual) {
- assertThat(actual.size(), is(1));
- LocalDataQueryResultRow row = actual.iterator().next();
- assertThat(row.getCell(1), is("ms_group"));
- assertThat(row.getCell(2), is("ds_0,ds_1"));
- assertThat(row.getCell(3), is("ds_0"));
- assertThat(row.getCell(4).toString(), is("{name=type_test, type=MySQL.MGR, props={}}"));
- assertThat(row.getCell(5).toString(), is("{name=heartbeat_test, props={}}"));
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutorTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutorTest.java
deleted file mode 100644
index eb8c2bab6fc..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/ShowDatabaseDiscoveryTypeExecutorTest.java
+++ /dev/null
@@ -1,81 +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.dbdiscovery.distsql.handler.query;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
-import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
-import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShowDatabaseDiscoveryTypeExecutorTest {
-
- @Test
- void assertGetRowData() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DatabaseDiscoveryRule rule = mock(DatabaseDiscoveryRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(rule)));
- RQLExecutor<ShowDatabaseDiscoveryTypesStatement> executor = new ShowDatabaseDiscoveryTypeExecutor();
- Collection<LocalDataQueryResultRow> actual = executor.getRows(database, mock(ShowDatabaseDiscoveryTypesStatement.class));
- assertThat(actual.size(), is(1));
- Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
- LocalDataQueryResultRow row = iterator.next();
- assertThat(row.getCell(1), is("test_name"));
- assertThat(row.getCell(2), is("MySQL.MGR"));
- assertThat(row.getCell(3).toString(), is("{type_key=type_value}"));
- }
-
- @Test
- void assertGetColumnNames() {
- RQLExecutor<ShowDatabaseDiscoveryTypesStatement> executor = new ShowDatabaseDiscoveryTypeExecutor();
- Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(3));
- Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("type"));
- assertThat(iterator.next(), is("props"));
- }
-
- private RuleConfiguration createRuleConfiguration() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ms_group", Arrays.asList("ds_0", "ds_1"), "ms-heartbeat", "test");
- AlgorithmConfiguration shardingSphereAlgorithmConfig = new AlgorithmConfiguration("MySQL.MGR", PropertiesBuilder.build(new Property("type_key", "type_value")));
- Map<String, AlgorithmConfiguration> discoverTypes = Collections.singletonMap("test_name", shardingSphereAlgorithmConfig);
- return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), discoverTypes);
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
deleted file mode 100644
index e85ad25bbc2..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ /dev/null
@@ -1,132 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class AlterDatabaseDiscoveryRuleStatementUpdaterTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereDatabase database;
-
- @Mock
- private ShardingSphereResourceMetaData resourceMetaData;
-
- private final AlterDatabaseDiscoveryRuleStatementUpdater updater = new AlterDatabaseDiscoveryRuleStatementUpdater();
-
- @BeforeEach
- void before() {
- when(database.getResourceMetaData()).thenReturn(resourceMetaData);
- }
-
- @Test
- void assertCheckSQLStatementWithoutCurrentRule() {
- assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, new AlterDatabaseDiscoveryRuleStatement(Collections.emptyList()), null));
- }
-
- @Test
- void assertCheckSQLStatementWithoutToBeAlteredDatabaseDiscoveryRule() {
- Properties props = new Properties();
- DatabaseDiscoveryRuleSegment segment =
- new DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), new AlgorithmSegment("MySQL.MGR", props), props);
- assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)),
- new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- @Test
- void assertCheckSQLStatementWithoutExistedResources() {
- when(resourceMetaData.getNotExistedDataSources(any())).thenReturn(Collections.singleton("ds0"));
- Properties props = new Properties();
- DatabaseDiscoveryRuleSegment segment =
- new DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), new AlgorithmSegment("MySQL.MGR", props), props);
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST");
- DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)),
- Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null));
- assertThrows(MissingRequiredStorageUnitsException.class, () -> updater.checkSQLStatement(database, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)), ruleConfig));
- }
-
- @Test
- void assertCheckSQLStatementWithDatabaseDiscoveryType() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("INVALID_TYPE", new Properties());
- DatabaseDiscoveryRuleSegment segment = new DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST");
- DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)),
- Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null));
- assertThrows(ServiceProviderNotFoundServerException.class, () -> updater.checkSQLStatement(database, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig));
- }
-
- @Test
- void assertBuild() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("MySQL.MGR", new Properties());
- DatabaseDiscoveryRuleSegment definitionSegment = new DatabaseDiscoveryRuleSegment("readwrite_ds_1", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig =
- (DatabaseDiscoveryRuleConfiguration) updater.buildToBeAlteredRuleConfiguration(new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(definitionSegment)));
- assertThat(databaseDiscoveryRuleConfig.getDataSources().size(), is(1));
- assertTrue(databaseDiscoveryRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName)
- .collect(Collectors.toList()).removeAll(Collections.singletonList("readwrite_ds_1")));
- assertTrue(databaseDiscoveryRuleConfig.getDiscoveryTypes().containsKey("readwrite_ds_1_mysql_mgr"));
- assertTrue(databaseDiscoveryRuleConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_1_heartbeat"));
- }
-
- @Test
- void assertUpdate() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("MySQL.MGR", new Properties());
- DatabaseDiscoveryRuleSegment definitionSegment = new DatabaseDiscoveryRuleSegment("readwrite_ds_1", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryRuleConfiguration toBeCreatedRuleConfig =
- (DatabaseDiscoveryRuleConfiguration) updater.buildToBeAlteredRuleConfiguration(new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(definitionSegment)));
- DatabaseDiscoveryDataSourceRuleConfiguration definitionRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds_1", Collections.emptyList(), "", "");
- DatabaseDiscoveryRuleConfiguration currentConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singletonList(definitionRuleConfig)),
- new HashMap<>(Collections.singletonMap("discovery_type_name", null)), new HashMap<>(Collections.singletonMap("heartbeat_name", null)));
- updater.updateCurrentRuleConfiguration(currentConfig, toBeCreatedRuleConfig);
- assertThat(currentConfig.getDataSources().size(), is(1));
- assertTrue(currentConfig.getDataSources().stream()
- .map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toList()).removeAll(Collections.singleton("readwrite_ds_1")));
- assertTrue(currentConfig.getDiscoveryTypes().containsKey("readwrite_ds_1_mysql_mgr"));
- assertTrue(currentConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_1_heartbeat"));
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
deleted file mode 100644
index da8af9d0d86..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ /dev/null
@@ -1,165 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class CreateDatabaseDiscoveryRuleStatementUpdaterTest {
-
- private final CreateDatabaseDiscoveryRuleStatementUpdater updater = new CreateDatabaseDiscoveryRuleStatementUpdater();
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereDatabase database;
-
- @Mock
- private ShardingSphereResourceMetaData resourceMetaData;
-
- @BeforeEach
- void before() {
- when(database.getResourceMetaData()).thenReturn(resourceMetaData);
- }
-
- @Test
- void assertCheckSQLStatementWithDuplicateRuleNames() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "test");
- Properties props = new Properties();
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment =
- new DatabaseDiscoveryRuleSegment("readwrite_ds", Collections.emptyList(), new AlgorithmSegment("MySQL.MGR", props), props);
- assertThrows(DuplicateRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement(false, Collections.singletonList(databaseDiscoveryRuleSegment)),
- new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- @Test
- void assertCheckSQLStatementWithoutExistedResources() {
- when(resourceMetaData.getNotExistedDataSources(any())).thenReturn(Collections.singleton("ds_read_0"));
- Properties props = new Properties();
- DatabaseDiscoveryRuleSegment segment =
- new DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), new AlgorithmSegment("MySQL.MGR", props), props);
- assertThrows(MissingRequiredStorageUnitsException.class, () -> updater.checkSQLStatement(database, createSQLStatement(false, Collections.singleton(segment)), null));
- }
-
- @Test
- void assertCheckSQLStatementWithDatabaseDiscoveryType() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("INVALID_TYPE", new Properties());
- DatabaseDiscoveryRuleSegment segment = new DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- assertThrows(ServiceProviderNotFoundServerException.class, () -> updater.checkSQLStatement(database, createSQLStatement(false, Collections.singleton(segment)), null));
- }
-
- @Test
- void assertBuild() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("MySQL.MGR", new Properties());
- DatabaseDiscoveryRuleSegment definitionSegment = new DatabaseDiscoveryRuleSegment("readwrite_ds_1", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryRuleConfiguration ruleConfig =
- updater.buildToBeCreatedRuleConfiguration(null, createSQLStatement(false, Collections.singletonList(definitionSegment)));
- assertThat(ruleConfig.getDataSources().size(), is(1));
- assertTrue(ruleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName)
- .collect(Collectors.toList()).removeAll(Collections.singletonList("readwrite_ds_1")));
- assertTrue(ruleConfig.getDiscoveryTypes().containsKey("readwrite_ds_1_mysql_mgr"));
- assertTrue(ruleConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_1_heartbeat"));
- }
-
- @Test
- void assertUpdate() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("MySQL.MGR", new Properties());
- DatabaseDiscoveryRuleSegment definitionSegment = new DatabaseDiscoveryRuleSegment("readwrite_ds_1", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryRuleConfiguration currentConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>());
- DatabaseDiscoveryRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentConfig,
- createSQLStatement(false, Collections.singletonList(definitionSegment)));
- updater.updateCurrentRuleConfiguration(currentConfig, toBeCreatedRuleConfig);
- assertThat(currentConfig.getDataSources().size(), is(1));
- assertTrue(currentConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName)
- .collect(Collectors.toList()).removeAll(Collections.singletonList("readwrite_ds_1")));
- assertTrue(currentConfig.getDiscoveryTypes().containsKey("readwrite_ds_1_mysql_mgr"));
- assertTrue(currentConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_1_heartbeat"));
- }
-
- @Test
- void assertUpdateWithIfNotExists() {
- AlgorithmSegment algorithmSegment = new AlgorithmSegment("MySQL.MGR", new Properties());
- DatabaseDiscoveryRuleSegment definitionSegmentDS1 = new DatabaseDiscoveryRuleSegment("readwrite_ds_1",
- Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- DatabaseDiscoveryRuleSegment definitionSegmentDS2 = new DatabaseDiscoveryRuleSegment("readwrite_ds_2",
- Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties());
- Collection<DatabaseDiscoveryRuleSegment> currentSegments = new LinkedList<>();
- currentSegments.add(definitionSegmentDS1);
- currentSegments.add(definitionSegmentDS2);
- DatabaseDiscoveryRuleConfiguration currentConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>());
- DatabaseDiscoveryRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentConfig, createSQLStatement(false, currentSegments));
- updater.updateCurrentRuleConfiguration(currentConfig, toBeCreatedRuleConfig);
- definitionSegmentDS1 = new DatabaseDiscoveryRuleSegment("readwrite_ds_1", Arrays.asList("ds_read_0", "ds_read_1", "ds_read_3"), algorithmSegment, new Properties());
- definitionSegmentDS2 = new DatabaseDiscoveryRuleSegment("readwrite_ds_2", Arrays.asList("ds_read_0", "ds_read_1", "ds_read_3"), algorithmSegment, new Properties());
- Collection<DatabaseDiscoveryRuleSegment> toBeCreatedSegments = new LinkedList<>();
- toBeCreatedSegments.add(definitionSegmentDS1);
- toBeCreatedSegments.add(definitionSegmentDS2);
- CreateDatabaseDiscoveryRuleStatement statement = createSQLStatement(true, toBeCreatedSegments);
- updater.checkSQLStatement(database, statement, currentConfig);
- toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentConfig, statement);
- updater.updateCurrentRuleConfiguration(currentConfig, toBeCreatedRuleConfig);
- assertThat(currentConfig.getDataSources().size(), is(2));
- assertTrue(currentConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName)
- .collect(Collectors.toList()).removeAll(Collections.singletonList("readwrite_ds_1")));
- assertTrue(currentConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName)
- .collect(Collectors.toList()).removeAll(Collections.singletonList("readwrite_ds_2")));
- assertTrue(currentConfig.getDiscoveryTypes().containsKey("readwrite_ds_1_mysql_mgr"));
- assertTrue(currentConfig.getDiscoveryTypes().containsKey("readwrite_ds_2_mysql_mgr"));
- assertTrue(currentConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_1_heartbeat"));
- assertTrue(currentConfig.getDiscoveryHeartbeats().containsKey("readwrite_ds_2_heartbeat"));
- Collection<String> dataSources = new LinkedList<>();
- currentConfig.getDataSources().forEach(each -> dataSources.addAll(each.getDataSourceNames()));
- assertThat(dataSources.size(), is(4));
- assertTrue(dataSources.contains("ds_read_0"));
- assertTrue(dataSources.contains("ds_read_1"));
- assertFalse(dataSources.contains("ds_read_3"));
- }
-
- private CreateDatabaseDiscoveryRuleStatement createSQLStatement(final boolean ifNotExists, final Collection<DatabaseDiscoveryRuleSegment> segments) {
- return new CreateDatabaseDiscoveryRuleStatement(ifNotExists, segments);
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java
deleted file mode 100644
index 01f010b64f8..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java
+++ /dev/null
@@ -1,102 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryHeartbeatStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(MockitoExtension.class)
-class DropDatabaseDiscoveryHeartbeatStatementUpdaterTest {
-
- private final DropDatabaseDiscoveryHeartbeatStatementUpdater updater = new DropDatabaseDiscoveryHeartbeatStatementUpdater();
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereDatabase database;
-
- @Test
- void assertCheckSQLStatementWithoutCurrentHeartbeat() {
- assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement(), null));
- }
-
- @Test
- void assertCheckSQLStatementWithoutToBeDroppedHeartbeat() {
- assertThrows(MissingRequiredRuleException.class,
- () -> updater.checkSQLStatement(database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- @Test
- void assertCheckSQLStatementWithInUsed() {
- DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.emptyList(), "heartbeat_name", "");
- assertThrows(RuleInUsedException.class,
- () -> updater.checkSQLStatement(database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(ruleConfig),
- Collections.singletonMap("heartbeat_name", null), Collections.emptyMap())));
- }
-
- @Test
- void assertUpdateCurrentRuleConfiguration() {
- DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration();
- updater.updateCurrentRuleConfiguration(createSQLStatement(), ruleConfig);
- assertFalse(ruleConfig.getDiscoveryHeartbeats().containsKey("heartbeat_name"));
- }
-
- @Test
- void assertUpdateCurrentRuleConfigurationWithIfExists() {
- DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration();
- DropDatabaseDiscoveryHeartbeatStatement dropDatabaseDiscoveryHeartbeatStatement = createSQLStatementWithIfExists();
- updater.checkSQLStatement(database, dropDatabaseDiscoveryHeartbeatStatement, ruleConfig);
- assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryHeartbeatStatement, ruleConfig));
- assertTrue(ruleConfig.getDiscoveryHeartbeats().containsKey("heartbeat_name"));
- assertThat(ruleConfig.getDiscoveryHeartbeats().size(), is(2));
- }
-
- private DropDatabaseDiscoveryHeartbeatStatement createSQLStatement() {
- return new DropDatabaseDiscoveryHeartbeatStatement(false, Collections.singleton("heartbeat_name"));
- }
-
- private DropDatabaseDiscoveryHeartbeatStatement createSQLStatementWithIfExists() {
- return new DropDatabaseDiscoveryHeartbeatStatement(true, Collections.singleton("heartbeat_name_0"));
- }
-
- private DatabaseDiscoveryRuleConfiguration createCurrentRuleConfiguration() {
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeat = new HashMap<>(2, 1);
- discoveryHeartbeat.put("heartbeat_name", new DatabaseDiscoveryHeartBeatConfiguration(new Properties()));
- discoveryHeartbeat.put("other", new DatabaseDiscoveryHeartBeatConfiguration(new Properties()));
- return new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), discoveryHeartbeat, Collections.emptyMap());
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderStatementUpdaterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderStatementUpdaterTest.java
deleted file mode 100644
index 6001cebb60d..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderStatementUpdaterTest.java
+++ /dev/null
@@ -1,102 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryTypeStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(MockitoExtension.class)
-class DropDatabaseDiscoveryProviderStatementUpdaterTest {
-
- private final DropDatabaseDiscoveryTypeStatementUpdater updater = new DropDatabaseDiscoveryTypeStatementUpdater();
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereDatabase database;
-
- @Test
- void assertCheckSQLStatementWithoutCurrentType() {
- assertThrows(MissingRequiredRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement(), null));
- }
-
- @Test
- void assertCheckSQLStatementWithoutToBeDroppedTypes() {
- assertThrows(MissingRequiredRuleException.class,
- () -> updater.checkSQLStatement(database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- @Test
- void assertCheckSQLStatementWithInUsed() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.emptyList(), "", "type_name");
- assertThrows(RuleInUsedException.class,
- () -> updater.checkSQLStatement(database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(dataSourceRuleConfig),
- Collections.emptyMap(), Collections.singletonMap("type_name", null))));
- }
-
- @Test
- void assertUpdateCurrentRuleConfiguration() {
- DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration();
- updater.updateCurrentRuleConfiguration(createSQLStatement(), ruleConfig);
- assertFalse(ruleConfig.getDiscoveryTypes().containsKey("type_name"));
- }
-
- @Test
- void assertUpdateCurrentRuleConfigurationWithIfExists() {
- DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration();
- DropDatabaseDiscoveryTypeStatement dropDatabaseDiscoveryRuleStatement = createSQLStatementWithIfExists();
- updater.checkSQLStatement(database, dropDatabaseDiscoveryRuleStatement, ruleConfig);
- assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryRuleStatement, ruleConfig));
- assertTrue(ruleConfig.getDiscoveryTypes().containsKey("type_name"));
- assertThat(ruleConfig.getDiscoveryTypes().size(), is(2));
- }
-
- private DropDatabaseDiscoveryTypeStatement createSQLStatement() {
- return new DropDatabaseDiscoveryTypeStatement(false, Collections.singleton("type_name"));
- }
-
- private DropDatabaseDiscoveryTypeStatement createSQLStatementWithIfExists() {
- return new DropDatabaseDiscoveryTypeStatement(true, Collections.singleton("type_name_0"));
- }
-
- private DatabaseDiscoveryRuleConfiguration createCurrentRuleConfiguration() {
- Map<String, AlgorithmConfiguration> discoveryTypes = new HashMap<>(2, 1);
- discoveryTypes.put("type_name", new AlgorithmConfiguration("MySQL.MGR", new Properties()));
- discoveryTypes.put("other", new AlgorithmConfiguration("MySQL.MGR", new Properties()));
- return new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), discoveryTypes);
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
deleted file mode 100644
index c4b7441a75d..00000000000
--- a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ /dev/null
@@ -1,161 +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.dbdiscovery.distsql.handler.update;
-
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class DropDatabaseDiscoveryRuleStatementUpdaterTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereDatabase database;
-
- @BeforeEach
- void init() {
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList()));
- }
-
- @Test
- void assertCheckSQLStatementWithoutCurrentRule() {
- assertThrows(MissingRequiredRuleException.class, () -> new DropDatabaseDiscoveryRuleStatementUpdater().checkSQLStatement(database, createSQLStatement(), null));
- }
-
- @Test
- void assertCheckSQLStatementWithoutToBeDroppedRules() {
- assertThrows(MissingRequiredRuleException.class, () -> new DropDatabaseDiscoveryRuleStatementUpdater().checkSQLStatement(
- database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- @Test
- void assertCheckSQLStatementWithRuleInUsed() {
- when(database.getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class, RETURNS_DEEP_STUBS));
- ExportableRule exportableRule = mock(ExportableRule.class);
- when(exportableRule.getExportData()).thenReturn(getExportData());
- when(database.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(exportableRule));
- DatabaseDiscoveryDataSourceRuleConfiguration config = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", null, null, null);
- assertThrows(RuleInUsedException.class, () -> new DropDatabaseDiscoveryRuleStatementUpdater().checkSQLStatement(
- database, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(config), Collections.emptyMap(), Collections.emptyMap())));
- }
-
- private Map<String, Object> getExportData() {
- Map<String, Object> result = new HashMap<>(2, 1);
- result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
- result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
- return result;
- }
-
- private Map<String, Map<String, String>> exportDynamicDataSources() {
- Map<String, String> result = new LinkedHashMap<>(3, 1);
- result.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
- result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
- result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds_0, read_ds_1");
- return Collections.singletonMap("dynamic_rule", result);
- }
-
- private Map<String, Map<String, String>> exportStaticDataSources() {
- Map<String, String> result = new LinkedHashMap<>(2, 1);
- result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
- result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds");
- return Collections.singletonMap("static_rule", result);
- }
-
- @Test
- void assertUpdateCurrentRuleConfiguration() {
- DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = createCurrentRuleConfiguration();
- assertTrue(new DropDatabaseDiscoveryRuleStatementUpdater().updateCurrentRuleConfiguration(createSQLStatement(), databaseDiscoveryRuleConfig));
- assertTrue(databaseDiscoveryRuleConfig.getDataSources().isEmpty());
- assertTrue(databaseDiscoveryRuleConfig.getDiscoveryTypes().isEmpty());
- assertTrue(databaseDiscoveryRuleConfig.getDiscoveryHeartbeats().isEmpty());
- }
-
- @Test
- void assertUpdateCurrentRuleConfigurationWithIfExists() {
- DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = createCurrentRuleConfiguration();
- DropDatabaseDiscoveryRuleStatement dropDatabaseDiscoveryRuleStatement = createSQLStatementWithIfExists();
- DropDatabaseDiscoveryRuleStatementUpdater updater = new DropDatabaseDiscoveryRuleStatementUpdater();
- updater.checkSQLStatement(database, dropDatabaseDiscoveryRuleStatement, databaseDiscoveryRuleConfig);
- assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryRuleStatement, databaseDiscoveryRuleConfig));
- assertThat(databaseDiscoveryRuleConfig.getDataSources().size(), is(1));
- assertThat(databaseDiscoveryRuleConfig.getDiscoveryTypes().size(), is(1));
- }
-
- @Test
- void assertUpdateCurrentRuleConfigurationWithInUsedDiscoveryType() {
- DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = createMultipleCurrentRuleConfigurations();
- assertFalse(new DropDatabaseDiscoveryRuleStatementUpdater().updateCurrentRuleConfiguration(createSQLStatement(), databaseDiscoveryRuleConfig));
- assertThat(databaseDiscoveryRuleConfig.getDiscoveryTypes().size(), is(1));
- }
-
- private DropDatabaseDiscoveryRuleStatement createSQLStatement() {
- return new DropDatabaseDiscoveryRuleStatement(Collections.singleton("ha_group"));
- }
-
- private DropDatabaseDiscoveryRuleStatement createSQLStatementWithIfExists() {
- return new DropDatabaseDiscoveryRuleStatement(true, Collections.singleton("ha_group_0"));
- }
-
- private DatabaseDiscoveryRuleConfiguration createCurrentRuleConfiguration() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR");
- Map<String, AlgorithmConfiguration> discoveryTypes = new HashMap<>(Collections.singletonMap("readwrite_ds_MGR", new AlgorithmConfiguration("readwrite_ds_MGR", new Properties())));
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeats = new HashMap<>(
- Collections.singletonMap("unused_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())));
- return new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), discoveryHeartbeats, discoveryTypes);
- }
-
- private DatabaseDiscoveryRuleConfiguration createMultipleCurrentRuleConfigurations() {
- DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR");
- Map<String, AlgorithmConfiguration> discoveryTypes = Collections.singletonMap(
- "readwrite_ds_MGR", new AlgorithmConfiguration("readwrite_ds_MGR", new Properties()));
- return new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Arrays.asList(dataSourceRuleConfig,
- new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group_another", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR"))), Collections.emptyMap(), discoveryTypes);
- }
-}
diff --git a/features/db-discovery/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider b/features/db-discovery/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
deleted file mode 100644
index 129bf62f0d8..00000000000
--- a/features/db-discovery/distsql/handler/src/test/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
+++ /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.dbdiscovery.distsql.handler.fixture.DistSQLDatabaseDiscoveryProviderFixture
diff --git a/features/db-discovery/distsql/parser/pom.xml b/features/db-discovery/distsql/parser/pom.xml
deleted file mode 100644
index d0ffaceebee..00000000000
--- a/features/db-discovery/distsql/parser/pom.xml
+++ /dev/null
@@ -1,110 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-distsql-parser</artifactId>
- <name>${project.artifactId}</name>
-
- <properties>
- <antlr.output.directory>${basedir}/target/generated-sources/antlr4</antlr.output.directory>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-sql-parser-spi</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-distsql-parser</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql-statement</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>jdk8</id>
- <activation>
- <jdk>1.8</jdk>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>${build-helper-maven-plugin.version}</version>
- <executions>
- <execution>
- <id>add-source</id>
- <goals>
- <goal>add-source</goal>
- </goals>
- <phase>generate-sources</phase>
- <configuration>
- <sources>
- <source>${antlr.output.directory}</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- <profile>
- <id>jdk11+</id>
- <activation>
- <jdk>[11,)</jdk>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>antlr</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- <configuration>
- <libDirectory>src/main/antlr4/imports/db-discovery/</libDirectory>
- <listener>false</listener>
- <visitor>true</visitor>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Alphabet.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Alphabet.g4
deleted file mode 100644
index f7603cc7e63..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Alphabet.g4
+++ /dev/null
@@ -1,48 +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.
- */
-
-lexer grammar Alphabet;
-
-FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
-
-fragment A: [Aa];
-fragment B: [Bb];
-fragment C: [Cc];
-fragment D: [Dd];
-fragment E: [Ee];
-fragment F: [Ff];
-fragment G: [Gg];
-fragment H: [Hh];
-fragment I: [Ii];
-fragment J: [Jj];
-fragment K: [Kk];
-fragment L: [Ll];
-fragment M: [Mm];
-fragment N: [Nn];
-fragment O: [Oo];
-fragment P: [Pp];
-fragment Q: [Qq];
-fragment R: [Rr];
-fragment S: [Ss];
-fragment T: [Tt];
-fragment U: [Uu];
-fragment V: [Vv];
-fragment W: [Ww];
-fragment X: [Xx];
-fragment Y: [Yy];
-fragment Z: [Zz];
-fragment UL_: '_';
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4
deleted file mode 100644
index 0bf6f3ce52a..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4
+++ /dev/null
@@ -1,50 +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.
- */
-
-grammar BaseRule;
-
-import Symbol, Keyword, Literals;
-
-literal
- : STRING_ | (MINUS_)? INT_ | TRUE | FALSE
- ;
-
-algorithmDefinition
- : TYPE LP_ NAME EQ_ algorithmTypeName (COMMA_ propertiesDefinition)? RP_
- ;
-
-algorithmTypeName
- : STRING_ | buildInDatabaseDiscoveryProviderType
- ;
-
-buildInDatabaseDiscoveryProviderType
- : MYSQL_MGR
- | MYSQL_NORMAL_REPLICATION
- | OPENGAUSS_NORMAL_REPLICATION
- ;
-
-propertiesDefinition
- : PROPERTIES LP_ properties? RP_
- ;
-
-properties
- : property (COMMA_ property)*
- ;
-
-property
- : key=STRING_ EQ_ value=literal
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4
deleted file mode 100644
index 0a8c0f9a83c..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4
+++ /dev/null
@@ -1,120 +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.
- */
-
-lexer grammar Keyword;
-
-import Alphabet, Symbol;
-
-WS
- : [ \t\r\n] + ->skip
- ;
-
-TRUE
- : T R U E
- ;
-
-FALSE
- : F A L S E
- ;
-
-CREATE
- : C R E A T E
- ;
-
-ALTER
- : A L T E R
- ;
-
-DROP
- : D R O P
- ;
-
-SHOW
- : S H O W
- ;
-
-STORAGE_UNITS
- : S T O R A G E UL_ U N I T S
- ;
-
-RULE
- : R U L E
- ;
-
-FROM
- : F R O M
- ;
-
-TYPE
- : T Y P E
- ;
-
-NAME
- : N A M E
- ;
-
-PROPERTIES
- : P R O P E R T I E S
- ;
-
-RULES
- : R U L E S
- ;
-
-TYPES
- : T Y P E S
- ;
-
-HEARTBEATS
- : H E A R T B E A T S
- ;
-
-DB_DISCOVERY
- : D B UL_ D I S C O V E R Y
- ;
-
-HEARTBEAT
- : H E A R T B E A T
- ;
-
-IF
- : I F
- ;
-
-EXISTS
- : E X I S T S
- ;
-
-COUNT
- : C O U N T
- ;
-
-MYSQL_MGR
- : M Y S Q L DOT_ M G R
- ;
-
-MYSQL_NORMAL_REPLICATION
- : M Y S Q L DOT_ N O R M A L UL_ R E P L I C A T I O N
- ;
-
-OPENGAUSS_NORMAL_REPLICATION
- : O P E N G A U S S DOT_ N O R M A L UL_ R E P L I C A T I O N
- ;
-
-NOT
- : N O T
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Literals.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Literals.g4
deleted file mode 100644
index 1d13bcc2332..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Literals.g4
+++ /dev/null
@@ -1,50 +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.
- */
-
-lexer grammar Literals;
-
-import Alphabet, Symbol;
-
-IDENTIFIER_
- : [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]*
- | BQ_ ~'`'+ BQ_
- ;
-
-STRING_
- : (DQ_ ('\\'. | '""' | ~('"' | '\\'))* DQ_)
- | (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_)
- ;
-
-INT_
- : [0-9]+
- ;
-
-HEX_
- : [0-9a-fA-F]
- ;
-
-NUMBER_
- : INT_? DOT_? INT_ (E (PLUS_ | MINUS_)? INT_)?
- ;
-
-HEXDIGIT_
- : '0x' HEX_+ | 'X' SQ_ HEX_+ SQ_
- ;
-
-BITNUM_
- : '0b' ('0' | '1')+ | B SQ_ ('0' | '1')+ SQ_
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
deleted file mode 100644
index 1f3b9c0df19..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
+++ /dev/null
@@ -1,76 +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.
- */
-
-grammar RDLStatement;
-
-import BaseRule;
-
-createDatabaseDiscoveryRule
- : CREATE DB_DISCOVERY RULE ifNotExists? databaseDiscoveryRule (COMMA_ databaseDiscoveryRule)*
- ;
-
-alterDatabaseDiscoveryRule
- : ALTER DB_DISCOVERY RULE databaseDiscoveryRule (COMMA_ databaseDiscoveryRule)*
- ;
-
-dropDatabaseDiscoveryRule
- : DROP DB_DISCOVERY RULE ifExists? ruleName (COMMA_ ruleName)*
- ;
-
-dropDatabaseDiscoveryType
- : DROP DB_DISCOVERY TYPE ifExists? discoveryTypeName (COMMA_ discoveryTypeName)*
- ;
-
-dropDatabaseDiscoveryHeartbeat
- : DROP DB_DISCOVERY HEARTBEAT ifExists? discoveryHeartbeatName (COMMA_ discoveryHeartbeatName)*
- ;
-
-databaseDiscoveryRule
- : ruleName LP_ storageUnits COMMA_ algorithmDefinition COMMA_ discoveryHeartbeat RP_
- ;
-
-ruleName
- : IDENTIFIER_
- ;
-
-storageUnits
- : STORAGE_UNITS LP_ storageUnitName (COMMA_ storageUnitName)* RP_
- ;
-
-storageUnitName
- : IDENTIFIER_
- ;
-
-discoveryHeartbeat
- : HEARTBEAT LP_ propertiesDefinition RP_
- ;
-
-discoveryTypeName
- : IDENTIFIER_
- ;
-
-discoveryHeartbeatName
- : IDENTIFIER_
- ;
-
-ifExists
- : IF EXISTS
- ;
-
-ifNotExists
- : IF NOT EXISTS
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
deleted file mode 100644
index 25addc2d0a8..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++ /dev/null
@@ -1,44 +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.
- */
-
-grammar RQLStatement;
-
-import BaseRule;
-
-showDatabaseDiscoveryRules
- : SHOW DB_DISCOVERY (RULE ruleName | RULES) (FROM databaseName)?
- ;
-
-showDatabaseDiscoveryTypes
- : SHOW DB_DISCOVERY TYPES (FROM databaseName)?
- ;
-
-showDatabaseDiscoveryHeartbeats
- : SHOW DB_DISCOVERY HEARTBEATS (FROM databaseName)?
- ;
-
-countDatabaseDiscoveryRule
- : COUNT DB_DISCOVERY RULE (FROM databaseName)?
- ;
-
-ruleName
- : IDENTIFIER_
- ;
-
-databaseName
- : IDENTIFIER_
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Symbol.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Symbol.g4
deleted file mode 100644
index 90dba68ccfc..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Symbol.g4
+++ /dev/null
@@ -1,61 +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.
- */
-
-lexer grammar Symbol;
-
-AND_: '&&';
-OR_: '||';
-NOT_: '!';
-TILDE_: '~';
-VERTICALBAR_: '|';
-AMPERSAND_: '&';
-SIGNEDLEFTSHIFT_: '<<';
-SIGNEDRIGHTSHIFT_: '>>';
-CARET_: '^';
-MOD_: '%';
-COLON_: ':';
-PLUS_: '+';
-MINUS_: '-';
-ASTERISK_: '*';
-SLASH_: '/';
-BACKSLASH_: '\\';
-DOT_: '.';
-DOTASTERISK_: '.*';
-SAFEEQ_: '<=>';
-DEQ_: '==';
-EQ_: '=';
-NEQ_: '<>' | '!=';
-GT_: '>';
-GTE_: '>=';
-LT_: '<';
-LTE_: '<=';
-POUND_: '#';
-LP_: '(';
-RP_: ')';
-LBE_: '{';
-RBE_: '}';
-LBT_: '[';
-RBT_: ']';
-COMMA_: ',';
-DQ_: '"';
-SQ_: '\'';
-BQ_: '`';
-QUESTION_: '?';
-AT_: '@';
-SEMI_: ';';
-JSONSEPARATOR_: '->>';
-UL_: '_';
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
deleted file mode 100644
index 405c9f1b195..00000000000
--- a/features/db-discovery/distsql/parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryDistSQLStatement.g4
+++ /dev/null
@@ -1,33 +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.
- */
-
-grammar DatabaseDiscoveryDistSQLStatement;
-
-import Symbol, RDLStatement, RQLStatement;
-
-execute
- : (createDatabaseDiscoveryRule
- | alterDatabaseDiscoveryRule
- | dropDatabaseDiscoveryRule
- | showDatabaseDiscoveryTypes
- | showDatabaseDiscoveryHeartbeats
- | showDatabaseDiscoveryRules
- | dropDatabaseDiscoveryType
- | dropDatabaseDiscoveryHeartbeat
- | countDatabaseDiscoveryRule
- ) SEMI?
- ;
diff --git a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLLexer.java b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLLexer.java
deleted file mode 100644
index 11ffb8e0119..00000000000
--- a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLLexer.java
+++ /dev/null
@@ -1,32 +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.dbdiscovery.distsql.parser.core;
-
-import org.antlr.v4.runtime.CharStream;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementLexer;
-import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
-
-/**
- * SQL lexer for database discovery DistSQL.
- */
-public final class DatabaseDiscoveryDistSQLLexer extends DatabaseDiscoveryDistSQLStatementLexer implements SQLLexer {
-
- public DatabaseDiscoveryDistSQLLexer(final CharStream input) {
- super(input);
- }
-}
diff --git a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLParser.java b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLParser.java
deleted file mode 100644
index 26809d949f9..00000000000
--- a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLParser.java
+++ /dev/null
@@ -1,40 +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.dbdiscovery.distsql.parser.core;
-
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.TokenStream;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser;
-import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
-
-/**
- * SQL parser for database discovery DistSQL.
- */
-public final class DatabaseDiscoveryDistSQLParser extends DatabaseDiscoveryDistSQLStatementParser implements SQLParser {
-
- public DatabaseDiscoveryDistSQLParser(final TokenStream input) {
- super(input);
- }
-
- @Override
- public ASTNode parse() {
- return new ParseASTNode(execute(), (CommonTokenStream) getTokenStream());
- }
-}
diff --git a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
deleted file mode 100644
index 178a16b291f..00000000000
--- a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
+++ /dev/null
@@ -1,144 +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.dbdiscovery.distsql.parser.core;
-
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CountDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryHeartbeatStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryTypeStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementBaseVisitor;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.AlgorithmDefinitionContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.AlterDatabaseDiscoveryRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.CreateDatabaseDiscoveryRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseNameContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryHeartbeatContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryTypeContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.PropertiesDefinitionContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.PropertyContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryHeartbeatsContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryRulesContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryTypesContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.StorageUnitsContext;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
-/**
- * SQL statement visitor for database discovery DistSQL.
- */
-public final class DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDiscoveryDistSQLStatementBaseVisitor<ASTNode> implements SQLVisitor {
-
- @Override
- public ASTNode visitCreateDatabaseDiscoveryRule(final CreateDatabaseDiscoveryRuleContext ctx) {
- return new CreateDatabaseDiscoveryRuleStatement(null != ctx.ifNotExists(),
- ctx.databaseDiscoveryRule().stream().map(each -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
- }
-
- @Override
- public ASTNode visitAlterDatabaseDiscoveryRule(final AlterDatabaseDiscoveryRuleContext ctx) {
- return new AlterDatabaseDiscoveryRuleStatement(ctx.databaseDiscoveryRule().stream().map(each -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
- }
-
- @Override
- public ASTNode visitDatabaseDiscoveryRule(final DatabaseDiscoveryRuleContext ctx) {
- return new DatabaseDiscoveryRuleSegment(getIdentifierValue(ctx.ruleName()), buildResources(ctx.storageUnits()), (AlgorithmSegment) visit(ctx.algorithmDefinition()),
- getProperties(ctx.discoveryHeartbeat().propertiesDefinition()));
- }
-
- private List<String> buildResources(final StorageUnitsContext ctx) {
- return ctx.storageUnitName().stream().map(each -> new IdentifierValue(each.getText()).getValue()).collect(Collectors.toList());
- }
-
- @Override
- public ASTNode visitDropDatabaseDiscoveryRule(final DropDatabaseDiscoveryRuleContext ctx) {
- return new DropDatabaseDiscoveryRuleStatement(null != ctx.ifExists(), ctx.ruleName().stream().map(this::getIdentifierValue).collect(Collectors.toList()));
- }
-
- @Override
- public ASTNode visitShowDatabaseDiscoveryRules(final ShowDatabaseDiscoveryRulesContext ctx) {
- return new ShowDatabaseDiscoveryRulesStatement(null == ctx.ruleName() ? null : getIdentifierValue(ctx.ruleName()),
- null == ctx.databaseName() ? null : (DatabaseSegment) visit(ctx.databaseName()));
- }
-
- @Override
- public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
- }
-
- @Override
- public ASTNode visitShowDatabaseDiscoveryTypes(final ShowDatabaseDiscoveryTypesContext ctx) {
- return new ShowDatabaseDiscoveryTypesStatement(null == ctx.databaseName() ? null : (DatabaseSegment) visit(ctx.databaseName()));
- }
-
- @Override
- public ASTNode visitShowDatabaseDiscoveryHeartbeats(final ShowDatabaseDiscoveryHeartbeatsContext ctx) {
- return new ShowDatabaseDiscoveryHeartbeatsStatement(null == ctx.databaseName() ? null : (DatabaseSegment) visit(ctx.databaseName()));
- }
-
- private String getIdentifierValue(final ParseTree context) {
- return null == context ? null : new IdentifierValue(context.getText()).getValue();
- }
-
- @Override
- public ASTNode visitDatabaseName(final DatabaseNameContext ctx) {
- return new DatabaseSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
- }
-
- @Override
- public ASTNode visitDropDatabaseDiscoveryType(final DropDatabaseDiscoveryTypeContext ctx) {
- return new DropDatabaseDiscoveryTypeStatement(null != ctx.ifExists(), ctx.discoveryTypeName().stream().map(this::getIdentifierValue).collect(Collectors.toList()));
- }
-
- @Override
- public ASTNode visitDropDatabaseDiscoveryHeartbeat(final DropDatabaseDiscoveryHeartbeatContext ctx) {
- return new DropDatabaseDiscoveryHeartbeatStatement(null != ctx.ifExists(), ctx.discoveryHeartbeatName().stream().map(this::getIdentifierValue).collect(Collectors.toList()));
- }
-
- @Override
- public ASTNode visitCountDatabaseDiscoveryRule(final DatabaseDiscoveryDistSQLStatementParser.CountDatabaseDiscoveryRuleContext ctx) {
- return new CountDatabaseDiscoveryRuleStatement(Objects.nonNull(ctx.databaseName()) ? (DatabaseSegment) visit(ctx.databaseName()) : null);
- }
-
- private Properties getProperties(final PropertiesDefinitionContext ctx) {
- Properties result = new Properties();
- if (null == ctx || null == ctx.properties()) {
- return result;
- }
- for (PropertyContext each : ctx.properties().property()) {
- result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
- }
- return result;
- }
-}
diff --git a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryDistSQLStatementParserFacade.java b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryDistSQLStatementParserFacade.java
deleted file mode 100644
index 73c042a8e35..00000000000
--- a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryDistSQLStatementParserFacade.java
+++ /dev/null
@@ -1,52 +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.dbdiscovery.distsql.parser.facade;
-
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryDistSQLLexer;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryDistSQLParser;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryDistSQLStatementVisitor;
-import org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
-import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
-import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
-
-/**
- * SQL parser facade for database discovery DistSQL statement.
- */
-public final class DatabaseDiscoveryDistSQLStatementParserFacade implements FeaturedDistSQLStatementParserFacade {
-
- @Override
- public Class<? extends SQLLexer> getLexerClass() {
- return DatabaseDiscoveryDistSQLLexer.class;
- }
-
- @Override
- public Class<? extends SQLParser> getParserClass() {
- return DatabaseDiscoveryDistSQLParser.class;
- }
-
- @Override
- public Class<? extends SQLVisitor> getVisitorClass() {
- return DatabaseDiscoveryDistSQLStatementVisitor.class;
- }
-
- @Override
- public String getType() {
- return "database-discovery";
- }
-}
diff --git a/features/db-discovery/distsql/parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade b/features/db-discovery/distsql/parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
deleted file mode 100644
index d9d07bb6154..00000000000
--- a/features/db-discovery/distsql/parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
+++ /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.dbdiscovery.distsql.parser.facade.DatabaseDiscoveryDistSQLStatementParserFacade
diff --git a/features/db-discovery/distsql/pom.xml b/features/db-discovery/distsql/pom.xml
deleted file mode 100644
index 89ecbf35e7e..00000000000
--- a/features/db-discovery/distsql/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-distsql</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <modules>
- <module>statement</module>
- <module>parser</module>
- <module>handler</module>
- </modules>
-</project>
diff --git a/features/db-discovery/distsql/statement/pom.xml b/features/db-discovery/distsql/statement/pom.xml
deleted file mode 100644
index 522c03b21ea..00000000000
--- a/features/db-discovery/distsql/statement/pom.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-distsql-statement</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-distsql-statement</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryHeartbeatSegment.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryHeartbeatSegment.java
deleted file mode 100644
index 6e0e9b75543..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryHeartbeatSegment.java
+++ /dev/null
@@ -1,36 +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.dbdiscovery.distsql.parser.segment;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-
-import java.util.Properties;
-
-/**
- * Database discovery heartbeat segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryHeartbeatSegment implements ASTNode {
-
- private final String heartbeatName;
-
- private final Properties properties;
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryProviderSegment.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryProviderSegment.java
deleted file mode 100644
index a0f08b5d88b..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryProviderSegment.java
+++ /dev/null
@@ -1,35 +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.dbdiscovery.distsql.parser.segment;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-
-/**
- * Database discovery provider segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryProviderSegment implements ASTNode {
-
- private final String discoveryProviderName;
-
- private final AlgorithmSegment algorithm;
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryRuleSegment.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryRuleSegment.java
deleted file mode 100644
index 60cb27f4ec8..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/segment/DatabaseDiscoveryRuleSegment.java
+++ /dev/null
@@ -1,43 +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.dbdiscovery.distsql.parser.segment;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-
-import java.util.Collection;
-import java.util.Properties;
-
-/**
- * Database discovery rule definition segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseDiscoveryRuleSegment implements ASTNode {
-
- private final String name;
-
- private final Collection<String> dataSources;
-
- private final AlgorithmSegment discoveryType;
-
- private final Properties discoveryHeartbeat;
-
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/AlterDatabaseDiscoveryRuleStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/AlterDatabaseDiscoveryRuleStatement.java
deleted file mode 100644
index 209c1d3f7bb..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/AlterDatabaseDiscoveryRuleStatement.java
+++ /dev/null
@@ -1,35 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterRuleStatement;
-
-import java.util.Collection;
-
-/**
- * Alter database discovery rule statement.
- */
-@RequiredArgsConstructor
-@Getter
-public final class AlterDatabaseDiscoveryRuleStatement extends AlterRuleStatement {
-
- private final Collection<DatabaseDiscoveryRuleSegment> rules;
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CountDatabaseDiscoveryRuleStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CountDatabaseDiscoveryRuleStatement.java
deleted file mode 100644
index ac6eb1caa44..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CountDatabaseDiscoveryRuleStatement.java
+++ /dev/null
@@ -1,31 +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.dbdiscovery.distsql.parser.statement;
-
-import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-
-/**
- * Count database discovery rule statement.
- */
-public final class CountDatabaseDiscoveryRuleStatement extends ShowRulesStatement {
-
- public CountDatabaseDiscoveryRuleStatement(final DatabaseSegment database) {
- super(database);
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryRuleStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryRuleStatement.java
deleted file mode 100644
index d8385930e72..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/CreateDatabaseDiscoveryRuleStatement.java
+++ /dev/null
@@ -1,38 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateRuleStatement;
-
-import java.util.Collection;
-
-/**
- * Create database discovery rule statement.
- */
-@Getter
-public final class CreateDatabaseDiscoveryRuleStatement extends CreateRuleStatement {
-
- private final Collection<DatabaseDiscoveryRuleSegment> rules;
-
- public CreateDatabaseDiscoveryRuleStatement(final boolean ifNotExists, final Collection<DatabaseDiscoveryRuleSegment> rules) {
- super(ifNotExists);
- this.rules = rules;
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryHeartbeatStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryHeartbeatStatement.java
deleted file mode 100644
index 709ff6ef6f3..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryHeartbeatStatement.java
+++ /dev/null
@@ -1,37 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement;
-
-import java.util.Collection;
-
-/**
- * Drop database discovery heartbeat statement.
- */
-@Getter
-public final class DropDatabaseDiscoveryHeartbeatStatement extends DropRuleStatement {
-
- private final Collection<String> names;
-
- public DropDatabaseDiscoveryHeartbeatStatement(final boolean ifExists, final Collection<String> names) {
- super(ifExists);
- this.names = names;
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryRuleStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryRuleStatement.java
deleted file mode 100644
index 7eee4bec6e6..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryRuleStatement.java
+++ /dev/null
@@ -1,39 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement;
-
-import java.util.Collection;
-
-/**
- * Drop database discovery rule statement.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DropDatabaseDiscoveryRuleStatement extends DropRuleStatement {
-
- private final Collection<String> names;
-
- public DropDatabaseDiscoveryRuleStatement(final boolean ifExists, final Collection<String> names) {
- super(ifExists);
- this.names = names;
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryTypeStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryTypeStatement.java
deleted file mode 100644
index eb53e50650d..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/DropDatabaseDiscoveryTypeStatement.java
+++ /dev/null
@@ -1,37 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement;
-
-import java.util.Collection;
-
-/**
- * Drop database discovery type statement.
- */
-@Getter
-public final class DropDatabaseDiscoveryTypeStatement extends DropRuleStatement {
-
- private final Collection<String> types;
-
- public DropDatabaseDiscoveryTypeStatement(final boolean ifExists, final Collection<String> types) {
- super(ifExists);
- this.types = types;
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryHeartbeatsStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryHeartbeatsStatement.java
deleted file mode 100644
index 3232ae821b4..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryHeartbeatsStatement.java
+++ /dev/null
@@ -1,31 +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.dbdiscovery.distsql.parser.statement;
-
-import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-
-/**
- * Show database discovery heartbeats statement.
- */
-public final class ShowDatabaseDiscoveryHeartbeatsStatement extends ShowRulesStatement {
-
- public ShowDatabaseDiscoveryHeartbeatsStatement(final DatabaseSegment database) {
- super(database);
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryRulesStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryRulesStatement.java
deleted file mode 100644
index ac5f38d4093..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryRulesStatement.java
+++ /dev/null
@@ -1,36 +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.dbdiscovery.distsql.parser.statement;
-
-import lombok.Getter;
-import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-
-/**
- * Show database discovery rules statement.
- */
-@Getter
-public final class ShowDatabaseDiscoveryRulesStatement extends ShowRulesStatement {
-
- private final String ruleName;
-
- public ShowDatabaseDiscoveryRulesStatement(final String ruleName, final DatabaseSegment database) {
- super(database);
- this.ruleName = ruleName;
- }
-}
diff --git a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryTypesStatement.java b/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryTypesStatement.java
deleted file mode 100644
index 9bf6c3bfa32..00000000000
--- a/features/db-discovery/distsql/statement/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/statement/ShowDatabaseDiscoveryTypesStatement.java
+++ /dev/null
@@ -1,31 +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.dbdiscovery.distsql.parser.statement;
-
-import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
-
-/**
- * Show database discovery types statement.
- */
-public final class ShowDatabaseDiscoveryTypesStatement extends ShowRulesStatement {
-
- public ShowDatabaseDiscoveryTypesStatement(final DatabaseSegment database) {
- super(database);
- }
-}
diff --git a/features/db-discovery/pom.xml b/features/db-discovery/pom.xml
deleted file mode 100644
index 5ba83235bcf..00000000000
--- a/features/db-discovery/pom.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-features</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <modules>
- <module>api</module>
- <module>core</module>
- <module>distsql</module>
- <module>provider</module>
- </modules>
-</project>
diff --git a/features/db-discovery/provider/mysql/pom.xml b/features/db-discovery/provider/mysql/pom.xml
deleted file mode 100644
index f96bd334bdd..00000000000
--- a/features/db-discovery/provider/mysql/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-provider</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-mysql</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-executor</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-test-util</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-test-fixture-jdbc</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
deleted file mode 100644
index a0a3b2e16ec..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.mgr;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Invalid MGR group name configuration exception.
- */
-public final class InvalidMGRGroupNameConfigurationException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = -2585442998454509788L;
-
- public InvalidMGRGroupNameConfigurationException(final String groupName, final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 83, "Group name in MGR is not same with configured one `%s` in database `%s`.", groupName, databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
deleted file mode 100644
index eccae20791a..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.mgr;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Invalid MGR mode exception.
- */
-public final class InvalidMGRModeException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = -2190741601319220590L;
-
- public InvalidMGRModeException(final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 81, "MGR is not in single primary mode in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
deleted file mode 100644
index 345c5cb2297..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.mgr;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Invalid MGR plugin exception.
- */
-public final class InvalidMGRPluginException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = 1703082683321097037L;
-
- public InvalidMGRPluginException(final String databaseName) {
- super(XOpenSQLState.GENERAL_ERROR, 80, "MGR plugin is not active in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
deleted file mode 100644
index 51fc450984a..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.mgr;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Invalid MGR replication group member exception.
- */
-public final class InvalidMGRReplicationGroupMemberException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = 3766206496827463146L;
-
- public InvalidMGRReplicationGroupMemberException(final String url, final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 82, "`%s` is not in MGR replication group member in database `%s`.", url, databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java
deleted file mode 100644
index 77d9c7c85aa..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.replica;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Duplicate primary data source exception.
- */
-public final class DuplicatePrimaryDataSourceException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = -7715117257616134436L;
-
- public DuplicatePrimaryDataSourceException(final String databaseName) {
- super(XOpenSQLState.DUPLICATE, 90, "Duplicate primary data source in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/PrimaryDataSourceNotFoundException.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/PrimaryDataSourceNotFoundException.java
deleted file mode 100644
index 69f363d505c..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/PrimaryDataSourceNotFoundException.java
+++ /dev/null
@@ -1,33 +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.dbdiscovery.mysql.exception.replica;
-
-import org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Primary data source not found exception.
- */
-public final class PrimaryDataSourceNotFoundException extends DBDiscoveryProviderException {
-
- private static final long serialVersionUID = -4646464806520242027L;
-
- public PrimaryDataSourceNotFoundException(final String databaseName) {
- super(XOpenSQLState.NOT_FOUND, 91, "Primary data source not found in database `%s`.", databaseName);
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProvider.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProvider.java
deleted file mode 100644
index acb07b8b13a..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProvider.java
+++ /dev/null
@@ -1,170 +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.dbdiscovery.mysql.type;
-
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr.InvalidMGRGroupNameConfigurationException;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr.InvalidMGRModeException;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr.InvalidMGRPluginException;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr.InvalidMGRReplicationGroupMemberException;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.database.metadata.dialect.MySQLDataSourceMetaData;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-/**
- * MGR database discovery provider for MySQL.
- */
-public final class MGRMySQLDatabaseDiscoveryProvider implements DatabaseDiscoveryProvider {
-
- private static final String QUERY_PLUGIN_STATUS = "SELECT PLUGIN_STATUS FROM information_schema.PLUGINS WHERE PLUGIN_NAME='group_replication'";
-
- private static final String QUERY_SINGLE_PRIMARY_MODE = "SELECT VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME='group_replication_single_primary_mode'";
-
- private static final String QUERY_GROUP_NAME = "SELECT VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME='group_replication_group_name'";
-
- private static final String QUERY_MEMBER_LIST = "SELECT MEMBER_HOST, MEMBER_PORT, MEMBER_STATE FROM performance_schema.replication_group_members";
-
- private static final String QUERY_PRIMARY_DATA_SOURCE = "SELECT MEMBER_HOST, MEMBER_PORT FROM performance_schema.replication_group_members WHERE MEMBER_ID = "
- + "(SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME = 'group_replication_primary_member')";
-
- private static final String QUERY_CURRENT_MEMBER_STATE = "SELECT MEMBER_STATE FROM performance_schema.replication_group_members WHERE MEMBER_HOST=? AND MEMBER_PORT=?";
-
- private int minEnabledReplicas;
-
- private String groupName;
-
- @Override
- public void init(final Properties props) {
- minEnabledReplicas = Integer.parseInt(props.getProperty("min-enabled-replicas", "0"));
- groupName = props.getProperty("group-name", "");
- }
-
- @SneakyThrows({InterruptedException.class, ExecutionException.class})
- @Override
- public void checkEnvironment(final String databaseName, final Collection<DataSource> dataSources) {
- ExecutorService executorService = ExecutorEngine.createExecutorEngineWithCPUAndResources(dataSources.size()).getExecutorServiceManager().getExecutorService();
- Collection<Future<Boolean>> futures = new LinkedList<>();
- for (DataSource each : dataSources) {
- futures.add(executorService.submit(() -> checkDataSourceEnvironment(databaseName, each)));
- }
- for (Future<Boolean> each : futures) {
- each.get();
- }
- }
-
- private Boolean checkDataSourceEnvironment(final String databaseName, final DataSource dataSource) {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement()) {
- checkPluginActive(databaseName, statement);
- checkSinglePrimaryMode(databaseName, statement);
- checkGroupName(databaseName, statement);
- checkMemberInstanceURL(databaseName, connection.getMetaData().getURL(), statement);
- return Boolean.TRUE;
- } catch (final SQLException ignored) {
- return Boolean.FALSE;
- }
- }
-
- private void checkPluginActive(final String databaseName, final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(QUERY_PLUGIN_STATUS)) {
- ShardingSpherePreconditions.checkState(resultSet.next() && "ACTIVE".equals(resultSet.getString("PLUGIN_STATUS")), () -> new InvalidMGRPluginException(databaseName));
- }
- }
-
- private void checkSinglePrimaryMode(final String databaseName, final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(QUERY_SINGLE_PRIMARY_MODE)) {
- ShardingSpherePreconditions.checkState(resultSet.next() && "ON".equals(resultSet.getString("VARIABLE_VALUE")), () -> new InvalidMGRModeException(databaseName));
- }
- }
-
- private void checkGroupName(final String databaseName, final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(QUERY_GROUP_NAME)) {
- ShardingSpherePreconditions.checkState(resultSet.next() && groupName.equals(resultSet.getString("VARIABLE_VALUE")),
- () -> new InvalidMGRGroupNameConfigurationException(groupName, databaseName));
- }
- }
-
- private void checkMemberInstanceURL(final String databaseName, final String url, final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(QUERY_MEMBER_LIST)) {
- while (resultSet.next()) {
- if (url.contains(String.join(":", resultSet.getString("MEMBER_HOST"), resultSet.getString("MEMBER_PORT")))) {
- return;
- }
- }
- }
- throw new InvalidMGRReplicationGroupMemberException(url, databaseName);
- }
-
- @Override
- public boolean isPrimaryInstance(final DataSource dataSource) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(QUERY_PRIMARY_DATA_SOURCE)) {
- if (resultSet.next()) {
- MySQLDataSourceMetaData metaData = new MySQLDataSourceMetaData(connection.getMetaData().getURL());
- return metaData.getHostname().equals(resultSet.getString("MEMBER_HOST")) && Integer.toString(metaData.getPort()).equals(resultSet.getString("MEMBER_PORT"));
- }
- }
- return false;
- }
-
- @Override
- public ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) throws SQLException {
- try (Connection connection = replicaDataSource.getConnection()) {
- return new ReplicaDataSourceStatus(isOnlineDataSource(connection, new MySQLDataSourceMetaData(connection.getMetaData().getURL())), 0L);
- }
- }
-
- private boolean isOnlineDataSource(final Connection connection, final MySQLDataSourceMetaData metaData) throws SQLException {
- try (PreparedStatement preparedStatement = connection.prepareStatement(QUERY_CURRENT_MEMBER_STATE)) {
- preparedStatement.setString(1, metaData.getHostname());
- preparedStatement.setString(2, Integer.toString(metaData.getPort()));
- try (ResultSet resultSet = preparedStatement.executeQuery()) {
- return resultSet.next() && "ONLINE".equals(resultSet.getString("MEMBER_STATE"));
- }
- }
- }
-
- @Override
- public Optional<Integer> getMinEnabledReplicas() {
- return Optional.of(minEnabledReplicas);
- }
-
- @Override
- public String getType() {
- return "MySQL.MGR";
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProvider.java b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProvider.java
deleted file mode 100644
index 252c606e34d..00000000000
--- a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProvider.java
+++ /dev/null
@@ -1,150 +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.dbdiscovery.mysql.type;
-
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.replica.DuplicatePrimaryDataSourceException;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.replica.PrimaryDataSourceNotFoundException;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
-import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.TreeSet;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-/**
- * Normal replication database discovery provider for MySQL.
- */
-public final class MySQLNormalReplicationDatabaseDiscoveryProvider implements DatabaseDiscoveryProvider {
-
- private static final String SHOW_SLAVE_STATUS = "SHOW SLAVE STATUS";
-
- private static final String SHOW_SLAVE_HOSTS = "SHOW SLAVE HOSTS";
-
- private static final String SHOW_VARIABLES_READ_ONLY = "SHOW VARIABLES LIKE 'read_only'";
-
- private int minEnabledReplicas;
-
- private long delayMillisecondsThreshold;
-
- @Override
- public void init(final Properties props) {
- minEnabledReplicas = Integer.parseInt(props.getProperty("min-enabled-replicas", "0"));
- delayMillisecondsThreshold = Long.parseLong(props.getProperty("delay-milliseconds-threshold", "0"));
- }
-
- @SneakyThrows({InterruptedException.class, ExecutionException.class})
- @Override
- public void checkEnvironment(final String databaseName, final Collection<DataSource> dataSources) {
- ExecutorService executorService = ExecutorEngine.createExecutorEngineWithCPUAndResources(dataSources.size()).getExecutorServiceManager().getExecutorService();
- Collection<Future<Boolean>> futures = new LinkedList<>();
- Collection<Boolean> primaryInstances = new TreeSet<>();
- for (DataSource each : dataSources) {
- futures.add(executorService.submit(() -> isPrimaryInstance(each)));
- }
- for (Future<Boolean> each : futures) {
- checkPrimaryInstances(databaseName, each.get(), primaryInstances);
- }
- ShardingSpherePreconditions.checkState(!primaryInstances.isEmpty(), () -> new PrimaryDataSourceNotFoundException(databaseName));
- }
-
- @Override
- public boolean isPrimaryInstance(final DataSource dataSource) throws SQLException {
- return !getReplicationInstances(dataSource).isEmpty() && isNotReadonlyInstance(dataSource);
- }
-
- private Collection<String> getReplicationInstances(final DataSource dataSource) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement()) {
- return getReplicationInstances(statement);
- }
- }
-
- private Collection<String> getReplicationInstances(final Statement statement) throws SQLException {
- Collection<String> result = new LinkedList<>();
- try (ResultSet resultSet = statement.executeQuery(SHOW_SLAVE_HOSTS)) {
- while (resultSet.next()) {
- result.add(String.join(":", resultSet.getString("HOST"), resultSet.getString("PORT")));
- }
- }
- return result;
- }
-
- private boolean isNotReadonlyInstance(final DataSource dataSource) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(SHOW_VARIABLES_READ_ONLY)) {
- return resultSet.next() && resultSet.getString("Value").equals("OFF");
- }
- }
-
- private void checkPrimaryInstances(final String databaseName, final boolean isPrimaryInstance, final Collection<Boolean> primaryInstances) {
- if (!isPrimaryInstance) {
- return;
- }
- ShardingSpherePreconditions.checkState(primaryInstances.add(Boolean.TRUE), () -> new DuplicatePrimaryDataSourceException(databaseName));
- }
-
- @Override
- public ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) throws SQLException {
- try (
- Connection connection = replicaDataSource.getConnection();
- Statement statement = connection.createStatement()) {
- if (0L == delayMillisecondsThreshold) {
- return new ReplicaDataSourceStatus(true, 0L);
- }
- long replicationDelayMilliseconds = queryReplicationDelayMilliseconds(statement);
- boolean isDelay = replicationDelayMilliseconds >= delayMillisecondsThreshold;
- return new ReplicaDataSourceStatus(!isDelay, replicationDelayMilliseconds);
- }
- }
-
- private long queryReplicationDelayMilliseconds(final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(SHOW_SLAVE_STATUS)) {
- if (resultSet.next()) {
- long delay = resultSet.getLong("Seconds_Behind_Master") * 1000;
- return resultSet.wasNull() ? Long.MAX_VALUE : delay;
- }
- return Long.MAX_VALUE;
- }
- }
-
- @Override
- public Optional<Integer> getMinEnabledReplicas() {
- return Optional.of(minEnabledReplicas);
- }
-
- @Override
- public String getType() {
- return "MySQL.NORMAL_REPLICATION";
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider b/features/db-discovery/provider/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
deleted file mode 100644
index bfba97339e9..00000000000
--- a/features/db-discovery/provider/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
+++ /dev/null
@@ -1,19 +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.dbdiscovery.mysql.type.MGRMySQLDatabaseDiscoveryProvider
-org.apache.shardingsphere.dbdiscovery.mysql.type.MySQLNormalReplicationDatabaseDiscoveryProvider
diff --git a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderTest.java b/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderTest.java
deleted file mode 100644
index f11e4ce8b23..00000000000
--- a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryProviderTest.java
+++ /dev/null
@@ -1,89 +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.dbdiscovery.mysql.type;
-
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class MGRDatabaseDiscoveryProviderTest {
-
- @Test
- void assertCheckEnvironment() throws SQLException {
- DatabaseDiscoveryProvider actual = TypedSPILoader.getService(DatabaseDiscoveryProvider.class, "MySQL.MGR", PropertiesBuilder.build(new Property("group-name", "foo_group")));
- actual.checkEnvironment("foo_db", Collections.singletonList(mockEnvironmentAvailableDataSource()));
- }
-
- private DataSource mockEnvironmentAvailableDataSource() throws SQLException {
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- ResultSet resultSet = mock(ResultSet.class);
- when(result.getConnection().createStatement().executeQuery(any())).thenReturn(resultSet);
- when(resultSet.next()).thenReturn(true, true, true, true, false);
- when(resultSet.getString("PLUGIN_STATUS")).thenReturn("ACTIVE");
- when(resultSet.getString("VARIABLE_VALUE")).thenReturn("ON", "foo_group");
- when(resultSet.getString("MEMBER_HOST")).thenReturn("127.0.0.1");
- when(resultSet.getString("MEMBER_PORT")).thenReturn("3306");
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1:3306/foo_ds");
- return result;
- }
-
- @Test
- void assertIsPrimaryInstance() throws SQLException {
- DatabaseDiscoveryProvider actual = TypedSPILoader.getService(DatabaseDiscoveryProvider.class, "MySQL.MGR");
- assertTrue(actual.isPrimaryInstance(mockPrimaryDataSource()));
- }
-
- private DataSource mockPrimaryDataSource() throws SQLException {
- String sql = "SELECT MEMBER_HOST, MEMBER_PORT FROM performance_schema.replication_group_members WHERE MEMBER_ID = "
- + "(SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME = 'group_replication_primary_member')";
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- ResultSet resultSet = mock(ResultSet.class);
- when(result.getConnection().createStatement().executeQuery(sql)).thenReturn(resultSet);
- when(resultSet.next()).thenReturn(true, false);
- when(resultSet.getString("MEMBER_HOST")).thenReturn("127.0.0.1");
- when(resultSet.getString("MEMBER_PORT")).thenReturn("3306");
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1:3306/foo_ds");
- return result;
- }
-
- @Test
- void assertLoadReplicaStatus() throws SQLException {
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1:3306/foo_ds");
- ReplicaDataSourceStatus actual = new MGRMySQLDatabaseDiscoveryProvider().loadReplicaStatus(dataSource);
- assertFalse(actual.isOnline());
- assertThat(actual.getReplicationDelayMilliseconds(), is(0L));
- }
-}
diff --git a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderTest.java b/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderTest.java
deleted file mode 100644
index 6f30d808556..00000000000
--- a/features/db-discovery/provider/mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderTest.java
+++ /dev/null
@@ -1,102 +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.dbdiscovery.mysql.type;
-
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.replica.DuplicatePrimaryDataSourceException;
-import org.apache.shardingsphere.dbdiscovery.mysql.exception.replica.PrimaryDataSourceNotFoundException;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class MySQLNormalReplicationDatabaseDiscoveryProviderTest {
-
- @Test
- void assertCheckEnvironmentNoPrimaryDataSource() {
- assertThrows(PrimaryDataSourceNotFoundException.class,
- () -> new MySQLNormalReplicationDatabaseDiscoveryProvider().checkEnvironment("foo_db", Collections.singleton(mockDataSourceForReplicationInstances("ON"))));
- }
-
- @Test
- void assertCheckEnvironmentHasSinglePrimaryDataSource() throws SQLException {
- new MySQLNormalReplicationDatabaseDiscoveryProvider().checkEnvironment("foo_db", Collections.singleton(mockDataSourceForReplicationInstances("OFF")));
- }
-
- @Test
- void assertCheckEnvironmentHasManyPrimaryDataSources() {
- assertThrows(DuplicatePrimaryDataSourceException.class,
- () -> new MySQLNormalReplicationDatabaseDiscoveryProvider().checkEnvironment("foo_db", Arrays.asList(mockDataSourceForReplicationInstances("OFF"),
- mockDataSourceForReplicationInstances("OFF"))));
- }
-
- @Test
- void assertIsPrimaryInstance() throws SQLException {
- assertTrue(new MySQLNormalReplicationDatabaseDiscoveryProvider().isPrimaryInstance(mockDataSourceForReplicationInstances("OFF")));
- }
-
- private DataSource mockDataSourceForReplicationInstances(final String readOnly) throws SQLException {
- ResultSet slaveHostsResultSet = mock(ResultSet.class);
- when(slaveHostsResultSet.next()).thenReturn(true, false);
- when(slaveHostsResultSet.getString("Host")).thenReturn("127.0.0.1");
- when(slaveHostsResultSet.getString("Port")).thenReturn("3306");
- ResultSet readonlyResultSet = mock(ResultSet.class);
- when(readonlyResultSet.next()).thenReturn(true, false);
- when(readonlyResultSet.getString("Value")).thenReturn(readOnly);
- Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
- when(connection.createStatement().executeQuery("SHOW SLAVE HOSTS")).thenReturn(slaveHostsResultSet);
- when(connection.getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1:3306/foo_ds");
- when(connection.createStatement().executeQuery("SHOW VARIABLES LIKE 'read_only'")).thenReturn(readonlyResultSet);
- return new MockedDataSource(connection);
- }
-
- @Test
- void assertLoadReplicaStatus() throws SQLException {
- DatabaseDiscoveryProvider provider = new MySQLNormalReplicationDatabaseDiscoveryProvider();
- provider.init(PropertiesBuilder.build(new Property("delay-milliseconds-threshold", "15000")));
- DataSource dataSource = mockDataSourceForReplicaStatus();
- ReplicaDataSourceStatus actual = provider.loadReplicaStatus(dataSource);
- assertTrue(actual.isOnline());
- assertThat(actual.getReplicationDelayMilliseconds(), is(10000L));
- }
-
- private DataSource mockDataSourceForReplicaStatus() throws SQLException {
- ResultSet resultSet = mock(ResultSet.class);
- when(resultSet.next()).thenReturn(true, false);
- when(resultSet.getLong("Seconds_Behind_Master")).thenReturn(10L);
- Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
- when(connection.createStatement().executeQuery("SHOW SLAVE STATUS")).thenReturn(resultSet);
- return new MockedDataSource(connection);
- }
-}
diff --git a/features/db-discovery/provider/opengauss/pom.xml b/features/db-discovery/provider/opengauss/pom.xml
deleted file mode 100644
index 37ca3ecf919..00000000000
--- a/features/db-discovery/provider/opengauss/pom.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-provider</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-opengauss</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
diff --git a/features/db-discovery/provider/opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProvider.java b/features/db-discovery/provider/opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProvider.java
deleted file mode 100644
index e7d76ae03c2..00000000000
--- a/features/db-discovery/provider/opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProvider.java
+++ /dev/null
@@ -1,84 +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.dbdiscovery.opengauss;
-
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collection;
-import java.util.Optional;
-import java.util.Properties;
-
-/**
- * Normal replication database discovery provider for openGauss.
- */
-public final class OpenGaussNormalReplicationDatabaseDiscoveryProvider implements DatabaseDiscoveryProvider {
-
- private static final String QUERY_DB_ROLE = "SELECT local_role,db_state FROM pg_stat_get_stream_replications()";
-
- private int minEnabledReplicas;
-
- @Override
- public void init(final Properties props) {
- minEnabledReplicas = Integer.parseInt(props.getProperty("min-enabled-replicas", "0"));
- }
-
- @Override
- public void checkEnvironment(final String databaseName, final Collection<DataSource> dataSources) {
- }
-
- @Override
- public boolean isPrimaryInstance(final DataSource dataSource) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(QUERY_DB_ROLE)) {
- return resultSet.next() && "Primary".equals(resultSet.getString("local_role")) && "Normal".equals(resultSet.getString("db_state"));
- }
- }
-
- @Override
- public ReplicaDataSourceStatus loadReplicaStatus(final DataSource replicaDataSource) throws SQLException {
- try (
- Connection connection = replicaDataSource.getConnection();
- Statement statement = connection.createStatement()) {
- return new ReplicaDataSourceStatus(isOnlineDataSource(statement), 0L);
- }
- }
-
- private boolean isOnlineDataSource(final Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery(QUERY_DB_ROLE)) {
- return resultSet.next() && resultSet.getString("local_role").equals("Standby") && resultSet.getString("db_state").equals("Normal");
- }
- }
-
- @Override
- public Optional<Integer> getMinEnabledReplicas() {
- return Optional.of(minEnabledReplicas);
- }
-
- @Override
- public String getType() {
- return "openGauss.NORMAL_REPLICATION";
- }
-}
diff --git a/features/db-discovery/provider/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider b/features/db-discovery/provider/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
deleted file mode 100644
index d68c592d063..00000000000
--- a/features/db-discovery/provider/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider
+++ /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.dbdiscovery.opengauss.OpenGaussNormalReplicationDatabaseDiscoveryProvider
diff --git a/features/db-discovery/provider/opengauss/src/test/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProviderTest.java b/features/db-discovery/provider/opengauss/src/test/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProviderTest.java
deleted file mode 100644
index 879218facf2..00000000000
--- a/features/db-discovery/provider/opengauss/src/test/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussNormalReplicationDatabaseDiscoveryProviderTest.java
+++ /dev/null
@@ -1,48 +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.dbdiscovery.opengauss;
-
-import org.junit.jupiter.api.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class OpenGaussNormalReplicationDatabaseDiscoveryProviderTest {
-
- @Test
- void assertIsPrimaryInstance() throws SQLException {
- assertTrue(new OpenGaussNormalReplicationDatabaseDiscoveryProvider().isPrimaryInstance(mockDatSource()));
- }
-
- private DataSource mockDatSource() throws SQLException {
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- ResultSet resultSet = mock(ResultSet.class);
- when(result.getConnection().createStatement().executeQuery("SELECT local_role,db_state FROM pg_stat_get_stream_replications()")).thenReturn(resultSet);
- when(resultSet.next()).thenReturn(true, false);
- when(resultSet.getString("local_role")).thenReturn("Primary");
- when(resultSet.getString("db_state")).thenReturn("Normal");
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:postgres://127.0.0.1:3306/foo_ds");
- return result;
- }
-}
diff --git a/features/db-discovery/provider/pom.xml b/features/db-discovery/provider/pom.xml
deleted file mode 100644
index 7542842c0a1..00000000000
--- a/features/db-discovery/provider/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery</artifactId>
- <version>5.3.3-SNAPSHOT</version>
- </parent>
- <artifactId>shardingsphere-db-discovery-provider</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <modules>
- <module>mysql</module>
- <module>opengauss</module>
- </modules>
-</project>
diff --git a/features/pom.xml b/features/pom.xml
index 1aa90933bfe..a797b6ee1ef 100644
--- a/features/pom.xml
+++ b/features/pom.xml
@@ -31,7 +31,6 @@
<modules>
<module>sharding</module>
<module>readwrite-splitting</module>
- <module>db-discovery</module>
<module>encrypt</module>
<module>shadow</module>
<module>mask</module>
diff --git a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/rule/ReadwriteSplittingDataSourceRuleConfiguration.java b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/rule/ReadwriteSplittingDataSourceRuleConfiguration.java
index d5472ff2038..063eeced37a 100644
--- a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/rule/ReadwriteSplittingDataSourceRuleConfiguration.java
+++ b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/rule/ReadwriteSplittingDataSourceRuleConfiguration.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.readwritesplitting.api.rule;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
@@ -34,14 +33,11 @@ public final class ReadwriteSplittingDataSourceRuleConfiguration {
private final StaticReadwriteSplittingStrategyConfiguration staticStrategy;
- private final DynamicReadwriteSplittingStrategyConfiguration dynamicStrategy;
-
private final TransactionalReadQueryStrategy transactionalReadQueryStrategy;
private final String loadBalancerName;
- public ReadwriteSplittingDataSourceRuleConfiguration(final String name, final StaticReadwriteSplittingStrategyConfiguration staticStrategy,
- final DynamicReadwriteSplittingStrategyConfiguration dynamicStrategy, final String loadBalancerName) {
- this(name, staticStrategy, dynamicStrategy, TransactionalReadQueryStrategy.DYNAMIC, loadBalancerName);
+ public ReadwriteSplittingDataSourceRuleConfiguration(final String name, final StaticReadwriteSplittingStrategyConfiguration staticStrategy, final String loadBalancerName) {
+ this(name, staticStrategy, TransactionalReadQueryStrategy.DYNAMIC, loadBalancerName);
}
}
diff --git a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/strategy/DynamicReadwriteSplittingStrategyConfiguration.java b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/strategy/DynamicReadwriteSplittingStrategyConfiguration.java
deleted file mode 100644
index 6aa2d1c1177..00000000000
--- a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/api/strategy/DynamicReadwriteSplittingStrategyConfiguration.java
+++ /dev/null
@@ -1,31 +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.readwritesplitting.api.strategy;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Dynamic Readwrite-splitting strategy configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DynamicReadwriteSplittingStrategyConfiguration {
-
- private final String autoAwareDataSourceName;
-}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
index 6bb34141daf..fed41cb1f3e 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
@@ -22,14 +22,12 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
import org.apache.shardingsphere.readwritesplitting.exception.algorithm.MissingRequiredReadDatabaseWeightException;
@@ -37,19 +35,15 @@ import org.apache.shardingsphere.readwritesplitting.exception.checker.DataSource
import org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.InvalidWeightLoadBalancerConfigurationException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.LoadBalancerAlgorithmNotFoundException;
-import org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredAutoAwareDataSourceNameException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredDataSourceNameException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredReadDataSourceNamesException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredWriteDataSourceNameException;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import javax.sql.DataSource;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -72,9 +66,8 @@ public final class ReadwriteSplittingRuleConfigurationChecker implements RuleCon
Collection<String> addedReadDataSourceNames = new HashSet<>();
for (ReadwriteSplittingDataSourceRuleConfiguration each : configs) {
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(each.getName()), () -> new MissingRequiredDataSourceNameException(databaseName));
- Preconditions.checkState(null != each.getStaticStrategy() || null != each.getDynamicStrategy(), "No available readwrite-splitting rule configuration in database `%s`.", databaseName);
- Optional.ofNullable(each.getStaticStrategy()).ifPresent(optional -> checkStaticStrategy(databaseName, dataSourceMap, addedWriteDataSourceNames, addedReadDataSourceNames, optional, rules));
- Optional.ofNullable(each.getDynamicStrategy()).ifPresent(optional -> checkDynamicStrategy(databaseName, rules, optional));
+ Preconditions.checkState(null != each.getStaticStrategy(), "No available readwrite-splitting rule configuration in database `%s`.", databaseName);
+ Optional.of(each.getStaticStrategy()).ifPresent(optional -> checkStaticStrategy(databaseName, dataSourceMap, addedWriteDataSourceNames, addedReadDataSourceNames, optional, rules));
}
}
@@ -117,12 +110,6 @@ public final class ReadwriteSplittingRuleConfigurationChecker implements RuleCon
}
}
- private void checkDynamicStrategy(final String databaseName, final Collection<ShardingSphereRule> rules, final DynamicReadwriteSplittingStrategyConfiguration dynamicStrategy) {
- ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(dynamicStrategy.getAutoAwareDataSourceName()), () -> new MissingRequiredAutoAwareDataSourceNameException(databaseName));
- Optional<ShardingSphereRule> dynamicDataSourceStrategy = rules.stream().filter(each -> each instanceof DynamicDataSourceContainedRule).findFirst();
- Preconditions.checkArgument(dynamicDataSourceStrategy.isPresent(), "Dynamic data source strategy is required");
- }
-
private void checkLoadBalancerDataSourceName(final String databaseName, final Collection<ReadwriteSplittingDataSourceRuleConfiguration> configs,
final Map<String, ReadQueryLoadBalanceAlgorithm> loadBalancers, final Collection<ShardingSphereRule> rules) {
for (ReadwriteSplittingDataSourceRuleConfiguration each : configs) {
@@ -134,27 +121,13 @@ public final class ReadwriteSplittingRuleConfigurationChecker implements RuleCon
if (loadBalancer instanceof WeightReadQueryLoadBalanceAlgorithm) {
ShardingSpherePreconditions.checkState(!((WeightReadQueryLoadBalanceAlgorithm) loadBalancer).getDataSourceNames().isEmpty(),
() -> new MissingRequiredReadDatabaseWeightException(loadBalancer.getType(), String.format("Read data source weight config are required in database `%s`", databaseName)));
- Collection<String> dataSourceNames = getDataSourceNames(each, rules);
+ Collection<String> dataSourceNames = each.getStaticStrategy().getReadDataSourceNames();
((WeightReadQueryLoadBalanceAlgorithm) loadBalancer).getDataSourceNames().forEach(dataSourceName -> ShardingSpherePreconditions.checkState(dataSourceNames.contains(dataSourceName),
() -> new InvalidWeightLoadBalancerConfigurationException(databaseName)));
}
}
}
- private List<String> getDataSourceNames(final ReadwriteSplittingDataSourceRuleConfiguration config, final Collection<ShardingSphereRule> rules) {
- if (null != config.getStaticStrategy()) {
- return config.getStaticStrategy().getReadDataSourceNames();
- }
- Optional<ShardingSphereRule> dynamicDataSourceStrategy = rules.stream().filter(each -> each instanceof DynamicDataSourceContainedRule).findFirst();
- if (!dynamicDataSourceStrategy.isPresent()) {
- return Collections.emptyList();
- }
- DynamicDataSourceContainedRule dynamicDataSourceRule = (DynamicDataSourceContainedRule) dynamicDataSourceStrategy.get();
- List<String> result = new ArrayList<>(dynamicDataSourceRule.getReplicaDataSourceNames(config.getDynamicStrategy().getAutoAwareDataSourceName()));
- result.add(dynamicDataSourceRule.getPrimaryDataSourceName(config.getDynamicStrategy().getAutoAwareDataSourceName()));
- return result;
- }
-
private Map<String, ReadQueryLoadBalanceAlgorithm> getLoadBalancer(final ReadwriteSplittingRuleConfiguration config) {
Map<String, ReadQueryLoadBalanceAlgorithm> result = new LinkedHashMap<>(config.getLoadBalancers().size(), 1);
config.getLoadBalancers().forEach((key, value) -> result.put(key, TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, value.getType(), value.getProps())));
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredAutoAwareDataSourceNameException.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredAutoAwareDataSourceNameException.java
deleted file mode 100644
index 7298a5c4763..00000000000
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredAutoAwareDataSourceNameException.java
+++ /dev/null
@@ -1,33 +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.readwritesplitting.exception.checker;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
-
-/**
- * Missing required auto aware data source name exception.
- */
-public final class MissingRequiredAutoAwareDataSourceNameException extends ReadwriteSplittingSQLException {
-
- private static final long serialVersionUID = -7921103941300062641L;
-
- public MissingRequiredAutoAwareDataSourceNameException(final String databaseName) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 95, "Auto aware data source name is required in database `%s`.", databaseName);
- }
-}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilter.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilter.java
index e1f18eb558e..fcec1cda1ef 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilter.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilter.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.readwritesplitting.route.filter;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
-import org.apache.shardingsphere.readwritesplitting.strategy.type.DynamicReadwriteSplittingStrategy;
import java.util.LinkedList;
import java.util.List;
@@ -30,9 +29,6 @@ public final class DisabledReadDataSourcesFilter implements ReadDataSourcesFilte
@Override
public List<String> filter(final ReadwriteSplittingDataSourceRule rule, final List<String> toBeFilteredReadDataSources) {
- if (rule.getReadwriteSplittingStrategy() instanceof DynamicReadwriteSplittingStrategy || rule.getDisabledDataSourceNames().isEmpty()) {
- return toBeFilteredReadDataSources;
- }
List<String> result = new LinkedList<>(toBeFilteredReadDataSources);
result.removeIf(rule.getDisabledDataSourceNames()::contains);
return result;
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
index 93bea4d656a..169d67e75f9 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
@@ -18,12 +18,12 @@
package org.apache.shardingsphere.readwritesplitting.rule;
import lombok.Getter;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingStrategy;
-import org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingStrategyFactory;
+import org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
import java.util.Collection;
import java.util.HashSet;
@@ -45,11 +45,15 @@ public final class ReadwriteSplittingDataSourceRule {
private final Collection<String> disabledDataSourceNames = new HashSet<>();
public ReadwriteSplittingDataSourceRule(final ReadwriteSplittingDataSourceRuleConfiguration config, final TransactionalReadQueryStrategy transactionalReadQueryStrategy,
- final ReadQueryLoadBalanceAlgorithm loadBalancer, final Collection<ShardingSphereRule> builtRules) {
+ final ReadQueryLoadBalanceAlgorithm loadBalancer) {
name = config.getName();
this.transactionalReadQueryStrategy = transactionalReadQueryStrategy;
this.loadBalancer = loadBalancer;
- readwriteSplittingStrategy = ReadwriteSplittingStrategyFactory.newInstance(config, builtRules);
+ readwriteSplittingStrategy = createStaticReadwriteSplittingStrategy(config.getStaticStrategy());
+ }
+
+ private StaticReadwriteSplittingStrategy createStaticReadwriteSplittingStrategy(final StaticReadwriteSplittingStrategyConfiguration staticConfig) {
+ return new StaticReadwriteSplittingStrategy(staticConfig.getWriteDataSourceName(), staticConfig.getReadDataSourceNames());
}
/**
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index 1e29e149e72..e3428877055 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -41,11 +41,9 @@ import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChanged
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.exception.rule.InvalidInlineExpressionDataSourceNameException;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-import org.apache.shardingsphere.readwritesplitting.strategy.type.DynamicReadwriteSplittingStrategy;
import org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
import java.util.Collection;
@@ -95,9 +93,7 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
final Collection<ShardingSphereRule> builtRules) {
ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = loadBalancers.getOrDefault(
config.getName() + "." + config.getLoadBalancerName(), TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, null));
- return null == config.getStaticStrategy()
- ? createDynamicReadwriteSplittingDataSourceRules(config, builtRules, loadBalanceAlgorithm)
- : createStaticReadwriteSplittingDataSourceRules(config, builtRules, loadBalanceAlgorithm);
+ return createStaticReadwriteSplittingDataSourceRules(config, builtRules, loadBalanceAlgorithm);
}
private Map<String, ReadwriteSplittingDataSourceRule> createStaticReadwriteSplittingDataSourceRules(final ReadwriteSplittingDataSourceRuleConfiguration config,
@@ -115,7 +111,7 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
for (int i = 0; i < inlineReadwriteDataSourceNames.size(); i++) {
ReadwriteSplittingDataSourceRuleConfiguration staticConfig = createStaticDataSourceRuleConfiguration(
config, i, inlineReadwriteDataSourceNames, inlineWriteDatasourceNames, inlineReadDatasourceNames);
- result.put(inlineReadwriteDataSourceNames.get(i), new ReadwriteSplittingDataSourceRule(staticConfig, config.getTransactionalReadQueryStrategy(), loadBalanceAlgorithm, builtRules));
+ result.put(inlineReadwriteDataSourceNames.get(i), new ReadwriteSplittingDataSourceRule(staticConfig, config.getTransactionalReadQueryStrategy(), loadBalanceAlgorithm));
}
return result;
}
@@ -128,27 +124,6 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
new StaticReadwriteSplittingStrategyConfiguration(writeDatasourceNames.get(index), readDataSourceNames), null, config.getLoadBalancerName());
}
- private Map<String, ReadwriteSplittingDataSourceRule> createDynamicReadwriteSplittingDataSourceRules(final ReadwriteSplittingDataSourceRuleConfiguration config,
- final Collection<ShardingSphereRule> builtRules,
- final ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm) {
- Map<String, ReadwriteSplittingDataSourceRule> result = new LinkedHashMap<>();
- List<String> inlineReadwriteDataSourceNames = new InlineExpressionParser(config.getName()).splitAndEvaluate();
- List<String> inlineAutoAwareDataSourceNames = new InlineExpressionParser(config.getDynamicStrategy().getAutoAwareDataSourceName()).splitAndEvaluate();
- ShardingSpherePreconditions.checkState(inlineAutoAwareDataSourceNames.size() == inlineReadwriteDataSourceNames.size(),
- () -> new InvalidInlineExpressionDataSourceNameException("Inline expression auto aware data source names size error."));
- for (int i = 0; i < inlineReadwriteDataSourceNames.size(); i++) {
- ReadwriteSplittingDataSourceRuleConfiguration dynamicConfig = createDynamicDataSourceRuleConfiguration(config, i, inlineReadwriteDataSourceNames, inlineAutoAwareDataSourceNames);
- result.put(inlineReadwriteDataSourceNames.get(i), new ReadwriteSplittingDataSourceRule(dynamicConfig, config.getTransactionalReadQueryStrategy(), loadBalanceAlgorithm, builtRules));
- }
- return result;
- }
-
- private ReadwriteSplittingDataSourceRuleConfiguration createDynamicDataSourceRuleConfiguration(final ReadwriteSplittingDataSourceRuleConfiguration config, final int index,
- final List<String> readwriteDataSourceNames, final List<String> autoAwareDataSourceNames) {
- return new ReadwriteSplittingDataSourceRuleConfiguration(readwriteDataSourceNames.get(index), null,
- new DynamicReadwriteSplittingStrategyConfiguration(autoAwareDataSourceNames.get(index)), config.getLoadBalancerName());
- }
-
/**
* Get single data source rule.
*
@@ -193,9 +168,6 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
}
private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceRule rule) {
- if (rule.getReadwriteSplittingStrategy() instanceof DynamicReadwriteSplittingStrategy) {
- return;
- }
rule.getReadwriteSplittingStrategy().getReadDataSources()
.forEach(each -> instanceContext.getEventBusContext().post(new StorageNodeDataSourceDeletedEvent(new QualifiedDatabase(databaseName, rule.getName(), each))));
}
@@ -210,25 +182,10 @@ public final class ReadwriteSplittingRule implements DatabaseRule, DataSourceCon
@Override
public Map<String, Object> getExportData() {
Map<String, Object> result = new HashMap<>(2, 1);
- result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
return result;
}
- private Map<String, Map<String, String>> exportDynamicDataSources() {
- Map<String, Map<String, String>> result = new LinkedHashMap<>(dataSourceRules.size(), 1);
- for (ReadwriteSplittingDataSourceRule each : dataSourceRules.values()) {
- if (each.getReadwriteSplittingStrategy() instanceof DynamicReadwriteSplittingStrategy) {
- Map<String, String> exportedDataSources = new LinkedHashMap<>(2, 1);
- exportedDataSources.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, ((DynamicReadwriteSplittingStrategy) each.getReadwriteSplittingStrategy()).getAutoAwareDataSourceName());
- exportedDataSources.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, each.getWriteDataSource());
- exportedDataSources.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, String.join(",", each.getReadwriteSplittingStrategy().getReadDataSources()));
- result.put(each.getName(), exportedDataSources);
- }
- }
- return result;
- }
-
private Map<String, Map<String, String>> exportStaticDataSources() {
Map<String, Map<String, String>> result = new LinkedHashMap<>(dataSourceRules.size(), 1);
for (ReadwriteSplittingDataSourceRule each : dataSourceRules.values()) {
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategyFactory.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategyFactory.java
deleted file mode 100644
index 3a670e36033..00000000000
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategyFactory.java
+++ /dev/null
@@ -1,61 +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.readwritesplitting.strategy;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
-import org.apache.shardingsphere.readwritesplitting.strategy.type.DynamicReadwriteSplittingStrategy;
-import org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Readwrite-splitting strategy factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReadwriteSplittingStrategyFactory {
-
- /**
- * Create new instance of readwrite-splitting strategy.
- *
- * @param readwriteSplittingConfig readwrite-splitting rule config
- * @param builtRules built rules
- * @return created instance
- */
- public static ReadwriteSplittingStrategy newInstance(final ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingConfig, final Collection<ShardingSphereRule> builtRules) {
- return null == readwriteSplittingConfig.getStaticStrategy()
- ? createDynamicReadwriteSplittingStrategy(readwriteSplittingConfig.getDynamicStrategy(), builtRules)
- : createStaticReadwriteSplittingStrategy(readwriteSplittingConfig.getStaticStrategy());
- }
-
- private static StaticReadwriteSplittingStrategy createStaticReadwriteSplittingStrategy(final StaticReadwriteSplittingStrategyConfiguration staticConfig) {
- return new StaticReadwriteSplittingStrategy(staticConfig.getWriteDataSourceName(), staticConfig.getReadDataSourceNames());
- }
-
- private static DynamicReadwriteSplittingStrategy createDynamicReadwriteSplittingStrategy(final DynamicReadwriteSplittingStrategyConfiguration dynamicConfig,
- final Collection<ShardingSphereRule> builtRules) {
- Optional<ShardingSphereRule> dynamicDataSourceStrategy = builtRules.stream().filter(each -> each instanceof DynamicDataSourceContainedRule).findFirst();
- return new DynamicReadwriteSplittingStrategy(dynamicConfig.getAutoAwareDataSourceName(), (DynamicDataSourceContainedRule) dynamicDataSourceStrategy.get());
- }
-}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
deleted file mode 100644
index bf0be192d26..00000000000
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
+++ /dev/null
@@ -1,57 +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.readwritesplitting.strategy.type;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingStrategy;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Dynamic readwrite-splitting strategy.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DynamicReadwriteSplittingStrategy implements ReadwriteSplittingStrategy {
-
- private final String autoAwareDataSourceName;
-
- private final DynamicDataSourceContainedRule dynamicDataSource;
-
- @Override
- public String getWriteDataSource() {
- return dynamicDataSource.getPrimaryDataSourceName(autoAwareDataSourceName);
- }
-
- @Override
- public List<String> getReadDataSources() {
- return new ArrayList<>(dynamicDataSource.getReplicaDataSourceNames(autoAwareDataSourceName));
- }
-
- @Override
- public Collection<DataSourceRoleInfo> getAllDataSources() {
- return Collections.singletonList(new DataSourceRoleInfo(autoAwareDataSourceName, DataSourceRole.PRIMARY));
- }
-}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
index fb9b350db99..496bca73281 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.readwritesplitting.api.transaction.Transactiona
import org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
import org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.yaml.swapper.strategy.YamlDynamicReadwriteSplittingStrategyConfigurationSwapper;
import org.apache.shardingsphere.readwritesplitting.yaml.swapper.strategy.YamlStaticReadwriteSplittingStrategyConfigurationSwapper;
import java.util.Collection;
@@ -46,8 +45,6 @@ public final class YamlReadwriteSplittingRuleConfigurationSwapper
private final YamlStaticReadwriteSplittingStrategyConfigurationSwapper staticConfigSwapper = new YamlStaticReadwriteSplittingStrategyConfigurationSwapper();
- private final YamlDynamicReadwriteSplittingStrategyConfigurationSwapper dynamicConfigSwapper = new YamlDynamicReadwriteSplittingStrategyConfigurationSwapper();
-
private final YamlAlgorithmConfigurationSwapper algorithmSwapper = new YamlAlgorithmConfigurationSwapper();
@Override
@@ -63,12 +60,7 @@ public final class YamlReadwriteSplittingRuleConfigurationSwapper
private YamlReadwriteSplittingDataSourceRuleConfiguration swapToYamlConfiguration(final ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig) {
YamlReadwriteSplittingDataSourceRuleConfiguration result = new YamlReadwriteSplittingDataSourceRuleConfiguration();
- if (null != dataSourceRuleConfig.getStaticStrategy()) {
- result.setStaticStrategy(staticConfigSwapper.swapToYamlConfiguration(dataSourceRuleConfig.getStaticStrategy()));
- }
- if (null != dataSourceRuleConfig.getDynamicStrategy()) {
- result.setDynamicStrategy(dynamicConfigSwapper.swapToYamlConfiguration(dataSourceRuleConfig.getDynamicStrategy()));
- }
+ result.setStaticStrategy(staticConfigSwapper.swapToYamlConfiguration(dataSourceRuleConfig.getStaticStrategy()));
result.setTransactionalReadQueryStrategy(dataSourceRuleConfig.getTransactionalReadQueryStrategy().name());
result.setLoadBalancerName(dataSourceRuleConfig.getLoadBalancerName());
return result;
@@ -89,7 +81,6 @@ public final class YamlReadwriteSplittingRuleConfigurationSwapper
private ReadwriteSplittingDataSourceRuleConfiguration swapToObject(final String name, final YamlReadwriteSplittingDataSourceRuleConfiguration yamlDataSourceRuleConfig) {
return new ReadwriteSplittingDataSourceRuleConfiguration(name, staticConfigSwapper.swapToObject(yamlDataSourceRuleConfig.getStaticStrategy()),
- dynamicConfigSwapper.swapToObject(yamlDataSourceRuleConfig.getDynamicStrategy()),
getTransactionalReadQueryStrategy(yamlDataSourceRuleConfig), yamlDataSourceRuleConfig.getLoadBalancerName());
}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/strategy/YamlDynamicReadwriteSplittingStrategyConfigurationSwapper.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/strategy/YamlDynamicReadwriteSplittingStrategyConfigurationSwapper.java
deleted file mode 100644
index 9d84f629ebd..00000000000
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/strategy/YamlDynamicReadwriteSplittingStrategyConfigurationSwapper.java
+++ /dev/null
@@ -1,42 +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.readwritesplitting.yaml.swapper.strategy;
-
-import org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
-import org.apache.shardingsphere.readwritesplitting.yaml.config.strategy.YamlDynamicReadwriteSplittingStrategyConfiguration;
-
-/**
- * YAML dynamic readwrite-splitting strategy configuration swapper.
- */
-public final class YamlDynamicReadwriteSplittingStrategyConfigurationSwapper
- implements
- YamlConfigurationSwapper<YamlDynamicReadwriteSplittingStrategyConfiguration, DynamicReadwriteSplittingStrategyConfiguration> {
-
- @Override
- public YamlDynamicReadwriteSplittingStrategyConfiguration swapToYamlConfiguration(final DynamicReadwriteSplittingStrategyConfiguration config) {
- YamlDynamicReadwriteSplittingStrategyConfiguration result = new YamlDynamicReadwriteSplittingStrategyConfiguration();
- result.setAutoAwareDataSourceName(config.getAutoAwareDataSourceName());
- return result;
- }
-
- @Override
- public DynamicReadwriteSplittingStrategyConfiguration swapToObject(final YamlDynamicReadwriteSplittingStrategyConfiguration config) {
- return null == config ? null : new DynamicReadwriteSplittingStrategyConfiguration(config.getAutoAwareDataSourceName());
- }
-}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
index cd632fd2bb9..c2110a3717d 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
@@ -20,11 +20,9 @@ package org.apache.shardingsphere.readwritesplitting.checker;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPILoader;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameExistedException;
import org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
@@ -47,23 +45,6 @@ import static org.mockito.Mockito.when;
class ReadwriteSplittingRuleConfigurationCheckerTest {
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Test
- void assertValidCheck() {
- ReadwriteSplittingRuleConfiguration config = createValidConfiguration();
- RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
- checker.check("test", config, Collections.emptyMap(), Collections.singleton(mock(DynamicDataSourceContainedRule.class)));
- }
-
- private ReadwriteSplittingRuleConfiguration createValidConfiguration() {
- ReadwriteSplittingRuleConfiguration result = mock(ReadwriteSplittingRuleConfiguration.class);
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig = mock(ReadwriteSplittingDataSourceRuleConfiguration.class);
- when(dataSourceConfig.getName()).thenReturn("readwrite_ds");
- when(dataSourceConfig.getDynamicStrategy()).thenReturn(new DynamicReadwriteSplittingStrategyConfiguration("ds0"));
- when(result.getDataSources()).thenReturn(Collections.singletonList(dataSourceConfig));
- return result;
- }
-
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertInvalidCheck() {
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilterTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilterTest.java
deleted file mode 100644
index c67bfad23ef..00000000000
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/filter/DisabledReadDataSourcesFilterTest.java
+++ /dev/null
@@ -1,75 +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.readwritesplitting.route.filter;
-
-import org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReadQueryLoadBalanceAlgorithm;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
-import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class DisabledReadDataSourcesFilterTest {
-
- private ReadwriteSplittingDataSourceRule rule;
-
- @BeforeEach
- void setUp() {
- rule = new ReadwriteSplittingDataSourceRule(
- new ReadwriteSplittingDataSourceRuleConfiguration("test_pr",
- new StaticReadwriteSplittingStrategyConfiguration("write_ds", Arrays.asList("read_ds_0", "read_ds_1")), null, null),
- TransactionalReadQueryStrategy.DYNAMIC, new RandomReadQueryLoadBalanceAlgorithm(), Collections.emptyList());
- }
-
- @Test
- void assertGetReadDataSourceNamesWithoutDisabledDataSourceNames() {
- assertThat(new DisabledReadDataSourcesFilter().filter(rule, Arrays.asList("read_ds_0", "read_ds_1")), is(Arrays.asList("read_ds_0", "read_ds_1")));
- }
-
- @Test
- void assertGetReadDataSourceNamesWithDisabledDataSourceNames() {
- rule.updateDisabledDataSourceNames("read_ds_0", true);
- assertThat(new DisabledReadDataSourcesFilter().filter(rule, Arrays.asList("read_ds_0", "read_ds_1")), is(Collections.singletonList("read_ds_1")));
- }
-
- @Test
- void assertUpdateDisabledDataSourceNamesForDisabled() {
- rule.updateDisabledDataSourceNames("read_ds_0", true);
- assertThat(new DisabledReadDataSourcesFilter().filter(rule, Arrays.asList("read_ds_0", "read_ds_1")), is(Collections.singletonList("read_ds_1")));
- }
-
- @Test
- void assertUpdateDisabledDataSourceNamesForEnabled() {
- rule.updateDisabledDataSourceNames("read_ds_0", true);
- rule.updateDisabledDataSourceNames("read_ds_0", false);
- assertThat(new DisabledReadDataSourcesFilter().filter(rule, Arrays.asList("read_ds_0", "read_ds_1")), is(Arrays.asList("read_ds_0", "read_ds_1")));
- }
-
- @Test
- void assertGetEnabledReplicaDataSources() {
- rule.updateDisabledDataSourceNames("read_ds_0", true);
- assertThat(new DisabledReadDataSourcesFilter().filter(rule, Arrays.asList("read_ds_0", "read_ds_1")), is(Collections.singletonList("read_ds_1")));
- }
-}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadWriteSplittingDataSourceRuleConfigurationTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadWriteSplittingDataSourceRuleConfigurationTest.java
index 65d34718726..03f0202c9d9 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadWriteSplittingDataSourceRuleConfigurationTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadWriteSplittingDataSourceRuleConfigurationTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.readwritesplitting.rule;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -33,14 +32,10 @@ class ReadWriteSplittingDataSourceRuleConfigurationTest {
private ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingDataSourceRuleConfig;
- private ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingDataSourceRuleConfigDynamic;
-
@BeforeEach
void setup() {
readwriteSplittingDataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("ds",
new StaticReadwriteSplittingStrategyConfiguration("write_ds", Arrays.asList("read_ds_0", "read_ds_1")), null, "");
- readwriteSplittingDataSourceRuleConfigDynamic = new ReadwriteSplittingDataSourceRuleConfiguration("ds", null,
- new DynamicReadwriteSplittingStrategyConfiguration("readwrite_ds"), "");
}
@Test
@@ -50,11 +45,4 @@ class ReadWriteSplittingDataSourceRuleConfigurationTest {
assertThat(actual.getWriteDataSourceName(), is("write_ds"));
assertThat(actual.getReadDataSourceNames(), is(Arrays.asList("read_ds_0", "read_ds_1")));
}
-
- @Test
- void assertDynamicReadWriteSplittingConfig() {
- assertNotNull(readwriteSplittingDataSourceRuleConfigDynamic.getDynamicStrategy());
- DynamicReadwriteSplittingStrategyConfiguration actual = readwriteSplittingDataSourceRuleConfigDynamic.getDynamicStrategy();
- assertThat(actual.getAutoAwareDataSourceName(), is("readwrite_ds"));
- }
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
index fa2e8a0008f..1747b17a53c 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.readwritesplitting.api.transaction.Transactiona
import org.junit.jupiter.api.Test;
import java.util.Arrays;
-import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -35,8 +34,8 @@ class ReadwriteSplittingDataSourceRuleTest {
void assertGetWriteDataSource() {
ReadwriteSplittingDataSourceRule readwriteSplittingDataSourceRule = new ReadwriteSplittingDataSourceRule(
new ReadwriteSplittingDataSourceRuleConfiguration("test_pr",
- new StaticReadwriteSplittingStrategyConfiguration("write_ds", Arrays.asList("read_ds_0", "read_ds_1")), null, null),
- TransactionalReadQueryStrategy.DYNAMIC, new RandomReadQueryLoadBalanceAlgorithm(), Collections.emptyList());
+ new StaticReadwriteSplittingStrategyConfiguration("write_ds", Arrays.asList("read_ds_0", "read_ds_1")), TransactionalReadQueryStrategy.DYNAMIC, null),
+ TransactionalReadQueryStrategy.DYNAMIC, new RandomReadQueryLoadBalanceAlgorithm());
String writeDataSourceName = readwriteSplittingDataSourceRule.getWriteDataSource();
assertThat(writeDataSourceName, is("write_ds"));
}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
deleted file mode 100644
index 20e7515421a..00000000000
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
+++ /dev/null
@@ -1,39 +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.readwritesplitting.strategy.type;
-
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
-import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-
-class DynamicReadwriteSplittingStrategyTest {
-
- @Test
- void assertGetDataSourceMapper() {
- DynamicReadwriteSplittingStrategy dynamicReadwriteSplittingStrategy = new DynamicReadwriteSplittingStrategy("database_discovery_ds",
- mock(DynamicDataSourceContainedRule.class));
- assertThat(dynamicReadwriteSplittingStrategy.getAllDataSources(), is(Collections.singletonList(new DataSourceRoleInfo("database_discovery_ds", DataSourceRole.PRIMARY))));
- }
-}
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
index d32c25ee3d6..5ea3c89ae54 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/swapper/YamlReadwriteSplittingRuleConfigurationSwapperTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigur
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
import org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.yaml.config.strategy.YamlStaticReadwriteSplittingStrategyConfiguration;
@@ -45,7 +46,7 @@ class YamlReadwriteSplittingRuleConfigurationSwapperTest {
void assertSwapToYamlWithLoadBalanceAlgorithm() {
ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig =
new ReadwriteSplittingDataSourceRuleConfiguration("ds",
- new StaticReadwriteSplittingStrategyConfiguration("write", Collections.singletonList("read")), null, "roundRobin");
+ new StaticReadwriteSplittingStrategyConfiguration("write", Collections.singletonList("read")), TransactionalReadQueryStrategy.FIXED, "roundRobin");
YamlReadwriteSplittingRuleConfiguration actual = getYamlReadwriteSplittingRuleConfigurationSwapper().swapToYamlConfiguration(new ReadwriteSplittingRuleConfiguration(
Collections.singleton(dataSourceConfig), Collections.singletonMap("roundRobin", new AlgorithmConfiguration("ROUND_ROBIN", new Properties()))));
assertNotNull(actual.getDataSources().get("ds").getStaticStrategy());
@@ -57,7 +58,7 @@ class YamlReadwriteSplittingRuleConfigurationSwapperTest {
@Test
void assertSwapToYamlWithoutLoadBalanceAlgorithm() {
ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig = new ReadwriteSplittingDataSourceRuleConfiguration("ds",
- new StaticReadwriteSplittingStrategyConfiguration("write", Collections.singletonList("read")), null, null);
+ new StaticReadwriteSplittingStrategyConfiguration("write", Collections.singletonList("read")), TransactionalReadQueryStrategy.FIXED, null);
YamlReadwriteSplittingRuleConfiguration actual = getYamlReadwriteSplittingRuleConfigurationSwapper().swapToYamlConfiguration(
new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceConfig), Collections.emptyMap()));
assertNotNull(actual.getDataSources().get("ds").getStaticStrategy());
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
index d1a82546d0e..23c94b6eb80 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
@@ -49,22 +48,20 @@ public final class ReadwriteSplittingRuleStatementConverter {
Map<String, AlgorithmConfiguration> loadBalancers = new HashMap<>(ruleSegments.size(), 1);
for (ReadwriteSplittingRuleSegment each : ruleSegments) {
if (null == each.getLoadBalancer()) {
- dataSources.add(createDataSourceRuleConfiguration(each, null, each.isAutoAware()));
+ dataSources.add(createDataSourceRuleConfiguration(each, null));
} else {
String loadBalancerName = getLoadBalancerName(each.getName(), each.getLoadBalancer().getName());
loadBalancers.put(loadBalancerName, createLoadBalancer(each));
- dataSources.add(createDataSourceRuleConfiguration(each, loadBalancerName, each.isAutoAware()));
+ dataSources.add(createDataSourceRuleConfiguration(each, loadBalancerName));
}
}
return new ReadwriteSplittingRuleConfiguration(dataSources, loadBalancers);
}
private static ReadwriteSplittingDataSourceRuleConfiguration createDataSourceRuleConfiguration(final ReadwriteSplittingRuleSegment segment,
- final String loadBalancerName, final boolean isAutoAware) {
- return isAutoAware ? new ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(), null,
- new DynamicReadwriteSplittingStrategyConfiguration(segment.getAutoAwareResource()), loadBalancerName)
- : new ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(),
- new StaticReadwriteSplittingStrategyConfiguration(segment.getWriteDataSource(), new ArrayList<>(segment.getReadDataSources())), null, loadBalancerName);
+ final String loadBalancerName) {
+ return new ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(),
+ new StaticReadwriteSplittingStrategyConfiguration(segment.getWriteDataSource(), new ArrayList<>(segment.getReadDataSources())), null, loadBalancerName);
}
private static AlgorithmConfiguration createLoadBalancer(final ReadwriteSplittingRuleSegment ruleSegment) {
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
index f017527711e..d641aae13aa 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
@@ -42,8 +42,6 @@ import java.util.Optional;
*/
public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<ShowReadwriteSplittingRulesStatement> {
- private Map<String, Map<String, String>> exportableAutoAwareDataSource = Collections.emptyMap();
-
private Map<String, Map<String, String>> exportableDataSourceMap = Collections.emptyMap();
@Override
@@ -60,7 +58,6 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
@SuppressWarnings("unchecked")
private void buildExportableMap(final ReadwriteSplittingRule rule) {
Map<String, Object> exportedData = rule.getExportData();
- exportableAutoAwareDataSource = (Map<String, Map<String, String>>) exportedData.get(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE);
exportableDataSourceMap = (Map<String, Map<String, String>>) exportedData.get(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE);
}
@@ -77,10 +74,9 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
private LocalDataQueryResultRow buildDataItem(final ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig, final Map<String, AlgorithmConfiguration> loadBalancers) {
String name = dataSourceRuleConfig.getName();
- Map<String, String> exportDataSources = null == dataSourceRuleConfig.getDynamicStrategy() ? exportableDataSourceMap.get(name) : exportableAutoAwareDataSource.get(name);
+ Map<String, String> exportDataSources = exportableDataSourceMap.get(name);
Optional<AlgorithmConfiguration> loadBalancer = Optional.ofNullable(loadBalancers.get(dataSourceRuleConfig.getLoadBalancerName()));
return new LocalDataQueryResultRow(name,
- getAutoAwareDataSourceName(dataSourceRuleConfig),
getWriteDataSourceName(dataSourceRuleConfig, exportDataSources),
getReadDataSourceNames(dataSourceRuleConfig, exportDataSources),
loadBalancer.map(AlgorithmConfiguration::getType).orElse(""),
@@ -92,10 +88,6 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
return null == loadBalancers ? Collections.emptyMap() : loadBalancers;
}
- private String getAutoAwareDataSourceName(final ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig) {
- return null == dataSourceRuleConfig.getDynamicStrategy() ? "" : dataSourceRuleConfig.getDynamicStrategy().getAutoAwareDataSourceName();
- }
-
private String getWriteDataSourceName(final ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig, final Map<String, String> exportDataSources) {
return null == exportDataSources ? dataSourceRuleConfig.getStaticStrategy().getWriteDataSourceName() : exportDataSources.get(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME);
}
@@ -108,7 +100,7 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
@Override
public Collection<String> getColumnNames() {
- return Arrays.asList("name", "auto_aware_data_source_name", "write_storage_unit_name", "read_storage_unit_names", "load_balancer_type", "load_balancer_props");
+ return Arrays.asList("name", "write_storage_unit_name", "read_storage_unit_names", "load_balancer_type", "load_balancer_props");
}
@Override
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
index 9ab1fe0d376..13643001d41 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingD
import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
import org.junit.jupiter.api.Test;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -49,8 +48,8 @@ class ReadwriteSplittingRuleStatementConverterTest {
@Test
void assertSingleRuleSegmentConvertResult() {
- ReadwriteSplittingRuleSegment expectedSingleReadwriteSplittingRuleSegment = createReadwriteSplittingRuleSegment("static", "write_ds",
- Arrays.asList("read_ds_01", "read_ds_02"), "static_load_balancer_type", new Properties());
+ ReadwriteSplittingRuleSegment expectedSingleReadwriteSplittingRuleSegment = createReadwriteSplittingRuleSegment("write_ds", Arrays.asList("read_ds_01", "read_ds_02"),
+ "static_load_balancer_type", new Properties());
ReadwriteSplittingRuleConfiguration actualSingleRuleSegmentConvertResult = ReadwriteSplittingRuleStatementConverter
.convert(Collections.singleton(expectedSingleReadwriteSplittingRuleSegment));
Collection<ReadwriteSplittingDataSourceRuleConfiguration> actualSingleRuleSegmentConvertResultDataSources = actualSingleRuleSegmentConvertResult.getDataSources();
@@ -71,51 +70,8 @@ class ReadwriteSplittingRuleStatementConverterTest {
assertThat(actualSphereAlgorithmConfig.getProps(), is(expectedSingleReadwriteSplittingRuleSegment.getLoadBalancer().getProps()));
}
- @Test
- void assertMultipleReadwriteSplittingRuleSegments() {
- List<ReadwriteSplittingRuleSegment> expectedMultipleReadwriteSplittingRuleSegments = Arrays.asList(
- createReadwriteSplittingRuleSegment("static", "write_ds", Arrays.asList("read_ds_01", "read_ds_02"), "static_load_balancer_type", new Properties()),
- createReadwriteSplittingRuleSegment("dynamic", "autoAwareResource", "dynamic_load_balancer", new Properties()));
- ReadwriteSplittingRuleConfiguration actualMultipleRuleSegmentConvertResult = ReadwriteSplittingRuleStatementConverter.convert(expectedMultipleReadwriteSplittingRuleSegments);
- Collection<ReadwriteSplittingDataSourceRuleConfiguration> actualMultipleRuleSegmentConvertResultDataSources = actualMultipleRuleSegmentConvertResult.getDataSources();
- Map<String, AlgorithmConfiguration> actualMultipleRuleSegmentConvertResultLoadBalancers = actualMultipleRuleSegmentConvertResult.getLoadBalancers();
- assertThat(actualMultipleRuleSegmentConvertResultDataSources.size(), is(expectedMultipleReadwriteSplittingRuleSegments.size()));
- assertThat(actualMultipleRuleSegmentConvertResultLoadBalancers.size(), is(expectedMultipleReadwriteSplittingRuleSegments.size()));
- List<ReadwriteSplittingDataSourceRuleConfiguration> actualRuleConfigs = new ArrayList<>(actualMultipleRuleSegmentConvertResultDataSources);
- long limit = expectedMultipleReadwriteSplittingRuleSegments.size();
- for (int i = 0;; i = i + 1) {
- if (0 == limit--) {
- break;
- }
- ReadwriteSplittingRuleSegment expectedReadwriteSplittingRuleSegment = expectedMultipleReadwriteSplittingRuleSegments.get(i);
- ReadwriteSplittingDataSourceRuleConfiguration actualRuleConfig = actualRuleConfigs.get(i);
- assertThat(actualRuleConfig.getName(), is(expectedReadwriteSplittingRuleSegment.getName()));
- String expectedLoadBalancerName = String.format("%s_%s", expectedReadwriteSplittingRuleSegment.getName(), expectedReadwriteSplittingRuleSegment.getLoadBalancer().getName());
- assertThat(actualRuleConfig.getLoadBalancerName(), is(expectedLoadBalancerName));
- assertThat(getWriteDataSourceName(actualRuleConfig), is(expectedReadwriteSplittingRuleSegment.getWriteDataSource()));
- assertThat(getReadDataSourceNames(actualRuleConfig),
- is(null == expectedReadwriteSplittingRuleSegment.getReadDataSources() ? Collections.emptyList() : expectedReadwriteSplittingRuleSegment.getReadDataSources()));
- assertTrue(actualMultipleRuleSegmentConvertResultLoadBalancers.containsKey(expectedLoadBalancerName));
- AlgorithmConfiguration actualSphereAlgorithmConfig = actualMultipleRuleSegmentConvertResultLoadBalancers.get(actualRuleConfig.getLoadBalancerName());
- assertThat(actualSphereAlgorithmConfig.getType(), is(expectedReadwriteSplittingRuleSegment.getLoadBalancer().getName()));
- assertThat(actualSphereAlgorithmConfig.getProps(), is(expectedReadwriteSplittingRuleSegment.getLoadBalancer().getProps()));
- }
- }
-
- private String getWriteDataSourceName(final ReadwriteSplittingDataSourceRuleConfiguration ruleConfig) {
- return null == ruleConfig.getDynamicStrategy() ? ruleConfig.getStaticStrategy().getWriteDataSourceName() : null;
- }
-
- private Collection<String> getReadDataSourceNames(final ReadwriteSplittingDataSourceRuleConfiguration ruleConfig) {
- return null == ruleConfig.getDynamicStrategy() ? ruleConfig.getStaticStrategy().getReadDataSourceNames() : Collections.emptyList();
- }
-
- private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name, final String writeDataSource,
- final List<String> readDataSources, final String loadBalancerTypeName, final Properties props) {
- return new ReadwriteSplittingRuleSegment(name, writeDataSource, readDataSources, new AlgorithmSegment(loadBalancerTypeName, props));
- }
-
- private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name, final String autoAwareResource, final String loadBalancer, final Properties props) {
- return new ReadwriteSplittingRuleSegment(name, autoAwareResource, new AlgorithmSegment(loadBalancer, props));
+ private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String writeDataSource, final List<String> readDataSources,
+ final String loadBalancerTypeName, final Properties props) {
+ return new ReadwriteSplittingRuleSegment("", writeDataSource, readDataSources, new AlgorithmSegment(loadBalancerTypeName, props));
}
}
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
index 25f649c1804..e809477161f 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingRulesStatement;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
@@ -74,11 +73,10 @@ class ShowReadwriteSplittingRuleExecutorTest {
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("readwrite_ds"));
- assertThat(row.getCell(2), is(""));
- assertThat(row.getCell(3), is("ds_primary"));
- assertThat(row.getCell(4), is("ds_slave_0,ds_slave_1"));
- assertThat(row.getCell(5), is("random"));
- assertThat(row.getCell(6), is("read_weight=2:1"));
+ assertThat(row.getCell(2), is("ds_primary"));
+ assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1"));
+ assertThat(row.getCell(4), is("random"));
+ assertThat(row.getCell(5), is("read_weight=2:1"));
}
@Test
@@ -94,11 +92,10 @@ class ShowReadwriteSplittingRuleExecutorTest {
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("readwrite_ds"));
- assertThat(row.getCell(2), is(""));
- assertThat(row.getCell(3), is("ds_primary"));
- assertThat(row.getCell(4), is("ds_slave_0,ds_slave_1"));
- assertThat(row.getCell(5), is("random"));
- assertThat(row.getCell(6), is("read_weight=2:1"));
+ assertThat(row.getCell(2), is("ds_primary"));
+ assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1"));
+ assertThat(row.getCell(4), is("random"));
+ assertThat(row.getCell(5), is("read_weight=2:1"));
}
private Map<String, Object> createExportedData() {
@@ -129,11 +126,10 @@ class ShowReadwriteSplittingRuleExecutorTest {
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("readwrite_ds"));
- assertThat(row.getCell(2), is(""));
- assertThat(row.getCell(3), is("write_ds"));
- assertThat(row.getCell(4), is("read_ds_0,read_ds_1"));
+ assertThat(row.getCell(2), is("write_ds"));
+ assertThat(row.getCell(3), is("read_ds_0,read_ds_1"));
+ assertThat(row.getCell(4), is(""));
assertThat(row.getCell(5), is(""));
- assertThat(row.getCell(6), is(""));
}
private RuleConfiguration createRuleConfigurationWithoutLoadBalancer() {
@@ -143,34 +139,13 @@ class ShowReadwriteSplittingRuleExecutorTest {
return new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceRuleConfig), null);
}
- @Test
- void assertGetRowDataWithAutoAwareDataSource() {
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class);
- when(rule.getConfiguration()).thenReturn(createRuleConfigurationWithAutoAwareDataSource());
- when(rule.getExportData()).thenReturn(getExportData());
- when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singleton(rule)));
- RQLExecutor<ShowReadwriteSplittingRulesStatement> executor = new ShowReadwriteSplittingRuleExecutor();
- Collection<LocalDataQueryResultRow> actual = executor.getRows(database, mock(ShowReadwriteSplittingRulesStatement.class));
- assertThat(actual.size(), is(1));
- Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
- LocalDataQueryResultRow row = iterator.next();
- assertThat(row.getCell(1), is("readwrite_ds"));
- assertThat(row.getCell(2), is("rd_rs"));
- assertThat(row.getCell(3), is("write_ds"));
- assertThat(row.getCell(4), is("read_ds_0,read_ds_1"));
- assertThat(row.getCell(5), is(""));
- assertThat(row.getCell(6), is(""));
- }
-
@Test
void assertGetColumnNames() {
RQLExecutor<ShowReadwriteSplittingRulesStatement> executor = new ShowReadwriteSplittingRuleExecutor();
Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(6));
+ assertThat(columns.size(), is(5));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("name"));
- assertThat(iterator.next(), is("auto_aware_data_source_name"));
assertThat(iterator.next(), is("write_storage_unit_name"));
assertThat(iterator.next(), is("read_storage_unit_names"));
assertThat(iterator.next(), is("load_balancer_type"));
@@ -179,23 +154,10 @@ class ShowReadwriteSplittingRuleExecutorTest {
private Map<String, Object> getExportData() {
Map<String, Object> result = new HashMap<>(2, 1);
- result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
return result;
}
- private Map<String, Map<String, String>> exportDynamicDataSources() {
- return Collections.singletonMap("readwrite_ds", getAutoAwareDataSources());
- }
-
- private Map<String, String> getAutoAwareDataSources() {
- Map<String, String> result = new HashMap<>(3, 1);
- result.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
- result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
- result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds_0,read_ds_1");
- return result;
- }
-
private Map<String, Map<String, String>> exportStaticDataSources() {
Map<String, Map<String, String>> result = new LinkedHashMap<>();
Map<String, String> staticRule = new LinkedHashMap<>(2, 1);
@@ -204,10 +166,4 @@ class ShowReadwriteSplittingRuleExecutorTest {
result.put("static_rule_1", staticRule);
return result;
}
-
- private RuleConfiguration createRuleConfigurationWithAutoAwareDataSource() {
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", null,
- new DynamicReadwriteSplittingStrategyConfiguration("rd_rs"), "");
- return new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceRuleConfig), null);
- }
}
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
index 3e6b21ccc61..05bc86f46ff 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -143,15 +143,14 @@ class CreateReadwriteSplittingRuleStatementUpdaterTest {
when(exportableRule.getExportData()).thenReturn(Collections.singletonMap(ExportableConstants.EXPORT_DB_DISCOVERY_PRIMARY_DATA_SOURCES, Collections.singletonMap("ms_group", "ds_0")));
when(database.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(exportableRule));
when(TypedSPILoader.contains(ReadQueryLoadBalanceAlgorithm.class, "TEST")).thenReturn(true);
- ReadwriteSplittingRuleSegment dynamicSegment = new ReadwriteSplittingRuleSegment("dynamic_rule", "ms_group", new AlgorithmSegment("TEST", new Properties()));
ReadwriteSplittingRuleSegment staticSegment = new ReadwriteSplittingRuleSegment("static_rule", "write_ds_0", Arrays.asList("read_ds_0", "read_ds_1"),
new AlgorithmSegment("TEST", new Properties()));
- CreateReadwriteSplittingRuleStatement statement = createSQLStatement(false, dynamicSegment, staticSegment);
+ CreateReadwriteSplittingRuleStatement statement = createSQLStatement(false, staticSegment);
updater.checkSQLStatement(database, statement, null);
ReadwriteSplittingRuleConfiguration currentRuleConfig = new ReadwriteSplittingRuleConfiguration(new ArrayList<>(), new HashMap<>());
ReadwriteSplittingRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, statement);
updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
- assertThat(currentRuleConfig.getDataSources().size(), is(2));
+ assertThat(currentRuleConfig.getDataSources().size(), is(1));
}
private CreateReadwriteSplittingRuleStatement createSQLStatement(final String loadBalancerName) {
diff --git a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4 b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
index d9263bdf531..9de2d95979e 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
+++ b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
@@ -32,17 +32,13 @@ dropReadwriteSplittingRule
;
readwriteSplittingRuleDefinition
- : ruleName LP_ (staticReadwriteSplittingRuleDefinition | dynamicReadwriteSplittingRuleDefinition) (COMMA_ algorithmDefinition)? RP_
+ : ruleName LP_ staticReadwriteSplittingRuleDefinition (COMMA_ algorithmDefinition)? RP_
;
staticReadwriteSplittingRuleDefinition
: WRITE_STORAGE_UNIT EQ_ writeStorageUnitName COMMA_ READ_STORAGE_UNITS LP_ readStorageUnitsNames RP_
;
-dynamicReadwriteSplittingRuleDefinition
- : AUTO_AWARE_RESOURCE EQ_ resourceName
- ;
-
ruleName
: IDENTIFIER_
;
diff --git a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
index 7931f0f8e90..f6f6d4ff648 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++ b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -88,10 +88,6 @@ public final class ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitReadwriteSplittingRuleDefinition(final ReadwriteSplittingRuleDefinitionContext ctx) {
- if (null == ctx.staticReadwriteSplittingRuleDefinition()) {
- return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.dynamicReadwriteSplittingRuleDefinition().resourceName()),
- null == ctx.algorithmDefinition() ? null : (AlgorithmSegment) visitAlgorithmDefinition(ctx.algorithmDefinition()));
- }
StaticReadwriteSplittingRuleDefinitionContext staticRuleDefinitionCtx = ctx.staticReadwriteSplittingRuleDefinition();
return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(staticRuleDefinitionCtx.writeStorageUnitName()),
staticRuleDefinitionCtx.readStorageUnitsNames().storageUnitName().stream().map(this::getIdentifierValue).collect(Collectors.toList()),
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
index b0ae4078eef..d19f1d656ba 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.config.props.internal.InternalConfigurati
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.ResourceHeldRule;
import org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
@@ -125,7 +124,6 @@ public final class ShardingSphereMetaData {
String databaseName = database.getName();
globalRuleMetaData.findRules(ResourceHeldRule.class).forEach(each -> each.closeStaleResource(databaseName));
database.getRuleMetaData().findRules(ResourceHeldRule.class).forEach(each -> each.closeStaleResource(databaseName));
- database.getRuleMetaData().findSingleRule(DynamicDataSourceContainedRule.class).ifPresent(DynamicDataSourceContainedRule::closeAllHeartBeatJob);
database.getRuleMetaData().findSingleRule(StaticDataSourceContainedRule.class).ifPresent(StaticDataSourceContainedRule::cleanStorageNodeDataSources);
Optional.ofNullable(database.getResourceMetaData()).ifPresent(optional -> optional.getDataSources().values().forEach(each -> database.getResourceMetaData().close(each)));
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DynamicDataSourceContainedRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DynamicDataSourceContainedRule.java
deleted file mode 100644
index 76f93fc1618..00000000000
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DynamicDataSourceContainedRule.java
+++ /dev/null
@@ -1,71 +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.infra.rule.identifier.type;
-
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
-
-import java.util.Collection;
-
-/**
- * Dynamic data source contained rule.
- */
-public interface DynamicDataSourceContainedRule extends ShardingSphereRule {
-
- /**
- * Get primary data source name.
- *
- * @param dataSourceName data source name
- * @return primary data source name
- */
- String getPrimaryDataSourceName(String dataSourceName);
-
- /**
- * Get replica data source names.
- *
- * @param dataSourceName data source name
- * @return replica data source names
- */
- Collection<String> getReplicaDataSourceNames(String dataSourceName);
-
- /**
- * Update data source status.
- *
- * @param event data source status changed event
- */
- void updateStatus(DataSourceStatusChangedEvent event);
-
- /**
- * Restart heart beat job.
- *
- * @param event data source status changed event
- */
- void restartHeartBeatJob(DataSourceStatusChangedEvent event);
-
- /**
- * Close single heart beat job.
- *
- * @param groupName group name
- */
- void closeSingleHeartBeatJob(String groupName);
-
- /**
- * Close all heart beat job.
- */
- void closeAllHeartBeatJob();
-}
diff --git a/jdbc/core/pom.xml b/jdbc/core/pom.xml
index 1eaa7a94c49..75c8b94aeb4 100644
--- a/jdbc/core/pom.xml
+++ b/jdbc/core/pom.xml
@@ -135,11 +135,6 @@
<artifactId>shardingsphere-readwrite-splitting-core</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-core</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-encrypt-core</artifactId>
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/PrimaryDataSourceChangedEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/PrimaryDataSourceChangedEvent.java
deleted file mode 100644
index 79991116690..00000000000
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/PrimaryDataSourceChangedEvent.java
+++ /dev/null
@@ -1,33 +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.mode.event.storage;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
-
-/**
- * Primary data source changed event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class PrimaryDataSourceChangedEvent implements DataSourceStatusChangedEvent {
-
- private final QualifiedDatabase qualifiedDatabase;
-}
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSource.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSource.java
index 0cfeb499631..301f0b9eb73 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSource.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/storage/StorageNodeDataSource.java
@@ -31,10 +31,4 @@ public final class StorageNodeDataSource {
private final StorageNodeRole role;
private final DataSourceState status;
-
- private final long replicationDelayMilliseconds;
-
- public StorageNodeDataSource(final StorageNodeRole role, final DataSourceState status) {
- this(role, status, 0L);
- }
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java
deleted file mode 100644
index 9300c58404e..00000000000
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java
+++ /dev/null
@@ -1,33 +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.mode.manager.cluster.coordinator.registry.status.storage.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
-import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-
-/**
- * Primary state event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class PrimaryStateChangedEvent implements GovernanceEvent {
-
- private final QualifiedDatabase qualifiedDatabase;
-}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java
index 5fa53b85bb6..0615291dc37 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java
@@ -18,16 +18,12 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber;
import com.google.common.eventbus.Subscribe;
-import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageNode;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.yaml.YamlStorageNodeDataSourceSwapper;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.event.storage.DataSourceDisabledEvent;
-import org.apache.shardingsphere.mode.event.storage.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
@@ -55,17 +51,6 @@ public final class StorageNodeStatusSubscriber {
YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(event.getStorageNodeDataSource())));
}
- /**
- * Update primary data source state.
- *
- * @param event primary data source event
- */
- @Subscribe
- public void update(final PrimaryDataSourceChangedEvent event) {
- repository.persist(StorageNode.getStorageNodeDataSourcePath(event.getQualifiedDatabase()),
- YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(new StorageNodeDataSource(StorageNodeRole.PRIMARY, DataSourceState.ENABLED))));
- }
-
/**
* Delete storage node data source.
*
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
index bc274cab077..f35517c461c 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
@@ -22,13 +22,11 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabas
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.PrimaryStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageNode;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.yaml.YamlStorageNodeDataSource;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.yaml.YamlStorageNodeDataSourceSwapper;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type;
@@ -61,9 +59,6 @@ public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<G
if (qualifiedDatabase.isPresent()) {
QualifiedDatabase database = qualifiedDatabase.get();
StorageNodeDataSource storageNodeDataSource = new YamlStorageNodeDataSourceSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlStorageNodeDataSource.class));
- if (StorageNodeRole.PRIMARY == storageNodeDataSource.getRole()) {
- return Optional.of(new PrimaryStateChangedEvent(database));
- }
return Optional.of(new StorageNodeChangedEvent(database, storageNodeDataSource));
}
return Optional.empty();
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/yaml/YamlStorageNodeDataSourceSwapper.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/yaml/YamlStorageNodeDataSourceSwapper.java
index 4a27ea02ac6..504eccca4e1 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/yaml/YamlStorageNodeDataSourceSwapper.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/yaml/YamlStorageNodeDataSourceSwapper.java
@@ -32,12 +32,11 @@ public final class YamlStorageNodeDataSourceSwapper implements YamlConfiguration
YamlStorageNodeDataSource result = new YamlStorageNodeDataSource();
result.setRole(data.getRole().name());
result.setStatus(data.getStatus().name());
- result.setReplicationDelayMilliseconds(data.getReplicationDelayMilliseconds());
return result;
}
@Override
public StorageNodeDataSource swapToObject(final YamlStorageNodeDataSource yamlConfig) {
- return new StorageNodeDataSource(StorageNodeRole.valueOf(yamlConfig.getRole()), DataSourceState.valueOf(yamlConfig.getStatus()), yamlConfig.getReplicationDelayMilliseconds());
+ return new StorageNodeDataSource(StorageNodeRole.valueOf(yamlConfig.getRole()), DataSourceState.valueOf(yamlConfig.getStatus()));
}
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
index 370d8df4de7..44657c68c24 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.datasource.state.DataSourceStateManager;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
@@ -34,9 +33,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.PrimaryStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
-import org.apache.shardingsphere.mode.event.storage.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent;
import java.util.Optional;
@@ -68,12 +65,6 @@ public final class StateChangedSubscriber {
if (!contextManager.getMetaDataContexts().getMetaData().containsDatabase(event.getQualifiedDatabase().getDatabaseName())) {
return;
}
- Optional<DynamicDataSourceContainedRule> dynamicDataSourceRule = contextManager.getMetaDataContexts()
- .getMetaData().getDatabase(qualifiedDatabase.getDatabaseName()).getRuleMetaData().findSingleRule(DynamicDataSourceContainedRule.class);
- if (dynamicDataSourceRule.isPresent()) {
- dynamicDataSourceRule.get().updateStatus(new StorageNodeDataSourceChangedEvent(qualifiedDatabase, event.getDataSource()));
- return;
- }
Optional<StaticDataSourceContainedRule> staticDataSourceRule = contextManager.getMetaDataContexts()
.getMetaData().getDatabase(qualifiedDatabase.getDatabaseName()).getRuleMetaData().findSingleRule(StaticDataSourceContainedRule.class);
staticDataSourceRule.ifPresent(optional -> optional.updateStatus(new StorageNodeDataSourceChangedEvent(qualifiedDatabase, event.getDataSource())));
@@ -81,23 +72,6 @@ public final class StateChangedSubscriber {
qualifiedDatabase.getDatabaseName(), qualifiedDatabase.getDataSourceName(), DataSourceState.valueOf(event.getDataSource().getStatus().name()));
}
- /**
- * Renew primary data source names.
- *
- * @param event primary state changed event
- */
- @Subscribe
- public synchronized void renew(final PrimaryStateChangedEvent event) {
- if (!contextManager.getMetaDataContexts().getMetaData().containsDatabase(event.getQualifiedDatabase().getDatabaseName())) {
- return;
- }
- QualifiedDatabase qualifiedDatabase = event.getQualifiedDatabase();
- for (DynamicDataSourceContainedRule each : contextManager.getMetaDataContexts()
- .getMetaData().getDatabase(qualifiedDatabase.getDatabaseName()).getRuleMetaData().findRules(DynamicDataSourceContainedRule.class)) {
- each.restartHeartBeatJob(new PrimaryDataSourceChangedEvent(qualifiedDatabase));
- }
- }
-
/**
* Reset cluster state.
*
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java
index 5dbc7d0a36c..8a4e51f7fd0 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.event.storage.DataSourceDisabledEvent;
-import org.apache.shardingsphere.mode.event.storage.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.junit.jupiter.api.Test;
@@ -68,17 +67,6 @@ class StorageNodeStatusSubscriberTest {
YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(storageNodeDataSource)));
}
- @Test
- void assertUpdatePrimaryDataSourceState() {
- String databaseName = "replica_query_db";
- String groupName = "readwrite_ds";
- String dataSourceName = "replica_ds_0";
- PrimaryDataSourceChangedEvent event = new PrimaryDataSourceChangedEvent(new QualifiedDatabase(databaseName, groupName, dataSourceName));
- new StorageNodeStatusSubscriber(repository, eventBusContext).update(event);
- verify(repository).persist(StorageNode.getStorageNodeDataSourcePath(new QualifiedDatabase(databaseName, groupName, dataSourceName)),
- YamlEngine.marshal(new YamlStorageNodeDataSourceSwapper().swapToYamlConfiguration(new StorageNodeDataSource(StorageNodeRole.PRIMARY, DataSourceState.ENABLED))));
- }
-
@Test
void assertDeleteStorageNodeDataSourceDataSourceState() {
String databaseName = "replica_query_db";
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
index 93a01eaaa00..984c3e7c1c3 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.PrimaryStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
@@ -35,17 +34,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class StorageNodeStateChangedWatcherTest {
- @Test
- void assertCreatePrimaryStateChangedEvent() {
- Optional<GovernanceEvent> actual = new StorageNodeStateChangedWatcher().createGovernanceEvent(
- new DataChangedEvent("/nodes/storage_nodes/replica_query_db.readwrite_ds.replica_ds_0", "role: PRIMARY\nstatus: ENABLED\n", Type.ADDED));
- assertTrue(actual.isPresent());
- PrimaryStateChangedEvent actualEvent = (PrimaryStateChangedEvent) actual.get();
- assertThat(actualEvent.getQualifiedDatabase().getDatabaseName(), is("replica_query_db"));
- assertThat(actualEvent.getQualifiedDatabase().getGroupName(), is("readwrite_ds"));
- assertThat(actualEvent.getQualifiedDatabase().getDataSourceName(), is("replica_ds_0"));
- }
-
@Test
void assertCreateEnabledStorageNodeChangedEvent() {
Optional<GovernanceEvent> actual = new StorageNodeStateChangedWatcher().createGovernanceEvent(
diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
index c777c3368e3..2a038c8fc54 100644
--- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
+++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java
@@ -26,11 +26,8 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.ResourceHeldRule;
import org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
import org.apache.shardingsphere.infra.state.cluster.ClusterState;
@@ -47,7 +44,6 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.PrimaryStateChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
@@ -77,7 +73,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -131,20 +126,6 @@ class StateChangedSubscriberTest {
&& Objects.equals(event.getDataSource(), argumentEvent.getDataSource())));
}
- @Test
- void assertRenewPrimaryDataSourceName() {
- Collection<ShardingSphereRule> rules = new LinkedList<>();
- DynamicDataSourceContainedRule dynamicDataSourceRule = mock(DynamicDataSourceContainedRule.class);
- rules.add(dynamicDataSourceRule);
- ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(rules);
- ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- when(database.getRuleMetaData()).thenReturn(ruleMetaData);
- contextManager.getMetaDataContexts().getMetaData().getDatabases().put("db", database);
- PrimaryStateChangedEvent mockPrimaryStateChangedEvent = new PrimaryStateChangedEvent(new QualifiedDatabase("db.readwrite_ds.test_ds"));
- subscriber.renew(mockPrimaryStateChangedEvent);
- verify(dynamicDataSourceRule).restartHeartBeatJob(any());
- }
-
@Test
void assertResetClusterStatus() {
ClusterLockDeletedEvent mockLockDeletedEvent = new ClusterLockDeletedEvent(ClusterState.OK);
diff --git a/proxy/backend/core/pom.xml b/proxy/backend/core/pom.xml
index 7ddcca8b5c5..98ea3988c2f 100644
--- a/proxy/backend/core/pom.xml
+++ b/proxy/backend/core/pom.xml
@@ -88,11 +88,6 @@
<artifactId>shardingsphere-readwrite-splitting-distsql-handler</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-db-discovery-distsql-handler</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-encrypt-distsql-handler</artifactId>
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
deleted file mode 100644
index 3b56367e119..00000000000
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
+++ /dev/null
@@ -1,74 +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.
- */
... 4361 lines suppressed ...