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

Add RawEncryptStrategyConfiguration and SPIEncryptStrategyConfiguration (#5952)

* Add RawEncryptStrategyConfiguration and SPIEncryptStrategyConfiguration

* Add RawLoadBalanceStrategyConfiguration and SPILoadBalanceStrategyConfiguration

* add StrategyConfiguration in infra

* remove useless constructor of TypedSPIConfiguration

* fix typo with MasterSlaveRule

* split MasterSlaveLoadBalanceAlgorithm and SPIMasterSlaveLoadBalanceAlgorithm

* split EncryptAlgorithm and SPIEncryptAlgorithm

* Add ShardingSphereAlgorithmPostProcessor

* for code style
上级 d3f453d1
......@@ -17,11 +17,11 @@
package org.apache.shardingsphere.example.fixture;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm;
import java.util.Properties;
public final class TestQueryAssistedShardingEncryptAlgorithm implements QueryAssistedEncryptAlgorithm {
public final class TestQueryAssistedShardingEncryptAlgorithm implements SPIQueryAssistedEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -18,10 +18,11 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
......@@ -54,7 +55,7 @@ public final class LocalEncryptConfiguration implements ExampleConfiguration {
private EncryptRuleConfiguration getEncryptRuleConfiguration() {
Properties properties = new Properties();
properties.setProperty("aes.key.value", "123456");
EncryptStrategyConfiguration aesRuleConfiguration = new EncryptStrategyConfiguration("status_encrypt_strategy", "aes", properties);
EncryptStrategyConfiguration aesRuleConfiguration = new SPIEncryptStrategyConfiguration("status_encrypt_strategy", "aes", properties);
EncryptColumnRuleConfiguration columnConfigAes = new EncryptColumnRuleConfiguration("status", "status", "", "", "status_encrypt_strategy");
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_order", Collections.singleton(columnConfigAes));
return new EncryptRuleConfiguration(Collections.singleton(aesRuleConfiguration), Collections.singleton(tableConfig));
......
......@@ -18,10 +18,11 @@
package org.apache.shardingsphere.example.encrypt.table.raw.jdbc.config;
import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
......@@ -44,8 +45,8 @@ public final class EncryptDatabasesConfiguration implements ExampleConfiguration
EncryptColumnRuleConfiguration columnConfigTest = new EncryptColumnRuleConfiguration("pwd", "pwd", "assisted_query_pwd", "", "pwd_encrypt_strategy");
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_user", Arrays.asList(columnConfigAes, columnConfigTest));
Collection<EncryptStrategyConfiguration> encryptStrategyConfigurations = new LinkedList<>();
encryptStrategyConfigurations.add(new EncryptStrategyConfiguration("name_encrypt_strategy", "aes", properties));
encryptStrategyConfigurations.add(new EncryptStrategyConfiguration("pwd_encrypt_strategy", "assistedTest", properties));
encryptStrategyConfigurations.add(new SPIEncryptStrategyConfiguration("name_encrypt_strategy", "aes", properties));
encryptStrategyConfigurations.add(new SPIEncryptStrategyConfiguration("pwd_encrypt_strategy", "assistedTest", properties));
EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration(encryptStrategyConfigurations, Collections.singleton(tableConfig));
try {
return ShardingSphereDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), Collections.singleton(encryptRuleConfiguration), properties);
......
......@@ -18,10 +18,11 @@
package org.apache.shardingsphere.example.shadow.table.raw.jdbc.config;
import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
......@@ -43,7 +44,7 @@ public final class EncryptShadowDatabasesConfiguration implements ExampleConfigu
Map<String, DataSource> dataSourceMap = new HashMap<>();
dataSourceMap.put("ds", DataSourceUtil.createDataSource("demo_ds"));
dataSourceMap.put("ds_0", DataSourceUtil.createDataSource("shadow_demo_ds"));
EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration(getEncryptStrategyConfiguration(), getEncryptTableRuleConfigurations());
EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration(getEncryptStrategyConfigurations(), getEncryptTableRuleConfigurations());
Properties properties = new Properties();
properties.setProperty("sql.show", "true");
properties.setProperty("query.with.cipher.column", "true");
......@@ -51,12 +52,12 @@ public final class EncryptShadowDatabasesConfiguration implements ExampleConfigu
return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Arrays.asList(shadowRuleConfiguration, encryptRuleConfiguration), properties);
}
private Collection<EncryptStrategyConfiguration> getEncryptStrategyConfiguration() {
private Collection<EncryptStrategyConfiguration> getEncryptStrategyConfigurations() {
Collection<EncryptStrategyConfiguration> result = new LinkedList<>();
Properties properties = new Properties();
properties.setProperty("aes.key.value", "123456");
EncryptStrategyConfiguration nameEncryptStrategyConfiguration = new EncryptStrategyConfiguration("name_encrypt_strategy", "aes", properties);
EncryptStrategyConfiguration pwdEncryptStrategyConfiguration = new EncryptStrategyConfiguration("pwd_encrypt_strategy", "assistedTest", null);
EncryptStrategyConfiguration nameEncryptStrategyConfiguration = new SPIEncryptStrategyConfiguration("name_encrypt_strategy", "aes", properties);
EncryptStrategyConfiguration pwdEncryptStrategyConfiguration = new SPIEncryptStrategyConfiguration("pwd_encrypt_strategy", "assistedTest", null);
result.add(nameEncryptStrategyConfiguration);
result.add(pwdEncryptStrategyConfiguration);
return result;
......
......@@ -45,10 +45,6 @@ public final class CenterConfiguration extends TypedSPIConfiguration {
*/
private String namespace;
public CenterConfiguration(final String type) {
super(type);
}
public CenterConfiguration(final String type, final Properties properties) {
super(type, properties);
}
......
......@@ -29,7 +29,7 @@ public final class CenterConfigurationTest {
@Test
public void assertConstructorWithType() {
String type = "zookeeper";
assertThat(new CenterConfiguration(type).getType(), is(type));
assertThat(new CenterConfiguration(type, new Properties()).getType(), is(type));
}
@Test
......@@ -45,7 +45,7 @@ public final class CenterConfigurationTest {
public void assertCenterType() {
String type = "zookeeper";
String orchestrationType = "config_center";
CenterConfiguration configuration = new CenterConfiguration(type);
CenterConfiguration configuration = new CenterConfiguration(type, new Properties());
configuration.setOrchestrationType(orchestrationType);
assertThat(configuration.getOrchestrationType(), is(orchestrationType));
}
......@@ -54,7 +54,7 @@ public final class CenterConfigurationTest {
public void assertServerLists() {
String type = "zookeeper";
String serverLists = "127.0.0.1:2181,127.0.0.1:2182";
CenterConfiguration configuration = new CenterConfiguration(type);
CenterConfiguration configuration = new CenterConfiguration(type, new Properties());
configuration.setServerLists(serverLists);
assertThat(configuration.getServerLists(), is(serverLists));
}
......@@ -63,7 +63,7 @@ public final class CenterConfigurationTest {
public void assertNamespace() {
String type = "zookeeper";
String namespace = "orchestration";
CenterConfiguration configuration = new CenterConfiguration(type);
CenterConfiguration configuration = new CenterConfiguration(type, new Properties());
configuration.setNamespace(namespace);
assertThat(configuration.getNamespace(), is(namespace));
}
......
......@@ -64,7 +64,7 @@ public final class ApolloCenterRepositoryTest {
@SneakyThrows(ReflectiveOperationException.class)
@BeforeClass
public static void init() {
CenterConfiguration configuration = new CenterConfiguration("apollo");
CenterConfiguration configuration = new CenterConfiguration("apollo", new Properties());
configuration.setServerLists("http://config-service-url");
configuration.setNamespace("orchestration");
Properties properties = new Properties();
......
......@@ -51,7 +51,7 @@ public final class ApolloConfigWrapperTest {
@Before
public void setup() {
CenterConfiguration configuration = new CenterConfiguration("apollo");
CenterConfiguration configuration = new CenterConfiguration("apollo", new Properties());
configuration.setServerLists("http://config-service-url");
configuration.setNamespace("orchestration");
Properties properties = new Properties();
......
......@@ -64,7 +64,7 @@ public final class ApolloOpenApiWrapperTest {
Properties properties = new Properties();
properties.setProperty(ApolloPropertyKey.PORTAL_URL.getKey(), PORTAL_URL);
properties.setProperty(ApolloPropertyKey.TOKEN.getKey(), TOKEN);
apolloOpenApiWrapper = new ApolloOpenApiWrapper(new CenterConfiguration("apollo"), new ApolloProperties(properties));
apolloOpenApiWrapper = new ApolloOpenApiWrapper(new CenterConfiguration("apollo", new Properties()), new ApolloProperties(properties));
FieldSetter.setField(apolloOpenApiWrapper, ApolloOpenApiWrapper.class.getDeclaredField("client"), client);
FieldSetter.setField(apolloOpenApiWrapper, ApolloOpenApiWrapper.class.getDeclaredField("namespace"), NAME_SPACE);
FieldSetter.setField(apolloOpenApiWrapper, ApolloOpenApiWrapper.class.getDeclaredField("appId"), ApolloPropertyKey.APP_ID.getDefaultValue());
......
......@@ -34,7 +34,6 @@ import io.etcd.jetcd.watch.WatchResponse;
import io.grpc.stub.StreamObserver;
import lombok.SneakyThrows;
import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -42,23 +41,24 @@ import org.mockito.Mock;
import org.mockito.internal.util.reflection.FieldSetter;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class EtcdCenterRepositoryTest {
......@@ -223,7 +223,7 @@ public final class EtcdCenterRepositoryTest {
@Test
public void assertProperties() {
CenterConfiguration configuration = new CenterConfiguration(CENTER_TYPE);
CenterConfiguration configuration = new CenterConfiguration(CENTER_TYPE, new Properties());
configuration.setServerLists("127.0.0.1");
Properties properties = new Properties();
centerRepository.setProperties(properties);
......@@ -239,7 +239,7 @@ public final class EtcdCenterRepositoryTest {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
Assert.assertTrue(ex instanceof InterruptedException);
assertThat(ex, instanceOf(InterruptedException.class));
}
}
......@@ -252,7 +252,7 @@ public final class EtcdCenterRepositoryTest {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
Assert.assertTrue(ex instanceof ExecutionException);
assertThat(ex, instanceOf(ExecutionException.class));
}
}
......@@ -265,7 +265,7 @@ public final class EtcdCenterRepositoryTest {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
Assert.assertTrue(ex instanceof InterruptedException);
assertThat(ex, instanceOf(InterruptedException.class));
}
}
......@@ -278,7 +278,7 @@ public final class EtcdCenterRepositoryTest {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
Assert.assertTrue(ex instanceof ExecutionException);
assertThat(ex, instanceOf(ExecutionException.class));
}
}
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.orchestration.core.configcenter;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration;
......@@ -461,7 +461,7 @@ public final class ConfigCenterTest {
} else if (each instanceof EncryptRuleConfiguration) {
EncryptRuleConfiguration encryptRuleConfiguration = (EncryptRuleConfiguration) each;
assertThat(encryptRuleConfiguration.getEncryptStrategies().size(), is(2));
EncryptStrategyConfiguration encryptStrategyConfiguration = encryptRuleConfiguration.getEncryptStrategies().iterator().next();
SPIEncryptStrategyConfiguration encryptStrategyConfiguration = (SPIEncryptStrategyConfiguration) encryptRuleConfiguration.getEncryptStrategies().iterator().next();
assertThat(encryptStrategyConfiguration.getName(), is("aes_encrypt_strategy"));
assertThat(encryptStrategyConfiguration.getType(), is("aes"));
assertThat(encryptStrategyConfiguration.getProperties().get("aes.key.value").toString(), is("123456abcd"));
......@@ -497,7 +497,7 @@ public final class ConfigCenterTest {
ConfigCenter configurationService = new ConfigCenter("test", configCenterRepository);
EncryptRuleConfiguration actual = (EncryptRuleConfiguration) configurationService.loadRuleConfigurations("sharding_db").iterator().next();
assertThat(actual.getEncryptStrategies().size(), is(1));
EncryptStrategyConfiguration encryptStrategyConfiguration = actual.getEncryptStrategies().iterator().next();
SPIEncryptStrategyConfiguration encryptStrategyConfiguration = (SPIEncryptStrategyConfiguration) actual.getEncryptStrategies().iterator().next();
assertThat(encryptStrategyConfiguration.getName(), is("order_encrypt_strategy"));
assertThat(encryptStrategyConfiguration.getType(), is("aes"));
assertThat(encryptStrategyConfiguration.getProperties().get("aes.key.value").toString(), is("123456"));
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.orchestration.core.configcenter.listener;
import lombok.SneakyThrows;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
......@@ -123,7 +123,7 @@ public final class SchemaChangedListenerTest {
assertThat(event.getRuleConfigurations().iterator().next(), instanceOf(EncryptRuleConfiguration.class));
EncryptRuleConfiguration encryptRuleConfiguration = (EncryptRuleConfiguration) event.getRuleConfigurations().iterator().next();
assertThat(encryptRuleConfiguration.getEncryptStrategies().size(), is(1));
EncryptStrategyConfiguration encryptStrategyConfiguration = encryptRuleConfiguration.getEncryptStrategies().iterator().next();
SPIEncryptStrategyConfiguration encryptStrategyConfiguration = (SPIEncryptStrategyConfiguration) encryptRuleConfiguration.getEncryptStrategies().iterator().next();
assertThat(encryptStrategyConfiguration.getName(), is("order_encrypt_strategy"));
assertThat(encryptStrategyConfiguration.getType(), is("aes"));
assertThat(encryptStrategyConfiguration.getProperties().get("aes.key.value").toString(), is("123456"));
......
......@@ -69,15 +69,15 @@ public final class ShardingOrchestrationFacadeTest {
@Before
public void setUp() {
Map<String, CenterConfiguration> instanceConfigurationMap = new HashMap<>();
CenterConfiguration configuration1 = new CenterConfiguration("SecondTestRegistryCenter");
CenterConfiguration configuration1 = new CenterConfiguration("SecondTestRegistryCenter", new Properties());
configuration1.setOrchestrationType("registry_center");
configuration1.setNamespace("namespace_1");
instanceConfigurationMap.put("test_name_1", configuration1);
CenterConfiguration configuration2 = new CenterConfiguration("FirstTestConfigCenter");
CenterConfiguration configuration2 = new CenterConfiguration("FirstTestConfigCenter", new Properties());
configuration2.setOrchestrationType("config_center");
configuration2.setNamespace("namespace_2");
instanceConfigurationMap.put("test_name_2", configuration2);
CenterConfiguration configuration3 = new CenterConfiguration("FirstTestConfigCenter");
CenterConfiguration configuration3 = new CenterConfiguration("FirstTestConfigCenter", new Properties());
configuration3.setOrchestrationType("metadata_center");
configuration3.setNamespace("namespace_3");
instanceConfigurationMap.put("test_name_3", configuration3);
......
......@@ -32,7 +32,7 @@ import java.util.Collection;
@Getter
public final class EncryptRuleConfiguration implements RuleConfiguration {
private final Collection<EncryptStrategyConfiguration> encryptStrategies;
private final Collection<? extends EncryptStrategyConfiguration> encryptStrategies;
private final Collection<EncryptTableRuleConfiguration> tables;
}
......@@ -15,19 +15,15 @@
* limitations under the License.
*/
package org.apache.shardingsphere.encrypt.strategy.spi;
package org.apache.shardingsphere.encrypt.api.config.algorithm;
import org.apache.shardingsphere.infra.spi.type.TypedSPI;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmPostProcessor;
/**
* Encrypt algorithm.
*/
public interface EncryptAlgorithm extends TypedSPI {
/**
* Initialize.
*/
void init();
public interface EncryptAlgorithm extends ShardingSphereAlgorithm, ShardingSphereAlgorithmPostProcessor {
/**
* Encode.
......
......@@ -17,21 +17,10 @@
package org.apache.shardingsphere.encrypt.api.config.strategy;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.TypedSPIConfiguration;
import java.util.Properties;
import org.apache.shardingsphere.infra.config.strategy.StrategyConfiguration;
/**
* Encrypt strategy configuration.
*/
@Getter
public final class EncryptStrategyConfiguration extends TypedSPIConfiguration {
private final String name;
public EncryptStrategyConfiguration(final String name, final String type, final Properties properties) {
super(type, properties);
this.name = name;
}
public interface EncryptStrategyConfiguration extends StrategyConfiguration {
}
/*
* 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.encrypt.api.config.strategy.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.config.strategy.RawStrategyConfiguration;
/**
* Encrypt strategy configuration for raw.
*/
@RequiredArgsConstructor
@Getter
public final class RawEncryptStrategyConfiguration implements EncryptStrategyConfiguration, RawStrategyConfiguration<EncryptAlgorithm> {
private final String name;
private final EncryptAlgorithm algorithm;
}
/*
* 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.encrypt.api.config.strategy.impl;
import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.config.TypedSPIConfiguration;
import org.apache.shardingsphere.infra.config.strategy.SPIStrategyConfiguration;
import java.util.Properties;
/**
* Encrypt strategy configuration for SPI.
*/
@Getter
public final class SPIEncryptStrategyConfiguration extends TypedSPIConfiguration implements EncryptStrategyConfiguration, SPIStrategyConfiguration {
private final String name;
public SPIEncryptStrategyConfiguration(final String name, final String type, final Properties properties) {
super(type, properties);
this.name = name;
}
}
/*
* 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.encrypt.spi;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.infra.spi.type.TypedSPI;
/**
* Encrypt algorithm for SPI.
*/
public interface SPIEncryptAlgorithm extends EncryptAlgorithm, TypedSPI {
}
/*
* 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.encrypt.spi;
import org.apache.shardingsphere.encrypt.api.config.algorithm.QueryAssistedEncryptAlgorithm;
/**
* Query assisted encrypt algorithm for SPI.
*/
public interface SPIQueryAssistedEncryptAlgorithm extends QueryAssistedEncryptAlgorithm, SPIEncryptAlgorithm {
}
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.encrypt.api.config;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.junit.Test;
import java.util.Properties;
......@@ -29,12 +29,12 @@ public final class EncryptStrategyConfigurationTest {
@Test(expected = IllegalArgumentException.class)
public void assertConstructorWithoutType() {
new EncryptStrategyConfiguration("test_encrypt_strategy", null, new Properties());
new SPIEncryptStrategyConfiguration("test_encrypt_strategy", null, new Properties());
}
@Test
public void assertConstructorWithoutAssistedQueryColumnsAndProperties() {
EncryptStrategyConfiguration actual = new EncryptStrategyConfiguration("test_encrypt_strategy", "TEST", new Properties());
SPIEncryptStrategyConfiguration actual = new SPIEncryptStrategyConfiguration("test_encrypt_strategy", "TEST", new Properties());
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getProperties(), is(new Properties()));
}
......@@ -43,7 +43,7 @@ public final class EncryptStrategyConfigurationTest {
public void assertConstructorWithMinArguments() {
Properties props = new Properties();
props.setProperty("key", "value");
EncryptStrategyConfiguration actual = new EncryptStrategyConfiguration("test_encrypt_strategy", "TEST", props);
SPIEncryptStrategyConfiguration actual = new SPIEncryptStrategyConfiguration("test_encrypt_strategy", "TEST", props);
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getProperties(), is(props));
}
......@@ -52,7 +52,7 @@ public final class EncryptStrategyConfigurationTest {
public void assertConstructorWithMaxArguments() {
Properties props = new Properties();
props.setProperty("key", "value");
EncryptStrategyConfiguration actual = new EncryptStrategyConfiguration("test_encrypt_strategy", "TEST", props);
SPIEncryptStrategyConfiguration actual = new SPIEncryptStrategyConfiguration("test_encrypt_strategy", "TEST", props);
assertThat(actual.getType(), is("TEST"));
assertThat(actual.getProperties(), is(props));
}
......
......@@ -19,15 +19,16 @@ package org.apache.shardingsphere.encrypt.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
import java.util.Collection;
import java.util.Collections;
......@@ -44,7 +45,7 @@ import java.util.stream.Collectors;
public final class EncryptRule implements ShardingSphereRule {
static {
ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
ShardingSphereServiceLoader.register(SPIEncryptAlgorithm.class);
}
private final Map<String, EncryptAlgorithm> encryptAlgorithms = new LinkedHashMap<>();
......@@ -53,7 +54,7 @@ public final class EncryptRule implements ShardingSphereRule {
public EncryptRule(final EncryptRuleConfiguration configuration) {
Preconditions.checkArgument(isValidRuleConfiguration(configuration), "Invalid encrypt column configurations in EncryptTableRuleConfigurations.");
configuration.getEncryptStrategies().forEach(each -> encryptAlgorithms.put(each.getName(), createEncryptAlgorithm(each)));
configuration.getEncryptStrategies().forEach(each -> encryptAlgorithms.put(each.getName(), ShardingSphereAlgorithmFactory.createAlgorithm(each, SPIEncryptAlgorithm.class)));
configuration.getTables().forEach(each -> tables.put(each.getName(), new EncryptTable(each)));
}
......@@ -85,12 +86,6 @@ public final class EncryptRule implements ShardingSphereRule {
return false;
}
private EncryptAlgorithm createEncryptAlgorithm(final EncryptStrategyConfiguration encryptStrategyConfiguration) {
EncryptAlgorithm result = TypedSPIRegistry.getRegisteredService(EncryptAlgorithm.class, encryptStrategyConfiguration.getType(), encryptStrategyConfiguration.getProperties());
result.init();
return result;
}
/**
* Find encrypt table.
*
......
......@@ -24,7 +24,7 @@ import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
......@@ -40,7 +40,7 @@ import java.util.Properties;
*/
@Getter
@Setter
public final class AESEncryptAlgorithm implements EncryptAlgorithm {
public final class AESEncryptAlgorithm implements SPIEncryptAlgorithm {
private static final String AES_KEY = "aes.key.value";
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.encrypt.strategy.impl;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
......@@ -29,7 +29,7 @@ import java.util.Properties;
*/
@Getter
@Setter
public final class MD5EncryptAlgorithm implements EncryptAlgorithm {
public final class MD5EncryptAlgorithm implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -22,7 +22,7 @@ import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import java.nio.charset.StandardCharsets;
......@@ -34,7 +34,7 @@ import java.util.Properties;
*/
@Getter
@Setter
public final class RC4EncryptAlgorithm implements EncryptAlgorithm {
public final class RC4EncryptAlgorithm implements SPIEncryptAlgorithm {
private static final String RC4_KEY = "rc4.key.value";
......
......@@ -19,7 +19,7 @@ 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.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptTableRuleConfiguration;
......@@ -42,7 +42,7 @@ public final class EncryptRuleConfigurationYamlSwapper implements YamlRuleConfig
@Override
public YamlEncryptRuleConfiguration swap(final EncryptRuleConfiguration data) {
YamlEncryptRuleConfiguration result = new YamlEncryptRuleConfiguration();
data.getEncryptStrategies().forEach(each -> result.getEncryptStrategies().put(each.getName(), encryptStrategyConfigurationYamlSwapper.swap(each)));
data.getEncryptStrategies().forEach(each -> result.getEncryptStrategies().put(each.getName(), encryptStrategyConfigurationYamlSwapper.swap((SPIEncryptStrategyConfiguration) each)));
data.getTables().forEach(each -> result.getTables().put(each.getName(), encryptTableRuleConfigurationYamlSwapper.swap(each)));
return result;
}
......@@ -52,8 +52,8 @@ public final class EncryptRuleConfigurationYamlSwapper implements YamlRuleConfig
return new EncryptRuleConfiguration(swapEncryptStrategy(yamlConfiguration), swapTables(yamlConfiguration));
}
private Collection<EncryptStrategyConfiguration> swapEncryptStrategy(final YamlEncryptRuleConfiguration yamlConfiguration) {
Collection<EncryptStrategyConfiguration> result = new LinkedList<>();
private Collection<SPIEncryptStrategyConfiguration> swapEncryptStrategy(final YamlEncryptRuleConfiguration yamlConfiguration) {
Collection<SPIEncryptStrategyConfiguration> result = new LinkedList<>();
for (Entry<String, YamlEncryptStrategyConfiguration> entry : yamlConfiguration.getEncryptStrategies().entrySet()) {
YamlEncryptStrategyConfiguration yamlEncryptStrategyConfiguration = entry.getValue();
yamlEncryptStrategyConfiguration.setName(entry.getKey());
......
......@@ -17,17 +17,17 @@
package org.apache.shardingsphere.encrypt.yaml.swapper;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
/**
* Encrypt strategy configuration YAML swapper.
*/
public final class EncryptStrategyConfigurationYamlSwapper implements YamlSwapper<YamlEncryptStrategyConfiguration, EncryptStrategyConfiguration> {
public final class EncryptStrategyConfigurationYamlSwapper implements YamlSwapper<YamlEncryptStrategyConfiguration, SPIEncryptStrategyConfiguration> {
@Override
public YamlEncryptStrategyConfiguration swap(final EncryptStrategyConfiguration data) {
public YamlEncryptStrategyConfiguration swap(final SPIEncryptStrategyConfiguration data) {
YamlEncryptStrategyConfiguration result = new YamlEncryptStrategyConfiguration();
result.setType(data.getType());
result.setProps(data.getProperties());
......@@ -35,7 +35,7 @@ public final class EncryptStrategyConfigurationYamlSwapper implements YamlSwappe
}
@Override
public EncryptStrategyConfiguration swap(final YamlEncryptStrategyConfiguration yamlConfiguration) {
return new EncryptStrategyConfiguration(yamlConfiguration.getName(), yamlConfiguration.getType(), yamlConfiguration.getProps());
public SPIEncryptStrategyConfiguration swap(final YamlEncryptStrategyConfiguration yamlConfiguration) {
return new SPIEncryptStrategyConfiguration(yamlConfiguration.getName(), yamlConfiguration.getType(), yamlConfiguration.getProps());
}
}
......@@ -21,7 +21,7 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.log.ConfigurationLogger;
import org.junit.Before;
import org.junit.Test;
......@@ -85,7 +85,7 @@ public final class EncryptConfigurationLoggerTest {
private EncryptRuleConfiguration getEncryptConfiguration() {
Properties properties = new Properties();
properties.put("aes.key.value", "123456abc");
EncryptStrategyConfiguration encryptStrategyConfiguration = new EncryptStrategyConfiguration("aes_encrypt_strategy", "aes", properties);
SPIEncryptStrategyConfiguration encryptStrategyConfiguration = new SPIEncryptStrategyConfiguration("aes_encrypt_strategy", "aes", properties);
EncryptTableRuleConfiguration encryptTableRuleConfiguration = new EncryptTableRuleConfiguration(
"t_encrypt", Collections.singleton(new EncryptColumnRuleConfiguration("user_id", "user_encrypt", "user_assisted", "user_decrypt", "aes_encrypt_strategy")));
return new EncryptRuleConfiguration(Collections.singleton(encryptStrategyConfiguration), Collections.singleton(encryptTableRuleConfiguration));
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.encrypt.rule;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.junit.Before;
import org.junit.Test;
......@@ -50,7 +50,7 @@ public final class EncryptRuleTest {
Properties props = new Properties();
EncryptColumnRuleConfiguration columnConfig = new EncryptColumnRuleConfiguration(column, "cipher_pwd", "", "plain_pwd", "aes");
EncryptColumnRuleConfiguration idNumberConfig = new EncryptColumnRuleConfiguration(idNumber, "cipher_id_number", "", "plain_id_number", "aes");
EncryptStrategyConfiguration encryptStrategyConfiguration = new EncryptStrategyConfiguration("aes", "assistedTest", props);
SPIEncryptStrategyConfiguration encryptStrategyConfiguration = new SPIEncryptStrategyConfiguration("aes", "assistedTest", props);
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(table, Arrays.asList(columnConfig, idNumberConfig));
encryptRuleConfig = new EncryptRuleConfiguration(Collections.singleton(encryptStrategyConfiguration), Collections.singleton(tableConfig));
}
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.encrypt.strategy.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class TestEncryptAlgorithm implements EncryptAlgorithm {
public final class TestEncryptAlgorithm implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.encrypt.strategy.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class TestQueryAssistedEncryptAlgorithm implements QueryAssistedEncryptAlgorithm {
public final class TestQueryAssistedEncryptAlgorithm implements SPIQueryAssistedEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.encrypt.merge.dql;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.Projection;
import org.apache.shardingsphere.sql.parser.binder.segment.select.projection.impl.ColumnProjection;
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.encrypt.merge.dql;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import java.io.InputStream;
......
......@@ -19,14 +19,14 @@ package org.apache.shardingsphere.encrypt.rewrite.parameter.impl;
import com.google.common.base.Preconditions;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rewrite.parameter.EncryptParameterRewriter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
import org.apache.shardingsphere.sql.parser.binder.segment.insert.values.OnDuplicateUpdateContext;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
import java.util.Collection;
import java.util.LinkedList;
......
......@@ -18,14 +18,14 @@
package org.apache.shardingsphere.encrypt.rewrite.parameter.impl;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rewrite.parameter.EncryptParameterRewriter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.StandardParameterBuilder;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.statement.dml.InsertStatementContext;
import java.util.ArrayList;
import java.util.Collection;
......
......@@ -18,10 +18,16 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator.impl;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.api.config.algorithm.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rewrite.token.generator.BaseEncryptSQLTokenGenerator;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptInsertValuesToken;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.PreviousSQLTokensAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.UseDefaultInsertColumnsToken;
import org.apache.shardingsphere.sql.parser.binder.segment.insert.values.InsertValueContext;
import org.apache.shardingsphere.sql.parser.binder.segment.insert.values.expression.DerivedLiteralExpressionSegment;
import org.apache.shardingsphere.sql.parser.binder.segment.insert.values.expression.DerivedParameterMarkerExpressionSegment;
......@@ -32,12 +38,6 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.assignment.InsertVal
import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.PreviousSQLTokensAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.UseDefaultInsertColumnsToken;
import java.util.Collection;
import java.util.Iterator;
......@@ -159,7 +159,7 @@ public final class EncryptInsertValuesTokenGenerator extends BaseEncryptSQLToken
return result;
}
private void setCipherColumn(final InsertValue insertValueToken,
private void setCipherColumn(final InsertValue insertValueToken,
final EncryptAlgorithm encryptAlgorithm, final int columnIndex, final ExpressionSegment valueExpression, final Object originalValue) {
if (valueExpression instanceof LiteralExpressionSegment) {
insertValueToken.getValues().set(columnIndex, new LiteralExpressionSegment(valueExpression.getStartIndex(), valueExpression.getStopIndex(), encryptAlgorithm.encrypt(originalValue)));
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.encrypt.rewrite.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class NormalEncryptAlgorithmFixture implements EncryptAlgorithm {
public final class NormalEncryptAlgorithmFixture implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.encrypt.rewrite.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class QueryAssistedEncryptAlgorithmFixture implements QueryAssistedEncryptAlgorithm {
public final class QueryAssistedEncryptAlgorithmFixture implements SPIQueryAssistedEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.encrypt.spring.namespace.parser;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptStrategyBeanDefinitionTag;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
......@@ -35,7 +35,7 @@ public final class EncryptStrategyBeanDefinitionParser extends AbstractBeanDefin
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(EncryptStrategyConfiguration.class);
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SPIEncryptStrategyConfiguration.class);
factory.addConstructorArgValue(element.getAttribute(EncryptStrategyBeanDefinitionTag.NAME_ATTRIBUTE));
factory.addConstructorArgValue(element.getAttribute(EncryptStrategyBeanDefinitionTag.TYPE_ATTRIBUTE));
factory.addConstructorArgValue(parseProperties(element, parserContext));
......
......@@ -15,16 +15,16 @@
* limitations under the License.
*/
package org.apache.shardingsphere.masterslave.spi;
package org.apache.shardingsphere.masterslave.api.config.algorithm;
import org.apache.shardingsphere.infra.spi.type.TypedSPI;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
import java.util.List;
/**
* Master-slave database load-balance algorithm.
*/
public interface MasterSlaveLoadBalanceAlgorithm extends TypedSPI {
public interface MasterSlaveLoadBalanceAlgorithm extends ShardingSphereAlgorithm {
/**
* Get data source.
......
......@@ -17,21 +17,10 @@
package org.apache.shardingsphere.masterslave.api.config.strategy;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.TypedSPIConfiguration;
import java.util.Properties;
import org.apache.shardingsphere.infra.config.strategy.StrategyConfiguration;
/**
* Master-slave load balance strategy configuration.
*/
@Getter
public final class LoadBalanceStrategyConfiguration extends TypedSPIConfiguration {
private final String name;
public LoadBalanceStrategyConfiguration(final String name, final String type, final Properties properties) {
super(type, properties);
this.name = name;
}
public interface LoadBalanceStrategyConfiguration extends StrategyConfiguration {
}
/*
* 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.api.config.strategy.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.strategy.RawStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.algorithm.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
/**
* Master-slave load balance strategy configuration for raw.
*/
@RequiredArgsConstructor
@Getter
public final class RawLoadBalanceStrategyConfiguration implements LoadBalanceStrategyConfiguration, RawStrategyConfiguration<MasterSlaveLoadBalanceAlgorithm> {
private final String name;
private final MasterSlaveLoadBalanceAlgorithm algorithm;
}
/*
* 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.api.config.strategy.impl;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.TypedSPIConfiguration;
import org.apache.shardingsphere.infra.config.strategy.SPIStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import java.util.Properties;
/**
* Master-slave load balance strategy configuration for SPI.
*/
@Getter
public final class SPILoadBalanceStrategyConfiguration extends TypedSPIConfiguration implements LoadBalanceStrategyConfiguration, SPIStrategyConfiguration {
private final String name;
public SPILoadBalanceStrategyConfiguration(final String name, final String type, final Properties properties) {
super(type, properties);
this.name = name;
}
}
/*
* 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.spi;
import org.apache.shardingsphere.infra.spi.type.TypedSPI;
import org.apache.shardingsphere.masterslave.api.config.algorithm.MasterSlaveLoadBalanceAlgorithm;
/**
* Master-slave database load-balance algorithm for SPI.
*/
public interface SPIMasterSlaveLoadBalanceAlgorithm extends MasterSlaveLoadBalanceAlgorithm, TypedSPI {
}
......@@ -21,8 +21,8 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.shardingsphere.masterslave.api.config.algorithm.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import java.util.Collection;
import java.util.HashMap;
......
......@@ -19,6 +19,7 @@ package org.apache.shardingsphere.masterslave.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.rule.DataSourceRoutedRule;
import org.apache.shardingsphere.infra.rule.StatusContainedRule;
import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
......@@ -26,9 +27,9 @@ import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEve
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.algorithm.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import java.util.Collection;
import java.util.HashMap;
......@@ -43,7 +44,7 @@ import java.util.Optional;
public final class MasterSlaveRule implements DataSourceRoutedRule, StatusContainedRule {
static {
ShardingSphereServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
ShardingSphereServiceLoader.register(SPIMasterSlaveLoadBalanceAlgorithm.class);
}
private final Map<String, MasterSlaveLoadBalanceAlgorithm> loadBalanceAlgorithms = new LinkedHashMap<>();
......@@ -52,20 +53,17 @@ public final class MasterSlaveRule implements DataSourceRoutedRule, StatusContai
public MasterSlaveRule(final MasterSlaveRuleConfiguration configuration) {
Preconditions.checkArgument(!configuration.getDataSources().isEmpty(), "Master-slave data source rules can not be empty.");
configuration.getLoadBalanceStrategies().forEach(each -> loadBalanceAlgorithms.put(each.getName(), createEncryptAlgorithm(each)));
configuration.getLoadBalanceStrategies().forEach(
each -> loadBalanceAlgorithms.put(each.getName(), ShardingSphereAlgorithmFactory.createAlgorithm(each, SPIMasterSlaveLoadBalanceAlgorithm.class)));
dataSourceRules = new HashMap<>(configuration.getDataSources().size(), 1);
for (MasterSlaveDataSourceRuleConfiguration each : configuration.getDataSources()) {
// TODO check if can not find load balance strategy should throw exception.
MasterSlaveLoadBalanceAlgorithm loadBalanceAlgorithm = Strings.isNullOrEmpty(each.getLoadBalanceStrategyName()) || !loadBalanceAlgorithms.containsKey(each.getLoadBalanceStrategyName())
? TypedSPIRegistry.getRegisteredService(MasterSlaveLoadBalanceAlgorithm.class) : loadBalanceAlgorithms.get(each.getLoadBalanceStrategyName());
? TypedSPIRegistry.getRegisteredService(SPIMasterSlaveLoadBalanceAlgorithm.class) : loadBalanceAlgorithms.get(each.getLoadBalanceStrategyName());
dataSourceRules.put(each.getName(), new MasterSlaveDataSourceRule(each, loadBalanceAlgorithm));
}
}
private MasterSlaveLoadBalanceAlgorithm createEncryptAlgorithm(final LoadBalanceStrategyConfiguration loadBalanceStrategyConfiguration) {
return TypedSPIRegistry.getRegisteredService(MasterSlaveLoadBalanceAlgorithm.class, loadBalanceStrategyConfiguration.getType(), loadBalanceStrategyConfiguration.getProperties());
}
/**
* Get single data source rule.
*
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.masterslave.strategy;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import java.util.List;
import java.util.Properties;
......@@ -30,7 +30,7 @@ import java.util.concurrent.ThreadLocalRandom;
*/
@Getter
@Setter
public final class RandomMasterSlaveLoadBalanceAlgorithm implements MasterSlaveLoadBalanceAlgorithm {
public final class RandomMasterSlaveLoadBalanceAlgorithm implements SPIMasterSlaveLoadBalanceAlgorithm {
private Properties properties = new Properties();
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.masterslave.strategy;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import java.util.List;
import java.util.Properties;
......@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
@Getter
@Setter
public final class RoundRobinMasterSlaveLoadBalanceAlgorithm implements MasterSlaveLoadBalanceAlgorithm {
public final class RoundRobinMasterSlaveLoadBalanceAlgorithm implements SPIMasterSlaveLoadBalanceAlgorithm {
private static final ConcurrentHashMap<String, AtomicInteger> COUNTS = new ConcurrentHashMap<>();
......
......@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.impl.SPILoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.constant.MasterSlaveOrder;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveLoadBalanceStrategyConfiguration;
......@@ -67,7 +68,7 @@ public final class MasterSlaveRuleConfigurationYamlSwapper implements YamlRuleCo
}
private LoadBalanceStrategyConfiguration swap(final String name, final YamlMasterSlaveLoadBalanceStrategyConfiguration yamlLoadBalanceStrategyConfiguration) {
return new LoadBalanceStrategyConfiguration(name, yamlLoadBalanceStrategyConfiguration.getType(), yamlLoadBalanceStrategyConfiguration.getProps());
return new SPILoadBalanceStrategyConfiguration(name, yamlLoadBalanceStrategyConfiguration.getType(), yamlLoadBalanceStrategyConfiguration.getProps());
}
private MasterSlaveDataSourceRuleConfiguration swap(final String name, final YamlMasterSlaveDataSourceRuleConfiguration yamlDataSourceRuleConfiguration) {
......
......@@ -17,9 +17,10 @@
package org.apache.shardingsphere.masterslave.rule;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.impl.SPILoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import org.junit.Test;
import java.util.Arrays;
......@@ -53,13 +54,13 @@ public final class MasterSlaveRuleTest {
private MasterSlaveRule createMasterSlaveRule() {
MasterSlaveDataSourceRuleConfiguration configuration = new MasterSlaveDataSourceRuleConfiguration("test_ms", "master_db", Arrays.asList("slave_db_0", "slave_db_1"), "random");
return new MasterSlaveRule(
new MasterSlaveRuleConfiguration(Collections.singleton(new LoadBalanceStrategyConfiguration("random", "RANDOM", new Properties())), Collections.singleton(configuration)));
new MasterSlaveRuleConfiguration(Collections.singleton(new SPILoadBalanceStrategyConfiguration("random", "RANDOM", new Properties())), Collections.singleton(configuration)));
}
private void assertDataSourceRule(final MasterSlaveDataSourceRule actual) {
assertThat(actual.getName(), is("test_ms"));
assertThat(actual.getMasterDataSourceName(), is("master_db"));
assertThat(actual.getSlaveDataSourceNames(), is(Arrays.asList("slave_db_0", "slave_db_1")));
assertThat(actual.getLoadBalanceAlgorithm().getType(), is("RANDOM"));
assertThat(((SPIMasterSlaveLoadBalanceAlgorithm) actual.getLoadBalanceAlgorithm()).getType(), is("RANDOM"));
}
}
......@@ -17,9 +17,9 @@
package org.apache.shardingsphere.masterslave.yaml.swapper;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.impl.SPILoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveRuleConfiguration;
import org.junit.Test;
......@@ -38,7 +38,7 @@ public final class MasterSlaveRuleConfigurationYamlSwapperTest {
public void assertSwapToYamlWithLoadBalanceAlgorithm() {
MasterSlaveDataSourceRuleConfiguration dataSourceConfiguration = new MasterSlaveDataSourceRuleConfiguration("ds", "master", Collections.singletonList("slave"), "roundRobin");
YamlMasterSlaveRuleConfiguration actual = new MasterSlaveRuleConfigurationYamlSwapper().swap(new MasterSlaveRuleConfiguration(
Collections.singleton(new LoadBalanceStrategyConfiguration("roundRobin", "ROUND_ROBIN", new Properties())), Collections.singleton(dataSourceConfiguration)));
Collections.singleton(new SPILoadBalanceStrategyConfiguration("roundRobin", "ROUND_ROBIN", new Properties())), Collections.singleton(dataSourceConfiguration)));
assertThat(actual.getDataSources().get("ds").getName(), is("ds"));
assertThat(actual.getDataSources().get("ds").getMasterDataSourceName(), is("master"));
assertThat(actual.getDataSources().get("ds").getSlaveDataSourceNames(), is(Collections.singletonList("slave")));
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.masterslave.spring.namespace.parser;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.impl.SPILoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.spring.namespace.tag.LoadBalanceStrategyBeanDefinitionTag;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
......@@ -35,7 +35,7 @@ public final class MasterSlaveLoadBalanceStrategyBeanDefinitionParser extends Ab
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(LoadBalanceStrategyConfiguration.class);
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SPILoadBalanceStrategyConfiguration.class);
factory.addConstructorArgValue(element.getAttribute(LoadBalanceStrategyBeanDefinitionTag.NAME_ATTRIBUTE));
factory.addConstructorArgValue(element.getAttribute(LoadBalanceStrategyBeanDefinitionTag.TYPE_ATTRIBUTE));
factory.addConstructorArgValue(parseProperties(element, parserContext));
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.sharding.rewrite.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class NormalEncryptAlgorithmFixture implements EncryptAlgorithm {
public final class NormalEncryptAlgorithmFixture implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.sharding.rewrite.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class QueryAssistedEncryptAlgorithmFixture implements QueryAssistedEncryptAlgorithm {
public final class QueryAssistedEncryptAlgorithmFixture implements SPIQueryAssistedEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -33,10 +33,6 @@ public abstract class TypedSPIConfiguration {
private final Properties properties;
public TypedSPIConfiguration(final String type) {
this(type, null);
}
public TypedSPIConfiguration(final String type, final Properties properties) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "Type is required.");
this.type = type;
......
/*
* 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.infra.config.algorithm;
/**
* ShardingSphere algorithm.
*/
public interface ShardingSphereAlgorithm {
}
/*
* 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.infra.config.algorithm;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.strategy.RawStrategyConfiguration;
import org.apache.shardingsphere.infra.config.strategy.SPIStrategyConfiguration;
import org.apache.shardingsphere.infra.config.strategy.StrategyConfiguration;
import org.apache.shardingsphere.infra.spi.type.TypedSPI;
import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
/**
* ShardingSphere algorithm factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ShardingSphereAlgorithmFactory {
/**
* Create algorithm.
*
* @param strategyConfiguration strategy configuration
* @param spiAlgorithmClass SPI algorithm class
* @param <T> type of algorithm
* @return algorithm
*/
@SuppressWarnings("unchecked")
public static <T extends ShardingSphereAlgorithm> T createAlgorithm(final StrategyConfiguration strategyConfiguration, final Class<? extends TypedSPI> spiAlgorithmClass) {
return strategyConfiguration instanceof RawStrategyConfiguration
? (T) ((RawStrategyConfiguration) strategyConfiguration).getAlgorithm() : createSPIAlgorithm((SPIStrategyConfiguration) strategyConfiguration, spiAlgorithmClass);
}
@SuppressWarnings("unchecked")
private static <T extends ShardingSphereAlgorithm> T createSPIAlgorithm(final SPIStrategyConfiguration spiStrategyConfiguration, final Class<? extends TypedSPI> spiAlgorithmClass) {
T result = (T) TypedSPIRegistry.getRegisteredService(spiAlgorithmClass, spiStrategyConfiguration.getType(), spiStrategyConfiguration.getProperties());
if (result instanceof ShardingSphereAlgorithmPostProcessor) {
((ShardingSphereAlgorithmPostProcessor) result).init();
}
return result;
}
}
/*
* 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.infra.config.algorithm;
/**
* ShardingSphere algorithm post processor.
*
* @author zhangliang
*/
public interface ShardingSphereAlgorithmPostProcessor {
/**
* Initialize algorithm.
*/
void init();
}
/*
* 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.infra.config.strategy;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
/**
* Raw strategy configuration.
*
* @param <T> type of algorithm
*/
public interface RawStrategyConfiguration<T extends ShardingSphereAlgorithm> extends StrategyConfiguration {
/**
* Get algorithm.
*
* @return algorithm
*/
T getAlgorithm();
}
/*
* 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.infra.config.strategy;
import java.util.Properties;
/**
* SPI strategy configuration.
*/
public interface SPIStrategyConfiguration extends StrategyConfiguration {
/**
* Get algorithm type.
*
* @return algorithm type
*/
String getType();
/**
* Get algorithm properties.
*
* @return algorithm properties
*/
Properties getProperties();
}
/*
* 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.infra.config.strategy;
/**
* Strategy configuration.
*/
public interface StrategyConfiguration {
/**
* Get strategy name.
*
* @return strategy name
*/
String getName();
}
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.driver.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class TestEncryptAlgorithm implements EncryptAlgorithm {
public final class TestEncryptAlgorithm implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.driver.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.QueryAssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class TestQueryAssistedEncryptAlgorithm implements QueryAssistedEncryptAlgorithm {
public final class TestQueryAssistedEncryptAlgorithm implements SPIQueryAssistedEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -15,5 +15,5 @@
# limitations under the License.
#
org.apache.shardingsphere.driver.fixture.TestQueryAssistedEncryptAlgorithm
org.apache.shardingsphere.driver.fixture.TestEncryptAlgorithm
org.apache.shardingsphere.driver.fixture.TestQueryAssistedEncryptAlgorithm
......@@ -18,12 +18,13 @@
package org.apache.shardingsphere.driver.orchestration.internal.datasource;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.strategy.impl.SPILoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
import org.apache.shardingsphere.orchestration.center.config.OrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.CenterType;
......@@ -32,10 +33,9 @@ import org.apache.shardingsphere.orchestration.core.common.event.PropertiesChang
import org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -78,7 +78,7 @@ public final class OrchestrationShardingSphereDataSourceTest {
}
private static CenterConfiguration getRegistryCenterConfiguration() {
CenterConfiguration result = new CenterConfiguration("FourthTestRegistryCenter");
CenterConfiguration result = new CenterConfiguration("FourthTestRegistryCenter", new Properties());
result.setOrchestrationType(CenterType.REGISTRY_CENTER.getValue());
result.setNamespace("test_sharding_registry");
result.setServerLists("localhost:3181");
......@@ -86,7 +86,7 @@ public final class OrchestrationShardingSphereDataSourceTest {
}
private static CenterConfiguration getConfigCenterConfiguration() {
CenterConfiguration result = new CenterConfiguration("FourthTestConfigCenter");
CenterConfiguration result = new CenterConfiguration("FourthTestConfigCenter", new Properties());
result.setOrchestrationType(CenterType.CONFIG_CENTER.getValue());
result.setNamespace("test_sharding_config");
result.setServerLists("localhost:3181");
......@@ -94,7 +94,7 @@ public final class OrchestrationShardingSphereDataSourceTest {
}
private static CenterConfiguration getMetaDataCenterConfiguration() {
CenterConfiguration result = new CenterConfiguration("FirstTestMetaDataCenter");
CenterConfiguration result = new CenterConfiguration("FirstTestMetaDataCenter", new Properties());
result.setOrchestrationType(CenterType.METADATA_CENTER.getValue());
result.setNamespace("test_encrypt_metadata");
result.setServerLists("localhost:3181");
......@@ -123,7 +123,7 @@ public final class OrchestrationShardingSphereDataSourceTest {
private MasterSlaveRuleConfiguration getMasterSlaveRuleConfiguration() {
MasterSlaveDataSourceRuleConfiguration dataSourceConfiguration = new MasterSlaveDataSourceRuleConfiguration("ds_ms", "ds_m", Collections.singletonList("ds_s"), "roundRobin");
return new MasterSlaveRuleConfiguration(
Collections.singleton(new LoadBalanceStrategyConfiguration("roundRobin", "ROUND_ROBIN", new Properties())), Collections.singleton(dataSourceConfiguration));
Collections.singleton(new SPILoadBalanceStrategyConfiguration("roundRobin", "ROUND_ROBIN", new Properties())), Collections.singleton(dataSourceConfiguration));
}
@Test
......
......@@ -19,13 +19,13 @@ package org.apache.shardingsphere.spring.boot.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
@Getter
@Setter
public final class TestEncryptAlgorithm implements EncryptAlgorithm {
public final class TestEncryptAlgorithm implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveDataSourceRule;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -64,6 +65,6 @@ public class SpringBootMasterSlaveTest {
assertThat(dataSourceRule.getSlaveDataSourceNames().size(), is(2));
assertThat(dataSourceRule.getSlaveDataSourceNames().get(0), is("ds_slave_0"));
assertThat(dataSourceRule.getSlaveDataSourceNames().get(1), is("ds_slave_1"));
assertThat(dataSourceRule.getLoadBalanceAlgorithm().getType(), is("RANDOM"));
assertThat(((SPIMasterSlaveLoadBalanceAlgorithm) dataSourceRule.getLoadBalanceAlgorithm()).getType(), is("RANDOM"));
}
}
......@@ -19,6 +19,7 @@ package org.apache.shardingsphere.spring;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.strategy.impl.AESEncryptAlgorithm;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
......@@ -41,7 +42,7 @@ public class EncryptNamespaceTest extends AbstractJUnit4SpringContextTests {
assertTrue(encryptRule.findEncryptAlgorithm("t_order", "user_id").isPresent());
assertThat(encryptRule.getCipherColumn("t_order", "user_id"), is("user_encrypt"));
assertTrue(encryptRule.findEncryptAlgorithm("t_order", "user_id").get() instanceof AESEncryptAlgorithm);
assertThat(encryptRule.findEncryptAlgorithm("t_order", "user_id").get().getProperties().getProperty("aes.key.value"), is("123456"));
assertThat(((SPIEncryptAlgorithm) encryptRule.findEncryptAlgorithm("t_order", "user_id").get()).getProperties().getProperty("aes.key.value"), is("123456"));
assertThat(encryptRule.findPlainColumn("t_order", "order_id"), is(Optional.of("order_decrypt")));
assertTrue(getProperties().<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW));
assertTrue(getProperties().<Boolean>getValue(ConfigurationPropertyKey.QUERY_WITH_CIPHER_COLUMN));
......
......@@ -21,7 +21,7 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.masterslave.api.config.strategy.LoadBalanceStrategyConfiguration;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveDataSourceRule;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.strategy.RandomMasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.strategy.RoundRobinMasterSlaveLoadBalanceAlgorithm;
import org.junit.Test;
......@@ -66,7 +66,7 @@ public class MasterSlaveNamespaceTest extends AbstractJUnit4SpringContextTests {
MasterSlaveRule masterSlaveRule = getMasterSlaveRule("refMasterSlaveDataSource");
Optional<MasterSlaveDataSourceRule> masterSlaveDataSourceRule = masterSlaveRule.findDataSourceRule("random_dbtbl_1");
assertTrue(masterSlaveDataSourceRule.isPresent());
assertThat(masterSlaveDataSourceRule.get().getLoadBalanceAlgorithm(), instanceOf(MasterSlaveLoadBalanceAlgorithm.class));
assertThat(masterSlaveDataSourceRule.get().getLoadBalanceAlgorithm(), instanceOf(SPIMasterSlaveLoadBalanceAlgorithm.class));
}
private MasterSlaveRule getMasterSlaveRule(final String masterSlaveDataSourceName) {
......
......@@ -17,11 +17,11 @@
package org.apache.shardingsphere.spring.fixture;
import org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm;
import java.util.Properties;
public final class TestEncryptAlgorithm implements EncryptAlgorithm {
public final class TestEncryptAlgorithm implements SPIEncryptAlgorithm {
private Properties properties = new Properties();
......
......@@ -52,7 +52,7 @@
<sharding:rule id="shardingRule">
<sharding:table-rules>
<sharding:table-rule logic-table="t_order" actual-data-nodes="dbtbl_0.t_order_${0..3}, dbtbl_1.t_order_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" />
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="dbtbl_0.t_order_item_${0..3}, dbtbl_1.t_order_item_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" />
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="dbtbl_0.t_order_item_${0..3}, dbtbl_1.t_order_item_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" />
</sharding:table-rules>
</sharding:rule>
......
......@@ -23,6 +23,7 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.spring.boot.orchestration.util.EmbedTestingServer;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -36,6 +37,7 @@ import javax.annotation.Resource;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
......@@ -68,8 +70,9 @@ public class OrchestrationSpringBootEncryptTest {
(EncryptRuleConfiguration) shardingSphereDataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getConfigurations().iterator().next();
assertThat(configuration.getEncryptStrategies().size(), is(1));
EncryptStrategyConfiguration encryptStrategyConfiguration = configuration.getEncryptStrategies().iterator().next();
assertThat(encryptStrategyConfiguration, instanceOf(SPIEncryptStrategyConfiguration.class));
assertThat(encryptStrategyConfiguration.getName(), is("order_encrypt"));
assertThat(encryptStrategyConfiguration.getType(), is("aes"));
assertThat(((SPIEncryptStrategyConfiguration) encryptStrategyConfiguration).getType(), is("aes"));
assertThat(configuration.getTables().size(), is(1));
assertThat(configuration.getTables().iterator().next().getColumns().iterator().next().getCipherColumn(), is("cipher_order_id"));
}
......
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.spring.boot.orchestration.registry.TestCenterRepository;
import org.apache.shardingsphere.spring.boot.orchestration.util.EmbedTestingServer;
import org.junit.BeforeClass;
......@@ -36,6 +37,7 @@ import javax.annotation.Resource;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
......@@ -91,7 +93,8 @@ public class OrchestrationSpringBootRegistryEncryptTest {
EncryptRuleConfiguration configuration = (EncryptRuleConfiguration) encryptDataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getConfigurations().iterator().next();
assertThat(configuration.getEncryptStrategies().size(), is(1));
EncryptStrategyConfiguration encryptStrategyConfiguration = configuration.getEncryptStrategies().iterator().next();
assertThat(encryptStrategyConfiguration, instanceOf(SPIEncryptStrategyConfiguration.class));
assertThat(encryptStrategyConfiguration.getName(), is("order_encrypt"));
assertThat(encryptStrategyConfiguration.getType(), is("aes"));
assertThat(((SPIEncryptStrategyConfiguration) encryptStrategyConfiguration).getType(), is("aes"));
}
}
......@@ -18,10 +18,11 @@
package org.apache.shardingsphere.spring.namespace.orchestration;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.EncryptStrategyConfiguration;
import org.apache.shardingsphere.encrypt.api.config.strategy.impl.SPIEncryptStrategyConfiguration;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.spring.namespace.orchestration.util.EmbedTestingServer;
......@@ -69,13 +70,13 @@ public class OrchestrationEncryptNamespaceTest extends AbstractJUnit4SpringConte
EncryptColumnRuleConfiguration orderIdColumnRuleConfiguration = encryptColumnRuleConfigurations.next();
assertThat(userIdColumnRuleConfiguration.getCipherColumn(), is("user_encrypt"));
assertThat(orderIdColumnRuleConfiguration.getPlainColumn(), is("order_decrypt"));
Iterator<EncryptStrategyConfiguration> encryptStrategyConfigurations = configuration.getEncryptStrategies().iterator();
assertEncryptStrategyConfiguration(encryptStrategyConfigurations.next());
assertEncryptStrategyConfiguration(encryptStrategyConfigurations.next());
Iterator<? extends EncryptStrategyConfiguration> encryptStrategyConfigurations = configuration.getEncryptStrategies().iterator();
assertEncryptStrategyConfiguration((SPIEncryptStrategyConfiguration) encryptStrategyConfigurations.next());
assertEncryptStrategyConfiguration((SPIEncryptStrategyConfiguration) encryptStrategyConfigurations.next());
assertFalse(encryptStrategyConfigurations.hasNext());
}
private void assertEncryptStrategyConfiguration(final EncryptStrategyConfiguration encryptStrategyConfiguration) {
private void assertEncryptStrategyConfiguration(final SPIEncryptStrategyConfiguration encryptStrategyConfiguration) {
if ("AES".equals(encryptStrategyConfiguration.getType())) {
assertThat(encryptStrategyConfiguration.getName(), is("aes_encrypt_strategy"));
assertThat(encryptStrategyConfiguration.getProperties().getProperty("aes.key.value"), is("123456"));
......
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveDataSourceRule;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.strategy.RandomMasterSlaveLoadBalanceAlgorithm;
import org.apache.shardingsphere.masterslave.strategy.RoundRobinMasterSlaveLoadBalanceAlgorithm;
import org.junit.BeforeClass;
......@@ -79,7 +79,7 @@ public class OrchestrationMasterSlaveNamespaceTest extends AbstractJUnit4SpringC
@Ignore
// TODO load balance algorithm have been construct twice for SpringMasterDatasource extends MasterSlaveDatasource.
public void assertRefMasterSlaveDataSource() {
MasterSlaveLoadBalanceAlgorithm randomLoadBalanceAlgorithm = applicationContext.getBean("randomLoadBalanceAlgorithm", MasterSlaveLoadBalanceAlgorithm.class);
SPIMasterSlaveLoadBalanceAlgorithm randomLoadBalanceAlgorithm = applicationContext.getBean("randomLoadBalanceAlgorithm", SPIMasterSlaveLoadBalanceAlgorithm.class);
MasterSlaveRule masterSlaveRule = getMasterSlaveRule("refMasterSlaveDataSourceOrchestration");
Optional<MasterSlaveDataSourceRule> masterSlaveDataSourceRule = masterSlaveRule.findDataSourceRule("randomLoadBalanceAlgorithm");
assertTrue(masterSlaveDataSourceRule.isPresent());
......
......@@ -26,6 +26,7 @@ import org.apache.shardingsphere.orchestration.center.instance.CuratorZookeeperC
import org.apache.shardingsphere.ui.common.constant.InstanceType;
import org.apache.shardingsphere.ui.common.domain.CenterConfig;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -63,7 +64,8 @@ public final class CenterRepositoryFactory {
}
/**
* Create config center instance
* Create config center instance.
*
* @param config config center config
* @return config center
*/
......@@ -85,9 +87,8 @@ public final class CenterRepositoryFactory {
return result;
}
private static CenterConfiguration convert(final CenterConfig config) {
CenterConfiguration result = new CenterConfiguration(config.getInstanceType());
CenterConfiguration result = new CenterConfiguration(config.getInstanceType(), new Properties());
result.setServerLists(config.getServerLists());
result.setNamespace(config.getNamespace());
result.getProperties().put("digest", config.getDigest());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册