This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 841553a Support sharding sphere jdbc as data source (#7657)
841553a is described below
commit 841553a2f08abd677064cd333c4bb5af9f8c5a21
Author: avalon5666 <[email protected]>
AuthorDate: Tue Sep 29 15:11:15 2020 +0800
Support sharding sphere jdbc as data source (#7657)
* * Refactor scaling configuration
* Support sharding sphere jdbc as data source
* Fixed naming
* Fixed spelling
---
.../user-manual/shardingsphere-scaling/usage.cn.md | 139 ++++++++++++--------
.../user-manual/shardingsphere-scaling/usage.en.md | 145 +++++++++++++--------
.../scaling/web/HttpServerHandlerTest.java | 10 ++
.../src/test/resources/config.json | 16 ++-
.../config_sharding_sphere_jdbc_target.json | 38 ++++++
.../shardingsphere-scaling-core/pom.xml | 5 +
.../core/check/AbstractDataConsistencyChecker.java | 19 +--
.../core/config/DataSourceConfiguration.java | 8 --
.../core/config/JDBCDataSourceConfiguration.java | 6 -
.../scaling/core/config/RuleConfiguration.java | 33 +++--
...n.java => ShardingSphereJDBCConfiguration.java} | 30 ++---
.../scaling/core/datasource/DataSourceFactory.java | 20 +++
.../scaling/core/datasource/DataSourceWrapper.java | 2 +-
.../scaling/core/utils/SyncConfigurationUtil.java | 12 +-
.../scaling/core/config/RuleConfigurationTest.java | 74 +++++++++++
.../ShardingSphereJDBCConfigurationTest.java} | 38 ++----
.../core/datasource/DataSourceFactoryTest.java | 49 +++++++
.../FixtureShardingSphereJDBCConfiguration.java | 32 +++++
.../src/test/resources/config.json | 22 +++-
19 files changed, 484 insertions(+), 214 deletions(-)
diff --git
a/docs/document/content/user-manual/shardingsphere-scaling/usage.cn.md
b/docs/document/content/user-manual/shardingsphere-scaling/usage.cn.md
index 7464e29..bca4f70 100644
--- a/docs/document/content/user-manual/shardingsphere-scaling/usage.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-scaling/usage.cn.md
@@ -53,16 +53,41 @@ PostgreSQL 需要开启
[test_decoding](https://www.postgresql.org/docs/9.4/test
请求体:
-| 参数 | 描述
|
+| 参数 | 描述
|
| ------------------------------------------------- |
------------------------------------------------------------ |
-| ruleConfiguration.sourceDataSource | 源端sharding sphere数据源相关配置
|
-| ruleConfiguration.sourceRule | 源端sharding sphere表规则相关配置
|
-| ruleConfiguration.targetDataSources.name | 目标端sharding proxy名称
|
-| ruleConfiguration.targetDataSources.url | 目标端sharding proxy jdbc
url |
-| ruleConfiguration.targetDataSources.username | 目标端sharding proxy用户名
|
-| ruleConfiguration.targetDataSources.password | 目标端sharding proxy密码
|
+| ruleConfiguration.source | 源端数据源相关配置
|
+| ruleConfiguration.target | 目标端数据源相关配置
|
| jobConfiguration.concurrency |
迁移并发度,举例:如果设置为3,则待迁移的表将会有三个线程同时对该表进行迁移,前提是该表有整数型主键 |
+数据源配置:
+
+| 参数 | 描述
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| type |
数据源类型(可选参数:shardingSphereJdbc、jdbc) |
+| parameter | 数据源参数
|
+
+Parameter配置:
+
+type = shardingSphereJdbc
+
+| 参数 | 描述
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| dataSource | 源端sharding sphere数据源相关配置
|
+| rule | 源端sharding sphere表规则相关配置
|
+
+type = jdbc
+
+| 参数 | 描述
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| name | jdbc 名称
|
+| ruleConfiguration.targetDataSources.url | jdbc 连接
|
+| ruleConfiguration.targetDataSources.username | jdbc 用户
|
+| ruleConfiguration.targetDataSources.password | jdbc 密码
|
+
+*** 注意 ***
+
+当前 source type 必须是 shardingSphereJdbc
+
示例:
```
@@ -71,52 +96,60 @@ curl -X POST \
-H 'content-type: application/json' \
-d '{
"ruleConfiguration": {
- "sourceDataSource":"
- dataSources:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- props:
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/scaling_0?useSSL=false
- username: scaling
- password: scaling
- ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- props:
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/scaling_1?useSSL=false
- username: scaling
- password: scaling
- ",
- "sourceRule":"
- rules:
- - !SHARDING
- tables:
- t_order:
- actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
- databaseStrategy:
- standard:
- shardingColumn: order_id
- shardingAlgorithmName: t_order_db_algorith
- logicTable: t_order
- tableStrategy:
- standard:
- shardingColumn: user_id
- shardingAlgorithmName: t_order_tbl_algorith
- shardingAlgorithms:
- t_order_db_algorith:
- type: INLINE
- props:
- algorithm-expression: ds_$->{order_id % 2}
- t_order_tbl_algorith:
- type: INLINE
- props:
- algorithm-expression: t_order_$->{user_id % 2}
- ",
- "targetDataSources":{
- "username":"root",
- "password":"root",
-
"url":"jdbc:mysql://127.0.0.1:3307/sharding_db?serverTimezone=UTC&useSSL=false"
+ "source": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource":"
+ dataSources:
+ ds_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ driverClassName: com.mysql.jdbc.Driver
+ jdbcUrl:
jdbc:mysql://127.0.0.1:3306/scaling_0?useSSL=false
+ username: scaling
+ password: scaling
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ driverClassName: com.mysql.jdbc.Driver
+ jdbcUrl:
jdbc:mysql://127.0.0.1:3306/scaling_1?useSSL=false
+ username: scaling
+ password: scaling
+ ",
+ "rule":"
+ rules:
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_db_algorith
+ logicTable: t_order
+ tableStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: t_order_tbl_algorith
+ shardingAlgorithms:
+ t_order_db_algorith:
+ type: INLINE
+ props:
+ algorithm-expression: ds_$->{order_id % 2}
+ t_order_tbl_algorith:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_$->{user_id % 2}
+ "
+ }
+ },
+ "target": {
+ "type": "jdbc",
+ "parameter": {
+ "username": "root",
+ "password": "root",
+ "url":
"jdbc:mysql://127.0.0.1:3307/sharding_db?serverTimezone=UTC&useSSL=false"
+ }
}
},
"jobConfiguration":{
diff --git
a/docs/document/content/user-manual/shardingsphere-scaling/usage.en.md
b/docs/document/content/user-manual/shardingsphere-scaling/usage.en.md
index d39f856..2d6f586 100644
--- a/docs/document/content/user-manual/shardingsphere-scaling/usage.en.md
+++ b/docs/document/content/user-manual/shardingsphere-scaling/usage.en.md
@@ -51,17 +51,42 @@ ShardingSphere-Scaling provides a simple HTTP API
Interface description:POST /scaling/job/start
-Body:
+Body:
+
+| Parameter | Describe
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| ruleConfiguration.source | source data source
configuration |
+| ruleConfiguration.target | target data source
configuration |
+| jobConfiguration.concurrency | sync task proposed
concurrency |
+
+Data source configuration:
+
+| Parameter | Describe
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| type | data source
type(available parameters:shardingSphereJdbc,jdbc)|
+| parameter | data source parameter
|
+
+Parameter configuration:
+
+type = shardingSphereJdbc
-| Parameter | Describe
|
-|---------------------------------------------------|-------------------------------------------------|
-| ruleConfiguration.sourceDataSource | source sharding sphere
data source configuration |
-| ruleConfiguration.sourceRule | source sharding sphere
table rule configuration |
-| ruleConfiguration.targetDataSources.name | target sharding proxy
name |
-| ruleConfiguration.targetDataSources.url | target sharding proxy
jdbc url |
-| ruleConfiguration.targetDataSources.username | target sharding proxy
username |
-| ruleConfiguration.targetDataSources.password | target sharding proxy
password |
-| jobConfiguration.concurrency | sync task proposed
concurrency |
+| Parameter | Describe
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| dataSource | sharding sphere data
source configuration |
+| rule | sharding sphere data
source table rule |
+
+type = jdbc
+
+| Parameter | Describe
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| name | jdbc name
|
+| ruleConfiguration.targetDataSources.url | jdbc url
|
+| ruleConfiguration.targetDataSources.username | jdbc username
|
+| ruleConfiguration.targetDataSources.password | jdbc password
|
+
+*** Notice ***
+
+Currently source type must shardingSphereJdbc
Example:
@@ -71,52 +96,60 @@ curl -X POST \
-H 'content-type: application/json' \
-d '{
"ruleConfiguration": {
- "sourceDataSource":"
- dataSources:
- ds_0:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- props:
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/scaling_0?useSSL=false
- username: scaling
- password: scaling
- ds_1:
- dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- props:
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/scaling_1?useSSL=false
- username: scaling
- password: scaling
- ",
- "sourceRule":"
- rules:
- - !SHARDING
- tables:
- t_order:
- actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
- databaseStrategy:
- standard:
- shardingColumn: order_id
- shardingAlgorithmName: t_order_db_algorith
- logicTable: t_order
- tableStrategy:
- standard:
- shardingColumn: user_id
- shardingAlgorithmName: t_order_tbl_algorith
- shardingAlgorithms:
- t_order_db_algorith:
- type: INLINE
- props:
- algorithm-expression: ds_$->{order_id % 2}
- t_order_tbl_algorith:
- type: INLINE
- props:
- algorithm-expression: t_order_$->{user_id % 2}
- ",
- "targetDataSources":{
- "username":"root",
- "password":"root",
-
"url":"jdbc:mysql://127.0.0.1:3307/sharding_db?serverTimezone=UTC&useSSL=false"
+ "source": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource":"
+ dataSources:
+ ds_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ driverClassName: com.mysql.jdbc.Driver
+ jdbcUrl:
jdbc:mysql://127.0.0.1:3306/scaling_0?useSSL=false
+ username: scaling
+ password: scaling
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ driverClassName: com.mysql.jdbc.Driver
+ jdbcUrl:
jdbc:mysql://127.0.0.1:3306/scaling_1?useSSL=false
+ username: scaling
+ password: scaling
+ ",
+ "rule":"
+ rules:
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_$->{0..1}.t_order_$->{0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_db_algorith
+ logicTable: t_order
+ tableStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: t_order_tbl_algorith
+ shardingAlgorithms:
+ t_order_db_algorith:
+ type: INLINE
+ props:
+ algorithm-expression: ds_$->{order_id % 2}
+ t_order_tbl_algorith:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_$->{user_id % 2}
+ "
+ }
+ },
+ "target": {
+ "type": "jdbc",
+ "parameter": {
+ "username": "root",
+ "password": "root",
+ "url":
"jdbc:mysql://127.0.0.1:3307/sharding_db?serverTimezone=UTC&useSSL=false"
+ }
}
},
"jobConfiguration":{
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/java/org/apache/shardingsphere/scaling/web/HttpServerHandlerTest.java
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/java/org/apache/shardingsphere/scaling/web/HttpServerHandlerTest.java
index a0dd379..9ae9a18 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/java/org/apache/shardingsphere/scaling/web/HttpServerHandlerTest.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/java/org/apache/shardingsphere/scaling/web/HttpServerHandlerTest.java
@@ -78,6 +78,16 @@ public final class HttpServerHandlerTest {
}
@Test
+ public void assertShardingSphereJDBCTargetChannelReadStartSuccess() {
+ initConfig("/config_sharding_sphere_jdbc_target.json");
+ startScalingJob();
+ ArgumentCaptor<FullHttpResponse> argumentCaptor =
ArgumentCaptor.forClass(FullHttpResponse.class);
+ verify(channelHandlerContext).writeAndFlush(argumentCaptor.capture());
+ FullHttpResponse fullHttpResponse = argumentCaptor.getValue();
+
assertTrue(fullHttpResponse.content().toString(CharsetUtil.UTF_8).contains("{\"success\":true"));
+ }
+
+ @Test
public void assertChannelReadProgressFail() {
fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.GET, "/scaling/job/progress/9");
httpServerHandler.channelRead0(channelHandlerContext, fullHttpRequest);
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config.json
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config.json
index 9096b8c..4eb01bd 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config.json
+++
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config.json
@@ -17,14 +17,22 @@
{
"ruleConfiguration": {
- "sourceDataSource":"dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: '123456'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
- "sourceRule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item [...]
- "targetDataSources": {
+ "source": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource": "dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: '123456'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
+ "rule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item_i [...]
+ }
+ },
+ "target": {
+ "type": "jdbc",
+ "parameter": {
"name": "dt_0",
- "url":
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
+ "jdbcUrl":
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
"username": "root",
"password": "password"
}
+ }
},
"jobConfiguration": {
"concurrency": 3
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config_sharding_sphere_jdbc_target.json
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config_sharding_sphere_jdbc_target.json
new file mode 100644
index 0000000..096ebf2
--- /dev/null
+++
b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/test/resources/config_sharding_sphere_jdbc_target.json
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "ruleConfiguration": {
+ "source": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource": "dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: '123456'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
+ "rule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item_i [...]
+ }
+ },
+ "target": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource": "dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: '123456'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
+ "rule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item_i [...]
+ }
+ }
+ },
+ "jobConfiguration": {
+ "concurrency": 3
+ }
+}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
b/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
index 9272041..e2a0edc 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
@@ -55,6 +55,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<scope>compile</scope>
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/check/AbstractDataConsistencyChecker.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/check/AbstractDataConsistencyChecker.java
index ae8ce84..5561496 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/check/AbstractDataConsistencyChecker.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/check/AbstractDataConsistencyChecker.java
@@ -17,21 +17,14 @@
package org.apache.shardingsphere.scaling.core.check;
-import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
-import
org.apache.shardingsphere.scaling.core.config.JDBCDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.RuleConfiguration;
import org.apache.shardingsphere.scaling.core.datasource.DataSourceFactory;
import org.apache.shardingsphere.scaling.core.datasource.DataSourceWrapper;
import org.apache.shardingsphere.scaling.core.exception.DataCheckFailException;
import
org.apache.shardingsphere.scaling.core.execute.executor.importer.AbstractSqlBuilder;
import org.apache.shardingsphere.scaling.core.job.ShardingScalingJob;
-import org.apache.shardingsphere.scaling.core.utils.ConfigurationYamlConverter;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import javax.sql.DataSource;
import java.io.IOException;
@@ -83,19 +76,11 @@ public abstract class AbstractDataConsistencyChecker
implements DataConsistencyC
}
protected DataSourceWrapper getSourceDataSource() {
- try {
- Map<String, DataSource> dataSourceMap =
DataSourceConverter.getDataSourceMap(
-
ConfigurationYamlConverter.loadDataSourceConfigurations(shardingScalingJob.getScalingConfiguration().getRuleConfiguration().getSourceDataSource()));
- ShardingRuleConfiguration ruleConfiguration =
ConfigurationYamlConverter.loadShardingRuleConfiguration(shardingScalingJob.getScalingConfiguration().getRuleConfiguration().getSourceRule());
- return new
DataSourceWrapper(ShardingSphereDataSourceFactory.createDataSource(dataSourceMap,
Lists.newArrayList(ruleConfiguration), null));
- } catch (SQLException ex) {
- throw new DataCheckFailException("get source data source failed.",
ex);
- }
+ return new
DataSourceFactory().newInstance(shardingScalingJob.getScalingConfiguration().getRuleConfiguration().getSource().toTypedDataSourceConfiguration());
}
protected DataSourceWrapper getTargetDataSource() {
- RuleConfiguration.YamlDataSourceParameter parameter =
shardingScalingJob.getScalingConfiguration().getRuleConfiguration().getTargetDataSources();
- return new DataSourceWrapper(new DataSourceFactory().newInstance(new
JDBCDataSourceConfiguration(parameter.getUrl(), parameter.getUsername(),
parameter.getPassword())));
+ return new
DataSourceFactory().newInstance(shardingScalingJob.getScalingConfiguration().getRuleConfiguration().getTarget().toTypedDataSourceConfiguration());
}
protected abstract AbstractSqlBuilder getSqlBuilder();
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/DataSourceConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/DataSourceConfiguration.java
index 04f1009..d42b94c 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/DataSourceConfiguration.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/DataSourceConfiguration.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.scaling.core.config;
-import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
/**
@@ -31,11 +30,4 @@ public interface DataSourceConfiguration {
* @return database type
*/
DatabaseType getDatabaseType();
-
- /**
- * Get data source metadata.
- *
- * @return data source metadata.
- */
- DataSourceMetaData getDataSourceMetaData();
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
index 2f8d36b..ce21f7e 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.scaling.core.config;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
@@ -46,9 +45,4 @@ public final class JDBCDataSourceConfiguration implements
DataSourceConfiguratio
this.password = password;
databaseType = DatabaseTypes.getDatabaseTypeByURL(jdbcUrl);
}
-
- @Override
- public DataSourceMetaData getDataSourceMetaData() {
- return databaseType.getDataSourceMetaData(jdbcUrl, username);
- }
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
index 0ec30bb..e82b2e8 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.scaling.core.config;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
@@ -27,22 +29,31 @@ import lombok.Setter;
@Getter
public final class RuleConfiguration {
- private String sourceDataSource;
+ private DataSourceConf source;
- private String sourceRule;
-
- private YamlDataSourceParameter targetDataSources;
+ private DataSourceConf target;
@Setter
@Getter
- public static final class YamlDataSourceParameter {
-
- private String name;
+ public static class DataSourceConf {
- private String url;
+ private String type;
- private String username;
-
- private String password;
+ private JsonObject parameter;
+
+ /**
+ * Get typed data source configuration.
+ *
+ * @return data source configuration
+ */
+ public DataSourceConfiguration toTypedDataSourceConfiguration() {
+ if ("jdbc".equalsIgnoreCase(type)) {
+ return new Gson().fromJson(parameter,
JDBCDataSourceConfiguration.class);
+ }
+ if ("shardingSphereJdbc".equalsIgnoreCase(type)) {
+ return new Gson().fromJson(parameter,
ShardingSphereJDBCConfiguration.class);
+ }
+ throw new UnsupportedOperationException("Unsupported Data Source
Type:" + type);
+ }
}
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfiguration.java
similarity index 62%
copy from
shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
copy to
shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfiguration.java
index 2f8d36b..9f8a81f 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JDBCDataSourceConfiguration.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfiguration.java
@@ -20,35 +20,27 @@ package org.apache.shardingsphere.scaling.core.config;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
+import org.apache.shardingsphere.scaling.core.utils.ConfigurationYamlConverter;
+
+import java.util.Map;
-/**
- * JDBC data source configuration.
- */
@Getter
@Setter
@EqualsAndHashCode(exclude = "databaseType")
-public final class JDBCDataSourceConfiguration implements
DataSourceConfiguration {
-
- private String jdbcUrl;
+public class ShardingSphereJDBCConfiguration implements
DataSourceConfiguration {
- private String username;
+ private String dataSource;
- private String password;
+ private String rule;
private DatabaseType databaseType;
- public JDBCDataSourceConfiguration(final String jdbcUrl, final String
username, final String password) {
- this.jdbcUrl = jdbcUrl;
- this.username = username;
- this.password = password;
- databaseType = DatabaseTypes.getDatabaseTypeByURL(jdbcUrl);
- }
-
- @Override
- public DataSourceMetaData getDataSourceMetaData() {
- return databaseType.getDataSourceMetaData(jdbcUrl, username);
+ public ShardingSphereJDBCConfiguration(final String dataSource, final
String rule) {
+ this.dataSource = dataSource;
+ this.rule = rule;
+ Map<String,
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration>
sourceDataSource =
ConfigurationYamlConverter.loadDataSourceConfigurations(dataSource);
+ this.databaseType =
DatabaseTypes.getDatabaseTypeByURL(sourceDataSource.values().iterator().next().getProps().get("jdbcUrl").toString());
}
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactory.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactory.java
index d09390e..e9ba95c 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactory.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactory.java
@@ -17,9 +17,19 @@
package org.apache.shardingsphere.scaling.core.datasource;
+import com.google.common.collect.Lists;
import com.zaxxer.hikari.HikariDataSource;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
import org.apache.shardingsphere.scaling.core.config.DataSourceConfiguration;
import
org.apache.shardingsphere.scaling.core.config.JDBCDataSourceConfiguration;
+import
org.apache.shardingsphere.scaling.core.config.ShardingSphereJDBCConfiguration;
+import org.apache.shardingsphere.scaling.core.utils.ConfigurationYamlConverter;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+
+import javax.sql.DataSource;
+import java.util.Map;
/**
* Data source factory.
@@ -35,6 +45,8 @@ public final class DataSourceFactory {
public DataSourceWrapper newInstance(final DataSourceConfiguration
dataSourceConfiguration) {
if (dataSourceConfiguration instanceof JDBCDataSourceConfiguration) {
return newInstanceDataSourceByJDBC((JDBCDataSourceConfiguration)
dataSourceConfiguration);
+ } else if (dataSourceConfiguration instanceof
ShardingSphereJDBCConfiguration) {
+ return
newInstanceDataSourceByShardingSphereJDBC((ShardingSphereJDBCConfiguration)
dataSourceConfiguration);
}
throw new UnsupportedOperationException("Unsupported data source
configuration");
}
@@ -46,4 +58,12 @@ public final class DataSourceFactory {
result.setPassword(dataSourceConfiguration.getPassword());
return new DataSourceWrapper(result);
}
+
+ @SneakyThrows
+ private DataSourceWrapper newInstanceDataSourceByShardingSphereJDBC(final
ShardingSphereJDBCConfiguration dataSourceConfiguration) {
+ Map<String, DataSource> dataSourceMap =
DataSourceConverter.getDataSourceMap(
+
ConfigurationYamlConverter.loadDataSourceConfigurations(dataSourceConfiguration.getDataSource()));
+ ShardingRuleConfiguration ruleConfiguration =
ConfigurationYamlConverter.loadShardingRuleConfiguration(dataSourceConfiguration.getRule());
+ return new
DataSourceWrapper(ShardingSphereDataSourceFactory.createDataSource(dataSourceMap,
Lists.newArrayList(ruleConfiguration), null));
+ }
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceWrapper.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceWrapper.java
index 522e6dc..323c2d2 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceWrapper.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceWrapper.java
@@ -31,7 +31,7 @@ import java.util.logging.Logger;
* Data source wrapper is for abstract standard jdbc and sharding jdbc.
*/
@RequiredArgsConstructor
-public class DataSourceWrapper implements DataSource, AutoCloseable {
+public final class DataSourceWrapper implements DataSource, AutoCloseable {
private final DataSource dataSource;
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/utils/SyncConfigurationUtil.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/utils/SyncConfigurationUtil.java
index 35fe8b1..3c84d07 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/utils/SyncConfigurationUtil.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/utils/SyncConfigurationUtil.java
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.scaling.core.config.ImporterConfiguration;
import
org.apache.shardingsphere.scaling.core.config.JDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.JobConfiguration;
import org.apache.shardingsphere.scaling.core.config.ScalingConfiguration;
+import
org.apache.shardingsphere.scaling.core.config.ShardingSphereJDBCConfiguration;
import org.apache.shardingsphere.scaling.core.config.SyncConfiguration;
import
org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineExpressionParser;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -60,8 +61,9 @@ public final class SyncConfigurationUtil {
*/
public static Collection<SyncConfiguration> toSyncConfigurations(final
ScalingConfiguration scalingConfiguration) {
Collection<SyncConfiguration> result = new LinkedList<>();
- Map<String, DataSourceConfiguration> sourceDataSource =
ConfigurationYamlConverter.loadDataSourceConfigurations(scalingConfiguration.getRuleConfiguration().getSourceDataSource());
- ShardingRuleConfiguration sourceRule =
ConfigurationYamlConverter.loadShardingRuleConfiguration(scalingConfiguration.getRuleConfiguration().getSourceRule());
+ ShardingSphereJDBCConfiguration shardingSphereJDBCConfiguration =
(ShardingSphereJDBCConfiguration)
scalingConfiguration.getRuleConfiguration().getSource().toTypedDataSourceConfiguration();
+ Map<String, DataSourceConfiguration> sourceDataSource =
ConfigurationYamlConverter.loadDataSourceConfigurations(shardingSphereJDBCConfiguration.getDataSource());
+ ShardingRuleConfiguration sourceRule =
ConfigurationYamlConverter.loadShardingRuleConfiguration(shardingSphereJDBCConfiguration.getRule());
Map<String, Map<String, String>> dataSourceTableNameMap =
toDataSourceTableNameMap(sourceRule, sourceDataSource.keySet());
filterByShardingDataSourceTables(dataSourceTableNameMap,
scalingConfiguration.getJobConfiguration());
for (Entry<String, Map<String, String>> entry :
dataSourceTableNameMap.entrySet()) {
@@ -162,11 +164,7 @@ public final class SyncConfigurationUtil {
private static ImporterConfiguration createImporterConfiguration(final
ScalingConfiguration scalingConfiguration, final ShardingRuleConfiguration
shardingRuleConfig) {
ImporterConfiguration result = new ImporterConfiguration();
- JDBCDataSourceConfiguration importerDataSourceConfiguration = new
JDBCDataSourceConfiguration(
-
scalingConfiguration.getRuleConfiguration().getTargetDataSources().getUrl(),
-
scalingConfiguration.getRuleConfiguration().getTargetDataSources().getUsername(),
-
scalingConfiguration.getRuleConfiguration().getTargetDataSources().getPassword());
- result.setDataSourceConfiguration(importerDataSourceConfiguration);
+
result.setDataSourceConfiguration(scalingConfiguration.getRuleConfiguration().getTarget().toTypedDataSourceConfiguration());
result.setShardingColumnsMap(toShardingColumnsMap(shardingRuleConfig));
return result;
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/RuleConfigurationTest.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/RuleConfigurationTest.java
new file mode 100644
index 0000000..07a2d36
--- /dev/null
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/RuleConfigurationTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.scaling.core.config;
+
+import com.google.gson.JsonObject;
+import
org.apache.shardingsphere.scaling.core.fixture.FixtureShardingSphereJDBCConfiguration;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class RuleConfigurationTest {
+
+ @Test
+ public void assertToJDBConfiguration() {
+ RuleConfiguration.DataSourceConf dataSourceConf = new
RuleConfiguration.DataSourceConf();
+ dataSourceConf.setType("jdbc");
+ String jdbcUrl =
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL";
+ String username = "root";
+ String password = "password";
+ dataSourceConf.setParameter(mockJDBCConfiguration(jdbcUrl, username,
password));
+ DataSourceConfiguration actual =
dataSourceConf.toTypedDataSourceConfiguration();
+ assertThat(actual, instanceOf(JDBCDataSourceConfiguration.class));
+ JDBCDataSourceConfiguration jdbcDataSourceConfiguration =
(JDBCDataSourceConfiguration) actual;
+ assertThat(jdbcDataSourceConfiguration.getJdbcUrl(), is(jdbcUrl));
+ assertThat(jdbcDataSourceConfiguration.getUsername(), is(username));
+ assertThat(jdbcDataSourceConfiguration.getPassword(), is(password));
+ }
+
+ private JsonObject mockJDBCConfiguration(final String jdbcUrl, final
String username, final String password) {
+ JsonObject result = new JsonObject();
+ result.addProperty("jdbcUrl", jdbcUrl);
+ result.addProperty("username", username);
+ result.addProperty("password", password);
+ return result;
+ }
+
+ @Test
+ public void assertToShardingSphereJDBConfiguration() {
+ RuleConfiguration.DataSourceConf dataSourceConf = new
RuleConfiguration.DataSourceConf();
+ dataSourceConf.setType("shardingSphereJdbc");
+ String dataSource = FixtureShardingSphereJDBCConfiguration.DATA_SOURCE;
+ String rule = FixtureShardingSphereJDBCConfiguration.RULE;
+
dataSourceConf.setParameter(mockShardingSphereJDBCConfiguration(dataSource,
rule));
+ DataSourceConfiguration actual =
dataSourceConf.toTypedDataSourceConfiguration();
+ assertThat(actual, instanceOf(ShardingSphereJDBCConfiguration.class));
+ ShardingSphereJDBCConfiguration shardingSphereJDBCConfiguration =
(ShardingSphereJDBCConfiguration) actual;
+ assertThat(shardingSphereJDBCConfiguration.getDataSource(),
is(dataSource));
+ assertThat(shardingSphereJDBCConfiguration.getRule(), is(rule));
+ }
+
+ private JsonObject mockShardingSphereJDBCConfiguration(final String
dataSource, final String rule) {
+ JsonObject result = new JsonObject();
+ result.addProperty("dataSource", dataSource);
+ result.addProperty("rule", rule);
+ return result;
+ }
+}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfigurationTest.java
similarity index 52%
copy from
shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
copy to
shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfigurationTest.java
index 0ec30bb..f40cec8 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/RuleConfiguration.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/ShardingSphereJDBCConfigurationTest.java
@@ -17,32 +17,20 @@
package org.apache.shardingsphere.scaling.core.config;
-import lombok.Getter;
-import lombok.Setter;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import
org.apache.shardingsphere.scaling.core.fixture.FixtureShardingSphereJDBCConfiguration;
+import org.junit.Test;
-/**
- * Rule configuration.
- */
-@Setter
-@Getter
-public final class RuleConfiguration {
-
- private String sourceDataSource;
-
- private String sourceRule;
-
- private YamlDataSourceParameter targetDataSources;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public class ShardingSphereJDBCConfigurationTest {
- @Setter
- @Getter
- public static final class YamlDataSourceParameter {
-
- private String name;
-
- private String url;
-
- private String username;
-
- private String password;
+ @Test
+ public void assertShardingSphereJDBCDataSourceConfigurationDatabaseType() {
+ ShardingSphereJDBCConfiguration shardingSphereJDBCConfiguration = new
ShardingSphereJDBCConfiguration(
+ FixtureShardingSphereJDBCConfiguration.DATA_SOURCE,
+ FixtureShardingSphereJDBCConfiguration.RULE);
+ assertThat(shardingSphereJDBCConfiguration.getDatabaseType(),
instanceOf(H2DatabaseType.class));
}
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactoryTest.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactoryTest.java
new file mode 100644
index 0000000..d4ed0ab
--- /dev/null
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/datasource/DataSourceFactoryTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.scaling.core.datasource;
+
+import
org.apache.shardingsphere.scaling.core.config.JDBCDataSourceConfiguration;
+import
org.apache.shardingsphere.scaling.core.config.ShardingSphereJDBCConfiguration;
+import
org.apache.shardingsphere.scaling.core.fixture.FixtureShardingSphereJDBCConfiguration;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class DataSourceFactoryTest {
+
+ @Test
+ public void assertNewJDBCInstance() {
+ JDBCDataSourceConfiguration jdbcDataSourceConfiguration = new
JDBCDataSourceConfiguration(
+
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
+ "root",
+ "password");
+ DataSourceWrapper actual = new
DataSourceFactory().newInstance(jdbcDataSourceConfiguration);
+ assertThat(actual, is(notNullValue()));
+ }
+
+ @Test
+ public void assertNewShardingSphereJDBCInstance() {
+ ShardingSphereJDBCConfiguration shardingSphereJDBCConfiguration = new
ShardingSphereJDBCConfiguration(
+ FixtureShardingSphereJDBCConfiguration.DATA_SOURCE,
+ FixtureShardingSphereJDBCConfiguration.RULE);
+ DataSourceWrapper actual = new
DataSourceFactory().newInstance(shardingSphereJDBCConfiguration);
+ assertThat(actual, is(notNullValue()));
+ }
+}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/fixture/FixtureShardingSphereJDBCConfiguration.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/fixture/FixtureShardingSphereJDBCConfiguration.java
new file mode 100644
index 0000000..b8a608c
--- /dev/null
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/fixture/FixtureShardingSphereJDBCConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.scaling.core.fixture;
+
+public class FixtureShardingSphereJDBCConfiguration {
+
+ public static final String DATA_SOURCE = "dataSources:\n ds_0:\n
dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n "
+ + "jdbcUrl:
jdbc:h2:mem:test_db_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: 'password'\n "
+ + "connectionTimeout: 30000\n idleTimeout: 60000\n
maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n
maintenanceIntervalMilliseconds: 30000\n "
+ + "readOnly: false\n";
+
+ public static final String RULE = "rules:\n- !SHARDING\n
defaultDatabaseStrategy:\n standard:\n shardingAlgorithmName: inline\n
shardingColumn: user_id\n "
+ + "tables:\n t1:\n actualDataNodes: ds_0.t1\n
keyGenerateStrategy:\n column: order_id\n "
+ + "logicTable: t1\n tableStrategy:\n standard:\n
shardingAlgorithmName: inline\n shardingColumn: order_id\n "
+ + "t2:\n actualDataNodes: ds_0.t2\n
keyGenerateStrategy:\n column: order_item_id\n "
+ + "logicTable: t2\n tableStrategy:\n standard:\n
shardingAlgorithmName: inline\n shardingColumn: order_id";
+}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
index 4433ab0..4f9eba7 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
@@ -17,13 +17,21 @@
{
"ruleConfiguration": {
- "sourceDataSource": "dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: 'password'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
- "sourceRule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item [...]
- "targetDataSources": {
- "name": "dt_0",
- "url":
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
- "username": "root",
- "password": "password"
+ "source": {
+ "type": "shardingSphereJdbc",
+ "parameter": {
+ "dataSource": "dataSources:\n ds_0:\n dataSourceClassName:
com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl:
jdbc:h2:mem:test_db_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n
username: root\n password: 'password'\n connectionTimeout: 30000\n
idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n
minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly:
false\n",
+ "rule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n
tables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n
column: order_id\n logicTable: t1\n tableStrategy:\n
standard:\n shardingAlgorithmName: inline\n shardingColumn:
order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n
column: order_item_i [...]
+ }
+ },
+ "target": {
+ "type": "jdbc",
+ "parameter": {
+ "name": "dt_0",
+ "jdbcUrl":
"jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
+ "username": "root",
+ "password": "password"
+ }
}
},
"jobConfiguration": {