This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 80ebf75c5fa Refactor check algorithms in DistSQL (#24688)
80ebf75c5fa is described below
commit 80ebf75c5fa8986c493d4c399e5502b90370fbe7
Author: ChenJiaHao <[email protected]>
AuthorDate: Mon Mar 20 18:20:12 2023 +0800
Refactor check algorithms in DistSQL (#24688)
* Refactor check algorithms in DistSQL
* fix
* fix code style
* fix check traffic rule
* fix code style
---
...AlterDatabaseDiscoveryRuleStatementUpdater.java | 8 ++--
...reateDatabaseDiscoveryRuleStatementUpdater.java | 8 ++--
...rDatabaseDiscoveryRuleStatementUpdaterTest.java | 4 +-
...eDatabaseDiscoveryRuleStatementUpdaterTest.java | 4 +-
.../update/AlterEncryptRuleStatementUpdater.java | 15 ++++---
.../update/CreateEncryptRuleStatementUpdater.java | 14 +++---
.../AlterEncryptRuleStatementUpdaterTest.java | 4 +-
.../CreateEncryptRuleStatementUpdaterTest.java | 51 ++++++++++++++++++----
.../update/CreateMaskRuleStatementUpdater.java | 4 +-
.../update/CreateMaskRuleStatementUpdaterTest.java | 4 +-
.../ReadwriteSplittingRuleStatementChecker.java | 6 +--
...ReadwriteSplittingRuleStatementUpdaterTest.java | 4 +-
...ReadwriteSplittingRuleStatementUpdaterTest.java | 5 ++-
...lterDefaultShadowAlgorithmStatementUpdater.java | 3 +-
.../update/AlterShadowRuleStatementUpdater.java | 9 +---
...eateDefaultShadowAlgorithmStatementUpdater.java | 4 +-
.../update/CreateShadowRuleStatementUpdater.java | 9 ++--
...DefaultShadowAlgorithmStatementUpdaterTest.java | 3 +-
...DefaultShadowAlgorithmStatementUpdaterTest.java | 4 +-
.../CreateShadowRuleStatementUpdaterTest.java | 4 +-
.../checker/ShardingTableRuleStatementChecker.java | 16 +++----
.../checker/ShardingRuleStatementCheckerTest.java | 5 ++-
.../infra/util/spi/type/typed/TypedSPI.java | 6 +--
.../infra/util/spi/type/typed/TypedSPILoader.java | 27 ++++++++++--
.../update/AlterTrafficRuleStatementUpdater.java | 20 +++------
.../AlterTrafficRuleStatementUpdaterTest.java | 4 +-
...aseDiscoveryRuleConfigurationImportChecker.java | 9 ++--
.../EncryptRuleConfigurationImportChecker.java | 6 +--
.../MaskRuleConfigurationImportChecker.java | 6 +--
...iteSplittingRuleConfigurationImportChecker.java | 6 +--
.../ShadowRuleConfigurationImportChecker.java | 6 +--
.../ShardingRuleConfigurationImportChecker.java | 37 +++++++---------
.../distsql/ral/updatable/LockClusterUpdater.java | 4 +-
...iscoveryRuleConfigurationImportCheckerTest.java | 4 +-
...plittingRuleConfigurationImportCheckerTest.java | 4 +-
...ShardingRuleConfigurationImportCheckerTest.java | 6 +--
.../ImportDatabaseConfigurationUpdaterTest.java | 4 +-
.../ral/updatable/LockClusterUpdaterTest.java | 4 +-
38 files changed, 174 insertions(+), 167 deletions(-)
diff --git
a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
index aa28a03d188..07e524324bc 100644
---
a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++
b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseD
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
@@ -85,10 +84,9 @@ public final class
AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
private void checkDiscoverTypeAndHeartbeat(final
AlterDatabaseDiscoveryRuleStatement sqlStatement) {
Map<String, List<DatabaseDiscoveryRuleSegment>> segmentMap =
sqlStatement.getRules().stream().collect(Collectors.groupingBy(each ->
each.getClass().getSimpleName()));
- Collection<String> invalidInput =
segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(),
Collections.emptyList()).stream()
- .map(each -> each.getDiscoveryType().getName()).distinct()
- .filter(each ->
!TypedSPILoader.contains(DatabaseDiscoveryProvider.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("database discovery", invalidInput));
+
segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(),
Collections.emptyList()).stream()
+ .map(DatabaseDiscoveryRuleSegment::getDiscoveryType)
+ .forEach(each ->
TypedSPILoader.checkService(DatabaseDiscoveryProvider.class, each.getName(),
each.getProps()));
}
@Override
diff --git
a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
index fc1ee56dadb..53a15f9ec47 100644
---
a/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
+++
b/features/db-discovery/distsql/handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
@@ -23,7 +23,6 @@ import
org.apache.shardingsphere.dbdiscovery.distsql.handler.converter.DatabaseD
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
@@ -106,10 +105,9 @@ public final class
CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDe
private void checkDiscoverTypeAndHeartbeat(final
CreateDatabaseDiscoveryRuleStatement sqlStatement) {
Map<String, List<DatabaseDiscoveryRuleSegment>> segmentMap =
sqlStatement.getRules().stream().collect(Collectors.groupingBy(each ->
each.getClass().getSimpleName()));
- Collection<String> invalidInput =
segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(),
Collections.emptyList()).stream()
- .map(each -> each.getDiscoveryType().getName()).distinct()
- .filter(each ->
!TypedSPILoader.contains(DatabaseDiscoveryProvider.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("database discovery", invalidInput));
+
segmentMap.getOrDefault(DatabaseDiscoveryRuleSegment.class.getSimpleName(),
Collections.emptyList()).stream()
+ .map(DatabaseDiscoveryRuleSegment::getDiscoveryType)
+ .forEach(each ->
TypedSPILoader.checkService(DatabaseDiscoveryProvider.class, each.getName(),
each.getProps()));
}
@Override
diff --git
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
index f3830ab4fdf..b21240b802e 100644
---
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
+++
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -21,12 +21,12 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleCon
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -97,7 +97,7 @@ public final class
AlterDatabaseDiscoveryRuleStatementUpdaterTest {
DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig =
new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds",
Collections.emptyList(), "ha-heartbeat", "TEST");
DatabaseDiscoveryRuleConfiguration ruleConfig = new
DatabaseDiscoveryRuleConfiguration(new
LinkedList<>(Collections.singleton(dataSourceRuleConfig)),
Collections.singletonMap("readwrite_ds_mgr", null),
Collections.singletonMap("readwrite_ds_heartbeat", null));
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, new
AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)),
ruleConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, new
AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)),
ruleConfig));
}
@Test
diff --git
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
index 5435fa6d047..f44a3a92fc0 100644
---
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
+++
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -21,12 +21,12 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleCon
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -89,7 +89,7 @@ public final class
CreateDatabaseDiscoveryRuleStatementUpdaterTest {
public void assertCheckSQLStatementWithDatabaseDiscoveryType() {
AlgorithmSegment algorithmSegment = new
AlgorithmSegment("INVALID_TYPE", new Properties());
DatabaseDiscoveryRuleSegment segment = new
DatabaseDiscoveryRuleSegment("readwrite_ds", Arrays.asList("ds_read_0",
"ds_read_1"), algorithmSegment, new Properties());
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false,
Collections.singleton(segment)), null));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false,
Collections.singleton(segment)), null));
}
@Test
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
index f5c9cd86a33..cc17a0c71a7 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgo
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
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;
@@ -38,6 +39,7 @@ import
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -82,12 +84,13 @@ public final class AlterEncryptRuleStatementUpdater
implements RuleDefinitionAlt
}
private void checkToBeAlteredEncryptors(final AlterEncryptRuleStatement
sqlStatement) throws InvalidAlgorithmConfigurationException {
- Collection<String> encryptors = new LinkedHashSet<>();
- for (EncryptRuleSegment each : sqlStatement.getRules()) {
- encryptors.addAll(each.getColumns().stream().map(column ->
column.getEncryptor().getName()).collect(Collectors.toSet()));
- }
- Collection<String> notExistedEncryptors =
encryptors.stream().filter(each ->
!TypedSPILoader.contains(EncryptAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("encryptor",
notExistedEncryptors));
+ Collection<AlgorithmSegment> encryptors = new LinkedHashSet<>();
+ sqlStatement.getRules().forEach(each ->
each.getColumns().forEach(column -> {
+ encryptors.add(column.getEncryptor());
+ encryptors.add(column.getAssistedQueryEncryptor());
+ encryptors.add(column.getLikeQueryEncryptor());
+ }));
+ encryptors.stream().filter(Objects::nonNull).forEach(each ->
TypedSPILoader.checkService(EncryptAlgorithm.class, each.getName(),
each.getProps()));
}
@Override
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
index e3a50530c7b..7c01d2d29ce 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.encrypt.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.EmptyStorageUnitException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import
org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleStatementConverter;
@@ -36,6 +36,7 @@ import
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -93,10 +94,13 @@ public final class CreateEncryptRuleStatementUpdater
implements RuleDefinitionCr
}
private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement
sqlStatement) {
- Collection<String> encryptors = new LinkedHashSet<>();
- sqlStatement.getRules().forEach(each ->
encryptors.addAll(each.getColumns().stream().map(column ->
column.getEncryptor().getName()).collect(Collectors.toSet())));
- Collection<String> notExistedEncryptors =
encryptors.stream().filter(each ->
!TypedSPILoader.contains(EncryptAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("encryptor",
notExistedEncryptors));
+ Collection<AlgorithmSegment> encryptors = new LinkedHashSet<>();
+ sqlStatement.getRules().forEach(each ->
each.getColumns().forEach(column -> {
+ encryptors.add(column.getEncryptor());
+ encryptors.add(column.getAssistedQueryEncryptor());
+ encryptors.add(column.getLikeQueryEncryptor());
+ }));
+ encryptors.stream().filter(Objects::nonNull).forEach(each ->
TypedSPILoader.checkService(EncryptAlgorithm.class, each.getName(),
each.getProps()));
}
private void checkDataSources(final ShardingSphereDatabase database) {
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
index 3a7f97756f2..407442bcdc2 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.encrypt.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
@@ -29,6 +28,7 @@ import
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegme
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
@@ -66,7 +66,7 @@ public final class AlterEncryptRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithoutToBeAlteredEncryptors() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"),
createCurrentRuleConfiguration()));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"),
createCurrentRuleConfiguration()));
}
@Test
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
index 0dc58783bd2..91ee50e3a2f 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.encrypt.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
@@ -26,7 +25,11 @@ import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
import
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
import
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
+import
org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
@@ -59,7 +62,7 @@ public final class CreateEncryptRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"),
null));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"),
null));
}
@Test
@@ -68,7 +71,7 @@ public final class CreateEncryptRuleStatementUpdaterTest {
"int varchar(10)", null, null, null, null, new
AlgorithmSegment("test", new Properties()),
new AlgorithmSegment("test", new Properties()),
new AlgorithmSegment("CHAR_DIGEST_LIKE", new Properties()),
null);
- EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt",
Collections.singleton(columnSegment), null);
+ EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_user",
Collections.singleton(columnSegment), null);
CreateEncryptRuleStatement statement = new
CreateEncryptRuleStatement(false, Collections.singleton(ruleSegment));
assertThrows(InvalidRuleConfigurationException.class, () ->
updater.checkSQLStatement(database, statement, null));
}
@@ -76,7 +79,7 @@ public final class CreateEncryptRuleStatementUpdaterTest {
@Test
public void assertCreateEncryptRuleWithIfNotExists() {
EncryptRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
- CreateEncryptRuleStatement sqlStatement = createSQLStatement(true,
"AES");
+ CreateEncryptRuleStatement sqlStatement =
createAESEncryptRuleSQLStatement(true);
updater.checkSQLStatement(database, sqlStatement, currentRuleConfig);
EncryptRuleConfiguration toBeCreatedRuleConfig =
updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement);
updater.updateCurrentRuleConfiguration(currentRuleConfig,
toBeCreatedRuleConfig);
@@ -84,8 +87,16 @@ public final class CreateEncryptRuleStatementUpdaterTest {
assertTrue(currentRuleConfig.getEncryptors().isEmpty());
}
+ private CreateEncryptRuleStatement createAESEncryptRuleSQLStatement(final
boolean ifNotExists) {
+ EncryptColumnSegment encryptColumnSegment = new
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column",
"like_column",
+ new AlgorithmSegment("AES", PropertiesBuilder.build(new
Property("aes-key-value", "abc"))), null, null, null);
+ Collection<EncryptRuleSegment> rules = new LinkedList<>();
+ rules.add(new EncryptRuleSegment("t_user",
Collections.singleton(encryptColumnSegment), null));
+ return new CreateEncryptRuleStatement(ifNotExists, rules);
+ }
+
private CreateEncryptRuleStatement createSQLStatement(final boolean
ifNotExists, final String encryptorName) {
- EncryptColumnSegment tEncryptColumnSegment = new
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column",
"like_column",
+ EncryptColumnSegment tUserColumnSegment = new
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column",
"like_column",
new AlgorithmSegment(encryptorName, new Properties()),
new AlgorithmSegment(encryptorName, new Properties()),
new AlgorithmSegment(encryptorName, new Properties()), null);
@@ -93,18 +104,42 @@ public final class CreateEncryptRuleStatementUpdaterTest {
new AlgorithmSegment(encryptorName, new Properties()),
new AlgorithmSegment(encryptorName, new Properties()),
new AlgorithmSegment(encryptorName, new Properties()), null);
- EncryptRuleSegment tEncryptRuleSegment = new
EncryptRuleSegment("t_encrypt", Collections.singleton(tEncryptColumnSegment),
null);
+ EncryptRuleSegment tUserRuleSegment = new EncryptRuleSegment("t_user",
Collections.singleton(tUserColumnSegment), null);
EncryptRuleSegment tOrderRuleSegment = new
EncryptRuleSegment("t_order", Collections.singleton(tOrderColumnSegment), null);
Collection<EncryptRuleSegment> rules = new LinkedList<>();
- rules.add(tEncryptRuleSegment);
+ rules.add(tUserRuleSegment);
rules.add(tOrderRuleSegment);
return new CreateEncryptRuleStatement(ifNotExists, rules);
}
private EncryptRuleConfiguration getCurrentRuleConfig() {
Collection<EncryptTableRuleConfiguration> rules = new LinkedList<>();
- rules.add(new EncryptTableRuleConfiguration("t_encrypt",
Collections.emptyList(), null));
+ rules.add(new EncryptTableRuleConfiguration("t_user",
Collections.emptyList(), null));
rules.add(new EncryptTableRuleConfiguration("t_order",
Collections.emptyList(), null));
return new EncryptRuleConfiguration(rules, new HashMap<>());
}
+
+ @Test
+ public void assertCreateAESEncryptRuleWithPropertiesNotExists() {
+ EncryptRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
+ CreateEncryptRuleStatement sqlStatement =
createWrongAESEncryptorSQLStatement();
+ assertThrows(EncryptAlgorithmInitializationException.class, () ->
updater.checkSQLStatement(database, sqlStatement, currentRuleConfig));
+ }
+
+ private CreateEncryptRuleStatement createWrongAESEncryptorSQLStatement() {
+ EncryptColumnSegment tUserColumnSegment = new
EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column",
"like_column",
+ new AlgorithmSegment("AES", new Properties()),
+ new AlgorithmSegment("AES", new Properties()),
+ new AlgorithmSegment("CHAR_DIGEST_LIKE", new Properties()),
null);
+ EncryptColumnSegment tOrderColumnSegment = new
EncryptColumnSegment("order_id", "order_cipher", "order_plain",
"assisted_column", "like_column",
+ new AlgorithmSegment("AES", new Properties()),
+ new AlgorithmSegment("AES", new Properties()),
+ new AlgorithmSegment("CHAR_DIGEST_LIKE", new Properties()),
null);
+ EncryptRuleSegment tUserRuleSegment = new EncryptRuleSegment("t_user",
Collections.singleton(tUserColumnSegment), null);
+ EncryptRuleSegment tOrderRuleSegment = new
EncryptRuleSegment("t_order", Collections.singleton(tOrderColumnSegment), null);
+ Collection<EncryptRuleSegment> rules = new LinkedList<>();
+ rules.add(tUserRuleSegment);
+ rules.add(tOrderRuleSegment);
+ return new CreateEncryptRuleStatement(true, rules);
+ }
}
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
index 36cdd419cef..dcf9b63e882 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdater.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.mask.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -63,8 +62,7 @@ public final class CreateMaskRuleStatementUpdater implements
RuleDefinitionCreat
private void checkAlgorithms(final CreateMaskRuleStatement sqlStatement) {
Collection<MaskColumnSegment> columns = new LinkedList<>();
sqlStatement.getRules().forEach(each ->
columns.addAll(each.getColumns()));
- columns.forEach(each ->
ShardingSpherePreconditions.checkState(TypedSPILoader.contains(MaskAlgorithm.class,
each.getAlgorithm().getName()),
- () -> new InvalidAlgorithmConfigurationException("mask",
each.getAlgorithm().getName())));
+ columns.forEach(each ->
TypedSPILoader.checkService(MaskAlgorithm.class, each.getAlgorithm().getName(),
each.getAlgorithm().getProps()));
}
@Override
diff --git
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
index 3f66390ff08..1e93d34e3db 100644
---
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
+++
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleStatementUpdaterTest.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.mask.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.distsql.parser.segment.MaskColumnSegment;
@@ -58,7 +58,7 @@ public final class CreateMaskRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithInvalidAlgorithm() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"),
null));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement(false, "INVALID_TYPE"),
null));
}
@Test
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 99e492159cc..541283e9a87 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.checker;
import com.google.common.base.Strings;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
@@ -41,7 +40,6 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -219,8 +217,6 @@ public final class ReadwriteSplittingRuleStatementChecker {
}
private static void checkLoadBalancers(final
Collection<ReadwriteSplittingRuleSegment> segments) {
- Collection<String> notExistedLoadBalancers =
segments.stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).filter(Objects::nonNull).distinct()
- .filter(each ->
!TypedSPILoader.contains(ReadQueryLoadBalanceAlgorithm.class,
each)).collect(Collectors.toSet());
-
ShardingSpherePreconditions.checkState(notExistedLoadBalancers.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("Load balancers",
notExistedLoadBalancers));
+ segments.forEach(each ->
TypedSPILoader.checkService(ReadQueryLoadBalanceAlgorithm.class,
each.getLoadBalancer(), each.getProps()));
}
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
index 2f7b52a9af7..1b0f8ed5553 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
@@ -25,6 +24,7 @@ import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.strategy.StaticReadwriteSplittingStrategyConfiguration;
@@ -95,7 +95,7 @@ public final class
AlterReadwriteSplittingRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithoutToBeAlteredLoadBalancers() {
when(database.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList());
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"),
createCurrentRuleConfiguration()));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"),
createCurrentRuleConfiguration()));
}
@Test
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
index 4c6fc12f326..3ce46d0b0bf 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
@@ -25,6 +24,7 @@ import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -102,7 +102,8 @@ public final class
CreateReadwriteSplittingRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() {
when(database.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList());
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"), null));
+ when(TypedSPILoader.checkService(any(), any(),
any())).thenCallRealMethod();
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, createSQLStatement("INVALID_TYPE"), null));
}
@Test
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
index 2bcdda357e6..7db65e77c9e 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmStatementUpdater.java
@@ -82,8 +82,7 @@ public final class
AlterDefaultShadowAlgorithmStatementUpdater implements RuleDe
}
private void checkAlgorithmType(final AlgorithmSegment algorithmSegment) {
- String shadowAlgorithmType = algorithmSegment.getName();
-
ShardingSpherePreconditions.checkState(TypedSPILoader.contains(ShadowAlgorithm.class,
shadowAlgorithmType), () -> new
InvalidAlgorithmConfigurationException("shadow", shadowAlgorithmType));
+ TypedSPILoader.checkService(ShadowAlgorithm.class,
algorithmSegment.getName(), algorithmSegment.getProps());
}
@Override
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
index 810aae05b42..f0bcd69e5cf 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java
@@ -18,13 +18,11 @@
package org.apache.shardingsphere.shadow.distsql.handler.update;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.AlgorithmInUsedException;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
@@ -39,7 +37,6 @@ import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.Map;
-import java.util.stream.Collectors;
/**
* Alter shadow rule statement updater.
@@ -88,10 +85,8 @@ public final class AlterShadowRuleStatementUpdater
implements RuleDefinitionAlte
}
private void checkAlgorithmType(final AlterShadowRuleStatement
sqlStatement) {
- Collection<String> invalidAlgorithmTypes =
sqlStatement.getRules().stream().flatMap(each ->
each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
- .map(each ->
each.getAlgorithmSegment().getName()).collect(Collectors.toSet()).stream()
- .filter(each ->
!TypedSPILoader.contains(ShadowAlgorithm.class,
each)).collect(Collectors.toSet());
-
ShardingSpherePreconditions.checkState(invalidAlgorithmTypes.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("shadow", invalidAlgorithmTypes));
+ sqlStatement.getRules().stream().flatMap(each ->
each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
+ .map(ShadowAlgorithmSegment::getAlgorithmSegment).forEach(each
-> TypedSPILoader.checkService(ShadowAlgorithm.class, each.getName(),
each.getProps()));
}
private void checkAlgorithms(final String databaseName, final
Collection<ShadowRuleSegment> segments) {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
index 9cde559aee0..181e2815b8a 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
@@ -86,8 +86,8 @@ public final class
CreateDefaultShadowAlgorithmStatementUpdater implements RuleD
}
private void checkAlgorithmType(final
CreateDefaultShadowAlgorithmStatement sqlStatement) {
- String shadowAlgorithmType =
sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment().getName();
-
ShardingSpherePreconditions.checkState(TypedSPILoader.contains(ShadowAlgorithm.class,
shadowAlgorithmType), () -> new
InvalidAlgorithmConfigurationException("shadow", shadowAlgorithmType));
+ AlgorithmSegment shadowAlgorithmType =
sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment();
+ TypedSPILoader.checkService(ShadowAlgorithm.class,
shadowAlgorithmType.getName(), shadowAlgorithmType.getProps());
}
private void checkAlgorithmCompleteness(final Collection<AlgorithmSegment>
algorithmSegments) {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
index 4b0db5ddff8..3de3e29b5ab 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.shadow.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
@@ -29,13 +28,13 @@ import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import
org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker;
import
org.apache.shardingsphere.shadow.distsql.handler.converter.ShadowRuleStatementConverter;
import
org.apache.shardingsphere.shadow.distsql.handler.supporter.ShadowRuleStatementSupporter;
+import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.CreateShadowRuleStatement;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Collection;
import java.util.Map;
-import java.util.stream.Collectors;
/**
* Create shadow rule statement updater.
@@ -92,10 +91,8 @@ public final class CreateShadowRuleStatementUpdater
implements RuleDefinitionCre
}
private void checkAlgorithmType(final Collection<ShadowRuleSegment>
segments) {
- Collection<String> invalidAlgorithmTypes =
segments.stream().flatMap(each ->
each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
- .map(each ->
each.getAlgorithmSegment().getName()).collect(Collectors.toSet())
- .stream().filter(each ->
!TypedSPILoader.contains(ShadowAlgorithm.class,
each)).collect(Collectors.toSet());
-
ShardingSpherePreconditions.checkState(invalidAlgorithmTypes.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("shadow", invalidAlgorithmTypes));
+ segments.stream().flatMap(each ->
each.getShadowTableRules().values().stream()).flatMap(Collection::stream)
+ .map(ShadowAlgorithmSegment::getAlgorithmSegment).forEach(each
-> TypedSPILoader.checkService(ShadowAlgorithm.class, each.getName(),
each.getProps()));
}
@Override
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
index 3052a0e985c..94a1c7a05b6 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredR
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.update.AlterDefaultShadowAlgorithmStatementUpdater;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
@@ -72,7 +73,7 @@ public final class
AlterDefaultShadowAlgorithmStatementUpdaterTest {
public void assertExecuteInvalidAlgorithmType() {
AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("NOT_EXIST_SQL_HINT", PropertiesBuilder.build(new
Property("type", "value")))));
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, sqlStatement, currentConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, sqlStatement, currentConfig));
}
@Test
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
index 1b2ff22c881..6e418be0b5d 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.distsql.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.update.CreateDefaultShadowAlgorithmStatementUpdater;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
@@ -51,7 +51,7 @@ public final class
CreateDefaultShadowAlgorithmStatementUpdaterTest {
public void assertExecuteWithInvalidAlgorithm() {
CreateDefaultShadowAlgorithmStatement statement =
mock(CreateDefaultShadowAlgorithmStatement.class);
when(statement.getShadowAlgorithmSegment()).thenReturn(new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value")))));
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, statement, currentConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, statement, currentConfig));
}
@Test
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
index f4f857ede46..8afc1cb807d 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.shadow.distsql.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.update.CreateShadowRuleStatementUpdater;
@@ -112,7 +112,7 @@ public final class CreateShadowRuleStatementUpdaterTest {
ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("type",
PropertiesBuilder.build(new Property("type", "value"))));
CreateShadowRuleStatement sqlStatement = new
CreateShadowRuleStatement(false,
Collections.singleton(new ShadowRuleSegment("ruleName", "ds",
null, Collections.singletonMap("t_order", Collections.singleton(segment)))));
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.checkSQLStatement(database, sqlStatement, currentConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.checkSQLStatement(database, sqlStatement, currentConfig));
}
@Test
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
index c086c7b6040..2878e68a225 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
@@ -251,27 +251,23 @@ public final class ShardingTableRuleStatementChecker {
private static void checkKeyGenerators(final
Collection<AbstractTableRuleSegment> rules, final ShardingRuleConfiguration
currentRuleConfig) {
Set<String> notExistKeyGenerator = new LinkedHashSet<>(rules.size());
- Set<String> requiredKeyGenerators = new LinkedHashSet<>(rules.size());
+ Set<AlgorithmSegment> requiredKeyGenerators = new
LinkedHashSet<>(rules.size());
rules.stream().map(AbstractTableRuleSegment::getKeyGenerateStrategySegment).filter(Objects::nonNull)
.peek(each -> each.getKeyGenerateAlgorithmName()
.filter(optional -> null == currentRuleConfig ||
!currentRuleConfig.getKeyGenerators().containsKey(optional)).ifPresent(notExistKeyGenerator::add))
- .filter(each ->
!each.getKeyGenerateAlgorithmName().isPresent()).forEach(each ->
requiredKeyGenerators.add(each.getKeyGenerateAlgorithmSegment().getName()));
+ .filter(each ->
!each.getKeyGenerateAlgorithmName().isPresent()).forEach(each ->
requiredKeyGenerators.add(each.getKeyGenerateAlgorithmSegment()));
ShardingSpherePreconditions.checkState(notExistKeyGenerator.isEmpty(),
() -> new MissingRequiredAlgorithmException("key generator",
notExistKeyGenerator));
- Collection<String> invalidKeyGenerators =
requiredKeyGenerators.stream()
- .distinct().filter(each ->
!TypedSPILoader.contains(KeyGenerateAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidKeyGenerators.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("key generator",
invalidKeyGenerators));
+ requiredKeyGenerators.forEach(each ->
TypedSPILoader.checkService(KeyGenerateAlgorithm.class, each.getName(),
each.getProps()));
}
private static void checkAuditors(final
Collection<AbstractTableRuleSegment> rules) {
Collection<AuditStrategySegment> auditStrategySegments =
rules.stream().map(AbstractTableRuleSegment::getAuditStrategySegment).filter(Objects::nonNull).collect(Collectors.toList());
- Set<String> requiredAuditors = new LinkedHashSet<>();
+ Set<AlgorithmSegment> requiredAuditors = new LinkedHashSet<>();
for (AuditStrategySegment each : auditStrategySegments) {
requiredAuditors.addAll(each.getAuditorSegments().stream()
-
.map(ShardingAuditorSegment::getAlgorithmSegment).collect(Collectors.toList()).stream().map(AlgorithmSegment::getName).collect(Collectors.toList()));
+
.map(ShardingAuditorSegment::getAlgorithmSegment).collect(Collectors.toList()));
}
- Collection<String> invalidAuditors = requiredAuditors.stream()
- .distinct().filter(each ->
!TypedSPILoader.contains(ShardingAuditAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidAuditors.isEmpty(), ()
-> new InvalidAlgorithmConfigurationException("auditor", invalidAuditors));
+ requiredAuditors.forEach(each ->
TypedSPILoader.checkService(ShardingAuditAlgorithm.class, each.getName(),
each.getProps()));
}
private static void checkAutoTableRule(final
Collection<AbstractTableRuleSegment> rules) {
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
index ee7a1d3b207..2d84a4e779f 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import
org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
@@ -138,7 +139,7 @@ public final class ShardingRuleStatementCheckerTest {
public void assertCheckCreationWithInvalidKeyGenerateAlgorithm() {
AutoTableRuleSegment autoTableRuleSegment = new
AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
autoTableRuleSegment.setKeyGenerateStrategySegment(new
KeyGenerateStrategySegment("product_id", new AlgorithmSegment("invalid",
PropertiesBuilder.build(new Property("invalid", "invalid")))));
- assertThrows(InvalidAlgorithmConfigurationException.class,
+ assertThrows(ServiceProviderNotFoundServerException.class,
() ->
ShardingTableRuleStatementChecker.checkCreation(database,
Collections.singleton(autoTableRuleSegment), false, shardingRuleConfig));
}
@@ -147,7 +148,7 @@ public final class ShardingRuleStatementCheckerTest {
AutoTableRuleSegment autoTableRuleSegment = new
AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
autoTableRuleSegment.setAuditStrategySegment(new
AuditStrategySegment(Collections.singletonList(new
ShardingAuditorSegment("sharding_key_required_auditor",
new AlgorithmSegment("invalid", new Properties()))), true));
- assertThrows(InvalidAlgorithmConfigurationException.class,
+ assertThrows(ServiceProviderNotFoundServerException.class,
() ->
ShardingTableRuleStatementChecker.checkCreation(database,
Collections.singleton(autoTableRuleSegment), false, shardingRuleConfig));
}
diff --git
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
index 882c37758d4..fd9d56d7d6c 100644
---
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
+++
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
@@ -28,7 +28,7 @@ public interface TypedSPI {
/**
* Initialize SPI.
- *
+ *
* @param props properties to be initialized
*/
default void init(Properties props) {
@@ -45,7 +45,7 @@ public interface TypedSPI {
/**
* Get type aliases.
- *
+ *
* @return type aliases
*/
default Collection<String> getTypeAliases() {
@@ -54,7 +54,7 @@ public interface TypedSPI {
/**
* Judge whether default service provider.
- *
+ *
* @return is default service provider or not
*/
default boolean isDefault() {
diff --git
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
index e6c10619ee2..0540392956c 100644
---
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
+++
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
+import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
@@ -45,7 +46,7 @@ public final class TypedSPILoader {
/**
* Find service.
- *
+ *
* @param spiClass typed SPI class
* @param type type
* @param <T> SPI class type
@@ -57,7 +58,7 @@ public final class TypedSPILoader {
/**
* Find service.
- *
+ *
* @param spiClass typed SPI class
* @param type type
* @param props properties
@@ -103,7 +104,7 @@ public final class TypedSPILoader {
/**
* Get service.
- *
+ *
* @param spiClass typed SPI class
* @param type type
* @param <T> SPI class type
@@ -125,4 +126,24 @@ public final class TypedSPILoader {
public static <T extends TypedSPI> T getService(final Class<T> spiClass,
final String type, final Properties props) {
return findService(spiClass, type, props).orElseGet(() ->
findService(spiClass).orElseThrow(() -> new
ServiceProviderNotFoundServerException(spiClass)));
}
+
+ /**
+ * Check service.
+ *
+ * @param spiClass typed SPI class
+ * @param type type
+ * @param props properties
+ * @param <T> SPI class type
+ * @return check result
+ */
+ public static <T extends TypedSPI> boolean checkService(final Class<T>
spiClass, final String type, final Properties props) {
+ Collection<T> serviceInstances =
ShardingSphereServiceLoader.getServiceInstances(spiClass);
+ for (T each : serviceInstances) {
+ if (matchesType(type, each)) {
+ each.init(null == props ? new Properties() :
convertToStringTypedProperties(props));
+ return true;
+ }
+ }
+ throw new ServiceProviderNotFoundServerException(spiClass, type);
+ }
}
diff --git
a/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
b/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
index 730e65c79e0..a20fce85ce8 100644
---
a/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
+++
b/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.traffic.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.ral.update.GlobalRuleRALUpdater;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
@@ -59,21 +58,12 @@ public final class AlterTrafficRuleStatementUpdater
implements GlobalRuleRALUpda
}
private void checkAlgorithmNames(final AlterTrafficRuleStatement
sqlStatement) {
- Collection<String> invalidAlgorithmNames =
getInvalidAlgorithmNames(sqlStatement);
-
ShardingSpherePreconditions.checkState(invalidAlgorithmNames.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("Traffic", invalidAlgorithmNames));
- }
-
- private Collection<String> getInvalidAlgorithmNames(final
AlterTrafficRuleStatement sqlStatement) {
- Collection<String> result = new LinkedList<>();
- for (TrafficRuleSegment each : sqlStatement.getSegments()) {
- if (!TypedSPILoader.contains(TrafficAlgorithm.class,
each.getAlgorithm().getName())) {
- result.add(each.getAlgorithm().getName());
- }
- if (null != each.getLoadBalancer() &&
!TypedSPILoader.contains(TrafficLoadBalanceAlgorithm.class,
each.getLoadBalancer().getName())) {
- result.add(each.getLoadBalancer().getName());
+ sqlStatement.getSegments().forEach(each -> {
+ TypedSPILoader.checkService(TrafficAlgorithm.class,
each.getAlgorithm().getName(), each.getAlgorithm().getProps());
+ if (null != each.getLoadBalancer()) {
+ TypedSPILoader.checkService(TrafficLoadBalanceAlgorithm.class,
each.getLoadBalancer().getName(), each.getLoadBalancer().getProps());
}
- }
- return result;
+ });
}
@Override
diff --git
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
index c2db9baab23..bf1d505d75c 100644
---
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
+++
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.traffic.distsql.handler.update;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
@@ -54,7 +54,7 @@ public final class AlterTrafficRuleStatementUpdaterTest {
TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
"rule_name_1", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid",
new Properties()));
AlterTrafficRuleStatementUpdater updater = new
AlterTrafficRuleStatementUpdater();
- assertThrows(InvalidAlgorithmConfigurationException.class,
+ assertThrows(ServiceProviderNotFoundServerException.class,
() ->
updater.checkSQLStatement(createTrafficRuleConfiguration(), new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment))));
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
index 8ea324a6e4a..3b56367e119 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java
@@ -19,17 +19,15 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.check
import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.LinkedHashSet;
-import java.util.stream.Collectors;
+import java.util.LinkedList;
/**
* Database discovery rule configuration import checker.
@@ -61,9 +59,8 @@ public final class
DatabaseDiscoveryRuleConfigurationImportChecker {
}
private void checkDiscoverTypeAndHeartbeat(final String databaseName,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) {
- Collection<String> invalidInput =
currentRuleConfig.getDiscoveryTypes().values().stream().map(AlgorithmConfiguration::getType)
- .filter(each ->
!TypedSPILoader.contains(DatabaseDiscoveryProvider.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidInput.isEmpty(), () ->
new InvalidAlgorithmConfigurationException(DB_DISCOVERY.toLowerCase(),
invalidInput));
+ currentRuleConfig.getDiscoveryTypes().values().forEach(each ->
TypedSPILoader.checkService(DatabaseDiscoveryProvider.class, each.getType(),
each.getProps()));
+ Collection<String> invalidInput = new LinkedList<>();
currentRuleConfig.getDataSources().forEach(each -> {
if
(!currentRuleConfig.getDiscoveryTypes().containsKey(each.getDiscoveryTypeName()))
{
invalidInput.add(each.getDiscoveryTypeName());
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
index fc70fb0a530..4203471d076 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
@@ -17,14 +17,12 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
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.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
@@ -63,9 +61,7 @@ public final class EncryptRuleConfigurationImportChecker {
}
private void checkEncryptors(final EncryptRuleConfiguration
currentRuleConfig) {
- Collection<String> notExistedAlgorithms =
currentRuleConfig.getEncryptors().values().stream().map(AlgorithmConfiguration::getType)
- .filter(each ->
!TypedSPILoader.contains(EncryptAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedAlgorithms.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("Encryptors",
notExistedAlgorithms));
+ currentRuleConfig.getEncryptors().values().forEach(each ->
TypedSPILoader.checkService(EncryptAlgorithm.class, each.getType(),
each.getProps()));
}
private void checkTableEncryptorsExisted(final EncryptRuleConfiguration
configuration, final String databaseName) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/MaskRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/MaskRuleConfigurationImportChecker.java
index 490fb843140..fa630cdabae 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/MaskRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/MaskRuleConfigurationImportChecker.java
@@ -17,10 +17,8 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
@@ -62,9 +60,7 @@ public final class MaskRuleConfigurationImportChecker {
}
private void checkMaskAlgorithms(final MaskRuleConfiguration
currentRuleConfig) {
- Collection<String> notExistedAlgorithms =
currentRuleConfig.getMaskAlgorithms().values().stream().map(AlgorithmConfiguration::getType)
- .filter(each -> !TypedSPILoader.contains(MaskAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedAlgorithms.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("Mask algorithms",
notExistedAlgorithms));
+ currentRuleConfig.getMaskAlgorithms().values().forEach(each ->
TypedSPILoader.checkService(MaskAlgorithm.class, each.getType(),
each.getProps()));
}
private void checkMaskAlgorithmsExisted(final MaskRuleConfiguration
currentRuleConfig, final String databaseName) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
index 889bf71e624..588f553c57e 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
@@ -17,9 +17,7 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -80,8 +78,6 @@ public final class
ReadwriteSplittingRuleConfigurationImportChecker {
}
private void checkLoadBalancers(final ReadwriteSplittingRuleConfiguration
currentRuleConfig) {
- Collection<String> notExistedLoadBalancers =
currentRuleConfig.getLoadBalancers().values().stream().map(AlgorithmConfiguration::getType)
- .filter(each ->
!TypedSPILoader.contains(ReadQueryLoadBalanceAlgorithm.class,
each)).collect(Collectors.toList());
-
ShardingSpherePreconditions.checkState(notExistedLoadBalancers.isEmpty(), () ->
new InvalidAlgorithmConfigurationException("Load balancers",
notExistedLoadBalancers));
+ currentRuleConfig.getLoadBalancers().values().forEach(each ->
TypedSPILoader.checkService(ReadQueryLoadBalanceAlgorithm.class,
each.getType(), each.getProps()));
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
index 207544d98fb..60160b84ef6 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
@@ -17,10 +17,8 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -88,8 +86,6 @@ public final class ShadowRuleConfigurationImportChecker {
}
private void checkShadowAlgorithms(final ShadowRuleConfiguration
currentRuleConfig) {
- Collection<String> notExistedAlgorithms =
currentRuleConfig.getShadowAlgorithms().values().stream().map(AlgorithmConfiguration::getType)
- .filter(each ->
!TypedSPILoader.contains(ShadowAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(notExistedAlgorithms.isEmpty(),
() -> new InvalidAlgorithmConfigurationException("Shadow algorithms",
notExistedAlgorithms));
+ currentRuleConfig.getShadowAlgorithms().values().forEach(each ->
TypedSPILoader.checkService(ShadowAlgorithm.class, each.getType(),
each.getProps()));
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
index c7520c622b8..a463977ae49 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
@@ -59,8 +58,8 @@ public final class ShardingRuleConfigurationImportChecker {
String databaseName = database.getName();
checkLogicTables(databaseName, currentRuleConfig);
checkResources(databaseName, database, currentRuleConfig);
-
checkInvalidKeyGeneratorAlgorithms(currentRuleConfig.getKeyGenerators().values());
-
checkInvalidShardingAlgorithms(currentRuleConfig.getShardingAlgorithms().values());
+
checkShardingAlgorithms(currentRuleConfig.getShardingAlgorithms().values());
+
checkKeyGeneratorAlgorithms(currentRuleConfig.getKeyGenerators().values());
}
private void checkLogicTables(final String databaseName, final
ShardingRuleConfiguration currentRuleConfig) {
@@ -74,16 +73,12 @@ public final class ShardingRuleConfigurationImportChecker {
ShardingSpherePreconditions.checkState(duplicatedLogicTables.isEmpty(), () ->
new DuplicateRuleException("sharding", databaseName, duplicatedLogicTables));
}
- private void checkInvalidShardingAlgorithms(final
Collection<AlgorithmConfiguration> algorithmConfigs) {
- Collection<String> invalidAlgorithms = algorithmConfigs.stream()
- .map(AlgorithmConfiguration::getType).filter(each ->
!TypedSPILoader.contains(ShardingAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidAlgorithms.isEmpty(), ()
-> new InvalidAlgorithmConfigurationException("sharding", invalidAlgorithms));
- }
-
- private void checkInvalidKeyGeneratorAlgorithms(final
Collection<AlgorithmConfiguration> algorithmConfigs) {
- Collection<String> invalidAlgorithms = algorithmConfigs.stream()
- .map(AlgorithmConfiguration::getType).filter(each ->
!TypedSPILoader.contains(KeyGenerateAlgorithm.class,
each)).collect(Collectors.toList());
- ShardingSpherePreconditions.checkState(invalidAlgorithms.isEmpty(), ()
-> new InvalidAlgorithmConfigurationException("key generator",
invalidAlgorithms));
+ private void checkResources(final String databaseName, final
ShardingSphereDatabase database, final ShardingRuleConfiguration
currentRuleConfig) {
+ Collection<String> requiredResource =
getRequiredResources(currentRuleConfig);
+ Collection<String> notExistedResources =
database.getResourceMetaData().getNotExistedDataSources(requiredResource);
+ Collection<String> logicResources = getLogicResources(database);
+ notExistedResources.removeIf(logicResources::contains);
+ ShardingSpherePreconditions.checkState(notExistedResources.isEmpty(),
() -> new MissingRequiredStorageUnitsException(databaseName,
notExistedResources));
}
private Collection<String> getRequiredResources(final
ShardingRuleConfiguration currentRuleConfig) {
@@ -103,16 +98,16 @@ public final class ShardingRuleConfigurationImportChecker {
return actualDataNodes.stream().map(each -> new
DataNode(each).getDataSourceName()).collect(Collectors.toList());
}
- private void checkResources(final String databaseName, final
ShardingSphereDatabase database, final ShardingRuleConfiguration
currentRuleConfig) {
- Collection<String> requiredResource =
getRequiredResources(currentRuleConfig);
- Collection<String> notExistedResources =
database.getResourceMetaData().getNotExistedDataSources(requiredResource);
- Collection<String> logicResources = getLogicResources(database);
- notExistedResources.removeIf(logicResources::contains);
- ShardingSpherePreconditions.checkState(notExistedResources.isEmpty(),
() -> new MissingRequiredStorageUnitsException(databaseName,
notExistedResources));
- }
-
private Collection<String> getLogicResources(final ShardingSphereDatabase
database) {
return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
.map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
+
+ private void checkShardingAlgorithms(final
Collection<AlgorithmConfiguration> algorithmConfigs) {
+ algorithmConfigs.forEach(each ->
TypedSPILoader.checkService(ShardingAlgorithm.class, each.getType(),
each.getProps()));
+ }
+
+ private void checkKeyGeneratorAlgorithms(final
Collection<AlgorithmConfiguration> algorithmConfigs) {
+ algorithmConfigs.forEach(each ->
TypedSPILoader.checkService(KeyGenerateAlgorithm.class, each.getType(),
each.getProps()));
+ }
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdater.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdater.java
index 47060b5bc26..2496a1a4a75 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdater.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdater.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import org.apache.shardingsphere.distsql.handler.ral.update.RALUpdater;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.LockClusterStatement;
@@ -57,8 +56,7 @@ public final class LockClusterUpdater implements
RALUpdater<LockClusterStatement
private void checkAlgorithm(final LockClusterStatement sqlStatement) {
ShardingSpherePreconditions.checkState(isStrategyDefinitionExists(sqlStatement),
MissingRequiredAlgorithmException::new);
-
ShardingSpherePreconditions.checkState(TypedSPILoader.contains(ClusterLockStrategy.class,
sqlStatement.getLockStrategy().getName()),
- () -> new InvalidAlgorithmConfigurationException("cluster
lock"));
+ TypedSPILoader.checkService(ClusterLockStrategy.class,
sqlStatement.getLockStrategy().getName(),
sqlStatement.getLockStrategy().getProps());
}
private boolean isStrategyDefinitionExists(final LockClusterStatement
sqlStatement) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
index 4ee362f793e..a205b294cd7 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
@@ -20,11 +20,11 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.check
import
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.junit.jupiter.api.Test;
import java.util.Collection;
@@ -55,7 +55,7 @@ public final class
DBDiscoveryRuleConfigurationImportCheckerTest {
public void assertCheckDiscoveryTypes() {
ShardingSphereDatabase database = mockDatabase();
DatabaseDiscoveryRuleConfiguration currentRuleConfig =
createRuleConfigWithInvalidDiscoveryType();
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
importChecker.check(database, currentRuleConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
importChecker.check(database, currentRuleConfig));
}
@Test
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
index 24d37c6c849..5cd3695c05e 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
@@ -17,10 +17,10 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.strategy.DynamicReadwriteSplittingStrategyConfiguration;
@@ -54,7 +54,7 @@ public final class
ReadwriteSplittingRuleConfigurationImportCheckerTest {
public void assertCheckLoadBalancers() {
ShardingSphereDatabase database = mockDatabase();
ReadwriteSplittingRuleConfiguration currentRuleConfig =
createInvalidLoadBalancerRuleConfig();
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
importChecker.check(database, currentRuleConfig));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
importChecker.check(database, currentRuleConfig));
}
private ShardingSphereDatabase mockDatabaseWithDataSource() {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
index 012eab1c299..eb61892cf8c 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
@@ -17,12 +17,12 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.junit.jupiter.api.Test;
@@ -53,12 +53,12 @@ public final class
ShardingRuleConfigurationImportCheckerTest {
@Test
public void assertCheckKeyGenerators() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () -> new
ShardingRuleConfigurationImportChecker().check(mockDatabase(),
createInvalidKeyGeneratorRuleConfiguration()));
+ assertThrows(ServiceProviderNotFoundServerException.class, () -> new
ShardingRuleConfigurationImportChecker().check(mockDatabase(),
createInvalidKeyGeneratorRuleConfiguration()));
}
@Test
public void assertCheckShardingAlgorithms() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () -> new
ShardingRuleConfigurationImportChecker().check(mockDatabase(),
createInvalidShardingAlgorithmRuleConfiguration()));
+ assertThrows(ServiceProviderNotFoundServerException.class, () -> new
ShardingRuleConfigurationImportChecker().check(mockDatabase(),
createInvalidShardingAlgorithmRuleConfiguration()));
}
private ShardingRuleConfiguration
createDuplicatedTablesRuleConfiguration() {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
index fd3f52ce574..231281eca9c 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.validate.DataSourcePropertiesValidateHandler;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ImportDatabaseConfigurationStatement;
@@ -29,6 +28,7 @@ import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.fixture.FixtureDataSourceContainedRule;
@@ -108,7 +108,7 @@ public final class ImportDatabaseConfigurationUpdaterTest {
@Test
public void assertImportInvalidAlgorithm() {
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
assertExecute("sharding_db", "/conf/import/config-invalid-algorithm.yaml"));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
assertExecute("sharding_db", "/conf/import/config-invalid-algorithm.yaml"));
}
private void assertExecute(final String databaseName, final String
filePath) throws SQLException {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdaterTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdaterTest.java
index 2b58d8d52e4..26a75bf3c5e 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdaterTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterUpdaterTest.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.LockClusterStatement;
import org.apache.shardingsphere.infra.state.cluster.ClusterState;
import
org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
@@ -65,6 +65,6 @@ public final class LockClusterUpdaterTest {
when(contextManager.getClusterStateContext().getCurrentState()).thenReturn(ClusterState.OK);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
LockClusterUpdater updater = new LockClusterUpdater();
- assertThrows(InvalidAlgorithmConfigurationException.class, () ->
updater.executeUpdate("foo", new LockClusterStatement(new
AlgorithmSegment("FOO", new Properties()))));
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
updater.executeUpdate("foo", new LockClusterStatement(new
AlgorithmSegment("FOO", new Properties()))));
}
}