未验证 提交 d7ac54f9 编写于 作者: L Liang Zhang 提交者: GitHub

Add YamlShardingSphereAlgorithmConfiguration to abstract yaml algorithm (#6033)

* remove YamlKeyGenerateAlgorithmConfiguration

* remove YamlShardingAlgorithmConfiguration

* remove YamlMasterSlaveLoadBalanceAlgorithmConfiguration

* remove YamlEncryptAlgorithmConfiguration
上级 12fb3f69
......@@ -20,9 +20,9 @@ package org.apache.shardingsphere.encrypt.yaml.config;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.algorithm.YamlEncryptAlgorithmConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -36,7 +36,7 @@ public final class YamlEncryptRuleConfiguration implements YamlRuleConfiguration
private Map<String, YamlEncryptTableRuleConfiguration> tables = new LinkedHashMap<>();
private Map<String, YamlEncryptAlgorithmConfiguration> encryptors = new LinkedHashMap<>();
private Map<String, YamlShardingSphereAlgorithmConfiguration> encryptors = new LinkedHashMap<>();
@Override
public Class<EncryptRuleConfiguration> getRuleConfigurationType() {
......
......@@ -18,14 +18,14 @@
package org.apache.shardingsphere.encrypt.yaml.swapper;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithmConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.algorithm.YamlEncryptAlgorithmConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.swapper.algorithm.EncryptAlgorithmConfigurationYamlSwapper;
import org.apache.shardingsphere.encrypt.yaml.swapper.rule.EncryptTableRuleConfigurationYamlSwapper;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
import java.util.Collection;
......@@ -68,8 +68,8 @@ public final class EncryptRuleConfigurationYamlSwapper implements YamlRuleConfig
private Map<String, EncryptAlgorithmConfiguration> swapEncryptAlgorithm(final YamlEncryptRuleConfiguration yamlConfiguration) {
Map<String, EncryptAlgorithmConfiguration> result = new LinkedHashMap<>();
for (Entry<String, YamlEncryptAlgorithmConfiguration> entry : yamlConfiguration.getEncryptors().entrySet()) {
YamlEncryptAlgorithmConfiguration yamlEncryptAlgorithmConfiguration = entry.getValue();
for (Entry<String, YamlShardingSphereAlgorithmConfiguration> entry : yamlConfiguration.getEncryptors().entrySet()) {
YamlShardingSphereAlgorithmConfiguration yamlEncryptAlgorithmConfiguration = entry.getValue();
result.put(entry.getKey(), encryptAlgorithmConfigurationYamlSwapper.swap(yamlEncryptAlgorithmConfiguration));
}
return result;
......
......@@ -18,24 +18,24 @@
package org.apache.shardingsphere.encrypt.yaml.swapper.algorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithmConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.algorithm.YamlEncryptAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
/**
* Encrypt algorithm configuration YAML swapper.
*/
public final class EncryptAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlEncryptAlgorithmConfiguration, EncryptAlgorithmConfiguration> {
public final class EncryptAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlShardingSphereAlgorithmConfiguration, EncryptAlgorithmConfiguration> {
@Override
public YamlEncryptAlgorithmConfiguration swap(final EncryptAlgorithmConfiguration data) {
YamlEncryptAlgorithmConfiguration result = new YamlEncryptAlgorithmConfiguration();
public YamlShardingSphereAlgorithmConfiguration swap(final EncryptAlgorithmConfiguration data) {
YamlShardingSphereAlgorithmConfiguration result = new YamlShardingSphereAlgorithmConfiguration();
result.setType(data.getType());
result.setProps(data.getProps());
return result;
}
@Override
public EncryptAlgorithmConfiguration swap(final YamlEncryptAlgorithmConfiguration yamlConfiguration) {
public EncryptAlgorithmConfiguration swap(final YamlShardingSphereAlgorithmConfiguration yamlConfiguration) {
return new EncryptAlgorithmConfiguration(yamlConfiguration.getType(), yamlConfiguration.getProps());
}
}
......@@ -20,8 +20,8 @@ package org.apache.shardingsphere.masterslave.yaml.config;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.algorithm.YamlMasterSlaveLoadBalanceAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
import java.util.LinkedHashMap;
......@@ -36,7 +36,7 @@ public final class YamlMasterSlaveRuleConfiguration implements YamlRuleConfigura
private Map<String, YamlMasterSlaveDataSourceRuleConfiguration> dataSources = new LinkedHashMap<>();
private Map<String, YamlMasterSlaveLoadBalanceAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>();
private Map<String, YamlShardingSphereAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>();
@Override
public Class<MasterSlaveRuleConfiguration> getRuleConfigurationType() {
......
/*
* 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.masterslave.yaml.config.algorithm;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
import java.util.Properties;
/**
* Master-slave load balance algorithm configuration for YAML.
*/
@Getter
@Setter
public final class YamlMasterSlaveLoadBalanceAlgorithmConfiguration implements YamlConfiguration {
private String type;
private Properties props = new Properties();
}
......@@ -17,14 +17,14 @@
package org.apache.shardingsphere.masterslave.yaml.swapper;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.algorithm.LoadBalanceAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.constant.MasterSlaveOrder;
import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.algorithm.YamlMasterSlaveLoadBalanceAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
import java.util.Collection;
import java.util.LinkedHashMap;
......@@ -61,7 +61,7 @@ public final class MasterSlaveRuleConfigurationYamlSwapper implements YamlRuleCo
dataSources.add(swap(entry.getKey(), entry.getValue()));
}
Map<String, LoadBalanceAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>(yamlConfiguration.getLoadBalancers().entrySet().size(), 1);
for (Entry<String, YamlMasterSlaveLoadBalanceAlgorithmConfiguration> entry : yamlConfiguration.getLoadBalancers().entrySet()) {
for (Entry<String, YamlShardingSphereAlgorithmConfiguration> entry : yamlConfiguration.getLoadBalancers().entrySet()) {
loadBalancers.put(entry.getKey(), swap(entry.getValue()));
}
return new MasterSlaveRuleConfiguration(dataSources, loadBalancers);
......@@ -72,7 +72,7 @@ public final class MasterSlaveRuleConfigurationYamlSwapper implements YamlRuleCo
yamlDataSourceRuleConfiguration.getMasterDataSourceName(), yamlDataSourceRuleConfiguration.getSlaveDataSourceNames(), yamlDataSourceRuleConfiguration.getLoadBalancerName());
}
private LoadBalanceAlgorithmConfiguration swap(final YamlMasterSlaveLoadBalanceAlgorithmConfiguration yamlLoadBalanceAlgorithmConfiguration) {
private LoadBalanceAlgorithmConfiguration swap(final YamlShardingSphereAlgorithmConfiguration yamlLoadBalanceAlgorithmConfiguration) {
return new LoadBalanceAlgorithmConfiguration(yamlLoadBalanceAlgorithmConfiguration.getType(), yamlLoadBalanceAlgorithmConfiguration.getProps());
}
......
......@@ -20,9 +20,8 @@ package org.apache.shardingsphere.sharding.yaml.config;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.algorithm.YamlKeyGenerateAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.algorithm.YamlShardingAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.strategy.keygen.YamlKeyGenerateStrategyConfiguration;
......@@ -54,9 +53,9 @@ public final class YamlShardingRuleConfiguration implements YamlRuleConfiguratio
private YamlKeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
private Map<String, YamlShardingAlgorithmConfiguration> shardingAlgorithms = new LinkedHashMap<>();
private Map<String, YamlShardingSphereAlgorithmConfiguration> shardingAlgorithms = new LinkedHashMap<>();
private Map<String, YamlKeyGenerateAlgorithmConfiguration> keyGenerators = new LinkedHashMap<>();
private Map<String, YamlShardingSphereAlgorithmConfiguration> keyGenerators = new LinkedHashMap<>();
@Override
public Class<ShardingRuleConfiguration> getRuleConfigurationType() {
......
/*
* 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.sharding.yaml.config.algorithm;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
import java.util.Properties;
/**
* Key generate algorithm configuration for YAML.
*/
@Getter
@Setter
public final class YamlKeyGenerateAlgorithmConfiguration implements YamlConfiguration {
private String type;
private Properties props = new Properties();
}
/*
* 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.sharding.yaml.config.algorithm;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
import java.util.Properties;
/**
* Sharding algorithm configuration for YAML.
*/
@Getter
@Setter
public final class YamlShardingAlgorithmConfiguration implements YamlConfiguration {
private String type;
private Properties props = new Properties();
}
......@@ -18,30 +18,30 @@
package org.apache.shardingsphere.sharding.yaml.swapper.algorithm;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
import org.apache.shardingsphere.sharding.api.config.algorithm.KeyGenerateAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.yaml.config.algorithm.YamlKeyGenerateAlgorithmConfiguration;
/**
* Key generate algorithm configuration YAML swapper.
*/
public final class KeyGenerateAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlKeyGenerateAlgorithmConfiguration, KeyGenerateAlgorithmConfiguration> {
public final class KeyGenerateAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlShardingSphereAlgorithmConfiguration, KeyGenerateAlgorithmConfiguration> {
static {
ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
}
@Override
public YamlKeyGenerateAlgorithmConfiguration swap(final KeyGenerateAlgorithmConfiguration data) {
YamlKeyGenerateAlgorithmConfiguration result = new YamlKeyGenerateAlgorithmConfiguration();
public YamlShardingSphereAlgorithmConfiguration swap(final KeyGenerateAlgorithmConfiguration data) {
YamlShardingSphereAlgorithmConfiguration result = new YamlShardingSphereAlgorithmConfiguration();
result.setType(data.getType());
result.setProps(data.getProps());
return result;
}
@Override
public KeyGenerateAlgorithmConfiguration swap(final YamlKeyGenerateAlgorithmConfiguration yamlConfiguration) {
public KeyGenerateAlgorithmConfiguration swap(final YamlShardingSphereAlgorithmConfiguration yamlConfiguration) {
return new KeyGenerateAlgorithmConfiguration(yamlConfiguration.getType(), yamlConfiguration.getProps());
}
}
......@@ -18,30 +18,30 @@
package org.apache.shardingsphere.sharding.yaml.swapper.algorithm;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
import org.apache.shardingsphere.sharding.api.config.algorithm.ShardingAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.sharding.yaml.config.algorithm.YamlShardingAlgorithmConfiguration;
/**
* Sharding algorithm configuration YAML swapper.
*/
public final class ShardingAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlShardingAlgorithmConfiguration, ShardingAlgorithmConfiguration> {
public final class ShardingAlgorithmConfigurationYamlSwapper implements YamlSwapper<YamlShardingSphereAlgorithmConfiguration, ShardingAlgorithmConfiguration> {
static {
ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
}
@Override
public YamlShardingAlgorithmConfiguration swap(final ShardingAlgorithmConfiguration data) {
YamlShardingAlgorithmConfiguration result = new YamlShardingAlgorithmConfiguration();
public YamlShardingSphereAlgorithmConfiguration swap(final ShardingAlgorithmConfiguration data) {
YamlShardingSphereAlgorithmConfiguration result = new YamlShardingSphereAlgorithmConfiguration();
result.setType(data.getType());
result.setProps(data.getProps());
return result;
}
@Override
public ShardingAlgorithmConfiguration swap(final YamlShardingAlgorithmConfiguration yamlConfiguration) {
public ShardingAlgorithmConfiguration swap(final YamlShardingSphereAlgorithmConfiguration yamlConfiguration) {
return new ShardingAlgorithmConfiguration(yamlConfiguration.getType(), yamlConfiguration.getProps());
}
}
......@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.yaml.swapper.algorithm;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.api.config.algorithm.KeyGenerateAlgorithmConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.algorithm.YamlKeyGenerateAlgorithmConfiguration;
import org.junit.Test;
import java.util.Properties;
......@@ -30,14 +30,14 @@ public final class KeyGenerateAlgorithmConfigurationYamlSwapperTest {
@Test
public void assertSwapToYaml() {
YamlKeyGenerateAlgorithmConfiguration actual = new KeyGenerateAlgorithmConfigurationYamlSwapper().swap(new KeyGenerateAlgorithmConfiguration("UUID", new Properties()));
YamlShardingSphereAlgorithmConfiguration actual = new KeyGenerateAlgorithmConfigurationYamlSwapper().swap(new KeyGenerateAlgorithmConfiguration("UUID", new Properties()));
assertThat(actual.getType(), is("UUID"));
assertThat(actual.getProps(), is(new Properties()));
}
@Test
public void assertSwapToObject() {
YamlKeyGenerateAlgorithmConfiguration yamlConfiguration = new YamlKeyGenerateAlgorithmConfiguration();
YamlShardingSphereAlgorithmConfiguration yamlConfiguration = new YamlShardingSphereAlgorithmConfiguration();
yamlConfiguration.setType("UUID");
KeyGenerateAlgorithmConfiguration actual = new KeyGenerateAlgorithmConfigurationYamlSwapper().swap(yamlConfiguration);
assertThat(actual.getType(), is("UUID"));
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.encrypt.yaml.config.algorithm;
package org.apache.shardingsphere.infra.yaml.config.algorithm;
import lombok.Getter;
import lombok.Setter;
......@@ -24,11 +24,11 @@ import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
import java.util.Properties;
/**
* Encrypt algorithm configuration for YAML.
* ShardingSphere algorithm configuration for YAML.
*/
@Getter
@Setter
public final class YamlEncryptAlgorithmConfiguration implements YamlConfiguration {
public final class YamlShardingSphereAlgorithmConfiguration implements YamlConfiguration {
private String type;
......
......@@ -18,13 +18,13 @@
package org.apache.shardingsphere.proxy.config;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.algorithm.YamlEncryptAlgorithmConfiguration;
import org.apache.shardingsphere.orchestration.center.yaml.config.YamlCenterRepositoryConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.orchestration.center.yaml.config.YamlCenterRepositoryConfiguration;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
import org.junit.Test;
import java.io.IOException;
......@@ -127,10 +127,10 @@ public final class ShardingConfigurationLoaderTest {
assertThat(actual.getEncryptors().size(), is(2));
assertTrue(actual.getEncryptors().containsKey("aes_encryptor"));
assertTrue(actual.getEncryptors().containsKey("md5_encryptor"));
YamlEncryptAlgorithmConfiguration aesEncryptAlgorithmConfiguration = actual.getEncryptors().get("aes_encryptor");
YamlShardingSphereAlgorithmConfiguration aesEncryptAlgorithmConfiguration = actual.getEncryptors().get("aes_encryptor");
assertThat(aesEncryptAlgorithmConfiguration.getType(), is("AES"));
assertThat(aesEncryptAlgorithmConfiguration.getProps().getProperty("aes.key.value"), is("123456abc"));
YamlEncryptAlgorithmConfiguration md5EncryptAlgorithmConfiguration = actual.getEncryptors().get("md5_encryptor");
YamlShardingSphereAlgorithmConfiguration md5EncryptAlgorithmConfiguration = actual.getEncryptors().get("md5_encryptor");
assertThat(md5EncryptAlgorithmConfiguration.getType(), is("MD5"));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册