This is an automated email from the ASF dual-hosted git repository.
tyrantlucifer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 205f78258 [Improve][Connector-V2][Redis] Unified exception for redis
source & sink exception (#3517)
205f78258 is described below
commit 205f782585ebefa0707b8359318ccc943b6f2dec
Author: Tyrantlucifer <[email protected]>
AuthorDate: Thu Nov 24 10:51:25 2022 +0800
[Improve][Connector-V2][Redis] Unified exception for redis source & sink
exception (#3517)
* [Improve][Connector-V2][Redis] Unified exception for redis source & sink
exception
* [Improve][Connector-V2][Redis] Fix code style
---
.../seatunnel/redis/config/RedisParameters.java | 12 ++++++--
.../redis/exception/RedisConnectorException.java | 35 ++++++++++++++++++++++
.../connectors/seatunnel/redis/sink/RedisSink.java | 6 +++-
.../seatunnel/redis/source/RedisSource.java | 10 +++++--
4 files changed, 57 insertions(+), 6 deletions(-)
diff --git
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/RedisParameters.java
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/RedisParameters.java
index f4190aadb..1e6c986e1 100644
---
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/RedisParameters.java
+++
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/config/RedisParameters.java
@@ -17,6 +17,9 @@
package org.apache.seatunnel.connectors.seatunnel.redis.config;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;
+
import org.apache.seatunnel.shade.com.typesafe.config.Config;
import lombok.Data;
@@ -88,7 +91,8 @@ public class RedisParameters implements Serializable {
String dataType = config.getString(RedisConfig.DATA_TYPE.key());
this.redisDataType = RedisDataType.valueOf(dataType.toUpperCase());
} catch (IllegalArgumentException e) {
- throw new RuntimeException("Redis source connector only support
these data types [key, hash, list, set, zset]", e);
+ throw new
RedisConnectorException(CommonErrorCode.UNSUPPORTED_DATA_TYPE,
+ "Redis source connector only support these data types
[key, hash, list, set, zset]", e);
}
}
@@ -111,7 +115,8 @@ public class RedisParameters implements Serializable {
for (String redisNode : redisNodes) {
String[] splits = redisNode.split(":");
if (splits.length != 2) {
- throw new IllegalArgumentException("Invalid redis
node information," +
+ throw new
RedisConnectorException(CommonErrorCode.ILLEGAL_ARGUMENT,
+ "Invalid redis node information," +
"redis node information must like as the
following: [host:port]");
}
HostAndPort hostAndPort = new HostAndPort(splits[0],
Integer.parseInt(splits[1]));
@@ -130,7 +135,8 @@ public class RedisParameters implements Serializable {
return new JedisWrapper(jedisCluster);
default:
// do nothing
- throw new IllegalArgumentException("Not support this redis
mode");
+ throw new
RedisConnectorException(CommonErrorCode.UNSUPPORTED_OPERATION,
+ "Not support this redis mode");
}
}
}
diff --git
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/exception/RedisConnectorException.java
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/exception/RedisConnectorException.java
new file mode 100644
index 000000000..27f2970d2
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/exception/RedisConnectorException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.redis.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class RedisConnectorException extends SeaTunnelRuntimeException {
+ public RedisConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage) {
+ super(seaTunnelErrorCode, errorMessage);
+ }
+
+ public RedisConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
String errorMessage, Throwable cause) {
+ super(seaTunnelErrorCode, errorMessage, cause);
+ }
+
+ public RedisConnectorException(SeaTunnelErrorCode seaTunnelErrorCode,
Throwable cause) {
+ super(seaTunnelErrorCode, cause);
+ }
+}
diff --git
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/sink/RedisSink.java
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/sink/RedisSink.java
index 43d01414d..f3ecf8632 100644
---
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/sink/RedisSink.java
+++
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/sink/RedisSink.java
@@ -18,6 +18,7 @@
package org.apache.seatunnel.connectors.seatunnel.redis.sink;
import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.api.sink.SinkWriter;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
@@ -30,6 +31,7 @@ import
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
import
org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisConfig;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters;
+import
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -53,7 +55,9 @@ public class RedisSink extends
AbstractSimpleSink<SeaTunnelRow, Void> {
this.pluginConfig = pluginConfig;
CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig,
RedisConfig.HOST.key(), RedisConfig.PORT.key(), RedisConfig.KEY.key(),
RedisConfig.DATA_TYPE.key());
if (!result.isSuccess()) {
- throw new PrepareFailException(getPluginName(), PluginType.SINK,
result.getMsg());
+ throw new
RedisConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+ String.format("PluginName: %s, PluginType: %s, Message:
%s",
+ getPluginName(), PluginType.SINK,
result.getMsg()));
}
this.redisParameters.buildWithConfig(pluginConfig);
}
diff --git
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSource.java
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSource.java
index 1219599ae..2447e36c6 100644
---
a/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSource.java
+++
b/seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSource.java
@@ -18,6 +18,7 @@
package org.apache.seatunnel.connectors.seatunnel.redis.source;
import org.apache.seatunnel.api.common.PrepareFailException;
+import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.serialization.DeserializationSchema;
import org.apache.seatunnel.api.source.Boundedness;
import org.apache.seatunnel.api.source.SeaTunnelSource;
@@ -33,6 +34,7 @@ import
org.apache.seatunnel.connectors.seatunnel.common.source.AbstractSingleSpl
import
org.apache.seatunnel.connectors.seatunnel.common.source.SingleSplitReaderContext;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisConfig;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters;
+import
org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;
import org.apache.seatunnel.format.json.JsonDeserializationSchema;
import org.apache.seatunnel.shade.com.typesafe.config.Config;
@@ -54,14 +56,18 @@ public class RedisSource extends
AbstractSingleSplitSource<SeaTunnelRow> {
public void prepare(Config pluginConfig) throws PrepareFailException {
CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig,
RedisConfig.HOST.key(), RedisConfig.PORT.key(), RedisConfig.KEY_PATTERN.key(),
RedisConfig.DATA_TYPE.key());
if (!result.isSuccess()) {
- throw new PrepareFailException(getPluginName(), PluginType.SOURCE,
result.getMsg());
+ throw new
RedisConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+ String.format("PluginName: %s, PluginType: %s, Message:
%s",
+ getPluginName(), PluginType.SOURCE, result.getMsg()));
}
this.redisParameters.buildWithConfig(pluginConfig);
// TODO: use format SPI
// default use json format
if (pluginConfig.hasPath(RedisConfig.FORMAT.key())) {
if (!pluginConfig.hasPath(SeaTunnelSchema.SCHEMA.key())) {
- throw new PrepareFailException(getPluginName(),
PluginType.SOURCE, "Must config schema when format parameter been config");
+ throw new
RedisConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+ String.format("PluginName: %s, PluginType: %s,
Message: %s",
+ getPluginName(), PluginType.SOURCE, "Must config
schema when format parameter been config"));
}
Config schema =
pluginConfig.getConfig(SeaTunnelSchema.SCHEMA.key());