You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by do...@apache.org on 2021/05/17 14:25:05 UTC
[shardingsphere] branch master updated: Inline
PersistedYamlConfigurationWrapper (#10369)
This is an automated email from the ASF dual-hosted git repository.
dongzonglei 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 e031fcf Inline PersistedYamlConfigurationWrapper (#10369)
e031fcf is described below
commit e031fcf943cb6067404ff41fc47da0015058ddbe
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon May 17 22:24:31 2021 +0800
Inline PersistedYamlConfigurationWrapper (#10369)
---
.../governance/core/registry/RegistryCenter.java | 27 +++++---
.../listener/impl/DataSourceChangedListener.java | 2 +-
.../listener/impl/GlobalRuleChangedListener.java | 2 +-
.../listener/impl/RuleChangedListener.java | 2 +-
.../PersistedYamlDataSourceConfiguration.java | 2 +-
.../{pojo => }/PersistedYamlRuleConfiguration.java | 2 +-
.../wrapper/PersistedYamlConfigurationWrapper.java | 72 ----------------------
.../core/registry/RegistryCenterTest.java | 2 +-
.../scaling/core/util/JobConfigurationUtil.java | 19 ++++--
.../scaling/core/util/JDBCUtilTest.java | 12 +++-
10 files changed, 49 insertions(+), 93 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index ec41d2b..c788772 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -40,11 +40,10 @@ import org.apache.shardingsphere.governance.core.registry.listener.event.rule.Ru
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.SwitchRuleConfigurationEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.scaling.StartScalingEvent;
-import org.apache.shardingsphere.governance.core.yaml.persisted.wrapper.PersistedYamlConfigurationWrapper;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlDataSourceConfiguration;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlRuleConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.pojo.schema.YamlSchema;
import org.apache.shardingsphere.governance.core.yaml.config.swapper.SchemaYamlSwapper;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlDataSourceConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlRuleConfiguration;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
@@ -265,8 +264,17 @@ public final class RegistryCenter {
* @return data source configurations
*/
public Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String schemaName) {
- return hasDataSourceConfiguration(schemaName)
- ? PersistedYamlConfigurationWrapper.unwrapDataSourceConfigurations(repository.get(node.getMetadataDataSourcePath(schemaName))) : new LinkedHashMap<>();
+ return hasDataSourceConfiguration(schemaName) ? getDataSourceConfigurations(repository.get(node.getMetadataDataSourcePath(schemaName))) : new LinkedHashMap<>();
+ }
+
+ private static Map<String, DataSourceConfiguration> getDataSourceConfigurations(final String yamlContent) {
+ PersistedYamlDataSourceConfiguration persistedConfig = YamlEngine.unmarshal(yamlContent, PersistedYamlDataSourceConfiguration.class);
+ if (null == persistedConfig.getDataSources() || persistedConfig.getDataSources().isEmpty()) {
+ return new LinkedHashMap<>();
+ }
+ Map<String, DataSourceConfiguration> result = new LinkedHashMap<>(persistedConfig.getDataSources().size());
+ persistedConfig.getDataSources().forEach((key, value) -> result.put(key, new YamlDataSourceConfigurationSwapper().swapToDataSourceConfiguration(value)));
+ return result;
}
/**
@@ -276,7 +284,10 @@ public final class RegistryCenter {
* @return rule configurations
*/
public Collection<RuleConfiguration> loadRuleConfigurations(final String schemaName) {
- return hasRuleConfiguration(schemaName) ? PersistedYamlConfigurationWrapper.unwrapRuleConfigurations(repository.get(node.getRulePath(schemaName))) : new LinkedList<>();
+ return hasRuleConfiguration(schemaName)
+ ? new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(
+ YamlEngine.unmarshal(repository.get(node.getRulePath(schemaName)), PersistedYamlRuleConfiguration.class).getRules())
+ : new LinkedList<>();
}
/**
@@ -303,7 +314,9 @@ public final class RegistryCenter {
* @return global rule configurations
*/
public Collection<RuleConfiguration> loadGlobalRuleConfigurations() {
- return hasGlobalRuleConfigurations() ? PersistedYamlConfigurationWrapper.unwrapRuleConfigurations(repository.get(node.getGlobalRuleNode())) : Collections.emptyList();
+ return hasGlobalRuleConfigurations()
+ ? new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(repository.get(node.getGlobalRuleNode()), PersistedYamlRuleConfiguration.class).getRules())
+ : Collections.emptyList();
}
/**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/DataSourceChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/DataSourceChangedListener.java
index 3173edd..29ab533 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/DataSourceChangedListener.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/DataSourceChangedListener.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
import org.apache.shardingsphere.governance.core.registry.listener.PostGovernanceRepositoryEventListener;
import org.apache.shardingsphere.governance.core.registry.listener.event.GovernanceEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.datasource.DataSourceChangedEvent;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlDataSourceConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlDataSourceConfiguration;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/GlobalRuleChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/GlobalRuleChangedListener.java
index c814be1..2656eef 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/GlobalRuleChangedListener.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/GlobalRuleChangedListener.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
import org.apache.shardingsphere.governance.core.registry.listener.PostGovernanceRepositoryEventListener;
import org.apache.shardingsphere.governance.core.registry.listener.event.GovernanceEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.GlobalRuleConfigurationsChangedEvent;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlRuleConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlRuleConfiguration;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/RuleChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/RuleChangedListener.java
index de3ee78..8ed8d20 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/RuleChangedListener.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/impl/RuleChangedListener.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.governance.core.registry.listener.PostGovernanc
import org.apache.shardingsphere.governance.core.registry.listener.event.GovernanceEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationCachedEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsChangedEvent;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlRuleConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlRuleConfiguration;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlDataSourceConfiguration.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlDataSourceConfiguration.java
similarity index 99%
rename from shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlDataSourceConfiguration.java
rename to shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlDataSourceConfiguration.java
index 50e43e2..031444f 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlDataSourceConfiguration.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlDataSourceConfiguration.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.governance.core.yaml.persisted.pojo;
+package org.apache.shardingsphere.governance.core.yaml.persisted;
import lombok.Getter;
import lombok.Setter;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlRuleConfiguration.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlRuleConfiguration.java
similarity index 99%
rename from shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlRuleConfiguration.java
rename to shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlRuleConfiguration.java
index 32a76d7..fa7a6be 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/pojo/PersistedYamlRuleConfiguration.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/PersistedYamlRuleConfiguration.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.governance.core.yaml.persisted.pojo;
+package org.apache.shardingsphere.governance.core.yaml.persisted;
import lombok.Getter;
import lombok.Setter;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/wrapper/PersistedYamlConfigurationWrapper.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/wrapper/PersistedYamlConfigurationWrapper.java
deleted file mode 100644
index e3059c9..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/persisted/wrapper/PersistedYamlConfigurationWrapper.java
+++ /dev/null
@@ -1,72 +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.governance.core.yaml.persisted.wrapper;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlDataSourceConfiguration;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlRuleConfiguration;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlDataSourceConfigurationSwapper;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Configuration wrapper for YAML content.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PersistedYamlConfigurationWrapper {
-
- /**
- * Unwrap data source configuration map from YAML content.
- *
- * @param yamlContent YAML content
- * @return data source configuration map
- */
- public static Map<String, DataSourceConfiguration> unwrapDataSourceConfigurations(final String yamlContent) {
- PersistedYamlDataSourceConfiguration persistedConfig = YamlEngine.unmarshal(yamlContent, PersistedYamlDataSourceConfiguration.class);
- return null == persistedConfig.getDataSources() || persistedConfig.getDataSources().isEmpty() ? new LinkedHashMap<>() : unwrapDataSourceConfigurations(persistedConfig.getDataSources());
- }
-
- /**
- * Unwrap data source configurations from YAML content.
- *
- * @param yamlDataSourceConfigs YAML data source configurations
- * @return data source configurations
- */
- public static Map<String, DataSourceConfiguration> unwrapDataSourceConfigurations(final Map<String, Map<String, Object>> yamlDataSourceConfigs) {
- Map<String, DataSourceConfiguration> result = new LinkedHashMap<>(yamlDataSourceConfigs.size());
- yamlDataSourceConfigs.forEach((key, value) -> result.put(key, new YamlDataSourceConfigurationSwapper().swapToDataSourceConfiguration(value)));
- return result;
- }
-
- /**
- * Unwrap rule configurations from YAML content.
- *
- * @param yamlContent YAML content
- * @return rule configurations
- */
- public static Collection<RuleConfiguration> unwrapRuleConfigurations(final String yamlContent) {
- return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(yamlContent, PersistedYamlRuleConfiguration.class).getRules());
- }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index 419a643..0523255 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.governance.core.registry.listener.event.metadat
import org.apache.shardingsphere.governance.core.registry.listener.event.metadata.MetaDataDroppedEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
import org.apache.shardingsphere.governance.core.registry.listener.event.rule.SwitchRuleConfigurationEvent;
-import org.apache.shardingsphere.governance.core.yaml.persisted.pojo.PersistedYamlRuleConfiguration;
+import org.apache.shardingsphere.governance.core.yaml.persisted.PersistedYamlRuleConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.pojo.schema.YamlSchema;
import org.apache.shardingsphere.governance.core.yaml.config.swapper.SchemaYamlSwapper;
import org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
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 798b218..666dee5 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
@@ -26,10 +26,10 @@ import com.google.common.collect.Sets;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
-import org.apache.shardingsphere.governance.core.yaml.persisted.wrapper.PersistedYamlConfigurationWrapper;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlDataSourceConfigurationSwapper;
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;
@@ -56,6 +56,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -219,12 +220,12 @@ public final class JobConfigurationUtil {
*/
public static List<TaskConfiguration> toTaskConfigs(final JobConfiguration jobConfig) {
List<TaskConfiguration> result = new LinkedList<>();
- ShardingSphereJDBCDataSourceConfiguration sourceConfig = getSourceConfig(jobConfig);
+ ShardingSphereJDBCDataSourceConfiguration sourceConfig = getSourceConfiguration(jobConfig);
ShardingRuleConfiguration sourceRuleConfig = ShardingRuleConfigurationSwapper.findAndConvertShardingRuleConfiguration(sourceConfig.getRootRuleConfigs().getRules());
- Map<String, DataSourceConfiguration> sourceDataSource = PersistedYamlConfigurationWrapper.unwrapDataSourceConfigurations(sourceConfig.getRootRuleConfigs().getDataSources());
+ Map<String, DataSourceConfiguration> sourceDataSource = getDataSourceConfigurations(sourceConfig.getRootRuleConfigs().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);
+ Optional<ShardingRuleConfiguration> targetRuleConfig = getTargetRuleConfiguration(jobConfig);
filterByShardingDataSourceTables(dataSourceTableNameMap, jobConfig.getHandleConfig());
Map<String, Set<String>> shardingColumnsMap = getShardingColumnsMap(targetRuleConfig.orElse(sourceRuleConfig));
for (Map.Entry<String, Map<String, String>> entry : dataSourceTableNameMap.entrySet()) {
@@ -235,13 +236,19 @@ public final class JobConfigurationUtil {
return result;
}
- private static ShardingSphereJDBCDataSourceConfiguration getSourceConfig(final JobConfiguration jobConfig) {
+ private static ShardingSphereJDBCDataSourceConfiguration getSourceConfiguration(final JobConfiguration jobConfig) {
ScalingDataSourceConfiguration result = jobConfig.getRuleConfig().getSource().unwrap();
Preconditions.checkArgument(result instanceof ShardingSphereJDBCDataSourceConfiguration, "Only support ShardingSphere source data source.");
return (ShardingSphereJDBCDataSourceConfiguration) result;
}
- private static Optional<ShardingRuleConfiguration> getTargetRuleConfig(final JobConfiguration jobConfig) {
+ private static Map<String, DataSourceConfiguration> getDataSourceConfigurations(final Map<String, Map<String, Object>> yamlDataSourceConfigs) {
+ Map<String, DataSourceConfiguration> result = new LinkedHashMap<>(yamlDataSourceConfigs.size());
+ yamlDataSourceConfigs.forEach((key, value) -> result.put(key, new YamlDataSourceConfigurationSwapper().swapToDataSourceConfiguration(value)));
+ return result;
+ }
+
+ private static Optional<ShardingRuleConfiguration> getTargetRuleConfiguration(final JobConfiguration jobConfig) {
ScalingDataSourceConfiguration dataSourceConfig = jobConfig.getRuleConfig().getTarget().unwrap();
if (dataSourceConfig instanceof ShardingSphereJDBCDataSourceConfiguration) {
return Optional.of(
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 a19c857..03b076d 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,13 +18,15 @@
package org.apache.shardingsphere.scaling.core.util;
import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.governance.core.yaml.persisted.wrapper.PersistedYamlConfigurationWrapper;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlDataSourceConfigurationSwapper;
import org.apache.shardingsphere.scaling.core.config.datasource.ShardingSphereJDBCDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.datasource.StandardJDBCDataSourceConfiguration;
import org.junit.Test;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -42,7 +44,7 @@ public final class JDBCUtilTest {
public void assertAppendShardingSphereJDBCDataSourceConfig() {
ShardingSphereJDBCDataSourceConfiguration dataSourceConfig = new ShardingSphereJDBCDataSourceConfiguration(mockDataSource(), "");
JDBCUtil.appendJDBCParameter(dataSourceConfig, ImmutableMap.<String, String>builder().put("rewriteBatchedStatements", "true").build());
- ArrayList<DataSourceConfiguration> actual = new ArrayList<>(PersistedYamlConfigurationWrapper.unwrapDataSourceConfigurations(dataSourceConfig.getRootRuleConfigs().getDataSources()).values());
+ ArrayList<DataSourceConfiguration> actual = new ArrayList<>(getDataSourceConfigurations(dataSourceConfig.getRootRuleConfigs().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"));
}
@@ -56,4 +58,10 @@ public final class JDBCUtilTest {
+ " dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n"
+ " url: jdbc:mysql://192.168.0.1:3306/scaling?serverTimezone=UTC&useSSL=false\n";
}
+
+ private static Map<String, DataSourceConfiguration> getDataSourceConfigurations(final Map<String, Map<String, Object>> yamlDataSourceConfigs) {
+ Map<String, DataSourceConfiguration> result = new LinkedHashMap<>(yamlDataSourceConfigs.size());
+ yamlDataSourceConfigs.forEach((key, value) -> result.put(key, new YamlDataSourceConfigurationSwapper().swapToDataSourceConfiguration(value)));
+ return result;
+ }
}