Skip to content

Commit

Permalink
use common error code
Browse files Browse the repository at this point in the history
  • Loading branch information
lhyundeadsoul committed Jan 9, 2023
1 parent 294a1b4 commit 80da544
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;

public enum TDengineConnectorErrorCode implements SeaTunnelErrorCode {
SQL_OPERATION_FAILED("TDengine-01", "execute sql failed"),
CONNECTION_FAILED("TDengine-02", "connection operation failed"),
TYPE_MAPPER_FAILED("TDengine-03", "type mapping failed"),
READER_FAILED("TDengine-04", "reader operation failed"),
WRITER_FAILED("TDengine-05", "writer operation failed");
;

private final String code;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
import org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorException;

import org.apache.seatunnel.shade.com.typesafe.config.Config;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void write(SeaTunnelRow element) {
StringUtils.join(convertDataType(metrics), ","));
final int rowCount = statement.executeUpdate(sql);
if (rowCount == 0) {
Throwables.propagateIfPossible(new TDengineConnectorException(TDengineConnectorErrorCode.SQL_OPERATION_FAILED, "insert error:" + element));
Throwables.propagateIfPossible(new TDengineConnectorException(CommonErrorCode.SQL_OPERATION_FAILED, "insert error:" + element));
}
}
}
Expand All @@ -99,7 +99,7 @@ public void close() {
try {
conn.close();
} catch (SQLException e) {
throw new TDengineConnectorException(TDengineConnectorErrorCode.CONNECTION_FAILED, "TDengine writer connection close failed", e);
throw new TDengineConnectorException(CommonErrorCode.WRITER_OPERATION_FAILED, "TDengine writer connection close failed", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig.buildSourceConfig;

import org.apache.seatunnel.api.common.PrepareFailException;
import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.source.Boundedness;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.api.source.SourceReader;
Expand All @@ -36,8 +37,8 @@
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.config.CheckConfigUtil;
import org.apache.seatunnel.common.config.CheckResult;
import org.apache.seatunnel.common.constants.PluginType;
import org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorException;
import org.apache.seatunnel.connectors.seatunnel.tdengine.state.TDengineSourceState;
import org.apache.seatunnel.connectors.seatunnel.tdengine.typemapper.TDengineTypeMapper;

Expand Down Expand Up @@ -78,7 +79,7 @@ public String getPluginName() {
public void prepare(Config pluginConfig) throws PrepareFailException {
CheckResult result = CheckConfigUtil.checkAllExists(pluginConfig, URL, DATABASE, STABLE, USERNAME, PASSWORD);
if (!result.isSuccess()) {
throw new PrepareFailException(getPluginName(), PluginType.SOURCE, "TDengine connection require url/database/stable/username/password. All of these must not be empty.");
throw new TDengineConnectorException(SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED, "TDengine connection require url/database/stable/username/password. All of these must not be empty.");
}
tdengineSourceConfig = buildSourceConfig(pluginConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.seatunnel.api.source.Collector;
import org.apache.seatunnel.api.source.SourceReader;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorException;

import com.google.common.collect.Sets;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void pollNext(Collector<SeaTunnelRow> collector) throws InterruptedExcept
try {
read(split, collector);
} catch (Exception e) {
throw new TDengineConnectorException(TDengineConnectorErrorCode.READER_FAILED, "TDengine split read error", e);
throw new TDengineConnectorException(CommonErrorCode.READER_OPERATION_FAILED, "TDengine split read error", e);
}
});
}
Expand All @@ -97,7 +97,7 @@ public void open(){
try {
conn = DriverManager.getConnection(jdbcUrl, connProps);
} catch (SQLException e) {
throw new TDengineConnectorException(TDengineConnectorErrorCode.CONNECTION_FAILED, "get TDengine connection failed:" + jdbcUrl);
throw new TDengineConnectorException(CommonErrorCode.READER_OPERATION_FAILED, "get TDengine connection failed:" + jdbcUrl);
}
}

Expand All @@ -108,7 +108,7 @@ public void close() {
conn.close();
}
} catch (SQLException e) {
throw new TDengineConnectorException(TDengineConnectorErrorCode.CONNECTION_FAILED, "TDengine reader connection close failed", e);
throw new TDengineConnectorException(CommonErrorCode.READER_OPERATION_FAILED, "TDengine reader connection close failed", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import org.apache.seatunnel.api.source.SourceEvent;
import org.apache.seatunnel.api.source.SourceSplitEnumerator;
import org.apache.seatunnel.api.source.SourceSplitEnumerator.Context;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.config.TDengineSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorException;
import org.apache.seatunnel.connectors.seatunnel.tdengine.state.TDengineSourceState;

Expand Down Expand Up @@ -194,7 +193,7 @@ public void close() {
conn.close();
}
} catch (SQLException e) {
throw new TDengineConnectorException(TDengineConnectorErrorCode.CONNECTION_FAILED, "TDengine split_enumerator connection close failed", e);
throw new TDengineConnectorException(CommonErrorCode.READER_OPERATION_FAILED, "TDengine split_enumerator connection close failed", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.seatunnel.api.table.type.LocalTimeType;
import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorErrorCode;
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.connectors.seatunnel.tdengine.exception.TDengineConnectorException;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -145,7 +145,7 @@ public static SeaTunnelDataType<?> mapping(String tdengineType) {
case TDENGINE_GEOMETRY:
case TDENGINE_UNKNOWN:
default:
throw new TDengineConnectorException(TDengineConnectorErrorCode.TYPE_MAPPER_FAILED, String.format(
throw new TDengineConnectorException(CommonErrorCode.UNSUPPORTED_DATA_TYPE, String.format(
"Doesn't support TDENGINE type '%s' on column '%s' yet.",
tdengineType));
}
Expand Down

0 comments on commit 80da544

Please sign in to comment.