From d99934d0da8d6d13b9a7a2d2d963f94e1399e678 Mon Sep 17 00:00:00 2001 From: JinyLeeChina <42576980+JinyLeeChina@users.noreply.github.com> Date: Tue, 23 Mar 2021 10:44:25 +0800 Subject: [PATCH 1/6] [Feature][JsonSplit] Fix api bug (#5102) * modify checkDAGRing and ProcessService method * merge * modify dagRing * modify process instance for project home page * fix save process bug * codeStyle * Fix logical bug in saving process definition * codeSytle * Fix bug in interface of queryProcessDefinitionList * codeSytle * Fix api bug" Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../service/impl/DataAnalysisServiceImpl.java | 38 ++++++++++--------- .../impl/ProcessInstanceServiceImpl.java | 6 +-- .../api/service/impl/ProjectServiceImpl.java | 2 +- .../impl/TaskDefinitionServiceImpl.java | 22 ++--------- .../api/service/impl/UsersServiceImpl.java | 4 +- .../api/service/ProjectServiceTest.java | 2 +- .../api/service/UsersServiceTest.java | 2 +- .../common/model/TaskNode.java | 15 -------- .../dao/entity/ProjectUser.java | 14 +------ .../dao/mapper/ProjectMapper.java | 7 ++++ .../dao/mapper/ProjectUserMapper.java | 14 ++++--- .../dao/mapper/ErrorCommandMapper.xml | 2 +- .../dao/mapper/ProjectMapper.xml | 29 ++++++++++---- .../dao/mapper/ProjectUserMapper.xml | 8 ++-- .../dao/mapper/ProjectUserMapperTest.java | 5 +-- .../service/process/ProcessService.java | 6 +-- sql/dolphinscheduler_mysql.sql | 2 +- 17 files changed, 80 insertions(+), 98 deletions(-) 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/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 95e3f5c4a5..e2f4320cdc 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(); 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 00cb72079f..869cfafe5c 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 @@ -525,10 +525,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 bba368b32d..e8707fc01e 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 @@ -305,7 +305,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/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-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/ProjectMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java index ffc45a2eb3..ad4cdb99cc 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java @@ -85,6 +85,13 @@ public interface ProjectMapper 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/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/ProjectMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml index 0469587c75..04db7ab238 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml @@ -19,7 +19,6 @@ - id, name, code, description, user_id, flag, create_time, update_time @@ -83,9 +82,9 @@ join t_ds_user u on u.id=p.user_id where 1=1 - and p.code in - (select project_code from t_ds_relation_project_user where user_id=#{userId} - union select id as project_code from t_ds_project where user_id=#{userId} + and p.id in + (select project_id from t_ds_relation_project_user where user_id=#{userId} + union select id as project_id from t_ds_project where user_id=#{userId} ) @@ -101,6 +100,18 @@ from t_ds_project p,t_ds_relation_project_user rel where p.id = rel.project_id and rel.user_id= #{userId} + 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/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..a1f5eca8b8 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); @@ -2243,7 +2242,7 @@ public class ProcessService { taskDefinition.setName(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()); @@ -2508,7 +2507,8 @@ public class ProcessService { 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() : ""); v.setTaskInstancePriority(taskDefinitionLog.getTaskPriority()); v.setWorkerGroup(taskDefinitionLog.getWorkerGroup()); v.setTimeout(JSONUtils.toJsonString(new TaskTimeoutParameter(taskDefinitionLog.getTimeoutFlag() == TimeoutFlag.OPEN, diff --git a/sql/dolphinscheduler_mysql.sql b/sql/dolphinscheduler_mysql.sql index 8158b54161..419e90b220 100644 --- a/sql/dolphinscheduler_mysql.sql +++ b/sql/dolphinscheduler_mysql.sql @@ -696,7 +696,7 @@ DROP TABLE IF EXISTS `t_ds_relation_project_user`; CREATE TABLE `t_ds_relation_project_user` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', `user_id` int(11) NOT NULL COMMENT 'user id', - `project_code` bigint(20) DEFAULT NULL COMMENT 'project code', + `project_id` int(11) DEFAULT NULL COMMENT 'project id', `perm` int(11) DEFAULT '1' COMMENT 'limits of authority', `create_time` datetime DEFAULT NULL COMMENT 'create time', `update_time` datetime DEFAULT NULL COMMENT 'update time', From 1eaf1f62349cdd469bce092297bacfc7893d1d0d Mon Sep 17 00:00:00 2001 From: JinyLeeChina <42576980+JinyLeeChina@users.noreply.github.com> Date: Wed, 24 Mar 2021 11:44:14 +0800 Subject: [PATCH 2/6] [Feature][JsonSplit] fix taskId in processDefinitionJson (#5136) * modify checkDAGRing and ProcessService method * merge * modify dagRing * modify process instance for project home page * fix save process bug * codeStyle * Fix logical bug in saving process definition * codeSytle * Fix bug in interface of queryProcessDefinitionList * codeSytle * Fix api bug" * fix taskId in processDefinitionJson Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../common/utils/StringUtils.java | 30 +++++++++++++++++++ .../service/process/ProcessService.java | 8 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) 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-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 a1f5eca8b8..2c826dc592 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 @@ -2239,7 +2239,8 @@ 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(TaskType.of(taskNode.getType()) == TaskType.DEPENDENT ? taskNode.getDependence() : taskNode.getParams()); @@ -2499,9 +2500,10 @@ 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); From 21b7b77d5034647690f6ebf72fedbcdc54a5b426 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Mar 2021 14:54:34 +0800 Subject: [PATCH 3/6] [Feature][JsonSplit]fix modifyBy field (#5112) * Modify Project and ProjectUser Mapper * Modify Project and ProjectUser Mapper * project_code is bigint(20) * modify ERROR name * modify saveProcessDefine, remove the duplicate code with createTaskAndRelation * modify import/export processdefinition, add genProcessData * fix ut and bug * code style * repalce project_id with code * conflicts solve * conflicts solve * conflicts solve * bugfix * modify listResources mothod and remove getResourceIds mothod * 1 * conflicts solve * modify listResources mothod and remove getResourceIds mothod * modify listResources mothod and remove getResourceIds mothod * replace processDefinitionVersion with processDefinitionLog * codestyle * codestyle * add mapper module ut * codestyle * fix ProcessInstanceMapperTest * codestyle * conflicts solve * conflicts solve * conflicts solve * conflicts solve * conflicts solve * fix ProcessInstanceMapperTest * fix ProjectMapperTest/ProjectUserMapperTest/ScheduleMapperTest * fix ProjectMapperTest/ProjectUserMapperTest/ScheduleMapperTest * fix TaskInstanceMapperTest * add TaskDefinitionLogMapperTest/TaskDefinitionMapperTest and bugfix * codestyle * codestyle * Refactor process lineage * Refactor process lineage * codestyle * codestyle * Refactor process lineage * Refactor process lineage * add WorkFlowLineageMapperTest/WorkFlowLineageServiceTest * add WorkFlowLineageMapperTest/WorkFlowLineageServiceTest * add ProcessServiceTest * 1 * 1 * fix modifyBy field * 1 * ut fix --- .../impl/ProcessDefinitionServiceImpl.java | 17 ++++++++++++-- .../mapper/ProcessDefinitionLogMapper.java | 5 ++++ .../dao/mapper/ProcessDefinitionLogMapper.xml | 8 +++++++ .../ProcessDefinitionLogMapperTest.java | 23 +++++++++++++------ 4 files changed, 44 insertions(+), 9 deletions(-) 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..dec3d19547 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,20 @@ 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()); + } + + 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); 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 + +