|
|
|
@ -18,32 +18,37 @@
|
|
|
|
|
package org.apache.dolphinscheduler.api.service.impl; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.ProjectService; |
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
|
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.ProjectMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* process task relation service impl |
|
|
|
@ -51,8 +56,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@Service |
|
|
|
|
public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements ProcessTaskRelationService { |
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProcessTaskRelationServiceImpl.class); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ProjectMapper projectMapper; |
|
|
|
|
|
|
|
|
@ -62,11 +65,18 @@ public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements P
|
|
|
|
|
@Autowired |
|
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ProcessTaskRelationLogMapper processTaskRelationLogMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private TaskDefinitionLogMapper taskDefinitionLogMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private UserMapper userMapper; |
|
|
|
|
private TaskDefinitionMapper taskDefinitionMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* create process task relation |
|
|
|
|
* |
|
|
|
@ -77,9 +87,87 @@ public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements P
|
|
|
|
|
* @param postTaskCode postTaskCode |
|
|
|
|
* @return create result code |
|
|
|
|
*/ |
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class) |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> createProcessTaskRelation(User loginUser, long projectCode, long processDefinitionCode, long preTaskCode, long postTaskCode) { |
|
|
|
|
return null; |
|
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
|
|
//check user access for project
|
|
|
|
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
|
|
|
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); |
|
|
|
|
if (processDefinition == null) { |
|
|
|
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionCode); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
if (processDefinition.getProjectCode() != projectCode) { |
|
|
|
|
putMsg(result, Status.PROJECT_PROCESS_NOT_MATCH); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, postTaskCode); |
|
|
|
|
if (!processTaskRelations.isEmpty()) { |
|
|
|
|
Map<Long, ProcessTaskRelation> preTaskCodeMap = processTaskRelations.stream() |
|
|
|
|
.collect(Collectors.toMap(ProcessTaskRelation::getPreTaskCode, processTaskRelation -> processTaskRelation)); |
|
|
|
|
if (preTaskCodeMap.containsKey(preTaskCode) || (!preTaskCodeMap.containsKey(0L) && preTaskCode == 0L)) { |
|
|
|
|
putMsg(result, Status.PROCESS_TASK_RELATION_EXIST, processDefinitionCode); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
if (preTaskCodeMap.containsKey(0L) && preTaskCode != 0L) { |
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(preTaskCodeMap.get(0L)); |
|
|
|
|
// delete no upstream
|
|
|
|
|
int delete = processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
|
|
|
|
int deleteLog = processTaskRelationLogMapper.deleteRelation(processTaskRelationLog); |
|
|
|
|
if ((delete & deleteLog) == 0) { |
|
|
|
|
putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Date now = new Date(); |
|
|
|
|
List<ProcessTaskRelationLog> processTaskRelationLogs = new ArrayList<>(); |
|
|
|
|
if (preTaskCode != 0L) { |
|
|
|
|
// upstream is or not exist
|
|
|
|
|
List<ProcessTaskRelation> upstreamProcessTaskRelations = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, preTaskCode); |
|
|
|
|
TaskDefinition preTaskDefinition = taskDefinitionMapper.queryByCode(preTaskCode); |
|
|
|
|
if (upstreamProcessTaskRelations.isEmpty()) { |
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), preTaskDefinition); |
|
|
|
|
processTaskRelationLog.setPreTaskCode(0L); |
|
|
|
|
processTaskRelationLog.setPreTaskVersion(0); |
|
|
|
|
processTaskRelationLogs.add(processTaskRelationLog); |
|
|
|
|
} |
|
|
|
|
TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(postTaskCode); |
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), postTaskDefinition); |
|
|
|
|
processTaskRelationLog.setPreTaskCode(preTaskDefinition.getCode()); |
|
|
|
|
processTaskRelationLog.setPreTaskVersion(preTaskDefinition.getVersion()); |
|
|
|
|
processTaskRelationLogs.add(processTaskRelationLog); |
|
|
|
|
} else { |
|
|
|
|
TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(postTaskCode); |
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), postTaskDefinition); |
|
|
|
|
processTaskRelationLog.setPreTaskCode(0L); |
|
|
|
|
processTaskRelationLog.setPreTaskVersion(0); |
|
|
|
|
processTaskRelationLogs.add(processTaskRelationLog); |
|
|
|
|
} |
|
|
|
|
int insert = processTaskRelationMapper.batchInsert(processTaskRelationLogs); |
|
|
|
|
int insertLog = processTaskRelationLogMapper.batchInsert(processTaskRelationLogs); |
|
|
|
|
if ((insert & insertLog) > 0) { |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ProcessTaskRelationLog setRelationLog(ProcessDefinition processDefinition, Date now, int userId, TaskDefinition taskDefinition) { |
|
|
|
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
|
|
|
|
processTaskRelationLog.setProjectCode(processDefinition.getProjectCode()); |
|
|
|
|
processTaskRelationLog.setProcessDefinitionCode(processDefinition.getCode()); |
|
|
|
|
processTaskRelationLog.setProcessDefinitionVersion(processDefinition.getVersion()); |
|
|
|
|
processTaskRelationLog.setPostTaskCode(taskDefinition.getCode()); |
|
|
|
|
processTaskRelationLog.setPostTaskVersion(taskDefinition.getVersion()); |
|
|
|
|
processTaskRelationLog.setCreateTime(now); |
|
|
|
|
processTaskRelationLog.setUpdateTime(now); |
|
|
|
|
processTaskRelationLog.setOperator(userId); |
|
|
|
|
processTaskRelationLog.setOperateTime(now); |
|
|
|
|
return processTaskRelationLog; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|