in tsdbreader/src/main/java/com/alibaba/datax/plugin/reader/tsdbreader/TSDBReader.java [40:156]
public void init() {
this.originalConfig = super.getPluginJobConf();
String type = originalConfig.getString(Key.SINK_DB_TYPE, Key.TYPE_DEFAULT_VALUE);
if (StringUtils.isBlank(type)) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.SINK_DB_TYPE + "] is not set.");
}
if (!Key.TYPE_SET.contains(type)) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.SINK_DB_TYPE + "] should be one of [" +
JSON.toJSONString(Key.TYPE_SET) + "].");
}
String address = originalConfig.getString(Key.ENDPOINT);
if (StringUtils.isBlank(address)) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.ENDPOINT + "] is not set.");
}
String username = originalConfig.getString(Key.USERNAME, null);
if (StringUtils.isBlank(username)) {
LOG.warn("The parameter [" + Key.USERNAME + "] is blank.");
}
String password = originalConfig.getString(Key.PASSWORD, null);
if (StringUtils.isBlank(password)) {
LOG.warn("The parameter [" + Key.PASSWORD + "] is blank.");
}
// tagK / field could be empty
if ("TSDB".equals(type)) {
List<String> columns = originalConfig.getList(Key.COLUMN, String.class);
if (columns == null || columns.isEmpty()) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.COLUMN + "] is not set.");
}
} else {
List<String> columns = originalConfig.getList(Key.COLUMN, String.class);
if (columns == null || columns.isEmpty()) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.COLUMN + "] is not set.");
}
for (String specifyKey : Constant.MUST_CONTAINED_SPECIFY_KEYS) {
boolean containSpecifyKey = false;
for (String column : columns) {
if (column.startsWith(specifyKey)) {
containSpecifyKey = true;
break;
}
}
if (!containSpecifyKey) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.COLUMN + "] should contain "
+ JSON.toJSONString(Constant.MUST_CONTAINED_SPECIFY_KEYS) + ".");
}
}
final List<String> metrics = originalConfig.getList(Key.METRIC, String.class);
if (metrics == null || metrics.isEmpty()) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.METRIC + "] is not set.");
}
}
Integer splitIntervalMs = originalConfig.getInt(Key.INTERVAL_DATE_TIME,
Key.INTERVAL_DATE_TIME_DEFAULT_VALUE);
if (splitIntervalMs <= 0) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.INTERVAL_DATE_TIME + "] should be great than zero.");
}
Boolean isCombine = originalConfig.getBool(Key.COMBINE, Key.COMBINE_DEFAULT_VALUE);
SimpleDateFormat format = new SimpleDateFormat(Constant.DEFAULT_DATA_FORMAT);
String startTime = originalConfig.getString(Key.BEGIN_DATE_TIME);
Long startDate;
if (startTime == null || startTime.trim().length() == 0) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.BEGIN_DATE_TIME + "] is not set.");
} else {
try {
startDate = format.parse(startTime).getTime();
} catch (ParseException e) {
throw DataXException.asDataXException(TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.BEGIN_DATE_TIME +
"] needs to conform to the [" + Constant.DEFAULT_DATA_FORMAT + "] format.");
}
}
String endTime = originalConfig.getString(Key.END_DATE_TIME);
Long endDate;
if (endTime == null || endTime.trim().length() == 0) {
throw DataXException.asDataXException(
TSDBReaderErrorCode.REQUIRED_VALUE,
"The parameter [" + Key.END_DATE_TIME + "] is not set.");
} else {
try {
endDate = format.parse(endTime).getTime();
} catch (ParseException e) {
throw DataXException.asDataXException(TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.END_DATE_TIME +
"] needs to conform to the [" + Constant.DEFAULT_DATA_FORMAT + "] format.");
}
}
if (startDate >= endDate) {
throw DataXException.asDataXException(TSDBReaderErrorCode.ILLEGAL_VALUE,
"The parameter [" + Key.BEGIN_DATE_TIME +
"] should be less than the parameter [" + Key.END_DATE_TIME + "].");
}
}