use of com.dtstack.taier.develop.common.template.Setting in project Taier by DTStack.
the class DatasourceService method getSyncSql.
/**
* 配置或修改离线任务
*
* @param isFilter 获取数据同步脚本时候是否进行过滤用户名密码操作
* @return
* @throws IOException
*/
public String getSyncSql(final TaskResourceParam param, boolean isFilter) {
// 来源集合
final Map<String, Object> sourceMap = param.getSourceMap();
// 目标集合
final Map<String, Object> targetMap = param.getTargetMap();
// 流控、错误集合
final Map<String, Object> settingMap = param.getSettingMap();
try {
this.setReaderJson(sourceMap, param.getId(), param.getTenantId(), isFilter);
this.setWriterJson(targetMap, param.getId(), param.getTenantId(), isFilter);
Reader reader = null;
Writer writer = null;
Setting setting = null;
final Integer sourceType = Integer.parseInt(sourceMap.get("dataSourceType").toString());
final Integer targetType = Integer.parseInt(targetMap.get("dataSourceType").toString());
if (!this.checkDataSourcePermission(sourceType, EDataSourcePermission.READ.getType())) {
throw new RdosDefineException(ErrorCode.SOURCE_CAN_NOT_AS_INPUT);
}
if (!this.checkDataSourcePermission(targetType, EDataSourcePermission.WRITE.getType())) {
throw new RdosDefineException(ErrorCode.SOURCE_CAN_NOT_AS_OUTPUT);
}
final List<Long> sourceIds = (List<Long>) sourceMap.get("sourceIds");
final List<Long> targetIds = (List<Long>) targetMap.get("sourceIds");
reader = this.syncReaderBuild(sourceType, sourceMap, sourceIds);
writer = this.syncWriterBuild(targetType, targetIds, targetMap, reader);
setting = PublicUtil.objectToObject(settingMap, DefaultSetting.class);
// 检查有效性
if (writer instanceof HiveWriter) {
final HiveWriter hiveWriter = (HiveWriter) writer;
if (!hiveWriter.isValid()) {
throw new RdosDefineException(hiveWriter.getErrMsg());
}
}
if (param.getCreateModel() == TaskCreateModelType.TEMPLATE.getType()) {
// 脚本模式直接返回
return this.getJobText(this.putDefaultEmptyValueForReader(sourceType, reader), this.putDefaultEmptyValueForWriter(targetType, writer), this.putDefaultEmptyValueForSetting(setting));
}
// 获得数据同步job.xml的配置
final String jobXml = this.getJobText(reader, writer, setting);
final String parserXml = this.getParserText(sourceMap, targetMap, settingMap);
final JSONObject sql = new JSONObject(3);
sql.put("job", jobXml);
sql.put("parser", parserXml);
sql.put("createModel", TaskCreateModelType.GUIDE.getType());
this.batchTaskParamService.checkParams(this.batchTaskParamService.checkSyncJobParams(sql.toJSONString()), param.getTaskVariables());
return sql.toJSONString();
} catch (final Exception e) {
LOGGER.error("", e);
throw new RdosDefineException("解析同步任务失败: " + e.getMessage(), ErrorCode.SERVER_EXCEPTION);
}
}
use of com.dtstack.taier.develop.common.template.Setting in project Taier by DTStack.
the class JobTemplate method toJobJsonString.
public String toJobJsonString() {
Reader reader = newReader();
Writer writer = newWrite();
Setting setting = newSetting();
JSONObject content = new JSONObject(2);
content.put("reader", reader.toReaderJson());
content.put("writer", writer.toWriterJson());
JSONObject jobJson = new JSONObject(2);
jobJson.put("content", Lists.newArrayList(content));
jobJson.put("setting", setting.toSettingJson());
StringBuilder job = new StringBuilder();
job.append("{ \"job\":");
job.append(jobJson.toJSONString());
job.append(" }");
return job.toString();
}
Aggregations