|
|
@ -28,9 +28,9 @@ import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
import org.apache.dolphinscheduler.common.enums.Flag; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; |
|
|
@ -39,7 +39,6 @@ import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
|
|
@ -67,6 +66,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* task definition service impl |
|
|
|
* task definition service impl |
|
|
@ -93,9 +93,6 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private ProcessTaskRelationLogMapper processTaskRelationLogMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
private ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
|
|
|
|
|
|
|
@ -218,17 +215,13 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
if (delete > 0) { |
|
|
|
if (delete > 0) { |
|
|
|
List<ProcessTaskRelation> taskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); |
|
|
|
List<ProcessTaskRelation> taskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); |
|
|
|
if (!taskRelationList.isEmpty()) { |
|
|
|
if (!taskRelationList.isEmpty()) { |
|
|
|
int deleteRelation = 0; |
|
|
|
|
|
|
|
for (ProcessTaskRelation processTaskRelation : taskRelationList) { |
|
|
|
|
|
|
|
deleteRelation += processTaskRelationMapper.deleteById(processTaskRelation.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (deleteRelation == 0) { |
|
|
|
|
|
|
|
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
long processDefinitionCode = taskRelationList.get(0).getProcessDefinitionCode(); |
|
|
|
long processDefinitionCode = taskRelationList.get(0).getProcessDefinitionCode(); |
|
|
|
updateProcessDefiniteVersion(loginUser, processDefinitionCode); |
|
|
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode); |
|
|
|
|
|
|
|
List<ProcessTaskRelation> relationList = processTaskRelations.stream().filter(r -> r.getPostTaskCode() != taskCode).collect(Collectors.toList()); |
|
|
|
|
|
|
|
updateDag(loginUser, result, processDefinitionCode, relationList, Lists.newArrayList()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
} |
|
|
|
} |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
|
|
|
putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
|
|
|
throw new ServiceException(Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
|
|
|
throw new ServiceException(Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
|
|
@ -236,7 +229,8 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int updateProcessDefiniteVersion(User loginUser, long processDefinitionCode) { |
|
|
|
private void updateDag(User loginUser, Map<String, Object> result, long processDefinitionCode, List<ProcessTaskRelation> processTaskRelationList, |
|
|
|
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs) { |
|
|
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); |
|
|
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); |
|
|
|
if (processDefinition == null) { |
|
|
|
if (processDefinition == null) { |
|
|
|
throw new ServiceException(Status.PROCESS_DEFINE_NOT_EXIST); |
|
|
|
throw new ServiceException(Status.PROCESS_DEFINE_NOT_EXIST); |
|
|
@ -245,7 +239,16 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
if (insertVersion <= 0) { |
|
|
|
if (insertVersion <= 0) { |
|
|
|
throw new ServiceException(Status.UPDATE_PROCESS_DEFINITION_ERROR); |
|
|
|
throw new ServiceException(Status.UPDATE_PROCESS_DEFINITION_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
return insertVersion; |
|
|
|
List<ProcessTaskRelationLog> relationLogs = processTaskRelationList.stream().map(ProcessTaskRelationLog::new).collect(Collectors.toList()); |
|
|
|
|
|
|
|
int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(), processDefinition.getCode(), |
|
|
|
|
|
|
|
insertVersion, relationLogs, taskDefinitionLogs, Boolean.TRUE); |
|
|
|
|
|
|
|
if (insertResult == Constants.EXIT_CODE_SUCCESS) { |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
result.put(Constants.DATA_LIST, processDefinition); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); |
|
|
|
|
|
|
|
throw new ServiceException(Status.UPDATE_PROCESS_DEFINITION_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -308,54 +311,28 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
putMsg(result, Status.UPDATE_TASK_DEFINITION_ERROR); |
|
|
|
putMsg(result, Status.UPDATE_TASK_DEFINITION_ERROR); |
|
|
|
throw new ServiceException(Status.UPDATE_TASK_DEFINITION_ERROR); |
|
|
|
throw new ServiceException(Status.UPDATE_TASK_DEFINITION_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
handleRelation(loginUser, taskCode, version, now); |
|
|
|
List<ProcessTaskRelation> taskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); |
|
|
|
|
|
|
|
if (!taskRelationList.isEmpty()) { |
|
|
|
|
|
|
|
long processDefinitionCode = taskRelationList.get(0).getProcessDefinitionCode(); |
|
|
|
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode); |
|
|
|
|
|
|
|
updateDag(loginUser, result, processDefinitionCode, processTaskRelations, Lists.newArrayList(taskDefinitionToUpdate)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
} |
|
|
|
result.put(Constants.DATA_LIST, taskCode); |
|
|
|
result.put(Constants.DATA_LIST, taskCode); |
|
|
|
putMsg(result, Status.SUCCESS, update); |
|
|
|
putMsg(result, Status.SUCCESS, update); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleRelation(User loginUser, long taskCode, Integer version, Date now) { |
|
|
|
|
|
|
|
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByTaskCode(taskCode); |
|
|
|
|
|
|
|
if (!processTaskRelationList.isEmpty()) { |
|
|
|
|
|
|
|
long processDefinitionCode = processTaskRelationList.get(0).getProcessDefinitionCode(); |
|
|
|
|
|
|
|
int definiteVersion = updateProcessDefiniteVersion(loginUser, processDefinitionCode); |
|
|
|
|
|
|
|
List<ProcessTaskRelationLog> processTaskRelationLogList = new ArrayList<>(); |
|
|
|
|
|
|
|
int delete = 0; |
|
|
|
|
|
|
|
for (ProcessTaskRelation processTaskRelation : processTaskRelationList) { |
|
|
|
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation); |
|
|
|
|
|
|
|
delete += processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
|
|
|
|
|
|
|
if (processTaskRelationLog.getPreTaskCode() == taskCode) { |
|
|
|
|
|
|
|
processTaskRelationLog.setPreTaskVersion(version); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (processTaskRelationLog.getPostTaskCode() == taskCode) { |
|
|
|
|
|
|
|
processTaskRelationLog.setPostTaskVersion(version); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
processTaskRelationLog.setProcessDefinitionVersion(definiteVersion); |
|
|
|
|
|
|
|
processTaskRelationLog.setOperator(loginUser.getId()); |
|
|
|
|
|
|
|
processTaskRelationLog.setOperateTime(now); |
|
|
|
|
|
|
|
processTaskRelationLog.setUpdateTime(now); |
|
|
|
|
|
|
|
processTaskRelationLogList.add(processTaskRelationLog); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (delete == 0) { |
|
|
|
|
|
|
|
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
int insertRelation = processTaskRelationMapper.batchInsert(processTaskRelationLogList); |
|
|
|
|
|
|
|
int insertRelationLog = processTaskRelationLogMapper.batchInsert(processTaskRelationLogList); |
|
|
|
|
|
|
|
if ((insertRelation & insertRelationLog) == 0) { |
|
|
|
|
|
|
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* update task definition |
|
|
|
* switch task definition |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param projectCode project code |
|
|
|
* @param projectCode project code |
|
|
|
* @param taskCode task code |
|
|
|
* @param taskCode task code |
|
|
|
* @param version the version user want to switch |
|
|
|
* @param version the version user want to switch |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> switchVersion(User loginUser, long projectCode, long taskCode, int version) { |
|
|
|
public Map<String, Object> switchVersion(User loginUser, long projectCode, long taskCode, int version) { |
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
@ -375,14 +352,18 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe |
|
|
|
} |
|
|
|
} |
|
|
|
TaskDefinitionLog taskDefinitionUpdate = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version); |
|
|
|
TaskDefinitionLog taskDefinitionUpdate = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version); |
|
|
|
taskDefinitionUpdate.setUserId(loginUser.getId()); |
|
|
|
taskDefinitionUpdate.setUserId(loginUser.getId()); |
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
taskDefinitionUpdate.setUpdateTime(new Date()); |
|
|
|
taskDefinitionUpdate.setUpdateTime(new Date()); |
|
|
|
taskDefinitionUpdate.setId(taskDefinition.getId()); |
|
|
|
taskDefinitionUpdate.setId(taskDefinition.getId()); |
|
|
|
int switchVersion = taskDefinitionMapper.updateById(taskDefinitionUpdate); |
|
|
|
int switchVersion = taskDefinitionMapper.updateById(taskDefinitionUpdate); |
|
|
|
if (switchVersion > 0) { |
|
|
|
if (switchVersion > 0) { |
|
|
|
handleRelation(loginUser, taskCode, version, now); |
|
|
|
List<ProcessTaskRelation> taskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); |
|
|
|
result.put(Constants.DATA_LIST, taskCode); |
|
|
|
if (!taskRelationList.isEmpty()) { |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
long processDefinitionCode = taskRelationList.get(0).getProcessDefinitionCode(); |
|
|
|
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode); |
|
|
|
|
|
|
|
updateDag(loginUser, result, processDefinitionCode, processTaskRelations, Lists.newArrayList(taskDefinitionUpdate)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
putMsg(result, Status.SWITCH_TASK_DEFINITION_VERSION_ERROR); |
|
|
|
putMsg(result, Status.SWITCH_TASK_DEFINITION_VERSION_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|