diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 84e4082ee5f5c..a0ab7b7aea296 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -50,6 +50,7 @@ 1. [ISSUE #1289](https://github.com/sharding-sphere/sharding-sphere/issues/1289) Adjust Hint API 1. [ISSUE #1302](https://github.com/sharding-sphere/sharding-sphere/issues/1302) Refine package structure 1. [ISSUE #1305](https://github.com/sharding-sphere/sharding-sphere/issues/1305) Deprecated and remove sharding-jdbc-transaction-parent module +1. [ISSUE #1382](https://github.com/sharding-sphere/sharding-sphere/issues/1328) Remove type configuration in Orchestration module ### Bug Fixes diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 3691928667648..287b1914135ef 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -50,7 +50,7 @@ 1. [ISSUE #1289](https://github.com/sharding-sphere/sharding-sphere/issues/1289) 调整Hint API 1. [ISSUE #1302](https://github.com/sharding-sphere/sharding-sphere/issues/1302) 调整包结构 1. [ISSUE #1305](https://github.com/sharding-sphere/sharding-sphere/issues/1305) 废弃并删除sharding-jdbc-transaction-parent模块 - +1. [ISSUE #1382](https://github.com/sharding-sphere/sharding-sphere/issues/1328) 去除Orchestration模块中type的配置 ### 缺陷修正 diff --git a/sharding-core/src/main/java/io/shardingsphere/api/config/TableRuleConfiguration.java b/sharding-core/src/main/java/io/shardingsphere/api/config/TableRuleConfiguration.java index e76b0d3138de7..350a5cdcb46a5 100644 --- a/sharding-core/src/main/java/io/shardingsphere/api/config/TableRuleConfiguration.java +++ b/sharding-core/src/main/java/io/shardingsphere/api/config/TableRuleConfiguration.java @@ -25,7 +25,7 @@ /** * Table rule configuration. * - * @author zhangiang + * @author zhangliang */ @Getter @Setter diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/H2DataSourceMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/H2DataSourceMetaData.java index c3f0b37ad602b..21c2d510e2c27 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/H2DataSourceMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/H2DataSourceMetaData.java @@ -40,7 +40,7 @@ public final class H2DataSourceMetaData implements DataSourceMetaData { private final String schemeName; - private final Pattern pattern = Pattern.compile("jdbc:h2:(mem|~)[:/]([\\w\\-]+);?\\w*", Pattern.CASE_INSENSITIVE); + private final Pattern pattern = Pattern.compile("jdbc:h2:(mem|~)[:/]([\\w\\-]+);?\\S*", Pattern.CASE_INSENSITIVE); public H2DataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/MySQLDataSourceMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/MySQLDataSourceMetaData.java index b8b0a121fb867..f9a202c76c045 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/MySQLDataSourceMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/MySQLDataSourceMetaData.java @@ -41,7 +41,7 @@ public final class MySQLDataSourceMetaData implements DataSourceMetaData { private final String schemeName; - private final Pattern pattern = Pattern.compile("jdbc:mysql://([\\w\\-\\.]+):?([0-9]*)/([\\w\\-]+);?\\w*", Pattern.CASE_INSENSITIVE); + private final Pattern pattern = Pattern.compile("jdbc:mysql://([\\w\\-\\.]+):?([0-9]*)/([\\w\\-]+);?\\S*", Pattern.CASE_INSENSITIVE); public MySQLDataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/SQLServerDataSourceMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/SQLServerDataSourceMetaData.java index 8ec50d4048fd3..c7fb32b78b7c6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/SQLServerDataSourceMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/dialect/SQLServerDataSourceMetaData.java @@ -41,7 +41,7 @@ public final class SQLServerDataSourceMetaData implements DataSourceMetaData { private final String schemeName; - private final Pattern pattern = Pattern.compile("jdbc:(microsoft:)?sqlserver://([\\w\\-\\.]+):?([0-9]*);(DatabaseName|database)=([\\w\\-]+)", Pattern.CASE_INSENSITIVE); + private final Pattern pattern = Pattern.compile("jdbc:(microsoft:)?sqlserver://([\\w\\-\\.]+):?([0-9]*);\\S*(DatabaseName|database)=([\\w\\-]+);?", Pattern.CASE_INSENSITIVE); public SQLServerDataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/StatementRoutingEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/StatementRoutingEngine.java index 5f2884f7167a7..17cf6b06e7d93 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/StatementRoutingEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/StatementRoutingEngine.java @@ -18,9 +18,9 @@ package io.shardingsphere.core.routing; import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; -import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.routing.router.masterslave.ShardingMasterSlaveRouter; import io.shardingsphere.core.routing.router.sharding.ShardingRouter; import io.shardingsphere.core.routing.router.sharding.ShardingRouterFactory; @@ -31,7 +31,7 @@ /** * Statement routing engine. * - * @author zhangiang + * @author zhangliang * @author panjuan */ public final class StatementRoutingEngine { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterSlaveRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterSlaveRouter.java index 533cf3ddd7ef2..b48a0df9797e0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterSlaveRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterSlaveRouter.java @@ -31,7 +31,7 @@ /** * Master slave router interface. * - * @author zhangiang + * @author zhangliang * @author panjuan */ @RequiredArgsConstructor diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java index b4fbe3537b9d1..0e40dd33198a5 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java @@ -22,7 +22,7 @@ * *

Trace master data source visited or not in current thread.

* - * @author zhangiang + * @author zhangliang */ public final class MasterVisitedManager { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/ShardingMasterSlaveRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/ShardingMasterSlaveRouter.java index a46de6176d857..3727e231940cc 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/ShardingMasterSlaveRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/ShardingMasterSlaveRouter.java @@ -31,7 +31,7 @@ /** * Sharding with master-slave router interface. * - * @author zhangiang + * @author zhangliang */ @RequiredArgsConstructor public final class ShardingMasterSlaveRouter { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/DatabaseHintSQLRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/DatabaseHintSQLRouter.java index 999bca491f976..bee615d86238d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/DatabaseHintSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/DatabaseHintSQLRouter.java @@ -37,7 +37,7 @@ /** * Sharding router for hint database only. * - * @author zhangiang + * @author zhangliang * @author maxiaoguang */ @RequiredArgsConstructor diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java index 384d778fd086d..d485d573bd008 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java @@ -51,9 +51,9 @@ import io.shardingsphere.core.routing.type.unicast.UnicastRoutingEngine; import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.core.rule.TableRule; +import io.shardingsphere.core.util.SQLLogger; import io.shardingsphere.spi.parsing.ParsingHook; import io.shardingsphere.spi.parsing.SPIParsingHook; -import io.shardingsphere.core.util.SQLLogger; import lombok.RequiredArgsConstructor; import java.util.Collection; @@ -63,7 +63,7 @@ /** * Sharding router with parse. * - * @author zhangiang + * @author zhangliang * @author maxiaoguang * @author panjuan */ diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouter.java index 38e555b92890c..d64a7cc49cea6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouter.java @@ -25,7 +25,7 @@ /** * Sharding router. * - * @author zhangiang + * @author zhangliang */ public interface ShardingRouter { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouterFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouterFactory.java index f7345b265e39b..d684f55dda388 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouterFactory.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ShardingRouterFactory.java @@ -19,8 +19,8 @@ import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.hint.HintManagerHolder; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.ShardingRule; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -28,7 +28,7 @@ /** * Sharding router factory. * - * @author zhangiang + * @author zhangliang * @author panjuan */ @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rule/MasterSlaveRule.java b/sharding-core/src/main/java/io/shardingsphere/core/rule/MasterSlaveRule.java index 565f2c63fa571..068cfe1beb9a8 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/rule/MasterSlaveRule.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/rule/MasterSlaveRule.java @@ -32,7 +32,7 @@ * @author panjuan */ @Getter -public final class MasterSlaveRule { +public class MasterSlaveRule { private final String name; @@ -42,6 +42,8 @@ public final class MasterSlaveRule { private final MasterSlaveLoadBalanceAlgorithm loadBalanceAlgorithm; + private final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration; + public MasterSlaveRule(final MasterSlaveRuleConfiguration config) { Preconditions.checkNotNull(config.getName(), "Master-slave rule name cannot be null."); Preconditions.checkNotNull(config.getMasterDataSourceName(), "Master data source name cannot be null."); @@ -51,6 +53,7 @@ public MasterSlaveRule(final MasterSlaveRuleConfiguration config) { masterDataSourceName = config.getMasterDataSourceName(); slaveDataSourceNames = config.getSlaveDataSourceNames(); loadBalanceAlgorithm = null == config.getLoadBalanceAlgorithm() ? MasterSlaveLoadBalanceAlgorithmType.getDefaultAlgorithmType().getAlgorithm() : config.getLoadBalanceAlgorithm(); + masterSlaveRuleConfiguration = config; } /** diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java b/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java index d00f09e5c9d6a..ba4e7bca538eb 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java @@ -47,7 +47,7 @@ * @author panjuan */ @Getter -public final class ShardingRule { +public class ShardingRule { private final ShardingRuleConfiguration shardingRuleConfig; diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java b/sharding-jdbc/sharding-jdbc-core/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java index 26f22d0150241..6ab7a73c2719c 100644 --- a/sharding-jdbc/sharding-jdbc-core/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java +++ b/sharding-jdbc/sharding-jdbc-core/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java @@ -78,7 +78,7 @@ private static DataSource createDBCP(final DatabaseType databaseType, final Stri result.setUrl(null == dataSourceName ? databaseEnvironment.getURL() : databaseEnvironment.getURL(dataSourceName)); result.setUsername(databaseEnvironment.getUsername()); result.setPassword(databaseEnvironment.getPassword()); - result.setMaxTotal(50); + result.setMaxTotal(5); result.setValidationQuery("SELECT 1"); if (DatabaseType.Oracle == databaseType) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dataSourceName)); @@ -93,7 +93,7 @@ private static DataSource createHikariCP(final DatabaseType databaseType, final result.setJdbcUrl(null == dataSourceName ? databaseEnvironment.getURL() : databaseEnvironment.getURL(dataSourceName)); result.setUsername(databaseEnvironment.getUsername()); result.setPassword(databaseEnvironment.getPassword()); - result.setMaximumPoolSize(50); + result.setMaximumPoolSize(5); result.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); result.setConnectionTestQuery("SELECT 1"); if (DatabaseType.Oracle == databaseType) { diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_multiple_values_for_order_1_2.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_multiple_values_for_order_1_2.xml new file mode 100644 index 0000000000000..1ac071d3f06e5 --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_multiple_values_for_order_1_2.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_on_duplicate_key_update.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_on_duplicate_key_update.xml new file mode 100644 index 0000000000000..7f972b435eba0 --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/db/insert_on_duplicate_key_update.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_multiple_values_for_order_1_2.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_multiple_values_for_order_1_2.xml new file mode 100644 index 0000000000000..3424f983feadf --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_multiple_values_for_order_1_2.xml @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_on_duplicate_key_update.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_on_duplicate_key_update.xml new file mode 100644 index 0000000000000..e4cc67d13e7de --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_on_duplicate_key_update.xml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_on_duplicate_key_update.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_on_duplicate_key_update.xml new file mode 100644 index 0000000000000..0179c323703c3 --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_on_duplicate_key_update.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_multiple_values_for_order_1_2.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_multiple_values_for_order_1_2.xml new file mode 100644 index 0000000000000..bc938e65879da --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_multiple_values_for_order_1_2.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_on_duplicate_key_update.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_on_duplicate_key_update.xml new file mode 100644 index 0000000000000..2562e40ccafcd --- /dev/null +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dataset/tbl/insert_on_duplicate_key_update.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml index c866ed643d232..1efe4ae591e5e 100644 --- a/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml +++ b/sharding-jdbc/sharding-jdbc-core/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml @@ -17,11 +17,11 @@ - + - + diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java index 634cdb5a7b706..26924db927c2a 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java @@ -19,9 +19,11 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import io.shardingsphere.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.orchestration.config.OrchestrationType; +import io.shardingsphere.orchestration.internal.OrchestrationFacade; import io.shardingsphere.shardingjdbc.jdbc.core.datasource.MasterSlaveDataSource; import io.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource; import io.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationMasterSlaveDataSource; @@ -44,7 +46,6 @@ import java.util.LinkedHashMap; import java.util.Map; - /** * Orchestration spring boot sharding and master-slave configuration. * @@ -74,9 +75,42 @@ public class OrchestrationSpringBootConfiguration implements EnvironmentAware { */ @Bean public DataSource dataSource() throws SQLException { - OrchestrationType type = orchestrationProperties.getType(); - Preconditions.checkState(null != type, "Missing the type of datasource configuration in orchestration configuration"); - return OrchestrationType.SHARDING == type ? createShardingDataSource() : createMasterSlaveDataSource(); + Preconditions.checkState(isValidConfiguration(), "The orchestration configuration is invalid, please choose one from Sharding rule and Master-slave rule."); + return OrchestrationType.SHARDING == getOrchestrationType() ? createShardingDataSource() : createMasterSlaveDataSource(); + } + + private boolean isValidConfiguration() { + return isValidRuleConfiguration() || isValidOrchestrationConfiguration(); + } + + private boolean isValidRuleConfiguration() { + return (shardingProperties.getTables().isEmpty() && !Strings.isNullOrEmpty(masterSlaveProperties.getMasterDataSourceName())) + || (!shardingProperties.getTables().isEmpty() && Strings.isNullOrEmpty(masterSlaveProperties.getMasterDataSourceName())); + } + + private boolean isValidOrchestrationConfiguration() { + return !Strings.isNullOrEmpty(orchestrationProperties.getName()); + } + + private OrchestrationType getOrchestrationType() { + if (isValidRuleConfiguration()) { + return getOrchestrationTypeByLocal(); + } + return getOrchestrationTypeByRegistry(); + } + + private OrchestrationType getOrchestrationTypeByLocal() { + return shardingProperties.getTables().isEmpty() ? OrchestrationType.MASTER_SLAVE : OrchestrationType.SHARDING; + } + + private OrchestrationType getOrchestrationTypeByRegistry() { + OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationProperties.getOrchestrationConfiguration()); + ShardingRuleConfiguration shardingRuleConfiguration = orchestrationFacade.getConfigService().loadShardingRuleConfiguration(); + orchestrationFacade.close(); + if (null != shardingRuleConfiguration && !shardingRuleConfiguration.getTableRuleConfigs().isEmpty()) { + return OrchestrationType.SHARDING; + } + return OrchestrationType.MASTER_SLAVE; } private DataSource createShardingDataSource() throws SQLException { diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-masterslave.properties b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-masterslave.properties index 0774a5a271630..d9f23e066841a 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-masterslave.properties +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-masterslave.properties @@ -26,7 +26,6 @@ sharding.jdbc.config.masterslave.master-data-source-name=ds_master sharding.jdbc.config.masterslave.slave-data-source-names=ds_slave_0,ds_slave_1 sharding.jdbc.config.orchestration.name=demo_spring_boot_ds_ms -sharding.jdbc.config.orchestration.type=master_slave sharding.jdbc.config.orchestration.overwrite=true sharding.jdbc.config.orchestration.zookeeper.namespace=orchestration-spring-boot-master-slave-test sharding.jdbc.config.orchestration.zookeeper.server-lists=localhost:3181 diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties index bd790e49e287f..47d59d33c4b05 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties @@ -36,9 +36,8 @@ sharding.jdbc.config.sharding.props.sql.show=true sharding.jdbc.config.sharding.props.executor.size=100 sharding.jdbc.config.orchestration.name=demo_spring_boot_ds_sharding -sharding.jdbc.config.orchestration.type=sharding sharding.jdbc.config.orchestration.overwrite=true sharding.jdbc.config.orchestration.zookeeper.namespace=orchestration-spring-boot-sharding-test sharding.jdbc.config.orchestration.zookeeper.server-lists=localhost:3181 -sharding.jdbc.config.sharding.config-map.key1=value1 +sharding.jdbc.config.sharding.config-map.key1=value1 \ No newline at end of file diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/namespace/parser/DataSourceBeanDefinitionParser.java b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/namespace/parser/DataSourceBeanDefinitionParser.java index 864cd85f5b452..0d945c4aa4645 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/namespace/parser/DataSourceBeanDefinitionParser.java +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/shardingjdbc/orchestration/spring/namespace/parser/DataSourceBeanDefinitionParser.java @@ -65,7 +65,6 @@ private BeanDefinition getOrchestrationConfiguration(final Element element) { factory.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE)); factory.addConstructorArgReference(element.getAttribute(ShardingDataSourceBeanDefinitionParserTag.REG_REF_TAG)); factory.addConstructorArgValue(element.getAttribute(ShardingDataSourceBeanDefinitionParserTag.OVERWRITE_TAG)); - factory.addConstructorArgValue(orchestrationType); return factory.getBeanDefinition(); } } diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java index 19326526223d8..cd12573f42ae7 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java @@ -83,7 +83,7 @@ private Map getDataSourceMap(final String shardingDataSource private ShardingRule getShardingRule(final String shardingDataSourceName) { OrchestrationSpringShardingDataSource shardingDataSource = applicationContext.getBean(shardingDataSourceName, OrchestrationSpringShardingDataSource.class); ShardingDataSource dataSource = (ShardingDataSource) FieldValueUtil.getFieldValue(shardingDataSource, "dataSource", true); - Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", true); + Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", false); return (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule"); } } diff --git a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java index a6920e9c5e472..50a0c1c08230b 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java +++ b/sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java @@ -140,9 +140,9 @@ public void assertPropsDataSource() { Map configMap = new HashMap<>(); configMap.put("key1", "value1"); assertThat(ConfigMapContext.getInstance().getShardingConfig(), is(configMap)); - Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", true); + Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", false); assertTrue((boolean) FieldValueUtil.getFieldValue(shardingContext, "showSQL")); - ShardingProperties shardingProperties = (ShardingProperties) FieldValueUtil.getFieldValue(dataSource, "shardingProperties", true); + ShardingProperties shardingProperties = (ShardingProperties) FieldValueUtil.getFieldValue(dataSource, "shardingProperties", false); boolean showSql = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); assertTrue(showSql); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); @@ -159,7 +159,7 @@ public void assertShardingDataSourceType() { public void assertDefaultActualDataNodes() { OrchestrationSpringShardingDataSource multiTableRulesDataSource = applicationContext.getBean("multiTableRulesDataSourceOrchestration", OrchestrationSpringShardingDataSource.class); ShardingDataSource dataSource = (ShardingDataSource) FieldValueUtil.getFieldValue(multiTableRulesDataSource, "dataSource", true); - Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", true); + Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", false); ShardingRule shardingRule = (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule"); assertThat(shardingRule.getTableRules().size(), is(2)); Iterator tableRules = shardingRule.getTableRules().iterator(); @@ -183,7 +183,7 @@ private Map getDataSourceMap(final String shardingDataSource private ShardingRule getShardingRule(final String shardingDataSourceName) { OrchestrationSpringShardingDataSource shardingDataSource = applicationContext.getBean(shardingDataSourceName, OrchestrationSpringShardingDataSource.class); ShardingDataSource dataSource = (ShardingDataSource) FieldValueUtil.getFieldValue(shardingDataSource, "dataSource", true); - Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", true); + Object shardingContext = FieldValueUtil.getFieldValue(dataSource, "shardingContext", false); return (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule"); } } diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java index 955f03ffcb891..35111e566655d 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/AbstractOrchestrationDataSource.java @@ -27,8 +27,6 @@ import javax.sql.DataSource; import java.sql.SQLException; -import java.util.Collection; -import java.util.LinkedHashMap; import java.util.Map; /** @@ -59,14 +57,6 @@ public AbstractOrchestrationDataSource(final OrchestrationFacade orchestrationFa ShardingEventBusInstance.getInstance().register(this); } - protected final Map getAvailableDataSourceMap(final Collection disabledDataSourceNames) { - Map result = new LinkedHashMap<>(dataSourceMap); - for (String each : disabledDataSourceNames) { - result.remove(each); - } - return result; - } - /** /** * Renew circuit breaker dataSource names. diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java index 730041f9b396b..7582b696e3fcb 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationMasterSlaveDataSource.java @@ -18,23 +18,22 @@ package io.shardingsphere.shardingjdbc.orchestration.internal.datasource; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.eventbus.Subscribe; import io.shardingsphere.api.ConfigMapContext; import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; +import io.shardingsphere.core.constant.properties.ShardingProperties; import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.orchestration.config.OrchestrationConfiguration; import io.shardingsphere.orchestration.internal.OrchestrationFacade; import io.shardingsphere.orchestration.internal.config.ConfigurationService; import io.shardingsphere.orchestration.internal.event.config.MasterSlaveConfigurationEventBusEvent; -import io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent; import io.shardingsphere.shardingjdbc.jdbc.core.datasource.MasterSlaveDataSource; import io.shardingsphere.shardingjdbc.orchestration.internal.circuit.datasource.CircuitBreakerDataSource; +import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -import java.util.LinkedHashMap; -import java.util.Map; /** * Orchestration master-slave datasource. @@ -47,7 +46,8 @@ public class OrchestrationMasterSlaveDataSource extends AbstractOrchestrationDat public OrchestrationMasterSlaveDataSource(final MasterSlaveDataSource masterSlaveDataSource, final OrchestrationConfiguration orchestrationConfig) throws SQLException { super(new OrchestrationFacade(orchestrationConfig), masterSlaveDataSource.getDataSourceMap()); - this.dataSource = masterSlaveDataSource; + dataSource = new MasterSlaveDataSource(masterSlaveDataSource.getDataSourceMap(), new OrchestrationMasterSlaveRule(masterSlaveDataSource.getMasterSlaveRule().getMasterSlaveRuleConfiguration()), + ConfigMapContext.getInstance().getMasterSlaveConfig(), masterSlaveDataSource.getShardingProperties()); initOrchestrationFacade(dataSource); } @@ -55,9 +55,9 @@ public OrchestrationMasterSlaveDataSource(final OrchestrationConfiguration orche super(new OrchestrationFacade(orchestrationConfig)); ConfigurationService configService = getOrchestrationFacade().getConfigService(); MasterSlaveRuleConfiguration masterSlaveRuleConfig = configService.loadMasterSlaveRuleConfiguration(); - Preconditions.checkNotNull(masterSlaveRuleConfig, "Missing the master-slave rule configuration on register center"); - dataSource = new MasterSlaveDataSource( - configService.loadDataSourceMap(), masterSlaveRuleConfig, configService.loadMasterSlaveConfigMap(), configService.loadMasterSlaveProperties()); + Preconditions.checkState(null != masterSlaveRuleConfig && !Strings.isNullOrEmpty(masterSlaveRuleConfig.getMasterDataSourceName()), "No available master slave rule configuration to load."); + dataSource = new MasterSlaveDataSource(configService.loadDataSourceMap(), new OrchestrationMasterSlaveRule(masterSlaveRuleConfig), configService.loadMasterSlaveConfigMap(), + new ShardingProperties(configService.loadMasterSlaveProperties())); initOrchestrationFacade(dataSource); } @@ -95,16 +95,4 @@ public void renew(final MasterSlaveConfigurationEventBusEvent masterSlaveEvent) dataSource = new MasterSlaveDataSource( masterSlaveEvent.getDataSourceMap(), masterSlaveEvent.getMasterSlaveRuleConfig(), ConfigMapContext.getInstance().getMasterSlaveConfig(), masterSlaveEvent.getProps()); } - - /** - * Renew disable dataSource names. - * - * @param disabledStateEventBusEvent jdbc disabled event bus event - * @throws SQLException sql exception - */ - @Subscribe - public void renew(final DisabledStateEventBusEvent disabledStateEventBusEvent) throws SQLException { - Map newDataSourceMap = getAvailableDataSourceMap(disabledStateEventBusEvent.getDisabledDataSourceNames()); - dataSource = new MasterSlaveDataSource(newDataSourceMap, dataSource.getMasterSlaveRule(), new LinkedHashMap(), dataSource.getShardingProperties()); - } } diff --git a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java index ceeda44a5a0af..c20bf3aa2e2da 100644 --- a/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java +++ b/sharding-jdbc/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationShardingDataSource.java @@ -21,20 +21,17 @@ import com.google.common.eventbus.Subscribe; import io.shardingsphere.api.ConfigMapContext; import io.shardingsphere.api.config.ShardingRuleConfiguration; -import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.orchestration.config.OrchestrationConfiguration; import io.shardingsphere.orchestration.internal.OrchestrationFacade; import io.shardingsphere.orchestration.internal.config.ConfigurationService; import io.shardingsphere.orchestration.internal.event.config.ShardingConfigurationEventBusEvent; -import io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent; import io.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource; import io.shardingsphere.shardingjdbc.orchestration.internal.circuit.datasource.CircuitBreakerDataSource; +import io.shardingsphere.orchestration.internal.rule.OrchestrationShardingRule; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.util.LinkedHashMap; -import java.util.Map; /** * Orchestration sharding datasource. @@ -47,7 +44,8 @@ public class OrchestrationShardingDataSource extends AbstractOrchestrationDataSo public OrchestrationShardingDataSource(final ShardingDataSource shardingDataSource, final OrchestrationConfiguration orchestrationConfig) throws SQLException { super(new OrchestrationFacade(orchestrationConfig), shardingDataSource.getDataSourceMap()); - this.dataSource = shardingDataSource; + dataSource = new ShardingDataSource(shardingDataSource.getDataSourceMap(), new OrchestrationShardingRule(shardingDataSource.getShardingContext().getShardingRule().getShardingRuleConfig(), + shardingDataSource.getDataSourceMap().keySet()), ConfigMapContext.getInstance().getShardingConfig(), shardingDataSource.getShardingProperties().getProps()); initOrchestrationFacade(dataSource); } @@ -55,9 +53,9 @@ public OrchestrationShardingDataSource(final OrchestrationConfiguration orchestr super(new OrchestrationFacade(orchestrationConfig)); ConfigurationService configService = getOrchestrationFacade().getConfigService(); ShardingRuleConfiguration shardingRuleConfig = configService.loadShardingRuleConfiguration(); - Preconditions.checkNotNull(shardingRuleConfig, "Missing the sharding rule configuration on register center"); + Preconditions.checkState(null != shardingRuleConfig && !shardingRuleConfig.getTableRuleConfigs().isEmpty(), "Missing the sharding rule configuration on register center"); dataSource = new ShardingDataSource(configService.loadDataSourceMap(), - new ShardingRule(shardingRuleConfig, configService.loadDataSourceMap().keySet()), configService.loadShardingConfigMap(), configService.loadShardingProperties()); + new OrchestrationShardingRule(shardingRuleConfig, configService.loadDataSourceMap().keySet()), configService.loadShardingConfigMap(), configService.loadShardingProperties()); initOrchestrationFacade(dataSource); } @@ -90,17 +88,4 @@ public final void close() { public void renew(final ShardingConfigurationEventBusEvent shardingEvent) throws SQLException { dataSource = new ShardingDataSource(shardingEvent.getDataSourceMap(), shardingEvent.getShardingRule(), new LinkedHashMap(), shardingEvent.getProps()); } - - /** - * Renew disable dataSource names. - * - * @param disabledStateEventBusEvent jdbc disabled event bus event - * @throws SQLException SQL exception - */ - @Subscribe - public void renew(final DisabledStateEventBusEvent disabledStateEventBusEvent) throws SQLException { - Map newDataSourceMap = getAvailableDataSourceMap(disabledStateEventBusEvent.getDisabledDataSourceNames()); - dataSource = new ShardingDataSource(newDataSourceMap, dataSource.getShardingContext(), dataSource.getShardingProperties()); - } } - diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/config/OrchestrationConfiguration.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/config/OrchestrationConfiguration.java index 09984451b6c0d..dbdfb2e326367 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/config/OrchestrationConfiguration.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/config/OrchestrationConfiguration.java @@ -25,6 +25,7 @@ * Orchestration configuration. * * @author zhangliang + * @author panjuan */ @RequiredArgsConstructor @Getter @@ -35,6 +36,4 @@ public final class OrchestrationConfiguration { private final RegistryCenterConfiguration regCenterConfig; private final boolean overwrite; - - private final OrchestrationType type; } diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/ConfigurationService.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/ConfigurationService.java index e401c34edd922..bde5810b8caf5 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/ConfigurationService.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/config/ConfigurationService.java @@ -259,13 +259,11 @@ public Map> loadProxyDataSources() { */ public ShardingRuleConfiguration loadShardingRuleConfiguration() { try { - ShardingRuleConfiguration result = ShardingConfigurationConverter.shardingRuleConfigFromYaml(regCenter.getDirectly(configNode.getFullPath(ConfigurationNode.SHARDING_RULE_NODE_PATH))); - Preconditions.checkState(null != result && !result.getTableRuleConfigs().isEmpty(), "No available sharding rule configuration to load."); - return result; + return ShardingConfigurationConverter.shardingRuleConfigFromYaml(regCenter.getDirectly(configNode.getFullPath(ConfigurationNode.SHARDING_RULE_NODE_PATH))); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON - throw new ShardingConfigurationException("No available sharding rule configuration to load."); + return new ShardingRuleConfiguration(); } } @@ -297,14 +295,12 @@ public Properties loadShardingProperties() { */ public MasterSlaveRuleConfiguration loadMasterSlaveRuleConfiguration() { try { - MasterSlaveRuleConfiguration result = MasterSlaveConfigurationConverter.masterSlaveRuleConfigFromYaml( + return MasterSlaveConfigurationConverter.masterSlaveRuleConfigFromYaml( regCenter.getDirectly(configNode.getFullPath(ConfigurationNode.MASTER_SLAVE_RULE_NODE_PATH))); - Preconditions.checkState(null != result && !Strings.isNullOrEmpty(result.getMasterDataSourceName()), "No available master slave rule configuration to load."); - return result; // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON - throw new ShardingConfigurationException("No available master slave rule configuration to load."); + return new MasterSlaveRuleConfiguration(); } } diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java new file mode 100644 index 0000000000000..52e5062b2e836 --- /dev/null +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationMasterSlaveRule.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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 io.shardingsphere.orchestration.internal.rule; + +import com.google.common.eventbus.Subscribe; +import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; +import io.shardingsphere.core.rule.MasterSlaveRule; +import io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * Orchestration master slave rule. + * + * @author panjuan + */ +public final class OrchestrationMasterSlaveRule extends MasterSlaveRule { + + private final Collection disabledDataSourceNames = new LinkedList<>(); + + public OrchestrationMasterSlaveRule(final MasterSlaveRuleConfiguration config) { + super(config); + } + + /** + * Get slave data source names. + * + * @return available slave data source name + */ + @Override + public Collection getSlaveDataSourceNames() { + Collection result = new LinkedList<>(super.getSlaveDataSourceNames()); + for (String each : disabledDataSourceNames) { + result.remove(each); + } + return result; + } + + /** + * Renew disable dataSource names. + * + * @param disabledStateEventBusEvent jdbc disabled event bus event + */ + @Subscribe + public void renew(final DisabledStateEventBusEvent disabledStateEventBusEvent) { + disabledDataSourceNames.clear(); + disabledDataSourceNames.addAll(disabledStateEventBusEvent.getDisabledDataSourceNames()); + } +} diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationShardingRule.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationShardingRule.java new file mode 100644 index 0000000000000..48e4fb3f98b0b --- /dev/null +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/rule/OrchestrationShardingRule.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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 io.shardingsphere.orchestration.internal.rule; + +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; +import io.shardingsphere.api.config.ShardingRuleConfiguration; +import io.shardingsphere.core.rule.MasterSlaveRule; +import io.shardingsphere.core.rule.ShardingRule; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * Orchestration sharding rule. + * + * @author panjuan + */ +public final class OrchestrationShardingRule extends ShardingRule { + + private final Collection masterSlaveRules = new LinkedList<>(); + + public OrchestrationShardingRule(final ShardingRuleConfiguration shardingRuleConfig, final Collection dataSourceNames) { + super(shardingRuleConfig, dataSourceNames); + initMasterSlaveRules(shardingRuleConfig); + } + + private void initMasterSlaveRules(final ShardingRuleConfiguration shardingRuleConfig) { + for (MasterSlaveRuleConfiguration each : shardingRuleConfig.getMasterSlaveRuleConfigs()) { + masterSlaveRules.add(new OrchestrationMasterSlaveRule(each)); + } + } + + @Override + public Collection getMasterSlaveRules() { + return Collections2.transform(masterSlaveRules, new Function() { + + @Override + public MasterSlaveRule apply(final OrchestrationMasterSlaveRule input) { + return input; + } + }); + } +} diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/state/datasource/DataSourceService.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/state/datasource/DataSourceService.java index 1086967c680e9..97ffdb92572a9 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/state/datasource/DataSourceService.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/internal/state/datasource/DataSourceService.java @@ -17,6 +17,8 @@ package io.shardingsphere.orchestration.internal.state.datasource; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import io.shardingsphere.api.config.MasterSlaveRuleConfiguration; import io.shardingsphere.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.rule.DataSourceParameter; @@ -100,6 +102,7 @@ public Map> getProxyAvailableDataSource */ public ShardingRuleConfiguration getAvailableShardingRuleConfiguration() { ShardingRuleConfiguration result = configService.loadShardingRuleConfiguration(); + Preconditions.checkState(null != result && !result.getTableRuleConfigs().isEmpty(), "Missing the sharding rule configuration on register center"); Collection disabledDataSourceNames = getDisabledDataSourceNames(); for (String each : disabledDataSourceNames) { for (MasterSlaveRuleConfiguration masterSlaveRuleConfig : result.getMasterSlaveRuleConfigs()) { @@ -116,6 +119,7 @@ public ShardingRuleConfiguration getAvailableShardingRuleConfiguration() { */ public MasterSlaveRuleConfiguration getAvailableMasterSlaveRuleConfiguration() { MasterSlaveRuleConfiguration result = configService.loadMasterSlaveRuleConfiguration(); + Preconditions.checkState(null != result && !Strings.isNullOrEmpty(result.getMasterDataSourceName()), "No available master slave rule configuration to load."); Collection disabledDataSourceNames = getDisabledDataSourceNames(); for (String each : disabledDataSourceNames) { result.getSlaveDataSourceNames().remove(each); diff --git a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/yaml/YamlOrchestrationConfiguration.java b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/yaml/YamlOrchestrationConfiguration.java index 692c824866e07..670ad603e1c12 100644 --- a/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/yaml/YamlOrchestrationConfiguration.java +++ b/sharding-orchestration/sharding-orchestration-core/src/main/java/io/shardingsphere/orchestration/yaml/YamlOrchestrationConfiguration.java @@ -19,7 +19,6 @@ import com.google.common.base.Preconditions; import io.shardingsphere.orchestration.config.OrchestrationConfiguration; -import io.shardingsphere.orchestration.config.OrchestrationType; import io.shardingsphere.orchestration.reg.etcd.EtcdConfiguration; import io.shardingsphere.orchestration.reg.zookeeper.ZookeeperConfiguration; import lombok.Getter; @@ -29,6 +28,7 @@ * Orchestration configuration for yaml. * * @author caohao + * @author panjuan */ @Getter @Setter @@ -42,8 +42,6 @@ public class YamlOrchestrationConfiguration { private boolean overwrite; - private OrchestrationType type; - /** * Get orchestration master-slave rule configuration from yaml. * @@ -51,6 +49,6 @@ public class YamlOrchestrationConfiguration { */ public OrchestrationConfiguration getOrchestrationConfiguration() { Preconditions.checkState(null == etcd || null == zookeeper, "Can't config both zookeeper and etcd as registry center!"); - return new OrchestrationConfiguration(getName(), null != etcd ? etcd : zookeeper, overwrite, type); + return new OrchestrationConfiguration(getName(), null != etcd ? etcd : zookeeper, overwrite); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/Bootstrap.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/Bootstrap.java index 462d9bb61ec5a..935e5577efb46 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/Bootstrap.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/Bootstrap.java @@ -92,7 +92,7 @@ private static void startWithRegistryCenter( orchestrationFacade.init(getYamlServerConfiguration(serverConfig), getSchemaDataSourceMap(ruleConfigs), getRuleConfiguration(ruleConfigs)); } GlobalRegistry.getInstance().init(orchestrationFacade.getConfigService().loadYamlServerConfiguration(), - orchestrationFacade.getConfigService().loadProxyDataSources(), orchestrationFacade.getConfigService().loadProxyConfiguration()); + orchestrationFacade.getConfigService().loadProxyDataSources(), orchestrationFacade.getConfigService().loadProxyConfiguration(), true); initOpenTracing(); new ShardingProxy().start(port); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCBackendDataSource.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCBackendDataSource.java index 80e695873816e..6edc5d87add27 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCBackendDataSource.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/datasource/JDBCBackendDataSource.java @@ -22,13 +22,13 @@ import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.shardingproxy.backend.BackendDataSource; import io.shardingsphere.shardingproxy.runtime.GlobalRegistry; -import io.shardingsphere.shardingproxy.runtime.ShardingSchema; import javax.sql.DataSource; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -44,22 +44,22 @@ */ public final class JDBCBackendDataSource implements BackendDataSource, AutoCloseable { - private final ShardingSchema shardingSchema; + private final Map dataSources; - private final Map dataSourceMap; + private final Map availableDataSources; - public JDBCBackendDataSource(final ShardingSchema shardingSchema) { - this.shardingSchema = shardingSchema; - dataSourceMap = createDataSourceMap(); + public JDBCBackendDataSource(final Map dataSourceParameters) { + dataSources = createDataSourceMap(dataSourceParameters); + availableDataSources = new LinkedHashMap<>(dataSources); } - private Map createDataSourceMap() { + private Map createDataSourceMap(final Map dataSourceParameters) { // TODO getCircuitDataSourceMap if getCircuitBreakerDataSourceNames() is not empty - return getNormalDataSourceMap(shardingSchema.getDataSources()); + return getNormalDataSourceMap(dataSourceParameters); } private Map getNormalDataSourceMap(final Map dataSourceParameters) { - Map result = new LinkedHashMap<>(dataSourceParameters.size()); + Map result = new LinkedHashMap<>(dataSourceParameters.size(), 1); for (Entry entry : dataSourceParameters.entrySet()) { try { result.put(entry.getKey(), getBackendDataSourceFactory().build(entry.getKey(), entry.getValue())); @@ -81,6 +81,22 @@ private JDBCBackendDataSourceFactory getBackendDataSourceFactory() { } } + /** + * Set available data sources. + * + * @param disabledDataSourceNames disabled data source names + */ + public void setAvailableDataSources(final Collection disabledDataSourceNames) { + synchronized (availableDataSources) { + availableDataSources.clear(); + for (Entry entry : dataSources.entrySet()) { + if (!disabledDataSourceNames.contains(entry.getKey())) { + availableDataSources.put(entry.getKey(), entry.getValue()); + } + } + } + } + /** * Get connection. * @@ -103,7 +119,7 @@ public Connection getConnection(final String dataSourceName) throws SQLException */ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") public List getConnections(final ConnectionMode connectionMode, final String dataSourceName, final int connectionSize) throws SQLException { - DataSource dataSource = getDataSourceMap().get(dataSourceName); + DataSource dataSource = availableDataSources.get(dataSourceName); if (1 == connectionSize) { return Collections.singletonList(dataSource.getConnection()); } @@ -115,18 +131,6 @@ public List getConnections(final ConnectionMode connectionMode, fina } } - private Map getDataSourceMap() { - return shardingSchema.getDisabledDataSourceNames().isEmpty() ? dataSourceMap : getAvailableDataSourceMap(); - } - - private Map getAvailableDataSourceMap() { - Map result = new LinkedHashMap<>(dataSourceMap); - for (String each : shardingSchema.getDisabledDataSourceNames()) { - result.remove(each); - } - return result; - } - private List createConnections(final DataSource dataSource, final int connectionSize) throws SQLException { List result = new ArrayList<>(connectionSize); for (int i = 0; i < connectionSize; i++) { @@ -141,7 +145,7 @@ public void close() { } private void closeOriginalDataSources() { - for (DataSource each : dataSourceMap.values()) { + for (DataSource each : dataSources.values()) { try { Method method = each.getClass().getDeclaredMethod("close"); method.invoke(each); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java index df49504b29dc4..a104c077b42d1 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java @@ -26,16 +26,21 @@ import io.shardingsphere.core.executor.ShardingExecuteEngine; import io.shardingsphere.core.rule.Authentication; import io.shardingsphere.core.rule.DataSourceParameter; +import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.yaml.YamlRuleConfiguration; import io.shardingsphere.core.yaml.other.YamlServerConfiguration; import io.shardingsphere.orchestration.internal.event.config.ProxyConfigurationEventBusEvent; import io.shardingsphere.orchestration.internal.event.state.CircuitStateEventBusEvent; +import io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent; import io.shardingsphere.orchestration.internal.event.state.ProxyDisabledStateEventBusEvent; +import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule; +import io.shardingsphere.orchestration.internal.rule.OrchestrationShardingRule; import io.shardingsphere.shardingproxy.runtime.nio.BackendNIOConfiguration; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -102,11 +107,23 @@ public void register() { * @param schemaRules schema rule map */ public void init(final YamlServerConfiguration serverConfig, final Map> schemaDataSources, final Map schemaRules) { + init(serverConfig, schemaDataSources, schemaRules, false); + } + + /** + * Initialize proxy context. + * + * @param serverConfig server configuration + * @param schemaDataSources data source map + * @param schemaRules schema rule map + * @param isUsingRegistry is using registry or not + */ + public void init(final YamlServerConfiguration serverConfig, final Map> schemaDataSources, final Map schemaRules, final boolean isUsingRegistry) { initServerConfiguration(serverConfig); for (Entry entry : schemaRules.entrySet()) { String schemaName = entry.getKey(); schemaNames.add(schemaName); - shardingSchemas.put(schemaName, new ShardingSchema(schemaName, schemaDataSources.get(schemaName), entry.getValue())); + shardingSchemas.put(schemaName, new ShardingSchema(schemaName, schemaDataSources.get(schemaName), entry.getValue(), isUsingRegistry)); } } @@ -174,7 +191,7 @@ public void renew(final ProxyConfigurationEventBusEvent proxyConfigurationEventB shardingSchemas.clear(); for (Entry> entry : proxyConfigurationEventBusEvent.getSchemaDataSourceMap().entrySet()) { String schemaName = entry.getKey(); - shardingSchemas.put(schemaName, new ShardingSchema(schemaName, entry.getValue(), proxyConfigurationEventBusEvent.getSchemaRuleMap().get(schemaName))); + shardingSchemas.put(schemaName, new ShardingSchema(schemaName, entry.getValue(), proxyConfigurationEventBusEvent.getSchemaRuleMap().get(schemaName), true)); } } @@ -196,7 +213,30 @@ public void renewCircuitBreakerDataSourceNames(final CircuitStateEventBusEvent c @Subscribe public void renewDisabledDataSourceNames(final ProxyDisabledStateEventBusEvent disabledStateEventBusEvent) { for (Entry entry : shardingSchemas.entrySet()) { - entry.getValue().setDisabledDataSourceNames(disabledStateEventBusEvent.getDisabledSchemaDataSourceMap().get(entry.getKey())); + DisabledStateEventBusEvent disabledEvent = new DisabledStateEventBusEvent(getDisabledDataSourceNames(entry.getKey(), disabledStateEventBusEvent.getDisabledSchemaDataSourceMap())); + if (entry.getValue().isMasterSlaveOnly()) { + renewShardingSchemaWithMasterSlaveRule(entry.getValue(), disabledEvent); + } else { + renewShardingSchemaWithShardingRule(entry.getValue(), disabledEvent); + } } } + + private Collection getDisabledDataSourceNames(final String shardingSchemaName, final Map> disabledSchemaDataSourceMap) { + Collection result = new LinkedList<>(); + if (disabledSchemaDataSourceMap.containsKey(shardingSchemaName)) { + result.addAll(disabledSchemaDataSourceMap.get(shardingSchemaName)); + } + return result; + } + + private void renewShardingSchemaWithShardingRule(final ShardingSchema shardingSchema, final DisabledStateEventBusEvent disabledEvent) { + for (MasterSlaveRule each : ((OrchestrationShardingRule) shardingSchema.getShardingRule()).getMasterSlaveRules()) { + ((OrchestrationMasterSlaveRule) each).renew(disabledEvent); + } + } + + private void renewShardingSchemaWithMasterSlaveRule(final ShardingSchema shardingSchema, final DisabledStateEventBusEvent disabledEvent) { + ((OrchestrationMasterSlaveRule) shardingSchema.getMasterSlaveRule()).renew(disabledEvent); + } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/ShardingSchema.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/ShardingSchema.java index bbfe3f1fa2ffb..cddc029eee782 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/ShardingSchema.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/ShardingSchema.java @@ -25,14 +25,13 @@ import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.core.yaml.YamlRuleConfiguration; +import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule; +import io.shardingsphere.orchestration.internal.rule.OrchestrationShardingRule; import io.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.shardingproxy.runtime.metadata.ProxyTableMetaDataConnectionManager; import lombok.Getter; -import lombok.Setter; -import java.util.Collection; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; @@ -60,16 +59,25 @@ public final class ShardingSchema { private ShardingMetaData metaData; - @Setter - private Collection disabledDataSourceNames = new LinkedList<>(); - - public ShardingSchema(final String name, final Map dataSources, final YamlRuleConfiguration rule) { + public ShardingSchema(final String name, final Map dataSources, final YamlRuleConfiguration rule, final boolean isUsingRegistry) { this.name = name; // TODO :jiaqi only use JDBC need connect db via JDBC, netty style should use SQL packet to get metadata this.dataSources = dataSources; - shardingRule = new ShardingRule(null == rule.getShardingRule() ? new ShardingRuleConfiguration() : rule.getShardingRule().getShardingRuleConfiguration(), dataSources.keySet()); - masterSlaveRule = null == rule.getMasterSlaveRule() ? null : new MasterSlaveRule(rule.getMasterSlaveRule().getMasterSlaveRuleConfiguration()); - backendDataSource = new JDBCBackendDataSource(this); + shardingRule = getShardingRule(rule, isUsingRegistry); + masterSlaveRule = getMasterSlaveRule(rule, isUsingRegistry); + backendDataSource = new JDBCBackendDataSource(dataSources); + } + + private ShardingRule getShardingRule(final YamlRuleConfiguration rule, final boolean isUsingRegistry) { + return isUsingRegistry ? new OrchestrationShardingRule(null == rule.getShardingRule() ? new ShardingRuleConfiguration() : rule.getShardingRule().getShardingRuleConfiguration(), dataSources.keySet()) + : new ShardingRule(null == rule.getShardingRule() ? new ShardingRuleConfiguration() : rule.getShardingRule().getShardingRuleConfiguration(), dataSources.keySet()); + } + + private MasterSlaveRule getMasterSlaveRule(final YamlRuleConfiguration rule, final boolean isUsingRegistry) { + if (null == rule.getMasterSlaveRule()) { + return null; + } + return isUsingRegistry ? new OrchestrationMasterSlaveRule(rule.getMasterSlaveRule().getMasterSlaveRuleConfiguration()) : new MasterSlaveRule(rule.getMasterSlaveRule().getMasterSlaveRuleConfiguration()); } /** @@ -98,24 +106,4 @@ private Map getDataSourceURLs(final Map getDataSources() { - if (!getDisabledDataSourceNames().isEmpty()) { - return getAvailableDataSourceConfigurationMap(); - } - return dataSources; - } - - private Map getAvailableDataSourceConfigurationMap() { - Map result = new LinkedHashMap<>(dataSources); - for (String each : disabledDataSourceNames) { - result.remove(each); - } - return result; - } }