This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 f6ad3b27f29 Add new pipeline exceptions to handle related exceptions
(#23539)
f6ad3b27f29 is described below
commit f6ad3b27f29e9e4c004322d2a6228fdbe52d7a4e
Author: Xinze Guo <[email protected]>
AuthorDate: Fri Jan 13 14:42:38 2023 +0800
Add new pipeline exceptions to handle related exceptions (#23539)
* Add new pipeline exception to handle related exceptions
* Fix codestyle
* Rename
---
.../user-manual/error-code/sql-error-code.cn.md | 3 ++
.../user-manual/error-code/sql-error-code.en.md | 3 ++
.../core/api/impl/AbstractPipelineJobAPIImpl.java | 7 +++--
.../MissingRequiredTargetDatabaseException.java | 33 ++++++++++++++++++++++
.../exception/job/ModeConfigNotFoundException.java | 33 ++++++++++++++++++++++
.../job/UnsupportedModeTypeException.java | 33 ++++++++++++++++++++++
.../handler/update/MigrateTableUpdater.java | 5 ++--
7 files changed, 112 insertions(+), 5 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 00f851fe8c8..6ca80d7875d 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
@@ -98,6 +98,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| SQL State | Vendor Code | 错误信息 |
| --------- | ----------- | ------ |
| 44000 | 18002 | Altered process configuration does not exist. |
+| 44000 | 18003 | Mode configuration does not exist. |
+| 44000 | 18004 | Target database name is null. You could define it
in DistSQL or select a database. |
| HY000 | 18020 | Failed to get DDL for table \`%s\`. |
| 42S01 | 18030 | Duplicate storage unit names \`%s\`. |
| 42S02 | 18031 | Storage units names \`%s\` do not exist. |
@@ -106,6 +108,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 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\`. |
+| 0A000 | 18054 | Unsupported mode type \`%s\`. |
| HY000 | 18080 | Can not find pipeline job \`%s\`. |
| HY000 | 18081 | Job has already started. |
| HY000 | 18082 | Sharding count of job \`%s\` is 0. |
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 38e93e74e8f..6e3f28427d9 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
@@ -98,6 +98,8 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| SQL State | Vendor Code | Reason |
| --------- | ----------- | ------ |
| 44000 | 18002 | Altered process configuration does not exist. |
+| 44000 | 18003 | Mode configuration does not exist. |
+| 44000 | 18004 | Target database name is null. You could define it
in DistSQL or select a database. |
| HY000 | 18020 | Failed to get DDL for table \`%s\`. |
| 42S01 | 18030 | Duplicate storage unit names \`%s\`. |
| 42S02 | 18031 | Storage units names \`%s\` do not exist. |
@@ -106,6 +108,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 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\`. |
+| 0A000 | 18054 | Unsupported mode type \`%s\`. |
| HY000 | 18080 | Can not find pipeline job \`%s\`. |
| HY000 | 18081 | Job has already started. |
| HY000 | 18082 | Sharding count of job \`%s\` is 0. |
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
index d758bda0568..8257ce1accf 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/AbstractPipelineJobAPIImpl.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.data.pipeline.core.api.impl;
-import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import
org.apache.shardingsphere.data.pipeline.api.config.job.PipelineJobConfiguration;
@@ -28,9 +27,11 @@ import
org.apache.shardingsphere.data.pipeline.core.api.GovernanceRepositoryAPI;
import org.apache.shardingsphere.data.pipeline.core.api.PipelineAPIFactory;
import org.apache.shardingsphere.data.pipeline.core.api.PipelineJobAPI;
import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext;
+import
org.apache.shardingsphere.data.pipeline.core.exception.job.ModeConfigNotFoundException;
import
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobCreationWithInvalidShardingCountException;
import
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobHasAlreadyStartedException;
import
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobNotFoundException;
+import
org.apache.shardingsphere.data.pipeline.core.exception.job.UnsupportedModeTypeException;
import org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtils;
import
org.apache.shardingsphere.data.pipeline.core.metadata.node.PipelineMetaDataNode;
import
org.apache.shardingsphere.data.pipeline.spi.barrier.PipelineDistributedBarrier;
@@ -72,8 +73,8 @@ public abstract class AbstractPipelineJobAPIImpl implements
PipelineJobAPI {
protected void checkModeConfig() {
ModeConfiguration modeConfig = PipelineContext.getModeConfig();
- Preconditions.checkNotNull(modeConfig, "Mode configuration is
required.");
- Preconditions.checkArgument("Cluster".equals(modeConfig.getType()),
"Mode must be `Cluster`.");
+ ShardingSpherePreconditions.checkNotNull(modeConfig,
ModeConfigNotFoundException::new);
+
ShardingSpherePreconditions.checkState("Cluster".equals(modeConfig.getType()),
() -> new UnsupportedModeTypeException(modeConfig.getType()));
}
private Stream<JobBriefInfo> getJobBriefInfos() {
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
new file mode 100644
index 00000000000..c9ffbf2c2c3
--- /dev/null
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/MissingRequiredTargetDatabaseException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.data.pipeline.core.exception.job;
+
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Missing required target database exception.
+ */
+public final class MissingRequiredTargetDatabaseException extends
PipelineSQLException {
+
+ private static final long serialVersionUID = -1557471818392592482L;
+
+ public MissingRequiredTargetDatabaseException() {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Target database name
is null. You could define it in DistSQL or select a database.");
+ }
+}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/ModeConfigNotFoundException.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/ModeConfigNotFoundException.java
new file mode 100644
index 00000000000..19c93e35237
--- /dev/null
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/ModeConfigNotFoundException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.data.pipeline.core.exception.job;
+
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Mode config not found exception.
+ */
+public final class ModeConfigNotFoundException extends PipelineSQLException {
+
+ private static final long serialVersionUID = -903289953649758722L;
+
+ public ModeConfigNotFoundException() {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "Mode configuration
does not exist.");
+ }
+}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/UnsupportedModeTypeException.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/UnsupportedModeTypeException.java
new file mode 100644
index 00000000000..240a0ea0323
--- /dev/null
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/UnsupportedModeTypeException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.data.pipeline.core.exception.job;
+
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Unsupported mode type exception.
+ */
+public final class UnsupportedModeTypeException extends PipelineSQLException {
+
+ private static final long serialVersionUID = -4100671584682823997L;
+
+ public UnsupportedModeTypeException(final String modeType) {
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 54,
String.format("Unsupported mode type `%s`.", modeType));
+ }
+}
diff --git
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
index 659c09016ab..0b6bc4d25af 100644
---
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
+++
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/MigrateTableUpdater.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.migration.distsql.handler.update;
-import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.data.pipeline.api.pojo.CreateMigrationJobParameter;
+import
org.apache.shardingsphere.data.pipeline.core.exception.job.MissingRequiredTargetDatabaseException;
import
org.apache.shardingsphere.data.pipeline.scenario.migration.api.impl.MigrationJobAPI;
import org.apache.shardingsphere.distsql.handler.update.RALUpdater;
+import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import
org.apache.shardingsphere.migration.distsql.statement.MigrateTableStatement;
/**
@@ -35,7 +36,7 @@ public final class MigrateTableUpdater implements
RALUpdater<MigrateTableStateme
@Override
public void executeUpdate(final String databaseName, final
MigrateTableStatement sqlStatement) {
String targetDatabaseName = null ==
sqlStatement.getTargetDatabaseName() ? databaseName :
sqlStatement.getTargetDatabaseName();
- Preconditions.checkNotNull(targetDatabaseName, "Target database name
is null. You could define it in DistSQL or select a database.");
+ ShardingSpherePreconditions.checkNotNull(targetDatabaseName,
MissingRequiredTargetDatabaseException::new);
jobAPI.createJobAndStart(new CreateMigrationJobParameter(
sqlStatement.getSourceResourceName(),
sqlStatement.getSourceSchemaName(), sqlStatement.getSourceTableName(),
targetDatabaseName, sqlStatement.getTargetTableName()));
}