[Feature][JsonSplit] modify ProcessService createTaskAndRelation (#4770)
* add task query * modify codestyle * add task delete/update/swich method * add task delete/update/swich method * codestyle * use updateById save task definition * modify method name * code style * code style * modify ProcessService createTaskAndRelation Co-authored-by: JinyLeeChina <297062848@qq.com>json_split
parent
061af08765
commit
069e9f980e
|
|
@ -44,7 +44,6 @@ import org.apache.dolphinscheduler.common.enums.TimeoutFlag;
|
|||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.common.model.DateInterval;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNode;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNodeRelation;
|
||||
import org.apache.dolphinscheduler.common.process.Property;
|
||||
import org.apache.dolphinscheduler.common.process.ResourceInfo;
|
||||
import org.apache.dolphinscheduler.common.task.AbstractParameters;
|
||||
|
|
@ -97,8 +96,8 @@ import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
|
|||
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
|
||||
import org.apache.dolphinscheduler.dao.utils.DagHelper;
|
||||
import org.apache.dolphinscheduler.remote.utils.Host;
|
||||
import org.apache.dolphinscheduler.service.exceptions.ServiceException;
|
||||
import org.apache.dolphinscheduler.service.log.LogClientService;
|
||||
import org.apache.dolphinscheduler.service.quartz.cron.CronUtils;
|
||||
|
||||
|
|
@ -2278,11 +2277,12 @@ public class ProcessService {
|
|||
/**
|
||||
* create task definition and task relations
|
||||
*/
|
||||
public int createTaskAndRelation(User operator,
|
||||
Long projectCode,
|
||||
ProcessDefinition processDefinition,
|
||||
ProcessData processData) {
|
||||
public void createTaskAndRelation(User operator,
|
||||
Long projectCode,
|
||||
ProcessDefinition processDefinition,
|
||||
ProcessData processData) {
|
||||
List<TaskNode> taskNodeList = (processData.getTasks() == null) ? new ArrayList<>() : processData.getTasks();
|
||||
Map<String, Long> taskNameAndCode = new HashMap<>();
|
||||
for (TaskNode taskNode : taskNodeList) {
|
||||
TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionName(projectCode, taskNode.getName());
|
||||
if (taskDefinition == null) {
|
||||
|
|
@ -2292,44 +2292,60 @@ public class ProcessService {
|
|||
taskDefinition = new TaskDefinition();
|
||||
taskDefinition.setCode(code);
|
||||
} catch (SnowFlakeException e) {
|
||||
logger.error("Task code get error, ", e);
|
||||
return -1;
|
||||
throw new ServiceException("Task code get error", e);
|
||||
}
|
||||
saveTaskDefinition(operator, projectCode, taskNode, taskDefinition);
|
||||
} else {
|
||||
if (isTaskOnline(taskDefinition.getCode())) {
|
||||
// TODO return something for fail
|
||||
return -1;
|
||||
throw new ServiceException(String.format("The task %s is on line in process", taskNode.getName()));
|
||||
}
|
||||
updateTaskDefinition(operator, projectCode, taskNode, taskDefinition);
|
||||
}
|
||||
taskNameAndCode.put(taskNode.getName(), taskDefinition.getCode());
|
||||
}
|
||||
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinition.getCode());
|
||||
if (!processTaskRelationList.isEmpty()) {
|
||||
processTaskRelationMapper.deleteByCode(projectCode, processDefinition.getCode());
|
||||
}
|
||||
// TODO parse taskNodeList for preTaskCode and postTaskCode
|
||||
List<TaskNodeRelation> taskNodeRelationList = DagHelper.getProcessDag(taskNodeList).getEdges();
|
||||
List<ProcessTaskRelation> builderRelationList = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation("",// todo relation name
|
||||
processDefinition.getVersion(),
|
||||
projectCode,
|
||||
processDefinition.getCode(),
|
||||
0L, // todo pre task code
|
||||
0L, // todo post task code
|
||||
ConditionType.of(""), // todo conditionType
|
||||
"", // todo conditionParams
|
||||
now,
|
||||
now);
|
||||
// save process task relation
|
||||
int insert = processTaskRelationMapper.insert(processTaskRelation);
|
||||
// save process task relation log
|
||||
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
|
||||
processTaskRelationLog.set(processTaskRelation);
|
||||
processTaskRelationLog.setOperator(operator.getId());
|
||||
processTaskRelationLog.setOperateTime(now);
|
||||
int logInsert = processTaskRelationLogMapper.insert(processTaskRelationLog);
|
||||
return insert & logInsert;
|
||||
for (TaskNode taskNode : taskNodeList) {
|
||||
List<String> depList = taskNode.getDepList();
|
||||
if (CollectionUtils.isNotEmpty(depList)) {
|
||||
for (String preTaskName : depList) {
|
||||
builderRelationList.add(new ProcessTaskRelation("",// todo relation name
|
||||
processDefinition.getVersion(),
|
||||
projectCode,
|
||||
processDefinition.getCode(),
|
||||
taskNameAndCode.get(preTaskName),
|
||||
taskNameAndCode.get(taskNode.getName()),
|
||||
ConditionType.of("none"), // todo conditionType
|
||||
taskNode.getConditionResult(),
|
||||
now,
|
||||
now));
|
||||
}
|
||||
} else {
|
||||
builderRelationList.add(new ProcessTaskRelation("",// todo relation name
|
||||
processDefinition.getVersion(),
|
||||
projectCode,
|
||||
processDefinition.getCode(),
|
||||
0L,
|
||||
taskNameAndCode.get(taskNode.getName()),
|
||||
ConditionType.of("none"), // todo conditionType
|
||||
taskNode.getConditionResult(),
|
||||
now,
|
||||
now));
|
||||
}
|
||||
}
|
||||
for (ProcessTaskRelation processTaskRelation : builderRelationList) {
|
||||
processTaskRelationMapper.insert(processTaskRelation);
|
||||
// save process task relation log
|
||||
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
|
||||
processTaskRelationLog.set(processTaskRelation);
|
||||
processTaskRelationLog.setOperator(operator.getId());
|
||||
processTaskRelationLog.setOperateTime(now);
|
||||
processTaskRelationLogMapper.insert(processTaskRelationLog);
|
||||
}
|
||||
}
|
||||
|
||||
public int saveTaskDefinition(User operator, Long projectCode, TaskNode taskNode, TaskDefinition taskDefinition) {
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ public class ProcessServiceTest {
|
|||
String expect = JSONUtils.toJsonString(exceptProcessData);
|
||||
String oldJson = JSONUtils.toJsonString(oldProcessData);
|
||||
|
||||
Assert.assertEquals(expect, processService.changeJson(newProcessData,oldJson));
|
||||
Assert.assertEquals(expect, processService.changeJson(newProcessData, oldJson));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue