From 46ab86d6dff94827bd265965f0c70b4f9c979868 Mon Sep 17 00:00:00 2001 From: zixi0825 <649790970@qq.com> Date: Thu, 13 Aug 2020 15:37:46 +0800 Subject: [PATCH] batch copy or move process #2753 (#2884) * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process sovle code smell * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * batch copy or move process * Roll back the package.json file * rerun test * revert blank * resolve conflicts * resolve conflicts * resolve ut error * resolve sonar error Co-authored-by: sunchaohe Co-authored-by: dailidong --- .../ProcessDefinitionController.java | 60 +++- .../controller/ProcessInstanceController.java | 2 +- .../api/controller/ProjectController.java | 20 ++ .../dolphinscheduler/api/enums/Status.java | 24 +- .../api/service/AlertGroupService.java | 12 +- .../api/service/DataSourceService.java | 6 +- .../api/service/ExecutorService.java | 12 +- .../api/service/MonitorService.java | 8 +- .../api/service/ProcessDefinitionService.java | 38 ++- .../api/service/ProcessInstanceService.java | 8 +- .../api/service/ProjectService.java | 36 ++- .../api/service/QueueService.java | 8 +- .../api/service/ResourcesService.java | 12 +- .../api/service/SchedulerService.java | 6 +- .../api/service/TaskInstanceService.java | 2 +- .../api/service/TenantService.java | 12 +- .../api/service/UdfFuncService.java | 6 +- .../api/service/UsersService.java | 24 +- .../api/service/WorkerGroupService.java | 2 +- .../impl/ProcessDefinitionServiceImpl.java | 285 +++++++++++++++--- .../main/resources/i18n/messages.properties | 8 +- .../resources/i18n/messages_en_US.properties | 6 +- .../resources/i18n/messages_zh_CN.properties | 6 +- .../ProcessDefinitionControllerTest.java | 52 ++-- .../api/service/AlertGroupServiceTest.java | 2 +- .../api/service/ExecutorServiceTest.java | 2 +- .../service/ProcessDefinitionServiceTest.java | 84 +++++- .../service/ProcessInstanceServiceTest.java | 14 +- .../api/service/ProjectServiceTest.java | 20 ++ .../api/service/TaskInstanceServiceTest.java | 2 +- .../common/utils/StringUtils.java | 4 + 31 files changed, 594 insertions(+), 189 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 6b539d01b1..29f415bac2 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 @@ -95,27 +95,65 @@ public class ProcessDefinitionController extends BaseController { } /** - * copy process definition + * copy process definition * * @param loginUser login user * @param projectName project name - * @param processId process definition id + * @param processDefinitionIds process definition ids + * @param targetProjectId target project id * @return copy result code */ @ApiOperation(value = "copyProcessDefinition", notes= "COPY_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, dataType = "String", example = "3,4"), + @ApiImplicitParam(name = "targetProjectId", value = "TARGET_PROJECT_ID", required = true, type = "Integer") }) @PostMapping(value = "/copy") @ResponseStatus(HttpStatus.OK) - @ApiException(COPY_PROCESS_DEFINITION_ERROR) + @ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR) public Result copyProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam(value = "processId", required = true) int processId) throws JsonProcessingException { - logger.info("copy process definition, login user:{}, project name:{}, process definition id:{}", - loginUser.getUserName(), projectName, processId); - Map result = processDefinitionService.copyProcessDefinition(loginUser, projectName, processId); - return returnDataList(result); + @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, + @RequestParam(value = "targetProjectId",required = true) int targetProjectId) { + logger.info("batch copy process definition, login user:{}, project name:{}, process definition ids:{},target project id:{}", + StringUtils.replaceNRTtoUnderline(loginUser.getUserName()), + StringUtils.replaceNRTtoUnderline(projectName), + StringUtils.replaceNRTtoUnderline(processDefinitionIds), + StringUtils.replaceNRTtoUnderline(String.valueOf(targetProjectId))); + + return returnDataList( + processDefinitionService.batchCopyProcessDefinition(loginUser,projectName,processDefinitionIds,targetProjectId)); + } + + /** + * move process definition + * + * @param loginUser login user + * @param projectName project name + * @param processDefinitionIds process definition ids + * @param targetProjectId target project id + * @return move result code + */ + @ApiOperation(value = "moveProcessDefinition", notes= "MOVE_PROCESS_DEFINITION_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, dataType = "String", example = "3,4"), + @ApiImplicitParam(name = "targetProjectId", value = "TARGET_PROJECT_ID", required = true, type = "Integer") + }) + @PostMapping(value = "/move") + @ResponseStatus(HttpStatus.OK) + @ApiException(BATCH_MOVE_PROCESS_DEFINITION_ERROR) + public Result moveProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, + @RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, + @RequestParam(value = "targetProjectId",required = true) int targetProjectId) { + logger.info("batch move process definition, login user:{}, project name:{}, process definition ids:{},target project id:{}", + StringUtils.replaceNRTtoUnderline(loginUser.getUserName()), + StringUtils.replaceNRTtoUnderline(projectName), + StringUtils.replaceNRTtoUnderline(processDefinitionIds), + StringUtils.replaceNRTtoUnderline(String.valueOf(targetProjectId))); + + return returnDataList( + processDefinitionService.batchMoveProcessDefinition(loginUser,projectName,processDefinitionIds,targetProjectId)); } /** @@ -365,7 +403,7 @@ public class ProcessDefinitionController extends BaseController { public Result getNodeListByDefinitionIdList( @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, - @RequestParam("processDefinitionIdList") String processDefinitionIdList) throws Exception { + @RequestParam("processDefinitionIdList") String processDefinitionIdList) { logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}", loginUser.getUserName(), projectName, processDefinitionIdList); @@ -420,7 +458,7 @@ public class ProcessDefinitionController extends BaseController { logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", loginUser.getUserName(), projectName, processDefinitionIds); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List deleteFailedIdList = new ArrayList<>(); if (StringUtils.isNotEmpty(processDefinitionIds)) { String[] processDefinitionIdArray = processDefinitionIds.split(","); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java index 7e9473d81c..1f1ec1ed7b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java @@ -370,7 +370,7 @@ public class ProcessInstanceController extends BaseController { logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", loginUser.getUserName(), projectName, processInstanceIds); // task queue - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List deleteFailedIdList = new ArrayList<>(); if (StringUtils.isNotEmpty(processInstanceIds)) { String[] processInstanceIdArray = processInstanceIds.split(","); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java index cc9e0f657f..dac97bca9d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java @@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.ParameterUtils; +import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.dao.entity.User; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -226,6 +227,25 @@ public class ProjectController extends BaseController { return returnDataList(result); } + /** + * query user created project + * + * @param loginUser login user + * @return projects which the user create + */ + @ApiOperation(value = "queryProjectCreatedByUser", notes = "QUERY_USER_CREATED_PROJECT_NOTES") + + @GetMapping(value = "/login-user-created-project") + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_USER_CREATED_PROJECT_ERROR) + public Result queryProjectCreatedByUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { + logger.info("login user {}, query authorized project by user id: {}.", + StringUtils.replaceNRTtoUnderline(loginUser.getUserName()), + StringUtils.replaceNRTtoUnderline(String.valueOf(loginUser.getId()))); + Map result = projectService.queryProjectCreatedByUser(loginUser); + return returnDataList(result); + } + /** * import process definition * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 8e90b4cb08..950d0a511d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -168,15 +168,21 @@ public enum Status { PREVIEW_SCHEDULE_ERROR(10139,"preview schedule error", "预览调度配置错误"), PARSE_TO_CRON_EXPRESSION_ERROR(10140,"parse cron to cron expression error", "解析调度表达式错误"), SCHEDULE_START_TIME_END_TIME_SAME(10141,"The start time must not be the same as the end", "开始时间不能和结束时间一样"), - DELETE_TENANT_BY_ID_FAIL(100142,"delete tenant by id fail, for there are {0} process instances in executing using it", "删除租户失败,有[{0}]个运行中的工作流实例正在使用"), - DELETE_TENANT_BY_ID_FAIL_DEFINES(100143,"delete tenant by id fail, for there are {0} process definitions using it", "删除租户失败,有[{0}]个工作流定义正在使用"), - DELETE_TENANT_BY_ID_FAIL_USERS(100144,"delete tenant by id fail, for there are {0} users using it", "删除租户失败,有[{0}]个用户正在使用"), - DELETE_WORKER_GROUP_BY_ID_FAIL(100145,"delete worker group by id fail, for there are {0} process instances in executing using it", "删除Worker分组失败,有[{0}]个运行中的工作流实例正在使用"), - QUERY_WORKER_GROUP_FAIL(100146,"query worker group fail ", "查询worker分组失败"), - DELETE_WORKER_GROUP_FAIL(100147,"delete worker group fail ", "删除worker分组失败"), - QUERY_WORKFLOW_LINEAGE_ERROR(10143,"query workflow lineage error", "查询血缘失败"), - COPY_PROCESS_DEFINITION_ERROR(10148,"copy process definition error", "复制工作流错误"), - USER_DISABLED(10149,"The current user is disabled", "当前用户已停用"), + DELETE_TENANT_BY_ID_FAIL(10142,"delete tenant by id fail, for there are {0} process instances in executing using it", "删除租户失败,有[{0}]个运行中的工作流实例正在使用"), + DELETE_TENANT_BY_ID_FAIL_DEFINES(10143,"delete tenant by id fail, for there are {0} process definitions using it", "删除租户失败,有[{0}]个工作流定义正在使用"), + DELETE_TENANT_BY_ID_FAIL_USERS(10144,"delete tenant by id fail, for there are {0} users using it", "删除租户失败,有[{0}]个用户正在使用"), + DELETE_WORKER_GROUP_BY_ID_FAIL(10145,"delete worker group by id fail, for there are {0} process instances in executing using it", "删除Worker分组失败,有[{0}]个运行中的工作流实例正在使用"), + QUERY_WORKER_GROUP_FAIL(10146,"query worker group fail ", "查询worker分组失败"), + DELETE_WORKER_GROUP_FAIL(10147,"delete worker group fail ", "删除worker分组失败"), + USER_DISABLED(10148,"The current user is disabled", "当前用户已停用"), + COPY_PROCESS_DEFINITION_ERROR(10149,"copy process definition from {0} to {1} error : {2}", "从{0}复制工作流到{1}错误 : {2}"), + MOVE_PROCESS_DEFINITION_ERROR(10150,"move process definition from {0} to {1} error : {2}", "从{0}移动工作流到{1}错误 : {2}"), + QUERY_USER_CREATED_PROJECT_ERROR(10151,"query user created project error error", "查询用户创建的项目错误"), + PROCESS_DEFINITION_IDS_IS_EMPTY(10152,"process definition ids is empty", "工作流IDS不能为空"), + BATCH_COPY_PROCESS_DEFINITION_ERROR(10153,"batch copy process definition error", "复制工作流错误"), + BATCH_MOVE_PROCESS_DEFINITION_ERROR(10154,"batch move process definition error", "移动工作流错误"), + QUERY_WORKFLOW_LINEAGE_ERROR(10155,"query workflow lineage error", "查询血缘失败"), + UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"), RESOURCE_NOT_EXIST(20004, "resource not exist", "资源不存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java index f3dcbfa237..72cbd50833 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java @@ -55,7 +55,7 @@ public class AlertGroupService extends BaseService{ */ public HashMap queryAlertgroup() { - HashMap result = new HashMap<>(5); + HashMap result = new HashMap<>(); List alertGroups = alertGroupMapper.queryAllGroupList(); result.put(Constants.DATA_LIST, alertGroups); putMsg(result, Status.SUCCESS); @@ -74,7 +74,7 @@ public class AlertGroupService extends BaseService{ */ public Map listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -101,7 +101,7 @@ public class AlertGroupService extends BaseService{ * @return create result code */ public Map createAlertgroup(User loginUser, String groupName, AlertType groupType, String desc) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (checkAdmin(loginUser, result)){ return result; @@ -138,7 +138,7 @@ public class AlertGroupService extends BaseService{ * @return update result code */ public Map updateAlertgroup(User loginUser, int id, String groupName, AlertType groupType, String desc) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)){ return result; @@ -179,7 +179,7 @@ public class AlertGroupService extends BaseService{ */ @Transactional(rollbackFor = RuntimeException.class) public Map delAlertgroupById(User loginUser, int id) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); //only admin can operate @@ -209,7 +209,7 @@ public class AlertGroupService extends BaseService{ * @return grant result code */ public Map grantUser(User loginUser, int alertgroupId, String userIds) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); //only admin can operate diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java index 41374f4478..9bb7a73cf2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java @@ -88,7 +88,7 @@ public class DataSourceService extends BaseService{ */ public Map createDataSource(User loginUser, String name, String desc, DbType type, String parameter) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); // check name can use or not if (checkName(name)) { putMsg(result, Status.DATASOURCE_EXIST); @@ -340,7 +340,7 @@ public class DataSourceService extends BaseService{ * @return data source list page */ public Map queryDataSourceList(User loginUser, Integer type) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List datasourceList; @@ -674,7 +674,7 @@ public class DataSourceService extends BaseService{ * @return authorized result code */ public Map authedDatasource(User loginUser, Integer userId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (!isAdmin(loginUser)) { putMsg(result, Status.USER_NO_OPERATION_PERM); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java index 6a8dad4f2a..fb735ecf19 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java @@ -98,7 +98,7 @@ public class ExecutorService extends BaseService{ TaskDependType taskDependType, WarningType warningType, int warningGroupId, String receivers, String receiversCc, RunMode runMode, Priority processInstancePriority, String workerGroup, Integer timeout) throws ParseException { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); // timeout is invalid if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) { putMsg(result,Status.TASK_TIMEOUT_PARAMS_ERROR); @@ -176,7 +176,7 @@ public class ExecutorService extends BaseService{ * @return check result code */ public Map checkProcessDefinitionValid(ProcessDefinition processDefinition, int processDefineId){ - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (processDefinition == null) { // check process definition exists putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST,processDefineId); @@ -201,7 +201,7 @@ public class ExecutorService extends BaseService{ * @return execute result code */ public Map execute(User loginUser, String projectName, Integer processInstanceId, ExecuteType executeType) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = checkResultAndAuth(loginUser, projectName, project); @@ -294,7 +294,7 @@ public class ExecutorService extends BaseService{ */ private Map checkExecuteType(ProcessInstance processInstance, ExecuteType executeType) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); ExecutionStatus executionStatus = processInstance.getState(); boolean checkResult = false; switch (executeType) { @@ -339,7 +339,7 @@ public class ExecutorService extends BaseService{ * @return update result */ private Map updateProcessInstancePrepare(ProcessInstance processInstance, CommandType commandType, ExecutionStatus executionStatus) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); processInstance.setCommandType(commandType); processInstance.addHistoryCmd(commandType); @@ -365,7 +365,7 @@ public class ExecutorService extends BaseService{ * @return insert result code */ private Map insertCommand(User loginUser, Integer instanceId, Integer processDefinitionId, CommandType commandType) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Command command = new Command(); command.setCommandType(commandType); command.setProcessDefinitionId(processDefinitionId); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/MonitorService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/MonitorService.java index 55c4fa113b..e46ca6fcf2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/MonitorService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/MonitorService.java @@ -56,7 +56,7 @@ public class MonitorService extends BaseService { * @return data base state */ public Map queryDatabaseState(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List monitorRecordList = monitorDBDao.queryDatabaseState(); @@ -75,7 +75,7 @@ public class MonitorService extends BaseService { */ public Map queryMaster(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List masterServers = getServerListFromZK(true); result.put(Constants.DATA_LIST, masterServers); @@ -91,7 +91,7 @@ public class MonitorService extends BaseService { * @return zookeeper information list */ public Map queryZookeeperState(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List zookeeperRecordList = zookeeperMonitor.zookeeperInfoList(); @@ -111,7 +111,7 @@ public class MonitorService extends BaseService { */ public Map queryWorker(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List workerServers = getServerListFromZK(false) .stream() .map((Server server) -> { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java index 6a4eb974ce..cc18de439f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java @@ -17,13 +17,10 @@ package org.apache.dolphinscheduler.api.service; import java.util.Map; - import javax.servlet.http.HttpServletResponse; - import org.apache.dolphinscheduler.dao.entity.ProcessData; import org.apache.dolphinscheduler.dao.entity.User; import org.springframework.web.multipart.MultipartFile; - import com.fasterxml.jackson.core.JsonProcessingException; /** @@ -88,21 +85,36 @@ public interface ProcessDefinitionService { * @param processId process definition id * @return process definition detail */ + Map queryProcessDefinitionById(User loginUser, String projectName, Integer processId); /** - * copy process definition - * - * @param loginUser login user - * @param projectName project name - * @param processId process definition id - * @return copy result code + * batch copy process definition + * @param loginUser loginUser + * @param projectName projectName + * @param processDefinitionIds processDefinitionIds + * @param targetProjectId targetProjectId + * @return + */ + Map batchCopyProcessDefinition(User loginUser, + String projectName, + String processDefinitionIds, + int targetProjectId); + + /** + * batch move process definition + * @param loginUser loginUser + * @param projectName projectName + * @param processDefinitionIds processDefinitionIds + * @param targetProjectId targetProjectId + * @return */ - Map copyProcessDefinition(User loginUser, - String projectName, - Integer processId) throws JsonProcessingException; + Map batchMoveProcessDefinition(User loginUser, + String projectName, + String processDefinitionIds, + int targetProjectId); /** * update process definition @@ -187,7 +199,6 @@ public interface ProcessDefinitionService { MultipartFile file, String currentProjectName); - /** * check the process definition node meets the specifications * @@ -214,7 +225,6 @@ public interface ProcessDefinitionService { */ Map getTaskNodeListByDefinitionIdList(String defineIdList); - /** * query process definition all by project id * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java index dc3dbe976f..40c009aa68 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java @@ -178,7 +178,7 @@ public class ProcessInstanceService extends BaseService { * @return process instance detail */ public Map queryProcessInstanceById(User loginUser, String projectName, Integer processId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); @@ -217,7 +217,7 @@ public class ProcessInstanceService extends BaseService { String searchVal, String executorName,ExecutionStatus stateType, String host, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); @@ -540,7 +540,7 @@ public class ProcessInstanceService extends BaseService { @Transactional(rollbackFor = RuntimeException.class) public Map deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); @@ -580,7 +580,7 @@ public class ProcessInstanceService extends BaseService { * @return variables data */ public Map viewVariables(Integer processInstanceId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); ProcessInstance processInstance = processInstanceMapper.queryDetailById(processInstanceId); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java index 6d3650b77f..36c5c10799 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java @@ -33,9 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - import java.util.*; - import static org.apache.dolphinscheduler.api.utils.CheckUtils.checkDesc; /** @@ -43,7 +41,7 @@ import static org.apache.dolphinscheduler.api.utils.CheckUtils.checkDesc; *HttpTask./ **/ @Service -public class ProjectService extends BaseService{ +public class ProjectService extends BaseService { private static final Logger logger = LoggerFactory.getLogger(ProjectService.class); @@ -66,7 +64,7 @@ public class ProjectService extends BaseService{ */ public Map createProject(User loginUser, String name, String desc) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Map descCheck = checkDesc(desc); if (descCheck.get(Constants.STATUS) != Status.SUCCESS) { return descCheck; @@ -105,7 +103,7 @@ public class ProjectService extends BaseService{ */ public Map queryById(Integer projectId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.selectById(projectId); if (project != null) { @@ -126,7 +124,7 @@ public class ProjectService extends BaseService{ * @return true if the login user have permission to see the project */ public Map checkProjectAndAuth(User loginUser, Project project, String projectName) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (project == null) { putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); } else if (!checkReadPermission(loginUser, project)) { @@ -191,7 +189,7 @@ public class ProjectService extends BaseService{ * @return delete result code */ public Map deleteProject(User loginUser, Integer projectId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.selectById(projectId); Map checkResult = getCheckResult(loginUser, project); if (checkResult != null) { @@ -245,7 +243,7 @@ public class ProjectService extends BaseService{ * @return update result code */ public Map update(User loginUser, Integer projectId, String projectName, String desc) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Map descCheck = checkDesc(desc); if (descCheck.get(Constants.STATUS) != Status.SUCCESS) { @@ -284,7 +282,7 @@ public class ProjectService extends BaseService{ * @return the projects which user have not permission to see */ public Map queryUnauthorizedProject(User loginUser, Integer userId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -347,6 +345,26 @@ public class ProjectService extends BaseService{ return result; } + /** + * query authorized project + * + * @param loginUser login user + * @return projects which the user have permission to see, Except for items created by this user + */ + public Map queryProjectCreatedByUser(User loginUser) { + Map result = new HashMap<>(); + + if (checkAdmin(loginUser, result)) { + return result; + } + + List projects = projectMapper.queryProjectCreatedByUser(loginUser.getId()); + result.put(Constants.DATA_LIST, projects); + putMsg(result,Status.SUCCESS); + + return result; + } + /** * check whether have read permission diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java index cba1b5f2bb..caffeabd5c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java @@ -59,7 +59,7 @@ public class QueueService extends BaseService { * @return queue list */ public Map queryList(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -81,7 +81,7 @@ public class QueueService extends BaseService { * @return queue list */ public Map queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -110,7 +110,7 @@ public class QueueService extends BaseService { * @return create result */ public Map createQueue(User loginUser, String queue, String queueName) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -159,7 +159,7 @@ public class QueueService extends BaseService { * @return update result code */ public Map updateQueue(User loginUser, int id, String queue, String queueName) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java index 3cb715b964..d26bef9f92 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java @@ -402,7 +402,7 @@ public class ResourcesService extends BaseService { putMsg(result, Status.SUCCESS); Map dataMap = new BeanMap(resource); - Map resultMap = new HashMap<>(5); + Map resultMap = new HashMap<>(); for (Map.Entry entry: dataMap.entrySet()) { if (!Constants.CLASS.equalsIgnoreCase(entry.getKey().toString())) { resultMap.put(entry.getKey().toString(), entry.getValue()); @@ -447,7 +447,7 @@ public class ResourcesService extends BaseService { */ public Map queryResourceListPaging(User loginUser, int direcotryId, ResourceType type, String searchVal, Integer pageNo, Integer pageSize) { - HashMap result = new HashMap<>(5); + HashMap result = new HashMap<>(); Page page = new Page(pageNo, pageSize); int userId = loginUser.getId(); if (isAdmin(loginUser)) { @@ -548,7 +548,7 @@ public class ResourcesService extends BaseService { */ public Map queryResourceList(User loginUser, ResourceType type) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); int userId = loginUser.getId(); if(isAdmin(loginUser)){ @@ -571,7 +571,7 @@ public class ResourcesService extends BaseService { */ public Map queryResourceJarList(User loginUser, ResourceType type) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); int userId = loginUser.getId(); if(isAdmin(loginUser)){ userId = 0; @@ -1094,7 +1094,7 @@ public class ResourcesService extends BaseService { * @return unauthorized result code */ public Map unauthorizedUDFFunction(User loginUser, Integer userId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (checkAdmin(loginUser, result)) { return result; @@ -1146,7 +1146,7 @@ public class ResourcesService extends BaseService { * @return authorized result */ public Map authorizedFile(User loginUser, Integer userId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)){ return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java index 78a36c639a..93fa14872a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java @@ -452,7 +452,7 @@ public class SchedulerService extends BaseService { * @return schedule list */ public Map queryScheduleList(User loginUser, String projectName) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); // check project auth @@ -534,7 +534,7 @@ public class SchedulerService extends BaseService { */ public Map deleteScheduleById(User loginUser, String projectName, Integer scheduleId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); @@ -583,7 +583,7 @@ public class SchedulerService extends BaseService { * @return the next five fire time */ public Map previewSchedule(User loginUser, String projectName, String schedule) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); CronExpression cronExpression; ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class); Date now = new Date(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java index 170278e02f..c5a09009d1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java @@ -83,7 +83,7 @@ public class TaskInstanceService extends BaseService { Integer processInstanceId, String taskName, String executorName, String startDate, String endDate, String searchVal, ExecutionStatus stateType,String host, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java index a78c951d34..586c1a1b53 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java @@ -86,7 +86,7 @@ public class TenantService extends BaseService{ int queueId, String desc) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); if (checkAdmin(loginUser, result)) { return result; @@ -138,7 +138,7 @@ public class TenantService extends BaseService{ */ public Map queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } @@ -169,7 +169,7 @@ public class TenantService extends BaseService{ */ public Map updateTenant(User loginUser,int id,String tenantCode, String tenantName, int queueId, String desc) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); if (checkAdmin(loginUser, result)) { @@ -235,7 +235,7 @@ public class TenantService extends BaseService{ */ @Transactional(rollbackFor = Exception.class) public Map deleteTenantById(User loginUser, int id) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; @@ -292,7 +292,7 @@ public class TenantService extends BaseService{ */ public Map queryTenantList(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List resourceList = tenantMapper.selectList(null); result.put(Constants.DATA_LIST, resourceList); @@ -307,7 +307,7 @@ public class TenantService extends BaseService{ * @return tenant list */ public Map queryTenantList(String tenantCode) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List resourceList = tenantMapper.queryByTenantCode(tenantCode); if (CollectionUtils.isNotEmpty(resourceList)) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java index bb92c9ccf7..8931454e27 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java @@ -151,7 +151,7 @@ public class UdfFuncService extends BaseService{ */ public Map queryUdfFuncDetail(int id) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); UdfFunc udfFunc = udfFuncMapper.selectById(id); if (udfFunc == null) { putMsg(result, Status.RESOURCE_NOT_EXIST); @@ -247,7 +247,7 @@ public class UdfFuncService extends BaseService{ * @return udf function list page */ public Map queryUdfFuncListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); PageInfo pageInfo = new PageInfo(pageNo, pageSize); @@ -286,7 +286,7 @@ public class UdfFuncService extends BaseService{ * @return resource list */ public Map queryResourceList(User loginUser, Integer type) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); List udfFuncList = udfFuncMapper.getUdfFuncByType(loginUser.getId(), type); result.put(Constants.DATA_LIST, udfFuncList); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java index 6dcb327597..d66ef7257c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java @@ -102,7 +102,7 @@ public class UsersService extends BaseService { String queue, int state) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //check all user params String msg = this.checkUserParams(userName, userPassword, email, phone); @@ -230,7 +230,7 @@ public class UsersService extends BaseService { * @return user list page */ public Map queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; @@ -270,7 +270,7 @@ public class UsersService extends BaseService { String phone, String queue, int state) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); User user = userMapper.selectById(userId); @@ -393,7 +393,7 @@ public class UsersService extends BaseService { * @throws Exception exception when operate hdfs */ public Map deleteUserById(User loginUser, int id) throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (!isAdmin(loginUser)) { putMsg(result, Status.USER_NO_OPERATION_PERM, id); @@ -433,7 +433,7 @@ public class UsersService extends BaseService { */ @Transactional(rollbackFor = RuntimeException.class) public Map grantProject(User loginUser, int userId, String projectIds) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); //only admin can operate @@ -483,7 +483,7 @@ public class UsersService extends BaseService { */ @Transactional(rollbackFor = RuntimeException.class) public Map grantResources(User loginUser, int userId, String resourceIds) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; @@ -580,7 +580,7 @@ public class UsersService extends BaseService { */ @Transactional(rollbackFor = RuntimeException.class) public Map grantUDFFunction(User loginUser, int userId, String udfIds) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { @@ -627,7 +627,7 @@ public class UsersService extends BaseService { */ @Transactional(rollbackFor = RuntimeException.class) public Map grantDataSource(User loginUser, int userId, String datasourceIds) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); result.put(Constants.STATUS, false); //only admin can operate @@ -707,7 +707,7 @@ public class UsersService extends BaseService { * @return user list */ public Map queryAllGeneralUsers(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; @@ -728,7 +728,7 @@ public class UsersService extends BaseService { * @return user list */ public Map queryUserList(User loginUser) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; @@ -772,7 +772,7 @@ public class UsersService extends BaseService { */ public Map unauthorizedUser(User loginUser, Integer alertgroupId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; @@ -808,7 +808,7 @@ public class UsersService extends BaseService { * @return authorized result code */ public Map authorizedUser(User loginUser, Integer alertgroupId) { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //only admin can operate if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java index 374fd6e718..95257e8c8a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java @@ -63,7 +63,7 @@ public class WorkerGroupService extends BaseService { // list to index Integer toIndex = (pageNo - 1) * pageSize + pageSize; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); if (checkAdmin(loginUser, result)) { return result; } 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 ee02940c09..e40fdfad30 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 @@ -33,10 +33,8 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; - import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; - import org.apache.dolphinscheduler.api.dto.ProcessMeta; import org.apache.dolphinscheduler.api.dto.treeview.Instance; import org.apache.dolphinscheduler.api.dto.treeview.TreeViewDto; @@ -94,7 +92,6 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; - import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; @@ -129,7 +126,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements @Autowired private ProcessInstanceMapper processInstanceMapper; - @Autowired private TaskInstanceMapper taskInstanceMapper; @@ -330,41 +326,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements return result; } - /** - * copy process definition - * - * @param loginUser login user - * @param projectName project name - * @param processId process definition id - * @return copy result code - */ - public Map copyProcessDefinition(User loginUser, String projectName, Integer processId) throws JsonProcessingException { - - Map result = new HashMap<>(5); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; - } - - ProcessDefinition processDefinition = processDefineMapper.selectById(processId); - if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); - return result; - } else { - return createProcessDefinition( - loginUser, - projectName, - processDefinition.getName() + "_copy_" + System.currentTimeMillis(), - processDefinition.getProcessDefinitionJson(), - processDefinition.getDescription(), - processDefinition.getLocations(), - processDefinition.getConnects()); - } - } - /** * update process definition * @@ -963,7 +924,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements return true; } - /** * import process add special task param * @@ -1010,7 +970,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements * @param processDefinitionId process definition id * @return insert schedule flag */ - private int importProcessSchedule(User loginUser, String currentProjectName, ProcessMeta processMeta, + public int importProcessSchedule(User loginUser, String currentProjectName, ProcessMeta processMeta, String processDefinitionName, Integer processDefinitionId) { Date now = new Date(); Schedule scheduleObj = new Schedule(); @@ -1489,5 +1449,248 @@ public class ProcessDefinitionServiceImpl extends BaseService implements return recursionProcessDefinitionName(projectId, processDefinitionName, num + 1); } + private Map copyProcessDefinition(User loginUser, + Integer processId, + Project targetProject) throws JsonProcessingException { + + Map result = new HashMap<>(); + + ProcessDefinition processDefinition = processDefineMapper.selectById(processId); + if (processDefinition == null) { + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); + return result; + } else { + return createProcessDefinition( + loginUser, + targetProject.getName(), + processDefinition.getName() + "_copy_" + System.currentTimeMillis(), + processDefinition.getProcessDefinitionJson(), + processDefinition.getDescription(), + processDefinition.getLocations(), + processDefinition.getConnects()); + + } + } + + /** + * batch copy process definition + * @param loginUser loginUser + * @param projectName projectName + * @param processDefinitionIds processDefinitionIds + * @param targetProjectId targetProjectId + * @return + */ + @Override + public Map batchCopyProcessDefinition(User loginUser, + String projectName, + String processDefinitionIds, + int targetProjectId){ + Map result = new HashMap<>(); + List failedProcessList = new ArrayList<>(); + + if (StringUtils.isEmpty(processDefinitionIds)) { + putMsg(result, Status.PROCESS_DEFINITION_IDS_IS_EMPTY, processDefinitionIds); + return result; + } + + //check src project auth + Map checkResult = checkProjectAndAuth(loginUser, projectName); + if (checkResult != null) { + return checkResult; + } + + Project targetProject = projectMapper.queryDetailById(targetProjectId); + if(targetProject == null){ + putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId); + return result; + } + + if(!(targetProject.getName()).equals(projectName)){ + Map checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProject.getName()); + if (checkTargetProjectResult != null) { + return checkTargetProjectResult; + } + } + + String[] processDefinitionIdList = processDefinitionIds.split(Constants.COMMA); + doBatchCopyProcessDefinition(loginUser, targetProject, failedProcessList, processDefinitionIdList); + + checkBatchOperateResult(projectName,targetProject.getName(),result,failedProcessList,true); + + return result; + } + + /** + * batch move process definition + * @param loginUser loginUser + * @param projectName projectName + * @param processDefinitionIds processDefinitionIds + * @param targetProjectId targetProjectId + * @return + */ + @Override + public Map batchMoveProcessDefinition(User loginUser, + String projectName, + String processDefinitionIds, + int targetProjectId) { + Map result = new HashMap<>(); + List failedProcessList = new ArrayList<>(); + + //check src project auth + Map checkResult = checkProjectAndAuth(loginUser, projectName); + if (checkResult != null) { + return checkResult; + } + + if (StringUtils.isEmpty(processDefinitionIds)) { + putMsg(result, Status.PROCESS_DEFINITION_IDS_IS_EMPTY, processDefinitionIds); + return result; + } + + Project targetProject = projectMapper.queryDetailById(targetProjectId); + if(targetProject == null){ + putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId); + return result; + } + + if(!(targetProject.getName()).equals(projectName)){ + Map checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProject.getName()); + if (checkTargetProjectResult != null) { + return checkTargetProjectResult; + } + } + + String[] processDefinitionIdList = processDefinitionIds.split(Constants.COMMA); + doBatchMoveProcessDefinition(targetProject, failedProcessList, processDefinitionIdList); + + checkBatchOperateResult(projectName,targetProject.getName(),result,failedProcessList,false); + + return result; + } + + /** + * do batch move process definition + * @param targetProject targetProject + * @param failedProcessList failedProcessList + * @param processDefinitionIdList processDefinitionIdList + */ + private void doBatchMoveProcessDefinition(Project targetProject, List failedProcessList, String[] processDefinitionIdList) { + for(String processDefinitionId:processDefinitionIdList){ + try { + Map moveProcessDefinitionResult = + moveProcessDefinition(Integer.valueOf(processDefinitionId),targetProject); + if (!Status.SUCCESS.equals(moveProcessDefinitionResult.get(Constants.STATUS))) { + setFailedProcessList(failedProcessList, processDefinitionId); + logger.error((String) moveProcessDefinitionResult.get(Constants.MSG)); + } + } catch (Exception e) { + setFailedProcessList(failedProcessList, processDefinitionId); + } + } + } + + /** + * batch copy process definition + * @param loginUser loginUser + * @param targetProject targetProject + * @param failedProcessList failedProcessList + * @param processDefinitionIdList processDefinitionIdList + */ + private void doBatchCopyProcessDefinition(User loginUser, Project targetProject, List failedProcessList, String[] processDefinitionIdList) { + for(String processDefinitionId:processDefinitionIdList){ + try { + Map copyProcessDefinitionResult = + copyProcessDefinition(loginUser,Integer.valueOf(processDefinitionId),targetProject); + if (!Status.SUCCESS.equals(copyProcessDefinitionResult.get(Constants.STATUS))) { + setFailedProcessList(failedProcessList, processDefinitionId); + logger.error((String) copyProcessDefinitionResult.get(Constants.MSG)); + } + } catch (Exception e) { + setFailedProcessList(failedProcessList, processDefinitionId); + } + } + } + + /** + * set failed processList + * @param failedProcessList failedProcessList + * @param processDefinitionId processDefinitionId + */ + private void setFailedProcessList(List failedProcessList, String processDefinitionId) { + ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(Integer.valueOf(processDefinitionId)); + if(processDefinition != null){ + failedProcessList.add(processDefinitionId+"["+processDefinition.getName()+"]"); + }else{ + failedProcessList.add(processDefinitionId+"[null]"); + } + } + + /** + * check project and auth + * @param loginUser loginUser + * @param projectName projectName + * @return + */ + private Map checkProjectAndAuth(User loginUser, String projectName) { + Project project = projectMapper.queryByName(projectName); + + //check user access for project + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Status resultStatus = (Status) checkResult.get(Constants.STATUS); + + if (resultStatus != Status.SUCCESS) { + return checkResult; + } + return null; + } + + /** + * move process definition + * @param processId processId + * @param targetProject targetProject + * @return move result code + */ + private Map moveProcessDefinition(Integer processId, + Project targetProject) { + + Map result = new HashMap<>(); + + ProcessDefinition processDefinition = processDefineMapper.selectById(processId); + if (processDefinition == null) { + putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); + return result; + } else { + processDefinition.setProjectId(targetProject.getId()); + processDefinition.setUpdateTime(new Date()); + if (processDefineMapper.updateById(processDefinition) > 0) { + putMsg(result, Status.SUCCESS); + } else { + putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR); + } + return result; + } + } + + /** + * check batch operate result + * @param srcProjectName srcProjectName + * @param targetProjectName targetProjectName + * @param result result + * @param failedProcessList failedProcessList + * @param isCopy isCopy + */ + private void checkBatchOperateResult(String srcProjectName,String targetProjectName, + Map result, List failedProcessList,boolean isCopy) { + if (!failedProcessList.isEmpty()) { + if(isCopy){ + putMsg(result, Status.COPY_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName,String.join(",", failedProcessList)); + }else{ + putMsg(result, Status.MOVE_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName,String.join(",", failedProcessList)); + } + } else { + putMsg(result, Status.SUCCESS); + } + } + } diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages.properties b/dolphinscheduler-api/src/main/resources/i18n/messages.properties index c8e48ad865..2005d05fde 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages.properties @@ -173,7 +173,6 @@ PROCESS_DEFINITION_ID=process definition id PROCESS_DEFINITION_IDS=process definition ids RELEASE_PROCESS_DEFINITION_NOTES=release process definition QUERY_PROCESS_DEFINITION_BY_ID_NOTES=query process definition by id -COPY_PROCESS_DEFINITION_NOTES=copy process definition QUERY_PROCESS_DEFINITION_LIST_NOTES=query process definition list QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES=query process definition list paging QUERY_ALL_DEFINITION_LIST_NOTES=query all definition list @@ -253,4 +252,9 @@ AUTHORIZED_DATA_SOURCE_NOTES=authorized data source DELETE_SCHEDULER_BY_ID_NOTES=delete scheduler by id QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging EXPORT_PROCESS_DEFINITION_BY_ID_NOTES=export process definition by id -BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES= batch export process definition by ids \ No newline at end of file +BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES= batch export process definition by ids +QUERY_USER_CREATED_PROJECT_NOTES= query user created project +COPY_PROCESS_DEFINITION_NOTES= copy process definition notes +MOVE_PROCESS_DEFINITION_NOTES= move process definition notes +TARGET_PROJECT_ID= target project id +IS_COPY = is copy diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties index 0669e8d8cf..2e079285ca 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties @@ -173,7 +173,6 @@ PROCESS_DEFINITION_ID=process definition id PROCESS_DEFINITION_IDS=process definition ids RELEASE_PROCESS_DEFINITION_NOTES=release process definition QUERY_PROCESS_DEFINITION_BY_ID_NOTES=query process definition by id -COPY_PROCESS_DEFINITION_NOTES=copy process definition QUERY_PROCESS_DEFINITION_LIST_NOTES=query process definition list QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES=query process definition list paging QUERY_ALL_DEFINITION_LIST_NOTES=query all definition list @@ -254,3 +253,8 @@ DELETE_SCHEDULER_BY_ID_NOTES=delete scheduler by id QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging EXPORT_PROCESS_DEFINITION_BY_ID_NOTES=export process definition by id BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES= batch export process definition by ids +QUERY_USER_CREATED_PROJECT_NOTES= query user created project +COPY_PROCESS_DEFINITION_NOTES= copy process definition notes +MOVE_PROCESS_DEFINITION_NOTES= move process definition notes +TARGET_PROJECT_ID= target project id +IS_COPY = is copy diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties index 9053b0924c..31f70ef40c 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties @@ -171,7 +171,6 @@ UPDATE_PROCESS_DEFINITION_NOTES=更新流程定义 PROCESS_DEFINITION_ID=流程定义ID RELEASE_PROCESS_DEFINITION_NOTES=发布流程定义 QUERY_PROCESS_DEFINITION_BY_ID_NOTES=查询流程定义通过流程定义ID -COPY_PROCESS_DEFINITION_NOTES=复制流程定义 QUERY_PROCESS_DEFINITION_LIST_NOTES=查询流程定义列表 QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES=分页查询流程定义列表 QUERY_ALL_DEFINITION_LIST_NOTES=查询所有流程定义 @@ -252,4 +251,9 @@ DELETE_SCHEDULER_BY_ID_NOTES=根据定时id删除定时数据 QUERY_ALERT_GROUP_LIST_PAGING_NOTES=分页查询告警组列表 EXPORT_PROCESS_DEFINITION_BY_ID_NOTES=通过工作流ID导出工作流定义 BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES=批量导出工作流定义 +QUERY_USER_CREATED_PROJECT_NOTES= 查询用户创建的项目 +COPY_PROCESS_DEFINITION_NOTES= 复制工作流定义 +MOVE_PROCESS_DEFINITION_NOTES= 移动工作流定义 +TARGET_PROJECT_ID= 目标项目ID +IS_COPY = 是否复制 diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java index c5f98630a2..ab0a3ce1f7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java @@ -24,11 +24,12 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.common.model.TaskNode; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Resource; import org.apache.dolphinscheduler.dao.entity.User; -import org.junit.*; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -48,7 +49,7 @@ import java.util.Map; * process definition controller test */ @RunWith(MockitoJUnitRunner.Silent.class) -public class ProcessDefinitionControllerTest{ +public class ProcessDefinitionControllerTest { private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class); @@ -79,7 +80,7 @@ public class ProcessDefinitionControllerTest{ String name = "dag_test"; String description = "desc test"; String connects = "[]"; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put("processDefinitionId",1); @@ -103,7 +104,7 @@ public class ProcessDefinitionControllerTest{ @Test public void testVerifyProcessDefinitionName() throws Exception { - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROCESS_INSTANCE_EXIST); String projectName = "test"; String name = "dag_test"; @@ -125,7 +126,7 @@ public class ProcessDefinitionControllerTest{ String description = "desc test"; String connects = "[]"; int id = 1; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put("processDefinitionId",1); @@ -141,7 +142,7 @@ public class ProcessDefinitionControllerTest{ public void testReleaseProcessDefinition() throws Exception { String projectName = "test"; int id = 1; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.releaseProcessDefinition(user, projectName,id,ReleaseState.OFFLINE.ordinal())).thenReturn(result); @@ -169,7 +170,7 @@ public class ProcessDefinitionControllerTest{ processDefinition.setName(name); processDefinition.setProcessDefinitionJson(json); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, processDefinition); @@ -180,16 +181,33 @@ public class ProcessDefinitionControllerTest{ } @Test - public void testCopyProcessDefinition() throws Exception { + public void testBatchCopyProcessDefinition() throws Exception { String projectName = "test"; - int id = 1; + int targetProjectId = 2; + String id = "1"; + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS); + + Mockito.when(processDefinitionService.batchCopyProcessDefinition(user,projectName,id,targetProjectId)).thenReturn(result); + Result response = processDefinitionController.copyProcessDefinition(user, projectName,id,targetProjectId); + + Assert.assertEquals(Status.SUCCESS.getCode(),response.getCode().intValue()); + } + + @Test + public void testBatchMoveProcessDefinition() throws Exception { + + String projectName = "test"; + int targetProjectId = 2; + String id = "1"; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(processDefinitionService.copyProcessDefinition(user, projectName,id)).thenReturn(result); - Result response = processDefinitionController.copyProcessDefinition(user, projectName,id); + Mockito.when(processDefinitionService.batchMoveProcessDefinition(user,projectName,id,targetProjectId)).thenReturn(result); + Result response = processDefinitionController.moveProcessDefinition(user, projectName,id,targetProjectId); Assert.assertEquals(Status.SUCCESS.getCode(),response.getCode().intValue()); } @@ -201,7 +219,7 @@ public class ProcessDefinitionControllerTest{ String projectName = "test"; List resourceList = getDefinitionList(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, resourceList); @@ -256,7 +274,7 @@ public class ProcessDefinitionControllerTest{ String projectName = "test"; int id = 1; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.deleteProcessDefinitionById(user, projectName,id)).thenReturn(result); @@ -270,7 +288,7 @@ public class ProcessDefinitionControllerTest{ String projectName = "test"; int id = 1; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.getTaskNodeListByDefinitionId(id)).thenReturn(result); @@ -284,7 +302,7 @@ public class ProcessDefinitionControllerTest{ String projectName = "test"; String idList = "1,2,3"; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.getTaskNodeListByDefinitionIdList(idList)).thenReturn(result); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java index ab7dac4d60..1b93e86773 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java @@ -76,7 +76,7 @@ public class AlertGroupServiceTest { @Test - public void testQueryAlertgroup(){ + public void testQueryAlertGroup(){ Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList()); HashMap result= alertGroupService.queryAlertgroup(); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java index 6551919e4a..57cd207c4d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java @@ -54,7 +54,7 @@ public class ExecutorServiceTest { @Test public void putMsgWithParamsTest() { - Map map = new HashMap<>(5); + Map map = new HashMap<>(); putMsgWithParams(map, Status.PROJECT_ALREADY_EXISTS); logger.info(map.toString()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index 168fe48fc3..67221c5514 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -86,8 +86,6 @@ public class ProcessDefinitionServiceTest { @Mock private ScheduleMapper scheduleMapper; - - @Mock private ProcessService processService; @@ -130,7 +128,7 @@ public class ProcessDefinitionServiceTest { loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project not found @@ -159,7 +157,7 @@ public class ProcessDefinitionServiceTest { loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project not found @@ -180,7 +178,7 @@ public class ProcessDefinitionServiceTest { loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project check auth fail @@ -209,13 +207,15 @@ public class ProcessDefinitionServiceTest { String projectName = "project_test1"; Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + Mockito.when(projectMapper.queryDetailById(1)).thenReturn(getProject(projectName)); + Project project = getProject(projectName); User loginUser = new User(); loginUser.setId(-1); loginUser.setUserType(UserType.GENERAL_USER); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); //project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectName); Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); @@ -227,7 +227,7 @@ public class ProcessDefinitionServiceTest { //instance exit Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); - Map createProcessResult = new HashMap<>(5); + Map createProcessResult = new HashMap<>(); putMsg(result, Status.SUCCESS); Mockito.when(processDefinitionService.createProcessDefinition( @@ -239,8 +239,51 @@ public class ProcessDefinitionServiceTest { definition.getLocations(), definition.getConnects())).thenReturn(createProcessResult); - Map successRes = processDefinitionService.copyProcessDefinition(loginUser, - "project_test1", 46); + Map successRes = processDefinitionService.batchCopyProcessDefinition(loginUser,"project_test1", + "46",1); + Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); + } + + @Test + public void testBatchMoveProcessDefinition() throws Exception{ + String projectName = "project_test1"; + Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); + + String projectName2 = "project_test2"; + Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(getProject(projectName2)); + + int targetProjectId = 2; + Mockito.when(projectMapper.queryDetailById(targetProjectId)).thenReturn(getProjectById(targetProjectId)); + + Project project = getProject(projectName); + Project targetProject = getProjectById(targetProjectId); + + User loginUser = new User(); + loginUser.setId(-1); + loginUser.setUserType(UserType.GENERAL_USER); + + Map result = new HashMap<>(); + putMsg(result, Status.SUCCESS, projectName); + + Map result2 = new HashMap<>(); + putMsg(result2, Status.SUCCESS, targetProject.getName()); + + Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser,targetProject,targetProject.getName())).thenReturn(result2); + + ProcessDefinition definition = getProcessDefinition(); + definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); + definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); + definition.setConnects("[]"); + //instance exit + Mockito.when(processDefineMapper.updateById(definition)).thenReturn(46); + Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); + + putMsg(result, Status.SUCCESS); + + + Map successRes = processDefinitionService.batchMoveProcessDefinition(loginUser,"project_test1", + "46",2); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @@ -256,7 +299,7 @@ public class ProcessDefinitionServiceTest { loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); Map map = processDefinitionService.deleteProcessDefinitionById(loginUser, "project_test1", 6); @@ -336,7 +379,7 @@ public class ProcessDefinitionServiceTest { loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); Map map = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", @@ -379,7 +422,7 @@ public class ProcessDefinitionServiceTest { loginUser.setUserType(UserType.GENERAL_USER); //project check auth fail - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); Map map = processDefinitionService.verifyProcessDefinitionName(loginUser, @@ -558,7 +601,7 @@ public class ProcessDefinitionServiceTest { loginUser.setUserType(UserType.ADMIN_USER); String currentProjectName = "testProject"; - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, currentProjectName); ProcessDefinition shellDefinition2 = new ProcessDefinition(); @@ -601,7 +644,7 @@ public class ProcessDefinitionServiceTest { loginUser.setId(1); loginUser.setUserType(UserType.ADMIN_USER); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); String projectName = "project_test1"; @@ -657,6 +700,19 @@ public class ProcessDefinitionServiceTest { return project; } + /** + * get mock Project + * @param projectId projectId + * @return Project + */ + private Project getProjectById(int projectId){ + Project project = new Project(); + project.setId(1); + project.setName("project_test2"); + project.setUserId(1); + return project; + } + /** * get mock schedule * @return schedule diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index 95ce1794c3..aad884d508 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -112,7 +112,7 @@ public class ProcessInstanceServiceTest { public void testQueryProcessInstanceList() { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -201,7 +201,7 @@ public class ProcessInstanceServiceTest { public void testQueryProcessInstanceById() { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -239,7 +239,7 @@ public class ProcessInstanceServiceTest { public void testQueryTaskListByProcessId() throws IOException { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -288,7 +288,7 @@ public class ProcessInstanceServiceTest { public void testQuerySubProcessInstanceByTaskId() { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -334,7 +334,7 @@ public class ProcessInstanceServiceTest { public void testUpdateProcessInstance() throws ParseException { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -390,7 +390,7 @@ public class ProcessInstanceServiceTest { public void testQueryParentInstanceBySubId() { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail @@ -431,7 +431,7 @@ public class ProcessInstanceServiceTest { public void testDeleteProcessInstanceById() { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail 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 51f9e148d1..742d18d406 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 @@ -266,6 +266,26 @@ public class ProjectServiceTest { List projects = (List) result.get(Constants.DATA_LIST); Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); + } + + @Test + public void testQueryCreatedProject(){ + + User loginUser = getLoginUser(); + + Mockito.when(projectMapper.queryProjectCreatedByUser(1)).thenReturn(getList()); + //USER_NO_OPERATION_PERM + Map result = projectService.queryProjectCreatedByUser(loginUser); + logger.info(result.toString()); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); + + //success + loginUser.setUserType(UserType.ADMIN_USER); + result = projectService.queryProjectCreatedByUser(loginUser); + logger.info(result.toString()); + List projects = (List) result.get(Constants.DATA_LIST); + Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); + } @Test public void testQueryAllProjectList(){ diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java index ebb6139577..8e220345bf 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java @@ -78,7 +78,7 @@ public class TaskInstanceServiceTest { String projectName = "project_test1"; User loginUser = getAdminUser(); - Map result = new HashMap<>(5); + Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); //project auth fail 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 af2817a8d7..45321a59e3 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 @@ -37,4 +37,8 @@ public class StringUtils { public static boolean isNotBlank(String s){ return !isBlank(s); } + + public static String replaceNRTtoUnderline(String src){ + return src.replaceAll("[\n|\r|\t]", "_"); + } }