diff --git a/docs/docs/zh/guide/homepage.md b/docs/docs/zh/guide/homepage.md index 9e63b2a925..04f63a79ce 100644 --- a/docs/docs/zh/guide/homepage.md +++ b/docs/docs/zh/guide/homepage.md @@ -1,5 +1,5 @@ # 首页 -Apache DolphinScheduler 首页可让您查看用户所有项目的任务状态统计、工作流状态统计和项目统计。 这是观察整个系统状态以及深入各个进程以检查任务和任务日志的每个状态的最佳方式。 +Apache DolphinScheduler 首页可让您查看用户所有项目的任务实例状态统计、工作流实例状态统计和项目统计。 这是观察整个系统状态以及深入各个进程以检查任务和任务日志的每个状态的最佳方式。 ![homepage](../../../img/new_ui/dev/homepage/homepage.png) diff --git a/docs/docs/zh/guide/project/project-list.md b/docs/docs/zh/guide/project/project-list.md index 19d9fd0aee..1c33f7ff4a 100644 --- a/docs/docs/zh/guide/project/project-list.md +++ b/docs/docs/zh/guide/project/project-list.md @@ -8,10 +8,10 @@ ## 项目首页 -在项目管理页面点击项目名称链接,进入项目首页,如下图所示,项目首页包含该项目的任务状态统计、流程状态统计、工作流定义统计。这几个指标的说明如下 +在项目管理页面点击项目名称链接,进入项目首页,如下图所示,项目首页包含该项目的任务实例状态统计、工作流实例状态统计、工作流定义统计。这几个指标的说明如下 -- **任务状态统计**:在指定时间范围内,统计任务实例中状态为提交成功、正在运行、准备暂停、暂停、准备停止、停止、失败、成功、需要容错、kill、等待线程的个数 -- **流程状态统计**:在指定时间范围内,统计工作流实例中状态为提交成功、正在运行、准备暂停、暂停、准备停止、停止、失败、成功、需要容错、kill、等待线程的个数 +- **任务实例状态统计**:在指定时间范围内,统计任务实例中状态为提交成功、正在运行、准备暂停、暂停、准备停止、停止、失败、成功、需要容错、kill、等待线程的个数 +- **工作流实例状态统计**:在指定时间范围内,统计工作流实例中状态为提交成功、正在运行、准备暂停、暂停、准备停止、停止、失败、成功、需要容错、kill、等待线程的个数 - **工作流定义统计**:统计用户创建的工作流定义及管理员授予该用户的工作流定义 ![project-overview](../../../../img/new_ui/dev/project/project-overview.png) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java index b52804643d..1035018e9c 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java @@ -77,11 +77,11 @@ public final class AlertPluginManager { String name = entry.getKey(); AlertChannelFactory factory = entry.getValue(); - log.info("Registering alert plugin: {} - {}", name, factory.getClass()); + log.info("Registering alert plugin: {} - {}", name, factory.getClass().getSimpleName()); final AlertChannel alertChannel = factory.create(); - log.info("Registered alert plugin: {} - {}", name, factory.getClass()); + log.info("Registered alert plugin: {} - {}", name, factory.getClass().getSimpleName()); final List params = new ArrayList<>(factory.params()); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java index a044b05dbb..a735433b73 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java @@ -24,11 +24,12 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUEUE_COUNT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.TASK_INSTANCE_STATE_COUNT_ERROR; import org.apache.dolphinscheduler.api.dto.CommandStateCount; -import org.apache.dolphinscheduler.api.dto.DefineUserDto; -import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.dao.entity.User; @@ -59,17 +60,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; public class DataAnalysisController extends BaseController { @Autowired - DataAnalysisService dataAnalysisService; + private DataAnalysisService dataAnalysisService; - /** - * statistical task instance status data - * - * @param loginUser login user - * @param startDate count start date - * @param endDate count end date - * @param projectCode project code - * @return task instance count data - */ @Operation(summary = "countTaskState", description = "COUNT_TASK_STATE_NOTES") @Parameters({ @Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)), @@ -79,25 +71,17 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/task-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(TASK_INSTANCE_STATE_COUNT_ERROR) - public Result countTaskState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "startDate", required = false) String startDate, - @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - - TaskCountDto taskCountDto = - dataAnalysisService.countTaskStateByProject(loginUser, projectCode, startDate, endDate); - return Result.success(taskCountDto); + public Result getTaskInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "projectCode", required = false) Long projectCode) { + if (projectCode == null) { + return Result.success(dataAnalysisService.getAllTaskInstanceStateCount(loginUser, startDate, endDate)); + } + return Result.success( + dataAnalysisService.getTaskInstanceStateCountByProject(loginUser, projectCode, startDate, endDate)); } - /** - * statistical process instance status data - * - * @param loginUser login user - * @param startDate start date - * @param endDate end date - * @param projectCode project code - * @return process instance data - */ @Operation(summary = "countProcessInstanceState", description = "COUNT_PROCESS_INSTANCE_NOTES") @Parameters({ @Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)), @@ -107,23 +91,17 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/process-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR) - public Result countProcessInstanceState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "startDate", required = false) String startDate, - @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - - TaskCountDto taskCountDto = - dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectCode, startDate, endDate); - return Result.success(taskCountDto); + public Result getWorkflowInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "projectCode", required = false) Long projectCode) { + if (projectCode == null) { + return Result.success(dataAnalysisService.getAllWorkflowInstanceStateCount(loginUser, startDate, endDate)); + } + return Result.success( + dataAnalysisService.getWorkflowInstanceStateCountByProject(loginUser, projectCode, startDate, endDate)); } - /** - * statistics the process definition quantities of certain person - * - * @param loginUser login user - * @param projectCode project code - * @return definition count in project code - */ @Operation(summary = "countDefinitionByUser", description = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES") @Parameters({ @Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "100")) @@ -131,11 +109,12 @@ public class DataAnalysisController extends BaseController { @GetMapping(value = "/define-user-count") @ResponseStatus(HttpStatus.OK) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) - public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { - - DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUser(loginUser, projectCode); - return Result.success(defineUserDto); + public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "projectCode", required = false) Long projectCode) { + if (projectCode == null) { + return Result.success(dataAnalysisService.getAllWorkflowDefinitionCount(loginUser)); + } + return Result.success(dataAnalysisService.getWorkflowDefinitionCountByProject(loginUser, projectCode)); } /** diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java index f23a29671c..9dda86b97b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.api.controller.v2; import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR; -import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR; @@ -34,10 +33,6 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.commons.lang3.StringUtils; - -import java.util.Map; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -62,20 +57,6 @@ public class StatisticsV2Controller extends BaseController { @Autowired private DataAnalysisService dataAnalysisService; - /** - * query all workflow count - * @param loginUser login user - * @return workflow count - */ - @Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT") - @GetMapping(value = "/workflows/count") - @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR) - public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = dataAnalysisService.queryAllWorkflowCounts(loginUser); - return returnDataList(result); - } - /** * query all workflow states count * @@ -157,13 +138,8 @@ public class StatisticsV2Controller extends BaseController { @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) { - String projectName = statisticsStateRequest.getProjectName(); - Long projectCode = statisticsStateRequest.getProjectCode(); - if (null == projectCode && !StringUtils.isBlank(projectName)) { - projectCode = dataAnalysisService.getProjectCodeByName(projectName); - } - DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null); - return Result.success(defineUserDto); + // todo: directly use StatisticsStateRequest + throw new UnsupportedOperationException("not supported"); } /** @@ -179,7 +155,7 @@ public class StatisticsV2Controller extends BaseController { @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) public Result countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable("userId") Integer userId) { - DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null); + DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, userId, null); return Result.success(defineUserDto); } @@ -199,7 +175,7 @@ public class StatisticsV2Controller extends BaseController { @PathVariable("userId") Integer userId, @PathVariable("releaseState") Integer releaseState) { DefineUserDto defineUserDto = - dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState); + dataAnalysisService.countDefinitionByUserV2(loginUser, userId, releaseState); return Result.success(defineUserDto); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java index dddc0a7560..93eba75b05 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.api.dto; -import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; +import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import java.util.List; @@ -28,11 +28,11 @@ public class DefineUserDto { private int count; - private List userList; + private List userList; - public DefineUserDto(List defineGroupByUsers) { + public DefineUserDto(List defineGroupByUsers) { - for (DefinitionGroupByUser define : defineGroupByUsers) { + for (WorkflowDefinitionCountDto define : defineGroupByUsers) { count += define.getCount(); } this.userList = defineGroupByUsers; @@ -46,11 +46,11 @@ public class DefineUserDto { this.count = count; } - public List getUserList() { + public List getUserList() { return userList; } - public void setUserList(List userList) { + public void setUserList(List userList) { this.userList = userList; } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java index 48131412c2..11488776f1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java @@ -21,12 +21,11 @@ import org.apache.dolphinscheduler.api.dto.CommandStateCount; import org.apache.dolphinscheduler.api.dto.DefineUserDto; import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest; -import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; +import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.ibatis.annotations.Param; - -import java.util.Date; import java.util.List; import java.util.Map; @@ -35,51 +34,39 @@ import java.util.Map; */ public interface DataAnalysisService { - /** - * statistical task instance status data - * - * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date - * @return task state count data - */ - TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate); + TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser, + Long projectCode, + String startDate, + String endDate); - /** - * statistical process instance status data - * - * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date - * @return process instance state count data - */ - TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, - String endDate); + TaskInstanceCountVo getAllTaskInstanceStateCount(User loginUser, + String startDate, + String endDate); + + WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser, + Long projectCodes, + String startDate, + String endDate); + + WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser, + String startDate, + String endDate); + + WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode); + + WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser); - /** - * statistics the process definition quantities of a certain person - *

