You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/09/20 15:46:23 UTC

[shardingsphere] branch master updated: Refactor DropMigrationSourceResourceException (#21097)

This is an automated email from the ASF dual-hosted git repository.

yx9o 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 8e5f5a82c6a Refactor DropMigrationSourceResourceException (#21097)
8e5f5a82c6a is described below

commit 8e5f5a82c6a93b6db9d602209436964ae9acead3
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Sep 20 23:46:14 2022 +0800

    Refactor DropMigrationSourceResourceException (#21097)
---
 .../content/user-manual/error-code/sql-error-code.cn.md       |  2 ++
 .../content/user-manual/error-code/sql-error-code.en.md       |  2 ++
 .../connection/DropMigrationSourceResourceException.java      | 11 ++++++++---
 .../data/pipeline/scenario/migration/MigrationJobAPIImpl.java |  5 ++---
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 8dd77285e90..13842ee5484 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -92,8 +92,10 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 44000     | 18001       | Created process configuration already existed |
 | 44000     | 18002       | Altered process configuration does not exist |
 | HY000     | 18020       | Failed to get DDL for table \`%s\` |
+| 42S02     | 18031       | Resource names \`%s\` do not exist |
 | HY000     | 18050       | Before data record is \`%s\`, after data record is \`%s\` |
 | 08000     | 18051       | Data check table \`%s\` failed |
+| 0A000     | 18052       | Unsupported pipeline database type \`%s\` |
 | 0A000     | 18053       | Unsupported CRC32 data consistency calculate algorithm with database type \`%s\` |
 | HY000     | 18080       | Can not find pipeline job \`%s\` |
 | HY000     | 18081       | Job has already started |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 45d5682f29d..849e3e63af5 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -92,8 +92,10 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 44000     | 18001       | Created process configuration already existed |
 | 44000     | 18002       | Altered process configuration does not exist |
 | HY000     | 18020       | Failed to get DDL for table \`%s\` |
+| 42S02     | 18031       | Resource names \`%s\` do not exist |
 | HY000     | 18050       | Before data record is \`%s\`, after data record is \`%s\` |
 | 08000     | 18051       | Data check table \`%s\` failed |
+| 0A000     | 18052       | Unsupported pipeline database type \`%s\` |
 | 0A000     | 18053       | Unsupported CRC32 data consistency calculate algorithm with database type \`%s\` |
 | HY000     | 18080       | Can not find pipeline job \`%s\` |
 | HY000     | 18081       | Job has already started |
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/DropMigrationSourceResourceException.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/DropMigrationSourceResourceException.java
index 4fb7726d183..3981fe637fa 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/DropMigrationSourceResourceException.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/DropMigrationSourceResourceException.java
@@ -17,14 +17,19 @@
 
 package org.apache.shardingsphere.data.pipeline.core.exception.connection;
 
+import org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+import java.util.Collection;
+
 /**
  * Drop migration source resource exception.
  */
-public final class DropMigrationSourceResourceException extends RuntimeException {
+public final class DropMigrationSourceResourceException extends PipelineSQLException {
     
     private static final long serialVersionUID = -7133815271017274299L;
     
-    public DropMigrationSourceResourceException(final String message) {
-        super(message);
+    public DropMigrationSourceResourceException(final Collection<String> resourceNames) {
+        super(XOpenSQLState.NOT_FOUND, 31, "Resource names `%s` do not exist", resourceNames);
     }
 }
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
index e2ad1584cb0..7b546d2f9b1 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
@@ -85,6 +85,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
 import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
 import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
@@ -394,9 +395,7 @@ public final class MigrationJobAPIImpl extends AbstractPipelineJobAPIImpl implem
     public void dropMigrationSourceResources(final Collection<String> resourceNames) {
         Map<String, DataSourceProperties> metaDataDataSource = dataSourcePersistService.load(getJobType());
         List<String> noExistResources = resourceNames.stream().filter(each -> !metaDataDataSource.containsKey(each)).collect(Collectors.toList());
-        if (!noExistResources.isEmpty()) {
-            throw new DropMigrationSourceResourceException(String.format("Resource names %s not exist.", resourceNames));
-        }
+        ShardingSpherePreconditions.checkState(noExistResources.isEmpty(), () -> new DropMigrationSourceResourceException(resourceNames));
         for (String each : resourceNames) {
             metaDataDataSource.remove(each);
         }