You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/02/19 05:53:54 UTC
[shardingsphere] branch master updated: Remove Gson from scaling.
(#9432)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 86b5112 Remove Gson from scaling. (#9432)
86b5112 is described below
commit 86b5112ac74b885cb547a26c51d1cac45bdf186c
Author: 邱鹿 Lucas <lu...@163.com>
AuthorDate: Fri Feb 19 13:53:24 2021 +0800
Remove Gson from scaling. (#9432)
Co-authored-by: qiulu3 <Lucas209910>
---
.../yaml/config/YamlConfigurationConverter.java | 49 +++++++++++++-
.../YamlDataSourceRuleConfigurationWrap.java | 18 +++--
.../shardingsphere-scaling-core/pom.xml | 4 --
.../scaling/core/api/ScalingWorker.java | 11 ++-
.../scaling/core/api/impl/ScalingAPIImpl.java | 11 ++-
.../scaling/core/config/HandleConfiguration.java | 2 +-
.../scaling/core/config/JobConfiguration.java | 2 +-
.../scaling/core/config/RuleConfiguration.java | 55 ++-------------
.../datasource/ConfigurationYamlConverter.java | 79 ----------------------
.../datasource/ScalingDataSourceConfiguration.java | 7 ++
.../ScalingDataSourceConfigurationWrap.java | 61 +++++++++++++++++
.../ShardingSphereJDBCDataSourceConfiguration.java | 43 ++++++------
.../StandardJDBCDataSourceConfiguration.java | 50 ++++++++------
.../scaling/core/job/ScalingJob.java | 7 +-
.../core/job/progress/yaml/YamlJobProgress.java | 5 +-
.../shardingsphere/scaling/core/util/JDBCUtil.java | 16 ++---
.../scaling/core/util/JobConfigurationUtil.java | 67 +++++++-----------
.../scaling/core/api/impl/ScalingAPIImplTest.java | 16 ++---
.../common/datasource/DataSourceFactoryTest.java | 41 -----------
.../common/datasource/DataSourceManagerTest.java | 4 +-
.../scaling/core/config/RuleConfigurationTest.java | 73 --------------------
.../JDBCDataSourceConfigurationTest.java | 45 ------------
...rdingSphereJDBCDataSourceConfigurationTest.java | 35 ----------
.../FixtureShardingSphereJDBCConfiguration.java | 36 ----------
.../check/AbstractDataConsistencyCheckerTest.java | 18 ++---
.../splitter/InventoryTaskSplitterTest.java | 8 +--
.../scaling/core/util/JDBCUtilTest.java | 8 +--
.../scaling/core/util/ResourceUtil.java | 79 ++++++++++++++++++++++
.../src/test/resources/config.json | 42 ------------
.../config_sharding_sphere_jdbc_source.yaml | 45 ++++++++++++
.../config_sharding_sphere_jdbc_target.json | 38 -----------
.../config_sharding_sphere_jdbc_target.yaml | 51 ++++++++++++++
.../resources/config_standard_jdbc_target.yaml | 16 +++++
.../scaling/mysql/component/MySQLBinlogDumper.java | 7 +-
.../scaling/postgresql/wal/LogicalReplication.java | 6 +-
.../scaling/postgresql/wal/WalEventConverter.java | 2 +-
36 files changed, 456 insertions(+), 601 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
index 972aae3..f194e55 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
@@ -17,21 +17,30 @@
package org.apache.shardingsphere.governance.core.yaml.config;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.governance.core.yaml.swapper.DataSourceConfigurationYamlSwapper;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
import org.apache.shardingsphere.infra.metadata.auth.builtin.yaml.config.YamlUserRuleConfiguration;
import org.apache.shardingsphere.infra.metadata.auth.builtin.yaml.swapper.UserRuleYamlSwapper;
import org.apache.shardingsphere.infra.metadata.auth.model.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.yaml.swapper.ShardingRuleConfigurationYamlSwapper;
+import javax.sql.DataSource;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -57,6 +66,42 @@ public final class YamlConfigurationConverter {
}
/**
+ * Convert data source configurations from YAML content.
+ *
+ * @param yamlDataSourceConfigs YAML data source configurations
+ * @return data source configurations
+ */
+ public static Map<String, DataSourceConfiguration> convertDataSourceConfigurations(final Map<String, YamlDataSourceConfiguration> yamlDataSourceConfigs) {
+ return Maps.transformValues(yamlDataSourceConfigs, new DataSourceConfigurationYamlSwapper()::swapToObject);
+ }
+
+ /**
+ * Convert data sources from YAML data source configurations.
+ *
+ * @param yamlDataSources YAML data sources
+ * @return data sources
+ */
+ public static Map<String, DataSource> convertDataSources(final Map<String, YamlDataSourceConfiguration> yamlDataSources) {
+ Map<String, DataSourceConfiguration> dataSourceConfigMap = yamlDataSources.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, entry -> new DataSourceConfigurationYamlSwapper().swapToObject(entry.getValue())));
+ return DataSourceConverter.getDataSourceMap(dataSourceConfigMap);
+ }
+
+ /**
+ * Convert sharding rule configuration from YAML .
+ *
+ * @param yamlRuleConfigs yaml rule configurations
+ * @return sharding rule configuration
+ */
+ public static ShardingRuleConfiguration convertShardingRuleConfig(final Collection<YamlRuleConfiguration> yamlRuleConfigs) {
+ Optional<YamlRuleConfiguration> ruleConfig = yamlRuleConfigs.stream()
+ .filter(each -> each instanceof YamlShardingRuleConfiguration)
+ .findFirst();
+ Preconditions.checkState(ruleConfig.isPresent(), "No available sharding rule to load for governance.");
+ return new ShardingRuleConfigurationYamlSwapper().swapToObject((YamlShardingRuleConfiguration) ruleConfig.get());
+ }
+
+ /**
* Convert rule configurations from YAML content.
*
* @param yamlContent YAML content
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlDataSourceRuleConfigurationWrap.java
similarity index 61%
copy from shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java
copy to shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlDataSourceRuleConfigurationWrap.java
index 7505205..219a120 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlDataSourceRuleConfigurationWrap.java
@@ -15,19 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.scaling.core.config;
+package org.apache.shardingsphere.governance.core.yaml.config;
import lombok.Getter;
import lombok.Setter;
+import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
/**
- * Scaling job configuration.
+ * Yaml data source and rule configuration wrap.
*/
-@Setter
@Getter
-public final class JobConfiguration {
+@Setter
+public final class YamlDataSourceRuleConfigurationWrap implements YamlConfiguration {
- private RuleConfiguration ruleConfig;
+ private Map<String, YamlDataSourceConfiguration> dataSources;
- private HandleConfiguration handleConfig;
+ private Collection<YamlRuleConfiguration> rules = new LinkedList<>();
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml b/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
index 16b44da..a750b03 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/pom.xml
@@ -81,10 +81,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
index 40beadd..e6ef32b 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
@@ -68,10 +68,15 @@ public final class ScalingWorker {
private JobConfiguration createJobConfig(final StartScalingEvent event) {
JobConfiguration result = new JobConfiguration();
- result.setRuleConfig(new RuleConfiguration(
- new ShardingSphereJDBCDataSourceConfiguration(event.getSourceDataSource(), event.getSourceRule()),
- new ShardingSphereJDBCDataSourceConfiguration(event.getTargetDataSource(), event.getTargetRule())));
+ result.setRuleConfig(getRuleConfiguration(event));
result.setHandleConfig(new HandleConfiguration(new WorkflowConfiguration(event.getSchemaName(), event.getRuleCacheId())));
return result;
}
+
+ private RuleConfiguration getRuleConfiguration(final StartScalingEvent event) {
+ RuleConfiguration result = new RuleConfiguration();
+ result.setSource(new ShardingSphereJDBCDataSourceConfiguration(event.getSourceDataSource(), event.getSourceRule()).wrap());
+ result.setTarget(new ShardingSphereJDBCDataSourceConfiguration(event.getTargetDataSource(), event.getTargetRule()).wrap());
+ return result;
+ }
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
index de01d4b..3c37e8c 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.scaling.core.api.impl;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
@@ -52,8 +50,6 @@ import java.util.stream.IntStream;
@Slf4j
public final class ScalingAPIImpl implements ScalingAPI {
- private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().serializeNulls().create();
-
@Override
public List<JobInfo> list() {
return ScalingAPIFactory.getJobStatisticsAPI().getAllJobsBriefInfo().stream()
@@ -121,11 +117,12 @@ public final class ScalingAPIImpl implements ScalingAPI {
@Override
public Optional<Long> start(final JobConfiguration jobConfig) {
- log.info("Start scaling job by {}", jobConfig);
JobConfigurationUtil.fillInProperties(jobConfig);
if (jobConfig.getHandleConfig().getShardingTotalCount() == 0) {
+ log.warn("Invalid scaling job config!");
return Optional.empty();
}
+ log.info("Start scaling job by {}", YamlEngine.marshal(jobConfig));
ScalingAPIFactory.getRegistryRepositoryAPI().persist(String.format("%s/%d", ScalingConstant.SCALING_ROOT, jobConfig.getHandleConfig().getJobId()), ScalingJob.class.getCanonicalName());
ScalingAPIFactory.getRegistryRepositoryAPI().persist(String.format("%s/%d/config", ScalingConstant.SCALING_ROOT, jobConfig.getHandleConfig().getJobId()), createElasticJobConfig(jobConfig));
return Optional.of(jobConfig.getHandleConfig().getJobId());
@@ -135,7 +132,7 @@ public final class ScalingAPIImpl implements ScalingAPI {
JobConfigurationPOJO jobConfigPOJO = new JobConfigurationPOJO();
jobConfigPOJO.setJobName(String.valueOf(jobConfig.getHandleConfig().getJobId()));
jobConfigPOJO.setShardingTotalCount(jobConfig.getHandleConfig().getShardingTotalCount());
- jobConfigPOJO.setJobParameter(GSON.toJson(jobConfig));
+ jobConfigPOJO.setJobParameter(YamlEngine.marshal(jobConfig));
return YamlEngine.marshal(jobConfigPOJO);
}
@@ -183,7 +180,7 @@ public final class ScalingAPIImpl implements ScalingAPI {
}
private JobConfiguration getJobConfig(final JobConfigurationPOJO elasticJobConfigPOJO) {
- return GSON.fromJson(elasticJobConfigPOJO.getJobParameter(), JobConfiguration.class);
+ return YamlEngine.unmarshal(elasticJobConfigPOJO.getJobParameter(), JobConfiguration.class);
}
private JobConfigurationPOJO getElasticJobConfigPOJO(final long jobId) {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/HandleConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/HandleConfiguration.java
index 3e70f70..319b66e 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/HandleConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/HandleConfiguration.java
@@ -37,7 +37,7 @@ public final class HandleConfiguration {
private String[] shardingTables;
- private Integer shardingItem;
+ private int shardingItem;
private int shardingSize = 1000 * 10000;
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java
index 7505205..06cd56d 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/JobConfiguration.java
@@ -29,5 +29,5 @@ public final class JobConfiguration {
private RuleConfiguration ruleConfig;
- private HandleConfiguration handleConfig;
+ private HandleConfiguration handleConfig = new HandleConfiguration();
}
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 6eb56b8..53218c9 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,63 +17,18 @@
package org.apache.shardingsphere.scaling.core.config;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
-
-import java.util.Map;
+import lombok.Setter;
+import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfigurationWrap;
/**
* Rule configuration.
*/
@Getter
+@Setter
public final class RuleConfiguration {
- private final DataSourceConfigurationWrapper source;
-
- private final DataSourceConfigurationWrapper target;
-
- public RuleConfiguration(final ScalingDataSourceConfiguration source, final ScalingDataSourceConfiguration target) {
- this.source = new DataSourceConfigurationWrapper(source.getConfigType(), new Gson().toJsonTree(source));
- this.target = new DataSourceConfigurationWrapper(target.getConfigType(), new Gson().toJsonTree(target));
- }
+ private ScalingDataSourceConfigurationWrap source;
- @RequiredArgsConstructor
- public static class DataSourceConfigurationWrapper {
-
- private final String type;
-
- private final JsonElement parameter;
-
- /**
- * Unwrap to {@code DataSourceConfiguration}.
- *
- * @return {@code DataSourceConfiguration}
- */
- public ScalingDataSourceConfiguration unwrap() {
- Map<String, Class<?>> instances = DataSourceConfigurationHolder.getInstances();
- Preconditions.checkArgument(instances.containsKey(type.toLowerCase()), "Unsupported Data Source Type:" + type);
- return (ScalingDataSourceConfiguration) new Gson().fromJson(parameter, instances.get(type.toLowerCase()));
- }
-
- private static class DataSourceConfigurationHolder {
-
- private static final Map<String, Class<?>> INSTANCES = Maps.newHashMap();
-
- static {
- INSTANCES.put(StandardJDBCDataSourceConfiguration.CONFIG_TYPE.toLowerCase(), StandardJDBCDataSourceConfiguration.class);
- INSTANCES.put(ShardingSphereJDBCDataSourceConfiguration.CONFIG_TYPE.toLowerCase(), ShardingSphereJDBCDataSourceConfiguration.class);
- }
-
- private static Map<String, Class<?>> getInstances() {
- return INSTANCES;
- }
- }
- }
+ private ScalingDataSourceConfigurationWrap target;
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ConfigurationYamlConverter.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ConfigurationYamlConverter.java
deleted file mode 100644
index 45eeaed..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ConfigurationYamlConverter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.config.datasource;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.governance.core.yaml.config.YamlDataSourceConfigurationWrap;
-import org.apache.shardingsphere.governance.core.yaml.swapper.DataSourceConfigurationYamlSwapper;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
-import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.yaml.swapper.ShardingRuleConfigurationYamlSwapper;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * YAML converter for configuration.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ConfigurationYamlConverter {
-
- /**
- * Load data source configurations.
- *
- * @param data data
- * @return data source configurations
- */
- public static Map<String, DataSourceConfiguration> loadDataSourceConfigs(final String data) {
- YamlDataSourceConfigurationWrap result = YamlEngine.unmarshal(data, YamlDataSourceConfigurationWrap.class);
- Preconditions.checkState(!result.getDataSources().isEmpty(), "No available data sources to load for governance.");
- return Maps.transformValues(result.getDataSources(), new DataSourceConfigurationYamlSwapper()::swapToObject);
- }
-
- /**
- * Serialize data source configurations.
- *
- * @param dataSourceConfigMap data source configurations
- * @return data
- */
- public static String serializeDataSourceConfigs(final Map<String, DataSourceConfiguration> dataSourceConfigMap) {
- YamlDataSourceConfigurationWrap yamlDataSourceConfigurationWrap = new YamlDataSourceConfigurationWrap();
- yamlDataSourceConfigurationWrap.setDataSources(Maps.transformValues(dataSourceConfigMap, new DataSourceConfigurationYamlSwapper()::swapToYamlConfiguration));
- return YamlEngine.marshal(yamlDataSourceConfigurationWrap);
- }
-
- /**
- * Load sharding rule configuration.
- *
- * @param data data
- * @return sharding rule configuration
- */
- public static ShardingRuleConfiguration loadShardingRuleConfig(final String data) {
- YamlRootRuleConfigurations rootRuleConfigs = YamlEngine.unmarshal(data, YamlRootRuleConfigurations.class);
- Optional<YamlRuleConfiguration> ruleConfig = rootRuleConfigs.getRules().stream().filter(each -> each instanceof YamlShardingRuleConfiguration).findFirst();
- Preconditions.checkState(ruleConfig.isPresent(), "No available sharding rule to load for governance.");
- return new ShardingRuleConfigurationYamlSwapper().swapToObject((YamlShardingRuleConfiguration) ruleConfig.get());
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfiguration.java
index 318689d..cfc0506 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfiguration.java
@@ -42,6 +42,13 @@ public interface ScalingDataSourceConfiguration {
DatabaseType getDatabaseType();
/**
+ * Wrap.
+ *
+ * @return scaling data source configuration wrap
+ */
+ ScalingDataSourceConfigurationWrap wrap();
+
+ /**
* To data source.
*
* @return data source
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfigurationWrap.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfigurationWrap.java
new file mode 100644
index 0000000..103e756
--- /dev/null
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ScalingDataSourceConfigurationWrap.java
@@ -0,0 +1,61 @@
+/*
+ * 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.datasource;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.SneakyThrows;
+
+import java.util.Map;
+
+@Getter
+@Setter
+public class ScalingDataSourceConfigurationWrap {
+
+ private String type;
+
+ private String parameter;
+
+ /**
+ * Unwrap.
+ *
+ * @return scaling data source configuration
+ */
+ @SneakyThrows(ReflectiveOperationException.class)
+ public ScalingDataSourceConfiguration unwrap() {
+ Map<String, Class<?>> classMap = DataSourceConfigurationHolder.getInstances();
+ Preconditions.checkArgument(classMap.containsKey(type.toLowerCase()), String.format("Unsupported data source type '%s'", type));
+ return (ScalingDataSourceConfiguration) classMap.get(type.toLowerCase()).getConstructor(String.class).newInstance(parameter);
+ }
+
+ private static class DataSourceConfigurationHolder {
+
+ private static final Map<String, Class<?>> INSTANCES = Maps.newHashMap();
+
+ static {
+ INSTANCES.put(StandardJDBCDataSourceConfiguration.CONFIG_TYPE.toLowerCase(), StandardJDBCDataSourceConfiguration.class);
+ INSTANCES.put(ShardingSphereJDBCDataSourceConfiguration.CONFIG_TYPE.toLowerCase(), ShardingSphereJDBCDataSourceConfiguration.class);
+ }
+
+ private static Map<String, Class<?>> getInstances() {
+ return INSTANCES;
+ }
+ }
+}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
index 195ea59..354f15c 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
@@ -20,12 +20,12 @@ package org.apache.shardingsphere.scaling.core.config.datasource;
import com.google.common.collect.Lists;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.Setter;
import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlDataSourceRuleConfigurationWrap;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -34,9 +34,8 @@ import java.util.Map;
/**
* ShardingSphere-JDBC data source configuration.
*/
-@Setter
@Getter
-@EqualsAndHashCode(exclude = "databaseType")
+@EqualsAndHashCode(of = "parameter")
public final class ShardingSphereJDBCDataSourceConfiguration implements ScalingDataSourceConfiguration {
/**
@@ -44,15 +43,21 @@ public final class ShardingSphereJDBCDataSourceConfiguration implements ScalingD
*/
public static final String CONFIG_TYPE = "ShardingSphereJDBC";
- private String dataSource;
+ private final String parameter;
- private String rule;
+ private final YamlDataSourceRuleConfigurationWrap dataSourceRuleConfig;
- private transient DatabaseType databaseType;
+ private final DatabaseType databaseType;
- public ShardingSphereJDBCDataSourceConfiguration(final String dataSource, final String rule) {
- this.dataSource = dataSource;
- this.rule = rule;
+ public ShardingSphereJDBCDataSourceConfiguration(final String parameter) {
+ this.parameter = parameter;
+ dataSourceRuleConfig = YamlEngine.unmarshal(parameter, YamlDataSourceRuleConfigurationWrap.class);
+ Map<String, Object> props = dataSourceRuleConfig.getDataSources().values().iterator().next().getProps();
+ databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(props.getOrDefault("url", props.get("jdbcUrl")).toString());
+ }
+
+ public ShardingSphereJDBCDataSourceConfiguration(final String dataSources, final String rules) {
+ this(String.format("%s\n%s", dataSources, rules));
}
@Override
@@ -61,18 +66,16 @@ public final class ShardingSphereJDBCDataSourceConfiguration implements ScalingD
}
@Override
- public DatabaseType getDatabaseType() {
- if (null == databaseType) {
- Map<String, Object> props = ConfigurationYamlConverter.loadDataSourceConfigs(dataSource).values().iterator().next().getProps();
- databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(props.getOrDefault("url", props.get("jdbcUrl")).toString());
- }
- return databaseType;
+ public ScalingDataSourceConfigurationWrap wrap() {
+ ScalingDataSourceConfigurationWrap result = new ScalingDataSourceConfigurationWrap();
+ result.setType(CONFIG_TYPE);
+ result.setParameter(parameter);
+ return result;
}
@Override
public DataSource toDataSource() throws SQLException {
- Map<String, DataSource> dataSourceMap = DataSourceConverter.getDataSourceMap(ConfigurationYamlConverter.loadDataSourceConfigs(dataSource));
- ShardingRuleConfiguration ruleConfig = ConfigurationYamlConverter.loadShardingRuleConfig(rule);
- return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Lists.newArrayList(ruleConfig), null);
+ return ShardingSphereDataSourceFactory.createDataSource(YamlConfigurationConverter.convertDataSources(dataSourceRuleConfig.getDataSources()),
+ Lists.newArrayList(YamlConfigurationConverter.convertShardingRuleConfig(dataSourceRuleConfig.getRules())), null);
}
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/StandardJDBCDataSourceConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/StandardJDBCDataSourceConfiguration.java
index 5222c4d..f2f948b 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/StandardJDBCDataSourceConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/StandardJDBCDataSourceConfiguration.java
@@ -17,12 +17,13 @@
package org.apache.shardingsphere.scaling.core.config.datasource;
+import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.Setter;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import javax.sql.DataSource;
@@ -30,8 +31,7 @@ import javax.sql.DataSource;
* Standard JDBC data source configuration.
*/
@Getter
-@Setter
-@EqualsAndHashCode(exclude = "databaseType")
+@EqualsAndHashCode(of = "parameter")
public final class StandardJDBCDataSourceConfiguration implements ScalingDataSourceConfiguration {
/**
@@ -39,19 +39,31 @@ public final class StandardJDBCDataSourceConfiguration implements ScalingDataSou
*/
public static final String CONFIG_TYPE = "JDBC";
- private String jdbcUrl;
+ private final String parameter;
- private String username;
+ private final HikariConfig hikariConfig;
- private String password;
+ private final DatabaseType databaseType;
- private transient DatabaseType databaseType;
+ public StandardJDBCDataSourceConfiguration(final String parameter) {
+ this.parameter = parameter;
+ hikariConfig = YamlEngine.unmarshal(parameter, HikariConfig.class);
+ databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(hikariConfig.getJdbcUrl());
+ }
public StandardJDBCDataSourceConfiguration(final String jdbcUrl, final String username, final String password) {
- this.jdbcUrl = jdbcUrl;
- this.username = username;
- this.password = password;
- databaseType = getDatabaseType();
+ HikariConfig hikariConfig = getHikariConfig(jdbcUrl, username, password);
+ this.hikariConfig = hikariConfig;
+ this.parameter = YamlEngine.marshal(hikariConfig);
+ databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(jdbcUrl);
+ }
+
+ private HikariConfig getHikariConfig(final String jdbcUrl, final String username, final String password) {
+ HikariConfig result = new HikariConfig();
+ result.setJdbcUrl(jdbcUrl);
+ result.setUsername(username);
+ result.setPassword(password);
+ return result;
}
@Override
@@ -60,19 +72,15 @@ public final class StandardJDBCDataSourceConfiguration implements ScalingDataSou
}
@Override
- public DatabaseType getDatabaseType() {
- if (null == databaseType) {
- databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(jdbcUrl);
- }
- return databaseType;
+ public ScalingDataSourceConfigurationWrap wrap() {
+ ScalingDataSourceConfigurationWrap result = new ScalingDataSourceConfigurationWrap();
+ result.setType(CONFIG_TYPE);
+ result.setParameter(parameter);
+ return result;
}
@Override
public DataSource toDataSource() {
- HikariDataSource result = new HikariDataSource();
- result.setJdbcUrl(jdbcUrl);
- result.setUsername(username);
- result.setPassword(password);
- return result;
+ return new HikariDataSource(hikariConfig);
}
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/ScalingJob.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/ScalingJob.java
index 28cc27b..fd62c0f 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/ScalingJob.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/ScalingJob.java
@@ -17,11 +17,10 @@
package org.apache.shardingsphere.scaling.core.job;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.scaling.core.api.RegistryRepositoryAPI;
import org.apache.shardingsphere.scaling.core.api.ScalingAPIFactory;
import org.apache.shardingsphere.scaling.core.config.JobConfiguration;
@@ -34,8 +33,6 @@ import org.apache.shardingsphere.scaling.core.job.schedule.JobSchedulerCenter;
@Slf4j
public final class ScalingJob implements SimpleJob {
- private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().serializeNulls().create();
-
private final RegistryRepositoryAPI registryRepositoryAPI = ScalingAPIFactory.getRegistryRepositoryAPI();
private final ScalingJobPreparer jobPreparer = new ScalingJobPreparer();
@@ -43,7 +40,7 @@ public final class ScalingJob implements SimpleJob {
@Override
public void execute(final ShardingContext shardingContext) {
log.info("Execute scaling job {}-{}", shardingContext.getJobName(), shardingContext.getShardingItem());
- JobConfiguration jobConfig = GSON.fromJson(shardingContext.getJobParameter(), JobConfiguration.class);
+ JobConfiguration jobConfig = YamlEngine.unmarshal(shardingContext.getJobParameter(), JobConfiguration.class);
jobConfig.getHandleConfig().setShardingItem(shardingContext.getShardingItem());
JobContext jobContext = new JobContext(jobConfig);
jobContext.setInitProgress(registryRepositoryAPI.getJobProgress(jobContext.getJobId(), jobContext.getShardingItem()));
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/progress/yaml/YamlJobProgress.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/progress/yaml/YamlJobProgress.java
index c27d949..f677266 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/progress/yaml/YamlJobProgress.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/progress/yaml/YamlJobProgress.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.scaling.core.job.progress.yaml;
+import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.scaling.core.job.task.incremental.IncrementalTaskDelay;
@@ -42,9 +43,9 @@ public final class YamlJobProgress {
@Setter
public static final class YamlInventory {
- private String[] finished;
+ private String[] finished = new String[0];
- private Map<String, String> unfinished;
+ private Map<String, String> unfinished = Maps.newHashMap();
}
@Getter
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JDBCUtil.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JDBCUtil.java
index cff4132..0eb40d3 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JDBCUtil.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JDBCUtil.java
@@ -19,14 +19,11 @@ package org.apache.shardingsphere.scaling.core.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.common.datasource.JdbcUri;
-import org.apache.shardingsphere.scaling.core.config.datasource.ConfigurationYamlConverter;
import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
-import java.util.HashMap;
import java.util.Map;
/**
@@ -50,16 +47,15 @@ public final class JDBCUtil {
}
private static void append(final StandardJDBCDataSourceConfiguration dataSourceConfig, final Map<String, String> parameters) {
- dataSourceConfig.setJdbcUrl(append(dataSourceConfig.getJdbcUrl(), parameters));
+ dataSourceConfig.getHikariConfig().setJdbcUrl(append(dataSourceConfig.getHikariConfig().getJdbcUrl(), parameters));
}
private static void append(final ShardingSphereJDBCDataSourceConfiguration dataSourceConfig, final Map<String, String> parameters) {
- Map<String, DataSourceConfiguration> dataSourceConfigMap = new HashMap<>(ConfigurationYamlConverter.loadDataSourceConfigs(dataSourceConfig.getDataSource()));
- dataSourceConfigMap.forEach((key, value) -> {
- String jdbcUrlKey = value.getProps().containsKey("url") ? "url" : "jdbcUrl";
- value.getProps().replace(jdbcUrlKey, append(value.getProps().get(jdbcUrlKey).toString(), parameters));
- });
- dataSourceConfig.setDataSource(ConfigurationYamlConverter.serializeDataSourceConfigs(dataSourceConfigMap));
+ dataSourceConfig.getDataSourceRuleConfig().getDataSources()
+ .forEach((key, value) -> {
+ String jdbcUrlKey = value.getProps().containsKey("url") ? "url" : "jdbcUrl";
+ value.getProps().replace(jdbcUrlKey, append(value.getProps().get(jdbcUrlKey).toString(), parameters));
+ });
}
private static String append(final String url, final Map<String, String> parameters) {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
index 04f087a..c69283e 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
@@ -23,19 +23,20 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
-import com.google.gson.Gson;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlDataSourceConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlDataSourceRuleConfigurationWrap;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.scaling.core.common.datasource.JdbcUri;
import org.apache.shardingsphere.scaling.core.config.DumperConfiguration;
import org.apache.shardingsphere.scaling.core.config.HandleConfiguration;
import org.apache.shardingsphere.scaling.core.config.ImporterConfiguration;
import org.apache.shardingsphere.scaling.core.config.JobConfiguration;
import org.apache.shardingsphere.scaling.core.config.TaskConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.ConfigurationYamlConverter;
import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
@@ -50,9 +51,6 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
import javax.sql.DataSource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -108,11 +106,11 @@ public final class JobConfigurationUtil {
"Only ShardingSphereJdbc type of source ScalingDataSourceConfiguration is supported.");
ShardingSphereJDBCDataSourceConfiguration source = (ShardingSphereJDBCDataSourceConfiguration) sourceConfig;
if (!(jobConfig.getRuleConfig().getTarget().unwrap() instanceof ShardingSphereJDBCDataSourceConfiguration)) {
- return getShardingRuleConfigMap(source.getRule()).values().stream().map(ShardingTableRuleConfiguration::getActualDataNodes).collect(Collectors.toList());
+ return getShardingRuleConfigMap(source.getDataSourceRuleConfig()).values().stream().map(ShardingTableRuleConfiguration::getActualDataNodes).collect(Collectors.toList());
}
ShardingSphereJDBCDataSourceConfiguration target = (ShardingSphereJDBCDataSourceConfiguration) jobConfig.getRuleConfig().getTarget().unwrap();
- return getShouldScalingActualDataNodes(getModifiedDataSources(source.getDataSource(), target.getDataSource()),
- getShardingRuleConfigMap(source.getRule()), getShardingRuleConfigMap(target.getRule()));
+ return getShouldScalingActualDataNodes(getModifiedDataSources(source.getDataSourceRuleConfig(), target.getDataSourceRuleConfig()),
+ getShardingRuleConfigMap(source.getDataSourceRuleConfig()), getShardingRuleConfigMap(target.getDataSourceRuleConfig()));
}
private static List<String> getShouldScalingActualDataNodes(final Set<String> modifiedDataSources,
@@ -132,10 +130,10 @@ public final class JobConfigurationUtil {
return result;
}
- private static Set<String> getModifiedDataSources(final String oldConfig, final String newConfig) {
+ private static Set<String> getModifiedDataSources(final YamlDataSourceRuleConfigurationWrap sourceDataSourceRuleConfig, final YamlDataSourceRuleConfigurationWrap targetDataSourceRuleConfig) {
Set<String> result = new HashSet<>();
- Map<String, String> oldDataSourceUrlMap = getDataSourceUrlMap(oldConfig);
- Map<String, String> newDataSourceUrlMap = getDataSourceUrlMap(newConfig);
+ Map<String, String> oldDataSourceUrlMap = getDataSourceUrlMap(sourceDataSourceRuleConfig.getDataSources());
+ Map<String, String> newDataSourceUrlMap = getDataSourceUrlMap(targetDataSourceRuleConfig.getDataSources());
newDataSourceUrlMap.forEach((key, value) -> {
if (!value.equals(oldDataSourceUrlMap.get(key))) {
result.add(key);
@@ -144,22 +142,21 @@ public final class JobConfigurationUtil {
return result;
}
- private static Map<String, String> getDataSourceUrlMap(final String configuration) {
- Map<String, String> result = new HashMap<>();
- ConfigurationYamlConverter.loadDataSourceConfigs(configuration).forEach((key, value) -> {
- JdbcUri uri = new JdbcUri(value.getProps().getOrDefault("url", value.getProps().get("jdbcUrl")).toString());
- result.put(key, String.format("%s/%s", uri.getHost(), uri.getDatabase()));
- });
- return result;
+ private static Map<String, String> getDataSourceUrlMap(final Map<String, YamlDataSourceConfiguration> dataSources) {
+ return dataSources.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, entry -> {
+ JdbcUri uri = new JdbcUri(entry.getValue().getProps().getOrDefault("url", entry.getValue().getProps().get("jdbcUrl")).toString());
+ return String.format("%s/%s", uri.getHost(), uri.getDatabase());
+ }));
}
private static boolean includeModifiedDataSources(final List<String> actualDataNodes, final Set<String> modifiedDataSources) {
return actualDataNodes.stream().anyMatch(each -> modifiedDataSources.contains(each.split("\\.")[0]));
}
- private static Map<String, ShardingTableRuleConfiguration> getShardingRuleConfigMap(final String configuration) {
- ShardingRuleConfiguration oldShardingRuleConfig = ConfigurationYamlConverter.loadShardingRuleConfig(configuration);
- return oldShardingRuleConfig.getTables().stream().collect(Collectors.toMap(ShardingTableRuleConfiguration::getLogicTable, Function.identity()));
+ private static Map<String, ShardingTableRuleConfiguration> getShardingRuleConfigMap(final YamlDataSourceRuleConfigurationWrap dataSourceRuleConfig) {
+ ShardingRuleConfiguration ruleConfig = YamlConfigurationConverter.convertShardingRuleConfig(dataSourceRuleConfig.getRules());
+ return ruleConfig.getTables().stream().collect(Collectors.toMap(ShardingTableRuleConfiguration::getLogicTable, Function.identity()));
}
private static String[] groupByDataSource(final List<String> actualDataNodeList) {
@@ -213,8 +210,8 @@ public final class JobConfigurationUtil {
public static List<TaskConfiguration> toTaskConfigs(final JobConfiguration jobConfig) {
List<TaskConfiguration> result = new LinkedList<>();
ShardingSphereJDBCDataSourceConfiguration sourceConfig = getSourceConfig(jobConfig);
- ShardingRuleConfiguration sourceRuleConfig = ConfigurationYamlConverter.loadShardingRuleConfig(sourceConfig.getRule());
- Map<String, DataSourceConfiguration> sourceDataSource = ConfigurationYamlConverter.loadDataSourceConfigs(sourceConfig.getDataSource());
+ ShardingRuleConfiguration sourceRuleConfig = YamlConfigurationConverter.convertShardingRuleConfig(sourceConfig.getDataSourceRuleConfig().getRules());
+ Map<String, DataSourceConfiguration> sourceDataSource = YamlConfigurationConverter.convertDataSourceConfigurations(sourceConfig.getDataSourceRuleConfig().getDataSources());
Map<String, DataSource> dataSourceMap = sourceDataSource.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().createDataSource()));
Map<String, Map<String, String>> dataSourceTableNameMap = toDataSourceTableNameMap(new ShardingRule(sourceRuleConfig, sourceConfig.getDatabaseType(), dataSourceMap));
Optional<ShardingRuleConfiguration> targetRuleConfig = getTargetRuleConfig(jobConfig);
@@ -237,13 +234,13 @@ public final class JobConfigurationUtil {
private static Optional<ShardingRuleConfiguration> getTargetRuleConfig(final JobConfiguration jobConfig) {
ScalingDataSourceConfiguration dataSourceConfig = jobConfig.getRuleConfig().getTarget().unwrap();
if (dataSourceConfig instanceof ShardingSphereJDBCDataSourceConfiguration) {
- return Optional.of(ConfigurationYamlConverter.loadShardingRuleConfig(((ShardingSphereJDBCDataSourceConfiguration) dataSourceConfig).getRule()));
+ return Optional.of(YamlConfigurationConverter.convertShardingRuleConfig(((ShardingSphereJDBCDataSourceConfiguration) dataSourceConfig).getDataSourceRuleConfig().getRules()));
}
return Optional.empty();
}
private static void filterByShardingDataSourceTables(final Map<String, Map<String, String>> dataSourceTableNameMap, final HandleConfiguration handleConfig) {
- if (null == handleConfig.getShardingTables() || null == handleConfig.getShardingItem()) {
+ if (null == handleConfig.getShardingTables()) {
return;
}
Map<String, Set<String>> shardingDataSourceTableMap = toDataSourceTableNameMap(getShardingDataSourceTables(handleConfig));
@@ -342,9 +339,7 @@ public final class JobConfigurationUtil {
private static DumperConfiguration createDumperConfig(final String dataSourceName, final Map<String, Object> props, final Map<String, String> tableMap) {
DumperConfiguration result = new DumperConfiguration();
result.setDataSourceName(dataSourceName);
- StandardJDBCDataSourceConfiguration dumperDataSourceConfig = new StandardJDBCDataSourceConfiguration(
- props.containsKey("jdbcUrl") ? props.get("jdbcUrl").toString() : props.get("url").toString(), props.get("username").toString(), props.get("password").toString());
- result.setDataSourceConfig(dumperDataSourceConfig);
+ result.setDataSourceConfig(new StandardJDBCDataSourceConfiguration(YamlEngine.marshal(props)));
result.setTableNameMap(tableMap);
return result;
}
@@ -356,18 +351,4 @@ public final class JobConfigurationUtil {
result.setRetryTimes(jobConfig.getHandleConfig().getRetryTimes());
return result;
}
-
- /**
- * Init job config.
- *
- * @param configFile config file
- * @return job configuration
- */
- @SneakyThrows(IOException.class)
- public static JobConfiguration initJobConfig(final String configFile) {
- try (InputStream fileInputStream = JobConfigurationUtil.class.getResourceAsStream(configFile);
- InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream)) {
- return new Gson().fromJson(inputStreamReader, JobConfiguration.class);
- }
- }
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
index 5cc1e7b..0310640 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.scaling.core.config.ServerConfiguration;
import org.apache.shardingsphere.scaling.core.fixture.EmbedTestingServer;
import org.apache.shardingsphere.scaling.core.job.JobStatus;
import org.apache.shardingsphere.scaling.core.job.progress.JobProgress;
-import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
+import org.apache.shardingsphere.scaling.core.util.ResourceUtil;
import org.apache.shardingsphere.scaling.core.util.ReflectionUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -57,13 +57,13 @@ public final class ScalingAPIImplTest {
@Test
public void assertStartAndList() {
- Optional<Long> jobId = scalingAPI.start(JobConfigurationUtil.initJobConfig("/config.json"));
+ Optional<Long> jobId = scalingAPI.start(ResourceUtil.mockJobConfig());
assertTrue(jobId.isPresent());
JobInfo jobInfo = getNonNullJobInfo(jobId.get());
assertTrue(jobInfo.isActive());
assertThat(jobInfo.getStatus(), is(JobStatus.RUNNING.name()));
- assertThat(jobInfo.getTables(), is(new String[]{"ds_0.t1", "ds_0.t2"}));
- assertThat(jobInfo.getShardingTotalCount(), is(2));
+ assertThat(jobInfo.getTables(), is(new String[]{"ds_0.t_order"}));
+ assertThat(jobInfo.getShardingTotalCount(), is(1));
assertThat(jobInfo.getInventoryFinishedPercentage(), is(0));
assertThat(jobInfo.getIncrementalAverageDelayMilliseconds(), is(-1L));
}
@@ -80,7 +80,7 @@ public final class ScalingAPIImplTest {
@Test
public void assertStartOrStopById() {
- Optional<Long> jobId = scalingAPI.start(JobConfigurationUtil.initJobConfig("/config.json"));
+ Optional<Long> jobId = scalingAPI.start(ResourceUtil.mockJobConfig());
assertTrue(jobId.isPresent());
assertTrue(getNonNullJobInfo(jobId.get()).isActive());
scalingAPI.stop(jobId.get());
@@ -91,7 +91,7 @@ public final class ScalingAPIImplTest {
@Test
public void assertRemove() {
- Optional<Long> jobId = scalingAPI.start(JobConfigurationUtil.initJobConfig("/config.json"));
+ Optional<Long> jobId = scalingAPI.start(ResourceUtil.mockJobConfig());
assertTrue(jobId.isPresent());
assertTrue(getJobInfo(jobId.get()).isPresent());
scalingAPI.remove(jobId.get());
@@ -100,10 +100,10 @@ public final class ScalingAPIImplTest {
@Test
public void assertGetProgress() {
- Optional<Long> jobId = scalingAPI.start(JobConfigurationUtil.initJobConfig("/config.json"));
+ Optional<Long> jobId = scalingAPI.start(ResourceUtil.mockJobConfig());
assertTrue(jobId.isPresent());
Map<Integer, JobProgress> jobProgressMap = scalingAPI.getProgress(jobId.get());
- assertThat(jobProgressMap.size(), is(2));
+ assertThat(jobProgressMap.size(), is(1));
}
@AfterClass
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceFactoryTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceFactoryTest.java
deleted file mode 100644
index e79eeda..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceFactoryTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.common.datasource;
-
-import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.fixture.FixtureShardingSphereJDBCConfiguration;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-
-public final class DataSourceFactoryTest {
-
- @Test
- public void assertNewJDBCInstance() {
- StandardJDBCDataSourceConfiguration config = new StandardJDBCDataSourceConfiguration("jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "root", "password");
- assertNotNull(new DataSourceFactory().newInstance(config));
- }
-
- @Test
- public void assertNewShardingSphereJDBCInstance() {
- ShardingSphereJDBCDataSourceConfiguration config = new ShardingSphereJDBCDataSourceConfiguration(
- FixtureShardingSphereJDBCConfiguration.DATA_SOURCE, FixtureShardingSphereJDBCConfiguration.RULE);
- assertNotNull(new DataSourceFactory().newInstance(config));
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceManagerTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceManagerTest.java
index a6a4039..c2d7964 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceManagerTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/common/datasource/DataSourceManagerTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.scaling.core.common.datasource;
import org.apache.shardingsphere.scaling.core.config.TaskConfiguration;
import org.apache.shardingsphere.scaling.core.job.JobContext;
-import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
+import org.apache.shardingsphere.scaling.core.util.ResourceUtil;
import org.apache.shardingsphere.scaling.core.util.ReflectionUtil;
import org.junit.Before;
import org.junit.Test;
@@ -39,7 +39,7 @@ public final class DataSourceManagerTest {
@Before
public void setUp() {
- taskConfigurations = new JobContext(JobConfigurationUtil.initJobConfig("/config.json")).getTaskConfigs();
+ taskConfigurations = new JobContext(ResourceUtil.mockJobConfig()).getTaskConfigs();
}
@Test
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
deleted file mode 100644
index 02adcd2..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/RuleConfigurationTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.config;
-
-import com.google.gson.JsonObject;
-import org.apache.shardingsphere.scaling.core.config.RuleConfiguration.DataSourceConfigurationWrapper;
-import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
-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 final class RuleConfigurationTest {
-
- @Test
- public void assertToJDBConfig() {
- String jdbcUrl = "jdbc:h2:mem:test_db_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL";
- String username = "root";
- String password = "password";
- ScalingDataSourceConfiguration actual = mockStandardJDBCDataSourceConfigWrapper(jdbcUrl, username, password).unwrap();
- assertThat(actual, instanceOf(StandardJDBCDataSourceConfiguration.class));
- StandardJDBCDataSourceConfiguration jdbcDataSourceConfig = (StandardJDBCDataSourceConfiguration) actual;
- assertThat(jdbcDataSourceConfig.getJdbcUrl(), is(jdbcUrl));
- assertThat(jdbcDataSourceConfig.getUsername(), is(username));
- assertThat(jdbcDataSourceConfig.getPassword(), is(password));
- }
-
- @Test
- public void assertToShardingSphereJDBConfiguration() {
- String dataSource = FixtureShardingSphereJDBCConfiguration.DATA_SOURCE;
- String rule = FixtureShardingSphereJDBCConfiguration.RULE;
- DataSourceConfigurationWrapper dataSourceConfigurationWrapper = getDataSourceConfigurationWrapper(dataSource, rule);
- ScalingDataSourceConfiguration actual = dataSourceConfigurationWrapper.unwrap();
- assertThat(actual, instanceOf(ShardingSphereJDBCDataSourceConfiguration.class));
- ShardingSphereJDBCDataSourceConfiguration shardingSphereJDBCConfig = (ShardingSphereJDBCDataSourceConfiguration) actual;
- assertThat(shardingSphereJDBCConfig.getDataSource(), is(dataSource));
- assertThat(shardingSphereJDBCConfig.getRule(), is(rule));
- }
-
- private DataSourceConfigurationWrapper mockStandardJDBCDataSourceConfigWrapper(final String jdbcUrl, final String username, final String password) {
- JsonObject parameter = new JsonObject();
- parameter.addProperty("jdbcUrl", jdbcUrl);
- parameter.addProperty("username", username);
- parameter.addProperty("password", password);
- return new DataSourceConfigurationWrapper("JDBC", parameter);
- }
-
- private DataSourceConfigurationWrapper getDataSourceConfigurationWrapper(final String dataSource, final String rule) {
- JsonObject parameter = new JsonObject();
- parameter.addProperty("dataSource", dataSource);
- parameter.addProperty("rule", rule);
- return new DataSourceConfigurationWrapper("shardingSphereJdbc", parameter);
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/JDBCDataSourceConfigurationTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/JDBCDataSourceConfigurationTest.java
deleted file mode 100644
index 6c9236a..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/JDBCDataSourceConfigurationTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.config.datasource;
-
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertThat;
-
-public final class JDBCDataSourceConfigurationTest {
-
- @Test
- public void assertJDBCDataSourceConfigEquals() {
- StandardJDBCDataSourceConfiguration sourceConfig = new StandardJDBCDataSourceConfiguration("jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false", "root", "root");
- StandardJDBCDataSourceConfiguration targetConfig = new StandardJDBCDataSourceConfiguration("jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false", "root", "root");
- assertThat(sourceConfig, is(targetConfig));
- sourceConfig.setDatabaseType(new MySQLDatabaseType());
- targetConfig.setDatabaseType(new MySQLDatabaseType());
- assertThat(sourceConfig, is(targetConfig));
- }
-
- @Test
- public void assertJDBCDataSourceConfigNotEquals() {
- StandardJDBCDataSourceConfiguration sourceConfig = new StandardJDBCDataSourceConfiguration("jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false", "sa", "root");
- StandardJDBCDataSourceConfiguration targetConfig = new StandardJDBCDataSourceConfiguration("jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false", "root", "root");
- assertThat(sourceConfig, not(targetConfig));
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfigurationTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfigurationTest.java
deleted file mode 100644
index 8b678a1..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfigurationTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.config.datasource;
-
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.scaling.core.fixture.FixtureShardingSphereJDBCConfiguration;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-
-public final class ShardingSphereJDBCDataSourceConfigurationTest {
-
- @Test
- public void assertShardingSphereJDBCDataSourceConfigurationDatabaseType() {
- ShardingSphereJDBCDataSourceConfiguration config = new ShardingSphereJDBCDataSourceConfiguration(
- FixtureShardingSphereJDBCConfiguration.DATA_SOURCE, FixtureShardingSphereJDBCConfiguration.RULE);
- assertThat(config.getDatabaseType(), instanceOf(H2DatabaseType.class));
- }
-}
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
deleted file mode 100644
index 5d93de7..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/fixture/FixtureShardingSphereJDBCConfiguration.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.core.fixture;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final 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/java/org/apache/shardingsphere/scaling/core/job/check/AbstractDataConsistencyCheckerTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/check/AbstractDataConsistencyCheckerTest.java
index 83f1987..b55466d 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/check/AbstractDataConsistencyCheckerTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/check/AbstractDataConsistencyCheckerTest.java
@@ -21,7 +21,7 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.scaling.core.common.datasource.DataSourceManager;
import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.job.JobContext;
-import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
+import org.apache.shardingsphere.scaling.core.util.ResourceUtil;
import org.junit.Test;
import javax.sql.DataSource;
@@ -38,13 +38,13 @@ public final class AbstractDataConsistencyCheckerTest {
@Test
public void assertCountCheck() {
- JobContext jobContext = mockJobContext();
+ JobContext jobContext = new JobContext(ResourceUtil.mockJobConfig());
DataConsistencyChecker dataConsistencyChecker = DataConsistencyCheckerFactory.newInstance(jobContext);
initTableData(jobContext.getTaskConfigs().get(0).getDumperConfig().getDataSourceConfig());
initTableData(jobContext.getTaskConfigs().get(0).getImporterConfig().getDataSourceConfig());
Map<String, DataConsistencyCheckResult> resultMap = dataConsistencyChecker.countCheck();
- assertTrue(resultMap.get("t1").isCountValid());
- assertThat(resultMap.get("t1").getSourceCount(), is(resultMap.get("t1").getTargetCount()));
+ assertTrue(resultMap.get("t_order").isCountValid());
+ assertThat(resultMap.get("t_order").getSourceCount(), is(resultMap.get("t_order").getTargetCount()));
}
@SneakyThrows(SQLException.class)
@@ -52,13 +52,9 @@ public final class AbstractDataConsistencyCheckerTest {
DataSource dataSource = new DataSourceManager().getDataSource(dataSourceConfig);
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
- statement.execute("DROP TABLE IF EXISTS t1");
- statement.execute("CREATE TABLE t1 (id INT PRIMARY KEY, user_id VARCHAR(12))");
- statement.execute("INSERT INTO t1 (id, user_id) VALUES (1, 'xxx'), (999, 'yyy')");
+ statement.execute("DROP TABLE IF EXISTS t_order");
+ statement.execute("CREATE TABLE t_order (order_id INT PRIMARY KEY, user_id VARCHAR(12))");
+ statement.execute("INSERT INTO t_order (order_id, user_id) VALUES (1, 'xxx'), (999, 'yyy')");
}
}
-
- private JobContext mockJobContext() {
- return new JobContext(JobConfigurationUtil.initJobConfig("/config.json"));
- }
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/preparer/splitter/InventoryTaskSplitterTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/preparer/splitter/InventoryTaskSplitterTest.java
index b88dac3..db89ead 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/preparer/splitter/InventoryTaskSplitterTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/job/preparer/splitter/InventoryTaskSplitterTest.java
@@ -21,12 +21,11 @@ import org.apache.shardingsphere.scaling.core.common.datasource.DataSourceManage
import org.apache.shardingsphere.scaling.core.config.DumperConfiguration;
import org.apache.shardingsphere.scaling.core.config.ImporterConfiguration;
import org.apache.shardingsphere.scaling.core.config.TaskConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.ScalingDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.job.JobContext;
import org.apache.shardingsphere.scaling.core.job.position.PrimaryKeyPosition;
import org.apache.shardingsphere.scaling.core.job.task.inventory.InventoryTask;
-import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
+import org.apache.shardingsphere.scaling.core.util.ResourceUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -149,7 +148,7 @@ public final class InventoryTaskSplitterTest {
}
private JobContext mockJobContext() {
- JobContext result = new JobContext(JobConfigurationUtil.initJobConfig("/config.json"));
+ JobContext result = new JobContext(ResourceUtil.mockJobConfig());
result.getJobConfig().getHandleConfig().setDatabaseType("H2");
result.getJobConfig().getHandleConfig().setShardingSize(10);
taskConfig = new TaskConfiguration(result.getJobConfig().getHandleConfig(), mockDumperConfig(), new ImporterConfiguration());
@@ -157,9 +156,8 @@ public final class InventoryTaskSplitterTest {
}
private DumperConfiguration mockDumperConfig() {
- ScalingDataSourceConfiguration dataSourceConfig = new StandardJDBCDataSourceConfiguration(DATA_SOURCE_URL, USERNAME, PASSWORD);
DumperConfiguration result = new DumperConfiguration();
- result.setDataSourceConfig(dataSourceConfig);
+ result.setDataSourceConfig(new StandardJDBCDataSourceConfiguration(DATA_SOURCE_URL, USERNAME, PASSWORD));
Map<String, String> tableMap = new HashMap<>(1, 1);
tableMap.put("t_order", "t_order");
result.setTableNameMap(tableMap);
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/JDBCUtilTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/JDBCUtilTest.java
index 08b0732..6753df7 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/JDBCUtilTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/JDBCUtilTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.scaling.core.util;
import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.governance.core.yaml.config.YamlConfigurationConverter;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.scaling.core.config.datasource.ConfigurationYamlConverter;
import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
import org.junit.Test;
@@ -35,14 +35,14 @@ public final class JDBCUtilTest {
public void assertAppendStandardJDBCDataSourceConfiguration() {
StandardJDBCDataSourceConfiguration dataSourceConfig = new StandardJDBCDataSourceConfiguration("jdbc:mysql://192.168.0.1:3306/scaling?serverTimezone=UTC&useSSL=false", null, null);
JDBCUtil.appendJDBCParameter(dataSourceConfig, ImmutableMap.<String, String>builder().put("rewriteBatchedStatements", "true").build());
- assertThat(dataSourceConfig.getJdbcUrl(), is("jdbc:mysql://192.168.0.1:3306/scaling?rewriteBatchedStatements=true&serverTimezone=UTC&useSSL=false"));
+ assertThat(dataSourceConfig.getHikariConfig().getJdbcUrl(), is("jdbc:mysql://192.168.0.1:3306/scaling?rewriteBatchedStatements=true&serverTimezone=UTC&useSSL=false"));
}
@Test
public void assertAppendShardingSphereJDBCDataSourceConfig() {
- ShardingSphereJDBCDataSourceConfiguration dataSourceConfig = new ShardingSphereJDBCDataSourceConfiguration(mockDataSource(), null);
+ ShardingSphereJDBCDataSourceConfiguration dataSourceConfig = new ShardingSphereJDBCDataSourceConfiguration(mockDataSource(), "");
JDBCUtil.appendJDBCParameter(dataSourceConfig, ImmutableMap.<String, String>builder().put("rewriteBatchedStatements", "true").build());
- ArrayList<DataSourceConfiguration> actual = new ArrayList<>(ConfigurationYamlConverter.loadDataSourceConfigs(dataSourceConfig.getDataSource()).values());
+ ArrayList<DataSourceConfiguration> actual = new ArrayList<>(YamlConfigurationConverter.convertDataSourceConfigurations(dataSourceConfig.getDataSourceRuleConfig().getDataSources()).values());
assertThat(actual.get(0).getProps().get("url"), is("jdbc:mysql://192.168.0.2:3306/scaling?rewriteBatchedStatements=true&serverTimezone=UTC&useSSL=false"));
assertThat(actual.get(1).getProps().get("url"), is("jdbc:mysql://192.168.0.1:3306/scaling?rewriteBatchedStatements=true&serverTimezone=UTC&useSSL=false"));
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/ResourceUtil.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/ResourceUtil.java
new file mode 100644
index 0000000..3ba8b25
--- /dev/null
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/util/ResourceUtil.java
@@ -0,0 +1,79 @@
+/*
+ * 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.util;
+
+import lombok.SneakyThrows;
+import org.apache.commons.io.IOUtils;
+import org.apache.shardingsphere.scaling.core.config.JobConfiguration;
+import org.apache.shardingsphere.scaling.core.config.RuleConfiguration;
+import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
+import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Resource util.
+ */
+public final class ResourceUtil {
+
+ /**
+ * Mock job configuration.
+ *
+ * @return job configuration
+ */
+ public static JobConfiguration mockJobConfig() {
+ return mockStandardJdbcTargetJobConfig();
+ }
+
+ /**
+ * Mock ShardingSphere-JDBC as target job configuration.
+ *
+ * @return ShardingSphere-JDBC target job configuration
+ */
+ public static JobConfiguration mockShardingSphereJdbcTargetJobConfig() {
+ JobConfiguration result = new JobConfiguration();
+ RuleConfiguration ruleConfig = new RuleConfiguration();
+ ruleConfig.setSource(new ShardingSphereJDBCDataSourceConfiguration(readFileToString("/config_sharding_sphere_jdbc_source.yaml")).wrap());
+ ruleConfig.setTarget(new ShardingSphereJDBCDataSourceConfiguration(readFileToString("/config_sharding_sphere_jdbc_target.yaml")).wrap());
+ result.setRuleConfig(ruleConfig);
+ return result;
+ }
+
+ /**
+ * Mock standard JDBC as target job configuration.
+ *
+ * @return standard JDBC as target job configuration
+ */
+ public static JobConfiguration mockStandardJdbcTargetJobConfig() {
+ JobConfiguration result = new JobConfiguration();
+ RuleConfiguration ruleConfig = new RuleConfiguration();
+ ruleConfig.setSource(new ShardingSphereJDBCDataSourceConfiguration(readFileToString("/config_sharding_sphere_jdbc_source.yaml")).wrap());
+ ruleConfig.setTarget(new StandardJDBCDataSourceConfiguration(readFileToString("/config_standard_jdbc_target.yaml")).wrap());
+ result.setRuleConfig(ruleConfig);
+ return result;
+ }
+
+ @SneakyThrows(IOException.class)
+ private static String readFileToString(final String fileName) {
+ try (InputStream in = ResourceUtil.class.getResourceAsStream(fileName)) {
+ return IOUtils.toString(in, StandardCharsets.UTF_8);
+ }
+ }
+}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
deleted file mode 100644
index ac2a2bd..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config.json
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-{
- "ruleConfig": {
- "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"
- }
- }
- },
- "handleConfig": {
- "concurrency": 3,
- "shardingTables": ["ds_0.t1", "ds_0.t2"],
- "shardingItem": 0
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_source.yaml b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_source.yaml
new file mode 100644
index 0000000..f2150b8
--- /dev/null
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_source.yaml
@@ -0,0 +1,45 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+dataSources:
+ ds_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ jdbcUrl: jdbc:h2:mem:test_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+ username: root
+ password: root
+rules:
+- !SHARDING
+ defaultDatabaseStrategy:
+ standard:
+ shardingAlgorithmName: default_db_inline
+ shardingColumn: user_id
+ tables:
+ t_order:
+ actualDataNodes: ds_0.t_order
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ tableStrategy:
+ standard:
+ shardingAlgorithmName: t_order_tbl_inline
+ shardingColumn: order_id
+ shardingAlgorithms:
+ default_db_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_0
+ t_order_tbl_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.json b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.json
deleted file mode 100644
index 97f50b9..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.json
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-{
- "ruleConfig": {
- "source": {
- "type": "shardingSphereJdbc",
- "parameter": {
- "dataSource": "dataSources:\n ds_0:\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:h2:mem:test_db_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL\n username: root\n password: 'password'\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_1:\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 ds_2:\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: 'password'\n",
- "rule": "rules:\n- !SHARDING\n defaultDatabaseStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\n tables:\n t1:\n actualDataNodes: ds_$->{1..2}.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_$->{1..2}.t2\n keyGenerateStrategy:\n colu [...]
- }
- }
- },
- "handleConfig": {
- "concurrency": 3
- }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.yaml b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.yaml
new file mode 100644
index 0000000..9e8bc97
--- /dev/null
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_sharding_sphere_jdbc_target.yaml
@@ -0,0 +1,51 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+dataSources:
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ jdbcUrl: jdbc:h2:mem:test_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+ username: root
+ password: root
+ ds_2:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ props:
+ jdbcUrl: jdbc:h2:mem:test_ds_2;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+ username: root
+ password: root
+rules:
+- !SHARDING
+ defaultDatabaseStrategy:
+ standard:
+ shardingAlgorithmName: default_db_inline
+ shardingColumn: user_id
+ tables:
+ t_order:
+ actualDataNodes: ds_$->{1..2}.t_order_$->{0..1}
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ tableStrategy:
+ standard:
+ shardingAlgorithmName: t1_tbl_inline
+ shardingColumn: order_id
+ shardingAlgorithms:
+ default_db_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_$->{user_id % 2 + 1}
+ t_order_tbl_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_$->{order_id % 2}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_standard_jdbc_target.yaml b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_standard_jdbc_target.yaml
new file mode 100644
index 0000000..235cdb6
--- /dev/null
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/resources/config_standard_jdbc_target.yaml
@@ -0,0 +1,16 @@
+# 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.
+#
+
+jdbcUrl: jdbc:h2:mem:test_ds_3;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+username: root
+password: root
diff --git a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/component/MySQLBinlogDumper.java b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/component/MySQLBinlogDumper.java
index d298735..7cccfab 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/component/MySQLBinlogDumper.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/component/MySQLBinlogDumper.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.scaling.mysql.component;
import com.google.common.base.Preconditions;
+import com.zaxxer.hikari.HikariConfig;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
@@ -83,9 +84,9 @@ public final class MySQLBinlogDumper extends AbstractScalingExecutor implements
}
private void dump() {
- StandardJDBCDataSourceConfiguration jdbcDataSourceConfig = (StandardJDBCDataSourceConfiguration) dumperConfig.getDataSourceConfig();
- JdbcUri uri = new JdbcUri(jdbcDataSourceConfig.getJdbcUrl());
- MySQLClient client = new MySQLClient(new ConnectInfo(random.nextInt(), uri.getHostname(), uri.getPort(), jdbcDataSourceConfig.getUsername(), jdbcDataSourceConfig.getPassword()));
+ HikariConfig hikariConfig = ((StandardJDBCDataSourceConfiguration) dumperConfig.getDataSourceConfig()).getHikariConfig();
+ JdbcUri uri = new JdbcUri(hikariConfig.getJdbcUrl());
+ MySQLClient client = new MySQLClient(new ConnectInfo(random.nextInt(), uri.getHostname(), uri.getPort(), hikariConfig.getUsername(), hikariConfig.getPassword()));
client.connect();
client.subscribe(binlogPosition.getFilename(), binlogPosition.getPosition());
while (isRunning()) {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/LogicalReplication.java b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/LogicalReplication.java
index cdfbe0b..3378a39 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/LogicalReplication.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/LogicalReplication.java
@@ -46,12 +46,12 @@ public final class LogicalReplication {
private Connection createConnection(final StandardJDBCDataSourceConfiguration jdbcDataSourceConfig) throws SQLException {
Properties props = new Properties();
- PGProperty.USER.set(props, jdbcDataSourceConfig.getUsername());
- PGProperty.PASSWORD.set(props, jdbcDataSourceConfig.getPassword());
+ PGProperty.USER.set(props, jdbcDataSourceConfig.getHikariConfig().getUsername());
+ PGProperty.PASSWORD.set(props, jdbcDataSourceConfig.getHikariConfig().getPassword());
PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.6");
PGProperty.REPLICATION.set(props, "database");
PGProperty.PREFER_QUERY_MODE.set(props, "simple");
- return DriverManager.getConnection(jdbcDataSourceConfig.getJdbcUrl(), props);
+ return DriverManager.getConnection(jdbcDataSourceConfig.getHikariConfig().getJdbcUrl(), props);
}
/**
diff --git a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/WalEventConverter.java b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/WalEventConverter.java
index 4b84ce4..314a33a 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/WalEventConverter.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/wal/WalEventConverter.java
@@ -58,7 +58,7 @@ public final class WalEventConverter {
* @return record
*/
public Record convert(final AbstractWalEvent event) {
- JdbcUri uri = new JdbcUri(((StandardJDBCDataSourceConfiguration) dumperConfig.getDataSourceConfig()).getJdbcUrl());
+ JdbcUri uri = new JdbcUri(((StandardJDBCDataSourceConfiguration) dumperConfig.getDataSourceConfig()).getHikariConfig().getJdbcUrl());
if (filter(uri.getDatabase(), event)) {
return createPlaceholderRecord(event);
} else if (event instanceof WriteRowEvent) {