diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index c4a8118261..a867deafc2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -43,13 +43,14 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.service.process.ProcessService; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; @@ -148,8 +149,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal } } - Project project = projectMapper.selectById(projectId); - Long[] projectCodeArray = getProjectCodesArrays(loginUser, project.getCode()); + Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectMapper.selectById(projectId).getCode() }; List processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray); @@ -172,9 +173,12 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal @Override public Map countDefinitionByUser(User loginUser, int projectId) { Map result = new HashMap<>(); - - Project project = projectMapper.selectById(projectId); - Long[] projectCodeArray = getProjectCodesArrays(loginUser, project.getCode()); + boolean checkProject = checkProject(loginUser, projectId, result); + if (!checkProject) { + return result; + } + Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectMapper.selectById(projectId).getCode() }; List defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser( loginUser.getId(), projectCodeArray, isAdmin(loginUser)); @@ -203,8 +207,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } - Project project = projectMapper.selectById(projectId); - /** * find all the task lists in the project under the user * statistics based on task status execution, failure, completion, wait, total @@ -226,7 +228,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal } } - Long[] projectCodeArray = getProjectCodesArrays(loginUser, project.getCode()); + Long[] projectCodeArray = projectId == 0 ? getProjectCodesArrays(loginUser) + : new Long[] { projectMapper.selectById(projectId).getCode() }; // count normal command state Map normalCountCommandCounts = commandMapper.countCommandState(loginUser.getId(), start, end, projectCodeArray) .stream() @@ -249,15 +252,14 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } - private Long[] getProjectCodesArrays(User loginUser, Long projectCode) { - List projectCodes = new ArrayList<>(); - if (projectCode != 0) { - projectCodes.add(projectCode); - } else if (loginUser.getUserType() == UserType.GENERAL_USER) { - projectCodes = processService.getProjectIdListHavePerm(loginUser.getId()); - if (projectCodes.isEmpty()) { - projectCodes.add(0L); - } + private Long[] getProjectCodesArrays(User loginUser) { + List projectList = projectMapper.queryRelationProjectListByUserId( + loginUser.getUserType() == UserType.ADMIN_USER ? 0 : loginUser.getId()); + Set projectCodes = new HashSet<>(); + projectList.forEach(project -> projectCodes.add(project.getCode())); + if (loginUser.getUserType() == UserType.GENERAL_USER) { + List createProjects = projectMapper.queryProjectCreatedByUser(loginUser.getId()); + createProjects.forEach(project -> projectCodes.add(project.getCode())); } return projectCodes.toArray(new Long[0]); } 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 4134ccaed0..96a7372781 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 @@ -66,6 +66,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.service.permission.PermissionCheck; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -123,6 +124,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro @Autowired private ProjectService projectService; + @Autowired + private UserMapper userMapper; + @Autowired private ProcessDefinitionLogMapper processDefinitionLogMapper; @@ -270,11 +274,21 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro IPage processDefinitionIPage = processDefinitionMapper.queryDefineListPaging( page, searchVal, userId, project.getCode(), isAdmin(loginUser)); - processDefinitionIPage.setRecords(processDefinitionIPage.getRecords()); + List records = processDefinitionIPage.getRecords(); + + for (ProcessDefinition pd : records) { + ProcessDefinitionLog processDefinitionLog = processDefinitionLogMapper.queryMaxVersionDefinitionLog(pd.getCode()); + int operator = processDefinitionLog.getOperator(); + User user = userMapper.selectById(operator); + pd.setModifyBy(user.getUserName()); + pd.setProjectId(project.getId()); + } + + processDefinitionIPage.setRecords(records); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); pageInfo.setTotalCount((int) processDefinitionIPage.getTotal()); - pageInfo.setLists(processDefinitionIPage.getRecords()); + pageInfo.setLists(records); result.put(Constants.DATA_LIST, pageInfo); putMsg(result, Status.SUCCESS); @@ -1384,7 +1398,10 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } else { ProcessData processData = processService.genProcessData(processDefinition); List taskNodeList = processData.getTasks(); - taskNodeList.forEach(taskNode -> taskNode.setCode(0L)); + taskNodeList.forEach(taskNode -> { + taskNode.setName(taskNode.getName() + "_copy_" + DateUtils.getCurrentTimeStamp()); + taskNode.setCode(0L); + }); processData.setTasks(taskNodeList); String processDefinitionJson = JSONUtils.toJsonString(processData); return createProcessDefinition( @@ -1566,6 +1583,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } } catch (Exception e) { setFailedProcessList(failedProcessList, processDefinitionId); + logger.error("move processDefinition error: {}", e.getMessage(), e); + } } } @@ -1589,6 +1608,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } } catch (Exception e) { setFailedProcessList(failedProcessList, processDefinitionId); + logger.error("copy processDefinition error: {}", e.getMessage(), e); + } } } @@ -1676,6 +1697,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.SUCCESS); } } + /** * check has associated process definition * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 54d07f74d9..266528f330 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -259,9 +259,9 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefineId); - IPage processInstanceList = - processInstanceMapper.queryProcessInstanceListPaging(page, - project.getCode(), processDefinition.getCode(), searchVal, executorId, statusArray, host, start, end); + IPage processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(page, + project.getCode(), processDefinition == null ? 0L : processDefinition.getCode(), searchVal, + executorId, statusArray, host, start, end); List processInstances = processInstanceList.getRecords(); List userIds = CollectionUtils.transformToList(processInstances, ProcessInstance::getExecutorId); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index a484e584fb..09d0a362f3 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -444,7 +444,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic return Constants.ALL_PERMISSIONS; } - ProjectUser projectUser = projectUserMapper.queryProjectRelation(project.getCode(), user.getId()); + ProjectUser projectUser = projectUserMapper.queryProjectRelation(project.getId(), user.getId()); if (projectUser == null) { return 0; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java index c1da442a72..885a17a88f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java @@ -271,25 +271,9 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe return result; } TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version); - taskDefinition.setVersion(version); - taskDefinition.setCode(taskCode); - taskDefinition.setName(taskDefinitionLog.getName()); - taskDefinition.setDescription(taskDefinitionLog.getDescription()); - taskDefinition.setProjectCode(taskDefinitionLog.getProjectCode()); - taskDefinition.setUserId(loginUser.getId()); - taskDefinition.setTaskType(taskDefinitionLog.getTaskType()); - taskDefinition.setTaskParams(taskDefinitionLog.getTaskParams()); - taskDefinition.setFlag(taskDefinitionLog.getFlag()); - taskDefinition.setTaskPriority(taskDefinitionLog.getTaskPriority()); - taskDefinition.setWorkerGroup(taskDefinitionLog.getWorkerGroup()); - taskDefinition.setFailRetryTimes(taskDefinitionLog.getFailRetryTimes()); - taskDefinition.setFailRetryInterval(taskDefinitionLog.getFailRetryInterval()); - taskDefinition.setTimeoutFlag(taskDefinitionLog.getTimeoutFlag()); - taskDefinition.setTimeoutNotifyStrategy(taskDefinitionLog.getTimeoutNotifyStrategy()); - taskDefinition.setTimeout(taskDefinitionLog.getTimeout()); - taskDefinition.setUpdateTime(new Date()); - taskDefinition.setResourceIds(taskDefinitionLog.getResourceIds()); - taskDefinitionMapper.updateById(taskDefinition); + taskDefinitionLog.setUserId(loginUser.getId()); + taskDefinitionLog.setUpdateTime(new Date()); + taskDefinitionMapper.updateById(taskDefinitionLog); result.put(Constants.DATA_LIST, taskCode); putMsg(result, Status.SUCCESS); return result; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java index 34ab22d85f..a4bb7c3bf3 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java @@ -533,10 +533,10 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { putMsg(result, Status.USER_NOT_EXIST, userId); return result; } - //if the selected projectIds are empty, delete all items associated with the user - projectUserMapper.deleteProjectRelation(0L, userId); + //if the selected projectIds are empty, delete all items associated with the user if (check(result, StringUtils.isEmpty(projectIds), Status.SUCCESS)) { + projectUserMapper.deleteProjectRelation(0, userId); return result; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index f227cc0559..857c52af79 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -116,7 +116,7 @@ public class ProjectServiceTest { @Test public void testCheckProjectAndAuth() { - Mockito.when(projectUserMapper.queryProjectRelation(1L, 1)).thenReturn(getProjectUser()); + Mockito.when(projectUserMapper.queryProjectRelation(1, 1)).thenReturn(getProjectUser()); User loginUser = getLoginUser(); Map result = projectService.checkProjectAndAuth(loginUser, null, projectName); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index fd08ec6f35..d8bcdb8070 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -318,7 +318,7 @@ public class UsersServiceTest { logger.info(result.toString()); Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); //success - when(projectUserMapper.deleteProjectRelation(Mockito.anyLong(), Mockito.anyInt())).thenReturn(1); + when(projectUserMapper.deleteProjectRelation(Mockito.anyInt(), Mockito.anyInt())).thenReturn(1); result = usersService.grantProject(loginUser, 1, projectIds); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/PreviousTaskNode.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/PreviousTaskNode.java index c0ac665d19..020357578e 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/PreviousTaskNode.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/PreviousTaskNode.java @@ -34,6 +34,10 @@ public class PreviousTaskNode { */ private int version; + public PreviousTaskNode() { + + } + public PreviousTaskNode(long code, String name, int version) { this.code = code; this.name = name; 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 1e338d908d..60be33bf6c 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 @@ -137,12 +137,6 @@ public class TaskNode { */ private String workerGroup; - /** - * worker group id - */ - private Integer workerGroupId; - - /** * task time out */ @@ -325,14 +319,6 @@ public class TaskNode { this.conditionResult = conditionResult; } - public Integer getWorkerGroupId() { - return workerGroupId; - } - - public void setWorkerGroupId(Integer workerGroupId) { - this.workerGroupId = workerGroupId; - } - public int getDelayTime() { return delayTime; } @@ -405,7 +391,6 @@ public class TaskNode { + ", conditionResult='" + conditionResult + '\'' + ", taskInstancePriority=" + taskInstancePriority + ", workerGroup='" + workerGroup + '\'' - + ", workerGroupId=" + workerGroupId + ", timeout='" + timeout + '\'' + ", delayTime=" + delayTime + '}'; diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java index e6cd041c57..3ec1a2e39b 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java @@ -23,6 +23,8 @@ public class StringUtils { public static final String EMPTY = ""; + public static final int INDEX_NOT_FOUND = -1; + private StringUtils() { throw new UnsupportedOperationException("Construct StringUtils"); } @@ -89,4 +91,32 @@ public class StringUtils { public static boolean equalsIgnoreCase(String str1, String str2) { return str1 == null ? str2 == null : str1.equalsIgnoreCase(str2); } + + public static String substringBefore(final String str, final String separator) { + if (isEmpty(str) || separator == null) { + return str; + } + if (separator.isEmpty()) { + return EMPTY; + } + final int pos = str.indexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return str; + } + return str.substring(0, pos); + } + + public static String substringAfter(final String str, final String separator) { + if (isEmpty(str)) { + return str; + } + if (separator == null) { + return EMPTY; + } + final int pos = str.indexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return EMPTY; + } + return str.substring(pos + separator.length()); + } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectUser.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectUser.java index e541ac0cc0..37722f3c79 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectUser.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectUser.java @@ -34,12 +34,9 @@ public class ProjectUser { @TableField("user_id") private int userId; - @TableField(exist = false) + @TableField("project_id") private int projectId; - @TableField("project_code") - private long projectCode; - /** * project name */ @@ -63,14 +60,6 @@ public class ProjectUser { @TableField("update_time") private Date updateTime; - public long getProjectCode() { - return projectCode; - } - - public void setProjectCode(long projectCode) { - this.projectCode = projectCode; - } - public int getId() { return id; } @@ -141,7 +130,6 @@ public class ProjectUser { + "id=" + id + ", userId=" + userId + ", projectId=" + projectId - + ", projectCode=" + projectCode + ", projectName='" + projectName + '\'' + ", userName='" + userName + '\'' + ", perm=" + perm diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java index aa8fc15312..4511051a43 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.java @@ -55,6 +55,11 @@ public interface ProcessDefinitionLogMapper extends BaseMapper { */ List queryAuthedProjectListByUserId(@Param("userId") int userId); + /** + * query relation project list by userId + * @param userId userId + * @return project list + */ + List queryRelationProjectListByUserId(@Param("userId") int userId); + /** * query project except userId * @param userId userId diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.java index f842eb35e4..b6947210be 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.java @@ -17,9 +17,11 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.ProjectUser; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; + import org.apache.ibatis.annotations.Param; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + /** * project user mapper interface */ @@ -27,19 +29,21 @@ public interface ProjectUserMapper extends BaseMapper { /** * delte prject user relation - * @param projectCode projectCode + * + * @param projectId projectId * @param userId userId * @return delete result */ - int deleteProjectRelation(@Param("projectCode") Long projectCode, + int deleteProjectRelation(@Param("projectId") int projectId, @Param("userId") int userId); /** * query project relation - * @param projectCode projectCode + * + * @param projectId projectId * @param userId userId * @return project user relation */ - ProjectUser queryProjectRelation(@Param("projectCode") Long projectCode, + ProjectUser queryProjectRelation(@Param("projectId") int projectId, @Param("userId") int userId); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java index 970fc47de8..695a98ac9e 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/DagHelper.java @@ -24,15 +24,21 @@ import org.apache.dolphinscheduler.common.model.TaskNodeRelation; import org.apache.dolphinscheduler.common.process.ProcessDag; import org.apache.dolphinscheduler.common.task.conditions.ConditionsParameters; import org.apache.dolphinscheduler.common.utils.CollectionUtils; -import org.apache.dolphinscheduler.common.utils.*; +import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; - /** * dag tools */ @@ -68,10 +74,10 @@ public class DagHelper { /** * generate task nodes needed by dag * - * @param taskNodeList taskNodeList - * @param startNodeNameList startNodeNameList + * @param taskNodeList taskNodeList + * @param startNodeNameList startNodeNameList * @param recoveryNodeNameList recoveryNodeNameList - * @param taskDependType taskDependType + * @param taskDependType taskDependType * @return task node list */ public static List generateFlowNodeListByStartNode(List taskNodeList, List startNodeNameList, @@ -129,7 +135,7 @@ public class DagHelper { /** * find all the nodes that depended on the start node * - * @param startNode startNode + * @param startNode startNode * @param taskNodeList taskNodeList * @return task node list */ @@ -154,9 +160,9 @@ public class DagHelper { /** * find all nodes that start nodes depend on. * - * @param startNode startNode + * @param startNode startNode * @param recoveryNodeNameList recoveryNodeNameList - * @param taskNodeList taskNodeList + * @param taskNodeList taskNodeList * @return task node list */ private static List getFlowNodeListPre(TaskNode startNode, List recoveryNodeNameList, List taskNodeList, List visitedNodeNameList) { @@ -189,10 +195,10 @@ public class DagHelper { /** * generate dag by start nodes and recovery nodes * - * @param totalTaskNodeList totalTaskNodeList - * @param startNodeNameList startNodeNameList - * @param recoveryNodeNameList recoveryNodeNameList - * @param depNodeType depNodeType + * @param totalTaskNodeList totalTaskNodeList + * @param startNodeNameList startNodeNameList + * @param recoveryNodeNameList recoveryNodeNameList + * @param depNodeType depNodeType * @return process dag * @throws Exception if error throws Exception */ @@ -216,7 +222,7 @@ public class DagHelper { * find node by node name * * @param nodeDetails nodeDetails - * @param nodeName nodeName + * @param nodeName nodeName * @return task node */ public static TaskNode findNodeByName(List nodeDetails, String nodeName) { @@ -231,8 +237,8 @@ public class DagHelper { /** * the task can be submit when all the depends nodes are forbidden or complete * - * @param taskNode taskNode - * @param dag dag + * @param taskNode taskNode + * @param dag dag * @param completeTaskList completeTaskList * @return can submit */ @@ -262,7 +268,6 @@ public class DagHelper { * this function parse the condition node to find the right branch. * also check all the depends nodes forbidden or complete * - * @param preNodeName * @return successor nodes */ public static Set parsePostNodes(String preNodeName, @@ -299,9 +304,6 @@ public class DagHelper { /** * if all of the task dependence are skipped, skip it too. - * - * @param taskNode - * @return */ private static boolean isTaskNodeNeedSkip(TaskNode taskNode, Map skipTaskNodeList @@ -321,9 +323,6 @@ public class DagHelper { /** * parse condition task find the branch process * set skip flag for another one. - * - * @param nodeName - * @return */ public static List parseConditionTask(String nodeName, Map skipTaskNodeList, @@ -358,11 +357,6 @@ public class DagHelper { /** * set task node and the post nodes skip flag - * - * @param skipNodeName - * @param dag - * @param completeTaskList - * @param skipTaskNodeList */ private static void setTaskNodeSkip(String skipNodeName, DAG dag, @@ -451,9 +445,13 @@ public class DagHelper { List taskNodeRelations = new ArrayList<>(); for (ProcessTaskRelation processTaskRelation : processTaskRelations) { - if (processTaskRelation.getPreTaskCode() != 0) { - TaskNode preNode = taskNodeMap.get(processTaskRelation.getPreTaskCode()); - TaskNode postNode = taskNodeMap.get(processTaskRelation.getPostTaskCode()); + long preTaskCode = processTaskRelation.getPreTaskCode(); + long postTaskCode = processTaskRelation.getPostTaskCode(); + + if (processTaskRelation.getPreTaskCode() != 0 + && taskNodeMap.containsKey(preTaskCode) && taskNodeMap.containsKey(postTaskCode)) { + TaskNode preNode = taskNodeMap.get(preTaskCode); + TaskNode postNode = taskNodeMap.get(postTaskCode); taskNodeRelations.add(new TaskNodeRelation(preNode.getName(), postNode.getName())); } } @@ -465,9 +463,6 @@ public class DagHelper { /** * is there have conditions after the parent node - * - * @param parentNodeName - * @return */ public static boolean haveConditionsAfterNode(String parentNodeName, DAG dag @@ -489,9 +484,6 @@ public class DagHelper { /** * is there have conditions after the parent node - * - * @param parentNodeName - * @return */ public static boolean haveConditionsAfterNode(String parentNodeName, List taskNodes diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml index 0865e964f4..5f93854a3d 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml @@ -29,7 +29,7 @@ - and cmd.startTime = ]]> #{startTime} and cmd.update_time #{endTime} + and cmd.start_time = ]]> #{startTime} and cmd.update_time #{endTime} group by cmd.command_type diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml index a6e2b35db7..92642e2592 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml @@ -56,6 +56,14 @@ where code = #{processDefinitionCode} + + + select from t_ds_relation_project_user - where project_code = #{projectCode} + where project_id = #{projectId} and user_id = #{userId} limit 1 diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java index 7316fc5f93..f0981b0c8d 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java @@ -107,7 +107,7 @@ public class ProcessDefinitionLogMapperTest { @Test public void testQueryByDefinitionName() { - ProcessDefinitionLog processDefinitionLog = insertOne(); + insertOne(); Project project = new Project(); project.setCode(1L); project.setName("ut project"); @@ -130,7 +130,7 @@ public class ProcessDefinitionLogMapperTest { @Test public void testQueryByDefinitionCode() { - ProcessDefinitionLog processDefinitionLog = insertOne(); + insertOne(); List processDefinitionLogs = processDefinitionLogMapper .queryByDefinitionCode(1L); @@ -139,7 +139,7 @@ public class ProcessDefinitionLogMapperTest { @Test public void testQueryByDefinitionCodeAndVersion() { - ProcessDefinitionLog processDefinitionLog = insertOne(); + insertOne(); ProcessDefinitionLog processDefinitionLogs = processDefinitionLogMapper .queryByDefinitionCodeAndVersion(1L, 1); @@ -148,8 +148,8 @@ public class ProcessDefinitionLogMapperTest { @Test public void testQueryMaxVersionForDefinition() { - ProcessDefinitionLog processDefinitionLog = insertOne(); - ProcessDefinitionLog processDefinitionLog1 = insertTwo(); + insertOne(); + insertTwo(); Integer version = processDefinitionLogMapper.queryMaxVersionForDefinition(1L); Assert.assertEquals(2, version == null ? 1 : version); @@ -157,7 +157,7 @@ public class ProcessDefinitionLogMapperTest { @Test public void testQueryProcessDefinitionVersionsPaging() { - ProcessDefinitionLog processDefinitionLog = insertOne(); + insertOne(); Page page = new Page(1, 3); IPage processDefinitionLogs = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, 1L); Assert.assertNotEquals(processDefinitionLogs.getTotal(), 0); @@ -165,10 +165,19 @@ public class ProcessDefinitionLogMapperTest { @Test public void testDeleteByProcessDefinitionCodeAndVersion() { - ProcessDefinitionLog processDefinitionLog = insertOne(); + insertOne(); Page page = new Page(1, 3); int processDefinitionLogs = processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(1L, 1); Assert.assertNotEquals(processDefinitionLogs, 0); } + @Test + public void testQueryMaxVersionDefinitionLog() { + insertOne(); + insertTwo(); + + ProcessDefinitionLog processDefinitionLog2 = processDefinitionLogMapper.queryMaxVersionDefinitionLog(1L); + Assert.assertEquals(2, processDefinitionLog2.getVersion()); + } + } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java index a5910f7711..e8eff87830 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java @@ -52,7 +52,6 @@ public class ProjectUserMapperTest { private ProjectUser insertOne(){ //insertOne ProjectUser projectUser = new ProjectUser(); - projectUser.setProjectCode(1010L); projectUser.setProjectId(1010); projectUser.setUserId(111); projectUserMapper.insert(projectUser); @@ -101,7 +100,7 @@ public class ProjectUserMapperTest { ProjectUser projectUser = insertOne(); - int delete = projectUserMapper.deleteProjectRelation(projectUser.getProjectCode(), projectUser.getUserId()); + int delete = projectUserMapper.deleteProjectRelation(projectUser.getProjectId(), projectUser.getUserId()); assertThat(delete,greaterThanOrEqualTo(1)); } @@ -112,7 +111,7 @@ public class ProjectUserMapperTest { @Test public void testQueryProjectRelation() { ProjectUser projectUser = insertOne(); - ProjectUser projectUser1 = projectUserMapper.queryProjectRelation(projectUser.getProjectCode(), projectUser.getUserId()); + ProjectUser projectUser1 = projectUserMapper.queryProjectRelation(projectUser.getProjectId(), projectUser.getUserId()); Assert.assertNotEquals(projectUser1, null); } 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 5a12c6e13a..9c9a4e7fbc 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 @@ -2222,7 +2222,6 @@ public class ProcessService { * update task definition */ public int updateTaskDefinition(User operator, Long projectCode, TaskNode taskNode, TaskDefinition taskDefinition) { - Integer version = taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinition.getCode()); Date now = new Date(); taskDefinition.setProjectCode(projectCode); @@ -2240,10 +2239,11 @@ public class ProcessService { } private void setTaskFromTaskNode(TaskNode taskNode, TaskDefinition taskDefinition) { - taskDefinition.setName(taskNode.getName()); + // TODO for the front-end UI, name with id + taskDefinition.setName(taskNode.getId() + "|" + taskNode.getName()); taskDefinition.setDescription(taskNode.getDesc()); taskDefinition.setTaskType(TaskType.of(taskNode.getType())); - taskDefinition.setTaskParams(taskNode.getParams()); + taskDefinition.setTaskParams(TaskType.of(taskNode.getType()) == TaskType.DEPENDENT ? taskNode.getDependence() : taskNode.getParams()); taskDefinition.setFlag(taskNode.isForbidden() ? Flag.NO : Flag.YES); taskDefinition.setTaskPriority(taskNode.getTaskInstancePriority()); taskDefinition.setWorkerGroup(taskNode.getWorkerGroup()); @@ -2298,6 +2298,7 @@ public class ProcessService { String desc, String locations, String connects) { ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog(); Integer version = processDefineLogMapper.queryMaxVersionForDefinition(processDefinitionCode); + processDefinitionLog.setUserId(operator.getId()); processDefinitionLog.setCode(processDefinitionCode); processDefinitionLog.setVersion(version == null || version == 0 ? 1 : version); processDefinitionLog.setName(processDefinitionName); @@ -2500,15 +2501,17 @@ public class ProcessService { Map taskDefinitionLogMap = taskDefinitionLogs.stream().collect(Collectors.toMap(TaskDefinitionLog::getCode, log -> log)); taskNodeMap.forEach((k, v) -> { TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMap.get(k); - v.setId("task-" + taskDefinitionLog.getId()); + // TODO split from name + v.setId(StringUtils.substringBefore(taskDefinitionLog.getName(), "|")); v.setCode(taskDefinitionLog.getCode()); - v.setName(taskDefinitionLog.getName()); + v.setName(StringUtils.substringAfter(taskDefinitionLog.getName(), "|")); v.setDesc(taskDefinitionLog.getDescription()); v.setType(taskDefinitionLog.getTaskType().getDescp().toUpperCase()); v.setRunFlag(taskDefinitionLog.getFlag() == Flag.YES ? Constants.FLOWNODE_RUN_FLAG_NORMAL : Constants.FLOWNODE_RUN_FLAG_FORBIDDEN); v.setMaxRetryTimes(taskDefinitionLog.getFailRetryTimes()); v.setRetryInterval(taskDefinitionLog.getFailRetryInterval()); - v.setParams(taskDefinitionLog.getTaskParams()); + v.setParams(taskDefinitionLog.getTaskType() == TaskType.DEPENDENT ? "" : taskDefinitionLog.getTaskParams()); + v.setDependence(taskDefinitionLog.getTaskType() == TaskType.DEPENDENT ? taskDefinitionLog.getTaskParams() : null); v.setTaskInstancePriority(taskDefinitionLog.getTaskPriority()); v.setWorkerGroup(taskDefinitionLog.getWorkerGroup()); v.setTimeout(JSONUtils.toJsonString(new TaskTimeoutParameter(taskDefinitionLog.getTimeoutFlag() == TimeoutFlag.OPEN, 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 364b283c34..1db3760366 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 @@ -21,27 +21,37 @@ import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_RECOVER_PRO import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_PARAMS; import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_DEFINE_ID; +import static org.mockito.ArgumentMatchers.any; + import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.Flag; +import org.apache.dolphinscheduler.common.enums.TaskType; import org.apache.dolphinscheduler.common.enums.WarningType; +import org.apache.dolphinscheduler.common.graph.DAG; import org.apache.dolphinscheduler.common.model.TaskNode; -import org.apache.dolphinscheduler.common.task.conditions.ConditionsParameters; +import org.apache.dolphinscheduler.common.model.TaskNodeRelation; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Command; import org.apache.dolphinscheduler.dao.entity.ProcessData; 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.ProcessTaskRelationLog; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.CommandMapper; import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper; +import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper; +import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.service.quartz.cron.CronUtilsTest; @@ -87,7 +97,13 @@ public class ProcessServiceTest { @Mock private UserMapper userMapper; @Mock - TaskInstanceMapper taskInstanceMapper; + private TaskInstanceMapper taskInstanceMapper; + @Mock + private TaskDefinitionLogMapper taskDefinitionLogMapper; + @Mock + private ProcessTaskRelationMapper processTaskRelationMapper; + @Mock + private ProcessDefinitionLogMapper processDefineLogMapper; @Test public void testCreateSubCommand() { @@ -328,4 +344,163 @@ public class ProcessServiceTest { processService.recurseFindSubProcessId(parentId, ids); } + + @Test + public void testSaveProcessDefinition() { + User user = new User(); + user.setId(1); + + Project project = new Project(); + project.setCode(1L); + + ProcessData processData = new ProcessData(); + + ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setCode(1L); + processDefinition.setId(123); + processDefinition.setName("test"); + processDefinition.setVersion(1); + processDefinition.setCode(11L); + + Mockito.when(processDefineMapper.updateById(any())).thenReturn(1); + Mockito.when(processDefineLogMapper.insert(any())).thenReturn(1); + + int i = processService.saveProcessDefinition(user, project, "name", "desc", "locations", "connects", processData, processDefinition); + Assert.assertEquals(1, i); + + } + + @Test + public void testSwitchVersion() { + ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setCode(1L); + processDefinition.setId(123); + processDefinition.setName("test"); + processDefinition.setVersion(1); + processDefinition.setCode(11L); + + ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog(); + processDefinitionLog.setCode(1L); + + Mockito.when(processDefineMapper.updateById(any())).thenReturn(1); + + int i = processService.switchVersion(processDefinition, processDefinitionLog); + + Assert.assertEquals(1, i); + + } + + @Test + public void testGenDagGraph() { + ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setCode(1L); + processDefinition.setId(123); + processDefinition.setName("test"); + 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); + + TaskDefinitionLog taskDefinition = new TaskDefinitionLog(); + taskDefinition.setCode(3L); + taskDefinition.setName("1-test"); + taskDefinition.setProjectCode(1L); + taskDefinition.setTaskType(TaskType.SHELL); + taskDefinition.setUserId(1); + taskDefinition.setVersion(2); + taskDefinition.setCreateTime(new Date()); + taskDefinition.setUpdateTime(new Date()); + + TaskDefinitionLog td2 = new TaskDefinitionLog(); + td2.setCode(2L); + td2.setName("unit-test"); + td2.setProjectCode(1L); + td2.setTaskType(TaskType.SHELL); + td2.setUserId(1); + td2.setVersion(1); + td2.setCreateTime(new Date()); + td2.setUpdateTime(new Date()); + + List taskDefinitionLogs = new ArrayList<>(); + taskDefinitionLogs.add(taskDefinition); + taskDefinitionLogs.add(td2); + + Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(any())).thenReturn(taskDefinitionLogs); + Mockito.when(processTaskRelationLogMapper.queryByProcessCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())).thenReturn(list); + + DAG stringTaskNodeTaskNodeRelationDAG = processService.genDagGraph(processDefinition); + Assert.assertNotEquals(0, stringTaskNodeTaskNodeRelationDAG.getNodesCount()); + + } + + @Test + public void testGenProcessData() { + String processDefinitionJson = "{\"tasks\":[{\"id\":\"task-0\",\"code\":3,\"version\":0,\"name\":\"1-test\"" + + ",\"desc\":null,\"type\":\"SHELL\",\"runFlag\":\"FORBIDDEN\",\"loc\":null,\"maxRetryTimes\":0" + + ",\"retryInterval\":0,\"params\":null,\"preTasks\":[\"unit-test\"],\"preTaskNodeList\":[{\"code\":2" + + ",\"name\":\"unit-test\",\"version\":0}],\"extras\":null,\"depList\":[\"unit-test\"],\"dependence\":null" + + ",\"conditionResult\":null,\"taskInstancePriority\":null,\"workerGroup\":null,\"workerGroupId\":null" + + ",\"timeout\":{\"enable\":false,\"strategy\":null,\"interval\":0},\"delayTime\":0}]" + + ",\"globalParams\":[],\"timeout\":0,\"tenantId\":0}"; + + ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setCode(1L); + processDefinition.setId(123); + processDefinition.setName("test"); + 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); + + TaskDefinitionLog taskDefinition = new TaskDefinitionLog(); + taskDefinition.setCode(3L); + taskDefinition.setName("1-test"); + taskDefinition.setProjectCode(1L); + taskDefinition.setTaskType(TaskType.SHELL); + taskDefinition.setUserId(1); + taskDefinition.setVersion(2); + taskDefinition.setCreateTime(new Date()); + taskDefinition.setUpdateTime(new Date()); + + TaskDefinitionLog td2 = new TaskDefinitionLog(); + td2.setCode(2L); + td2.setName("unit-test"); + td2.setProjectCode(1L); + td2.setTaskType(TaskType.SHELL); + td2.setUserId(1); + td2.setVersion(1); + td2.setCreateTime(new Date()); + td2.setUpdateTime(new Date()); + + List taskDefinitionLogs = new ArrayList<>(); + taskDefinitionLogs.add(taskDefinition); + taskDefinitionLogs.add(td2); + + Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(any())).thenReturn(taskDefinitionLogs); + Mockito.when(processTaskRelationLogMapper.queryByProcessCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())).thenReturn(list); + String json = JSONUtils.toJsonString(processService.genProcessData(processDefinition)); + + Assert.assertEquals(processDefinitionJson, json); + + } } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue index 582c6a43f4..3f60abaab0 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/formModel.vue @@ -64,7 +64,7 @@ :rows="2" type="textarea" :disabled="isDetails" - v-model="description" + v-model="desc" :placeholder="$t('Please enter description')"> @@ -314,7 +314,7 @@ // node name name: '', // description - description: '', + desc: '', // Node echo data backfillItem: {}, cacheBackfillItem: {}, @@ -332,8 +332,8 @@ dependence: {}, // cache dependence cacheDependence: {}, - //task code - code:'', + // task code + code: '', // Current node params data params: {}, // Running sign @@ -475,9 +475,9 @@ type: this.nodeData.taskType, id: this.nodeData.id, name: this.name, - code:this.code, + code: this.code, params: this.params, - description: this.description, + desc: this.desc, runFlag: this.runFlag, conditionResult: this.conditionResult, dependence: this.cacheDependence, @@ -601,7 +601,7 @@ name: this.name, code: this.code, params: this.params, - description: this.description, + desc: this.desc, runFlag: this.runFlag, conditionResult: this.conditionResult, dependence: this.dependence, @@ -696,7 +696,7 @@ this.name = o.name this.taskInstancePriority = o.taskInstancePriority this.runFlag = o.runFlag || 'NORMAL' - this.description = o.description + this.desc = o.desc this.maxRetryTimes = o.maxRetryTimes this.retryInterval = o.retryInterval this.delayTime = o.delayTime @@ -767,7 +767,7 @@ type: this.nodeData.taskType, id: this.nodeData.id, name: this.name, - description: this.description, + desc: this.desc, runFlag: this.runFlag, dependence: this.cacheDependence, maxRetryTimes: this.maxRetryTimes, diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/index.vue index 252fedc971..bcd2ab6996 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/instance/pages/gantt/index.vue @@ -29,7 +29,7 @@ -