From e40adbdbf39c4ce1daf87c7a90b8758bcc4d9b33 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 8 Jun 2020 19:08:57 +0800 Subject: [PATCH] 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 --- ...QueryAssistedShardingEncryptAlgorithm.java | 4 +- ...rypt.spi.SPIQueryAssistedEncryptAlgorithm} | 0 .../local/LocalEncryptConfiguration.java | 5 +- .../config/EncryptDatabasesConfiguration.java | 7 ++- .../EncryptShadowDatabasesConfiguration.java | 11 ++-- .../center/config/CenterConfiguration.java | 4 -- .../config/CenterConfigurationTest.java | 8 +-- .../instance/ApolloCenterRepositoryTest.java | 2 +- .../wrapper/ApolloConfigWrapperTest.java | 2 +- .../wrapper/ApolloOpenApiWrapperTest.java | 2 +- .../instance/EtcdCenterRepositoryTest.java | 22 ++++---- .../core/configcenter/ConfigCenterTest.java | 6 +- .../listener/SchemaChangedListenerTest.java | 4 +- .../ShardingOrchestrationFacadeTest.java | 6 +- .../api/config/EncryptRuleConfiguration.java | 2 +- .../config/algorithm}/EncryptAlgorithm.java | 12 ++-- .../QueryAssistedEncryptAlgorithm.java | 2 +- .../EncryptStrategyConfiguration.java | 15 +---- .../impl/RawEncryptStrategyConfiguration.java | 36 ++++++++++++ .../impl/SPIEncryptStrategyConfiguration.java | 39 +++++++++++++ .../encrypt/spi/SPIEncryptAlgorithm.java | 27 +++++++++ .../spi/SPIQueryAssistedEncryptAlgorithm.java | 26 +++++++++ .../EncryptStrategyConfigurationTest.java | 10 ++-- .../encrypt/rule/EncryptRule.java | 19 +++---- .../strategy/impl/AESEncryptAlgorithm.java | 4 +- .../strategy/impl/MD5EncryptAlgorithm.java | 4 +- .../strategy/impl/RC4EncryptAlgorithm.java | 4 +- .../EncryptRuleConfigurationYamlSwapper.java | 8 +-- ...cryptStrategyConfigurationYamlSwapper.java | 10 ++-- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../log/EncryptConfigurationLoggerTest.java | 4 +- .../encrypt/rule/EncryptRuleTest.java | 4 +- .../fixture/TestEncryptAlgorithm.java | 4 +- .../TestQueryAssistedEncryptAlgorithm.java | 4 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../merge/dql/EncryptAlgorithmMetaData.java | 2 +- .../merge/dql/EncryptMergedResult.java | 2 +- ...licateKeyUpdateValueParameterRewriter.java | 8 +-- .../EncryptInsertValueParameterRewriter.java | 8 +-- .../EncryptInsertValuesTokenGenerator.java | 18 +++--- .../NormalEncryptAlgorithmFixture.java | 4 +- .../QueryAssistedEncryptAlgorithmFixture.java | 4 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../EncryptStrategyBeanDefinitionParser.java | 4 +- .../MasterSlaveLoadBalanceAlgorithm.java | 6 +- .../LoadBalanceStrategyConfiguration.java | 15 +---- .../RawLoadBalanceStrategyConfiguration.java | 36 ++++++++++++ .../SPILoadBalanceStrategyConfiguration.java | 39 +++++++++++++ .../SPIMasterSlaveLoadBalanceAlgorithm.java | 27 +++++++++ .../rule/MasterSlaveDataSourceRule.java | 2 +- .../masterslave/rule/MasterSlaveRule.java | 16 +++--- ...RandomMasterSlaveLoadBalanceAlgorithm.java | 4 +- ...dRobinMasterSlaveLoadBalanceAlgorithm.java | 4 +- ...sterSlaveRuleConfigurationYamlSwapper.java | 3 +- ...ve.spi.SPIMasterSlaveLoadBalanceAlgorithm} | 0 .../masterslave/rule/MasterSlaveRuleTest.java | 9 +-- ...SlaveRuleConfigurationYamlSwapperTest.java | 6 +- ...adBalanceStrategyBeanDefinitionParser.java | 4 +- .../NormalEncryptAlgorithmFixture.java | 4 +- .../QueryAssistedEncryptAlgorithmFixture.java | 4 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../infra/config/TypedSPIConfiguration.java | 4 -- .../algorithm/ShardingSphereAlgorithm.java | 24 ++++++++ .../ShardingSphereAlgorithmFactory.java | 56 +++++++++++++++++++ .../ShardingSphereAlgorithmPostProcessor.java | 31 ++++++++++ .../strategy/RawStrategyConfiguration.java | 35 ++++++++++++ .../strategy/SPIStrategyConfiguration.java | 40 +++++++++++++ .../strategy/StrategyConfiguration.java | 31 ++++++++++ .../driver/fixture/TestEncryptAlgorithm.java | 4 +- .../TestQueryAssistedEncryptAlgorithm.java | 4 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 2 +- ...estrationShardingSphereDataSourceTest.java | 26 ++++----- .../boot/fixture/TestEncryptAlgorithm.java | 4 +- .../boot/type/SpringBootMasterSlaveTest.java | 3 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../spring/EncryptNamespaceTest.java | 3 +- .../spring/MasterSlaveNamespaceTest.java | 4 +- .../spring/fixture/TestEncryptAlgorithm.java | 4 +- .../rdb/withNamespaceDifferentTables.xml | 2 +- ...ingsphere.encrypt.spi.SPIEncryptAlgorithm} | 0 .../OrchestrationSpringBootEncryptTest.java | 5 +- ...strationSpringBootRegistryEncryptTest.java | 5 +- .../OrchestrationEncryptNamespaceTest.java | 11 ++-- ...OrchestrationMasterSlaveNamespaceTest.java | 4 +- .../ui/util/CenterRepositoryFactory.java | 7 ++- 85 files changed, 638 insertions(+), 217 deletions(-) rename examples/example-core/config-utility/src/main/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm} (100%) rename shardingsphere-features/shardingsphere-encrypt/{shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi => shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm}/EncryptAlgorithm.java (76%) rename shardingsphere-features/shardingsphere-encrypt/{shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi => shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm}/QueryAssistedEncryptAlgorithm.java (94%) create mode 100644 shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/RawEncryptStrategyConfiguration.java create mode 100644 shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/SPIEncryptStrategyConfiguration.java create mode 100644 shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIEncryptAlgorithm.java create mode 100644 shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIQueryAssistedEncryptAlgorithm.java rename shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) rename shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) rename shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) rename shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/{spi => api/config/algorithm}/MasterSlaveLoadBalanceAlgorithm.java (84%) create mode 100644 shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/RawLoadBalanceStrategyConfiguration.java create mode 100644 shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/SPILoadBalanceStrategyConfiguration.java create mode 100644 shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/SPIMasterSlaveLoadBalanceAlgorithm.java rename shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/{org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm => org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm} (100%) rename shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmFactory.java create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/RawStrategyConfiguration.java create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/SPIStrategyConfiguration.java create mode 100644 shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/StrategyConfiguration.java rename shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) rename shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) rename shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/services/{org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm => org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm} (100%) diff --git a/examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/fixture/TestQueryAssistedShardingEncryptAlgorithm.java b/examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/fixture/TestQueryAssistedShardingEncryptAlgorithm.java index f6da39c45f..7d5030c343 100644 --- a/examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/fixture/TestQueryAssistedShardingEncryptAlgorithm.java +++ b/examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/fixture/TestQueryAssistedShardingEncryptAlgorithm.java @@ -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(); diff --git a/examples/example-core/config-utility/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/examples/example-core/config-utility/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm similarity index 100% rename from examples/example-core/config-utility/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to examples/example-core/config-utility/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIQueryAssistedEncryptAlgorithm diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java index 6676155e0f..32d0bc3831 100644 --- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java +++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java @@ -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)); diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java index 6350a0680e..d7d79721ca 100644 --- a/examples/shardingsphere-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java +++ b/examples/shardingsphere-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java @@ -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 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); diff --git a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java index f333ea5582..8e556b5fd8 100644 --- a/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java +++ b/examples/shardingsphere-jdbc-example/other-feature-example/shadow-example/shadow-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/shadow/table/raw/jdbc/config/EncryptShadowDatabasesConfiguration.java @@ -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 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 getEncryptStrategyConfiguration() { + private Collection getEncryptStrategyConfigurations() { Collection 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; diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/config/CenterConfiguration.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/config/CenterConfiguration.java index 56f04ae75f..095d513b9f 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/config/CenterConfiguration.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/main/java/org/apache/shardingsphere/orchestration/center/config/CenterConfiguration.java @@ -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); } diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/test/java/org/apache/shardingsphere/orchestration/center/config/CenterConfigurationTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/test/java/org/apache/shardingsphere/orchestration/center/config/CenterConfigurationTest.java index 7d2c0f3429..dd116010ff 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/test/java/org/apache/shardingsphere/orchestration/center/config/CenterConfigurationTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-api/src/test/java/org/apache/shardingsphere/orchestration/center/config/CenterConfigurationTest.java @@ -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)); } diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloCenterRepositoryTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloCenterRepositoryTest.java index a50134da42..93259c412f 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloCenterRepositoryTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloCenterRepositoryTest.java @@ -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(); diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloConfigWrapperTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloConfigWrapperTest.java index 7c87a1722e..ccb797a2e5 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloConfigWrapperTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloConfigWrapperTest.java @@ -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(); diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloOpenApiWrapperTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloOpenApiWrapperTest.java index 1491f178d2..9ebaa3c1ba 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloOpenApiWrapperTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/wrapper/ApolloOpenApiWrapperTest.java @@ -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()); diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-etcd/src/test/java/org/apache/shardingsphere/orchestration/center/instance/EtcdCenterRepositoryTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-etcd/src/test/java/org/apache/shardingsphere/orchestration/center/instance/EtcdCenterRepositoryTest.java index f346afe27c..0f842a5c6a 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-etcd/src/test/java/org/apache/shardingsphere/orchestration/center/instance/EtcdCenterRepositoryTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-center/shardingsphere-orchestration-center-etcd/src/test/java/org/apache/shardingsphere/orchestration/center/instance/EtcdCenterRepositoryTest.java @@ -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)); } } diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java index 292ec8f0b2..122555a9ff 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java @@ -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")); diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/SchemaChangedListenerTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/SchemaChangedListenerTest.java index 589f7121c8..c4172937bd 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/SchemaChangedListenerTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/SchemaChangedListenerTest.java @@ -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")); diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java index c08b62b2ed..5c3f07a58d 100644 --- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java +++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java @@ -69,15 +69,15 @@ public final class ShardingOrchestrationFacadeTest { @Before public void setUp() { Map 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); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/EncryptRuleConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/EncryptRuleConfiguration.java index a265b51555..4381042930 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/EncryptRuleConfiguration.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/EncryptRuleConfiguration.java @@ -32,7 +32,7 @@ import java.util.Collection; @Getter public final class EncryptRuleConfiguration implements RuleConfiguration { - private final Collection encryptStrategies; + private final Collection encryptStrategies; private final Collection tables; } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/EncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/EncryptAlgorithm.java similarity index 76% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/EncryptAlgorithm.java rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/EncryptAlgorithm.java index cd56729f05..77be82c913 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/EncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/EncryptAlgorithm.java @@ -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. diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/QueryAssistedEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/QueryAssistedEncryptAlgorithm.java similarity index 94% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/QueryAssistedEncryptAlgorithm.java rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/QueryAssistedEncryptAlgorithm.java index 07fcf0318b..f722fb7e68 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/spi/QueryAssistedEncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/algorithm/QueryAssistedEncryptAlgorithm.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.encrypt.strategy.spi; +package org.apache.shardingsphere.encrypt.api.config.algorithm; /** * Query assisted encrypt algorithm. diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/EncryptStrategyConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/EncryptStrategyConfiguration.java index 2e2e48a29f..e57561973f 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/EncryptStrategyConfiguration.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/EncryptStrategyConfiguration.java @@ -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 { } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/RawEncryptStrategyConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/RawEncryptStrategyConfiguration.java new file mode 100644 index 0000000000..917ac52e4c --- /dev/null +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/RawEncryptStrategyConfiguration.java @@ -0,0 +1,36 @@ +/* + * 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 { + + private final String name; + + private final EncryptAlgorithm algorithm; +} diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/SPIEncryptStrategyConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/SPIEncryptStrategyConfiguration.java new file mode 100644 index 0000000000..55080ddc92 --- /dev/null +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/strategy/impl/SPIEncryptStrategyConfiguration.java @@ -0,0 +1,39 @@ +/* + * 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; + } +} diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIEncryptAlgorithm.java new file mode 100644 index 0000000000..b07a08cd10 --- /dev/null +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIEncryptAlgorithm.java @@ -0,0 +1,27 @@ +/* + * 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 { +} diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIQueryAssistedEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIQueryAssistedEncryptAlgorithm.java new file mode 100644 index 0000000000..e06e6bb051 --- /dev/null +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/SPIQueryAssistedEncryptAlgorithm.java @@ -0,0 +1,26 @@ +/* + * 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 { +} diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptStrategyConfigurationTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptStrategyConfigurationTest.java index 7fac6ecaef..c20ab530c1 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptStrategyConfigurationTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptStrategyConfigurationTest.java @@ -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)); } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java index 390799c96b..d9212dd2e5 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java @@ -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 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. * diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/AESEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/AESEncryptAlgorithm.java index 38474e4baa..cf937aa2c9 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/AESEncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/AESEncryptAlgorithm.java @@ -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"; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/MD5EncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/MD5EncryptAlgorithm.java index f41b4cb2b6..e2bc2e31a8 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/MD5EncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/MD5EncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/RC4EncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/RC4EncryptAlgorithm.java index 6fc3435e6a..dffcf958e9 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/RC4EncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/strategy/impl/RC4EncryptAlgorithm.java @@ -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"; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapper.java index 5760078ad8..6c6fb72778 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapper.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationYamlSwapper.java @@ -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 swapEncryptStrategy(final YamlEncryptRuleConfiguration yamlConfiguration) { - Collection result = new LinkedList<>(); + private Collection swapEncryptStrategy(final YamlEncryptRuleConfiguration yamlConfiguration) { + Collection result = new LinkedList<>(); for (Entry entry : yamlConfiguration.getEncryptStrategies().entrySet()) { YamlEncryptStrategyConfiguration yamlEncryptStrategyConfiguration = entry.getValue(); yamlEncryptStrategyConfiguration.setName(entry.getKey()); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptStrategyConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptStrategyConfigurationYamlSwapper.java index 54cf61af36..c83089ab9d 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptStrategyConfigurationYamlSwapper.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptStrategyConfigurationYamlSwapper.java @@ -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 { +public final class EncryptStrategyConfigurationYamlSwapper implements YamlSwapper { @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()); } } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/log/EncryptConfigurationLoggerTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/log/EncryptConfigurationLoggerTest.java index 192d82e7f7..9f2e9c7057 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/log/EncryptConfigurationLoggerTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/log/EncryptConfigurationLoggerTest.java @@ -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)); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java index 2b07d00dd1..9ea3523ac3 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java @@ -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)); } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestEncryptAlgorithm.java index bc97a50a8a..5830f24ba4 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestEncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestQueryAssistedEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestQueryAssistedEncryptAlgorithm.java index 9934ae484a..5890944a95 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestQueryAssistedEncryptAlgorithm.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/strategy/fixture/TestQueryAssistedEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java index 1cd78970fa..20bb3ee418 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java @@ -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; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java index ac5d4a5e3c..ecb01c7105 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-merge/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java @@ -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; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertOnDuplicateKeyUpdateValueParameterRewriter.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertOnDuplicateKeyUpdateValueParameterRewriter.java index ffcb085186..708b13d3e1 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertOnDuplicateKeyUpdateValueParameterRewriter.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertOnDuplicateKeyUpdateValueParameterRewriter.java @@ -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; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertValueParameterRewriter.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertValueParameterRewriter.java index db096a1647..6a4ffa5cdd 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertValueParameterRewriter.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/impl/EncryptInsertValueParameterRewriter.java @@ -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; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptInsertValuesTokenGenerator.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptInsertValuesTokenGenerator.java index 1750434842..da99f52f23 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptInsertValuesTokenGenerator.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptInsertValuesTokenGenerator.java @@ -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))); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/NormalEncryptAlgorithmFixture.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/NormalEncryptAlgorithmFixture.java index 2b98f7a577..2cd84ffc33 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/NormalEncryptAlgorithmFixture.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/NormalEncryptAlgorithmFixture.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java index b64f642f1c..769738abc5 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptStrategyBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptStrategyBeanDefinitionParser.java index f0e05d99bd..107c35aec5 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptStrategyBeanDefinitionParser.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptStrategyBeanDefinitionParser.java @@ -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)); diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/algorithm/MasterSlaveLoadBalanceAlgorithm.java similarity index 84% rename from shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/algorithm/MasterSlaveLoadBalanceAlgorithm.java index 912eab7de9..f740e06109 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/algorithm/MasterSlaveLoadBalanceAlgorithm.java @@ -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. diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/LoadBalanceStrategyConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/LoadBalanceStrategyConfiguration.java index 0b0406ae94..e845795b0a 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/LoadBalanceStrategyConfiguration.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/LoadBalanceStrategyConfiguration.java @@ -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 { } diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/RawLoadBalanceStrategyConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/RawLoadBalanceStrategyConfiguration.java new file mode 100644 index 0000000000..d65a1656e0 --- /dev/null +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/RawLoadBalanceStrategyConfiguration.java @@ -0,0 +1,36 @@ +/* + * 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 { + + private final String name; + + private final MasterSlaveLoadBalanceAlgorithm algorithm; +} diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/SPILoadBalanceStrategyConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/SPILoadBalanceStrategyConfiguration.java new file mode 100644 index 0000000000..140e729938 --- /dev/null +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/strategy/impl/SPILoadBalanceStrategyConfiguration.java @@ -0,0 +1,39 @@ +/* + * 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; + } +} diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/SPIMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/SPIMasterSlaveLoadBalanceAlgorithm.java new file mode 100644 index 0000000000..d59dbcfcf4 --- /dev/null +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/SPIMasterSlaveLoadBalanceAlgorithm.java @@ -0,0 +1,27 @@ +/* + * 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 { +} diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java index 1396afea0c..0475101328 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java @@ -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; diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java index fff916dd16..b2af7f6c32 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java @@ -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 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. * diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RandomMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RandomMasterSlaveLoadBalanceAlgorithm.java index 95c20f44c6..af1f73d19c 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RandomMasterSlaveLoadBalanceAlgorithm.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RandomMasterSlaveLoadBalanceAlgorithm.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RoundRobinMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RoundRobinMasterSlaveLoadBalanceAlgorithm.java index 02b1b5f7cb..bd90052f07 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RoundRobinMasterSlaveLoadBalanceAlgorithm.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/strategy/RoundRobinMasterSlaveLoadBalanceAlgorithm.java @@ -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 COUNTS = new ConcurrentHashMap<>(); diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java index 07e85ee535..199747c2e6 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java @@ -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) { diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm similarity index 100% rename from shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.SPIMasterSlaveLoadBalanceAlgorithm diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java index 1dddd95e9d..9ee5260681 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java @@ -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")); } } diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java index a8ac1fd196..e706c93c85 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java @@ -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"))); diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceStrategyBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceStrategyBeanDefinitionParser.java index f8848f9a25..02add93d91 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceStrategyBeanDefinitionParser.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceStrategyBeanDefinitionParser.java @@ -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)); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/NormalEncryptAlgorithmFixture.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/NormalEncryptAlgorithmFixture.java index 50f0ddcb0e..6ffaeb8786 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/NormalEncryptAlgorithmFixture.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/NormalEncryptAlgorithmFixture.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java index d49ef73417..cbea8570c5 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/fixture/QueryAssistedEncryptAlgorithmFixture.java @@ -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(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/TypedSPIConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/TypedSPIConfiguration.java index 60c17a04d5..703cb5fd88 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/TypedSPIConfiguration.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/TypedSPIConfiguration.java @@ -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; diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java new file mode 100644 index 0000000000..eb7ee53fbb --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java @@ -0,0 +1,24 @@ +/* + * 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 { +} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmFactory.java new file mode 100644 index 0000000000..62ae976e8a --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmFactory.java @@ -0,0 +1,56 @@ +/* + * 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 type of algorithm + * @return algorithm + */ + @SuppressWarnings("unchecked") + public static T createAlgorithm(final StrategyConfiguration strategyConfiguration, final Class spiAlgorithmClass) { + return strategyConfiguration instanceof RawStrategyConfiguration + ? (T) ((RawStrategyConfiguration) strategyConfiguration).getAlgorithm() : createSPIAlgorithm((SPIStrategyConfiguration) strategyConfiguration, spiAlgorithmClass); + } + + @SuppressWarnings("unchecked") + private static T createSPIAlgorithm(final SPIStrategyConfiguration spiStrategyConfiguration, final Class spiAlgorithmClass) { + T result = (T) TypedSPIRegistry.getRegisteredService(spiAlgorithmClass, spiStrategyConfiguration.getType(), spiStrategyConfiguration.getProperties()); + if (result instanceof ShardingSphereAlgorithmPostProcessor) { + ((ShardingSphereAlgorithmPostProcessor) result).init(); + } + return result; + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java new file mode 100644 index 0000000000..a2a973f8fe --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java @@ -0,0 +1,31 @@ +/* + * 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(); +} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/RawStrategyConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/RawStrategyConfiguration.java new file mode 100644 index 0000000000..5cf6035722 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/RawStrategyConfiguration.java @@ -0,0 +1,35 @@ +/* + * 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 type of algorithm + */ +public interface RawStrategyConfiguration extends StrategyConfiguration { + + /** + * Get algorithm. + * + * @return algorithm + */ + T getAlgorithm(); +} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/SPIStrategyConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/SPIStrategyConfiguration.java new file mode 100644 index 0000000000..52e93967e9 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/SPIStrategyConfiguration.java @@ -0,0 +1,40 @@ +/* + * 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(); +} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/StrategyConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/StrategyConfiguration.java new file mode 100644 index 0000000000..5cd0dd4af3 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/strategy/StrategyConfiguration.java @@ -0,0 +1,31 @@ +/* + * 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(); +} diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestEncryptAlgorithm.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestEncryptAlgorithm.java index c80835a8df..32ddf282b0 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestEncryptAlgorithm.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestQueryAssistedEncryptAlgorithm.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestQueryAssistedEncryptAlgorithm.java index a97a2fa4b2..5ebe90ef7f 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestQueryAssistedEncryptAlgorithm.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/fixture/TestQueryAssistedEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm index ac361c934b..8df4a42d90 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm @@ -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 diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSourceTest.java index f2f0f554d9..0ed16d7dd7 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSourceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSourceTest.java @@ -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 diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestEncryptAlgorithm.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestEncryptAlgorithm.java index b9cc764a2d..b33819296b 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestEncryptAlgorithm.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/fixture/TestEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootMasterSlaveTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootMasterSlaveTest.java index 6c1e848b09..8a8d7f1daa 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootMasterSlaveTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootMasterSlaveTest.java @@ -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")); } } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/EncryptNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/EncryptNamespaceTest.java index 6299159252..84511d9503 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/EncryptNamespaceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/EncryptNamespaceTest.java @@ -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().getValue(ConfigurationPropertyKey.SQL_SHOW)); assertTrue(getProperties().getValue(ConfigurationPropertyKey.QUERY_WITH_CIPHER_COLUMN)); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/MasterSlaveNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/MasterSlaveNamespaceTest.java index ae4cba4197..f8d5740f2f 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/MasterSlaveNamespaceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/MasterSlaveNamespaceTest.java @@ -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 = 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) { diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/fixture/TestEncryptAlgorithm.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/fixture/TestEncryptAlgorithm.java index 8bf10a3f41..e0274dba5a 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/fixture/TestEncryptAlgorithm.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/fixture/TestEncryptAlgorithm.java @@ -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(); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/rdb/withNamespaceDifferentTables.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/rdb/withNamespaceDifferentTables.xml index 84282b9b13..0a76bfd3c4 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/rdb/withNamespaceDifferentTables.xml +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/rdb/withNamespaceDifferentTables.xml @@ -52,7 +52,7 @@ - + diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm similarity index 100% rename from shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.strategy.spi.EncryptAlgorithm rename to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.SPIEncryptAlgorithm diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootEncryptTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootEncryptTest.java index 312d9bf42f..637cf0cedb 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootEncryptTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootEncryptTest.java @@ -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")); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java index 8af0e7c18a..dca657024a 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java @@ -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")); } } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationEncryptNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationEncryptNamespaceTest.java index 712d560b21..0488c1823f 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationEncryptNamespaceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationEncryptNamespaceTest.java @@ -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 encryptStrategyConfigurations = configuration.getEncryptStrategies().iterator(); - assertEncryptStrategyConfiguration(encryptStrategyConfigurations.next()); - assertEncryptStrategyConfiguration(encryptStrategyConfigurations.next()); + Iterator 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")); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationMasterSlaveNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationMasterSlaveNamespaceTest.java index 78972e3380..d131721864 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationMasterSlaveNamespaceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/OrchestrationMasterSlaveNamespaceTest.java @@ -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 = masterSlaveRule.findDataSourceRule("randomLoadBalanceAlgorithm"); assertTrue(masterSlaveDataSourceRule.isPresent()); diff --git a/shardingsphere-ui/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java b/shardingsphere-ui/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java index f7401228ff..05d1f1ff5d 100644 --- a/shardingsphere-ui/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java +++ b/shardingsphere-ui/shardingsphere-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/CenterRepositoryFactory.java @@ -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()); -- GitLab