use of com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO in project Taier by DTStack.
the class BatchFunctionService method addOrUpdateFunction.
/**
* 添加函数
*/
@Transactional(rollbackFor = Exception.class)
public TaskCatalogueVO addOrUpdateFunction(BatchFunction batchFunction, Long resourceId, Long tenantId) {
if (!PublicUtil.matcher(batchFunction.getName(), PatternConstant.FUNCTION_PATTERN)) {
throw new RdosDefineException("注意名称只允许存在字母、数字、下划线、横线,hive函数不支持大写字母", ErrorCode.NAME_FORMAT_ERROR);
}
if (resourceId == null) {
throw new RdosDefineException("新增函数必须添加资源", ErrorCode.INVALID_PARAMETERS);
} else {
checkResourceType(resourceId);
}
try {
// id小于0走新增逻辑
if (Objects.isNull(batchFunction.getId()) || batchFunction.getId() < 1) {
// 名称重复校验
batchTaskService.checkName(batchFunction.getName(), CatalogueType.CUSTOM_FUNCTION.name(), null, 1, 0L);
batchFunction.setGmtCreate(Timestamp.valueOf(LocalDateTime.now()));
}
batchFunction.setType(FuncType.CUSTOM.getType());
batchFunction.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
addOrUpdate(batchFunction);
addOrUpdateFunctionResource(batchFunction, resourceId);
// 添加类目关系
TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO();
taskCatalogueVO.setId(batchFunction.getId());
taskCatalogueVO.setName(batchFunction.getName());
taskCatalogueVO.setType("file");
taskCatalogueVO.setLevel(null);
taskCatalogueVO.setChildren(null);
taskCatalogueVO.setParentId(batchFunction.getNodePid());
String username = userService.getUserName(batchFunction.getCreateUserId());
taskCatalogueVO.setCreateUser(username);
return taskCatalogueVO;
} catch (Exception e) {
LOGGER.error("addFunction, functions={},resource={},tenantId={}", JSONObject.toJSONString(batchFunction), resourceId, tenantId);
LOGGER.error(e.getMessage(), e);
if (e instanceof RdosDefineException) {
throw e;
} else {
throw new RdosDefineException(String.format("添加函数失败:%s", e.getMessage()));
}
}
}
use of com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO in project Taier by DTStack.
the class BatchTaskService method addOrUpdateTask.
/**
* 数据开发-新建/更新 任务
*
* @param param 任务
* @return
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @author toutian
*/
@Transactional(rollbackFor = Exception.class)
public TaskCatalogueVO addOrUpdateTask(final TaskResourceParam param) {
// 检查密码回填操作
this.checkFillPassword(param);
// 数据预处理 主要是数据同步任务 生成sqlText
this.checkBeforeUpdateTask(param);
if (StringUtils.isNotBlank(param.getScheduleConf())) {
// 处理调度配置
JSONObject schduleConf = JSON.parseObject(param.getScheduleConf());
if (schduleConf.get("isExpire") != null && "false".equals(schduleConf.get("isExpire").toString())) {
schduleConf.replace("isLastInstance", true);
param.setScheduleConf(schduleConf.toString());
}
param.setPeriodType(schduleConf.getInteger("periodType"));
}
if (param.getId() > 0 && param.getTaskType().equals(EScheduleJobType.WORK_FLOW.getVal())) {
// 更新子任务间的依赖关系
final String sqlText = param.getSqlText();
if (StringUtils.isNotBlank(sqlText)) {
final Map<Long, List<Long>> relations = this.parseTaskRelationsFromSqlText(sqlText);
// 判断任务依赖是否成环
if (MapUtils.isNotEmpty(relations)) {
checkIsLoopByList(relations);
}
for (final Map.Entry<Long, List<Long>> entry : relations.entrySet()) {
List<BatchTask> dependencyTasks = getTaskByIds(entry.getValue());
dependencyTasks.stream().forEach(task -> {
task.setTenantId(param.getTenantId());
});
batchTaskTaskService.addOrUpdateTaskTask(entry.getKey(), dependencyTasks);
}
}
}
BatchTaskBatchVO task = PublicUtil.objectToObject(param, BatchTaskBatchVO.class);
task.setModifyUserId(param.getUserId());
task.setVersion(Objects.isNull(param.getVersion()) ? 0 : param.getVersion());
task.parsePeriodType();
task = this.updateTask(task, param.getEditBaseInfo());
TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO(task, task.getNodePid());
// 强行置为更新
taskCatalogueVO.getReadWriteLockVO().setResult(TaskLockStatus.TO_UPDATE.getVal());
// 更新 关联资源
if (param.getResourceIdList() != null) {
final Map<String, Object> params = Maps.newHashMap();
params.put("id", task.getId());
params.put("resources", param.getResourceIdList());
params.put("createUserId", task.getCreateUserId());
this.updateTaskResource(params);
}
if (param.getRefResourceIdList() != null) {
final Map<String, Object> params = Maps.newHashMap();
params.put("id", task.getId());
params.put("refResource", param.getRefResourceIdList());
params.put("createUserId", task.getCreateUserId());
this.updateTaskRefResource(params);
}
final User user = userService.getById(task.getModifyUserId());
if (user != null) {
taskCatalogueVO.setCreateUser(user.getUserName());
}
final List<BatchTask> dependencyTasks = param.getDependencyTasks();
if (dependencyTasks != null) {
this.batchTaskTaskService.addOrUpdateTaskTask(task.getId(), dependencyTasks);
taskCatalogueVO.setDependencyTasks(dependencyTasks);
}
String createUserName = userService.getUserName(task.getCreateUserId());
taskCatalogueVO.setCreateUser(createUserName);
taskCatalogueVO.setCatalogueType(CatalogueType.TASK_DEVELOP.getType());
return taskCatalogueVO;
}
use of com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO in project Taier by DTStack.
the class BatchTaskService method guideToTemplate.
/**
* 向导模式转模版
* @param param
* @return
* @throws Exception
*/
@Transactional
public TaskCatalogueVO guideToTemplate(final TaskResourceParam param) {
final BatchTask task = this.developTaskDao.getOne(param.getId());
BatchTaskBatchVO taskVO = new BatchTaskBatchVO();
taskVO.setId(param.getId());
taskVO.setName(task.getName());
taskVO.setVersion(param.getVersion());
taskVO.setUserId(param.getUserId());
taskVO.setNodePid(task.getNodePid());
taskVO.setReadWriteLockVO(param.getReadWriteLockVO());
taskVO.setLockVersion(param.getLockVersion());
taskVO.setTenantId(param.getTenantId());
final JSONObject sqlJson = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
sqlJson.put("createModel", TaskCreateModelType.TEMPLATE.getType());
taskVO.setSqlText(Base64Util.baseEncode(sqlJson.toJSONString()));
taskVO = this.updateTask(taskVO, true);
final TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO(taskVO, taskVO.getNodePid());
return taskCatalogueVO;
}
Aggregations