From 14e4d7086d2dab9847c608c3d02f541893bcef10 Mon Sep 17 00:00:00 2001 From: JinyLeeChina <42576980+JinyLeeChina@users.noreply.github.com> Date: Mon, 13 Sep 2021 20:40:52 +0800 Subject: [PATCH] [Fix-6139][API] fix bug of view-tree api (#6188) * fix bug of view-tree api * fix bug of view-tree api * fix ut * fix ut Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../ProcessDefinitionController.java | 2 +- .../controller/WorkFlowLineageController.java | 2 +- .../api/dto/treeview/Instance.java | 39 ++++++++++----- .../api/dto/treeview/TreeViewDto.java | 34 ++++++++----- .../impl/ProcessDefinitionServiceImpl.java | 49 +++++++++++-------- .../common/model/TaskNode.java | 6 +-- .../dolphinscheduler/dao/entity/DagData.java | 14 +++--- .../service/process/ProcessService.java | 36 +++++--------- .../service/process/ProcessServiceTest.java | 28 +++++------ 9 files changed, 115 insertions(+), 95 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java index 9200e8ae48..b6de4d8c65 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java @@ -533,7 +533,7 @@ public class ProcessDefinitionController extends BaseController { */ @ApiOperation(value = "getTaskListByDefinitionCodes", notes = "GET_TASK_LIST_BY_DEFINITION_CODE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionCodes", value = "PROCESS_DEFINITION_CODES", required = true, type = "String", example = "100,200,300") + @ApiImplicitParam(name = "codes", value = "PROCESS_DEFINITION_CODES", required = true, type = "String", example = "100,200,300") }) @GetMapping(value = "/batch-query-tasks") @ResponseStatus(HttpStatus.OK) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java index 4e88486310..f89906c6f3 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java @@ -96,7 +96,7 @@ public class WorkFlowLineageController extends BaseController { @GetMapping(value = "/list") @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, + public Result> queryWorkFlowLineage(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) { try { Map result = workFlowLineageService.queryWorkFlowLineage(projectCode); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java index 9bab520ed5..e13a7d1440 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java @@ -14,23 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dolphinscheduler.api.dto.treeview; -import com.fasterxml.jackson.annotation.JsonFormat; +package org.apache.dolphinscheduler.api.dto.treeview; import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + /** * Instance */ public class Instance { private int id; + /** * node name */ private String name; + /** + * node code + */ + private long code; + /** * node type */ @@ -44,17 +51,16 @@ public class Instance { /** * node start time */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startTime; /** * node end time */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime; - /** * node running on which host */ @@ -67,18 +73,20 @@ public class Instance { private int subflowId; + public Instance() { + } - public Instance(){} - - public Instance(int id,String name, String type){ + public Instance(int id, String name, long code, String type) { this.id = id; this.name = name; + this.code = code; this.type = type; } - public Instance(int id,String name, String type,String state,Date startTime, Date endTime, String host, String duration,int subflowId) { + public Instance(int id, String name, long code, String type, String state, Date startTime, Date endTime, String host, String duration, int subflowId) { this.id = id; this.name = name; + this.code = code; this.type = type; this.state = state; this.startTime = startTime; @@ -88,12 +96,11 @@ public class Instance { this.subflowId = subflowId; } - public Instance(int id,String name, String type,String state,Date startTime, Date endTime, String host, String duration) { - this(id, name, type, state, startTime, endTime,host,duration,0); + public Instance(int id, String name, long code, String type, String state, Date startTime, Date endTime, String host, String duration) { + this(id, name, code, type, state, startTime, endTime, host, duration, 0); } - public int getId() { return id; } @@ -110,6 +117,14 @@ public class Instance { this.name = name; } + public long getCode() { + return code; + } + + public void setCode(long code) { + this.code = code; + } + public String getType() { return type; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java index e30eea849f..8645bf30b6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.dto.treeview; import java.util.ArrayList; @@ -34,6 +35,21 @@ public class TreeViewDto { */ private String type; + /** + * code + */ + private long code; + + /** + * instances list + */ + + private List instances = new ArrayList<>(); + + /** + * children + */ + private List children = new ArrayList<>(); public String getName() { return name; @@ -51,17 +67,13 @@ public class TreeViewDto { this.type = type; } - /** - * instances list - */ - - private List instances = new ArrayList<>(); - - /** - * children - */ - private List children = new ArrayList<>(); + public long getCode() { + return code; + } + public void setCode(long code) { + this.code = code; + } public List getInstances() { return instances; @@ -78,6 +90,4 @@ public class TreeViewDto { public void setChildren(List children) { this.children = children; } - - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index ef00f5041c..eaec2e47b7 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -281,8 +281,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.DATA_IS_NOT_VALID, taskRelationJson); return result; } - - List taskNodeList = processService.transformTask(taskRelationList, taskDefinitionLogs); + List processTaskRelations = taskRelationList.stream() + .map(processTaskRelationLog -> JSONUtils.parseObject(JSONUtils.toJsonString(processTaskRelationLog), ProcessTaskRelation.class)) + .collect(Collectors.toList()); + List taskNodeList = processService.transformTask(processTaskRelations, taskDefinitionLogs); if (taskNodeList.size() != taskRelationList.size()) { Set postTaskCodes = taskRelationList.stream().map(ProcessTaskRelationLog::getPostTaskCode).collect(Collectors.toSet()); Set taskNodeCodes = taskNodeList.stream().map(TaskNode::getCode).collect(Collectors.toSet()); @@ -827,10 +829,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); return false; } - List taskDefinitionList = dagDataSchedule.getTaskDefinitionList(); + List taskDefinitionList = dagDataSchedule.getTaskDefinitionList(); Map taskCodeMap = new HashMap<>(); Date now = new Date(); - for (TaskDefinitionLog taskDefinitionLog : taskDefinitionList) { + List taskDefinitionLogList = new ArrayList<>(); + for (TaskDefinition taskDefinition : taskDefinitionList) { + TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition); taskDefinitionLog.setName(taskDefinitionLog.getName() + "_import_" + DateUtils.getCurrentTimeStamp()); taskDefinitionLog.setProjectCode(projectCode); taskDefinitionLog.setUserId(loginUser.getId()); @@ -848,22 +852,26 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS, "Error generating task definition code"); return false; } + taskDefinitionLogList.add(taskDefinitionLog); } - int insert = taskDefinitionMapper.batchInsert(taskDefinitionList); - int logInsert = taskDefinitionLogMapper.batchInsert(taskDefinitionList); + int insert = taskDefinitionMapper.batchInsert(taskDefinitionLogList); + int logInsert = taskDefinitionLogMapper.batchInsert(taskDefinitionLogList); if ((logInsert & insert) == 0) { putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); return false; } - List taskRelationList = dagDataSchedule.getProcessTaskRelationList(); - taskRelationList.forEach(processTaskRelationLog -> { + List taskRelationList = dagDataSchedule.getProcessTaskRelationList(); + List taskRelationLogList = new ArrayList<>(); + for (ProcessTaskRelation processTaskRelation : taskRelationList) { + ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation); processTaskRelationLog.setPreTaskCode(taskCodeMap.get(processTaskRelationLog.getPreTaskCode())); processTaskRelationLog.setPostTaskCode(taskCodeMap.get(processTaskRelationLog.getPostTaskCode())); processTaskRelationLog.setPreTaskVersion(Constants.VERSION_FIRST); processTaskRelationLog.setPostTaskVersion(Constants.VERSION_FIRST); - }); - Map createProcessResult = createProcessDefine(loginUser, result, taskRelationList, processDefinition, null); + taskRelationLogList.add(processTaskRelationLog); + } + Map createProcessResult = createProcessDefine(loginUser, result, taskRelationLogList, processDefinition, null); if (Status.SUCCESS.equals(createProcessResult.get(Constants.STATUS))) { putMsg(createProcessResult, Status.SUCCESS); } else { @@ -937,7 +945,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return result; } - List taskRelationList = JSONUtils.toList(processTaskRelationJson, ProcessTaskRelationLog.class); + List taskRelationList = JSONUtils.toList(processTaskRelationJson, ProcessTaskRelation.class); // Check whether the task node is normal List taskNodes = processService.transformTask(taskRelationList, Lists.newArrayList()); @@ -1026,7 +1034,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, codes); return result; } - Map> taskNodeMap = new HashMap<>(); + Map> taskNodeMap = new HashMap<>(); for (ProcessDefinition processDefinition : processDefinitionList) { DagData dagData = processService.genDagData(processDefinition); taskNodeMap.put(processDefinition.getCode(), dagData.getTaskDefinitionList()); @@ -1087,7 +1095,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro // List of process instances List processInstanceList = processInstanceService.queryByProcessDefineCode(code, limit); processInstanceList.forEach(processInstance -> processInstance.setDuration(DateUtils.format2Duration(processInstance.getStartTime(), processInstance.getEndTime()))); - List taskDefinitionList = processService.queryTaskDefinitionListByProcess(code, processDefinition.getVersion()); + List taskDefinitionList = processService.genTaskDefineList(processTaskRelationMapper.queryByProcessCode(processDefinition.getProjectCode(), processDefinition.getCode())); Map taskDefinitionMap = taskDefinitionList.stream() .collect(Collectors.toMap(TaskDefinitionLog::getCode, taskDefinitionLog -> taskDefinitionLog)); @@ -1098,12 +1106,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro TreeViewDto parentTreeViewDto = new TreeViewDto(); parentTreeViewDto.setName("DAG"); parentTreeViewDto.setType(""); + parentTreeViewDto.setCode(0L); // Specify the process definition, because it is a TreeView for a process definition for (int i = limit - 1; i >= 0; i--) { ProcessInstance processInstance = processInstanceList.get(i); Date endTime = processInstance.getEndTime() == null ? new Date() : processInstance.getEndTime(); - parentTreeViewDto.getInstances().add(new Instance(processInstance.getId(), processInstance.getName(), "", - processInstance.getState().toString(), processInstance.getStartTime(), endTime, processInstance.getHost(), + parentTreeViewDto.getInstances().add(new Instance(processInstance.getId(), processInstance.getName(), processInstance.getProcessDefinitionCode(), + "", processInstance.getState().toString(), processInstance.getStartTime(), endTime, processInstance.getHost(), DateUtils.format2Readable(endTime.getTime() - processInstance.getStartTime().getTime()))); } @@ -1126,13 +1135,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro treeViewDto.setName(nodeName); TaskNode taskNode = dag.getNode(nodeName); treeViewDto.setType(taskNode.getType()); - + treeViewDto.setCode(taskNode.getCode()); //set treeViewDto instances for (int i = limit - 1; i >= 0; i--) { ProcessInstance processInstance = processInstanceList.get(i); TaskInstance taskInstance = taskInstanceMapper.queryByInstanceIdAndName(processInstance.getId(), nodeName); if (taskInstance == null) { - treeViewDto.getInstances().add(new Instance(-1, "not running", "null")); + treeViewDto.getInstances().add(new Instance(-1, "not running", 0, "null")); } else { Date startTime = taskInstance.getStartTime() == null ? new Date() : taskInstance.getStartTime(); Date endTime = taskInstance.getEndTime() == null ? new Date() : taskInstance.getEndTime(); @@ -1144,9 +1153,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro subProcessId = Integer.parseInt(JSONUtils.parseObject( taskDefinition.getTaskParams()).path(CMD_PARAM_SUB_PROCESS_DEFINE_ID).asText()); } - treeViewDto.getInstances().add(new Instance(taskInstance.getId(), taskInstance.getName(), taskInstance.getTaskType(), - taskInstance.getState().toString(), taskInstance.getStartTime(), taskInstance.getEndTime(), taskInstance.getHost(), - DateUtils.format2Readable(endTime.getTime() - startTime.getTime()), subProcessId)); + treeViewDto.getInstances().add(new Instance(taskInstance.getId(), taskInstance.getName(), taskInstance.getTaskCode(), + taskInstance.getTaskType(), taskInstance.getState().toString(), taskInstance.getStartTime(), taskInstance.getEndTime(), + taskInstance.getHost(), DateUtils.format2Readable(endTime.getTime() - startTime.getTime()), subProcessId)); } } for (TreeViewDto pTreeViewDto : parentTreeViewDtoList) { diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java index d950aa4c2f..d43e1f9710 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java @@ -45,7 +45,7 @@ public class TaskNode { /** * task node code */ - private Long code; + private long code; /** * task node version @@ -342,11 +342,11 @@ public class TaskNode { this.delayTime = delayTime; } - public Long getCode() { + public long getCode() { return code; } - public void setCode(Long code) { + public void setCode(long code) { this.code = code; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java index e66d4d09e0..b6754a3b67 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DagData.java @@ -32,14 +32,14 @@ public class DagData { /** * processTaskRelationList */ - private List processTaskRelationList; + private List processTaskRelationList; /** * processTaskRelationList */ - private List taskDefinitionList; + private List taskDefinitionList; - public DagData(ProcessDefinition processDefinition, List processTaskRelationList, List taskDefinitionList) { + public DagData(ProcessDefinition processDefinition, List processTaskRelationList, List taskDefinitionList) { this.processDefinition = processDefinition; this.processTaskRelationList = processTaskRelationList; this.taskDefinitionList = taskDefinitionList; @@ -56,19 +56,19 @@ public class DagData { this.processDefinition = processDefinition; } - public List getProcessTaskRelationList() { + public List getProcessTaskRelationList() { return processTaskRelationList; } - public void setProcessTaskRelationList(List processTaskRelationList) { + public void setProcessTaskRelationList(List processTaskRelationList) { this.processTaskRelationList = processTaskRelationList; } - public List getTaskDefinitionList() { + public List getTaskDefinitionList() { return taskDefinitionList; } - public void setTaskDefinitionList(List taskDefinitionList) { + public void setTaskDefinitionList(List taskDefinitionList) { this.taskDefinitionList = taskDefinitionList; } } diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index 99b4f8fe87..3c2e0dd3e5 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -2350,7 +2350,7 @@ public class ProcessService { * @return dag graph */ public DAG genDagGraph(ProcessDefinition processDefinition) { - List processTaskRelations = processTaskRelationLogMapper.queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion()); + List processTaskRelations = processTaskRelationMapper.queryByProcessCode(processDefinition.getProjectCode(), processDefinition.getCode()); List taskNodeList = transformTask(processTaskRelations, Lists.newArrayList()); ProcessDag processDag = DagHelper.getProcessDag(taskNodeList, new ArrayList<>(processTaskRelations)); // Generate concrete Dag to be executed @@ -2361,13 +2361,17 @@ public class ProcessService { * generate DagData */ public DagData genDagData(ProcessDefinition processDefinition) { - List processTaskRelations = processTaskRelationLogMapper.queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion()); - return new DagData(processDefinition, processTaskRelations, genTaskDefineList(processTaskRelations)); + List processTaskRelations = processTaskRelationMapper.queryByProcessCode(processDefinition.getProjectCode(), processDefinition.getCode()); + List taskDefinitionLogList = genTaskDefineList(processTaskRelations); + List taskDefinitions = taskDefinitionLogList.stream() + .map(taskDefinitionLog -> JSONUtils.parseObject(JSONUtils.toJsonString(taskDefinitionLog), TaskDefinition.class)) + .collect(Collectors.toList()); + return new DagData(processDefinition, processTaskRelations, taskDefinitions); } - private List genTaskDefineList(List processTaskRelations) { + public List genTaskDefineList(List processTaskRelations) { Set taskDefinitionSet = new HashSet<>(); - for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) { + for (ProcessTaskRelation processTaskRelation : processTaskRelations) { if (processTaskRelation.getPreTaskCode() > 0) { taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPreTaskCode(), processTaskRelation.getPreTaskVersion())); } @@ -2446,24 +2450,6 @@ public class ProcessService { return taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, taskDefinitionVersion); } - /** - * query tasks definition list by process code and process version - */ - public List queryTaskDefinitionListByProcess(long processCode, int processVersion) { - List processTaskRelationLogs = - processTaskRelationLogMapper.queryByProcessCodeAndVersion(processCode, processVersion); - Set taskDefinitionSet = new HashSet<>(); - for (ProcessTaskRelationLog processTaskRelationLog : processTaskRelationLogs) { - if (processTaskRelationLog.getPreTaskCode() > 0) { - taskDefinitionSet.add(new TaskDefinition(processTaskRelationLog.getPreTaskCode(), processTaskRelationLog.getPreTaskVersion())); - } - if (processTaskRelationLog.getPostTaskCode() > 0) { - taskDefinitionSet.add(new TaskDefinition(processTaskRelationLog.getPostTaskCode(), processTaskRelationLog.getPostTaskVersion())); - } - } - return taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitionSet); - } - /** * add authorized resources * @@ -2479,9 +2465,9 @@ public class ProcessService { /** * Use temporarily before refactoring taskNode */ - public List transformTask(List taskRelationList, List taskDefinitionLogs) { + public List transformTask(List taskRelationList, List taskDefinitionLogs) { Map> taskCodeMap = new HashMap<>(); - for (ProcessTaskRelationLog processTaskRelation : taskRelationList) { + for (ProcessTaskRelation processTaskRelation : taskRelationList) { taskCodeMap.compute(processTaskRelation.getPostTaskCode(), (k, v) -> { if (v == null) { v = new ArrayList<>(); diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java index deec43a462..dee4c0cb4d 100644 --- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java +++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java @@ -38,6 +38,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstanceMap; +import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; @@ -368,17 +369,17 @@ public class ProcessServiceTest { processDefinition.setVersion(1); processDefinition.setCode(11L); - ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); - processTaskRelationLog.setName("def 1"); - processTaskRelationLog.setProcessDefinitionVersion(1); - processTaskRelationLog.setProjectCode(1L); - processTaskRelationLog.setProcessDefinitionCode(1L); - processTaskRelationLog.setPostTaskCode(3L); - processTaskRelationLog.setPreTaskCode(2L); - processTaskRelationLog.setUpdateTime(new Date()); - processTaskRelationLog.setCreateTime(new Date()); - List list = new ArrayList<>(); - list.add(processTaskRelationLog); + ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); + processTaskRelation.setName("def 1"); + processTaskRelation.setProcessDefinitionVersion(1); + processTaskRelation.setProjectCode(1L); + processTaskRelation.setProcessDefinitionCode(1L); + processTaskRelation.setPostTaskCode(3L); + processTaskRelation.setPreTaskCode(2L); + processTaskRelation.setUpdateTime(new Date()); + processTaskRelation.setCreateTime(new Date()); + List list = new ArrayList<>(); + list.add(processTaskRelation); TaskDefinitionLog taskDefinition = new TaskDefinitionLog(); taskDefinition.setCode(3L); @@ -405,11 +406,10 @@ public class ProcessServiceTest { taskDefinitionLogs.add(td2); Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(any())).thenReturn(taskDefinitionLogs); - Mockito.when(processTaskRelationLogMapper.queryByProcessCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())).thenReturn(list); + Mockito.when(processTaskRelationMapper.queryByProcessCode(Mockito.anyLong(), Mockito.anyLong())).thenReturn(list); DAG stringTaskNodeTaskNodeRelationDAG = processService.genDagGraph(processDefinition); - Assert.assertNotEquals(0, stringTaskNodeTaskNodeRelationDAG.getNodesCount()); - + Assert.assertEquals(1, stringTaskNodeTaskNodeRelationDAG.getNodesCount()); } @Test