use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method updateTask.
/**
* 新增/更新任务
*
* @param task
* @param isEditBaseInfo 如果是右键编辑的情况则不更新任务参数
* @return
*/
@Transactional
public BatchTaskBatchVO updateTask(final BatchTaskBatchVO task, final Boolean isEditBaseInfo) {
if (task.getName() == null) {
throw new RdosDefineException("任务名称不能为空.", ErrorCode.INVALID_PARAMETERS);
}
if (!PublicUtil.matcher(task.getName(), TASK_PATTERN)) {
throw new RdosDefineException("名称只能由字母、数据、中文、下划线组成", ErrorCode.INVALID_PARAMETERS);
}
task.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
BatchTask batchTask = this.developTaskDao.getByName(task.getName(), task.getTenantId());
boolean isAdd = false;
if (task.getId() > 0) {
// update
BatchTask specialTask = getOneWithError(task.getId());
if (task.getTaskType() == null) {
task.setTaskType(specialTask.getTaskType());
}
String oriTaskName = specialTask.getName();
if (batchTask != null && !batchTask.getId().equals(task.getId())) {
throw new RdosDefineException(ErrorCode.NAME_ALREADY_EXIST);
}
BatchTask specialTask1 = new BatchTask();
ReadWriteLockVO readWriteLockVO = this.readWriteLockService.dealWithLock(task.getTenantId(), task.getId(), ReadWriteLockType.BATCH_TASK, task.getUserId(), res -> {
task.setCreateUser(null);
task.setIsDeleted(Deleted.NORMAL.getStatus());
if (task.getVersion() == null) {
task.setVersion(0);
}
PublicUtil.copyPropertiesIgnoreNull(task, specialTask1);
final Integer updateResult = this.developTaskDao.update(specialTask1);
if (updateResult == 1) {
task.setVersion(task.getVersion() + 1);
}
return updateResult;
});
task.setReadWriteLockVO(readWriteLockVO);
// 如果是工作流任务 更新父节点调度类型时,需要同样更新子节点
if (EScheduleJobType.WORK_FLOW.getVal().equals(task.getTaskType()) && task.getFlowId() == 0 && StringUtils.isNotEmpty(task.getScheduleConf())) {
updateSonTaskPeriodType(task.getId(), task.getPeriodType(), task.getScheduleConf());
}
if (!oriTaskName.equals(task.getName())) {
// 修改名字需要同步到taskShade
this.taskService.updateTaskName(task.getId(), task.getName());
}
LOGGER.info("success update batchTask, taskId:{}", task.getId());
} else {
if (batchTask != null) {
throw new RdosDefineException(ErrorCode.NAME_ALREADY_EXIST);
}
// 初始化task的一些属性
isAdd = initTaskInfo(task);
BatchTask insertTask = new BatchTask();
BeanUtils.copyProperties(task, insertTask);
// 如果是工作流获取父任务的锁 用来保证父任务一定会更新成功 这里有并发问题 如果同时对一个工作流添加子任务 会丢失
if (task.getFlowId() > 0) {
BatchTask parentTask = developTaskDao.getOne(task.getFlowId());
BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(0L, parentTask.getId(), ReadWriteLockType.BATCH_TASK.name());
if (readWriteLock == null) {
throw new RdosDefineException("父任务锁不存在");
}
if (!readWriteLock.getVersion().equals(task.getParentReadWriteLockVersion())) {
throw new RdosDefineException("当前任务已被修改,请重新打开任务后再次提交");
}
}
developTaskDao.insert(insertTask);
task.setTaskId(insertTask.getId());
task.setId(insertTask.getId());
// parseCreateTaskExeArgs(task);
// 新增锁
ReadWriteLockVO readWriteLockVO = this.readWriteLockService.getLock(task.getTenantId(), task.getUserId(), ReadWriteLockType.BATCH_TASK.name(), task.getId(), null);
task.setReadWriteLockVO(readWriteLockVO);
LOGGER.info("success insert batchTask, taskId:{}", task.getId());
}
// 右键编辑时会调用另一个接口
if (BooleanUtils.isNotTrue(isEditBaseInfo)) {
if (!EScheduleJobType.WORK_FLOW.getVal().equals(task.getTaskType()) && !EScheduleJobType.VIRTUAL.getVal().equals(task.getTaskType())) {
// 新增加不校验自定义参数
if (!isAdd) {
this.batchTaskParamService.checkParams(task.getSqlText(), task.getTaskVariables());
}
}
this.batchTaskParamService.addOrUpdateTaskParam(task);
}
final BatchTaskBatchVO batchTaskBatchVO = new BatchTaskBatchVO(task);
batchTaskBatchVO.setReadWriteLockVO(task.getReadWriteLockVO());
batchTaskBatchVO.setVersion(task.getVersion());
return batchTaskBatchVO;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method getFlowWorkSubTasks.
/**
* 获取任务流下的所有子任务
*
* @param taskId
* @return
*/
public List<BatchTask> getFlowWorkSubTasks(final Long taskId) {
BatchTaskDTO batchTaskDTO = new BatchTaskDTO();
batchTaskDTO.setIsDeleted(Deleted.NORMAL.getStatus());
batchTaskDTO.setFlowId(taskId);
PageQuery<BatchTaskDTO> pageQuery = new PageQuery<>(batchTaskDTO);
List<BatchTask> batchTasks = this.developTaskDao.generalQuery(pageQuery);
return batchTasks;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchCatalogueService method deleteCatalogue.
/**
* 删除目录
*/
public void deleteCatalogue(BatchCatalogue catalogueInput) {
BatchCatalogue catalogue = developCatalogueDao.getOne(catalogueInput.getId());
catalogueOneNotUpdate(catalogue);
if (catalogue == null || catalogue.getIsDeleted() == 1) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_CATALOGUE);
}
// 判断文件夹下任务
List<BatchTask> taskList = batchTaskService.listBatchTaskByNodePid(catalogueInput.getTenantId(), catalogue.getId());
List<BatchResource> resourceList = batchResourceService.listByPidAndTenantId(catalogueInput.getTenantId(), catalogue.getId());
if (taskList.size() > 0 || resourceList.size() > 0) {
throw new RdosDefineException(ErrorCode.CATALOGUE_NO_EMPTY);
}
// 判断文件夹下子目录
if (CollectionUtils.isNotEmpty(developCatalogueDao.listByPidAndTenantId(catalogue.getId(), catalogueInput.getTenantId()))) {
throw new RdosDefineException(ErrorCode.CATALOGUE_NO_EMPTY);
}
catalogue.setIsDeleted(Deleted.DELETED.getStatus());
catalogue.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
developCatalogueDao.deleteById(catalogue.getId());
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method canSetIncreConf.
/**
* 判断任务是否可以配置增量标识
*/
public boolean canSetIncreConf(Long taskId) {
final BatchTask task = this.getBatchTaskById(taskId);
if (task == null) {
throw new RdosDefineException(ErrorCode.DATA_NOT_FIND);
}
if (!EScheduleJobType.SYNC.getVal().equals(task.getTaskType())) {
return false;
}
// 增量同步任务不能在工作流中运行
if (task.getFlowId() != 0) {
return false;
}
if (StringUtils.isEmpty(task.getSqlText())) {
throw new RdosDefineException("同步任务未配置数据源");
}
try {
final JSONObject json = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
this.checkSyncJobContent(json.getJSONObject("job"), false);
} catch (final RdosDefineException e) {
return false;
}
return true;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method deleteTask.
/**
* 数据开发-删除任务
*
* @param taskId 任务id
* @param tenantId 项目id
* @param userId 用户id
* @return
* @author toutian
*/
@Transactional
public Long deleteTask(Long taskId, Long tenantId, Long userId, String sqlText) {
final BatchTask batchTask = this.developTaskDao.getOne(taskId);
if (batchTask == null) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
}
// 判断该任务是否有子任务(调用engine接口) 工作流不需要判断
if (batchTask.getFlowId() == 0) {
List<TaskGetNotDeleteVO> notDeleteTaskVOS = getChildTasks(taskId);
if (CollectionUtils.isNotEmpty(notDeleteTaskVOS)) {
throw new RdosDefineException("(当前任务被其他任务依赖)", ErrorCode.CAN_NOT_DELETE_TASK);
}
}
final ScheduleTaskShade dbTask = this.taskService.findTaskByTaskId(taskId);
if (batchTask.getFlowId() == 0 && Objects.nonNull(dbTask) && batchTask.getScheduleStatus().intValue() == EScheduleStatus.NORMAL.getVal().intValue()) {
throw new RdosDefineException("(当前任务未被冻结)", ErrorCode.CAN_NOT_DELETE_TASK);
}
if (batchTask.getTaskType().intValue() == EScheduleJobType.WORK_FLOW.getVal()) {
final List<BatchTask> batchTasks = this.getFlowWorkSubTasks(taskId);
// 删除所有子任务相关
batchTasks.forEach(task -> this.deleteTaskInfos(task.getId(), tenantId, userId));
}
// 删除工作流中的子任务同时删除被依赖的关系
if (batchTask.getFlowId() > 0) {
this.batchTaskTaskService.deleteTaskTaskByParentId(batchTask.getId());
}
if (StringUtils.isNotBlank(sqlText)) {
final BatchTask batchTaskBean = new BatchTask();
batchTaskBean.setId(batchTask.getFlowId());
batchTaskBean.setSqlText(sqlText);
this.developTaskDao.updateSqlText(batchTaskBean);
LOGGER.info("sqlText 修改成功");
} else {
LOGGER.error("deleteTask sqlText is null");
}
// 删除任务
this.deleteTaskInfos(taskId, tenantId, userId);
return taskId;
}
Aggregations