You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/08/01 07:33:15 UTC
(shardingsphere) branch master updated: Refactor MCP algorithm discovery to use Proxy plugin catalogs (#39301)
This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 438eb61b906 Refactor MCP algorithm discovery to use Proxy plugin catalogs (#39301)
438eb61b906 is described below
commit 438eb61b9064bf509fc7903f4bfaf43240a52492
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Aug 1 15:33:09 2026 +0800
Refactor MCP algorithm discovery to use Proxy plugin catalogs (#39301)
* Add ProxyDatabaseTypeUtilsTest
* Refactor MCP algorithm discovery to use Proxy plugin catalogs
Remove compatibility fallback catalogs and WorkflowQueryResult.
Validate algorithms against the current Proxy and clarify recommendation
provenance and capability risks.
* Add more test cases on ClickHouseConnectionPropertiesParserTest
* Refactor MCP algorithm discovery to use Proxy plugin catalogs
Remove compatibility fallback catalogs and WorkflowQueryResult.
Validate algorithms against the current Proxy and clarify recommendation
provenance and capability risks.
---
.../ClickHouseConnectionPropertiesParserTest.java | 1 +
.../EncryptAlgorithmCompletionHandler.java | 2 +-
.../resource/handler/EncryptAlgorithmsHandler.java | 2 +-
.../tool/service/EncryptAlgorithmCatalog.java | 9 ---
.../EncryptAlgorithmPropertyTemplateService.java | 9 ---
.../EncryptAlgorithmRecommendationService.java | 78 +++++++++++---------
.../tool/service/EncryptRuleInspectionService.java | 20 +-----
.../service/EncryptWorkflowPlanningService.java | 3 +-
.../handler/EncryptAlgorithmsHandlerTest.java | 3 +-
.../tool/service/EncryptAlgorithmCatalogTest.java | 4 --
...ncryptAlgorithmPropertyTemplateServiceTest.java | 6 --
.../EncryptAlgorithmRecommendationServiceTest.java | 83 ++++++----------------
.../service/EncryptRuleInspectionServiceTest.java | 43 +++++------
.../EncryptWorkflowPlanningServiceTest.java | 9 ++-
.../completion/MaskAlgorithmCompletionHandler.java | 2 +-
.../resource/handler/MaskAlgorithmsHandler.java | 2 +-
.../MaskAlgorithmPropertyTemplateService.java | 9 ---
.../MaskAlgorithmRecommendationService.java | 11 ++-
.../tool/service/MaskRuleInspectionService.java | 18 +----
.../tool/service/MaskWorkflowPlanningService.java | 3 +-
.../handler/MaskAlgorithmsHandlerTest.java | 3 +-
.../MaskAlgorithmPropertyTemplateServiceTest.java | 7 --
.../MaskAlgorithmRecommendationServiceTest.java | 27 ++-----
.../service/MaskRuleInspectionServiceTest.java | 36 ++++------
.../service/MaskWorkflowPlanningServiceTest.java | 7 +-
...ttingLoadBalanceAlgorithmCompletionHandler.java | 2 +-
.../LoadBalanceAlgorithmPluginsHandler.java | 2 +-
...iteSplittingAlgorithmRecommendationService.java | 12 ++--
.../ReadwriteSplittingInspectionService.java | 19 +----
.../LoadBalanceAlgorithmPluginsHandlerTest.java | 3 +-
...plittingAlgorithmRecommendationServiceTest.java | 18 ++---
.../ReadwriteSplittingInspectionServiceTest.java | 29 +++-----
.../ShadowAlgorithmCompletionHandler.java | 2 +-
.../resource/handler/ShadowResourceHandler.java | 2 +-
.../ShadowAlgorithmRecommendationService.java | 12 ++--
.../tool/service/ShadowInspectionService.java | 19 +----
.../handler/ShadowResourceHandlerTest.java | 3 +-
.../ShadowAlgorithmRecommendationServiceTest.java | 18 ++---
.../tool/service/ShadowInspectionServiceTest.java | 30 +++-----
.../service/ShadowWorkflowPlanningServiceTest.java | 18 ++---
.../ShardingAlgorithmCompletionHandler.java | 4 +-
.../handler/ShardingAlgorithmResourceHandler.java | 4 +-
.../ShardingAlgorithmRecommendationService.java | 32 ++++-----
.../tool/service/ShardingInspectionService.java | 42 ++---------
.../ShardingAlgorithmResourceHandlerTest.java | 5 +-
...ShardingAlgorithmRecommendationServiceTest.java | 22 ++----
.../service/ShardingInspectionServiceTest.java | 52 ++++----------
.../workflow/model/WorkflowQueryResult.java | 56 ---------------
.../workflow/model/WorkflowQueryResultTest.java | 47 ------------
.../AbstractFunctionalityE2ETest.java | 4 ++
.../AbstractHttpProxyWorkflowE2ETest.java | 8 +--
.../functionality/AbstractMySQLRuntimeE2ETest.java | 52 --------------
.../AbstractTransportParameterizedE2ETest.java | 7 ++
.../HttpProxyMaskWorkflowE2ETest.java | 79 ++++++++++++++++++++
.../mcp/functionality/MySQLReadOnlySQLE2ETest.java | 36 ----------
55 files changed, 321 insertions(+), 715 deletions(-)
diff --git a/database/connector/dialect/clickhouse/src/test/java/org/apache/shardingsphere/database/connector/clickhouse/jdbcurl/ClickHouseConnectionPropertiesParserTest.java b/database/connector/dialect/clickhouse/src/test/java/org/apache/shardingsphere/database/connector/clickhouse/jdbcurl/ClickHouseConnectionPropertiesParserTest.java
index 81413dc09f5..8a55e7f59f4 100644
--- a/database/connector/dialect/clickhouse/src/test/java/org/apache/shardingsphere/database/connector/clickhouse/jdbcurl/ClickHouseConnectionPropertiesParserTest.java
+++ b/database/connector/dialect/clickhouse/src/test/java/org/apache/shardingsphere/database/connector/clickhouse/jdbcurl/ClickHouseConnectionPropertiesParserTest.java
@@ -65,6 +65,7 @@ class ClickHouseConnectionPropertiesParserTest {
@Override
public Stream<? extends Arguments> provideArguments(final ParameterDeclarations parameters, final ExtensionContext context) {
return Stream.of(
+ Arguments.of("service", "jdbc:clickhouse:http://127.0.0.1:8123/", "127.0.0.1", 8123, "", null, new Properties()),
Arguments.of("simple", "jdbc:ch://127.0.0.1/foo_ds", "127.0.0.1", 8123, "foo_ds", null, new Properties()),
Arguments.of("complex", "jdbc:clickhouse:http://127.0.0.1:9999/foo_ds?continueBatchOnError=true", "127.0.0.1", 9999, "foo_ds", null,
PropertiesBuilder.build(new Property("continueBatchOnError", "true"))));
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/completion/EncryptAlgorithmCompletionHandler.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/completion/EncryptAlgorithmCompletionHandler.java
index 9bbb672d220..f3700afe080 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/completion/EncryptAlgorithmCompletionHandler.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/completion/EncryptAlgorithmCompletionHandler.java
@@ -55,7 +55,7 @@ public final class EncryptAlgorithmCompletionHandler implements MCPCompletionHan
@Override
public MCPCompletionHandlerResult complete(final MCPFeatureRequestContext handlerContext, final MCPCompletionRequest request) {
- return new MCPCompletionHandlerResult(ruleInspectionService.queryEncryptAlgorithms(handlerContext.getQueryFacade()).getRows().stream()
+ return new MCPCompletionHandlerResult(ruleInspectionService.queryEncryptAlgorithms(handlerContext.getQueryFacade()).stream()
.map(this::createAlgorithmCandidate).filter(each -> !each.getValue().isEmpty()).toList());
}
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandler.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandler.java
index cf790eeb479..9f0cde1ffa9 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandler.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandler.java
@@ -46,7 +46,7 @@ public final class EncryptAlgorithmsHandler implements MCPResourceHandler<MCPFea
@Override
public MCPSuccessPayload handle(final MCPFeatureRequestContext requestContext, final MCPResourceURIVariables uriVariables) {
- return new MCPItemsPayload(ruleInspectionService.queryEncryptAlgorithms(requestContext.getQueryFacade()).getRows(),
+ return new MCPItemsPayload(ruleInspectionService.queryEncryptAlgorithms(requestContext.getQueryFacade()),
MCPResourceNavigationPayloadBuilder.create(MCPDescriptorCatalogIndex.getRequiredResourceDescriptor(getResourceUriTemplate()), uriVariables));
}
}
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalog.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalog.java
index 2fb4aa6f80c..89cb033b37e 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalog.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalog.java
@@ -70,15 +70,6 @@ public final class EncryptAlgorithmCatalog {
return null == definition ? List.of() : definition.createRequirements(algorithmRole);
}
- /**
- * Get supported fallback algorithm types.
- *
- * @return supported algorithm types
- */
- public static List<String> getSupportedAlgorithmTypes() {
- return new LinkedList<>(DEFINITIONS.keySet());
- }
-
private static String normalize(final String algorithmType) {
return Objects.toString(algorithmType, "").trim().toUpperCase(Locale.ENGLISH);
}
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateService.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateService.java
index 548504d14f2..9feb961559a 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateService.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateService.java
@@ -48,15 +48,6 @@ public final class EncryptAlgorithmPropertyTemplateService {
return result;
}
- /**
- * Get supported algorithm types.
- *
- * @return supported algorithm types
- */
- public List<String> getSupportedAlgorithmTypes() {
- return EncryptAlgorithmCatalog.getSupportedAlgorithmTypes();
- }
-
/**
* Mask properties for review.
*
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationService.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationService.java
index b5734562aa3..43cfed97eb1 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationService.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationService.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
import java.util.LinkedList;
@@ -39,48 +38,48 @@ public final class EncryptAlgorithmRecommendationService {
* Recommend encrypt algorithms.
*
* @param request workflow request
- * @param algorithmResult encrypt algorithm query result
+ * @param algorithms encrypt algorithms reported by the current Proxy
* @param issues workflow issues
* @return selected candidates
*/
public List<AlgorithmCandidate> recommendEncryptAlgorithms(final EncryptWorkflowRequest request,
- final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
+ final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
List<AlgorithmCandidate> result = new LinkedList<>();
- String primaryType = resolvePrimaryEncryptAlgorithm(request, algorithmResult, issues);
+ String primaryType = resolvePrimaryEncryptAlgorithm(request, algorithms, issues);
if (!primaryType.isEmpty()) {
result.add(createEncryptCandidate(EncryptFeatureDefinition.ALGORITHM_ROLE_PRIMARY, primaryType, request));
}
if (Boolean.TRUE.equals(request.getOptions().getRequiresEqualityFilter())) {
- addAssistedQueryCandidate(result, request, algorithmResult, issues);
+ addAssistedQueryCandidate(result, request, algorithms, issues);
}
if (Boolean.TRUE.equals(request.getOptions().getRequiresLikeQuery())) {
- addLikeQueryCandidate(result, request, algorithmResult, issues);
+ addLikeQueryCandidate(result, request, algorithms, issues);
}
return result;
}
- private String resolvePrimaryEncryptAlgorithm(final EncryptWorkflowRequest request, final WorkflowQueryResult algorithmResult,
+ private String resolvePrimaryEncryptAlgorithm(final EncryptWorkflowRequest request, final List<Map<String, Object>> algorithms,
final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getAlgorithmType());
if (!actualAlgorithmType.isEmpty()) {
- return resolveSpecifiedPrimaryEncryptAlgorithm(request, algorithmResult, issues, actualAlgorithmType);
+ return resolveSpecifiedPrimaryEncryptAlgorithm(request, algorithms, issues, actualAlgorithmType);
}
if (Boolean.TRUE.equals(request.getOptions().getRequiresLikeQuery())) {
- for (Map<String, Object> each : algorithmResult.getRows()) {
+ for (Map<String, Object> each : algorithms) {
if (Boolean.TRUE.equals(each.get(EncryptFeatureDefinition.ALGORITHM_CAPABILITY_LIKE))) {
return WorkflowAlgorithmUtils.getAlgorithmType(each);
}
}
}
- if (WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), "AES")) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(algorithms, "AES")) {
return "AES";
}
- return algorithmResult.getRows().isEmpty() ? "" : WorkflowAlgorithmUtils.getAlgorithmType(algorithmResult.getRows().getFirst());
+ return algorithms.isEmpty() ? "" : WorkflowAlgorithmUtils.getAlgorithmType(algorithms.getFirst());
}
- private String resolveSpecifiedPrimaryEncryptAlgorithm(final EncryptWorkflowRequest request, final WorkflowQueryResult algorithmResult,
+ private String resolveSpecifiedPrimaryEncryptAlgorithm(final EncryptWorkflowRequest request, final List<Map<String, Object>> algorithms,
final List<WorkflowIssue> issues, final String algorithmType) {
- if (algorithmResult.isAvailabilityConfirmed() && !WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), algorithmType)) {
+ if (!WorkflowAlgorithmUtils.containsAlgorithm(algorithms, algorithmType)) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
String.format("Encrypt algorithm `%s` is not visible from the current Proxy.", algorithmType), "Choose an available encrypt algorithm.", false, Map.of()));
return "";
@@ -95,8 +94,8 @@ public final class EncryptAlgorithmRecommendationService {
}
private void addAssistedQueryCandidate(final List<AlgorithmCandidate> candidates, final EncryptWorkflowRequest request,
- final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
- String assistedQueryType = resolveAssistedQueryAlgorithm(request, algorithmResult, issues);
+ final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
+ String assistedQueryType = resolveAssistedQueryAlgorithm(request, algorithms, issues);
if (assistedQueryType.isEmpty()) {
addCapabilityConflictIssue(issues, request.getOptions().getAssistedQueryAlgorithmType(),
"No assisted-query algorithm is available for the current requirement.", "Install or specify a supported assisted-query algorithm.");
@@ -107,8 +106,8 @@ public final class EncryptAlgorithmRecommendationService {
}
private void addLikeQueryCandidate(final List<AlgorithmCandidate> candidates, final EncryptWorkflowRequest request,
- final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
- String likeQueryType = resolveLikeQueryAlgorithm(request, algorithmResult, issues);
+ final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
+ String likeQueryType = resolveLikeQueryAlgorithm(request, algorithms, issues);
if (likeQueryType.isEmpty()) {
addCapabilityConflictIssue(issues, request.getOptions().getLikeQueryAlgorithmType(),
"No like-query algorithm is available for the current requirement.", "Install or specify a supported like-query algorithm.");
@@ -125,17 +124,17 @@ public final class EncryptAlgorithmRecommendationService {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM, message, userAction, false, Map.of()));
}
- private String resolveAssistedQueryAlgorithm(final EncryptWorkflowRequest request, final WorkflowQueryResult algorithmResult,
+ private String resolveAssistedQueryAlgorithm(final EncryptWorkflowRequest request, final List<Map<String, Object>> algorithms,
final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getOptions().getAssistedQueryAlgorithmType());
if (!actualAlgorithmType.isEmpty()) {
- return resolveSpecifiedAssistedQueryAlgorithm(algorithmResult, issues, actualAlgorithmType);
+ return resolveSpecifiedAssistedQueryAlgorithm(algorithms, issues, actualAlgorithmType);
}
- return WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), "MD5") ? "MD5" : "";
+ return WorkflowAlgorithmUtils.containsAlgorithm(algorithms, "MD5") ? "MD5" : "";
}
- private String resolveSpecifiedAssistedQueryAlgorithm(final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues, final String algorithmType) {
- if (algorithmResult.isAvailabilityConfirmed() && !WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), algorithmType)) {
+ private String resolveSpecifiedAssistedQueryAlgorithm(final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues, final String algorithmType) {
+ if (!WorkflowAlgorithmUtils.containsAlgorithm(algorithms, algorithmType)) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
String.format("Assisted-query algorithm `%s` is not visible from the current Proxy.", algorithmType),
"Choose an available assisted-query algorithm.", false, Map.of()));
@@ -144,13 +143,13 @@ public final class EncryptAlgorithmRecommendationService {
return algorithmType;
}
- private String resolveLikeQueryAlgorithm(final EncryptWorkflowRequest request, final WorkflowQueryResult algorithmResult,
+ private String resolveLikeQueryAlgorithm(final EncryptWorkflowRequest request, final List<Map<String, Object>> algorithms,
final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getOptions().getLikeQueryAlgorithmType());
if (!actualAlgorithmType.isEmpty()) {
- return resolveSpecifiedLikeQueryAlgorithm(algorithmResult, issues, actualAlgorithmType);
+ return resolveSpecifiedLikeQueryAlgorithm(algorithms, issues, actualAlgorithmType);
}
- for (Map<String, Object> each : algorithmResult.getRows()) {
+ for (Map<String, Object> each : algorithms) {
if (Boolean.TRUE.equals(each.get(EncryptFeatureDefinition.ALGORITHM_CAPABILITY_LIKE))) {
return WorkflowAlgorithmUtils.getAlgorithmType(each);
}
@@ -158,8 +157,8 @@ public final class EncryptAlgorithmRecommendationService {
return "";
}
- private String resolveSpecifiedLikeQueryAlgorithm(final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues, final String algorithmType) {
- if (algorithmResult.isAvailabilityConfirmed() && !WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), algorithmType)) {
+ private String resolveSpecifiedLikeQueryAlgorithm(final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues, final String algorithmType) {
+ if (!WorkflowAlgorithmUtils.containsAlgorithm(algorithms, algorithmType)) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
String.format("LIKE-query algorithm `%s` is not visible from the current Proxy.", algorithmType),
"Choose an available LIKE-query algorithm.", false, Map.of()));
@@ -209,22 +208,35 @@ public final class EncryptAlgorithmRecommendationService {
}
private String createEncryptReason(final String role, final String algorithmType, final EncryptWorkflowRequest request) {
+ String specifiedAlgorithmType;
+ if (EncryptFeatureDefinition.ALGORITHM_ROLE_PRIMARY.equals(role)) {
+ specifiedAlgorithmType = request.getAlgorithmType();
+ } else if (EncryptFeatureDefinition.ALGORITHM_ROLE_ASSISTED_QUERY.equals(role)) {
+ specifiedAlgorithmType = request.getOptions().getAssistedQueryAlgorithmType();
+ } else {
+ specifiedAlgorithmType = request.getOptions().getLikeQueryAlgorithmType();
+ }
+ if (!WorkflowAlgorithmUtils.normalizeAlgorithmType(specifiedAlgorithmType).isEmpty()) {
+ return "User specified algorithm.";
+ }
if (EncryptFeatureDefinition.ALGORITHM_ROLE_PRIMARY.equals(role) && "AES".equals(algorithmType)) {
return Boolean.TRUE.equals(request.getOptions().getRequiresDecrypt())
- ? "AES is preferred because decrypt support is required."
- : "AES is the default recommended encryptor.";
+ ? "AES is MCP's built-in default for decrypt support and is reported by the current Proxy."
+ : "AES is MCP's built-in default encryptor and is reported by the current Proxy.";
}
if (EncryptFeatureDefinition.ALGORITHM_ROLE_ASSISTED_QUERY.equals(role) && "MD5".equals(algorithmType)) {
- return "MD5 is recommended for assisted query support.";
+ return "MD5 is MCP's built-in assisted-query default and is reported by the current Proxy.";
}
if (EncryptFeatureDefinition.ALGORITHM_ROLE_LIKE_QUERY.equals(role)) {
- return "Selected as a like-query capable algorithm.";
+ return "Selected from algorithms reported by the current Proxy using the required LIKE-query capability.";
}
- return request.getAlgorithmType().isEmpty() ? "Recommended by current intent." : "User specified algorithm.";
+ return "Selected from algorithms reported by the current Proxy using the current workflow requirements.";
}
private String createEncryptRisk(final Map<String, Boolean> capability) {
- return capability.containsValue(null) ? "Capability is discoverable from plugins but not fully confirmed." : "";
+ return capability.containsValue(null)
+ ? "The algorithm is reported by the current Proxy, but its capabilities are not described by MCP's built-in metadata."
+ : "";
}
}
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionService.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionService.java
index 94efd197885..54d2a1299a3 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionService.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionService.java
@@ -17,11 +17,9 @@
package org.apache.shardingsphere.mcp.feature.encrypt.tool.service;
-import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.feature.encrypt.EncryptFeatureDefinition;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmPropertyRequirement;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowDistSQLQueryUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
@@ -67,10 +65,9 @@ public final class EncryptRuleInspectionService {
* @param queryFacade query facade
* @return encrypt algorithms
*/
- public WorkflowQueryResult queryEncryptAlgorithms(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult algorithmResult = queryAlgorithmRows(queryFacade);
+ public List<Map<String, Object>> queryEncryptAlgorithms(final MCPFeatureQueryFacade queryFacade) {
List<Map<String, Object>> result = new LinkedList<>();
- for (Map<String, Object> each : algorithmResult.getRows()) {
+ for (Map<String, Object> each : queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS")) {
String type = WorkflowAlgorithmUtils.getAlgorithmType(each);
Map<String, Boolean> capability = EncryptAlgorithmCatalog.findCapability(type);
List<AlgorithmPropertyRequirement> propertyTemplates = EncryptAlgorithmCatalog.findRequirements(EncryptFeatureDefinition.ALGORITHM_ROLE_PRIMARY, type);
@@ -85,17 +82,6 @@ public final class EncryptRuleInspectionService {
row.put("secret_properties", propertyTemplates.stream().filter(AlgorithmPropertyRequirement::isSecret).map(AlgorithmPropertyRequirement::getPropertyKey).toList());
result.add(row);
}
- return new WorkflowQueryResult(result, algorithmResult.isAvailabilityConfirmed());
- }
-
- private WorkflowQueryResult queryAlgorithmRows(final MCPFeatureQueryFacade queryFacade) {
- try {
- return WorkflowQueryResult.confirmed(queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS"));
- } catch (final MCPQueryFailedException ex) {
- if (WorkflowDistSQLQueryUtils.isUnsupportedDistSQLQueryFailure(ex)) {
- return WorkflowQueryResult.fallback(EncryptAlgorithmCatalog.getSupportedAlgorithmTypes().stream().map(each -> Map.<String, Object>of("type", each)).toList());
- }
- throw ex;
- }
+ return result;
}
}
diff --git a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningService.java b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningService.java
index 7c7bdcaaade..bbf14107d42 100644
--- a/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningService.java
+++ b/mcp/features/encrypt/src/main/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningService.java
@@ -32,7 +32,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowFieldNames;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowPlanningSupport;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowRuleValueUtils;
@@ -201,7 +200,7 @@ public final class EncryptWorkflowPlanningService {
}
private void planAlgorithms(final MCPFeatureQueryFacade queryFacade, final EncryptWorkflowRequest request, final WorkflowContextSnapshot snapshot) {
- WorkflowQueryResult encryptAlgorithms = ruleInspectionService.queryEncryptAlgorithms(queryFacade);
+ List<Map<String, Object>> encryptAlgorithms = ruleInspectionService.queryEncryptAlgorithms(queryFacade);
List<AlgorithmCandidate> algorithmCandidates = algorithmRecommendationService.recommendEncryptAlgorithms(request, encryptAlgorithms, snapshot.getIssues());
snapshot.getAlgorithmCandidates().addAll(algorithmCandidates);
applyRecommendedAlgorithms(request, algorithmCandidates);
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandlerTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandlerTest.java
index ed4a9b9145d..4657b1b5f35 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandlerTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/resource/handler/EncryptAlgorithmsHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceURIVaria
import org.apache.shardingsphere.mcp.feature.encrypt.tool.service.EncryptRuleInspectionService;
import org.apache.shardingsphere.mcp.support.MCPFeatureRequestContext;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
@@ -46,7 +45,7 @@ class EncryptAlgorithmsHandlerTest {
when(requestContext.getQueryFacade()).thenReturn(queryFacade);
try (
MockedConstruction<EncryptRuleInspectionService> mockedConstruction = mockConstruction(EncryptRuleInspectionService.class,
- (mock, context) -> when(mock.queryEncryptAlgorithms(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "AES")))))) {
+ (mock, context) -> when(mock.queryEncryptAlgorithms(queryFacade)).thenReturn(List.of(Map.of("type", "AES"))))) {
MCPSuccessPayload actual = new EncryptAlgorithmsHandler().handle(requestContext, new MCPResourceURIVariables(Map.of()));
verify(mockedConstruction.constructed().getFirst()).queryEncryptAlgorithms(queryFacade);
assertThat(((Collection<?>) actual.toPayload().get("items")).size(), is(1));
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalogTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalogTest.java
index f3a85ad94c8..3fcfac2189b 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalogTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmCatalogTest.java
@@ -74,8 +74,4 @@ class EncryptAlgorithmCatalogTest {
assertTrue(actual.isEmpty());
}
- @Test
- void assertGetSupportedAlgorithmTypes() {
- assertThat(EncryptAlgorithmCatalog.getSupportedAlgorithmTypes(), is(List.of("AES", "MD5")));
- }
}
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateServiceTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateServiceTest.java
index e2d6c84ea7b..65314c985eb 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateServiceTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmPropertyTemplateServiceTest.java
@@ -47,12 +47,6 @@ class EncryptAlgorithmPropertyTemplateServiceTest {
assertTrue(actual.isEmpty());
}
- @Test
- void assertGetSupportedAlgorithmTypes() {
- List<String> actual = service.getSupportedAlgorithmTypes();
- assertThat(actual, is(List.of("AES", "MD5")));
- }
-
@Test
void assertMaskProperties() {
List<AlgorithmPropertyRequirement> requirements = List.of(
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationServiceTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationServiceTest.java
index a5d27126caf..1b8660b94ad 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationServiceTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptAlgorithmRecommendationServiceTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.mcp.feature.encrypt.tool.model.EncryptWorkflowR
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
@@ -31,7 +30,6 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class EncryptAlgorithmRecommendationServiceTest {
@@ -44,10 +42,11 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresDecrypt(true);
request.setAlgorithmType("AES");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(actual.getFirst().getAlgorithmRole(), is("primary"));
assertThat(actual.getFirst().getAlgorithmType(), is("AES"));
+ assertThat(actual.getFirst().getRecommendationReason(), is("User specified algorithm."));
assertTrue(issues.isEmpty());
}
@@ -57,7 +56,7 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresDecrypt(true);
request.setAlgorithmType("MD5");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("MD5", false, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("MD5", false, true, false)), issues);
assertTrue(actual.isEmpty());
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT));
}
@@ -67,7 +66,7 @@ class EncryptAlgorithmRecommendationServiceTest {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.setAlgorithmType("SM4");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertTrue(actual.isEmpty());
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
@@ -75,16 +74,16 @@ class EncryptAlgorithmRecommendationServiceTest {
@Test
void assertRecommendEncryptAlgorithmsWithoutAvailableAlgorithm() {
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(new EncryptWorkflowRequest(), WorkflowQueryResult.confirmed(List.of()), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(new EncryptWorkflowRequest(), List.of(), issues);
assertTrue(actual.isEmpty());
assertTrue(issues.isEmpty());
}
@Test
- void assertRecommendEncryptAlgorithmsFallsBackToFirstAvailableAlgorithm() {
+ void assertRecommendEncryptAlgorithmsUsesFirstAvailableAlgorithm() {
List<WorkflowIssue> issues = new LinkedList<>();
List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(
- new EncryptWorkflowRequest(), confirmed(createAlgorithmRow("FPE", null, null, null)), issues);
+ new EncryptWorkflowRequest(), List.of(createAlgorithmRow("FPE", null, null, null)), issues);
assertThat(actual.getFirst().getAlgorithmType(), is("FPE"));
assertTrue(issues.isEmpty());
}
@@ -94,7 +93,7 @@ class EncryptAlgorithmRecommendationServiceTest {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.getOptions().setRequiresEqualityFilter(true);
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(actual.getFirst().getAlgorithmType(), is("AES"));
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT));
@@ -105,7 +104,7 @@ class EncryptAlgorithmRecommendationServiceTest {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.getOptions().setRequiresEqualityFilter(true);
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(
createAlgorithmRow("AES", true, true, false), createAlgorithmRow("MD5", false, true, false)), issues);
assertThat(actual.size(), is(2));
assertThat(actual.get(1).getAlgorithmRole(), is("assisted_query"));
@@ -119,7 +118,7 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresEqualityFilter(true);
request.getOptions().setAssistedQueryAlgorithmType("CUSTOM_HASH");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(
createAlgorithmRow("AES", true, true, false), createAlgorithmRow("CUSTOM_HASH", null, true, false)), issues);
assertThat(actual.size(), is(2));
assertThat(actual.get(1).getAlgorithmType(), is("CUSTOM_HASH"));
@@ -132,20 +131,21 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresEqualityFilter(true);
request.getOptions().setAssistedQueryAlgorithmType("MD5");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(issues.size(), is(1));
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
@Test
- void assertRecommendEncryptAlgorithmsWithUnconfirmedCapability() {
+ void assertRecommendEncryptAlgorithmsWithUnknownCapabilityMetadata() {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.setAlgorithmType("FPE");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("FPE", null, null, null)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("FPE", null, null, null)), issues);
assertThat(actual.size(), is(1));
- assertFalse(actual.getFirst().getRiskNotes().isEmpty());
+ assertThat(actual.getFirst().getRiskNotes(), is(
+ "The algorithm is reported by the current Proxy, but its capabilities are not described by MCP's built-in metadata."));
assertTrue(issues.isEmpty());
}
@@ -154,7 +154,7 @@ class EncryptAlgorithmRecommendationServiceTest {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.getOptions().setRequiresLikeQuery(true);
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(
createAlgorithmRow("AES", true, true, false),
createAlgorithmRow("FPE", null, null, true)), issues);
assertThat(actual.size(), is(2));
@@ -170,7 +170,7 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresLikeQuery(true);
request.getOptions().setLikeQueryAlgorithmType("AES");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT));
}
@@ -180,7 +180,7 @@ class EncryptAlgorithmRecommendationServiceTest {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.getOptions().setRequiresLikeQuery(true);
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT));
}
@@ -191,19 +191,19 @@ class EncryptAlgorithmRecommendationServiceTest {
request.getOptions().setRequiresLikeQuery(true);
request.getOptions().setLikeQueryAlgorithmType("FPE");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(createAlgorithmRow("AES", true, true, false)), issues);
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(createAlgorithmRow("AES", true, true, false)), issues);
assertThat(actual.size(), is(1));
assertThat(issues.size(), is(1));
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
@Test
- void assertRecommendEncryptAlgorithmsWithSpecifiedUnconfirmedLikeAlgorithm() {
+ void assertRecommendEncryptAlgorithmsWithSpecifiedLikeAlgorithmAndUnknownCapabilityMetadata() {
EncryptWorkflowRequest request = new EncryptWorkflowRequest();
request.getOptions().setRequiresLikeQuery(true);
request.getOptions().setLikeQueryAlgorithmType("FPE");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, List.of(
createAlgorithmRow("AES", true, true, false), createAlgorithmRow("FPE", null, null, true)), issues);
assertThat(actual.size(), is(2));
assertThat(actual.get(1).getAlgorithmType(), is("FPE"));
@@ -211,47 +211,6 @@ class EncryptAlgorithmRecommendationServiceTest {
assertTrue(issues.isEmpty());
}
- @Test
- void assertRecommendEncryptAlgorithmsWithUnconfirmedAvailability() {
- EncryptWorkflowRequest request = new EncryptWorkflowRequest();
- request.setAlgorithmType("CUSTOM");
- List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(request, WorkflowQueryResult.fallback(List.of()), issues);
- assertThat(actual.getFirst().getAlgorithmType(), is("CUSTOM"));
- assertTrue(issues.isEmpty());
- }
-
- @Test
- void assertRecommendAssistedQueryAlgorithmWithUnconfirmedAvailability() {
- EncryptWorkflowRequest request = new EncryptWorkflowRequest();
- request.setAlgorithmType("AES");
- request.getOptions().setRequiresEqualityFilter(true);
- request.getOptions().setAssistedQueryAlgorithmType("CUSTOM_HASH");
- List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(
- request, WorkflowQueryResult.fallback(List.of(createAlgorithmRow("AES", true, true, false))), issues);
- assertThat(actual.get(1).getAlgorithmType(), is("CUSTOM_HASH"));
- assertTrue(issues.isEmpty());
- }
-
- @Test
- void assertRecommendLikeQueryAlgorithmWithUnconfirmedAvailability() {
- EncryptWorkflowRequest request = new EncryptWorkflowRequest();
- request.setAlgorithmType("AES");
- request.getOptions().setRequiresLikeQuery(true);
- request.getOptions().setLikeQueryAlgorithmType("CUSTOM_LIKE");
- List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendEncryptAlgorithms(
- request, WorkflowQueryResult.fallback(List.of(createAlgorithmRow("AES", true, true, false))), issues);
- assertThat(actual.get(1).getAlgorithmType(), is("CUSTOM_LIKE"));
- assertTrue(issues.isEmpty());
- }
-
- @SafeVarargs
- private WorkflowQueryResult confirmed(final Map<String, Object>... rows) {
- return WorkflowQueryResult.confirmed(List.of(rows));
- }
-
private Map<String, Object> createAlgorithmRow(final String type, final Boolean decrypt, final Boolean equivalentFilter, final Boolean like) {
Map<String, Object> result = new LinkedHashMap<>(4, 1F);
result.put("type", type);
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionServiceTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionServiceTest.java
index 2554f2dd1f8..b1c25a05d85 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionServiceTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptRuleInspectionServiceTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.mcp.feature.encrypt.tool.service;
import org.apache.shardingsphere.mcp.api.exception.MCPInvalidRequestException;
import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
@@ -103,37 +102,27 @@ class EncryptRuleInspectionServiceTest {
void assertQueryEncryptAlgorithms() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "AES"), Map.of("type", "CUSTOM")));
- WorkflowQueryResult actual = service.queryEncryptAlgorithms(queryFacade);
- assertTrue((Boolean) actual.getRows().getFirst().get("supports_decrypt"));
- assertTrue((Boolean) actual.getRows().getFirst().get("capability_confirmed"));
- assertThat(actual.getRows().getFirst().get("required_properties"), is(List.of("aes-key-value")));
- assertThat(actual.getRows().getFirst().get("optional_properties"), is(List.of("digest-algorithm-name")));
- assertThat(actual.getRows().getFirst().get("secret_properties"), is(List.of("aes-key-value")));
- List<?> propertyTemplates = (List<?>) actual.getRows().getFirst().get("property_templates");
+ List<Map<String, Object>> actual = service.queryEncryptAlgorithms(queryFacade);
+ assertTrue((Boolean) actual.getFirst().get("supports_decrypt"));
+ assertTrue((Boolean) actual.getFirst().get("capability_confirmed"));
+ assertThat(actual.getFirst().get("required_properties"), is(List.of("aes-key-value")));
+ assertThat(actual.getFirst().get("optional_properties"), is(List.of("digest-algorithm-name")));
+ assertThat(actual.getFirst().get("secret_properties"), is(List.of("aes-key-value")));
+ List<?> propertyTemplates = (List<?>) actual.getFirst().get("property_templates");
assertThat(((Map<?, ?>) propertyTemplates.getFirst()).get("property_key"), is("aes-key-value"));
- assertThat(actual.getRows().get(1).get("type"), is("CUSTOM"));
- assertNull(actual.getRows().get(1).get("supports_like"));
- assertFalse((Boolean) actual.getRows().get(1).get("capability_confirmed"));
- assertThat(actual.getRows().get(1).get("property_templates"), is(List.of()));
- assertTrue(actual.isAvailabilityConfirmed());
+ assertThat(actual.get(1).get("type"), is("CUSTOM"));
+ assertNull(actual.get(1).get("supports_like"));
+ assertFalse((Boolean) actual.get(1).get("capability_confirmed"));
+ assertThat(actual.get(1).get("property_templates"), is(List.of()));
}
@Test
void assertQueryEncryptAlgorithmsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'ENCRYPT ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = service.queryEncryptAlgorithms(queryFacade);
- assertThat(actual.getRows().getFirst().get("type"), is("AES"));
- assertThat(actual.getRows().getFirst().get("required_properties"), is(List.of("aes-key-value")));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryEncryptAlgorithmsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> service.queryEncryptAlgorithms(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'ENCRYPT ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW ENCRYPT ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(MCPQueryFailedException.class, () -> service.queryEncryptAlgorithms(queryFacade));
+ assertThat(actual, is(expected));
}
}
diff --git a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningServiceTest.java b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningServiceTest.java
index 3205f76020e..b0c0cf30cb2 100644
--- a/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningServiceTest.java
+++ b/mcp/features/encrypt/src/test/java/org/apache/shardingsphere/mcp/feature/encrypt/tool/service/EncryptWorkflowPlanningServiceTest.java
@@ -41,7 +41,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowContextSnaps
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowFieldNames;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowPlanPayloadBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -156,7 +155,7 @@ class EncryptWorkflowPlanningServiceTest {
final String expectedOperationType, final String expectedFieldSemantics, final String expectedStatus) {
EncryptRuleInspectionService ruleInspectionService = mock(EncryptRuleInspectionService.class);
when(ruleInspectionService.queryEncryptRules(any(), any(), any())).thenReturn(ruleExists ? List.of(Map.of("logic_column", "phone")) : List.of());
- when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "AES", "supports_like", false))));
+ when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(List.of(Map.of("type", "AES", "supports_like", false)));
EncryptWorkflowRequest request = createNaturalLanguageRequest(naturalLanguageIntent);
request.getOptions().setCipherColumnName("phone_cipher");
request.getPrimaryAlgorithmProperties().put("aes-key-value", "123456");
@@ -174,7 +173,7 @@ class EncryptWorkflowPlanningServiceTest {
void assertPlanStopsOnBlockingAlgorithmIssue() {
EncryptRuleInspectionService ruleInspectionService = mock(EncryptRuleInspectionService.class);
when(ruleInspectionService.queryEncryptRules(any(), any(), any())).thenReturn(List.of());
- when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of()));
+ when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(List.of());
EncryptAlgorithmRecommendationService algorithmRecommendationService = mock(EncryptAlgorithmRecommendationService.class);
when(algorithmRecommendationService.recommendEncryptAlgorithms(any(), any(), any())).thenAnswer(invocation -> {
List<WorkflowIssue> issues = invocation.getArgument(2);
@@ -214,9 +213,9 @@ class EncryptWorkflowPlanningServiceTest {
void assertPlanDoesNotApplyLikeQueryCandidateWithoutExplicitInput() {
EncryptRuleInspectionService ruleInspectionService = mock(EncryptRuleInspectionService.class);
when(ruleInspectionService.queryEncryptRules(any(), any(), any())).thenReturn(List.of());
- when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of(
+ when(ruleInspectionService.queryEncryptAlgorithms(any())).thenReturn(List.of(
Map.of("type", "AES", "supports_like", false),
- Map.of("type", "FPE", "supports_like", true))));
+ Map.of("type", "FPE", "supports_like", true)));
EncryptAlgorithmPropertyTemplateService propertyTemplateService = mock(EncryptAlgorithmPropertyTemplateService.class);
when(propertyTemplateService.findRequirements(any(), any(), any())).thenReturn(List.of());
EncryptWorkflowRequest request = createRequest("create");
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/completion/MaskAlgorithmCompletionHandler.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/completion/MaskAlgorithmCompletionHandler.java
index 8bb4d5ecfa2..757bbd9a242 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/completion/MaskAlgorithmCompletionHandler.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/completion/MaskAlgorithmCompletionHandler.java
@@ -52,7 +52,7 @@ public final class MaskAlgorithmCompletionHandler implements MCPCompletionHandle
@Override
public MCPCompletionHandlerResult complete(final MCPFeatureRequestContext handlerContext, final MCPCompletionRequest request) {
- return new MCPCompletionHandlerResult(ruleInspectionService.queryMaskAlgorithms(handlerContext.getQueryFacade()).getRows().stream()
+ return new MCPCompletionHandlerResult(ruleInspectionService.queryMaskAlgorithms(handlerContext.getQueryFacade()).stream()
.map(this::createAlgorithmCandidate).filter(each -> !each.getValue().isEmpty()).toList());
}
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandler.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandler.java
index d0197c4c37a..94099e45fb7 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandler.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandler.java
@@ -46,7 +46,7 @@ public final class MaskAlgorithmsHandler implements MCPResourceHandler<MCPFeatur
@Override
public MCPSuccessPayload handle(final MCPFeatureRequestContext requestContext, final MCPResourceURIVariables uriVariables) {
- return new MCPItemsPayload(ruleInspectionService.queryMaskAlgorithms(requestContext.getQueryFacade()).getRows(),
+ return new MCPItemsPayload(ruleInspectionService.queryMaskAlgorithms(requestContext.getQueryFacade()),
MCPResourceNavigationPayloadBuilder.create(MCPDescriptorCatalogIndex.getRequiredResourceDescriptor(getResourceUriTemplate()), uriVariables));
}
}
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateService.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateService.java
index f5653937481..3fae5ef343e 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateService.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateService.java
@@ -52,15 +52,6 @@ public final class MaskAlgorithmPropertyTemplateService {
return result;
}
- /**
- * Get supported algorithm types.
- *
- * @return supported algorithm types
- */
- public List<String> getSupportedAlgorithmTypes() {
- return new LinkedList<>(MASK_TEMPLATES.keySet());
- }
-
/**
* Mask properties for review.
*
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationService.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationService.java
index 49e9be072ba..d29ce9df242 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationService.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationService.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.ClarifiedIntent;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
@@ -40,15 +39,15 @@ public final class MaskAlgorithmRecommendationService {
*
* @param intent clarified intent
* @param request workflow request
- * @param algorithmResult mask algorithm query result
+ * @param algorithms mask algorithms reported by the current Proxy
* @param issues workflow issues
* @return selected candidates
*/
public List<AlgorithmCandidate> recommendMaskAlgorithms(final ClarifiedIntent intent, final WorkflowRequest request,
- final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
+ final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getAlgorithmType());
if (!actualAlgorithmType.isEmpty()) {
- if (!algorithmResult.isAvailabilityConfirmed() || WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), actualAlgorithmType)) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(algorithms, actualAlgorithmType)) {
return List.of(AlgorithmCandidate.builder().algorithmRole("primary").algorithmType(actualAlgorithmType).recommendationScore(100)
.recommendationReason("User specified algorithm.").riskNotes("").build());
}
@@ -56,14 +55,14 @@ public final class MaskAlgorithmRecommendationService {
String.format("Mask algorithm `%s` is not visible from the current Proxy.", actualAlgorithmType), "Choose an available mask algorithm.", false, Map.of()));
return List.of();
}
- String recommendedType = resolveRecommendedAlgorithm(intent, request, algorithmResult.getRows());
+ String recommendedType = resolveRecommendedAlgorithm(intent, request, algorithms);
if (recommendedType.isEmpty()) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
"No mask algorithm is available from the current Proxy.", "Install or register at least one visible mask algorithm.", false, Map.of()));
return List.of();
}
return List.of(AlgorithmCandidate.builder().algorithmRole("primary").algorithmType(recommendedType).recommendationScore(100)
- .recommendationReason("Recommended by field semantics and current algorithm availability.").riskNotes("").build());
+ .recommendationReason("Selected from algorithms reported by the current Proxy using field semantics and MCP's built-in mask defaults.").riskNotes("").build());
}
private String resolveRecommendedAlgorithm(final ClarifiedIntent intent, final WorkflowRequest request, final List<Map<String, Object>> maskAlgorithms) {
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionService.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionService.java
index 79cbc641b60..42286ea0426 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionService.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionService.java
@@ -17,10 +17,8 @@
package org.apache.shardingsphere.mcp.feature.mask.tool.service;
-import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmPropertyRequirement;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowDistSQLQueryUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
@@ -67,20 +65,8 @@ public final class MaskRuleInspectionService {
* @param queryFacade query facade
* @return mask algorithms
*/
- public WorkflowQueryResult queryMaskAlgorithms(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult result = queryAlgorithmRows(queryFacade);
- return new WorkflowQueryResult(decorateMaskAlgorithms(result.getRows()), result.isAvailabilityConfirmed());
- }
-
- private WorkflowQueryResult queryAlgorithmRows(final MCPFeatureQueryFacade queryFacade) {
- try {
- return WorkflowQueryResult.confirmed(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS"));
- } catch (final MCPQueryFailedException ex) {
- if (WorkflowDistSQLQueryUtils.isUnsupportedDistSQLQueryFailure(ex)) {
- return WorkflowQueryResult.fallback(propertyTemplateService.getSupportedAlgorithmTypes().stream().map(each -> Map.<String, Object>of("type", each)).toList());
- }
- throw ex;
- }
+ public List<Map<String, Object>> queryMaskAlgorithms(final MCPFeatureQueryFacade queryFacade) {
+ return decorateMaskAlgorithms(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS"));
}
private List<Map<String, Object>> decorateMaskAlgorithms(final List<Map<String, Object>> maskAlgorithms) {
diff --git a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningService.java b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningService.java
index 6d4f9ee8983..74d5f1ce359 100644
--- a/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningService.java
+++ b/mcp/features/mask/src/main/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningService.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowContextSnaps
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowPlanningSupport;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowRuleValueUtils;
@@ -171,7 +170,7 @@ public final class MaskWorkflowPlanningService {
}
private void planAlgorithms(final MCPFeatureQueryFacade queryFacade, final ClarifiedIntent clarifiedIntent, final WorkflowRequest request, final WorkflowContextSnapshot snapshot) {
- WorkflowQueryResult maskAlgorithms = ruleInspectionService.queryMaskAlgorithms(queryFacade);
+ List<Map<String, Object>> maskAlgorithms = ruleInspectionService.queryMaskAlgorithms(queryFacade);
List<AlgorithmCandidate> algorithmCandidates = algorithmRecommendationService.recommendMaskAlgorithms(clarifiedIntent, request, maskAlgorithms, snapshot.getIssues());
snapshot.getAlgorithmCandidates().addAll(algorithmCandidates);
if (!algorithmCandidates.isEmpty()) {
diff --git a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandlerTest.java b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandlerTest.java
index 6a5b6efeb7c..757e1f844e4 100644
--- a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandlerTest.java
+++ b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/resource/handler/MaskAlgorithmsHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceURIVaria
import org.apache.shardingsphere.mcp.feature.mask.tool.service.MaskRuleInspectionService;
import org.apache.shardingsphere.mcp.support.MCPFeatureRequestContext;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
@@ -46,7 +45,7 @@ class MaskAlgorithmsHandlerTest {
when(requestContext.getQueryFacade()).thenReturn(queryFacade);
try (
MockedConstruction<MaskRuleInspectionService> mockedConstruction = mockConstruction(MaskRuleInspectionService.class,
- (mock, context) -> when(mock.queryMaskAlgorithms(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "MD5")))))) {
+ (mock, context) -> when(mock.queryMaskAlgorithms(queryFacade)).thenReturn(List.of(Map.of("type", "MD5"))))) {
MCPSuccessPayload actual = new MaskAlgorithmsHandler().handle(requestContext, new MCPResourceURIVariables(Map.of()));
verify(mockedConstruction.constructed().getFirst()).queryMaskAlgorithms(queryFacade);
assertThat(((Collection<?>) actual.toPayload().get("items")).size(), is(1));
diff --git a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateServiceTest.java b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateServiceTest.java
index c908269a4f9..cbca6874100 100644
--- a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateServiceTest.java
+++ b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmPropertyTemplateServiceTest.java
@@ -52,13 +52,6 @@ class MaskAlgorithmPropertyTemplateServiceTest {
assertTrue(actual.isEmpty());
}
- @Test
- void assertGetSupportedAlgorithmTypes() {
- List<String> actual = service.getSupportedAlgorithmTypes();
- assertThat(actual, is(List.of("KEEP_FIRST_N_LAST_M", "KEEP_FROM_X_TO_Y", "MASK_FIRST_N_LAST_M", "MASK_FROM_X_TO_Y",
- "MASK_AFTER_SPECIAL_CHARS", "MASK_BEFORE_SPECIAL_CHARS", "GENERIC_TABLE_RANDOM_REPLACE", "MD5")));
- }
-
@Test
void assertMaskProperties() {
List<AlgorithmPropertyRequirement> requirements = List.of(
diff --git a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationServiceTest.java b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationServiceTest.java
index 46b210c716a..de2761f563d 100644
--- a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationServiceTest.java
+++ b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskAlgorithmRecommendationServiceTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.ClarifiedIntent;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.junit.jupiter.api.Test;
@@ -42,7 +41,7 @@ class MaskAlgorithmRecommendationServiceTest {
WorkflowRequest request = new WorkflowRequest();
request.setAlgorithmType("MD5");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(new ClarifiedIntent(), request, confirmed(Map.of("type", "MD5")), issues);
+ List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(new ClarifiedIntent(), request, List.of(Map.of("type", "MD5")), issues);
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getAlgorithmType(), is("MD5"));
assertTrue(issues.isEmpty());
@@ -53,7 +52,7 @@ class MaskAlgorithmRecommendationServiceTest {
WorkflowRequest request = new WorkflowRequest();
request.setAlgorithmType("CUSTOM");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(new ClarifiedIntent(), request, confirmed(Map.of("type", "MD5")), issues);
+ List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(new ClarifiedIntent(), request, List.of(Map.of("type", "MD5")), issues);
assertTrue(actual.isEmpty());
assertThat(issues.get(0).getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
@@ -64,11 +63,13 @@ class MaskAlgorithmRecommendationServiceTest {
clarifiedIntent.setFieldSemantics("phone");
WorkflowRequest request = new WorkflowRequest();
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(clarifiedIntent, request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(clarifiedIntent, request, List.of(
Map.of("type", "MASK_FROM_X_TO_Y"),
Map.of("type", "KEEP_FIRST_N_LAST_M")), issues);
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getAlgorithmType(), is("MASK_FROM_X_TO_Y"));
+ assertThat(actual.get(0).getRecommendationReason(), is(
+ "Selected from algorithms reported by the current Proxy using field semantics and MCP's built-in mask defaults."));
}
@Test
@@ -77,7 +78,7 @@ class MaskAlgorithmRecommendationServiceTest {
WorkflowRequest request = new WorkflowRequest();
request.setNaturalLanguageIntent("保留前3后4位");
List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(clarifiedIntent, request, confirmed(
+ List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(clarifiedIntent, request, List.of(
Map.of("type", "MASK_FROM_X_TO_Y"),
Map.of("type", "KEEP_FIRST_N_LAST_M")), issues);
assertThat(actual.size(), is(1));
@@ -88,23 +89,9 @@ class MaskAlgorithmRecommendationServiceTest {
void assertRecommendMaskAlgorithmsWithoutAvailableAlgorithms() {
List<WorkflowIssue> issues = new LinkedList<>();
List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(
- new ClarifiedIntent(), new WorkflowRequest(), WorkflowQueryResult.confirmed(List.of()), issues);
+ new ClarifiedIntent(), new WorkflowRequest(), List.of(), issues);
assertTrue(actual.isEmpty());
assertThat(issues.get(0).getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
- @Test
- void assertRecommendMaskAlgorithmsWithUnconfirmedAvailability() {
- WorkflowRequest request = new WorkflowRequest();
- request.setAlgorithmType("CUSTOM");
- List<WorkflowIssue> issues = new LinkedList<>();
- List<AlgorithmCandidate> actual = service.recommendMaskAlgorithms(new ClarifiedIntent(), request, WorkflowQueryResult.fallback(List.of()), issues);
- assertThat(actual.getFirst().getAlgorithmType(), is("CUSTOM"));
- assertTrue(issues.isEmpty());
- }
-
- @SafeVarargs
- private WorkflowQueryResult confirmed(final Map<String, Object>... rows) {
- return WorkflowQueryResult.confirmed(List.of(rows));
- }
}
diff --git a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionServiceTest.java b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionServiceTest.java
index 5a6251016c5..e06a10e9d2c 100644
--- a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionServiceTest.java
+++ b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskRuleInspectionServiceTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.mcp.feature.mask.tool.service;
import org.apache.shardingsphere.mcp.api.exception.MCPInvalidRequestException;
import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
@@ -30,7 +29,6 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
@@ -104,33 +102,23 @@ class MaskRuleInspectionServiceTest {
void assertQueryMaskAlgorithms() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "MASK_FROM_X_TO_Y"), Map.of("type", "CUSTOM")));
- WorkflowQueryResult actual = service.queryMaskAlgorithms(queryFacade);
- assertThat(actual.getRows().getFirst().get("type"), is("MASK_FROM_X_TO_Y"));
- assertThat(actual.getRows().getFirst().get("required_properties"), is(List.of("from-x", "to-y", "replace-char")));
- assertThat(actual.getRows().getFirst().get("optional_properties"), is(List.of()));
- List<?> propertyTemplates = (List<?>) actual.getRows().getFirst().get("property_templates");
+ List<Map<String, Object>> actual = service.queryMaskAlgorithms(queryFacade);
+ assertThat(actual.getFirst().get("type"), is("MASK_FROM_X_TO_Y"));
+ assertThat(actual.getFirst().get("required_properties"), is(List.of("from-x", "to-y", "replace-char")));
+ assertThat(actual.getFirst().get("optional_properties"), is(List.of()));
+ List<?> propertyTemplates = (List<?>) actual.getFirst().get("property_templates");
assertThat(((Map<?, ?>) propertyTemplates.getFirst()).get("property_key"), is("from-x"));
- assertThat(actual.getRows().get(1).get("type"), is("CUSTOM"));
- assertThat(actual.getRows().get(1).get("property_templates"), is(List.of()));
- assertTrue(actual.isAvailabilityConfirmed());
+ assertThat(actual.get(1).get("type"), is("CUSTOM"));
+ assertThat(actual.get(1).get("property_templates"), is(List.of()));
}
@Test
void assertQueryMaskAlgorithmsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'MASK ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = service.queryMaskAlgorithms(queryFacade);
- assertThat(actual.getRows().getFirst().get("type"), is("KEEP_FIRST_N_LAST_M"));
- assertThat(actual.getRows().getFirst().get("required_properties"), is(List.of("first-n", "last-m", "replace-char")));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryMaskAlgorithmsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> service.queryMaskAlgorithms(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'MASK ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW MASK ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(MCPQueryFailedException.class, () -> service.queryMaskAlgorithms(queryFacade));
+ assertThat(actual, is(expected));
}
}
diff --git a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningServiceTest.java b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningServiceTest.java
index 2f34f988112..363de26165c 100644
--- a/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningServiceTest.java
+++ b/mcp/features/mask/src/test/java/org/apache/shardingsphere/mcp/feature/mask/tool/service/MaskWorkflowPlanningServiceTest.java
@@ -41,7 +41,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowContextSnaps
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowFieldNames;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowPlanPayloadBuilder;
import org.junit.jupiter.api.AfterEach;
@@ -141,7 +140,7 @@ class MaskWorkflowPlanningServiceTest {
void assertPlanRejectsAddingColumnToExistingTableRule() {
MaskRuleInspectionService ruleInspectionService = mock(MaskRuleInspectionService.class);
when(ruleInspectionService.queryMaskRules(any(), any(), any())).thenReturn(List.of(Map.of("column", "phone", "algorithm_type", "MD5")));
- when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of()));
+ when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(List.of());
WorkflowRequest request = createRequest("create");
request.setColumn("amount");
request.getPrimaryAlgorithmProperties().put("from-x", "1");
@@ -201,7 +200,7 @@ class MaskWorkflowPlanningServiceTest {
final String expectedStatus) {
MaskRuleInspectionService ruleInspectionService = mock(MaskRuleInspectionService.class);
when(ruleInspectionService.queryMaskRules(any(), any(), any())).thenReturn(ruleExists ? List.of(Map.of("column", "phone")) : List.of());
- when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "MASK_FROM_X_TO_Y"))));
+ when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(List.of(Map.of("type", "MASK_FROM_X_TO_Y")));
WorkflowContextSnapshot actual = createService(ruleInspectionService, new MaskAlgorithmRecommendationService(), new MaskAlgorithmPropertyTemplateService(),
new MaskRuleDistSQLPlanningService()).plan(new TestWorkflowSessionContext(), createMetadataQueryFacade(), createQueryFacade(),
createNaturalLanguageRequest(naturalLanguageIntent));
@@ -217,7 +216,7 @@ class MaskWorkflowPlanningServiceTest {
void assertPlanStopsOnBlockingAlgorithmIssue() {
MaskRuleInspectionService ruleInspectionService = mock(MaskRuleInspectionService.class);
when(ruleInspectionService.queryMaskRules(any(), any(), any())).thenReturn(List.of());
- when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(WorkflowQueryResult.confirmed(List.of()));
+ when(ruleInspectionService.queryMaskAlgorithms(any())).thenReturn(List.of());
MaskAlgorithmRecommendationService algorithmRecommendationService = mock(MaskAlgorithmRecommendationService.class);
when(algorithmRecommendationService.recommendMaskAlgorithms(any(), any(), any(), any())).thenAnswer(invocation -> {
List<WorkflowIssue> issues = invocation.getArgument(3);
diff --git a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/completion/ReadwriteSplittingLoadBalanceAlgorithmCompletionHandler.java b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/completion/ReadwriteSplittingLoadBalanceAlgorithmCompletionHandler.java
index 39df942690c..0f141a97b3f 100644
--- a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/completion/ReadwriteSplittingLoadBalanceAlgorithmCompletionHandler.java
+++ b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/completion/ReadwriteSplittingLoadBalanceAlgorithmCompletionHandler.java
@@ -53,7 +53,7 @@ public final class ReadwriteSplittingLoadBalanceAlgorithmCompletionHandler imple
@Override
public MCPCompletionHandlerResult complete(final MCPFeatureRequestContext handlerContext, final MCPCompletionRequest request) {
- return new MCPCompletionHandlerResult(inspectionService.queryLoadBalanceAlgorithmPlugins(handlerContext.getQueryFacade()).getRows().stream()
+ return new MCPCompletionHandlerResult(inspectionService.queryLoadBalanceAlgorithmPlugins(handlerContext.getQueryFacade()).stream()
.map(this::createAlgorithmCandidate).filter(each -> !each.getValue().isEmpty()).toList());
}
diff --git a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandler.java b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandler.java
index 49a578358d5..6b732d1ed43 100644
--- a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandler.java
+++ b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandler.java
@@ -46,7 +46,7 @@ public final class LoadBalanceAlgorithmPluginsHandler implements MCPResourceHand
@Override
public MCPSuccessPayload handle(final MCPFeatureRequestContext requestContext, final MCPResourceURIVariables uriVariables) {
- return new MCPItemsPayload(inspectionService.queryLoadBalanceAlgorithmPlugins(requestContext.getQueryFacade()).getRows(),
+ return new MCPItemsPayload(inspectionService.queryLoadBalanceAlgorithmPlugins(requestContext.getQueryFacade()),
MCPResourceNavigationPayloadBuilder.create(MCPDescriptorCatalogIndex.getRequiredResourceDescriptor(getResourceUriTemplate()), uriVariables));
}
}
diff --git a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationService.java b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationService.java
index 037a2838d5a..16096a538a2 100644
--- a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationService.java
+++ b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationService.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
import java.util.List;
@@ -37,15 +36,15 @@ public final class ReadwriteSplittingAlgorithmRecommendationService {
* Recommend load-balance algorithms.
*
* @param request workflow request
- * @param algorithmResult load-balance algorithm query result
+ * @param algorithms load-balance algorithms reported by the current Proxy
* @param issues workflow issues
* @return selected candidates
*/
public List<AlgorithmCandidate> recommendLoadBalanceAlgorithms(final ReadwriteSplittingRuleWorkflowRequest request,
- final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
+ final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getLoadBalancerType());
if (!actualAlgorithmType.isEmpty()) {
- if (!algorithmResult.isAvailabilityConfirmed() || WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), actualAlgorithmType, "type", "name")) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(algorithms, actualAlgorithmType, "type", "name")) {
return List.of(createCandidate(actualAlgorithmType, 100, "User specified load-balance algorithm."));
}
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
@@ -53,13 +52,14 @@ public final class ReadwriteSplittingAlgorithmRecommendationService {
"Choose an available load-balance algorithm.", false, Map.of()));
return List.of();
}
- String recommendedType = resolveRecommendedAlgorithm(algorithmResult.getRows());
+ String recommendedType = resolveRecommendedAlgorithm(algorithms);
if (recommendedType.isEmpty()) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
"No load-balance algorithm is available from the current Proxy.", "Install or expose at least one load-balance algorithm.", false, Map.of()));
return List.of();
}
- return List.of(createCandidate(recommendedType, 90, "Recommended from current load-balance algorithm availability."));
+ return List.of(createCandidate(recommendedType, 90,
+ "Selected from algorithms reported by the current Proxy using MCP's built-in load-balance preference order."));
}
private AlgorithmCandidate createCandidate(final String algorithmType, final int score, final String reason) {
diff --git a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionService.java b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionService.java
index 2318d1cf9ef..a328a7f40ae 100644
--- a/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionService.java
+++ b/mcp/features/readwrite-splitting/src/main/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionService.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.mcp.feature.readwritesplitting.tool.service;
-import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
-import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowDistSQLQueryUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowRuleValueUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
@@ -105,20 +102,8 @@ public final class ReadwriteSplittingInspectionService {
* @param queryFacade query facade
* @return algorithm plugin query result with built-in property hints
*/
- public WorkflowQueryResult queryLoadBalanceAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult result = queryAlgorithmRows(queryFacade);
- return new WorkflowQueryResult(result.getRows().stream().map(this::appendPropertyGuidance).toList(), result.isAvailabilityConfirmed());
- }
-
- private WorkflowQueryResult queryAlgorithmRows(final MCPFeatureQueryFacade queryFacade) {
- try {
- return WorkflowQueryResult.confirmed(queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS"));
- } catch (final MCPQueryFailedException ex) {
- if (WorkflowDistSQLQueryUtils.isUnsupportedDistSQLQueryFailure(ex)) {
- return WorkflowQueryResult.fallback(List.of(Map.of("type", "RANDOM"), Map.of("type", "ROUND_ROBIN"), Map.of("type", "WEIGHT")));
- }
- throw ex;
- }
+ public List<Map<String, Object>> queryLoadBalanceAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
+ return queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS").stream().map(this::appendPropertyGuidance).toList();
}
private Map<String, Object> appendPropertyGuidance(final Map<String, Object> row) {
diff --git a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandlerTest.java b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandlerTest.java
index 4471557a5ed..7ac357a1025 100644
--- a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandlerTest.java
+++ b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/resource/handler/LoadBalanceAlgorithmPluginsHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceURIVaria
import org.apache.shardingsphere.mcp.feature.readwritesplitting.tool.service.ReadwriteSplittingInspectionService;
import org.apache.shardingsphere.mcp.support.MCPFeatureRequestContext;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
@@ -48,7 +47,7 @@ class LoadBalanceAlgorithmPluginsHandlerTest {
MCPFeatureRequestContext requestContext = mock(MCPFeatureRequestContext.class);
when(requestContext.getQueryFacade()).thenReturn(queryFacade);
when(inspectionService.queryLoadBalanceAlgorithmPlugins(queryFacade))
- .thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "ROUND_ROBIN"))));
+ .thenReturn(List.of(Map.of("type", "ROUND_ROBIN")));
MCPSuccessPayload actual = handler.handle(requestContext, new MCPResourceURIVariables(Map.of()));
verify(inspectionService).queryLoadBalanceAlgorithmPlugins(queryFacade);
assertThat(((Collection<?>) actual.toPayload().get("items")).size(), is(1));
diff --git a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationServiceTest.java b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationServiceTest.java
index d0d93b9e65b..7d016852e81 100644
--- a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationServiceTest.java
+++ b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingAlgorithmRecommendationServiceTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.mcp.feature.readwritesplitting.tool.model.Readw
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import java.util.LinkedList;
@@ -41,7 +40,7 @@ class ReadwriteSplittingAlgorithmRecommendationServiceTest {
ReadwriteSplittingRuleWorkflowRequest request = new ReadwriteSplittingRuleWorkflowRequest();
request.setLoadBalancerType("round_robin");
List<AlgorithmCandidate> actual = service.recommendLoadBalanceAlgorithms(
- request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "ROUND_ROBIN"))), new LinkedList<>());
+ request, List.of(Map.of("type", "ROUND_ROBIN")), new LinkedList<>());
assertThat(actual.getFirst().getAlgorithmType(), is("ROUND_ROBIN"));
assertThat(actual.getFirst().getAlgorithmRole(), is("primary"));
}
@@ -50,8 +49,10 @@ class ReadwriteSplittingAlgorithmRecommendationServiceTest {
void assertRecommendDefaultAlgorithm() {
ReadwriteSplittingRuleWorkflowRequest request = new ReadwriteSplittingRuleWorkflowRequest();
List<AlgorithmCandidate> actual = service.recommendLoadBalanceAlgorithms(
- request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "RANDOM"), Map.of("type", "ROUND_ROBIN"))), new LinkedList<>());
+ request, List.of(Map.of("type", "RANDOM"), Map.of("type", "ROUND_ROBIN")), new LinkedList<>());
assertThat(actual.getFirst().getAlgorithmType(), is("ROUND_ROBIN"));
+ assertThat(actual.getFirst().getRecommendationReason(), is(
+ "Selected from algorithms reported by the current Proxy using MCP's built-in load-balance preference order."));
}
@Test
@@ -59,16 +60,7 @@ class ReadwriteSplittingAlgorithmRecommendationServiceTest {
ReadwriteSplittingRuleWorkflowRequest request = new ReadwriteSplittingRuleWorkflowRequest();
request.setLoadBalancerType("WEIGHT");
List<WorkflowIssue> issues = new LinkedList<>();
- assertTrue(service.recommendLoadBalanceAlgorithms(request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "RANDOM"))), issues).isEmpty());
+ assertTrue(service.recommendLoadBalanceAlgorithms(request, List.of(Map.of("type", "RANDOM")), issues).isEmpty());
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
-
- @Test
- void assertRecommendSpecifiedAlgorithmWithFallbackCatalog() {
- ReadwriteSplittingRuleWorkflowRequest request = new ReadwriteSplittingRuleWorkflowRequest();
- request.setLoadBalancerType("CUSTOM");
- List<AlgorithmCandidate> actual = service.recommendLoadBalanceAlgorithms(
- request, WorkflowQueryResult.fallback(List.of(Map.of("type", "ROUND_ROBIN"))), new LinkedList<>());
- assertThat(actual.getFirst().getAlgorithmType(), is("CUSTOM"));
- }
}
diff --git a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionServiceTest.java b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionServiceTest.java
index 86c900a6012..b2c6623cedf 100644
--- a/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionServiceTest.java
+++ b/mcp/features/readwrite-splitting/src/test/java/org/apache/shardingsphere/mcp/feature/readwritesplitting/tool/service/ReadwriteSplittingInspectionServiceTest.java
@@ -19,10 +19,8 @@ package org.apache.shardingsphere.mcp.feature.readwritesplitting.tool.service;
import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
-import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.util.List;
import java.util.Map;
@@ -30,9 +28,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -72,28 +68,19 @@ class ReadwriteSplittingInspectionServiceTest {
void assertQueryLoadBalanceAlgorithmPlugins() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "WEIGHT")));
- WorkflowQueryResult actual = new ReadwriteSplittingInspectionService().queryLoadBalanceAlgorithmPlugins(queryFacade);
- assertThat(actual.getRows().getFirst().get("property_guidance").toString(), containsString("numeric property"));
- assertTrue(actual.isAvailabilityConfirmed());
+ List<Map<String, Object>> actual = new ReadwriteSplittingInspectionService().queryLoadBalanceAlgorithmPlugins(queryFacade);
+ assertThat(actual.getFirst().get("property_guidance").toString(), containsString("numeric property"));
}
@Test
void assertQueryLoadBalanceAlgorithmPluginsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'LOAD BALANCE ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = new ReadwriteSplittingInspectionService().queryLoadBalanceAlgorithmPlugins(queryFacade);
- assertTrue(actual.getRows().stream().anyMatch(each -> "ROUND_ROBIN".equals(each.get("type"))));
- assertTrue(actual.getRows().stream().anyMatch(each -> "ROUND_ROBIN".equals(each.get("type")) && "No required properties.".equals(each.get("property_guidance"))));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryLoadBalanceAlgorithmPluginsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> new ReadwriteSplittingInspectionService().queryLoadBalanceAlgorithmPlugins(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'LOAD BALANCE ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW LOAD BALANCE ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(
+ MCPQueryFailedException.class, () -> new ReadwriteSplittingInspectionService().queryLoadBalanceAlgorithmPlugins(queryFacade));
+ assertThat(actual, is(expected));
}
@Test
diff --git a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/completion/ShadowAlgorithmCompletionHandler.java b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/completion/ShadowAlgorithmCompletionHandler.java
index afc97508e57..cca96e7b1f8 100644
--- a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/completion/ShadowAlgorithmCompletionHandler.java
+++ b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/completion/ShadowAlgorithmCompletionHandler.java
@@ -55,7 +55,7 @@ public final class ShadowAlgorithmCompletionHandler implements MCPCompletionHand
@Override
public MCPCompletionHandlerResult complete(final MCPFeatureRequestContext handlerContext, final MCPCompletionRequest request) {
- Stream<MCPCompletionCandidate> candidates = inspectionService.queryAlgorithmPlugins(handlerContext.getQueryFacade()).getRows().stream()
+ Stream<MCPCompletionCandidate> candidates = inspectionService.queryAlgorithmPlugins(handlerContext.getQueryFacade()).stream()
.map(this::createAlgorithmCandidate).filter(each -> !each.getValue().isEmpty());
if (ShadowFeatureDefinition.PLAN_DEFAULT_ALGORITHM_PROMPT_NAME.equals(request.getDescriptor().getReference())) {
candidates = candidates.filter(each -> ShadowFeatureDefinition.DEFAULT_ALGORITHM_TYPE.equalsIgnoreCase(each.getValue()));
diff --git a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandler.java b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandler.java
index 793608566ca..c1663103453 100644
--- a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandler.java
+++ b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandler.java
@@ -141,7 +141,7 @@ public final class ShadowResourceHandler implements MCPResourceHandler<MCPFeatur
case ALGORITHMS -> inspectionService.queryAlgorithms(requestContext.getQueryFacade(), uriVariables.getValue("database"));
case DEFAULT_ALGORITHM -> inspectionService.queryDefaultAlgorithm(requestContext.getQueryFacade(), uriVariables.getValue("database"));
case RULE_COUNT -> inspectionService.queryRuleCount(requestContext.getQueryFacade(), uriVariables.getValue("database"));
- case ALGORITHM_PLUGINS -> inspectionService.queryAlgorithmPlugins(requestContext.getQueryFacade()).getRows();
+ case ALGORITHM_PLUGINS -> inspectionService.queryAlgorithmPlugins(requestContext.getQueryFacade());
};
}
diff --git a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationService.java b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationService.java
index ded9d32b1ca..d16af933a74 100644
--- a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationService.java
+++ b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationService.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
@@ -37,15 +36,15 @@ public final class ShadowAlgorithmRecommendationService {
* Recommend shadow algorithm.
*
* @param request workflow request
- * @param algorithmResult algorithm query result
+ * @param algorithms algorithms reported by the current Proxy
* @param issues workflow issues
* @return selected candidates
*/
- public List<AlgorithmCandidate> recommendShadowAlgorithms(final WorkflowRequest request, final WorkflowQueryResult algorithmResult,
+ public List<AlgorithmCandidate> recommendShadowAlgorithms(final WorkflowRequest request, final List<Map<String, Object>> algorithms,
final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(request.getAlgorithmType());
if (!actualAlgorithmType.isEmpty()) {
- if (!algorithmResult.isAvailabilityConfirmed() || WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), actualAlgorithmType, "type", "name")) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(algorithms, actualAlgorithmType, "type", "name")) {
return List.of(createCandidate(actualAlgorithmType, 100, "User specified shadow algorithm."));
}
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
@@ -53,13 +52,14 @@ public final class ShadowAlgorithmRecommendationService {
"Choose an available shadow algorithm.", false, Map.of()));
return List.of();
}
- String recommendedType = resolveRecommendedAlgorithm(algorithmResult.getRows());
+ String recommendedType = resolveRecommendedAlgorithm(algorithms);
if (recommendedType.isEmpty()) {
issues.add(new WorkflowIssue(WorkflowIssueCode.ALGORITHM_NOT_FOUND, "error", WorkflowLifecycle.STEP_SELECTING_ALGORITHM,
"No shadow algorithm is available from the current Proxy.", "Install or expose at least one shadow algorithm.", false, Map.of()));
return List.of();
}
- return List.of(createCandidate(recommendedType, 90, "Recommended from current shadow algorithm availability."));
+ return List.of(createCandidate(recommendedType, 90,
+ "Selected from algorithms reported by the current Proxy using MCP's built-in shadow preference order."));
}
private AlgorithmCandidate createCandidate(final String algorithmType, final int score, final String reason) {
diff --git a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionService.java b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionService.java
index e0c9af6e985..e81c6dff399 100644
--- a/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionService.java
+++ b/mcp/features/shadow/src/main/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionService.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.mcp.feature.shadow.tool.service;
-import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
-import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowDistSQLQueryUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
import java.util.LinkedHashMap;
@@ -120,20 +117,8 @@ public final class ShadowInspectionService {
* @param queryFacade query facade
* @return shadow algorithm plugin query result with built-in property guidance
*/
- public WorkflowQueryResult queryAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult result = queryAlgorithmRows(queryFacade);
- return new WorkflowQueryResult(result.getRows().stream().map(this::appendPropertyGuidance).toList(), result.isAvailabilityConfirmed());
- }
-
- private WorkflowQueryResult queryAlgorithmRows(final MCPFeatureQueryFacade queryFacade) {
- try {
- return WorkflowQueryResult.confirmed(queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS"));
- } catch (final MCPQueryFailedException ex) {
- if (WorkflowDistSQLQueryUtils.isUnsupportedDistSQLQueryFailure(ex)) {
- return WorkflowQueryResult.fallback(List.of(Map.of("type", "SQL_HINT"), Map.of("type", "REGEX_MATCH"), Map.of("type", "VALUE_MATCH")));
- }
- throw ex;
- }
+ public List<Map<String, Object>> queryAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
+ return queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS").stream().map(this::appendPropertyGuidance).toList();
}
private Map<String, Object> appendPropertyGuidance(final Map<String, Object> row) {
diff --git a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandlerTest.java b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandlerTest.java
index ca5993572e5..60856ad6a76 100644
--- a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandlerTest.java
+++ b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/resource/handler/ShadowResourceHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.api.payload.MCPSuccessPayload;
import org.apache.shardingsphere.mcp.feature.shadow.tool.service.ShadowInspectionService;
import org.apache.shardingsphere.mcp.support.MCPFeatureRequestContext;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -55,7 +54,7 @@ class ShadowResourceHandlerTest {
when(mock.queryAlgorithms(any(), eq("logic_db"))).thenReturn(createRows("algorithms"));
when(mock.queryDefaultAlgorithm(any(), eq("logic_db"))).thenReturn(createRows("default_algorithm"));
when(mock.queryRuleCount(any(), eq("logic_db"))).thenReturn(createRows("rule_count"));
- when(mock.queryAlgorithmPlugins(any())).thenReturn(WorkflowQueryResult.confirmed(createRows("algorithm_plugins")));
+ when(mock.queryAlgorithmPlugins(any())).thenReturn(createRows("algorithm_plugins"));
})) {
MCPFeatureRequestContext requestContext = mock(MCPFeatureRequestContext.class);
when(requestContext.getQueryFacade()).thenReturn(mock(MCPFeatureQueryFacade.class));
diff --git a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationServiceTest.java b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationServiceTest.java
index a5282e08a5b..fa8a5d64839 100644
--- a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationServiceTest.java
+++ b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowAlgorithmRecommendationServiceTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.mcp.feature.shadow.tool.service;
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowRequest;
import org.junit.jupiter.api.Test;
@@ -41,7 +40,7 @@ class ShadowAlgorithmRecommendationServiceTest {
WorkflowRequest request = new WorkflowRequest();
request.setAlgorithmType("value_match");
List<AlgorithmCandidate> actual = service.recommendShadowAlgorithms(
- request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "VALUE_MATCH"))), new LinkedList<>());
+ request, List.of(Map.of("type", "VALUE_MATCH")), new LinkedList<>());
assertThat(actual.getFirst().getAlgorithmType(), is("VALUE_MATCH"));
}
@@ -49,8 +48,10 @@ class ShadowAlgorithmRecommendationServiceTest {
void assertRecommendSqlHintDefault() {
WorkflowRequest request = new WorkflowRequest();
List<AlgorithmCandidate> actual = service.recommendShadowAlgorithms(
- request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "VALUE_MATCH"), Map.of("type", "SQL_HINT"))), new LinkedList<>());
+ request, List.of(Map.of("type", "VALUE_MATCH"), Map.of("type", "SQL_HINT")), new LinkedList<>());
assertThat(actual.getFirst().getAlgorithmType(), is("SQL_HINT"));
+ assertThat(actual.getFirst().getRecommendationReason(), is(
+ "Selected from algorithms reported by the current Proxy using MCP's built-in shadow preference order."));
}
@Test
@@ -58,16 +59,7 @@ class ShadowAlgorithmRecommendationServiceTest {
WorkflowRequest request = new WorkflowRequest();
request.setAlgorithmType("REGEX_MATCH");
List<WorkflowIssue> issues = new LinkedList<>();
- assertTrue(service.recommendShadowAlgorithms(request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "SQL_HINT"))), issues).isEmpty());
+ assertTrue(service.recommendShadowAlgorithms(request, List.of(Map.of("type", "SQL_HINT")), issues).isEmpty());
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
-
- @Test
- void assertRecommendSpecifiedAlgorithmWithFallbackCatalog() {
- WorkflowRequest request = new WorkflowRequest();
- request.setAlgorithmType("CUSTOM");
- List<AlgorithmCandidate> actual = service.recommendShadowAlgorithms(
- request, WorkflowQueryResult.fallback(List.of(Map.of("type", "SQL_HINT"))), new LinkedList<>());
- assertThat(actual.getFirst().getAlgorithmType(), is("CUSTOM"));
- }
}
diff --git a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionServiceTest.java b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionServiceTest.java
index 109693bd396..896bb2f1263 100644
--- a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionServiceTest.java
+++ b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowInspectionServiceTest.java
@@ -19,10 +19,8 @@ package org.apache.shardingsphere.mcp.feature.shadow.tool.service;
import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
-import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.util.List;
import java.util.Map;
@@ -30,9 +28,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -64,28 +60,18 @@ class ShadowInspectionServiceTest {
void assertQueryAlgorithmPlugins() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "VALUE_MATCH")));
- WorkflowQueryResult actual = new ShadowInspectionService().queryAlgorithmPlugins(queryFacade);
- assertThat(actual.getRows().size(), is(1));
- assertThat(String.valueOf(actual.getRows().getFirst().get("property_guidance")), containsString("operation"));
- assertTrue(actual.isAvailabilityConfirmed());
+ List<Map<String, Object>> actual = new ShadowInspectionService().queryAlgorithmPlugins(queryFacade);
+ assertThat(actual.size(), is(1));
+ assertThat(String.valueOf(actual.getFirst().get("property_guidance")), containsString("operation"));
}
@Test
void assertQueryAlgorithmPluginsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'SHADOW ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = new ShadowInspectionService().queryAlgorithmPlugins(queryFacade);
- assertTrue(actual.getRows().stream().anyMatch(each -> "VALUE_MATCH".equals(each.get("type"))));
- assertTrue(actual.getRows().stream().anyMatch(each -> "VALUE_MATCH".equals(each.get("type")) && String.valueOf(each.get("property_guidance")).contains("operation")));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryAlgorithmPluginsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> new ShadowInspectionService().queryAlgorithmPlugins(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'SHADOW ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW SHADOW ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(MCPQueryFailedException.class, () -> new ShadowInspectionService().queryAlgorithmPlugins(queryFacade));
+ assertThat(actual, is(expected));
}
}
diff --git a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowWorkflowPlanningServiceTest.java b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowWorkflowPlanningServiceTest.java
index 12a49fcf177..ff625ccb1b5 100644
--- a/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowWorkflowPlanningServiceTest.java
+++ b/mcp/features/shadow/src/test/java/org/apache/shardingsphere/mcp/feature/shadow/tool/service/ShadowWorkflowPlanningServiceTest.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowContextSnaps
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -52,7 +51,7 @@ class ShadowWorkflowPlanningServiceTest {
@BeforeEach
void setUp() {
mockedInspectionServices = mockConstruction(ShadowInspectionService.class,
- (mock, context) -> when(mock.queryAlgorithmPlugins(any())).thenReturn(WorkflowQueryResult.fallback(List.of())));
+ (mock, context) -> when(mock.queryAlgorithmPlugins(any())).thenReturn(List.of(Map.of("type", "SQL_HINT"), Map.of("type", "VALUE_MATCH"))));
}
@AfterEach
@@ -176,7 +175,7 @@ class ShadowWorkflowPlanningServiceTest {
request.getAlgorithmProperties().clear();
ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
ShadowInspectionService inspectionService = getInspectionService();
- when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "SQL_HINT"))));
+ when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(List.of(Map.of("type", "SQL_HINT")));
when(inspectionService.queryRules(queryFacade, "logic_db")).thenReturn(List.of());
WorkflowContextSnapshot actual = service.planRule(new TestWorkflowSessionContext(), queryFacade, request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_PLANNED));
@@ -203,7 +202,7 @@ class ShadowWorkflowPlanningServiceTest {
ShadowDefaultAlgorithmWorkflowRequest request = createDefaultAlgorithmRequest();
ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
ShadowInspectionService inspectionService = getInspectionService();
- when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "SQL_HINT"))));
+ when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(List.of(Map.of("type", "SQL_HINT")));
when(inspectionService.queryDefaultAlgorithm(queryFacade, "logic_db")).thenReturn(List.of());
WorkflowContextSnapshot actual = service.planDefaultAlgorithm(new TestWorkflowSessionContext(), queryFacade, request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_PLANNED));
@@ -224,8 +223,9 @@ class ShadowWorkflowPlanningServiceTest {
void assertPlanDefaultAlgorithmWithoutAlgorithmType() {
ShadowDefaultAlgorithmWorkflowRequest request = createDefaultAlgorithmRequest();
request.setAlgorithmType("");
- WorkflowContextSnapshot actual = new ShadowWorkflowPlanningService().planDefaultAlgorithm(
- new TestWorkflowSessionContext(), mock(MCPFeatureQueryFacade.class), request);
+ ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
+ when(getInspectionService().queryAlgorithmPlugins(any())).thenReturn(List.of());
+ WorkflowContextSnapshot actual = service.planDefaultAlgorithm(new TestWorkflowSessionContext(), mock(MCPFeatureQueryFacade.class), request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_CLARIFYING));
WorkflowIssue actualIssue = actual.getIssues().stream()
.filter(each -> WorkflowIssueCode.RULE_INPUT_REQUIRED.equals(each.getCode())).findFirst().orElseThrow();
@@ -238,7 +238,7 @@ class ShadowWorkflowPlanningServiceTest {
ShadowDefaultAlgorithmWorkflowRequest request = createDefaultAlgorithmRequest();
ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
ShadowInspectionService inspectionService = getInspectionService();
- when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "SQL_HINT"))));
+ when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(List.of(Map.of("type", "SQL_HINT")));
when(inspectionService.queryDefaultAlgorithm(queryFacade, "logic_db")).thenReturn(List.of(Map.of("shadow_algorithm_name", "default_shadow_algorithm")));
WorkflowContextSnapshot actual = service.planDefaultAlgorithm(new TestWorkflowSessionContext(), queryFacade, request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_FAILED));
@@ -252,7 +252,7 @@ class ShadowWorkflowPlanningServiceTest {
request.setOperationType("alter");
ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
ShadowInspectionService inspectionService = getInspectionService();
- when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "SQL_HINT"))));
+ when(inspectionService.queryAlgorithmPlugins(queryFacade)).thenReturn(List.of(Map.of("type", "SQL_HINT")));
when(inspectionService.queryDefaultAlgorithm(queryFacade, "logic_db")).thenReturn(List.of(Map.of("shadow_algorithm_name", "default_shadow_algorithm")));
WorkflowContextSnapshot actual = service.planDefaultAlgorithm(new TestWorkflowSessionContext(), queryFacade, request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_PLANNED));
@@ -266,7 +266,7 @@ class ShadowWorkflowPlanningServiceTest {
request.setDatabase("logic_db");
request.setAlgorithmType("VALUE_MATCH");
ShadowWorkflowPlanningService service = new ShadowWorkflowPlanningService();
- when(getInspectionService().queryAlgorithmPlugins(queryFacade)).thenReturn(WorkflowQueryResult.confirmed(List.of(Map.of("type", "VALUE_MATCH"))));
+ when(getInspectionService().queryAlgorithmPlugins(queryFacade)).thenReturn(List.of(Map.of("type", "VALUE_MATCH")));
WorkflowContextSnapshot actual = service.planDefaultAlgorithm(new TestWorkflowSessionContext(), queryFacade, request);
assertThat(actual.getStatus(), is(WorkflowLifecycle.STATUS_FAILED));
assertThat(actual.getIssues().getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_CAPABILITY_CONFLICT));
diff --git a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/completion/ShardingAlgorithmCompletionHandler.java b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/completion/ShardingAlgorithmCompletionHandler.java
index e8c15ba1c8c..0982ab671b7 100644
--- a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/completion/ShardingAlgorithmCompletionHandler.java
+++ b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/completion/ShardingAlgorithmCompletionHandler.java
@@ -77,8 +77,8 @@ public final class ShardingAlgorithmCompletionHandler implements MCPCompletionHa
private List<Map<String, Object>> queryPlugins(final MCPFeatureRequestContext handlerContext, final MCPCompletionRequest request) {
return KEY_GENERATOR_TYPE_FIELD.equals(request.getArgumentName())
- ? inspectionService.queryKeyGenerateAlgorithmPlugins(handlerContext.getQueryFacade()).getRows()
- : inspectionService.queryAlgorithmPlugins(handlerContext.getQueryFacade()).getRows();
+ ? inspectionService.queryKeyGenerateAlgorithmPlugins(handlerContext.getQueryFacade())
+ : inspectionService.queryAlgorithmPlugins(handlerContext.getQueryFacade());
}
private MCPCompletionCandidate createAlgorithmCandidate(final Map<String, Object> row, final String argumentName) {
diff --git a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandler.java b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandler.java
index 6366c669f6a..4344436d485 100644
--- a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandler.java
+++ b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandler.java
@@ -84,8 +84,8 @@ public final class ShardingAlgorithmResourceHandler extends AbstractShardingReso
@Override
protected List<Map<String, Object>> query(final MCPFeatureRequestContext requestContext, final MCPResourceURIVariables uriVariables) {
return switch (resourceKind) {
- case ALGORITHM_PLUGINS -> getInspectionService().queryAlgorithmPlugins(requestContext.getQueryFacade()).getRows();
- case KEY_GENERATE_ALGORITHM_PLUGINS -> getInspectionService().queryKeyGenerateAlgorithmPlugins(requestContext.getQueryFacade()).getRows();
+ case ALGORITHM_PLUGINS -> getInspectionService().queryAlgorithmPlugins(requestContext.getQueryFacade());
+ case KEY_GENERATE_ALGORITHM_PLUGINS -> getInspectionService().queryKeyGenerateAlgorithmPlugins(requestContext.getQueryFacade());
case ALGORITHMS -> getInspectionService().queryAlgorithms(requestContext.getQueryFacade(), uriVariables.getValue("database"));
case UNUSED_ALGORITHMS -> getInspectionService().queryUnusedAlgorithms(requestContext.getQueryFacade(), uriVariables.getValue("database"));
case ALGORITHM_USED_TABLE_RULES -> getInspectionService().queryTableRulesUsedAlgorithm(
diff --git a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationService.java b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationService.java
index 40f0c108d84..b225aad6a13 100644
--- a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationService.java
+++ b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationService.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowLifecycle;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowAlgorithmUtils;
import java.util.LinkedList;
@@ -38,59 +37,60 @@ public final class ShardingAlgorithmRecommendationService {
* Recommend sharding algorithm and key generator.
*
* @param request workflow request
- * @param algorithmResult algorithm query result
- * @param keyGeneratorResult key-generator query result
+ * @param algorithms sharding algorithms reported by the current Proxy
+ * @param keyGenerators key generators reported by the current Proxy
* @param includeShardingAlgorithm whether to include sharding algorithm recommendation
* @param includeKeyGenerator whether to include key-generator recommendation
* @param issues workflow issues
* @return selected candidates
*/
- public List<AlgorithmCandidate> recommend(final ShardingWorkflowRequest request, final WorkflowQueryResult algorithmResult,
- final WorkflowQueryResult keyGeneratorResult, final boolean includeShardingAlgorithm,
+ public List<AlgorithmCandidate> recommend(final ShardingWorkflowRequest request, final List<Map<String, Object>> algorithms,
+ final List<Map<String, Object>> keyGenerators, final boolean includeShardingAlgorithm,
final boolean includeKeyGenerator, final List<WorkflowIssue> issues) {
List<AlgorithmCandidate> result = new LinkedList<>();
if (includeShardingAlgorithm) {
- recommendAlgorithm(request.getAlgorithmType(), algorithmResult, issues).forEach(result::add);
+ recommendAlgorithm(request.getAlgorithmType(), algorithms, issues).forEach(result::add);
}
if (includeKeyGenerator) {
- recommendKeyGenerator(request.getKeyGeneratorType(), keyGeneratorResult, issues).forEach(result::add);
+ recommendKeyGenerator(request.getKeyGeneratorType(), keyGenerators, issues).forEach(result::add);
}
return result;
}
- private List<AlgorithmCandidate> recommendAlgorithm(final String algorithmType, final WorkflowQueryResult algorithmResult, final List<WorkflowIssue> issues) {
+ private List<AlgorithmCandidate> recommendAlgorithm(final String algorithmType, final List<Map<String, Object>> algorithms, final List<WorkflowIssue> issues) {
String actualAlgorithmType = WorkflowAlgorithmUtils.normalizeAlgorithmType(algorithmType);
if (!actualAlgorithmType.isEmpty()) {
- if (!algorithmResult.isAvailabilityConfirmed() || WorkflowAlgorithmUtils.containsAlgorithm(algorithmResult.getRows(), actualAlgorithmType, "type", "name")) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(algorithms, actualAlgorithmType, "type", "name")) {
return List.of(createCandidate("primary", actualAlgorithmType, 100, "User specified sharding algorithm."));
}
addAlgorithmNotFoundIssue(issues, "Sharding algorithm", actualAlgorithmType);
return List.of();
}
- String recommendedType = resolveRecommendedAlgorithm(algorithmResult.getRows(), List.of("INLINE", "MOD", "HASH_MOD"));
+ String recommendedType = resolveRecommendedAlgorithm(algorithms, List.of("INLINE", "MOD", "HASH_MOD"));
if (recommendedType.isEmpty()) {
addNoAlgorithmIssue(issues, "sharding algorithm");
return List.of();
}
- return List.of(createCandidate("primary", recommendedType, 90, "Recommended from current sharding algorithm availability."));
+ return List.of(createCandidate("primary", recommendedType, 90,
+ "Selected from algorithms reported by the current Proxy using MCP's built-in sharding preference order."));
}
- private List<AlgorithmCandidate> recommendKeyGenerator(final String keyGeneratorType, final WorkflowQueryResult keyGeneratorResult, final List<WorkflowIssue> issues) {
+ private List<AlgorithmCandidate> recommendKeyGenerator(final String keyGeneratorType, final List<Map<String, Object>> keyGenerators, final List<WorkflowIssue> issues) {
String actualKeyGeneratorType = WorkflowAlgorithmUtils.normalizeAlgorithmType(keyGeneratorType);
if (!actualKeyGeneratorType.isEmpty()) {
- if (!keyGeneratorResult.isAvailabilityConfirmed()
- || WorkflowAlgorithmUtils.containsAlgorithm(keyGeneratorResult.getRows(), actualKeyGeneratorType, "type", "name")) {
+ if (WorkflowAlgorithmUtils.containsAlgorithm(keyGenerators, actualKeyGeneratorType, "type", "name")) {
return List.of(createCandidate("key_generator", actualKeyGeneratorType, 100, "User specified key-generator algorithm."));
}
addAlgorithmNotFoundIssue(issues, "Key-generator algorithm", actualKeyGeneratorType);
return List.of();
}
- String recommendedType = resolveRecommendedAlgorithm(keyGeneratorResult.getRows(), List.of("SNOWFLAKE", "UUID"));
+ String recommendedType = resolveRecommendedAlgorithm(keyGenerators, List.of("SNOWFLAKE", "UUID"));
if (recommendedType.isEmpty()) {
addNoAlgorithmIssue(issues, "key-generator algorithm");
return List.of();
}
- return List.of(createCandidate("key_generator", recommendedType, 90, "Recommended from current key-generator availability."));
+ return List.of(createCandidate("key_generator", recommendedType, 90,
+ "Selected from algorithms reported by the current Proxy using MCP's built-in key-generator preference order."));
}
private AlgorithmCandidate createCandidate(final String role, final String algorithmType, final int score, final String reason) {
diff --git a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
index 688265f135a..42a7c101e31 100644
--- a/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
+++ b/mcp/features/sharding/src/main/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionService.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.mcp.feature.sharding.tool.service;
-import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
-import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowDistSQLQueryUtils;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
import java.util.LinkedHashMap;
@@ -39,9 +36,8 @@ public final class ShardingInspectionService {
* @param queryFacade feature query facade
* @return sharding algorithm plugin query result
*/
- public WorkflowQueryResult queryAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult result = queryPluginRows(queryFacade, "SHOW SHARDING ALGORITHM PLUGINS", getShardingAlgorithmPluginRows());
- return new WorkflowQueryResult(result.getRows().stream().map(this::appendShardingAlgorithmGuidance).toList(), result.isAvailabilityConfirmed());
+ public List<Map<String, Object>> queryAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
+ return queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS").stream().map(this::appendShardingAlgorithmGuidance).toList();
}
/**
@@ -50,38 +46,8 @@ public final class ShardingInspectionService {
* @param queryFacade feature query facade
* @return key generate algorithm plugin query result
*/
- public WorkflowQueryResult queryKeyGenerateAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
- WorkflowQueryResult result = queryPluginRows(queryFacade, "SHOW KEY GENERATE ALGORITHM PLUGINS", getKeyGenerateAlgorithmPluginRows());
- return new WorkflowQueryResult(result.getRows().stream().map(this::appendKeyGeneratorGuidance).toList(), result.isAvailabilityConfirmed());
- }
-
- private WorkflowQueryResult queryPluginRows(final MCPFeatureQueryFacade queryFacade, final String sql, final List<Map<String, Object>> fallbackRows) {
- try {
- return WorkflowQueryResult.confirmed(queryFacade.queryWithAnyDatabase(sql));
- } catch (final MCPQueryFailedException ex) {
- if (WorkflowDistSQLQueryUtils.isUnsupportedDistSQLQueryFailure(ex)) {
- return WorkflowQueryResult.fallback(fallbackRows);
- }
- throw ex;
- }
- }
-
- private List<Map<String, Object>> getShardingAlgorithmPluginRows() {
- return List.of(
- Map.of("type", "MOD"),
- Map.of("type", "HASH_MOD"),
- Map.of("type", "VOLUME_RANGE"),
- Map.of("type", "BOUNDARY_RANGE"),
- Map.of("type", "AUTO_INTERVAL"),
- Map.of("type", "INTERVAL"),
- Map.of("type", "CLASS_BASED"),
- Map.of("type", "INLINE"),
- Map.of("type", "COMPLEX_INLINE"),
- Map.of("type", "HINT_INLINE"));
- }
-
- private List<Map<String, Object>> getKeyGenerateAlgorithmPluginRows() {
- return List.of(Map.of("type", "SNOWFLAKE"), Map.of("type", "UUID"));
+ public List<Map<String, Object>> queryKeyGenerateAlgorithmPlugins(final MCPFeatureQueryFacade queryFacade) {
+ return queryFacade.queryWithAnyDatabase("SHOW KEY GENERATE ALGORITHM PLUGINS").stream().map(this::appendKeyGeneratorGuidance).toList();
}
/**
diff --git a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandlerTest.java b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandlerTest.java
index ec85403a986..9caa6a30126 100644
--- a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandlerTest.java
+++ b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/resource/handler/ShardingAlgorithmResourceHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceURIVaria
import org.apache.shardingsphere.mcp.feature.sharding.tool.service.ShardingInspectionService;
import org.apache.shardingsphere.mcp.support.MCPFeatureRequestContext;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -80,8 +79,8 @@ class ShardingAlgorithmResourceHandlerTest {
}
private static void stubInspectionService(final ShardingInspectionService inspectionService, final List<Map<String, Object>> rows) {
- when(inspectionService.queryAlgorithmPlugins(any())).thenReturn(WorkflowQueryResult.confirmed(rows));
- when(inspectionService.queryKeyGenerateAlgorithmPlugins(any())).thenReturn(WorkflowQueryResult.confirmed(rows));
+ when(inspectionService.queryAlgorithmPlugins(any())).thenReturn(rows);
+ when(inspectionService.queryKeyGenerateAlgorithmPlugins(any())).thenReturn(rows);
when(inspectionService.queryAlgorithms(any(), eq("logic_db"))).thenReturn(rows);
when(inspectionService.queryUnusedAlgorithms(any(), eq("logic_db"))).thenReturn(rows);
when(inspectionService.queryTableRulesUsedAlgorithm(any(), eq("logic_db"), eq("inline_algorithm"))).thenReturn(rows);
diff --git a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationServiceTest.java b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationServiceTest.java
index dc64dcb871a..46c472a3bfe 100644
--- a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationServiceTest.java
+++ b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingAlgorithmRecommendationServiceTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.mcp.feature.sharding.tool.model.ShardingWorkflo
import org.apache.shardingsphere.mcp.support.workflow.model.AlgorithmCandidate;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssue;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import java.util.LinkedList;
@@ -41,8 +40,7 @@ class ShardingAlgorithmRecommendationServiceTest {
ShardingWorkflowRequest request = new ShardingWorkflowRequest();
request.setAlgorithmType("inline");
request.setKeyGeneratorType("snowflake");
- List<AlgorithmCandidate> actual = service.recommend(request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "INLINE"))),
- WorkflowQueryResult.confirmed(List.of(Map.of("type", "SNOWFLAKE"))), true, true, new LinkedList<>());
+ List<AlgorithmCandidate> actual = service.recommend(request, List.of(Map.of("type", "INLINE")), List.of(Map.of("type", "SNOWFLAKE")), true, true, new LinkedList<>());
assertThat(actual.get(0).getAlgorithmType(), is("INLINE"));
assertThat(actual.get(1).getAlgorithmRole(), is("key_generator"));
assertThat(actual.get(1).getAlgorithmType(), is("SNOWFLAKE"));
@@ -51,10 +49,12 @@ class ShardingAlgorithmRecommendationServiceTest {
@Test
void assertRecommendDefaultAlgorithms() {
ShardingWorkflowRequest request = new ShardingWorkflowRequest();
- List<AlgorithmCandidate> actual = service.recommend(request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "MOD"), Map.of("type", "INLINE"))),
- WorkflowQueryResult.confirmed(List.of(Map.of("type", "UUID"), Map.of("type", "SNOWFLAKE"))), true, true, new LinkedList<>());
+ List<AlgorithmCandidate> actual = service.recommend(request, List.of(Map.of("type", "MOD"), Map.of("type", "INLINE")),
+ List.of(Map.of("type", "UUID"), Map.of("type", "SNOWFLAKE")), true, true, new LinkedList<>());
assertThat(actual.get(0).getAlgorithmType(), is("INLINE"));
+ assertThat(actual.get(0).getRecommendationReason(), is("Selected from algorithms reported by the current Proxy using MCP's built-in sharding preference order."));
assertThat(actual.get(1).getAlgorithmType(), is("SNOWFLAKE"));
+ assertThat(actual.get(1).getRecommendationReason(), is("Selected from algorithms reported by the current Proxy using MCP's built-in key-generator preference order."));
}
@Test
@@ -62,17 +62,7 @@ class ShardingAlgorithmRecommendationServiceTest {
ShardingWorkflowRequest request = new ShardingWorkflowRequest();
request.setAlgorithmType("CLASS_BASED");
List<WorkflowIssue> issues = new LinkedList<>();
- assertTrue(service.recommend(request, WorkflowQueryResult.confirmed(List.of(Map.of("type", "INLINE"))),
- WorkflowQueryResult.confirmed(List.of()), true, false, issues).isEmpty());
+ assertTrue(service.recommend(request, List.of(Map.of("type", "INLINE")), List.of(), true, false, issues).isEmpty());
assertThat(issues.getFirst().getCode(), is(WorkflowIssueCode.ALGORITHM_NOT_FOUND));
}
-
- @Test
- void assertRecommendSpecifiedAlgorithmWithFallbackCatalog() {
- ShardingWorkflowRequest request = new ShardingWorkflowRequest();
- request.setAlgorithmType("CLASS_BASED");
- List<AlgorithmCandidate> actual = service.recommend(request, WorkflowQueryResult.fallback(List.of(Map.of("type", "INLINE"))),
- WorkflowQueryResult.fallback(List.of(Map.of("type", "SNOWFLAKE"))), true, false, new LinkedList<>());
- assertThat(actual.getFirst().getAlgorithmType(), is("CLASS_BASED"));
- }
}
diff --git a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
index e3d03d3d1ed..e367e180605 100644
--- a/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
+++ b/mcp/features/sharding/src/test/java/org/apache/shardingsphere/mcp/feature/sharding/tool/service/ShardingInspectionServiceTest.java
@@ -19,13 +19,11 @@ package org.apache.shardingsphere.mcp.feature.sharding.tool.service;
import org.apache.shardingsphere.mcp.api.exception.MCPQueryFailedException;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
-import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowQueryResult;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.util.List;
import java.util.Map;
@@ -34,9 +32,7 @@ import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -56,56 +52,36 @@ class ShardingInspectionServiceTest {
void assertQueryAlgorithmPlugins() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "INLINE")));
- WorkflowQueryResult actual = new ShardingInspectionService().queryAlgorithmPlugins(queryFacade);
- assertThat(actual.getRows().getFirst().get("property_guidance").toString(), containsString("algorithm-expression"));
- assertTrue(actual.isAvailabilityConfirmed());
+ List<Map<String, Object>> actual = new ShardingInspectionService().queryAlgorithmPlugins(queryFacade);
+ assertThat(actual.getFirst().get("property_guidance").toString(), containsString("algorithm-expression"));
}
@Test
void assertQueryAlgorithmPluginsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'SHARDING ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = new ShardingInspectionService().queryAlgorithmPlugins(queryFacade);
- assertTrue(actual.getRows().stream().anyMatch(each -> "INLINE".equals(each.get("type"))));
- assertTrue(actual.getRows().stream().anyMatch(each -> "INLINE".equals(each.get("type")) && String.valueOf(each.get("property_guidance")).contains("algorithm-expression")));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryAlgorithmPluginsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> new ShardingInspectionService().queryAlgorithmPlugins(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'SHARDING ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW SHARDING ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(MCPQueryFailedException.class, () -> new ShardingInspectionService().queryAlgorithmPlugins(queryFacade));
+ assertThat(actual, is(expected));
}
@Test
void assertQueryKeyGenerateAlgorithmPlugins() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
when(queryFacade.queryWithAnyDatabase("SHOW KEY GENERATE ALGORITHM PLUGINS")).thenReturn(List.of(Map.of("type", "UUID")));
- WorkflowQueryResult actual = new ShardingInspectionService().queryKeyGenerateAlgorithmPlugins(queryFacade);
- assertThat(actual.getRows().getFirst().get("property_guidance").toString(), is("No required properties."));
- assertTrue(actual.isAvailabilityConfirmed());
+ List<Map<String, Object>> actual = new ShardingInspectionService().queryKeyGenerateAlgorithmPlugins(queryFacade);
+ assertThat(actual.getFirst().get("property_guidance").toString(), is("No required properties."));
}
@Test
void assertQueryKeyGenerateAlgorithmPluginsWithUnavailableDistSQL() {
MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW KEY GENERATE ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("syntax error near 'KEY GENERATE ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error")));
- WorkflowQueryResult actual = new ShardingInspectionService().queryKeyGenerateAlgorithmPlugins(queryFacade);
- assertTrue(actual.getRows().stream().anyMatch(each -> "SNOWFLAKE".equals(each.get("type"))));
- assertTrue(actual.getRows().stream().anyMatch(each -> "SNOWFLAKE".equals(each.get("type")) && String.valueOf(each.get("property_guidance")).contains("worker-id")));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertQueryKeyGenerateAlgorithmPluginsPropagatesQueryFailure() {
- MCPFeatureQueryFacade queryFacade = mock(MCPFeatureQueryFacade.class);
- when(queryFacade.queryWithAnyDatabase("SHOW KEY GENERATE ALGORITHM PLUGINS"))
- .thenThrow(new MCPQueryFailedException("Connection refused.", new SQLException("Connection refused.")));
- assertThrows(MCPQueryFailedException.class, () -> new ShardingInspectionService().queryKeyGenerateAlgorithmPlugins(queryFacade));
+ MCPQueryFailedException expected = new MCPQueryFailedException(
+ "syntax error near 'KEY GENERATE ALGORITHM PLUGINS'", new SQLSyntaxErrorException("syntax error"));
+ when(queryFacade.queryWithAnyDatabase("SHOW KEY GENERATE ALGORITHM PLUGINS")).thenThrow(expected);
+ MCPQueryFailedException actual = assertThrows(MCPQueryFailedException.class, () -> new ShardingInspectionService().queryKeyGenerateAlgorithmPlugins(queryFacade));
+ assertThat(actual, is(expected));
}
private static Stream<Arguments> assertDatabaseScopedQueryArguments() {
diff --git a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResult.java b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResult.java
deleted file mode 100644
index f9efc667528..00000000000
--- a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResult.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mcp.support.workflow.model;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Workflow query result that distinguishes confirmed backend data from compatibility fallback data.
- */
-@RequiredArgsConstructor
-@Getter
-public final class WorkflowQueryResult {
-
- private final List<Map<String, Object>> rows;
-
- private final boolean availabilityConfirmed;
-
- /**
- * Create a confirmed query result.
- *
- * @param rows queried rows
- * @return confirmed query result
- */
- public static WorkflowQueryResult confirmed(final List<Map<String, Object>> rows) {
- return new WorkflowQueryResult(rows, true);
- }
-
- /**
- * Create a compatibility fallback result.
- *
- * @param rows fallback rows
- * @return fallback query result
- */
- public static WorkflowQueryResult fallback(final List<Map<String, Object>> rows) {
- return new WorkflowQueryResult(rows, false);
- }
-}
diff --git a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResultTest.java b/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResultTest.java
deleted file mode 100644
index 539dd7e4361..00000000000
--- a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/workflow/model/WorkflowQueryResultTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mcp.support.workflow.model;
-
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class WorkflowQueryResultTest {
-
- @Test
- void assertCreateConfirmedResult() {
- List<Map<String, Object>> rows = List.of(Map.of("type", "INLINE"));
- WorkflowQueryResult actual = WorkflowQueryResult.confirmed(rows);
- assertThat(actual.getRows(), is(rows));
- assertTrue(actual.isAvailabilityConfirmed());
- }
-
- @Test
- void assertCreateFallbackResult() {
- List<Map<String, Object>> rows = List.of(Map.of("type", "INLINE"));
- WorkflowQueryResult actual = WorkflowQueryResult.fallback(rows);
- assertThat(actual.getRows(), is(rows));
- assertFalse(actual.isAvailabilityConfirmed());
- }
-}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractFunctionalityE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractFunctionalityE2ETest.java
index c32ae7ec6ad..da88bb037b2 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractFunctionalityE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractFunctionalityE2ETest.java
@@ -37,6 +37,10 @@ abstract class AbstractFunctionalityE2ETest extends AbstractConfigBackedRuntimeE
return MCPInteractionPayloads.getRequiredObjectList(payload, "resourceTemplates");
}
+ protected final List<String> getRequiredStringList(final Object value) {
+ return ((List<?>) value).stream().map(String::valueOf).toList();
+ }
+
protected final List<String> getNestedNames(final Map<String, Object> item, final String nestedKey, final String nameKey) {
return ((List<?>) item.get(nestedKey)).stream().map(each -> String.valueOf(((Map<?, ?>) each).get(nameKey))).toList();
}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractHttpProxyWorkflowE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractHttpProxyWorkflowE2ETest.java
index 37161c7ceda..6e143176f3a 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractHttpProxyWorkflowE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractHttpProxyWorkflowE2ETest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.test.e2e.mcp.support.assertion.MCPModelContract
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.MySQLRuntimeTestSupport;
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.ProxyWorkflowRuntimeTestSupport;
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.ProxyWorkflowRuntimeTestSupport.ProxyWorkflowRuntimeFixture;
-import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionPayloads;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.client.MCPInteractionClient;
import org.junit.jupiter.api.AfterAll;
@@ -39,7 +38,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-abstract class AbstractHttpProxyWorkflowE2ETest extends AbstractFunctionalityE2ETest {
+abstract class AbstractHttpProxyWorkflowE2ETest extends AbstractTransportParameterizedE2ETest {
private ProxyWorkflowRuntimeFixture runtimeFixture;
@@ -71,11 +70,6 @@ abstract class AbstractHttpProxyWorkflowE2ETest extends AbstractFunctionalityE2E
}
}
- @Override
- protected final RuntimeTransport getTransport() {
- return RuntimeTransport.HTTP;
- }
-
@Override
protected final void prepareRuntimeFixture() throws IOException {
if (!MySQLRuntimeTestSupport.isDockerAvailable()) {
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractMySQLRuntimeE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractMySQLRuntimeE2ETest.java
index 487d492589a..148ea24ab9f 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractMySQLRuntimeE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractMySQLRuntimeE2ETest.java
@@ -17,16 +17,11 @@
package org.apache.shardingsphere.test.e2e.mcp.functionality;
-import io.modelcontextprotocol.client.McpSyncClient;
-import io.modelcontextprotocol.spec.McpClientTransport;
-import io.modelcontextprotocol.spec.McpSchema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.shardingsphere.mcp.support.database.metadata.jdbc.RuntimeDatabaseConfiguration;
-import org.apache.shardingsphere.mcp.support.descriptor.MCPShardingSphereMetadataKeys;
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.MySQLRuntimeTestSupport;
-import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionPayloads;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.client.MCPInteractionClient;
import org.junit.jupiter.api.AfterAll;
@@ -43,7 +38,6 @@ import java.util.Map;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -56,8 +50,6 @@ abstract class AbstractMySQLRuntimeE2ETest extends AbstractTransportParameterize
protected static final String PHYSICAL_DATABASE_NAME = "orders";
- protected static final String MASK_PLAN_TOOL_NAME = "database_gateway_plan_mask_rule";
-
@Getter(AccessLevel.PROTECTED)
private GenericContainer<?> container;
@@ -148,10 +140,6 @@ abstract class AbstractMySQLRuntimeE2ETest extends AbstractTransportParameterize
return Map.of("database", databaseName, "schema", databaseName, "sql", sql, "execution_mode", "execute");
}
- protected static Stream<Arguments> allTransportCases() {
- return FunctionalityTransportCases.allTransportCases();
- }
-
protected static Stream<Arguments> singleMetadataResourceCases() {
return FunctionalityTransportCases.singleMetadataResourceCases(LOGICAL_DATABASE_NAME);
}
@@ -249,42 +237,6 @@ abstract class AbstractMySQLRuntimeE2ETest extends AbstractTransportParameterize
assertThat(String.valueOf(getRequiredObjectList(actual.get("next_actions")).getFirst().get("type")), is("ask_user"));
}
- protected McpSyncClient createElicitationClient(final RuntimeTransport transport, final List<McpSchema.ElicitRequest> elicitationRequests) throws IOException {
- return MCPClientTransportFactory.createElicitationClient(createClientTransport(transport), elicitationRequests, this::createElicitationResult);
- }
-
- private McpClientTransport createClientTransport(final RuntimeTransport transport) throws IOException {
- return RuntimeTransport.HTTP == transport
- ? MCPClientTransportFactory.createHttpClientTransport(getHttpEndpointUri())
- : MCPClientTransportFactory.createStdioClientTransport(getConfigFile());
- }
-
- private McpSchema.ElicitResult createElicitationResult(final List<McpSchema.ElicitRequest> elicitationRequests,
- final McpSchema.ElicitRequest request) {
- elicitationRequests.add(request);
- List<String> requiredFields = getRequiredStringList(request.requestedSchema().get("required"));
- return new McpSchema.ElicitResult(McpSchema.ElicitResult.Action.ACCEPT, Map.of(
- requiredFields.getFirst(), "1",
- requiredFields.get(1), "3"));
- }
-
- protected void assertElicitationRequest(final List<McpSchema.ElicitRequest> actualRequests) {
- assertThat(actualRequests.size(), is(1));
- McpSchema.ElicitRequest actual = actualRequests.getFirst();
- assertThat(actual.meta().get(MCPShardingSphereMetadataKeys.TOOL), is(MASK_PLAN_TOOL_NAME));
- assertFalse(String.valueOf(actual.meta().get(MCPShardingSphereMetadataKeys.PLAN_ID)).isBlank());
- Map<String, Object> actualRequestedSchema = actual.requestedSchema();
- assertThat(actualRequestedSchema.get("type"), is("object"));
- assertFalse((Boolean) actualRequestedSchema.get("additionalProperties"));
- Map<String, Object> actualProperties = MCPInteractionPayloads.getRequiredObject(actualRequestedSchema, "properties");
- assertTrue(actualProperties.containsKey("field_1"));
- assertTrue(actualProperties.containsKey("field_2"));
- assertThat(String.valueOf(MCPInteractionPayloads.getRequiredObject(actualProperties, "field_1").get("description")), is("Please provide property `from-x`."));
- assertThat(String.valueOf(MCPInteractionPayloads.getRequiredObject(actualProperties, "field_2").get("description")), is("Please provide property `to-y`."));
- assertFalse(actualProperties.keySet().stream().map(String::valueOf).anyMatch(each -> each.contains("secret") || each.contains("password") || each.contains("token")));
- assertThat(getRequiredStringList(actualRequestedSchema.get("required")), hasItems("field_1", "field_2"));
- }
-
protected Map<String, Object> getObjectOrEmpty(final Object value) {
return value instanceof Map ? MCPInteractionPayloads.getRequiredObjectValue(value, "payload") : Map.of();
}
@@ -293,10 +245,6 @@ abstract class AbstractMySQLRuntimeE2ETest extends AbstractTransportParameterize
return MCPInteractionPayloads.getRequiredObjectList(value, "payload");
}
- protected List<String> getRequiredStringList(final Object value) {
- return ((List<?>) value).stream().map(String::valueOf).toList();
- }
-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
private static final class MySQLRuntimeFixture implements AutoCloseable {
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractTransportParameterizedE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractTransportParameterizedE2ETest.java
index f8abeaec543..ebb0498f960 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractTransportParameterizedE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/AbstractTransportParameterizedE2ETest.java
@@ -19,11 +19,18 @@ package org.apache.shardingsphere.test.e2e.mcp.functionality;
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.params.provider.Arguments;
+
+import java.util.stream.Stream;
abstract class AbstractTransportParameterizedE2ETest extends AbstractFunctionalityE2ETest {
private RuntimeTransport transport = RuntimeTransport.HTTP;
+ protected static Stream<Arguments> allTransportCases() {
+ return FunctionalityTransportCases.allTransportCases();
+ }
+
protected final void useTransport(final RuntimeTransport transport) {
this.transport = transport;
}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/HttpProxyMaskWorkflowE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/HttpProxyMaskWorkflowE2ETest.java
index 14c69ebf3c9..61ba1e5e6eb 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/HttpProxyMaskWorkflowE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/HttpProxyMaskWorkflowE2ETest.java
@@ -17,21 +17,33 @@
package org.apache.shardingsphere.test.e2e.mcp.functionality;
+import io.modelcontextprotocol.client.McpSyncClient;
+import io.modelcontextprotocol.spec.McpClientTransport;
+import io.modelcontextprotocol.spec.McpSchema;
+import org.apache.shardingsphere.mcp.support.descriptor.MCPShardingSphereMetadataKeys;
import org.apache.shardingsphere.mcp.support.workflow.descriptor.WorkflowToolDescriptors;
import org.apache.shardingsphere.mcp.support.workflow.model.WorkflowIssueCode;
+import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
+import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionPayloads;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.client.MCPInteractionClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("org.apache.shardingsphere.test.e2e.mcp.env.MCPE2ECondition#isDockerEnabled")
class HttpProxyMaskWorkflowE2ETest extends AbstractHttpProxyWorkflowE2ETest {
@@ -57,6 +69,73 @@ class HttpProxyMaskWorkflowE2ETest extends AbstractHttpProxyWorkflowE2ETest {
}
}
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("allTransportCases")
+ void assertElicitMaskPlanning(final String name, final RuntimeTransport transport) throws IOException {
+ useTransport(transport);
+ List<McpSchema.ElicitRequest> actualElicitationRequests = new CopyOnWriteArrayList<>();
+ try (McpSyncClient client = createElicitationClient(transport, actualElicitationRequests)) {
+ client.initialize();
+ McpSchema.CallToolResult actual = client.callTool(new McpSchema.CallToolRequest(PLAN_TOOL_NAME, Map.of(
+ "database", getLogicalDatabaseName(),
+ "schema", getLogicalDatabaseName(),
+ "table", "orders",
+ "column", "status",
+ "operation_type", "create",
+ "algorithm_type", "MASK_FROM_X_TO_Y")));
+ Map<String, Object> actualPayload = MCPInteractionPayloads.getRequiredObjectValue(actual.structuredContent(), "structuredContent");
+ if (RuntimeTransport.HTTP == transport) {
+ assertThat(String.valueOf(actualPayload.get("status")), is("clarifying"));
+ assertThat(String.valueOf(actualPayload.get("fallback_reason")), is("remote_identity_required"));
+ assertTrue(actualElicitationRequests.isEmpty());
+ return;
+ }
+ assertThat(String.valueOf(actualPayload.get("status")), is("planned"));
+ assertThat(String.valueOf(actualPayload.get("current_step")), is("review"));
+ Map<String, Object> maskedPropertyPreview = MCPInteractionPayloads.getRequiredObject(actualPayload, "masked_property_preview");
+ Map<String, Object> primaryProperties = MCPInteractionPayloads.getRequiredObject(maskedPropertyPreview, "primary");
+ assertThat(String.valueOf(primaryProperties.get("from-x")), is("1"));
+ assertThat(String.valueOf(primaryProperties.get("to-y")), is("3"));
+ assertElicitationRequest(actualElicitationRequests);
+ }
+ }
+
+ private McpSyncClient createElicitationClient(final RuntimeTransport transport, final List<McpSchema.ElicitRequest> elicitationRequests) throws IOException {
+ return MCPClientTransportFactory.createElicitationClient(createClientTransport(transport), elicitationRequests, this::createElicitationResult);
+ }
+
+ private McpClientTransport createClientTransport(final RuntimeTransport transport) throws IOException {
+ return RuntimeTransport.HTTP == transport
+ ? MCPClientTransportFactory.createHttpClientTransport(getHttpEndpointUri())
+ : MCPClientTransportFactory.createStdioClientTransport(getConfigFile());
+ }
+
+ private McpSchema.ElicitResult createElicitationResult(final List<McpSchema.ElicitRequest> elicitationRequests,
+ final McpSchema.ElicitRequest request) {
+ elicitationRequests.add(request);
+ List<String> requiredFields = getRequiredStringList(request.requestedSchema().get("required"));
+ return new McpSchema.ElicitResult(McpSchema.ElicitResult.Action.ACCEPT, Map.of(
+ requiredFields.getFirst(), "1",
+ requiredFields.get(1), "3"));
+ }
+
+ private void assertElicitationRequest(final List<McpSchema.ElicitRequest> actualRequests) {
+ assertThat(actualRequests.size(), is(1));
+ McpSchema.ElicitRequest actual = actualRequests.getFirst();
+ assertThat(actual.meta().get(MCPShardingSphereMetadataKeys.TOOL), is(PLAN_TOOL_NAME));
+ assertFalse(String.valueOf(actual.meta().get(MCPShardingSphereMetadataKeys.PLAN_ID)).isBlank());
+ Map<String, Object> actualRequestedSchema = actual.requestedSchema();
+ assertThat(actualRequestedSchema.get("type"), is("object"));
+ assertFalse((Boolean) actualRequestedSchema.get("additionalProperties"));
+ Map<String, Object> actualProperties = MCPInteractionPayloads.getRequiredObject(actualRequestedSchema, "properties");
+ assertTrue(actualProperties.containsKey("field_1"));
+ assertTrue(actualProperties.containsKey("field_2"));
+ assertThat(String.valueOf(MCPInteractionPayloads.getRequiredObject(actualProperties, "field_1").get("description")), is("Please provide property `from-x`."));
+ assertThat(String.valueOf(MCPInteractionPayloads.getRequiredObject(actualProperties, "field_2").get("description")), is("Please provide property `to-y`."));
+ assertFalse(actualProperties.keySet().stream().map(String::valueOf).anyMatch(each -> each.contains("secret") || each.contains("password") || each.contains("token")));
+ assertThat(getRequiredStringList(actualRequestedSchema.get("required")), hasItems("field_1", "field_2"));
+ }
+
@Test
void assertPlanApplyAndValidateMaskWorkflow() throws IOException, InterruptedException {
try (MCPInteractionClient interactionClient = createOpenedInteractionClient()) {
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MySQLReadOnlySQLE2ETest.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MySQLReadOnlySQLE2ETest.java
index a512582a2e3..6f90f61d19d 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MySQLReadOnlySQLE2ETest.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/functionality/MySQLReadOnlySQLE2ETest.java
@@ -17,10 +17,7 @@
package org.apache.shardingsphere.test.e2e.mcp.functionality;
-import io.modelcontextprotocol.client.McpSyncClient;
-import io.modelcontextprotocol.spec.McpSchema;
import org.apache.shardingsphere.test.e2e.mcp.support.runtime.RuntimeTransport;
-import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionPayloads;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPPayloadAssertions;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.client.MCPInteractionClient;
import org.junit.jupiter.api.Test;
@@ -31,12 +28,10 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("org.apache.shardingsphere.test.e2e.mcp.env.MCPE2ECondition#isDockerEnabled")
class MySQLReadOnlySQLE2ETest extends AbstractMySQLRuntimeE2ETest {
@@ -87,37 +82,6 @@ class MySQLReadOnlySQLE2ETest extends AbstractMySQLRuntimeE2ETest {
}
}
- @ParameterizedTest(name = "{0}")
- @MethodSource("allTransportCases")
- void assertElicitMaskPlanning(final String name, final RuntimeTransport transport) throws IOException {
- useTransport(transport);
- List<McpSchema.ElicitRequest> actualElicitationRequests = new CopyOnWriteArrayList<>();
- try (McpSyncClient client = createElicitationClient(transport, actualElicitationRequests)) {
- client.initialize();
- McpSchema.CallToolResult actual = client.callTool(new McpSchema.CallToolRequest(MASK_PLAN_TOOL_NAME, Map.of(
- "database", LOGICAL_DATABASE_NAME,
- "schema", LOGICAL_DATABASE_NAME,
- "table", "orders",
- "column", "status",
- "operation_type", "create",
- "algorithm_type", "MASK_FROM_X_TO_Y")));
- Map<String, Object> actualPayload = MCPInteractionPayloads.getRequiredObjectValue(actual.structuredContent(), "structuredContent");
- if (RuntimeTransport.HTTP == transport) {
- assertThat(String.valueOf(actualPayload.get("status")), is("clarifying"));
- assertThat(String.valueOf(actualPayload.get("fallback_reason")), is("remote_identity_required"));
- assertTrue(actualElicitationRequests.isEmpty());
- return;
- }
- assertThat(String.valueOf(actualPayload.get("status")), is("planned"));
- assertThat(String.valueOf(actualPayload.get("current_step")), is("review"));
- Map<String, Object> maskedPropertyPreview = MCPInteractionPayloads.getRequiredObject(actualPayload, "masked_property_preview");
- Map<String, Object> primaryProperties = MCPInteractionPayloads.getRequiredObject(maskedPropertyPreview, "primary");
- assertThat(String.valueOf(primaryProperties.get("from-x")), is("1"));
- assertThat(String.valueOf(primaryProperties.get("to-y")), is("3"));
- assertElicitationRequest(actualElicitationRequests);
- }
- }
-
@Test
void assertRejectSequenceResource() throws IOException, InterruptedException {
try (MCPInteractionClient interactionClient = createOpenedInteractionClient()) {