- * We only need projects which users have permission to see to determine whether the definition belongs to the user or not. - * - * @param loginUser login user - * @param projectCode project code - * @return workflow count data - */ - DefineUserDto countDefinitionByUser(User loginUser, long projectCode); /** * statistics the workflow quantities of certain user *

* We only need projects which users have permission to see to determine whether the definition belongs to the user or not. * * @param loginUser login user - * @param projectCode project code * @param userId userId * @param releaseState releaseState * @return workflow count data */ - DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, Integer releaseState); + DefineUserDto countDefinitionByUserV2(User loginUser, Integer userId, Integer releaseState); /** * statistical command status data @@ -97,27 +84,6 @@ public interface DataAnalysisService { */ Map countQueueState(User loginUser); - /** - * Statistics task instance group by given project codes list - *

- * We only need project codes to determine whether the task instance belongs to the user or not. - * - * @param startTime Statistics start time - * @param endTime Statistics end time - * @param projectCodes Project codes list to filter - * @return List of ExecuteStatusCount - */ - List countTaskInstanceAllStatesByProjectCodes(@Param("startTime") Date startTime, - @Param("endTime") Date endTime, - @Param("projectCodes") Long[] projectCodes); - - /** - * query all workflow count - * @param loginUser login user - * @return workflow count - */ - Map queryAllWorkflowCounts(User loginUser); - /** * query all workflow states count * @param loginUser login user @@ -151,5 +117,4 @@ public interface DataAnalysisService { */ TaskCountDto countOneTaskStates(User loginUser, Long taskCode); - Long getProjectCodeByName(String projectName); } 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 4736633fa1..91f34e92a3 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 @@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.User; +import java.util.List; import java.util.Map; /** @@ -70,7 +71,7 @@ public interface ProjectService { void checkProjectAndAuthThrowException(User loginUser, Project project, String permission) throws ServiceException; - void checkProjectAndAuthThrowException(User loginUser, long projectCode, String permission) throws ServiceException; + void checkProjectAndAuthThrowException(User loginUser, Long projectCode, String permission) throws ServiceException; boolean hasProjectAndPerm(User loginUser, Project project, Map result, String perm); @@ -213,4 +214,6 @@ public interface ProjectService { * @return project list */ Result queryAllProjectListForDependent(); + + List getAuthorizedProjectCodes(User loginUser); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java index 6d9d1868a4..26dcbc5449 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java @@ -186,4 +186,12 @@ public class BaseServiceImpl implements BaseService { public boolean checkDescriptionLength(String description) { return description != null && description.codePointCount(0, description.length()) > 255; } + + protected Date transformDate(String dateStr) { + Date date = DateUtils.stringToDate(dateStr); + if (date == null) { + throw new IllegalArgumentException("dateStr: [" + dateStr + "] is invalid"); + } + return date; + } } 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 aa716cc6b2..84c5ca17f8 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 @@ -27,14 +27,14 @@ import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.service.ProjectService; +import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.CommandType; -import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.DateUtils; -import org.apache.dolphinscheduler.common.utils.TriFunction; import org.apache.dolphinscheduler.dao.entity.CommandCount; -import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Project; @@ -44,14 +44,16 @@ import org.apache.dolphinscheduler.dao.mapper.CommandMapper; import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; -import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; +import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto; +import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; +import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; import java.util.Arrays; @@ -60,7 +62,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -70,6 +71,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.google.common.collect.Lists; + /** * data analysis service impl */ @@ -101,165 +104,94 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal @Autowired private TaskDefinitionMapper taskDefinitionMapper; - @Autowired - private ProcessTaskRelationMapper relationMapper; - - /** - * statistical task instance status data - * - * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date - * @return task state count data - */ @Override - public TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate, - String endDate) { - - return countStateByProject( - loginUser, - projectCode, - startDate, - endDate, - this::countTaskInstanceAllStatesByProjectCodes); + public TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser, + Long projectCode, + String startDate, + String endDate) { + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); + Date start = startDate == null ? null : transformDate(startDate); + Date end = endDate == null ? null : transformDate(endDate); + List taskInstanceStatusCounts = + taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode)); + return TaskInstanceCountVo.of(taskInstanceStatusCounts); } - /** - * statistical process instance status data - * - * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date - * @return process instance state count data - */ @Override - public TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, - String endDate) { - TaskCountDto taskCountDto = countStateByProject( - loginUser, - projectCode, - startDate, - endDate, - (start, end, projectCodes) -> processInstanceMapper.countInstanceStateByProjectCodes(start, end, - projectCodes)); - - // process state count needs to remove state of forced success - if (taskCountDto != null) { - taskCountDto.removeStateFromCountList(TaskExecutionStatus.FORCED_SUCCESS); + public TaskInstanceCountVo getAllTaskInstanceStateCount(User loginUser, + String startDate, + String endDate) { + List projectCodes = projectService.getAuthorizedProjectCodes(loginUser); + if (CollectionUtils.isEmpty(projectCodes)) { + return TaskInstanceCountVo.empty(); } - return taskCountDto; + Date start = startDate == null ? null : transformDate(startDate); + Date end = endDate == null ? null : transformDate(endDate); + List taskInstanceStatusCounts = + taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, projectCodes); + return TaskInstanceCountVo.of(taskInstanceStatusCounts); } - /** - * Wrapper function of counting process instance state and task state - * - * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date - */ - private TaskCountDto countStateByProject(User loginUser, - long projectCode, - String startDate, - String endDate, - TriFunction> instanceStateCounter) { - if (projectCode != 0) { - projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); - } - - Date start = null; - Date end = null; - if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate)) { - start = DateUtils.stringToDate(startDate); - end = DateUtils.stringToDate(endDate); - if (Objects.isNull(start) || Objects.isNull(end)) { - throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); - } - } - Pair, TaskCountDto> projectIds = getProjectIds(loginUser); - if (projectIds.getRight() != null) { - return projectIds.getRight(); - } - Long[] projectCodeArray = - projectCode == 0 ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode}; - List processInstanceStateCounts = new ArrayList<>(); + @Override + public WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser, + Long projectCode, + String startDate, + String endDate) { + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); + Date start = startDate == null ? null : transformDate(startDate); + Date end = endDate == null ? null : transformDate(endDate); + List workflowInstanceStatusCountDtos = processInstanceMapper + .countWorkflowInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode)); + return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos); + } - if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) { - processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray); + @Override + public WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser, + String startDate, + String endDate) { + List projectCodes = projectService.getAuthorizedProjectCodes(loginUser); + if (CollectionUtils.isEmpty(projectCodes)) { + return WorkflowInstanceCountVo.empty(); } + Date start = startDate == null ? null : transformDate(startDate); + Date end = endDate == null ? null : transformDate(endDate); - if (processInstanceStateCounts != null) { - return new TaskCountDto(processInstanceStateCounts); - } - return null; + List workflowInstanceStatusCountDtos = + processInstanceMapper.countWorkflowInstanceStateByProjectCodes(start, end, projectCodes); + return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos); } - /** - * statistics the process definition quantities of a certain person - *

- * We only need projects which users have permission to see to determine whether the definition belongs to the user or not. - * - * @param loginUser login user - * @param projectCode project code - * @return definition count data - */ @Override - public DefineUserDto countDefinitionByUser(User loginUser, long projectCode) { - if (projectCode != 0) { - projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); - } - - // todo: refactor this method, don't use Pair - Pair, TaskCountDto> projectIds = getProjectIds(loginUser); - if (projectIds.getRight() != null) { - List emptyList = new ArrayList<>(); - return new DefineUserDto(emptyList); - } + public WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode) { + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); + List workflowDefinitionCounts = + processDefinitionMapper.countDefinitionByProjectCodes(Lists.newArrayList(projectCode)); + return WorkflowDefinitionCountVo.of(workflowDefinitionCounts); + } - List defineGroupByUsers = new ArrayList<>(); - Long[] projectCodeArray = - projectCode == 0 ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode}; - if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) { - defineGroupByUsers = processDefinitionMapper.countDefinitionByProjectCodes(projectCodeArray); + @Override + public WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser) { + List projectCodes = projectService.getAuthorizedProjectCodes(loginUser); + if (CollectionUtils.isEmpty(projectCodes)) { + return WorkflowDefinitionCountVo.empty(); } - - return new DefineUserDto(defineGroupByUsers); + return WorkflowDefinitionCountVo.of(processDefinitionMapper.countDefinitionByProjectCodes(projectCodes)); } - /** - * statistical command status data - * - * @param loginUser login user - * @return command state count data - */ @Override public List countCommandState(User loginUser) { - /** - * find all the task lists in the project under the user - * statistics based on task status execution, failure, completion, wait, total - */ - Date start = null; - Date end = null; - Pair, TaskCountDto> projectIds = getProjectIds(loginUser); - if (projectIds.getRight() != null) { - List noData = Arrays.stream(CommandType.values()) - .map(commandType -> new CommandStateCount(0, 0, commandType)) - .collect(Collectors.toList()); - return noData; - } - Long[] projectCodeArray = getProjectCodesArrays(projectIds.getLeft()); + List projectCodes = projectService.getAuthorizedProjectCodes(loginUser); + // count normal command state Map normalCountCommandCounts = - commandMapper.countCommandState(start, end, projectCodeArray) + commandMapper.countCommandState(null, null, projectCodes) .stream() .collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount)); // count error command state Map errorCommandCounts = - errorCommandMapper.countCommandState(start, end, projectCodeArray) + errorCommandMapper.countCommandState(null, null, projectCodes) .stream() .collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount)); @@ -272,24 +204,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return list; } - private Pair, TaskCountDto> getProjectIds(User loginUser) { - Set projectIds = resourcePermissionCheckService - .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log); - if (projectIds.isEmpty()) { - List taskInstanceStateCounts = new ArrayList<>(); - return Pair.of(null, new TaskCountDto(taskInstanceStateCounts)); - } - return Pair.of(projectIds, null); - } - - private Long[] getProjectCodesArrays(Set projectIds) { - List projects = projectMapper.selectBatchIds(projectIds); - List codeList = projects.stream().map(Project::getCode).collect(Collectors.toList()); - Long[] projectCodeArray = new Long[codeList.size()]; - codeList.toArray(projectCodeArray); - return projectCodeArray; - } - /** * count queue state * @@ -306,59 +220,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return dataMap; } - @Override - public List countTaskInstanceAllStatesByProjectCodes(Date startTime, Date endTime, - Long[] projectCodes) { - Optional> startTimeStates = Optional.ofNullable( - this.taskInstanceMapper.countTaskInstanceStateByProjectCodes(startTime, endTime, projectCodes)); - - List allState = Arrays.stream(TaskExecutionStatus.values()).collect(Collectors.toList()); - List needRecountState; - if (startTimeStates.isPresent() && startTimeStates.get().size() != 0) { - List instanceState = - startTimeStates.get().stream().map(ExecuteStatusCount::getState).collect(Collectors.toList()); - // value 0 state need to recount by submit time - needRecountState = - allState.stream().filter(ele -> !instanceState.contains(ele)).collect(Collectors.toList()); - if (needRecountState.size() == 0) { - return startTimeStates.get(); - } - } else { - needRecountState = allState; - } - - // use submit time to recount when 0 - // if have any issues with this code, should change to specified states 0 8 9 17 not state count is 0 - List recounts = this.taskInstanceMapper - .countTaskInstanceStateByProjectCodesAndStatesBySubmitTime(startTime, endTime, projectCodes, - needRecountState); - startTimeStates.orElseGet(ArrayList::new).addAll(recounts); - - return startTimeStates.orElse(null); - } - /** - * query all workflow count - * - * @param loginUser login user - * @return workflow count - */ - @Override - public Map queryAllWorkflowCounts(User loginUser) { - Map result = new HashMap<>(); - int count = 0; - Set projectIds = resourcePermissionCheckService - .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log); - if (!projectIds.isEmpty()) { - List projects = projectMapper.selectBatchIds(projectIds); - List projectCodes = projects.stream().map(project -> project.getCode()).collect(Collectors.toList()); - count = projectMapper.queryAllWorkflowCounts(projectCodes); - } - // todo: refactor this method, don't use Map - result.put("data", "AllWorkflowCounts = " + count); - putMsg(result, Status.SUCCESS); - return result; - } - /** * query all workflow states count * @@ -524,38 +385,27 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal *

* We only need projects which users have permission to see to determine whether the definition belongs to the user or not. * - * @param loginUser login user - * @param projectCode project code + * @param loginUser login user * @return definition count data */ @Override - public DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, + public DefineUserDto countDefinitionByUserV2(User loginUser, + Integer userId, Integer releaseState) { - if (null != projectCode) { - Project project = projectMapper.queryByCode(projectCode); - projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW); - } - - List defineGroupByUsers = new ArrayList<>(); - Pair, TaskCountDto> projectIds = getProjectIds(loginUser); - if (projectIds.getRight() != null) { - List emptyList = new ArrayList<>(); - return new DefineUserDto(emptyList); - } - Long[] projectCodeArray = - projectCode == null ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode}; - if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) { - defineGroupByUsers = - processDefinitionMapper.countDefinitionByProjectCodesV2(projectCodeArray, userId, releaseState); + Set projectIds = resourcePermissionCheckService + .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log); + if (CollectionUtils.isEmpty(projectIds)) { + return new DefineUserDto(Collections.emptyList()); } + List projectCodes = projectMapper.selectBatchIds(projectIds) + .stream() + .map(Project::getCode) + .collect(Collectors.toList()); - return new DefineUserDto(defineGroupByUsers); - } + List workflowDefinitionCountDtos = + processDefinitionMapper.countDefinitionByProjectCodesV2(projectCodes, userId, releaseState); - @Override - public Long getProjectCodeByName(String projectName) { - Project project = projectMapper.queryByName(projectName); - return project == null ? 0 : project.getCode(); + return new DefineUserDto(workflowDefinitionCountDtos); } private List setOptional(Optional> startTimeStates) { 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 49fcf01086..e6e36cc55b 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 @@ -573,10 +573,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro Integer userId, Integer pageNo, Integer pageSize) { - Project project = projectMapper.queryByCode(projectCode); // check user access for project - projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_DEFINITION); PageListingResult processDefinitionsPageListingResult = processDefinitionDao.listingProcessDefinition( 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 db6c7d1ae7..899f578e57 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 @@ -337,10 +337,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByCode(projectCode); // check user access for project - projectService.checkProjectAndAuthThrowException(loginUser, project, - ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); int[] statusArray = null; // filter by state @@ -356,7 +354,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce IPage processInstanceList = processInstanceMapper.queryProcessInstanceListPaging( page, - project.getCode(), + projectCode, processDefineCode, searchVal, executorName, @@ -685,14 +683,10 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce String taskDefinitionJson, String scheduleTime, Boolean syncDefine, String globalParams, String locations, int timeout) { - Project project = projectMapper.queryByCode(projectCode); // check user access for project - Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, - ApiFuncIdentificationConstant.INSTANCE_UPDATE); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, + ApiFuncIdentificationConstant.INSTANCE_UPDATE); + Map result = new HashMap<>(); // check process instance exists ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId) .orElseThrow(() -> new ServiceException(PROCESS_INSTANCE_NOT_EXIST, processInstanceId)); 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 0f57e55722..1a00584a26 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 @@ -41,6 +41,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -52,6 +53,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -239,7 +241,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic } @Override - public void checkProjectAndAuthThrowException(User loginUser, long projectCode, String permission) { + public void checkProjectAndAuthThrowException(User loginUser, Long projectCode, String permission) { + if (projectCode == null) { + throw new ServiceException(Status.PROJECT_NOT_EXIST); + } Project project = projectMapper.queryByCode(projectCode); checkProjectAndAuthThrowException(loginUser, project, permission); } @@ -834,4 +839,20 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic putMsg(result, Status.SUCCESS); return result; } + + @Override + public List getAuthorizedProjectCodes(User loginUser) { + if (loginUser == null) { + throw new IllegalArgumentException("loginUser can not be null"); + } + Set projectIds = resourcePermissionCheckService + .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log); + if (CollectionUtils.isEmpty(projectIds)) { + return Collections.emptyList(); + } + return projectMapper.selectBatchIds(projectIds) + .stream() + .map(Project::getCode) + .collect(Collectors.toList()); + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java index 67f200d443..026b54e701 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java @@ -144,9 +144,8 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst Integer pageNo, Integer pageSize) { Result result = new Result(); - Project project = projectMapper.queryByCode(projectCode); // check user access for project - projectService.checkProjectAndAuthThrowException(loginUser, project, TASK_INSTANCE); + projectService.checkProjectAndAuthThrowException(loginUser, projectCode, TASK_INSTANCE); int[] statusArray = null; if (stateType != null) { statusArray = new int[]{stateType.getCode()}; @@ -160,7 +159,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst // stream task without process instance taskInstanceIPage = taskInstanceMapper.queryStreamTaskInstanceListPaging( page, - project.getCode(), + projectCode, processDefinitionName, searchVal, taskName, @@ -174,7 +173,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst } else { taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( page, - project.getCode(), + projectCode, processInstanceId, processInstanceName, searchVal, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/TaskInstanceCountVo.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/TaskInstanceCountVo.java new file mode 100644 index 0000000000..d55cfc4f78 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/TaskInstanceCountVo.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.vo; + +import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto; +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TaskInstanceCountVo { + + private int totalCount; + + private List taskInstanceStatusCounts; + + public static TaskInstanceCountVo empty() { + return of(Collections.emptyList()); + } + + public static TaskInstanceCountVo of(List taskInstanceStatusCounts) { + taskInstanceStatusCounts = new ArrayList<>(taskInstanceStatusCounts); + + Map taskInstanceStatusCountMap = + taskInstanceStatusCounts.stream() + .collect(Collectors.toMap(TaskInstanceStatusCountDto::getState, Function.identity())); + + for (TaskExecutionStatus value : TaskExecutionStatus.values()) { + if (!taskInstanceStatusCountMap.containsKey(value)) { + taskInstanceStatusCounts.add(new TaskInstanceStatusCountDto(value, 0)); + } + } + + TaskInstanceCountVo taskInstanceCountVo = new TaskInstanceCountVo(); + taskInstanceCountVo.setTaskInstanceStatusCounts(taskInstanceStatusCounts); + taskInstanceCountVo + .setTotalCount(taskInstanceStatusCounts.stream().mapToInt(TaskInstanceStatusCountDto::getCount).sum()); + return taskInstanceCountVo; + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowDefinitionCountVo.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowDefinitionCountVo.java new file mode 100644 index 0000000000..85435375d9 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowDefinitionCountVo.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.vo; + +import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.Collections; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WorkflowDefinitionCountVo { + + private int count; + + private List userList; + + public static WorkflowDefinitionCountVo empty() { + return new WorkflowDefinitionCountVo(0, Collections.emptyList()); + } + + public static WorkflowDefinitionCountVo of(List workflowDefinitionCounts) { + if (CollectionUtils.isEmpty(workflowDefinitionCounts)) { + return empty(); + } + WorkflowDefinitionCountVo workflowDefinitionCountVo = new WorkflowDefinitionCountVo(); + workflowDefinitionCountVo.setUserList(workflowDefinitionCounts); + workflowDefinitionCountVo + .setCount(workflowDefinitionCounts.stream().mapToInt(WorkflowDefinitionCountDto::getCount).sum()); + return workflowDefinitionCountVo; + } + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowInstanceCountVo.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowInstanceCountVo.java new file mode 100644 index 0000000000..92380982ad --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowInstanceCountVo.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.vo; + +import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; +import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WorkflowInstanceCountVo { + + private int totalCount; + + private List workflowInstanceStatusCounts; + + public static WorkflowInstanceCountVo empty() { + return of(Collections.emptyList()); + } + + public static WorkflowInstanceCountVo of(List workflowInstanceStatusCountDtos) { + workflowInstanceStatusCountDtos = new ArrayList<>(workflowInstanceStatusCountDtos); + + Map workflowExecutionStatusWorkflowInstanceStatusCountMap = + workflowInstanceStatusCountDtos.stream() + .collect(Collectors.toMap(WorkflowInstanceStatusCountDto::getState, Function.identity())); + for (WorkflowExecutionStatus workflowExecutionStatus : WorkflowExecutionStatus.values()) { + if (!workflowExecutionStatusWorkflowInstanceStatusCountMap.containsKey(workflowExecutionStatus)) { + workflowInstanceStatusCountDtos.add(new WorkflowInstanceStatusCountDto(workflowExecutionStatus, 0)); + } + } + + WorkflowInstanceCountVo workflowInstanceCountVo = new WorkflowInstanceCountVo(); + workflowInstanceCountVo.setWorkflowInstanceStatusCounts(workflowInstanceStatusCountDtos); + workflowInstanceCountVo.setTotalCount( + workflowInstanceStatusCountDtos.stream().mapToInt(WorkflowInstanceStatusCountDto::getCount).sum()); + return workflowInstanceCountVo; + } + +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java index 553f9a255c..30b30da607 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java @@ -24,6 +24,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo; +import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; @@ -39,6 +41,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import com.fasterxml.jackson.core.type.TypeReference; + /** * data analysis controller test */ @@ -60,7 +64,7 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { } @Test - public void testCountTaskState() throws Exception { + public void testGetTaskInstanceStateCount() throws Exception { int projectId = createProject(); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); @@ -73,15 +77,17 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode()); - logger.info(mvcResult.getResponse().getContentAsString()); - + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), + new TypeReference>() { + }); + assertThat(result.getCode()) + .isNotNull() + .isEqualTo(Status.SUCCESS.getCode()); projectMapper.deleteById(projectId); } @Test - public void testCountProcessInstanceState() throws Exception { + public void testGetWorkflowInstanceStateCount() throws Exception { int projectId = createProject(); MultiValueMap paramsMap = new LinkedMultiValueMap<>(); @@ -95,9 +101,11 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode()); - logger.info(mvcResult.getResponse().getContentAsString()); + Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), + new TypeReference>() { + }); + assertThat(result.getCode()) + .isEqualTo(Status.SUCCESS.getCode()); projectMapper.deleteById(projectId); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2ControllerTest.java index f5c488581f..e39727f866 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2ControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2ControllerTest.java @@ -25,18 +25,14 @@ import org.apache.dolphinscheduler.api.controller.AbstractControllerTest; import org.apache.dolphinscheduler.api.dto.DefineUserDto; import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest; -import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl; import org.apache.dolphinscheduler.api.utils.Result; -import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.User; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -50,21 +46,6 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest { @Mock private DataAnalysisServiceImpl dataAnalysisService; - @Test - public void testQueryWorkflowInstanceCounts() { - User loginUser = getLoginUser(); - int count = 0; - Map result = new HashMap<>(); - result.put("data", "AllWorkflowCounts = " + count); - putMsg(result, Status.SUCCESS); - - when(dataAnalysisService.queryAllWorkflowCounts(loginUser)).thenReturn(result); - - Result result1 = statisticsV2Controller.queryWorkflowInstanceCounts(loginUser); - - assertTrue(result1.isSuccess()); - - } @Test public void testQueryWorkflowStatesCounts() { User loginUser = getLoginUser(); @@ -121,27 +102,14 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest { assertTrue(result1.isSuccess()); } - @Test - public void testCountDefinitionByUser() { - User loginUser = getLoginUser(); - - StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest(); - List definitionGroupByUsers = new ArrayList<>(); - DefineUserDto taskCountResult = new DefineUserDto(definitionGroupByUsers); - when(dataAnalysisService.countDefinitionByUserV2(loginUser, statisticsStateRequest.getProjectCode(), null, - null)).thenReturn(taskCountResult); - - assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUser(loginUser, statisticsStateRequest)); - - } @Test public void testCountDefinitionByUserId() { User loginUser = getLoginUser(); Integer userId = 1; DefineUserDto defineUserDto = new DefineUserDto(Collections.emptyList()); - when(dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null)).thenReturn(defineUserDto); + when(dataAnalysisService.countDefinitionByUserV2(loginUser, userId, null)).thenReturn(defineUserDto); assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUserId(loginUser, userId)); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index 1d15ce6107..112a69db9d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.service; import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow; import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; @@ -27,12 +28,11 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import org.apache.dolphinscheduler.api.dto.CommandStateCount; -import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; -import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl; +import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.CommandType; @@ -77,8 +77,6 @@ import org.slf4j.LoggerFactory; @MockitoSettings(strictness = Strictness.LENIENT) public class DataAnalysisServiceTest { - private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); - private static final Logger serviceLogger = LoggerFactory.getLogger(DataAnalysisServiceImpl.class); @InjectMocks @@ -138,10 +136,10 @@ public class DataAnalysisServiceTest { String endDate = "2020-02-11 16:03:18"; doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); - when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // SUCCESS - assertDoesNotThrow(() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate)); + assertDoesNotThrow( + () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate, endDate)); } @Test @@ -153,37 +151,35 @@ public class DataAnalysisServiceTest { doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService) .checkProjectAndAuthThrowException(any(), anyLong(), any()); assertThrowsServiceException(Status.PROJECT_NOT_FOUND, - () -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate)); + () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate, endDate)); } @Test public void testCountTaskStateByProject_paramValid() { doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); - when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when date in illegal format then return error message String startDate2 = "illegalDateString"; String endDate2 = "illegalDateString"; - assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, - () -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate2, endDate2)); + assertThrows(IllegalArgumentException.class, + () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate2, endDate2)); // when one of date in illegal format then return error message String startDate3 = "2020-08-28 14:13:40"; String endDate3 = "illegalDateString"; - assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, - () -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate3, endDate3)); + assertThrows(IllegalArgumentException.class, + () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate3, endDate3)); // when one of date in illegal format then return error message String startDate4 = "illegalDateString"; String endDate4 = "2020-08-28 14:13:40"; - assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, - () -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate4, endDate4)); + assertThrows(IllegalArgumentException.class, + () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate4, endDate4)); } @Test public void testCountTaskStateByProject_allCountZero() { doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); - when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when general user doesn't have any task then return all count are 0 user.setUserType(UserType.GENERAL_USER); @@ -191,25 +187,23 @@ public class DataAnalysisServiceTest { serviceLogger)).thenReturn(projectIds()); when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())) .thenReturn(Collections.emptyList()); - TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); - assertThat(taskCountDto).extracting("totalCount").isEqualTo(0); - assertThat(taskCountDto).extracting("taskCountDtos").asList().hasSameSizeAs(TaskExecutionStatus.values()); - assertThat(taskCountDto).extracting("taskCountDtos").asList().extracting("count") - .allMatch(count -> count.equals(0)); + assertDoesNotThrow(() -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, null, null)); + } @Test public void testCountTaskStateByProject_noData() { doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); - when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(projectIds()); // when instanceStateCounter return null, then return nothing user.setUserType(UserType.GENERAL_USER); - when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn(null); - TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); - assertThat(taskCountDto).isNull(); + when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())) + .thenReturn(Collections.emptyList()); + TaskInstanceCountVo taskInstanceStateCountByProject = + dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, null, null); + assertThat(taskInstanceStateCountByProject).isNotNull(); } @Test @@ -217,31 +211,30 @@ public class DataAnalysisServiceTest { String startDate = "2020-02-11 16:02:18"; String endDate = "2020-02-11 16:03:18"; - when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); - // checkProject false doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService) .checkProjectAndAuthThrowException(any(), anyLong(), any()); assertThrowsServiceException(Status.PROJECT_NOT_FOUND, - () -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate)); + () -> dataAnalysisServiceImpl.getWorkflowInstanceStateCountByProject(user, 1L, startDate, endDate)); doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); // SUCCESS assertDoesNotThrow( - () -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate)); + () -> dataAnalysisServiceImpl.getWorkflowInstanceStateCountByProject(user, 1L, startDate, endDate)); } @Test public void testCountDefinitionByUser() { + doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(projectIds()); - assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0)); + assertDoesNotThrow(() -> dataAnalysisServiceImpl.getWorkflowDefinitionCountByProject(user, 0L)); when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(Collections.emptySet()); - assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0)); + assertDoesNotThrow(() -> dataAnalysisServiceImpl.getWorkflowDefinitionCountByProject(user, 0L)); } @Test diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java index 4f93043bb0..cd95511130 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java @@ -101,17 +101,17 @@ public class LoggerServiceTest { // PROJECT_NOT_EXIST taskInstance.setHost("127.0.0.1:8080"); taskInstance.setLogPath("/temp/log"); + Project project = getProject(1); + Mockito.when(projectMapper.queryProjectByTaskInstanceId(1)).thenReturn(project); try { Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) - .checkProjectAndAuthThrowException(loginUser, null, VIEW_LOG); + .checkProjectAndAuthThrowException(loginUser, project, VIEW_LOG); loggerService.queryLog(loginUser, 1, 1, 1); } catch (ServiceException serviceException) { Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); } // USER_NO_OPERATION_PERM - Project project = getProject(1); - when(projectMapper.queryProjectByTaskInstanceId(1)).thenReturn(project); try { Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PERM)).when(projectService) .checkProjectAndAuthThrowException(loginUser, project, VIEW_LOG); @@ -160,7 +160,7 @@ public class LoggerServiceTest { taskInstance.setLogPath("/temp/log"); try { Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) - .checkProjectAndAuthThrowException(loginUser, null, DOWNLOAD_LOG); + .checkProjectAndAuthThrowException(loginUser, taskInstance.getProjectCode(), DOWNLOAD_LOG); loggerService.queryLog(loginUser, 1, 1, 1); } catch (ServiceException serviceException) { Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); 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 dd0801977a..78de18c8e7 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 @@ -28,7 +28,10 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_UPDATE; import static org.apache.dolphinscheduler.common.constants.Constants.EMPTY_STRING; import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.when; import org.apache.dolphinscheduler.api.dto.workflow.WorkflowCreateRequest; import org.apache.dolphinscheduler.api.dto.workflow.WorkflowFilterRequest; @@ -212,7 +215,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testQueryProcessDefinitionList() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); @@ -220,18 +223,18 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project not found - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionList(user, projectCode); Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); // project check auth success putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); List resourceList = new ArrayList<>(); resourceList.add(getProcessDefinition()); - Mockito.when(processDefinitionMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); + when(processDefinitionMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); Map checkSuccessRes = processDefinitionService.queryProcessDefinitionList(user, projectCode); Assertions.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); @@ -239,15 +242,11 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testQueryProcessDefinitionListPaging() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - - Project project = getProject(projectCode); // project not found try { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(null); - Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) - .checkProjectAndAuthThrowException(user, null, WORKFLOW_DEFINITION); + doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) + .checkProjectAndAuthThrowException(user, projectCode, WORKFLOW_DEFINITION); processDefinitionService.queryProcessDefinitionListPaging(user, projectCode, "", "", 1, 5, 0); } catch (ServiceException serviceException) { Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); @@ -256,9 +255,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); user.setId(1); - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, - WORKFLOW_DEFINITION); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + doNothing().when(projectService).checkProjectAndAuthThrowException(user, projectCode, WORKFLOW_DEFINITION); long processDefinitionCode1 = 1L; long processDefinitionCode2 = 2L; List processDefinitions = Arrays.asList( @@ -272,15 +269,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { .pageSize(10) .totalCount(30) .build(); - Mockito.when(processDefinitionDao.listingProcessDefinition( + when(processDefinitionDao.listingProcessDefinition( Mockito.eq(0), Mockito.eq(10), Mockito.eq(""), Mockito.eq(1), - Mockito.eq(project.getCode()))).thenReturn(pageListingResult); + Mockito.eq(projectCode))).thenReturn(pageListingResult); String user1 = "user1"; String user2 = "user2"; - Mockito.when(userMapper.queryUserWithProcessDefinitionCode(processDefinitionCodes)) + when(userMapper.queryUserWithProcessDefinitionCode(processDefinitionCodes)) .thenReturn(Arrays.asList( UserWithProcessDefinitionCode.builder() .processDefinitionCode(processDefinitionCode1) @@ -296,10 +293,16 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Schedule schedule2 = new Schedule(); schedule2.setProcessDefinitionCode(processDefinitionCode2); schedule2.setReleaseState(ReleaseState.ONLINE); - Mockito.when(schedulerService.queryScheduleByProcessDefinitionCodes(processDefinitionCodes)) + when(schedulerService.queryScheduleByProcessDefinitionCodes(processDefinitionCodes)) .thenReturn(Arrays.asList(schedule1, schedule2)); PageInfo pageInfo = processDefinitionService.queryProcessDefinitionListPaging( - user, project.getCode(), "", "", 1, 0, 10); + user, + projectCode, + "", + "", + 1, + 0, + 10); Assertions.assertNotNull(pageInfo); ProcessDefinition pd1 = pageInfo.getTotalList().stream() .filter(pd -> pd.getCode() == processDefinitionCode1).findFirst().orElse(null); @@ -309,7 +312,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testQueryProcessDefinitionByCode() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); @@ -317,26 +320,26 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project check auth fail - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionByCode(user, 1L, 1L); Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); // project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); DagData dagData = new DagData(getProcessDefinition(), null, null); - Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); + when(processService.genDagData(Mockito.any())).thenReturn(dagData); Map instanceNotexitRes = processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 1L); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); // instance exit - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map successRes = processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L); @@ -345,7 +348,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testQueryProcessDefinitionByName() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); @@ -353,7 +356,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project check auth fail - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def"); @@ -361,19 +364,19 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); - Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); + when(processDefinitionMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); Map instanceNotExitRes = processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def"); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); // instance exit - Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test")) + when(processDefinitionMapper.queryByDefineName(project.getCode(), "test")) .thenReturn(getProcessDefinition()); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map successRes = processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test"); @@ -384,7 +387,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { public void testBatchCopyProcessDefinition() { Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); Mockito.doReturn(result) @@ -398,7 +401,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // project check auth fail putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_BATCH_COPY)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_BATCH_COPY)) .thenReturn(result); Map map1 = processDefinitionService.batchCopyProcessDefinition( user, projectCode, String.valueOf(project.getId()), 2L); @@ -406,7 +409,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // project check auth success, target project name not equal project name, check auth target project fail Project project1 = getProject(projectCodeOther); - Mockito.when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project1); + when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project1); Mockito.doReturn(result) .when(projectService) .checkProjectAndAuth(user, project1, projectCodeOther, WORKFLOW_BATCH_COPY); @@ -425,8 +428,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.fail(); } } - Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); - Mockito.when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); + when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); + when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); Map map3 = processDefinitionService.batchCopyProcessDefinition( user, projectCodeOther, String.valueOf(processDefinitionCode), projectCode); Assertions.assertEquals(Status.SUCCESS, map3.get(Constants.STATUS)); @@ -435,17 +438,17 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testBatchMoveProcessDefinition() { Project project1 = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); + when(projectMapper.queryByCode(projectCode)).thenReturn(project1); Project project2 = getProject(projectCodeOther); - Mockito.when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project2); + when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project2); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project1, projectCode, TASK_DEFINITION_MOVE)) + when(projectService.checkProjectAndAuth(user, project1, projectCode, TASK_DEFINITION_MOVE)) .thenReturn(result); - Mockito.when(projectService.checkProjectAndAuth(user, project2, projectCodeOther, TASK_DEFINITION_MOVE)) + when(projectService.checkProjectAndAuth(user, project2, projectCodeOther, TASK_DEFINITION_MOVE)) .thenReturn(result); ProcessDefinition definition = getProcessDefinition(); @@ -462,9 +465,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.fail(); } } - Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); - Mockito.when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); - Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode)) + when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); + when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); + when(processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode)) .thenReturn(getProcessTaskRelation()); putMsg(result, Status.SUCCESS); @@ -475,8 +478,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void deleteProcessDefinitionByCodeTest() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Mockito.doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(46L); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(46L); Project project = getProject(projectCode); @@ -486,24 +489,24 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); // project check auth fail - Mockito.when(processDefinitionDao.queryByCode(6L)).thenReturn(Optional.of(getProcessDefinition())); - Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_FOUND)).when(projectService) + when(processDefinitionDao.queryByCode(6L)).thenReturn(Optional.of(getProcessDefinition())); + doThrow(new ServiceException(Status.PROJECT_NOT_FOUND)).when(projectService) .checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION_DELETE); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 6L)); Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode()); // project check auth success, instance not exist - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, + doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION_DELETE); - Mockito.when(processDefinitionDao.queryByCode(1L)).thenReturn(Optional.empty()); + when(processDefinitionDao.queryByCode(1L)).thenReturn(Optional.empty()); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 1L)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); ProcessDefinition processDefinition = getProcessDefinition(); // user no auth - Mockito.when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); + when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); Assertions.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), ((ServiceException) exception).getCode()); @@ -511,17 +514,17 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // process definition online user.setUserType(UserType.ADMIN_USER); processDefinition.setReleaseState(ReleaseState.ONLINE); - Mockito.when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); + when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); Assertions.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE.getCode(), ((ServiceException) exception).getCode()); // scheduler list elements > 1 processDefinition.setReleaseState(ReleaseState.OFFLINE); - Mockito.when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); - Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); - Mockito.when(scheduleMapper.deleteById(46)).thenReturn(1); - Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) + when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); + when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); + when(scheduleMapper.deleteById(46)).thenReturn(1); + when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) .thenReturn(Collections.emptySet()); processDefinitionService.deleteProcessDefinitionByCode(user, 46L); Mockito.verify(metricsCleanUpService, times(1)).cleanUpWorkflowMetricsByDefinitionCode(46L); @@ -529,7 +532,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // scheduler online Schedule schedule = getSchedule(); schedule.setReleaseState(ReleaseState.ONLINE); - Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedule); + when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedule); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); Assertions.assertEquals(Status.SCHEDULE_STATE_ONLINE.getCode(), ((ServiceException) exception).getCode()); @@ -537,7 +540,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // process used by other task, sub process user.setUserType(UserType.ADMIN_USER); TaskMainInfo taskMainInfo = getTaskMainInfo().get(0); - Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) + when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) .thenReturn(ImmutableSet.copyOf(getTaskMainInfo())); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); @@ -546,9 +549,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // delete success schedule.setReleaseState(ReleaseState.OFFLINE); - Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); - Mockito.when(scheduleMapper.deleteById(schedule.getId())).thenReturn(1); - Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) + when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); + when(scheduleMapper.deleteById(schedule.getId())).thenReturn(1); + when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) .thenReturn(Collections.emptySet()); Assertions.assertDoesNotThrow(() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); Mockito.verify(metricsCleanUpService, times(2)).cleanUpWorkflowMetricsByDefinitionCode(46L); @@ -556,7 +559,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void batchDeleteProcessDefinitionByCodeTest() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); @@ -567,7 +570,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { ProcessDefinition process = getProcessDefinition(); List processDefinitionList = new ArrayList<>(); processDefinitionList.add(process); - Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); + when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); Throwable exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, twoCodes)); String formatter = MessageFormat.format(Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR.getMsg(), @@ -579,8 +582,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { final String singleCodes = "11"; definitionCodes = Lists.newArrayList(singleCodes.split(Constants.COMMA)).stream().map(Long::parseLong) .collect(Collectors.toSet()); - Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); - Mockito.when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); + when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); + when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); // process definition online user.setUserType(UserType.ADMIN_USER); @@ -596,11 +599,11 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // delete success process.setReleaseState(ReleaseState.OFFLINE); - Mockito.when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); - Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), process.getCode())) + when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); + when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), process.getCode())) .thenReturn(Collections.emptySet()); putMsg(result, Status.SUCCESS, projectCode); - Mockito.doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(11L); + doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(11L); Map deleteSuccess = processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, singleCodes); Assertions.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); @@ -609,14 +612,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testReleaseProcessDefinition() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); // project check auth fail Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_ONLINE_OFFLINE)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_ONLINE_OFFLINE)) .thenReturn(result); Map map = processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.OFFLINE); @@ -624,14 +627,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // project check auth success, processes definition online putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); List processTaskRelationList = new ArrayList<>(); ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); processTaskRelation.setProjectCode(projectCode); processTaskRelation.setProcessDefinitionCode(46L); processTaskRelation.setPostTaskCode(123L); processTaskRelationList.add(processTaskRelation); - Mockito.when(processService.findRelationByCode(46L, 1)).thenReturn(processTaskRelationList); + when(processService.findRelationByCode(46L, 1)).thenReturn(processTaskRelationList); Map onlineRes = processDefinitionService.releaseProcessDefinition(user, projectCode, 46, ReleaseState.ONLINE); Assertions.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); @@ -649,13 +652,13 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testVerifyProcessDefinitionName() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); // project check auth fail Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_CREATE)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_CREATE)) .thenReturn(result); Map map = processDefinitionService.verifyProcessDefinitionName(user, projectCode, "test_pdf", 0); @@ -663,13 +666,13 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // project check auth success, process not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); + when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); Map processNotExistRes = processDefinitionService.verifyProcessDefinitionName(user, projectCode, "test_pdf", 0); Assertions.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); // process exist - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")) + when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")) .thenReturn(getProcessDefinition()); Map processExistRes = processDefinitionService.verifyProcessDefinitionName(user, projectCode, "test_pdf", 0); @@ -690,15 +693,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testGetTaskNodeListByDefinitionCode() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); // project check auth fail Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); + when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); // process definition not exist - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(null); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(null); Map processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); @@ -706,8 +709,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // success ProcessDefinition processDefinition = getProcessDefinition(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); + when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); Map dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L); Assertions.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); @@ -715,18 +718,18 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testGetTaskNodeListByDefinitionCodes() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); // project check auth fail Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); + when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); // process definition not exist String defineCodes = "46"; Set defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong) .collect(Collectors.toSet()); - Mockito.when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(null); + when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(null); Map processNotExistRes = processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processNotExistRes.get(Constants.STATUS)); @@ -736,12 +739,12 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { List processDefinitionList = new ArrayList<>(); processDefinitionList.add(processDefinition); - Mockito.when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(processDefinitionList); - Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); + when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(processDefinitionList); + when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); Project project1 = getProject(projectCode); List projects = new ArrayList<>(); projects.add(project1); - Mockito.when(projectMapper.queryProjectCreatedAndAuthorizedByUserId(user.getId())).thenReturn(projects); + when(projectMapper.queryProjectCreatedAndAuthorizedByUserId(user.getId())).thenReturn(projects); Map successRes = processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes); @@ -752,14 +755,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { public void testQueryAllProcessDefinitionByProjectCode() { Map result = new HashMap<>(); Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); ProcessDefinition processDefinition = getProcessDefinition(); List processDefinitionList = new ArrayList<>(); processDefinitionList.add(processDefinition); - Mockito.when(processDefinitionMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList); + when(processDefinitionMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList); Map successRes = processDefinitionService.queryAllProcessDefinitionByProjectCode(user, projectCode); Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); @@ -770,8 +773,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Project project1 = getProject(projectCode); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); - Mockito.when(projectService.checkProjectAndAuth(user, project1, projectCode, WORKFLOW_TREE_VIEW)) + when(projectMapper.queryByCode(1)).thenReturn(project1); + when(projectService.checkProjectAndAuth(user, project1, projectCode, WORKFLOW_TREE_VIEW)) .thenReturn(result); // process definition not exist ProcessDefinition processDefinition = getProcessDefinition(); @@ -781,10 +784,10 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // task instance not existproject putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); - Mockito.when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); - Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); + when(projectMapper.queryByCode(1)).thenReturn(project1); + when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); + when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); Map taskNullRes = processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10); Assertions.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS)); @@ -798,14 +801,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testSubProcessViewTree() { ProcessDefinition processDefinition = getProcessDefinition(); - Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); + when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); Project project1 = getProject(1); Map result = new HashMap<>(); result.put(Constants.STATUS, Status.SUCCESS); - Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); - Mockito.when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); - Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); + when(projectMapper.queryByCode(1)).thenReturn(project1); + when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); + when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); Map taskNotNuLLRes = processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10); Assertions.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); @@ -816,8 +819,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Map result = new HashMap<>(); Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Mockito.when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true); try { processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1, @@ -835,16 +838,16 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUND); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); processDefinitionService.batchExportProcessDefinitionByCodes(user, projectCode, "1", null); ProcessDefinition processDefinition = new ProcessDefinition(); processDefinition.setId(1); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); + when(projectMapper.queryByCode(projectCode)).thenReturn(project); HttpServletResponse response = Mockito.mock(HttpServletResponse.class); DagData dagData = new DagData(getProcessDefinition(), null, null); - Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); + when(processService.genDagData(Mockito.any())).thenReturn(dagData); processDefinitionService.batchExportProcessDefinitionByCodes(user, projectCode, "1", response); Assertions.assertNotNull(processDefinitionService.exportProcessDagData(processDefinition)); } @@ -869,25 +872,25 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { new MockMultipartFile("import_sql.zip", byteArrayOutputStream.toByteArray()); DataSource dataSource = Mockito.mock(DataSource.class); - Mockito.when(dataSource.getId()).thenReturn(1); - Mockito.when(dataSource.getType()).thenReturn(DbType.MYSQL); + when(dataSource.getId()).thenReturn(1); + when(dataSource.getType()).thenReturn(DbType.MYSQL); - Mockito.when(dataSourceMapper.queryDataSourceByNameAndUserId(user.getId(), "mysql_1")).thenReturn(dataSource); + when(dataSourceMapper.queryDataSourceByNameAndUserId(user.getId(), "mysql_1")).thenReturn(dataSource); Project project = getProject(projectCode); Map result = new HashMap<>(); result.put(Constants.STATUS, Status.SUCCESS); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_IMPORT)) + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_IMPORT)) .thenReturn(result); - Mockito.when(processService.saveTaskDefine(Mockito.same(user), Mockito.eq(projectCode), Mockito.notNull(), + when(processService.saveTaskDefine(Mockito.same(user), Mockito.eq(projectCode), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(2); - Mockito.when(processService.saveProcessDefine(Mockito.same(user), Mockito.notNull(), Mockito.notNull(), + when(processService.saveProcessDefine(Mockito.same(user), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(1); - Mockito.when( + when( processService.saveTaskRelation(Mockito.same(user), Mockito.eq(projectCode), Mockito.anyLong(), Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())) - .thenReturn(0); + .thenReturn(0); result = processDefinitionService.importSqlProcessDefinition(user, projectCode, mockMultipartFile); Assertions.assertEquals(result.get(Constants.STATUS), Status.SUCCESS); @@ -920,8 +923,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode()); // project permission error - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) + when(projectMapper.queryByCode(projectCode)).thenReturn(project); + doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) .checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); @@ -930,7 +933,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // description too long workflowCreateRequest.setDescription(taskDefinitionJson); - Mockito.doThrow(new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR)).when(projectService) + doThrow(new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR)).when(projectService) .checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); @@ -938,15 +941,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { workflowCreateRequest.setDescription(EMPTY_STRING); // duplicate process definition name - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)) + doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); + when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)) .thenReturn(this.getProcessDefinition()); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), ((ServiceException) exception).getCode()); - Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null); + when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null); // test success workflowCreateRequest.setDescription(description); @@ -954,8 +957,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { workflowCreateRequest.setReleaseState(releaseState); workflowCreateRequest.setWarningGroupId(warningGroupId); workflowCreateRequest.setExecutionType(executionType); - Mockito.when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); - Mockito.when(processDefinitionMapper.insert(Mockito.any())).thenReturn(1); + when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); + when(processDefinitionMapper.insert(Mockito.any())).thenReturn(1); ProcessDefinition processDefinition = processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest); @@ -976,8 +979,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { workflowFilterRequest.setProjectName(project.getName()); // project permission error - Mockito.when(projectMapper.queryByName(project.getName())).thenReturn(project); - Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) + when(projectMapper.queryByName(project.getName())).thenReturn(project); + doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) .when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.filterProcessDefinition(user, workflowFilterRequest)); @@ -993,10 +996,10 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); // project permission error - Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)) + when(processDefinitionMapper.queryByCode(processDefinitionCode)) .thenReturn(this.getProcessDefinition()); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); - Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) + when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); + doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) .when(projectService) .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION); exception = Assertions.assertThrows(ServiceException.class, @@ -1005,7 +1008,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { ((ServiceException) exception).getCode()); // success - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode), + doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION); ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition(user, processDefinitionCode); @@ -1027,7 +1030,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // error old process definition in release state processDefinition = this.getProcessDefinition(); processDefinition.setReleaseState(ReleaseState.ONLINE); - Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); + when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_ALLOWED_EDIT.getCode(), @@ -1035,9 +1038,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // error project permission processDefinition = this.getProcessDefinition(); - Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); - Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) + when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); + when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); + doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) .when(projectService) .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION); exception = Assertions.assertThrows(ServiceException.class, @@ -1047,7 +1050,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { // error description too long workflowUpdateRequest.setDescription(taskDefinitionJson); - Mockito.doThrow(new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR)).when(projectService) + doThrow(new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR)).when(projectService) .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_UPDATE); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); @@ -1055,31 +1058,31 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { workflowUpdateRequest.setDescription(EMPTY_STRING); // error new definition name already exists - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode), + doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_UPDATE); - Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) + when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) .thenReturn(this.getProcessDefinition()); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), ((ServiceException) exception).getCode()); - Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); - Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) + when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); + when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) .thenReturn(null); // error update process definition mapper workflowUpdateRequest.setName(name); - Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); - Mockito.when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); + when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); + when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); Assertions.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR.getCode(), ((ServiceException) exception).getCode()); // success - Mockito.when(processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode())) + when(processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode())) .thenReturn(processDefinition.getVersion()); - Mockito.when(processDefinitionMapper.updateById(isA(ProcessDefinition.class))).thenReturn(1); + when(processDefinitionMapper.updateById(isA(ProcessDefinition.class))).thenReturn(1); ProcessDefinition processDefinitionUpdate = processDefinitionService.updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest); @@ -1098,7 +1101,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testViewVariables() { - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Project project = getProject(projectCode); @@ -1108,7 +1111,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project check auth fail - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) + when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); Map map = 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 a0d83c4649..800f8bda18 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 @@ -20,7 +20,10 @@ package org.apache.dolphinscheduler.api.service; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.INSTANCE_DELETE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.INSTANCE_UPDATE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_INSTANCE; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import org.apache.dolphinscheduler.api.enums.Status; @@ -192,13 +195,23 @@ public class ProcessInstanceServiceTest { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project auth fail - when(projectMapper.queryByCode(projectCode)).thenReturn(null); - Mockito.doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(Mockito.any(), - Mockito.any(), Mockito.any()); - Assertions.assertThrows(ServiceException.class, () -> { - processInstanceService.queryProcessInstanceList(loginUser, projectCode, 46, "2020-01-01 00:00:00", - "2020-01-02 00:00:00", "", "test_user", WorkflowExecutionStatus.SUBMITTED_SUCCESS, - "192.168.xx.xx", "", 1, 10); + doThrow(new ServiceException()) + .when(projectService) + .checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); + assertThrows(ServiceException.class, () -> { + processInstanceService.queryProcessInstanceList( + loginUser, + projectCode, + 46, + "2020-01-01 00:00:00", + "2020-01-02 00:00:00", + "", + "test_user", + WorkflowExecutionStatus.SUBMITTED_SUCCESS, + "192.168.xx.xx", + "", + 1, + 10); }); Date start = DateUtils.stringToDate("2020-01-01 00:00:00"); @@ -212,13 +225,14 @@ public class ProcessInstanceServiceTest { // data parameter check putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(Mockito.any(), Mockito.any(), + Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(Mockito.any(), + Mockito.any(Project.class), Mockito.any()); when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition()); when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); - Assertions.assertThrows(ServiceException.class, () -> processInstanceService.queryProcessInstanceList( + assertThrows(ServiceException.class, () -> processInstanceService.queryProcessInstanceList( loginUser, projectCode, 1, @@ -235,13 +249,20 @@ public class ProcessInstanceServiceTest { // project auth success putMsg(result, Status.SUCCESS, projectCode); - when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result); + doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); - when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), - eq(1L), eq(""), eq(""), Mockito.any(), - eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); + when(processInstanceMapper.queryProcessInstanceListPaging( + Mockito.any(Page.class), + eq(project.getCode()), + eq(1L), + eq(""), + eq(""), + Mockito.any(), + eq("192.168.xx.xx"), + eq(start), + eq(end))) + .thenReturn(pageReturn); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); Result successRes = @@ -554,18 +575,22 @@ public class ProcessInstanceServiceTest { // project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); - Map projectAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, - shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0); - Assertions.assertEquals(Status.PROJECT_NOT_FOUND, projectAuthFailRes.get(Constants.STATUS)); + doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, projectCode)) + .when(projectService) + .checkProjectAndAuthThrowException(loginUser, projectCode, INSTANCE_UPDATE); + Assertions.assertThrows(ServiceException.class, + () -> processInstanceService.updateProcessInstance(loginUser, projectCode, 1, + shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0)); // process instance null putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); + doNothing() + .when(projectService) + .checkProjectAndAuthThrowException(loginUser, projectCode, INSTANCE_UPDATE); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); - Assertions.assertThrows(ServiceException.class, () -> { + assertThrows(ServiceException.class, () -> { processInstanceService.updateProcessInstance(loginUser, projectCode, 1, shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0); }); @@ -637,7 +662,7 @@ public class ProcessInstanceServiceTest { when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); - Assertions.assertThrows(ServiceException.class, () -> { + assertThrows(ServiceException.class, () -> { processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); }); @@ -678,7 +703,7 @@ public class ProcessInstanceServiceTest { when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE)).thenReturn(result); - Assertions.assertThrows(ServiceException.class, + assertThrows(ServiceException.class, () -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); // not sub process @@ -689,7 +714,7 @@ public class ProcessInstanceServiceTest { when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(new ProcessDefinitionLog()); - Assertions.assertThrows(ServiceException.class, + assertThrows(ServiceException.class, () -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); processInstance.setState(WorkflowExecutionStatus.SUCCESS); @@ -704,7 +729,7 @@ public class ProcessInstanceServiceTest { processDefinition.setProjectCode(0L); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); when(processService.findProcessInstanceDetailById(Mockito.anyInt())).thenReturn(Optional.empty()); - Assertions.assertThrows(ServiceException.class, + assertThrows(ServiceException.class, () -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); processDefinition.setProjectCode(projectCode); 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 2c912f4103..b537c06dda 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 @@ -21,6 +21,8 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_INSTANCE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import org.apache.dolphinscheduler.api.ApiApplicationServer; @@ -108,9 +110,8 @@ public class TaskInstanceServiceTest { putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); // project auth fail - when(projectMapper.queryByCode(projectCode)).thenReturn(null); - Mockito.doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(Mockito.any(), - Mockito.any(), Mockito.any()); + doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, + TASK_INSTANCE); Assertions.assertThrows(ServiceException.class, () -> taskInstanceService.queryTaskListPaging(loginUser, projectCode, 0, @@ -159,9 +160,7 @@ public class TaskInstanceServiceTest { Page pageReturn = new Page<>(1, 10); taskInstanceList.add(taskInstance); pageReturn.setRecords(taskInstanceList); - when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(Mockito.any(), Mockito.any(), - Mockito.any()); + doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, TASK_INSTANCE); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(taskInstanceMapper.queryTaskInstanceListPaging( @@ -183,9 +182,22 @@ public class TaskInstanceServiceTest { when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())) .thenReturn(Optional.of(processInstance)); - Result successRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", - null, "test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", TaskExecutionStatus.SUCCESS, - "192.168.xx.xx", TaskExecuteType.BATCH, 1, 20); + Result successRes = taskInstanceService.queryTaskListPaging(loginUser, + projectCode, + 1, + "", + "", + "", + null, + "test_user", + "2020-01-01 00:00:00", + "2020-01-02 00:00:00", + "", + TaskExecutionStatus.SUCCESS, + "192.168.xx.xx", + TaskExecuteType.BATCH, + 1, + 20); Assertions.assertEquals(Status.SUCCESS.getCode(), (int) successRes.getCode()); // executor name empty diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java index d3cdb1a3ab..a8490cbef7 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java @@ -36,13 +36,13 @@ public interface CommandMapper extends BaseMapper { * count command state * @param startTime startTime * @param endTime endTime - * @param projectCodeArray projectCodeArray + * @param projectCodes projectCodes * @return CommandCount list */ List countCommandState( @Param("startTime") Date startTime, @Param("endTime") Date endTime, - @Param("projectCodeArray") Long[] projectCodeArray); + @Param("projectCodes") List projectCodes); /** * query command page diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java index 5c04e217e1..8054a91786 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java @@ -36,11 +36,11 @@ public interface ErrorCommandMapper extends BaseMapper { * count command state * @param startTime startTime * @param endTime endTime - * @param projectCodeArray projectCodeArray + * @param projectCodes projectCodes * @return CommandCount list */ List countCommandState( @Param("startTime") Date startTime, @Param("endTime") Date endTime, - @Param("projectCodeArray") Long[] projectCodeArray); + @Param("projectCodes") List projectCodes); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 806b91982e..38011cd0e1 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -17,9 +17,9 @@ package org.apache.dolphinscheduler.dao.mapper; -import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.DependentSimplifyDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; +import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; @@ -158,7 +158,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param projectCodes projectCodes * @return definition group by user */ - List countDefinitionByProjectCodes(@Param("projectCodes") Long[] projectCodes); + List countDefinitionByProjectCodes(@Param("projectCodes") Collection projectCodes); /** * Statistics process definition group by project codes list @@ -170,9 +170,9 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param releaseState releaseState * @return definition group by user */ - List countDefinitionByProjectCodesV2(@Param("projectCodes") Long[] projectCodes, - @Param("userId") Integer userId, - @Param("releaseState") Integer releaseState); + List countDefinitionByProjectCodesV2(@Param("projectCodes") List projectCodes, + @Param("userId") Integer userId, + @Param("releaseState") Integer releaseState); /** * list all resource ids diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java index 9048e6f3ba..deef2a9d4c 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java @@ -20,9 +20,11 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; +import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Set; @@ -168,10 +170,10 @@ public interface ProcessInstanceMapper extends BaseMapper { * @param projectCodes projectCodes * @return ExecuteStatusCount list */ - List countInstanceStateByProjectCodes( - @Param("startTime") Date startTime, - @Param("endTime") Date endTime, - @Param("projectCodes") Long[] projectCodes); + List countWorkflowInstanceStateByProjectCodes( + @Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("projectCodes") Collection projectCodes); /** * query process instance by processDefinitionCode diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java index 105cf04700..6c1a133a87 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java @@ -18,10 +18,10 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.common.enums.TaskExecuteType; -import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; +import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; @@ -72,7 +72,7 @@ public interface TaskDefinitionMapper extends BaseMapper { * @param projectCodes projectCodes * @return task definition list */ - List countDefinitionGroupByUser(@Param("projectCodes") Long[] projectCodes); + List countDefinitionGroupByUser(@Param("projectCodes") Long[] projectCodes); /** * list all resource ids and task_params containing resourceList diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java index bcf6f056f8..bc28c1d5e6 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java @@ -21,10 +21,12 @@ import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.TaskExecuteType; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Set; @@ -77,9 +79,9 @@ public interface TaskInstanceMapper extends BaseMapper { * @param projectCodes Project codes list to filter * @return List of ExecuteStatusCount */ - List countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime, - @Param("endTime") Date endTime, - @Param("projectCodes") Long[] projectCodes); + List countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("projectCodes") Collection projectCodes); /** * Statistics task instance group by given project ids list by start time diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/TaskInstanceStatusCountDto.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/TaskInstanceStatusCountDto.java new file mode 100644 index 0000000000..017ef64a52 --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/TaskInstanceStatusCountDto.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.dao.model; + +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TaskInstanceStatusCountDto { + + private TaskExecutionStatus state; + + private int count; +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowDefinitionCountDto.java similarity index 79% rename from dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java rename to dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowDefinitionCountDto.java index b92b33ff5c..08aa0132b0 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowDefinitionCountDto.java @@ -15,28 +15,20 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.dao.entity; +package org.apache.dolphinscheduler.dao.model; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; -/** - * count definition number group by user - */ @Data -public class DefinitionGroupByUser { +@NoArgsConstructor +@AllArgsConstructor +public class WorkflowDefinitionCountDto { - /** - * user name - */ private String userName; - /** - * user id - */ private Integer userId; - /** - * count number - */ private int count; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowInstanceStatusCountDto.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowInstanceStatusCountDto.java new file mode 100644 index 0000000000..a539bc109d --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowInstanceStatusCountDto.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.dao.model; + +import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WorkflowInstanceStatusCountDto { + + private WorkflowExecutionStatus state; + + private int count; + +} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml index 0cbf7ea0ff..c950f66413 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml @@ -22,9 +22,9 @@ select cmd.command_type as command_type, count(1) as count from t_ds_command cmd, t_ds_process_definition process where cmd.process_definition_code = process.code - + and process.project_code in - + #{i} 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 8179ff44d1..8cf9fbd802 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 @@ -22,9 +22,9 @@ select cmd.command_type as command_type, count(1) as count from t_ds_error_command cmd, t_ds_process_definition process where cmd.process_definition_code = process.code - + and process.project_code in - + #{i} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml index 6781471be0..f8c3375b80 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml @@ -131,24 +131,27 @@ #{i} - + SELECT user_id as user_id, tu.user_name as user_name, count(0) as count FROM t_ds_process_definition td JOIN t_ds_user tu on tu.id=td.user_id where 1 = 1 - + and td.project_code in #{i} group by td.user_id,tu.user_name - + + - select t.state, count(0) as count - from t_ds_process_instance t - join t_ds_process_definition d on d.code=t.process_definition_code - where t.is_sub_process = 0 - - and t.start_time = ]]> #{startTime} and t.start_time #{endTime} + + - SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count FROM t_ds_task_definition td JOIN t_ds_user tu on tu.id=td.user_id diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml index cd9c36ed12..8e3674e523 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml @@ -78,26 +78,26 @@ - select state, count(0) as count - from t_ds_task_instance t - left join t_ds_task_definition_log d on d.code=t.task_code and d.version=t.task_definition_version - left join t_ds_project p on p.code=d.project_code + from t_ds_task_instance where 1=1 - - and d.project_code in + + and project_code in #{i} - and t.start_time ]]> #{startTime} + and start_time ]]> #{startTime} - and t.start_time #{endTime} + and start_time #{endTime} - group by t.state + group by state +