use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class RDBWriter method checkFormat.
@Override
public void checkFormat(JSONObject data) {
String name = data.getString("name");
data = data.getJSONObject("parameter");
if (name.equals(PluginName.Clichhouse_W)) {
// 1、clickhouse不支持修改删除,写入模式只能为insert into
String writeMode = data.getString("writeMode");
if (!"insert".equalsIgnoreCase(writeMode)) {
throw new DtCenterDefException("clickhouse 写入模式只能为insert into");
}
}
if (data.get("column") == null) {
throw new RdosDefineException("column 不能为空");
}
if (data.get("column") == null) {
throw new RdosDefineException("需要匹配映射");
}
if (!(data.get("column") instanceof JSONArray)) {
throw new RdosDefineException("column 必须为数组格式");
}
JSONArray column = data.getJSONArray("column");
if (column.isEmpty()) {
throw new RdosDefineException("需要匹配映射");
}
if (data.get("connection") == null) {
throw new RdosDefineException("connection 不能为空");
}
if (!(data.get("connection") instanceof JSONArray)) {
throw new RdosDefineException("connection 必须为数组格式");
}
JSONArray connections = data.getJSONArray("connection");
if (connections.isEmpty()) {
throw new RdosDefineException("connection 不能为空");
}
if (connections.size() > 1) {
throw new RdosDefineException("暂不支持多个数据源写入");
}
if (StringUtils.isEmpty(connections.getJSONObject(0).getString("jdbcUrl"))) {
throw new RdosDefineException("jdbcUrl 不能为空");
}
if (connections.getJSONObject(0).get("table") == null) {
throw new RdosDefineException("table 不能为空");
}
if (!(connections.getJSONObject(0).get("table") instanceof JSONArray)) {
throw new RdosDefineException("table 必须为数组格式");
}
JSONArray tables = connections.getJSONObject(0).getJSONArray("table");
if (tables.isEmpty()) {
throw new RdosDefineException("table 不能为空");
}
if (tables.size() > 1) {
throw new RdosDefineException("暂不支持多张表写入");
}
for (Object table : tables) {
if (!(table instanceof String)) {
throw new RdosDefineException("table 必须为字符串数组格式");
}
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class SyncJobCheck method checkRwiter.
private static void checkRwiter(JSONObject writer) {
CheckFormat checkFormat;
String writerName = writer.getString("name");
switch(writerName) {
case PluginName.MySQL_W:
case PluginName.Oracle_W:
case PluginName.SQLServer_W:
case PluginName.DB2_W:
case PluginName.GBase_W:
case PluginName.Clichhouse_W:
case PluginName.Polardb_for_MySQL_W:
case PluginName.PostgreSQL_W:
case PluginName.DM_W:
case PluginName.GREENPLUM_W:
case PluginName.KINGBASE_W:
case PluginName.Phoenix_W:
case PluginName.ADB_FOR_PG_W:
case PluginName.Phoenix5_W:
checkFormat = new RDBWriter();
break;
case PluginName.ES_W:
checkFormat = new EsWriter();
break;
case PluginName.HDFS_W:
checkFormat = new HDFSWriter();
break;
case PluginName.HBase_W:
checkFormat = new HBaseWriter();
break;
case PluginName.FTP_W:
checkFormat = new FtpWriter();
break;
case PluginName.MongoDB_W:
checkFormat = new MongoDbWriter();
break;
case PluginName.ODPS_W:
checkFormat = new OdpsWriter();
break;
case PluginName.Redis_W:
checkFormat = new RedisWriter();
break;
case PluginName.Stream_W:
checkFormat = new StreamWriter();
break;
case PluginName.CarbonData_W:
checkFormat = new CarbonDataWriter();
break;
case PluginName.Kudu_W:
checkFormat = new KuduWriter();
break;
case PluginName.AWS_S3_W:
checkFormat = new AwsS3Writer();
break;
case PluginName.INCEPTOR_W:
checkFormat = new InceptorWriter();
break;
default:
throw new RdosDefineException("未知的writer插件类型:" + writerName);
}
checkFormat.checkFormat(writer);
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class SyncJobCheck method checkJobData.
/**
* 检测 job 参数的合理性
* @param job
*/
private static void checkJobData(JSONObject job) {
if (JSONPath.eval(job, JobElementPath.SPEED) != null) {
long speed = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.SPEED)));
// -1是不限制速度
if (speed < -1) {
throw new RdosDefineException("速率 bytes 必须大于 0");
}
}
if (JSONPath.eval(job, JobElementPath.CHANNEL) != null) {
long channel = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.CHANNEL)));
if (channel <= 0) {
throw new RdosDefineException("并发度 channel 必须大于 0");
}
String name = (String) JSONPath.eval(job, "$.job.content[0].writer.name");
if (PluginName.Clichhouse_W.equals(name)) {
// 2、clickhouse不支持并发写入,当写入clickhouse时,作业并发数只能设置为1
if (1 != channel) {
throw new DtCenterDefException("clickhouse 作业并发数只能设置为1");
}
}
}
if (JSONPath.eval(job, JobElementPath.RECORD) != null) {
long record = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.RECORD)));
if (record < 0) {
throw new RdosDefineException("错误记录数 record 必须大于等于 0");
}
}
Object percentageObj = JSONPath.eval(job, JobElementPath.PERCENTAGE);
if (percentageObj != null) {
Double percentage = NumberUtils.toDouble(percentageObj.toString(), -1);
if (percentage < 0 || percentage > 100) {
throw new RdosDefineException("错误比率 percentage 必须介于 0-100");
}
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class SyncJobCheck method checkJobFormat.
/**
* 校验脚本模式下的 job 格式是否正确
* @param jobJsonStr
*/
public static void checkJobFormat(String jobJsonStr, Integer createModelType) {
try {
if (StringUtils.isEmpty(jobJsonStr)) {
throw new RdosDefineException("job内容不能为空");
}
// 检测 job 的完整性
JSONObject job = JSONObject.parseObject(jobJsonStr);
jobFormat.forEach((path, error) -> {
if (!JSONPath.contains(job, path)) {
throw new RdosDefineException(error);
}
});
checkJobData(job);
// 检查各个reader和writer的正确性
if (TaskCreateModelType.GUIDE.getType().equals(createModelType)) {
checkReader((JSONObject) JSONPath.eval(job, JobElementPath.READER));
checkRwiter((JSONObject) JSONPath.eval(job, JobElementPath.WRITER));
}
} catch (JSONException e) {
throw new RdosDefineException(String.format("json格式解析失败,原因是: %s", e.getMessage()));
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class CarbonDataReader method checkFormat.
@Override
public void checkFormat(JSONObject data) {
JSONObject parameter = data.getJSONObject("parameter");
if (parameter == null) {
throw new RdosDefineException("parameter 不能为空");
} else {
String path = parameter.getString("path");
if (StringUtils.isEmpty(path)) {
throw new RdosDefineException("目标源的表路径不能为空");
}
String table = parameter.getString("table");
if (StringUtils.isEmpty(table)) {
throw new RdosDefineException("输入源的表名不能为空");
}
String database = parameter.getString("database");
if (StringUtils.isEmpty(database)) {
throw new RdosDefineException("输入源的数据库名不能为空");
}
JSONArray columnArray = parameter.getJSONArray("column");
if (columnArray == null || columnArray.size() == 0) {
throw new RdosDefineException("输入源的列名列表不能为空");
}
for (int i = 0; i < columnArray.size(); i++) {
JSONObject obj = columnArray.getJSONObject(i);
if (obj == null || StringUtils.isEmpty(obj.getString("name")) || StringUtils.isEmpty(obj.getString("type"))) {
throw new RdosDefineException("输入源列名格式错误");
}
}
}
}
Aggregations