Browse Source

Fix home page workflow instance miss status (#15193)

3.2.1-prepare
Wenjun Ruan 1 year ago committed by GitHub
parent
commit
df656a7671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/docs/zh/guide/homepage.md
  2. 6
      docs/docs/zh/guide/project/project-list.md
  3. 4
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java
  4. 69
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java
  5. 32
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java
  6. 12
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java
  7. 81
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java
  8. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java
  9. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/BaseServiceImpl.java
  10. 302
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java
  11. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  12. 14
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  13. 23
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  14. 7
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
  15. 66
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/TaskInstanceCountVo.java
  16. 55
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowDefinitionCountVo.java
  17. 66
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/WorkflowInstanceCountVo.java
  18. 26
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java
  19. 34
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2ControllerTest.java
  20. 53
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java
  21. 8
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java
  22. 283
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  23. 73
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
  24. 30
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
  25. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java
  26. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java
  27. 6
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  28. 6
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java
  29. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java
  30. 6
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java
  31. 34
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/TaskInstanceStatusCountDto.java
  32. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowDefinitionCountDto.java
  33. 35
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowInstanceStatusCountDto.java
  34. 4
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml
  35. 4
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.xml
  36. 13
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  37. 24
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
  38. 2
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml
  39. 18
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
  40. 7
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java
  41. 10
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java
  42. 9
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java
  43. 33
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java
  44. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java
  45. 32
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
  46. 2
      dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/server/SpringServerMethodInvokerDiscovery.java
  47. 2
      dolphinscheduler-standalone-server/src/main/resources/application.yaml
  48. 4
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskPluginManager.java
  49. 3
      dolphinscheduler-ui/src/locales/en_US/home.ts
  50. 9
      dolphinscheduler-ui/src/locales/zh_CN/home.ts
  51. 25
      dolphinscheduler-ui/src/service/modules/projects-analysis/types.ts
  52. 2
      dolphinscheduler-ui/src/views/home/use-process-definition.ts
  53. 13
      dolphinscheduler-ui/src/views/home/use-process-state.ts
  54. 14
      dolphinscheduler-ui/src/views/home/use-task-state.ts
  55. 12
      dolphinscheduler-ui/src/views/projects/overview/use-process-state.ts
  56. 12
      dolphinscheduler-ui/src/views/projects/overview/use-task-state.ts

2
docs/docs/zh/guide/homepage.md

@ -1,5 +1,5 @@
# 首页 # 首页
Apache DolphinScheduler 首页可让您查看用户所有项目的任务状态统计、工作流状态统计和项目统计。 这是观察整个系统状态以及深入各个进程以检查任务和任务日志的每个状态的最佳方式。 Apache DolphinScheduler 首页可让您查看用户所有项目的任务实例状态统计、工作流实例状态统计和项目统计。 这是观察整个系统状态以及深入各个进程以检查任务和任务日志的每个状态的最佳方式。
![homepage](../../../img/new_ui/dev/homepage/homepage.png) ![homepage](../../../img/new_ui/dev/homepage/homepage.png)

6
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) ![project-overview](../../../../img/new_ui/dev/project/project-overview.png)

4
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(); String name = entry.getKey();
AlertChannelFactory factory = entry.getValue(); 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(); final AlertChannel alertChannel = factory.create();
log.info("Registered alert plugin: {} - {}", name, factory.getClass()); log.info("Registered alert plugin: {} - {}", name, factory.getClass().getSimpleName());
final List<PluginParams> params = new ArrayList<>(factory.params()); final List<PluginParams> params = new ArrayList<>(factory.params());

69
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 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.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.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.utils.Result; 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.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
@ -59,17 +60,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
public class DataAnalysisController extends BaseController { public class DataAnalysisController extends BaseController {
@Autowired @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") @Operation(summary = "countTaskState", description = "COUNT_TASK_STATE_NOTES")
@Parameters({ @Parameters({
@Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)), @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") @GetMapping(value = "/task-state-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(TASK_INSTANCE_STATE_COUNT_ERROR) @ApiException(TASK_INSTANCE_STATE_COUNT_ERROR)
public Result<TaskCountDto> countTaskState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<TaskInstanceCountVo> getTaskInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { @RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
TaskCountDto taskCountDto = return Result.success(dataAnalysisService.getAllTaskInstanceStateCount(loginUser, startDate, endDate));
dataAnalysisService.countTaskStateByProject(loginUser, projectCode, startDate, endDate); }
return Result.success(taskCountDto); 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") @Operation(summary = "countProcessInstanceState", description = "COUNT_PROCESS_INSTANCE_NOTES")
@Parameters({ @Parameters({
@Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)), @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") @GetMapping(value = "/process-state-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR) @ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR)
public Result<TaskCountDto> countProcessInstanceState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<WorkflowInstanceCountVo> getWorkflowInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate, @RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { @RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
TaskCountDto taskCountDto = return Result.success(dataAnalysisService.getAllWorkflowInstanceStateCount(loginUser, startDate, endDate));
dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectCode, startDate, endDate); }
return Result.success(taskCountDto); 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") @Operation(summary = "countDefinitionByUser", description = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES")
@Parameters({ @Parameters({
@Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "100")) @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") @GetMapping(value = "/define-user-count")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<WorkflowDefinitionCountVo> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { @RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUser(loginUser, projectCode); return Result.success(dataAnalysisService.getAllWorkflowDefinitionCount(loginUser));
return Result.success(defineUserDto); }
return Result.success(dataAnalysisService.getWorkflowDefinitionCountByProject(loginUser, projectCode));
} }
/** /**

32
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/StatisticsV2Controller.java

@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.api.controller.v2; 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.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_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_ONE_WORKFLOW_STATE_COUNT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_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.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User; 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.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -62,20 +57,6 @@ public class StatisticsV2Controller extends BaseController {
@Autowired @Autowired
private DataAnalysisService dataAnalysisService; 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<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
return returnDataList(result);
}
/** /**
* query all workflow states count * query all workflow states count
* *
@ -157,13 +138,8 @@ public class StatisticsV2Controller extends BaseController {
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) { @RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
String projectName = statisticsStateRequest.getProjectName(); // todo: directly use StatisticsStateRequest
Long projectCode = statisticsStateRequest.getProjectCode(); throw new UnsupportedOperationException("not supported");
if (null == projectCode && !StringUtils.isBlank(projectName)) {
projectCode = dataAnalysisService.getProjectCodeByName(projectName);
}
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
return Result.success(defineUserDto);
} }
/** /**
@ -179,7 +155,7 @@ public class StatisticsV2Controller extends BaseController {
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR) @ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<DefineUserDto> countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("userId") Integer userId) { @PathVariable("userId") Integer userId) {
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null); DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, userId, null);
return Result.success(defineUserDto); return Result.success(defineUserDto);
} }
@ -199,7 +175,7 @@ public class StatisticsV2Controller extends BaseController {
@PathVariable("userId") Integer userId, @PathVariable("userId") Integer userId,
@PathVariable("releaseState") Integer releaseState) { @PathVariable("releaseState") Integer releaseState) {
DefineUserDto defineUserDto = DefineUserDto defineUserDto =
dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState); dataAnalysisService.countDefinitionByUserV2(loginUser, userId, releaseState);
return Result.success(defineUserDto); return Result.success(defineUserDto);
} }
} }

12
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/DefineUserDto.java

@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.api.dto; package org.apache.dolphinscheduler.api.dto;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import java.util.List; import java.util.List;
@ -28,11 +28,11 @@ public class DefineUserDto {
private int count; private int count;
private List<DefinitionGroupByUser> userList; private List<WorkflowDefinitionCountDto> userList;
public DefineUserDto(List<DefinitionGroupByUser> defineGroupByUsers) { public DefineUserDto(List<WorkflowDefinitionCountDto> defineGroupByUsers) {
for (DefinitionGroupByUser define : defineGroupByUsers) { for (WorkflowDefinitionCountDto define : defineGroupByUsers) {
count += define.getCount(); count += define.getCount();
} }
this.userList = defineGroupByUsers; this.userList = defineGroupByUsers;
@ -46,11 +46,11 @@ public class DefineUserDto {
this.count = count; this.count = count;
} }
public List<DefinitionGroupByUser> getUserList() { public List<WorkflowDefinitionCountDto> getUserList() {
return userList; return userList;
} }
public void setUserList(List<DefinitionGroupByUser> userList) { public void setUserList(List<WorkflowDefinitionCountDto> userList) {
this.userList = userList; this.userList = userList;
} }
} }

81
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.DefineUserDto;
import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.dto.TaskCountDto;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest; 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.dolphinscheduler.dao.entity.User;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -35,51 +34,39 @@ import java.util.Map;
*/ */
public interface DataAnalysisService { public interface DataAnalysisService {
/** TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser,
* statistical task instance status data Long projectCode,
* String startDate,
* @param loginUser login user String endDate);
* @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 getAllTaskInstanceStateCount(User loginUser,
* statistical process instance status data String startDate,
*
* @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); String endDate);
/** WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser,
* statistics the process definition quantities of a certain person Long projectCodes,
* <p> String startDate,
* We only need projects which users have permission to see to determine whether the definition belongs to the user or not. String endDate);
*
* @param loginUser login user WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser,
* @param projectCode project code String startDate,
* @return workflow count data String endDate);
*/
DefineUserDto countDefinitionByUser(User loginUser, long projectCode); WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode);
WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser);
/** /**
* statistics the workflow quantities of certain user * statistics the workflow quantities of certain user
* <p> * <p>
* We only need projects which users have permission to see to determine whether the definition belongs to the user or not. * 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 loginUser login user
* @param projectCode project code
* @param userId userId * @param userId userId
* @param releaseState releaseState * @param releaseState releaseState
* @return workflow count data * @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 * statistical command status data
@ -97,27 +84,6 @@ public interface DataAnalysisService {
*/ */
Map<String, Integer> countQueueState(User loginUser); Map<String, Integer> countQueueState(User loginUser);
/**
* Statistics task instance group by given project codes list
* <p>
* 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<ExecuteStatusCount> 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<String, Object> queryAllWorkflowCounts(User loginUser);
/** /**
* query all workflow states count * query all workflow states count
* @param loginUser login user * @param loginUser login user
@ -151,5 +117,4 @@ public interface DataAnalysisService {
*/ */
TaskCountDto countOneTaskStates(User loginUser, Long taskCode); TaskCountDto countOneTaskStates(User loginUser, Long taskCode);
Long getProjectCodeByName(String projectName);
} }

5
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.Project;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import java.util.List;
import java.util.Map; 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, 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<String, Object> result, String perm); boolean hasProjectAndPerm(User loginUser, Project project, Map<String, Object> result, String perm);
@ -213,4 +214,6 @@ public interface ProjectService {
* @return project list * @return project list
*/ */
Result queryAllProjectListForDependent(); Result queryAllProjectListForDependent();
List<Long> getAuthorizedProjectCodes(User loginUser);
} }

8
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) { public boolean checkDescriptionLength(String description) {
return description != null && description.codePointCount(0, description.length()) > 255; 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;
}
} }

302
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.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.service.ProjectService; 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.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.CommandType; 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.DateUtils;
import org.apache.dolphinscheduler.common.utils.TriFunction;
import org.apache.dolphinscheduler.dao.entity.CommandCount; 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.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project; 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.ErrorCommandMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; 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.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; 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.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -60,7 +62,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -70,6 +71,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.google.common.collect.Lists;
/** /**
* data analysis service impl * data analysis service impl
*/ */
@ -101,165 +104,94 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
@Autowired @Autowired
private TaskDefinitionMapper taskDefinitionMapper; 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 @Override
public TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate, public TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser,
Long projectCode,
String startDate,
String endDate) { String endDate) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
return countStateByProject( Date start = startDate == null ? null : transformDate(startDate);
loginUser, Date end = endDate == null ? null : transformDate(endDate);
projectCode, List<TaskInstanceStatusCountDto> taskInstanceStatusCounts =
startDate, taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode));
endDate, return TaskInstanceCountVo.of(taskInstanceStatusCounts);
this::countTaskInstanceAllStatesByProjectCodes);
} }
/**
* 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 @Override
public TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, public TaskInstanceCountVo getAllTaskInstanceStateCount(User loginUser,
String startDate,
String endDate) { String endDate) {
TaskCountDto taskCountDto = countStateByProject( List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
loginUser, if (CollectionUtils.isEmpty(projectCodes)) {
projectCode, return TaskInstanceCountVo.empty();
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);
} }
return taskCountDto; Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
List<TaskInstanceStatusCountDto> taskInstanceStatusCounts =
taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, projectCodes);
return TaskInstanceCountVo.of(taskInstanceStatusCounts);
} }
/** @Override
* Wrapper function of counting process instance state and task state public WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser,
* Long projectCode,
* @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 startDate,
String endDate, String endDate) {
TriFunction<Date, Date, Long[], List<ExecuteStatusCount>> instanceStateCounter) {
if (projectCode != 0) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos = processInstanceMapper
.countWorkflowInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode));
return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos);
} }
Date start = null; @Override
Date end = null; public WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser,
if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate)) { String startDate,
start = DateUtils.stringToDate(startDate); String endDate) {
end = DateUtils.stringToDate(endDate); List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
if (Objects.isNull(start) || Objects.isNull(end)) { if (CollectionUtils.isEmpty(projectCodes)) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); return WorkflowInstanceCountVo.empty();
}
}
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
if (projectIds.getRight() != null) {
return projectIds.getRight();
}
Long[] projectCodeArray =
projectCode == 0 ? getProjectCodesArrays(projectIds.getLeft()) : new Long[]{projectCode};
List<ExecuteStatusCount> processInstanceStateCounts = new ArrayList<>();
if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) {
processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray);
} }
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
if (processInstanceStateCounts != null) { List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos =
return new TaskCountDto(processInstanceStateCounts); processInstanceMapper.countWorkflowInstanceStateByProjectCodes(start, end, projectCodes);
} return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos);
return null;
} }
/**
* statistics the process definition quantities of a certain person
* <p>
* 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 @Override
public DefineUserDto countDefinitionByUser(User loginUser, long projectCode) { public WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode) {
if (projectCode != 0) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
List<WorkflowDefinitionCountDto> workflowDefinitionCounts =
processDefinitionMapper.countDefinitionByProjectCodes(Lists.newArrayList(projectCode));
return WorkflowDefinitionCountVo.of(workflowDefinitionCounts);
} }
// todo: refactor this method, don't use Pair @Override
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser); public WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser) {
if (projectIds.getRight() != null) { List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
List<DefinitionGroupByUser> emptyList = new ArrayList<>(); if (CollectionUtils.isEmpty(projectCodes)) {
return new DefineUserDto(emptyList); return WorkflowDefinitionCountVo.empty();
}
List<DefinitionGroupByUser> 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);
} }
return WorkflowDefinitionCountVo.of(processDefinitionMapper.countDefinitionByProjectCodes(projectCodes));
return new DefineUserDto(defineGroupByUsers);
} }
/**
* statistical command status data
*
* @param loginUser login user
* @return command state count data
*/
@Override @Override
public List<CommandStateCount> countCommandState(User loginUser) { public List<CommandStateCount> countCommandState(User loginUser) {
/** List<Long> projectCodes = projectService.getAuthorizedProjectCodes(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<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
if (projectIds.getRight() != null) {
List<CommandStateCount> noData = Arrays.stream(CommandType.values())
.map(commandType -> new CommandStateCount(0, 0, commandType))
.collect(Collectors.toList());
return noData;
}
Long[] projectCodeArray = getProjectCodesArrays(projectIds.getLeft());
// count normal command state // count normal command state
Map<CommandType, Integer> normalCountCommandCounts = Map<CommandType, Integer> normalCountCommandCounts =
commandMapper.countCommandState(start, end, projectCodeArray) commandMapper.countCommandState(null, null, projectCodes)
.stream() .stream()
.collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount)); .collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount));
// count error command state // count error command state
Map<CommandType, Integer> errorCommandCounts = Map<CommandType, Integer> errorCommandCounts =
errorCommandMapper.countCommandState(start, end, projectCodeArray) errorCommandMapper.countCommandState(null, null, projectCodes)
.stream() .stream()
.collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount)); .collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount));
@ -272,24 +204,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return list; return list;
} }
private Pair<Set<Integer>, TaskCountDto> getProjectIds(User loginUser) {
Set<Integer> projectIds = resourcePermissionCheckService
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
if (projectIds.isEmpty()) {
List<ExecuteStatusCount> taskInstanceStateCounts = new ArrayList<>();
return Pair.of(null, new TaskCountDto(taskInstanceStateCounts));
}
return Pair.of(projectIds, null);
}
private Long[] getProjectCodesArrays(Set<Integer> projectIds) {
List<Project> projects = projectMapper.selectBatchIds(projectIds);
List<Long> codeList = projects.stream().map(Project::getCode).collect(Collectors.toList());
Long[] projectCodeArray = new Long[codeList.size()];
codeList.toArray(projectCodeArray);
return projectCodeArray;
}
/** /**
* count queue state * count queue state
* *
@ -306,59 +220,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return dataMap; return dataMap;
} }
@Override
public List<ExecuteStatusCount> countTaskInstanceAllStatesByProjectCodes(Date startTime, Date endTime,
Long[] projectCodes) {
Optional<List<ExecuteStatusCount>> startTimeStates = Optional.ofNullable(
this.taskInstanceMapper.countTaskInstanceStateByProjectCodes(startTime, endTime, projectCodes));
List<TaskExecutionStatus> allState = Arrays.stream(TaskExecutionStatus.values()).collect(Collectors.toList());
List<TaskExecutionStatus> needRecountState;
if (startTimeStates.isPresent() && startTimeStates.get().size() != 0) {
List<TaskExecutionStatus> 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<ExecuteStatusCount> 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<String, Object> queryAllWorkflowCounts(User loginUser) {
Map<String, Object> result = new HashMap<>();
int count = 0;
Set<Integer> projectIds = resourcePermissionCheckService
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
if (!projectIds.isEmpty()) {
List<Project> projects = projectMapper.selectBatchIds(projectIds);
List<Long> 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 * query all workflow states count
* *
@ -525,37 +386,26 @@ 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. * 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 loginUser login user
* @param projectCode project code
* @return definition count data * @return definition count data
*/ */
@Override @Override
public DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, public DefineUserDto countDefinitionByUserV2(User loginUser,
Integer userId,
Integer releaseState) { Integer releaseState) {
if (null != projectCode) { Set<Integer> projectIds = resourcePermissionCheckService
Project project = projectMapper.queryByCode(projectCode); .userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW); if (CollectionUtils.isEmpty(projectIds)) {
} return new DefineUserDto(Collections.emptyList());
List<DefinitionGroupByUser> defineGroupByUsers = new ArrayList<>();
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
if (projectIds.getRight() != null) {
List<DefinitionGroupByUser> 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);
} }
List<Long> projectCodes = projectMapper.selectBatchIds(projectIds)
.stream()
.map(Project::getCode)
.collect(Collectors.toList());
return new DefineUserDto(defineGroupByUsers); List<WorkflowDefinitionCountDto> workflowDefinitionCountDtos =
} processDefinitionMapper.countDefinitionByProjectCodesV2(projectCodes, userId, releaseState);
@Override return new DefineUserDto(workflowDefinitionCountDtos);
public Long getProjectCodeByName(String projectName) {
Project project = projectMapper.queryByName(projectName);
return project == null ? 0 : project.getCode();
} }
private List<TaskExecutionStatus> setOptional(Optional<List<ExecuteStatusCount>> startTimeStates) { private List<TaskExecutionStatus> setOptional(Optional<List<ExecuteStatusCount>> startTimeStates) {

3
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 userId,
Integer pageNo, Integer pageNo,
Integer pageSize) { Integer pageSize) {
Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_DEFINITION);
PageListingResult<ProcessDefinition> processDefinitionsPageListingResult = PageListingResult<ProcessDefinition> processDefinitionsPageListingResult =
processDefinitionDao.listingProcessDefinition( processDefinitionDao.listingProcessDefinition(

14
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) { Integer pageSize) {
Result result = new Result(); Result result = new Result();
Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE);
ApiFuncIdentificationConstant.WORKFLOW_INSTANCE);
int[] statusArray = null; int[] statusArray = null;
// filter by state // filter by state
@ -356,7 +354,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
IPage<ProcessInstance> processInstanceList = processInstanceMapper.queryProcessInstanceListPaging( IPage<ProcessInstance> processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(
page, page,
project.getCode(), projectCode,
processDefineCode, processDefineCode,
searchVal, searchVal,
executorName, executorName,
@ -685,14 +683,10 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
String taskDefinitionJson, String scheduleTime, Boolean syncDefine, String taskDefinitionJson, String scheduleTime, Boolean syncDefine,
String globalParams, String globalParams,
String locations, int timeout) { String locations, int timeout) {
Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
Map<String, Object> result = projectService.checkProjectAndAuthThrowException(loginUser, projectCode,
projectService.checkProjectAndAuth(loginUser, project, projectCode,
ApiFuncIdentificationConstant.INSTANCE_UPDATE); ApiFuncIdentificationConstant.INSTANCE_UPDATE);
if (result.get(Constants.STATUS) != Status.SUCCESS) { Map<String, Object> result = new HashMap<>();
return result;
}
// check process instance exists // check process instance exists
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId) ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId)
.orElseThrow(() -> new ServiceException(PROCESS_INSTANCE_NOT_EXIST, processInstanceId)); .orElseThrow(() -> new ServiceException(PROCESS_INSTANCE_NOT_EXIST, processInstanceId));

23
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.ProjectUserMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,6 +53,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -239,7 +241,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
} }
@Override @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); Project project = projectMapper.queryByCode(projectCode);
checkProjectAndAuthThrowException(loginUser, project, permission); checkProjectAndAuthThrowException(loginUser, project, permission);
} }
@ -834,4 +839,20 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
@Override
public List<Long> getAuthorizedProjectCodes(User loginUser) {
if (loginUser == null) {
throw new IllegalArgumentException("loginUser can not be null");
}
Set<Integer> 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());
}
} }

7
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 pageNo,
Integer pageSize) { Integer pageSize) {
Result result = new Result(); Result result = new Result();
Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, TASK_INSTANCE); projectService.checkProjectAndAuthThrowException(loginUser, projectCode, TASK_INSTANCE);
int[] statusArray = null; int[] statusArray = null;
if (stateType != null) { if (stateType != null) {
statusArray = new int[]{stateType.getCode()}; statusArray = new int[]{stateType.getCode()};
@ -160,7 +159,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
// stream task without process instance // stream task without process instance
taskInstanceIPage = taskInstanceMapper.queryStreamTaskInstanceListPaging( taskInstanceIPage = taskInstanceMapper.queryStreamTaskInstanceListPaging(
page, page,
project.getCode(), projectCode,
processDefinitionName, processDefinitionName,
searchVal, searchVal,
taskName, taskName,
@ -174,7 +173,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
} else { } else {
taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging( taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page, page,
project.getCode(), projectCode,
processInstanceId, processInstanceId,
processInstanceName, processInstanceName,
searchVal, searchVal,

66
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<TaskInstanceStatusCountDto> taskInstanceStatusCounts;
public static TaskInstanceCountVo empty() {
return of(Collections.emptyList());
}
public static TaskInstanceCountVo of(List<TaskInstanceStatusCountDto> taskInstanceStatusCounts) {
taskInstanceStatusCounts = new ArrayList<>(taskInstanceStatusCounts);
Map<TaskExecutionStatus, TaskInstanceStatusCountDto> 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;
}
}

55
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<WorkflowDefinitionCountDto> userList;
public static WorkflowDefinitionCountVo empty() {
return new WorkflowDefinitionCountVo(0, Collections.emptyList());
}
public static WorkflowDefinitionCountVo of(List<WorkflowDefinitionCountDto> workflowDefinitionCounts) {
if (CollectionUtils.isEmpty(workflowDefinitionCounts)) {
return empty();
}
WorkflowDefinitionCountVo workflowDefinitionCountVo = new WorkflowDefinitionCountVo();
workflowDefinitionCountVo.setUserList(workflowDefinitionCounts);
workflowDefinitionCountVo
.setCount(workflowDefinitionCounts.stream().mapToInt(WorkflowDefinitionCountDto::getCount).sum());
return workflowDefinitionCountVo;
}
}

66
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<WorkflowInstanceStatusCountDto> workflowInstanceStatusCounts;
public static WorkflowInstanceCountVo empty() {
return of(Collections.emptyList());
}
public static WorkflowInstanceCountVo of(List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos) {
workflowInstanceStatusCountDtos = new ArrayList<>(workflowInstanceStatusCountDtos);
Map<WorkflowExecutionStatus, WorkflowInstanceStatusCountDto> 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;
}
}

26
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.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result; 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.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; 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.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import com.fasterxml.jackson.core.type.TypeReference;
/** /**
* data analysis controller test * data analysis controller test
*/ */
@ -60,7 +64,7 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
} }
@Test @Test
public void testCountTaskState() throws Exception { public void testGetTaskInstanceStateCount() throws Exception {
int projectId = createProject(); int projectId = createProject();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
@ -73,15 +77,17 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result<TaskInstanceCountVo> result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(),
assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode()); new TypeReference<Result<TaskInstanceCountVo>>() {
logger.info(mvcResult.getResponse().getContentAsString()); });
assertThat(result.getCode())
.isNotNull()
.isEqualTo(Status.SUCCESS.getCode());
projectMapper.deleteById(projectId); projectMapper.deleteById(projectId);
} }
@Test @Test
public void testCountProcessInstanceState() throws Exception { public void testGetWorkflowInstanceStateCount() throws Exception {
int projectId = createProject(); int projectId = createProject();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
@ -95,9 +101,11 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result<WorkflowInstanceCountVo> result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(),
assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode()); new TypeReference<Result<WorkflowInstanceCountVo>>() {
logger.info(mvcResult.getResponse().getContentAsString()); });
assertThat(result.getCode())
.isEqualTo(Status.SUCCESS.getCode());
projectMapper.deleteById(projectId); projectMapper.deleteById(projectId);
} }

34
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.DefineUserDto;
import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.dto.TaskCountDto;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest; 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.service.impl.DataAnalysisServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result; 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.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
@ -50,21 +46,6 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest {
@Mock @Mock
private DataAnalysisServiceImpl dataAnalysisService; private DataAnalysisServiceImpl dataAnalysisService;
@Test
public void testQueryWorkflowInstanceCounts() {
User loginUser = getLoginUser();
int count = 0;
Map<String, Object> 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 @Test
public void testQueryWorkflowStatesCounts() { public void testQueryWorkflowStatesCounts() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
@ -121,27 +102,14 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest {
assertTrue(result1.isSuccess()); assertTrue(result1.isSuccess());
} }
@Test
public void testCountDefinitionByUser() {
User loginUser = getLoginUser();
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
List<DefinitionGroupByUser> definitionGroupByUsers = new ArrayList<>();
DefineUserDto taskCountResult = new DefineUserDto(definitionGroupByUsers);
when(dataAnalysisService.countDefinitionByUserV2(loginUser, statisticsStateRequest.getProjectCode(), null,
null)).thenReturn(taskCountResult);
assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUser(loginUser, statisticsStateRequest));
}
@Test @Test
public void testCountDefinitionByUserId() { public void testCountDefinitionByUserId() {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
Integer userId = 1; Integer userId = 1;
DefineUserDto defineUserDto = new DefineUserDto(Collections.emptyList()); 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)); assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUserId(loginUser, userId));
} }

53
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.assertDoesNotThrow;
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException; import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException;
import static org.assertj.core.api.Assertions.assertThat; 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.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
@ -27,12 +28,11 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.dto.CommandStateCount; 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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; 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.service.impl.DataAnalysisServiceImpl;
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo;
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.CommandType;
@ -77,8 +77,6 @@ import org.slf4j.LoggerFactory;
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
public class DataAnalysisServiceTest { public class DataAnalysisServiceTest {
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
private static final Logger serviceLogger = LoggerFactory.getLogger(DataAnalysisServiceImpl.class); private static final Logger serviceLogger = LoggerFactory.getLogger(DataAnalysisServiceImpl.class);
@InjectMocks @InjectMocks
@ -138,10 +136,10 @@ public class DataAnalysisServiceTest {
String endDate = "2020-02-11 16:03:18"; String endDate = "2020-02-11 16:03:18";
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
// SUCCESS // SUCCESS
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate)); assertDoesNotThrow(
() -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate, endDate));
} }
@Test @Test
@ -153,37 +151,35 @@ public class DataAnalysisServiceTest {
doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService) doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService)
.checkProjectAndAuthThrowException(any(), anyLong(), any()); .checkProjectAndAuthThrowException(any(), anyLong(), any());
assertThrowsServiceException(Status.PROJECT_NOT_FOUND, assertThrowsServiceException(Status.PROJECT_NOT_FOUND,
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate)); () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate, endDate));
} }
@Test @Test
public void testCountTaskStateByProject_paramValid() { public void testCountTaskStateByProject_paramValid() {
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
// when date in illegal format then return error message // when date in illegal format then return error message
String startDate2 = "illegalDateString"; String startDate2 = "illegalDateString";
String endDate2 = "illegalDateString"; String endDate2 = "illegalDateString";
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, assertThrows(IllegalArgumentException.class,
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate2, endDate2)); () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate2, endDate2));
// when one of date in illegal format then return error message // when one of date in illegal format then return error message
String startDate3 = "2020-08-28 14:13:40"; String startDate3 = "2020-08-28 14:13:40";
String endDate3 = "illegalDateString"; String endDate3 = "illegalDateString";
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, assertThrows(IllegalArgumentException.class,
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate3, endDate3)); () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate3, endDate3));
// when one of date in illegal format then return error message // when one of date in illegal format then return error message
String startDate4 = "illegalDateString"; String startDate4 = "illegalDateString";
String endDate4 = "2020-08-28 14:13:40"; String endDate4 = "2020-08-28 14:13:40";
assertThrowsServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, assertThrows(IllegalArgumentException.class,
() -> dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate4, endDate4)); () -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, startDate4, endDate4));
} }
@Test @Test
public void testCountTaskStateByProject_allCountZero() { public void testCountTaskStateByProject_allCountZero() {
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); 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 // when general user doesn't have any task then return all count are 0
user.setUserType(UserType.GENERAL_USER); user.setUserType(UserType.GENERAL_USER);
@ -191,25 +187,23 @@ public class DataAnalysisServiceTest {
serviceLogger)).thenReturn(projectIds()); serviceLogger)).thenReturn(projectIds());
when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())) when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any()))
.thenReturn(Collections.emptyList()); .thenReturn(Collections.emptyList());
TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); assertDoesNotThrow(() -> dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, 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));
} }
@Test @Test
public void testCountTaskStateByProject_noData() { public void testCountTaskStateByProject_noData() {
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
serviceLogger)).thenReturn(projectIds()); serviceLogger)).thenReturn(projectIds());
// when instanceStateCounter return null, then return nothing // when instanceStateCounter return null, then return nothing
user.setUserType(UserType.GENERAL_USER); user.setUserType(UserType.GENERAL_USER);
when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn(null); when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any()))
TaskCountDto taskCountDto = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); .thenReturn(Collections.emptyList());
assertThat(taskCountDto).isNull(); TaskInstanceCountVo taskInstanceStateCountByProject =
dataAnalysisServiceImpl.getTaskInstanceStateCountByProject(user, 1L, null, null);
assertThat(taskInstanceStateCountByProject).isNotNull();
} }
@Test @Test
@ -217,31 +211,30 @@ public class DataAnalysisServiceTest {
String startDate = "2020-02-11 16:02:18"; String startDate = "2020-02-11 16:02:18";
String endDate = "2020-02-11 16:03:18"; String endDate = "2020-02-11 16:03:18";
when(projectMapper.queryByCode(1L)).thenReturn(getProject("test"));
// checkProject false // checkProject false
doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService) doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, 1)).when(projectService)
.checkProjectAndAuthThrowException(any(), anyLong(), any()); .checkProjectAndAuthThrowException(any(), anyLong(), any());
assertThrowsServiceException(Status.PROJECT_NOT_FOUND, assertThrowsServiceException(Status.PROJECT_NOT_FOUND,
() -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate)); () -> dataAnalysisServiceImpl.getWorkflowInstanceStateCountByProject(user, 1L, startDate, endDate));
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any()); doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
// SUCCESS // SUCCESS
assertDoesNotThrow( assertDoesNotThrow(
() -> dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate)); () -> dataAnalysisServiceImpl.getWorkflowInstanceStateCountByProject(user, 1L, startDate, endDate));
} }
@Test @Test
public void testCountDefinitionByUser() { public void testCountDefinitionByUser() {
doNothing().when(projectService).checkProjectAndAuthThrowException(any(), anyLong(), any());
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
serviceLogger)).thenReturn(projectIds()); serviceLogger)).thenReturn(projectIds());
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0)); assertDoesNotThrow(() -> dataAnalysisServiceImpl.getWorkflowDefinitionCountByProject(user, 0L));
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1,
serviceLogger)).thenReturn(Collections.emptySet()); serviceLogger)).thenReturn(Collections.emptySet());
assertDoesNotThrow(() -> dataAnalysisServiceImpl.countDefinitionByUser(user, 0)); assertDoesNotThrow(() -> dataAnalysisServiceImpl.getWorkflowDefinitionCountByProject(user, 0L));
} }
@Test @Test

8
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/LoggerServiceTest.java

@ -101,17 +101,17 @@ public class LoggerServiceTest {
// PROJECT_NOT_EXIST // PROJECT_NOT_EXIST
taskInstance.setHost("127.0.0.1:8080"); taskInstance.setHost("127.0.0.1:8080");
taskInstance.setLogPath("/temp/log"); taskInstance.setLogPath("/temp/log");
Project project = getProject(1);
Mockito.when(projectMapper.queryProjectByTaskInstanceId(1)).thenReturn(project);
try { try {
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) 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); loggerService.queryLog(loginUser, 1, 1, 1);
} catch (ServiceException serviceException) { } catch (ServiceException serviceException) {
Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode());
} }
// USER_NO_OPERATION_PERM // USER_NO_OPERATION_PERM
Project project = getProject(1);
when(projectMapper.queryProjectByTaskInstanceId(1)).thenReturn(project);
try { try {
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PERM)).when(projectService) Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PERM)).when(projectService)
.checkProjectAndAuthThrowException(loginUser, project, VIEW_LOG); .checkProjectAndAuthThrowException(loginUser, project, VIEW_LOG);
@ -160,7 +160,7 @@ public class LoggerServiceTest {
taskInstance.setLogPath("/temp/log"); taskInstance.setLogPath("/temp/log");
try { try {
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) 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); loggerService.queryLog(loginUser, 1, 1, 1);
} catch (ServiceException serviceException) { } catch (ServiceException serviceException) {
Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode());

283
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.api.constants.ApiFuncIdentificationConstant.WORKFLOW_UPDATE;
import static org.apache.dolphinscheduler.common.constants.Constants.EMPTY_STRING; import static org.apache.dolphinscheduler.common.constants.Constants.EMPTY_STRING;
import static org.mockito.ArgumentMatchers.isA; 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.times;
import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowCreateRequest; import org.apache.dolphinscheduler.api.dto.workflow.WorkflowCreateRequest;
import org.apache.dolphinscheduler.api.dto.workflow.WorkflowFilterRequest; import org.apache.dolphinscheduler.api.dto.workflow.WorkflowFilterRequest;
@ -212,7 +215,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testQueryProcessDefinitionList() { public void testQueryProcessDefinitionList() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -220,18 +223,18 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project not found // project not found
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionList(user, projectCode); Map<String, Object> map = processDefinitionService.queryProcessDefinitionList(user, projectCode);
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS));
// project check auth success // project check auth success
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
List<ProcessDefinition> resourceList = new ArrayList<>(); List<ProcessDefinition> resourceList = new ArrayList<>();
resourceList.add(getProcessDefinition()); resourceList.add(getProcessDefinition());
Mockito.when(processDefinitionMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); when(processDefinitionMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList);
Map<String, Object> checkSuccessRes = Map<String, Object> checkSuccessRes =
processDefinitionService.queryProcessDefinitionList(user, projectCode); processDefinitionService.queryProcessDefinitionList(user, projectCode);
Assertions.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS));
@ -239,15 +242,11 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testQueryProcessDefinitionListPaging() { public void testQueryProcessDefinitionListPaging() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode);
// project not found // project not found
try { try {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(null); doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService)
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) .checkProjectAndAuthThrowException(user, projectCode, WORKFLOW_DEFINITION);
.checkProjectAndAuthThrowException(user, null, WORKFLOW_DEFINITION);
processDefinitionService.queryProcessDefinitionListPaging(user, projectCode, "", "", 1, 5, 0); processDefinitionService.queryProcessDefinitionListPaging(user, projectCode, "", "", 1, 5, 0);
} catch (ServiceException serviceException) { } catch (ServiceException serviceException) {
Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode()); Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode());
@ -256,9 +255,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
user.setId(1); user.setId(1);
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, doNothing().when(projectService).checkProjectAndAuthThrowException(user, projectCode, WORKFLOW_DEFINITION);
WORKFLOW_DEFINITION);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
long processDefinitionCode1 = 1L; long processDefinitionCode1 = 1L;
long processDefinitionCode2 = 2L; long processDefinitionCode2 = 2L;
List<ProcessDefinition> processDefinitions = Arrays.asList( List<ProcessDefinition> processDefinitions = Arrays.asList(
@ -272,15 +269,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
.pageSize(10) .pageSize(10)
.totalCount(30) .totalCount(30)
.build(); .build();
Mockito.when(processDefinitionDao.listingProcessDefinition( when(processDefinitionDao.listingProcessDefinition(
Mockito.eq(0), Mockito.eq(0),
Mockito.eq(10), Mockito.eq(10),
Mockito.eq(""), Mockito.eq(""),
Mockito.eq(1), Mockito.eq(1),
Mockito.eq(project.getCode()))).thenReturn(pageListingResult); Mockito.eq(projectCode))).thenReturn(pageListingResult);
String user1 = "user1"; String user1 = "user1";
String user2 = "user2"; String user2 = "user2";
Mockito.when(userMapper.queryUserWithProcessDefinitionCode(processDefinitionCodes)) when(userMapper.queryUserWithProcessDefinitionCode(processDefinitionCodes))
.thenReturn(Arrays.asList( .thenReturn(Arrays.asList(
UserWithProcessDefinitionCode.builder() UserWithProcessDefinitionCode.builder()
.processDefinitionCode(processDefinitionCode1) .processDefinitionCode(processDefinitionCode1)
@ -296,10 +293,16 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Schedule schedule2 = new Schedule(); Schedule schedule2 = new Schedule();
schedule2.setProcessDefinitionCode(processDefinitionCode2); schedule2.setProcessDefinitionCode(processDefinitionCode2);
schedule2.setReleaseState(ReleaseState.ONLINE); schedule2.setReleaseState(ReleaseState.ONLINE);
Mockito.when(schedulerService.queryScheduleByProcessDefinitionCodes(processDefinitionCodes)) when(schedulerService.queryScheduleByProcessDefinitionCodes(processDefinitionCodes))
.thenReturn(Arrays.asList(schedule1, schedule2)); .thenReturn(Arrays.asList(schedule1, schedule2));
PageInfo<ProcessDefinition> pageInfo = processDefinitionService.queryProcessDefinitionListPaging( PageInfo<ProcessDefinition> pageInfo = processDefinitionService.queryProcessDefinitionListPaging(
user, project.getCode(), "", "", 1, 0, 10); user,
projectCode,
"",
"",
1,
0,
10);
Assertions.assertNotNull(pageInfo); Assertions.assertNotNull(pageInfo);
ProcessDefinition pd1 = pageInfo.getTotalList().stream() ProcessDefinition pd1 = pageInfo.getTotalList().stream()
.filter(pd -> pd.getCode() == processDefinitionCode1).findFirst().orElse(null); .filter(pd -> pd.getCode() == processDefinitionCode1).findFirst().orElse(null);
@ -309,7 +312,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testQueryProcessDefinitionByCode() { public void testQueryProcessDefinitionByCode() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -317,26 +320,26 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project check auth fail // project check auth fail
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionByCode(user, 1L, 1L); Map<String, Object> map = processDefinitionService.queryProcessDefinitionByCode(user, 1L, 1L);
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); Assertions.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS));
// project check auth success, instance not exist // project check auth success, instance not exist
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
DagData dagData = new DagData(getProcessDefinition(), null, null); DagData dagData = new DagData(getProcessDefinition(), null, null);
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); when(processService.genDagData(Mockito.any())).thenReturn(dagData);
Map<String, Object> instanceNotexitRes = Map<String, Object> instanceNotexitRes =
processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 1L); processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 1L);
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
// instance exit // instance exit
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition());
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> successRes = Map<String, Object> successRes =
processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L); processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L);
@ -345,7 +348,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testQueryProcessDefinitionByName() { public void testQueryProcessDefinitionByName() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -353,7 +356,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project check auth fail // project check auth fail
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> map = Map<String, Object> map =
processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def"); processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def");
@ -361,19 +364,19 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// project check auth success, instance not exist // project check auth success, instance not exist
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); when(processDefinitionMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null);
Map<String, Object> instanceNotExitRes = Map<String, Object> instanceNotExitRes =
processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def"); processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test_def");
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS));
// instance exit // instance exit
Mockito.when(processDefinitionMapper.queryByDefineName(project.getCode(), "test")) when(processDefinitionMapper.queryByDefineName(project.getCode(), "test"))
.thenReturn(getProcessDefinition()); .thenReturn(getProcessDefinition());
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> successRes = Map<String, Object> successRes =
processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test"); processDefinitionService.queryProcessDefinitionByName(user, projectCode, "test");
@ -384,7 +387,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
public void testBatchCopyProcessDefinition() { public void testBatchCopyProcessDefinition() {
Project project = getProject(projectCode); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.doReturn(result) Mockito.doReturn(result)
@ -398,7 +401,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// project check auth fail // project check auth fail
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); 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); .thenReturn(result);
Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition( Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition(
user, projectCode, String.valueOf(project.getId()), 2L); 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 check auth success, target project name not equal project name, check auth target project fail
Project project1 = getProject(projectCodeOther); Project project1 = getProject(projectCodeOther);
Mockito.when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project1); when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project1);
Mockito.doReturn(result) Mockito.doReturn(result)
.when(projectService) .when(projectService)
.checkProjectAndAuth(user, project1, projectCodeOther, WORKFLOW_BATCH_COPY); .checkProjectAndAuth(user, project1, projectCodeOther, WORKFLOW_BATCH_COPY);
@ -425,8 +428,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.fail(); Assertions.fail();
} }
} }
Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Mockito.when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2);
Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition( Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition(
user, projectCodeOther, String.valueOf(processDefinitionCode), projectCode); user, projectCodeOther, String.valueOf(processDefinitionCode), projectCode);
Assertions.assertEquals(Status.SUCCESS, map3.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, map3.get(Constants.STATUS));
@ -435,17 +438,17 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testBatchMoveProcessDefinition() { public void testBatchMoveProcessDefinition() {
Project project1 = getProject(projectCode); Project project1 = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); when(projectMapper.queryByCode(projectCode)).thenReturn(project1);
Project project2 = getProject(projectCodeOther); Project project2 = getProject(projectCodeOther);
Mockito.when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project2); when(projectMapper.queryByCode(projectCodeOther)).thenReturn(project2);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); 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); .thenReturn(result);
Mockito.when(projectService.checkProjectAndAuth(user, project2, projectCodeOther, TASK_DEFINITION_MOVE)) when(projectService.checkProjectAndAuth(user, project2, projectCodeOther, TASK_DEFINITION_MOVE))
.thenReturn(result); .thenReturn(result);
ProcessDefinition definition = getProcessDefinition(); ProcessDefinition definition = getProcessDefinition();
@ -462,9 +465,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.fail(); Assertions.fail();
} }
} }
Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Mockito.when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); when(processService.saveProcessDefine(user, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2);
Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode)) when(processTaskRelationMapper.queryByProcessCode(projectCode, processDefinitionCode))
.thenReturn(getProcessTaskRelation()); .thenReturn(getProcessTaskRelation());
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -475,8 +478,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void deleteProcessDefinitionByCodeTest() { public void deleteProcessDefinitionByCodeTest() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(46L); doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(46L);
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -486,24 +489,24 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode());
// project check auth fail // project check auth fail
Mockito.when(processDefinitionDao.queryByCode(6L)).thenReturn(Optional.of(getProcessDefinition())); when(processDefinitionDao.queryByCode(6L)).thenReturn(Optional.of(getProcessDefinition()));
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_FOUND)).when(projectService) doThrow(new ServiceException(Status.PROJECT_NOT_FOUND)).when(projectService)
.checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION_DELETE); .checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION_DELETE);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 6L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 6L));
Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode());
// project check auth success, instance not exist // project check auth success, instance not exist
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, doNothing().when(projectService).checkProjectAndAuthThrowException(user, project,
WORKFLOW_DEFINITION_DELETE); WORKFLOW_DEFINITION_DELETE);
Mockito.when(processDefinitionDao.queryByCode(1L)).thenReturn(Optional.empty()); when(processDefinitionDao.queryByCode(1L)).thenReturn(Optional.empty());
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 1L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 1L));
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode());
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
// user no auth // 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, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L));
Assertions.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), ((ServiceException) exception).getCode());
@ -511,17 +514,17 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// process definition online // process definition online
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
processDefinition.setReleaseState(ReleaseState.ONLINE); 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, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L));
Assertions.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE.getCode(), ((ServiceException) exception).getCode());
// scheduler list elements > 1 // scheduler list elements > 1
processDefinition.setReleaseState(ReleaseState.OFFLINE); processDefinition.setReleaseState(ReleaseState.OFFLINE);
Mockito.when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition)); when(processDefinitionDao.queryByCode(46L)).thenReturn(Optional.of(processDefinition));
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule());
Mockito.when(scheduleMapper.deleteById(46)).thenReturn(1); when(scheduleMapper.deleteById(46)).thenReturn(1);
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode()))
.thenReturn(Collections.emptySet()); .thenReturn(Collections.emptySet());
processDefinitionService.deleteProcessDefinitionByCode(user, 46L); processDefinitionService.deleteProcessDefinitionByCode(user, 46L);
Mockito.verify(metricsCleanUpService, times(1)).cleanUpWorkflowMetricsByDefinitionCode(46L); Mockito.verify(metricsCleanUpService, times(1)).cleanUpWorkflowMetricsByDefinitionCode(46L);
@ -529,7 +532,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// scheduler online // scheduler online
Schedule schedule = getSchedule(); Schedule schedule = getSchedule();
schedule.setReleaseState(ReleaseState.ONLINE); schedule.setReleaseState(ReleaseState.ONLINE);
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedule); when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedule);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L));
Assertions.assertEquals(Status.SCHEDULE_STATE_ONLINE.getCode(), ((ServiceException) exception).getCode()); 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 // process used by other task, sub process
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
TaskMainInfo taskMainInfo = getTaskMainInfo().get(0); TaskMainInfo taskMainInfo = getTaskMainInfo().get(0);
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode()))
.thenReturn(ImmutableSet.copyOf(getTaskMainInfo())); .thenReturn(ImmutableSet.copyOf(getTaskMainInfo()));
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); () -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L));
@ -546,9 +549,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// delete success // delete success
schedule.setReleaseState(ReleaseState.OFFLINE); schedule.setReleaseState(ReleaseState.OFFLINE);
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule());
Mockito.when(scheduleMapper.deleteById(schedule.getId())).thenReturn(1); when(scheduleMapper.deleteById(schedule.getId())).thenReturn(1);
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode()))
.thenReturn(Collections.emptySet()); .thenReturn(Collections.emptySet());
Assertions.assertDoesNotThrow(() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L)); Assertions.assertDoesNotThrow(() -> processDefinitionService.deleteProcessDefinitionByCode(user, 46L));
Mockito.verify(metricsCleanUpService, times(2)).cleanUpWorkflowMetricsByDefinitionCode(46L); Mockito.verify(metricsCleanUpService, times(2)).cleanUpWorkflowMetricsByDefinitionCode(46L);
@ -556,7 +559,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void batchDeleteProcessDefinitionByCodeTest() { public void batchDeleteProcessDefinitionByCodeTest() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -567,7 +570,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
ProcessDefinition process = getProcessDefinition(); ProcessDefinition process = getProcessDefinition();
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
processDefinitionList.add(process); processDefinitionList.add(process);
Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Throwable exception = Assertions.assertThrows(ServiceException.class, Throwable exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, twoCodes)); () -> processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, twoCodes));
String formatter = MessageFormat.format(Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR.getMsg(), 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"; final String singleCodes = "11";
definitionCodes = Lists.newArrayList(singleCodes.split(Constants.COMMA)).stream().map(Long::parseLong) definitionCodes = Lists.newArrayList(singleCodes.split(Constants.COMMA)).stream().map(Long::parseLong)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Mockito.when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Mockito.when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process));
// process definition online // process definition online
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
@ -596,11 +599,11 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// delete success // delete success
process.setReleaseState(ReleaseState.OFFLINE); process.setReleaseState(ReleaseState.OFFLINE);
Mockito.when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process)); when(processDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(process));
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), process.getCode())) when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), process.getCode()))
.thenReturn(Collections.emptySet()); .thenReturn(Collections.emptySet());
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(11L); doNothing().when(metricsCleanUpService).cleanUpWorkflowMetricsByDefinitionCode(11L);
Map<String, Object> deleteSuccess = Map<String, Object> deleteSuccess =
processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, singleCodes); processDefinitionService.batchDeleteProcessDefinitionByCodes(user, projectCode, singleCodes);
Assertions.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS));
@ -609,14 +612,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testReleaseProcessDefinition() { public void testReleaseProcessDefinition() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
// project check auth fail // project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); 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); .thenReturn(result);
Map<String, Object> map = processDefinitionService.releaseProcessDefinition(user, projectCode, Map<String, Object> map = processDefinitionService.releaseProcessDefinition(user, projectCode,
processDefinitionCode, ReleaseState.OFFLINE); processDefinitionCode, ReleaseState.OFFLINE);
@ -624,14 +627,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// project check auth success, processes definition online // project check auth success, processes definition online
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); when(processDefinitionMapper.queryByCode(46L)).thenReturn(getProcessDefinition());
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>();
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
processTaskRelation.setProjectCode(projectCode); processTaskRelation.setProjectCode(projectCode);
processTaskRelation.setProcessDefinitionCode(46L); processTaskRelation.setProcessDefinitionCode(46L);
processTaskRelation.setPostTaskCode(123L); processTaskRelation.setPostTaskCode(123L);
processTaskRelationList.add(processTaskRelation); processTaskRelationList.add(processTaskRelation);
Mockito.when(processService.findRelationByCode(46L, 1)).thenReturn(processTaskRelationList); when(processService.findRelationByCode(46L, 1)).thenReturn(processTaskRelationList);
Map<String, Object> onlineRes = Map<String, Object> onlineRes =
processDefinitionService.releaseProcessDefinition(user, projectCode, 46, ReleaseState.ONLINE); processDefinitionService.releaseProcessDefinition(user, projectCode, 46, ReleaseState.ONLINE);
Assertions.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS));
@ -649,13 +652,13 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testVerifyProcessDefinitionName() { public void testVerifyProcessDefinitionName() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
// project check auth fail // project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); 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); .thenReturn(result);
Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(user, Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(user,
projectCode, "test_pdf", 0); projectCode, "test_pdf", 0);
@ -663,13 +666,13 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// project check auth success, process not exist // project check auth success, process not exist
putMsg(result, Status.SUCCESS, projectCode); 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<String, Object> processNotExistRes = Map<String, Object> processNotExistRes =
processDefinitionService.verifyProcessDefinitionName(user, projectCode, "test_pdf", 0); processDefinitionService.verifyProcessDefinitionName(user, projectCode, "test_pdf", 0);
Assertions.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
// process exist // process exist
Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf")) when(processDefinitionMapper.verifyByDefineName(project.getCode(), "test_pdf"))
.thenReturn(getProcessDefinition()); .thenReturn(getProcessDefinition());
Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(user, Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(user,
projectCode, "test_pdf", 0); projectCode, "test_pdf", 0);
@ -690,15 +693,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testGetTaskNodeListByDefinitionCode() { public void testGetTaskNodeListByDefinitionCode() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
// project check auth fail // project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); 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 // process definition not exist
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(null); when(processDefinitionMapper.queryByCode(46L)).thenReturn(null);
Map<String, Object> processDefinitionNullRes = Map<String, Object> processDefinitionNullRes =
processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L); processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L);
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS));
@ -706,8 +709,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// success // success
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null));
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition);
Map<String, Object> dataNotValidRes = Map<String, Object> dataNotValidRes =
processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L); processDefinitionService.getTaskNodeListByDefinitionCode(user, projectCode, 46L);
Assertions.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS));
@ -715,18 +718,18 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testGetTaskNodeListByDefinitionCodes() { public void testGetTaskNodeListByDefinitionCodes() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
// project check auth fail // project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); 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 // process definition not exist
String defineCodes = "46"; String defineCodes = "46";
Set<Long> defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong) Set<Long> defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Mockito.when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(null); when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(null);
Map<String, Object> processNotExistRes = Map<String, Object> processNotExistRes =
processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes); processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes);
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processNotExistRes.get(Constants.STATUS)); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processNotExistRes.get(Constants.STATUS));
@ -736,12 +739,12 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
processDefinitionList.add(processDefinition); processDefinitionList.add(processDefinition);
Mockito.when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryByCodes(defineCodeSet)).thenReturn(processDefinitionList);
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null));
Project project1 = getProject(projectCode); Project project1 = getProject(projectCode);
List<Project> projects = new ArrayList<>(); List<Project> projects = new ArrayList<>();
projects.add(project1); projects.add(project1);
Mockito.when(projectMapper.queryProjectCreatedAndAuthorizedByUserId(user.getId())).thenReturn(projects); when(projectMapper.queryProjectCreatedAndAuthorizedByUserId(user.getId())).thenReturn(projects);
Map<String, Object> successRes = Map<String, Object> successRes =
processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes); processDefinitionService.getNodeListMapByDefinitionCodes(user, projectCode, defineCodes);
@ -752,14 +755,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
public void testQueryAllProcessDefinitionByProjectCode() { public void testQueryAllProcessDefinitionByProjectCode() {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Project project = getProject(projectCode); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
processDefinitionList.add(processDefinition); processDefinitionList.add(processDefinition);
Mockito.when(processDefinitionMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList); when(processDefinitionMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList);
Map<String, Object> successRes = Map<String, Object> successRes =
processDefinitionService.queryAllProcessDefinitionByProjectCode(user, projectCode); processDefinitionService.queryAllProcessDefinitionByProjectCode(user, projectCode);
Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
@ -770,8 +773,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Project project1 = getProject(projectCode); Project project1 = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); when(projectMapper.queryByCode(1)).thenReturn(project1);
Mockito.when(projectService.checkProjectAndAuth(user, project1, projectCode, WORKFLOW_TREE_VIEW)) when(projectService.checkProjectAndAuth(user, project1, projectCode, WORKFLOW_TREE_VIEW))
.thenReturn(result); .thenReturn(result);
// process definition not exist // process definition not exist
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
@ -781,10 +784,10 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// task instance not existproject // task instance not existproject
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); when(projectMapper.queryByCode(1)).thenReturn(project1);
Mockito.when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result);
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition);
Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>());
Map<String, Object> taskNullRes = Map<String, Object> taskNullRes =
processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10); processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10);
Assertions.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS));
@ -798,14 +801,14 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testSubProcessViewTree() { public void testSubProcessViewTree() {
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
Mockito.when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(46L)).thenReturn(processDefinition);
Project project1 = getProject(1); Project project1 = getProject(1);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, Status.SUCCESS); result.put(Constants.STATUS, Status.SUCCESS);
Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); when(projectMapper.queryByCode(1)).thenReturn(project1);
Mockito.when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); when(projectService.checkProjectAndAuth(user, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result);
Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>());
Map<String, Object> taskNotNuLLRes = Map<String, Object> taskNotNuLLRes =
processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10); processDefinitionService.viewTree(user, processDefinition.getProjectCode(), 46, 10);
Assertions.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS));
@ -816,8 +819,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Project project = getProject(projectCode); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true); when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true);
try { try {
processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1, processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1,
@ -835,16 +838,16 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUND); 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); processDefinitionService.batchExportProcessDefinitionByCodes(user, projectCode, "1", null);
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setId(1); processDefinition.setId(1);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class); HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
DagData dagData = new DagData(getProcessDefinition(), null, null); 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); processDefinitionService.batchExportProcessDefinitionByCodes(user, projectCode, "1", response);
Assertions.assertNotNull(processDefinitionService.exportProcessDagData(processDefinition)); Assertions.assertNotNull(processDefinitionService.exportProcessDagData(processDefinition));
} }
@ -869,22 +872,22 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
new MockMultipartFile("import_sql.zip", byteArrayOutputStream.toByteArray()); new MockMultipartFile("import_sql.zip", byteArrayOutputStream.toByteArray());
DataSource dataSource = Mockito.mock(DataSource.class); DataSource dataSource = Mockito.mock(DataSource.class);
Mockito.when(dataSource.getId()).thenReturn(1); when(dataSource.getId()).thenReturn(1);
Mockito.when(dataSource.getType()).thenReturn(DbType.MYSQL); 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); Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, Status.SUCCESS); result.put(Constants.STATUS, Status.SUCCESS);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_IMPORT)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_IMPORT))
.thenReturn(result); .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.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.anyBoolean())).thenReturn(1);
Mockito.when( when(
processService.saveTaskRelation(Mockito.same(user), Mockito.eq(projectCode), Mockito.anyLong(), processService.saveTaskRelation(Mockito.same(user), Mockito.eq(projectCode), Mockito.anyLong(),
Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())) Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean()))
.thenReturn(0); .thenReturn(0);
@ -920,8 +923,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), ((ServiceException) exception).getCode());
// project permission error // project permission error
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService)
.checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); .checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest));
@ -930,7 +933,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// description too long // description too long
workflowCreateRequest.setDescription(taskDefinitionJson); 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); .checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest));
@ -938,15 +941,15 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
workflowCreateRequest.setDescription(EMPTY_STRING); workflowCreateRequest.setDescription(EMPTY_STRING);
// duplicate process definition name // duplicate process definition name
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE);
Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)) when(processDefinitionMapper.verifyByDefineName(project.getCode(), name))
.thenReturn(this.getProcessDefinition()); .thenReturn(this.getProcessDefinition());
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest));
Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(),
((ServiceException) exception).getCode()); ((ServiceException) exception).getCode());
Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null); when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null);
// test success // test success
workflowCreateRequest.setDescription(description); workflowCreateRequest.setDescription(description);
@ -954,8 +957,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
workflowCreateRequest.setReleaseState(releaseState); workflowCreateRequest.setReleaseState(releaseState);
workflowCreateRequest.setWarningGroupId(warningGroupId); workflowCreateRequest.setWarningGroupId(warningGroupId);
workflowCreateRequest.setExecutionType(executionType); workflowCreateRequest.setExecutionType(executionType);
Mockito.when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1);
Mockito.when(processDefinitionMapper.insert(Mockito.any())).thenReturn(1); when(processDefinitionMapper.insert(Mockito.any())).thenReturn(1);
ProcessDefinition processDefinition = ProcessDefinition processDefinition =
processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest); processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest);
@ -976,8 +979,8 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
workflowFilterRequest.setProjectName(project.getName()); workflowFilterRequest.setProjectName(project.getName());
// project permission error // project permission error
Mockito.when(projectMapper.queryByName(project.getName())).thenReturn(project); when(projectMapper.queryByName(project.getName())).thenReturn(project);
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode))
.when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION); .when(projectService).checkProjectAndAuthThrowException(user, project, WORKFLOW_DEFINITION);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
() -> processDefinitionService.filterProcessDefinition(user, workflowFilterRequest)); () -> processDefinitionService.filterProcessDefinition(user, workflowFilterRequest));
@ -993,10 +996,10 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode());
// project permission error // project permission error
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)) when(processDefinitionMapper.queryByCode(processDefinitionCode))
.thenReturn(this.getProcessDefinition()); .thenReturn(this.getProcessDefinition());
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode));
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode))
.when(projectService) .when(projectService)
.checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION); .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
@ -1005,7 +1008,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
((ServiceException) exception).getCode()); ((ServiceException) exception).getCode());
// success // success
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode), doNothing().when(projectService).checkProjectAndAuthThrowException(user, this.getProject(projectCode),
WORKFLOW_DEFINITION); WORKFLOW_DEFINITION);
ProcessDefinition processDefinition = ProcessDefinition processDefinition =
processDefinitionService.getProcessDefinition(user, processDefinitionCode); processDefinitionService.getProcessDefinition(user, processDefinitionCode);
@ -1027,7 +1030,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// error old process definition in release state // error old process definition in release state
processDefinition = this.getProcessDefinition(); processDefinition = this.getProcessDefinition();
processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setReleaseState(ReleaseState.ONLINE);
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService
.updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest));
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_ALLOWED_EDIT.getCode(), Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_ALLOWED_EDIT.getCode(),
@ -1035,9 +1038,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// error project permission // error project permission
processDefinition = this.getProcessDefinition(); processDefinition = this.getProcessDefinition();
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(this.getProject(projectCode));
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode)) doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode))
.when(projectService) .when(projectService)
.checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION); .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_DEFINITION);
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,
@ -1047,7 +1050,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
// error description too long // error description too long
workflowUpdateRequest.setDescription(taskDefinitionJson); 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); .checkProjectAndAuthThrowException(user, this.getProject(projectCode), WORKFLOW_UPDATE);
exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService
.updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest));
@ -1055,31 +1058,31 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
workflowUpdateRequest.setDescription(EMPTY_STRING); workflowUpdateRequest.setDescription(EMPTY_STRING);
// error new definition name already exists // 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); WORKFLOW_UPDATE);
Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName()))
.thenReturn(this.getProcessDefinition()); .thenReturn(this.getProcessDefinition());
exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService
.updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest));
Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(),
((ServiceException) exception).getCode()); ((ServiceException) exception).getCode());
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName()))
.thenReturn(null); .thenReturn(null);
// error update process definition mapper // error update process definition mapper
workflowUpdateRequest.setName(name); workflowUpdateRequest.setName(name);
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
Mockito.when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); when(processDefinitionLogMapper.insert(Mockito.any())).thenReturn(1);
exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService
.updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest));
Assertions.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR.getCode(), Assertions.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR.getCode(),
((ServiceException) exception).getCode()); ((ServiceException) exception).getCode());
// success // success
Mockito.when(processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode())) when(processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode()))
.thenReturn(processDefinition.getVersion()); .thenReturn(processDefinition.getVersion());
Mockito.when(processDefinitionMapper.updateById(isA(ProcessDefinition.class))).thenReturn(1); when(processDefinitionMapper.updateById(isA(ProcessDefinition.class))).thenReturn(1);
ProcessDefinition processDefinitionUpdate = ProcessDefinition processDefinitionUpdate =
processDefinitionService.updateSingleProcessDefinition(user, processDefinitionCode, processDefinitionService.updateSingleProcessDefinition(user, processDefinitionCode,
workflowUpdateRequest); workflowUpdateRequest);
@ -1098,7 +1101,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testViewVariables() { public void testViewVariables() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectCode); Project project = getProject(projectCode);
@ -1108,7 +1111,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project check auth fail // project check auth fail
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Map<String, Object> map = Map<String, Object> map =

73
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_DELETE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.INSTANCE_UPDATE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.INSTANCE_UPDATE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_INSTANCE; 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.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
@ -192,13 +195,23 @@ public class ProcessInstanceServiceTest {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project auth fail // project auth fail
when(projectMapper.queryByCode(projectCode)).thenReturn(null); doThrow(new ServiceException())
Mockito.doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(Mockito.any(), .when(projectService)
Mockito.any(), Mockito.any()); .checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE);
Assertions.assertThrows(ServiceException.class, () -> { assertThrows(ServiceException.class, () -> {
processInstanceService.queryProcessInstanceList(loginUser, projectCode, 46, "2020-01-01 00:00:00", processInstanceService.queryProcessInstanceList(
"2020-01-02 00:00:00", "", "test_user", WorkflowExecutionStatus.SUBMITTED_SUCCESS, loginUser,
"192.168.xx.xx", "", 1, 10); 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"); Date start = DateUtils.stringToDate("2020-01-01 00:00:00");
@ -212,13 +225,14 @@ public class ProcessInstanceServiceTest {
// data parameter check // data parameter check
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByCode(projectCode)).thenReturn(project); 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()); Mockito.any());
when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition()); when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition());
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), Mockito.any(), Mockito.any(), when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn);
Assertions.assertThrows(ServiceException.class, () -> processInstanceService.queryProcessInstanceList( assertThrows(ServiceException.class, () -> processInstanceService.queryProcessInstanceList(
loginUser, loginUser,
projectCode, projectCode,
1, 1,
@ -235,13 +249,20 @@ public class ProcessInstanceServiceTest {
// project auth success // project auth success
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByCode(projectCode)).thenReturn(project); doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE);
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result);
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId());
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), when(processInstanceMapper.queryProcessInstanceListPaging(
eq(1L), eq(""), eq(""), Mockito.any(), Mockito.any(Page.class),
eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); 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); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser);
Result successRes = Result successRes =
@ -554,18 +575,22 @@ public class ProcessInstanceServiceTest {
// project auth fail // project auth fail
when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); doThrow(new ServiceException(Status.PROJECT_NOT_FOUND, projectCode))
Map<String, Object> projectAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, .when(projectService)
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0); .checkProjectAndAuthThrowException(loginUser, projectCode, INSTANCE_UPDATE);
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, projectAuthFailRes.get(Constants.STATUS)); Assertions.assertThrows(ServiceException.class,
() -> processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0));
// process instance null // process instance null
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
when(projectMapper.queryByCode(projectCode)).thenReturn(project); 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()); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty());
Assertions.assertThrows(ServiceException.class, () -> { assertThrows(ServiceException.class, () -> {
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0); shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0);
}); });
@ -637,7 +662,7 @@ public class ProcessInstanceServiceTest {
when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result);
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty());
Assertions.assertThrows(ServiceException.class, () -> { assertThrows(ServiceException.class, () -> {
processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
}); });
@ -678,7 +703,7 @@ public class ProcessInstanceServiceTest {
when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE)).thenReturn(result);
Assertions.assertThrows(ServiceException.class, assertThrows(ServiceException.class,
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); () -> processInstanceService.deleteProcessInstanceById(loginUser, 1));
// not sub process // not sub process
@ -689,7 +714,7 @@ public class ProcessInstanceServiceTest {
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance));
when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())) when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion(Mockito.anyLong(), Mockito.anyInt()))
.thenReturn(new ProcessDefinitionLog()); .thenReturn(new ProcessDefinitionLog());
Assertions.assertThrows(ServiceException.class, assertThrows(ServiceException.class,
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); () -> processInstanceService.deleteProcessInstanceById(loginUser, 1));
processInstance.setState(WorkflowExecutionStatus.SUCCESS); processInstance.setState(WorkflowExecutionStatus.SUCCESS);
@ -704,7 +729,7 @@ public class ProcessInstanceServiceTest {
processDefinition.setProjectCode(0L); processDefinition.setProjectCode(0L);
when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition);
when(processService.findProcessInstanceDetailById(Mockito.anyInt())).thenReturn(Optional.empty()); when(processService.findProcessInstanceDetailById(Mockito.anyInt())).thenReturn(Optional.empty());
Assertions.assertThrows(ServiceException.class, assertThrows(ServiceException.class,
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); () -> processInstanceService.deleteProcessInstanceById(loginUser, 1));
processDefinition.setProjectCode(projectCode); processDefinition.setProjectCode(projectCode);

30
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.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_INSTANCE;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; 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 static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.ApiApplicationServer; import org.apache.dolphinscheduler.api.ApiApplicationServer;
@ -108,9 +110,8 @@ public class TaskInstanceServiceTest {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
// project auth fail // project auth fail
when(projectMapper.queryByCode(projectCode)).thenReturn(null); doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode,
Mockito.doThrow(new ServiceException()).when(projectService).checkProjectAndAuthThrowException(Mockito.any(), TASK_INSTANCE);
Mockito.any(), Mockito.any());
Assertions.assertThrows(ServiceException.class, () -> taskInstanceService.queryTaskListPaging(loginUser, Assertions.assertThrows(ServiceException.class, () -> taskInstanceService.queryTaskListPaging(loginUser,
projectCode, projectCode,
0, 0,
@ -159,9 +160,7 @@ public class TaskInstanceServiceTest {
Page<TaskInstance> pageReturn = new Page<>(1, 10); Page<TaskInstance> pageReturn = new Page<>(1, 10);
taskInstanceList.add(taskInstance); taskInstanceList.add(taskInstance);
pageReturn.setRecords(taskInstanceList); pageReturn.setRecords(taskInstanceList);
when(projectMapper.queryByCode(projectCode)).thenReturn(project); doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, TASK_INSTANCE);
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(Mockito.any(), Mockito.any(),
Mockito.any());
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId());
when(taskInstanceMapper.queryTaskInstanceListPaging( when(taskInstanceMapper.queryTaskInstanceListPaging(
@ -183,9 +182,22 @@ public class TaskInstanceServiceTest {
when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())) when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId()))
.thenReturn(Optional.of(processInstance)); .thenReturn(Optional.of(processInstance));
Result successRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "", Result successRes = taskInstanceService.queryTaskListPaging(loginUser,
null, "test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", TaskExecutionStatus.SUCCESS, projectCode,
"192.168.xx.xx", TaskExecuteType.BATCH, 1, 20); 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()); Assertions.assertEquals(Status.SUCCESS.getCode(), (int) successRes.getCode());
// executor name empty // executor name empty

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/CommandMapper.java

@ -36,13 +36,13 @@ public interface CommandMapper extends BaseMapper<Command> {
* count command state * count command state
* @param startTime startTime * @param startTime startTime
* @param endTime endTime * @param endTime endTime
* @param projectCodeArray projectCodeArray * @param projectCodes projectCodes
* @return CommandCount list * @return CommandCount list
*/ */
List<CommandCount> countCommandState( List<CommandCount> countCommandState(
@Param("startTime") Date startTime, @Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodeArray") Long[] projectCodeArray); @Param("projectCodes") List<Long> projectCodes);
/** /**
* query command page * query command page

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapper.java

@ -36,11 +36,11 @@ public interface ErrorCommandMapper extends BaseMapper<ErrorCommand> {
* count command state * count command state
* @param startTime startTime * @param startTime startTime
* @param endTime endTime * @param endTime endTime
* @param projectCodeArray projectCodeArray * @param projectCodes projectCodes
* @return CommandCount list * @return CommandCount list
*/ */
List<CommandCount> countCommandState( List<CommandCount> countCommandState(
@Param("startTime") Date startTime, @Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodeArray") Long[] projectCodeArray); @Param("projectCodes") List<Long> projectCodes);
} }

6
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java

@ -17,9 +17,9 @@
package org.apache.dolphinscheduler.dao.mapper; 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.DependentSimplifyDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; 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.MapKey;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -158,7 +158,7 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @param projectCodes projectCodes * @param projectCodes projectCodes
* @return definition group by user * @return definition group by user
*/ */
List<DefinitionGroupByUser> countDefinitionByProjectCodes(@Param("projectCodes") Long[] projectCodes); List<WorkflowDefinitionCountDto> countDefinitionByProjectCodes(@Param("projectCodes") Collection<Long> projectCodes);
/** /**
* Statistics process definition group by project codes list * Statistics process definition group by project codes list
@ -170,7 +170,7 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @param releaseState releaseState * @param releaseState releaseState
* @return definition group by user * @return definition group by user
*/ */
List<DefinitionGroupByUser> countDefinitionByProjectCodesV2(@Param("projectCodes") Long[] projectCodes, List<WorkflowDefinitionCountDto> countDefinitionByProjectCodesV2(@Param("projectCodes") List<Long> projectCodes,
@Param("userId") Integer userId, @Param("userId") Integer userId,
@Param("releaseState") Integer releaseState); @Param("releaseState") Integer releaseState);

6
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.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -168,10 +170,10 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
* @param projectCodes projectCodes * @param projectCodes projectCodes
* @return ExecuteStatusCount list * @return ExecuteStatusCount list
*/ */
List<ExecuteStatusCount> countInstanceStateByProjectCodes( List<WorkflowInstanceStatusCountDto> countWorkflowInstanceStateByProjectCodes(
@Param("startTime") Date startTime, @Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes); @Param("projectCodes") Collection<Long> projectCodes);
/** /**
* query process instance by processDefinitionCode * query process instance by processDefinitionCode

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java

@ -18,10 +18,10 @@
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType; 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.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; 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.MapKey;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -72,7 +72,7 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
* @param projectCodes projectCodes * @param projectCodes projectCodes
* @return task definition list * @return task definition list
*/ */
List<DefinitionGroupByUser> countDefinitionGroupByUser(@Param("projectCodes") Long[] projectCodes); List<WorkflowDefinitionCountDto> countDefinitionGroupByUser(@Param("projectCodes") Long[] projectCodes);
/** /**
* list all resource ids and task_params containing resourceList * list all resource ids and task_params containing resourceList

6
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.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -77,9 +79,9 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
* @param projectCodes Project codes list to filter * @param projectCodes Project codes list to filter
* @return List of ExecuteStatusCount * @return List of ExecuteStatusCount
*/ */
List<ExecuteStatusCount> countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime, List<TaskInstanceStatusCountDto> countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes); @Param("projectCodes") Collection<Long> projectCodes);
/** /**
* Statistics task instance group by given project ids list by start time * Statistics task instance group by given project ids list by start time

34
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;
}

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java → dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/model/WorkflowDefinitionCountDto.java

@ -15,28 +15,20 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.dao.entity; package org.apache.dolphinscheduler.dao.model;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/**
* count definition number group by user
*/
@Data @Data
public class DefinitionGroupByUser { @NoArgsConstructor
@AllArgsConstructor
public class WorkflowDefinitionCountDto {
/**
* user name
*/
private String userName; private String userName;
/**
* user id
*/
private Integer userId; private Integer userId;
/**
* count number
*/
private int count; private int count;
} }

35
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;
}

4
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 select cmd.command_type as command_type, count(1) as count
from t_ds_command cmd, t_ds_process_definition process from t_ds_command cmd, t_ds_process_definition process
where cmd.process_definition_code = process.code where cmd.process_definition_code = process.code
<if test="projectCodeArray != null and projectCodeArray.length != 0"> <if test="projectCodes != null and projectCodes.size() != 0">
and process.project_code in and process.project_code in
<foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=","> <foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i} #{i}
</foreach> </foreach>
</if> </if>

4
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 select cmd.command_type as command_type, count(1) as count
from t_ds_error_command cmd, t_ds_process_definition process from t_ds_error_command cmd, t_ds_process_definition process
where cmd.process_definition_code = process.code where cmd.process_definition_code = process.code
<if test="projectCodeArray != null and projectCodeArray.length != 0"> <if test="projectCodes != null and projectCodes.size() != 0">
and process.project_code in and process.project_code in
<foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=","> <foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i} #{i}
</foreach> </foreach>
</if> </if>

13
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -131,24 +131,27 @@
#{i} #{i}
</foreach> </foreach>
</select> </select>
<select id="countDefinitionByProjectCodes" resultType="org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser">
SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count <select id="countDefinitionByProjectCodes" resultType="org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto">
SELECT user_id as user_id, tu.user_name as user_name, count(0) as count
FROM t_ds_process_definition td FROM t_ds_process_definition td
JOIN t_ds_user tu on tu.id=td.user_id JOIN t_ds_user tu on tu.id=td.user_id
where 1 = 1 where 1 = 1
<if test="projectCodes != null and projectCodes.length != 0"> <if test="projectCodes != null and projectCodes.size() != 0">
and td.project_code in and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
</if> </if>
group by td.user_id,tu.user_name group by td.user_id,tu.user_name
</select><select id="countDefinitionByProjectCodesV2" resultType="org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser"> </select>
<select id="countDefinitionByProjectCodesV2" resultType="org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto">
SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count
FROM t_ds_process_definition td FROM t_ds_process_definition td
JOIN t_ds_user tu on tu.id=td.user_id JOIN t_ds_user tu on tu.id=td.user_id
where 1 = 1 where 1 = 1
<if test="projectCodes != null and projectCodes.length != 0"> <if test="projectCodes != null and projectCodes.size() != 0">
and td.project_code in and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}

24
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml

@ -170,23 +170,25 @@
where worker_group = #{originWorkerGroupName} where worker_group = #{originWorkerGroupName}
</update> </update>
<select id="countInstanceStateByProjectCodes" <select id="countWorkflowInstanceStateByProjectCodes" resultType="org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto">
resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount"> select state, count(0) as count
select t.state, count(0) as count from t_ds_process_instance
from t_ds_process_instance t where is_sub_process = 0
join t_ds_process_definition d on d.code=t.process_definition_code <if test="startTime != null">
where t.is_sub_process = 0 and start_time <![CDATA[ >= ]]> #{startTime}
<if test="startTime != null and endTime != null">
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
</if> </if>
<if test="projectCodes != null and projectCodes.length != 0"> <if test="endTime != null">
and d.project_code in and start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="projectCodes != null and projectCodes.size() != 0">
and project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=","> <foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i} #{i}
</foreach> </foreach>
</if> </if>
group by t.state group by state
</select> </select>
<select id="queryByProcessDefineCode" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance"> <select id="queryByProcessDefineCode" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select select
<include refid="baseSql"/> <include refid="baseSql"/>

2
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml

@ -51,7 +51,7 @@
order by create_time desc order by create_time desc
</select> </select>
<select id="countDefinitionGroupByUser" resultType="org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser"> <select id="countDefinitionGroupByUser" resultType="org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto">
SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count
FROM t_ds_task_definition td FROM t_ds_task_definition td
JOIN t_ds_user tu on tu.id=td.user_id JOIN t_ds_user tu on tu.id=td.user_id

18
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

@ -78,26 +78,26 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<select id="countTaskInstanceStateByProjectCodes" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
<select id="countTaskInstanceStateByProjectCodes" resultType="org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto">
select state, count(0) as count select state, count(0) as count
from t_ds_task_instance t from t_ds_task_instance
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
where 1=1 where 1=1
<if test="projectCodes != null and projectCodes.length != 0"> <if test="projectCodes != null and projectCodes.size() != 0">
and d.project_code in and project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
</if> </if>
<if test="startTime != null"> <if test="startTime != null">
and t.start_time <![CDATA[ > ]]> #{startTime} and start_time <![CDATA[ > ]]> #{startTime}
</if> </if>
<if test="endTime != null"> <if test="endTime != null">
and t.start_time <![CDATA[ <= ]]> #{endTime} and start_time <![CDATA[ <= ]]> #{endTime}
</if> </if>
group by t.state group by state
</select> </select>
<select id="countTaskInstanceStateByProjectIdsV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount"> <select id="countTaskInstanceStateByProjectIdsV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select state, count(0) as count select state, count(0) as count
from t_ds_task_instance t from t_ds_task_instance t

7
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java

@ -40,6 +40,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Lists;
/** /**
* command mapper test * command mapper test
*/ */
@ -147,13 +149,12 @@ public class CommandMapperTest extends BaseDaoTest {
createCommandMap(count, CommandType.START_PROCESS, processDefinition.getCode()); createCommandMap(count, CommandType.START_PROCESS, processDefinition.getCode());
Long[] projectCodeArray = {processDefinition.getProjectCode()};
Date startTime = DateUtils.stringToDate("2019-12-29 00:10:00"); Date startTime = DateUtils.stringToDate("2019-12-29 00:10:00");
Date endTime = DateUtils.stringToDate("2019-12-29 23:59:59"); Date endTime = DateUtils.stringToDate("2019-12-29 23:59:59");
List<CommandCount> actualCommandCounts = commandMapper.countCommandState(startTime, endTime, projectCodeArray); List<CommandCount> actualCommandCounts = commandMapper.countCommandState(startTime, endTime,
Lists.newArrayList(processDefinition.getProjectCode()));
Assertions.assertTrue(actualCommandCounts.size() >= 1); Assertions.assertTrue(actualCommandCounts.size() >= 1);
} }

10
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java

@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -75,17 +76,14 @@ public class ErrorCommandMapperTest extends BaseDaoTest {
List<CommandCount> commandCounts = errorCommandMapper.countCommandState( List<CommandCount> commandCounts = errorCommandMapper.countCommandState(
null, null,
null, null,
new Long[0]); Lists.newArrayList(0L));
Long[] projectCodeArray = new Long[2];
projectCodeArray[0] = processDefinition.getProjectCode();
projectCodeArray[1] = 200L;
List<CommandCount> commandCounts2 = errorCommandMapper.countCommandState( List<CommandCount> commandCounts2 = errorCommandMapper.countCommandState(
null, null,
null, null,
projectCodeArray); Lists.newArrayList(processDefinition.getProjectCode(), 200L));
Assertions.assertNotEquals(0, commandCounts.size()); Assertions.assertEquals(0, commandCounts.size());
Assertions.assertNotEquals(0, commandCounts2.size()); Assertions.assertNotEquals(0, commandCounts2.size());
} }
} }

9
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -20,12 +20,12 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.BaseDaoTest; import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.Queue; import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class ProcessDefinitionMapperTest extends BaseDaoTest { public class ProcessDefinitionMapperTest extends BaseDaoTest {
@ -296,10 +297,8 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest {
processDefinition.setUserId(user.getId()); processDefinition.setUserId(user.getId());
processDefinitionMapper.updateById(processDefinition); processDefinitionMapper.updateById(processDefinition);
Long[] projectCodes = new Long[1]; List<WorkflowDefinitionCountDto> processDefinitions = processDefinitionMapper
projectCodes[0] = processDefinition.getProjectCode(); .countDefinitionByProjectCodes(Lists.newArrayList(processDefinition.getProjectCode()));
List<DefinitionGroupByUser> processDefinitions =
processDefinitionMapper.countDefinitionByProjectCodes(projectCodes);
Assertions.assertNotEquals(0, processDefinitions.size()); Assertions.assertNotEquals(0, processDefinitions.size());
} }

33
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java

@ -21,10 +21,9 @@ import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.dao.BaseDaoTest; import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import java.util.Date; import java.util.Date;
@ -36,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class ProcessInstanceMapperTest extends BaseDaoTest { public class ProcessInstanceMapperTest extends BaseDaoTest {
@ -75,6 +75,7 @@ public class ProcessInstanceMapperTest extends BaseDaoTest {
Date start = new Date(2019 - 1900, 1 - 1, 1, 0, 10, 0); Date start = new Date(2019 - 1900, 1 - 1, 1, 0, 10, 0);
Date end = new Date(2019 - 1900, 1 - 1, 1, 1, 0, 0); Date end = new Date(2019 - 1900, 1 - 1, 1, 1, 0, 0);
processInstance.setProcessDefinitionCode(1L); processInstance.setProcessDefinitionCode(1L);
processInstance.setProjectCode(1L);
processInstance.setStartTime(start); processInstance.setStartTime(start);
processInstance.setEndTime(end); processInstance.setEndTime(end);
processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS); processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS);
@ -245,34 +246,14 @@ public class ProcessInstanceMapperTest extends BaseDaoTest {
*/ */
@Test @Test
public void testCountInstanceStateByUser() { public void testCountInstanceStateByUser() {
Project project = new Project();
project.setName("testProject");
project.setCode(1L);
project.setCreateTime(new Date());
project.setUpdateTime(new Date());
projectMapper.insert(project);
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setCode(1L);
processDefinition.setProjectCode(1L);
processDefinition.setReleaseState(ReleaseState.ONLINE);
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinitionMapper.insert(processDefinition);
ProcessInstance processInstance = insertOne(); ProcessInstance processInstance = insertOne();
int update = processInstanceMapper.updateById(processInstance);
Long[] projectCodes = new Long[]{processDefinition.getProjectCode()};
List<ExecuteStatusCount> executeStatusCounts = List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos =
processInstanceMapper.countInstanceStateByProjectCodes(null, null, projectCodes); processInstanceMapper.countWorkflowInstanceStateByProjectCodes(null, null,
Lists.newArrayList(processInstance.getProjectCode()));
Assertions.assertNotEquals(0, executeStatusCounts.size()); Assertions.assertNotEquals(0, workflowInstanceStatusCountDtos.size());
projectMapper.deleteById(project.getId());
processDefinitionMapper.deleteById(processDefinition.getId());
processInstanceMapper.deleteById(processInstance.getId()); processInstanceMapper.deleteById(processInstance.getId());
} }

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java

@ -19,10 +19,10 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.BaseDaoTest; import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -123,7 +123,7 @@ public class TaskDefinitionMapperTest extends BaseDaoTest {
User un = userMapper.queryByUserNameAccurately("un"); User un = userMapper.queryByUserNameAccurately("un");
TaskDefinition taskDefinition = insertOne(un.getId()); TaskDefinition taskDefinition = insertOne(un.getId());
List<DefinitionGroupByUser> users = List<WorkflowDefinitionCountDto> users =
taskDefinitionMapper.countDefinitionGroupByUser(new Long[]{taskDefinition.getProjectCode()}); taskDefinitionMapper.countDefinitionGroupByUser(new Long[]{taskDefinition.getProjectCode()});
Assertions.assertNotEquals(0, users.size()); Assertions.assertNotEquals(0, users.size());

32
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

@ -21,10 +21,10 @@ import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType; import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.dao.BaseDaoTest; import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import java.util.Collections; import java.util.Collections;
@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class TaskInstanceMapperTest extends BaseDaoTest { public class TaskInstanceMapperTest extends BaseDaoTest {
@ -72,9 +73,10 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
processInstance.setStartTime(new Date()); processInstance.setStartTime(new Date());
processInstance.setEndTime(new Date()); processInstance.setEndTime(new Date());
processInstance.setProcessDefinitionCode(1L); processInstance.setProcessDefinitionCode(1L);
processInstance.setProjectCode(1L);
processInstance.setTestFlag(0); processInstance.setTestFlag(0);
processInstanceMapper.insert(processInstance); processInstanceMapper.insert(processInstance);
return processInstanceMapper.queryByProcessDefineCode(1L, 1).get(0); return processInstance;
} }
/** /**
@ -88,6 +90,7 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
taskInstance.setStartTime(new Date()); taskInstance.setStartTime(new Date());
taskInstance.setEndTime(new Date()); taskInstance.setEndTime(new Date());
taskInstance.setProcessInstanceId(processInstanceId); taskInstance.setProcessInstanceId(processInstanceId);
taskInstance.setProjectCode(1L);
taskInstance.setTaskType(taskType); taskInstance.setTaskType(taskType);
taskInstanceMapper.insert(taskInstance); taskInstanceMapper.insert(taskInstance);
return taskInstance; return taskInstance;
@ -326,26 +329,19 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
* test count task instance state by user * test count task instance state by user
*/ */
@Test @Test
public void testCountTaskInstanceStateByUser() { public void testcountTaskInstanceStateByProjectCodes() {
// insert ProcessInstance
ProcessInstance processInstance = insertProcessInstance();
// insert taskInstance // insert taskInstance
TaskInstance task = insertTaskInstance(processInstance.getId()); TaskInstance task = insertTaskInstance(1);
ProcessDefinition definition = new ProcessDefinition();
definition.setCode(1111L);
definition.setProjectCode(1111L);
definition.setCreateTime(new Date());
definition.setUpdateTime(new Date());
processDefinitionMapper.insert(definition);
taskInstanceMapper.updateById(task);
List<ExecuteStatusCount> count = taskInstanceMapper.countTaskInstanceStateByProjectCodes( List<TaskInstanceStatusCountDto> taskInstanceStatusCountDtos =
null, null, taskInstanceMapper.countTaskInstanceStateByProjectCodes(
new Long[]{definition.getProjectCode()}); null,
null,
Lists.newArrayList(task.getProjectCode()));
Assertions.assertEquals(1, taskInstanceStatusCountDtos.size());
processDefinitionMapper.deleteById(definition.getId());
taskInstanceMapper.deleteById(task.getId()); taskInstanceMapper.deleteById(task.getId());
} }

2
dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/server/SpringServerMethodInvokerDiscovery.java

@ -60,7 +60,7 @@ public class SpringServerMethodInvokerDiscovery implements BeanPostProcessor {
} }
ServerMethodInvoker methodInvoker = new ServerMethodInvokerImpl(bean, method); ServerMethodInvoker methodInvoker = new ServerMethodInvokerImpl(bean, method);
nettyRemotingServer.registerMethodInvoker(methodInvoker); nettyRemotingServer.registerMethodInvoker(methodInvoker);
log.info("Register ServerMethodInvoker: {} to bean: {}", methodInvoker.getMethodIdentify(), beanName); log.debug("Register ServerMethodInvoker: {} to bean: {}", methodInvoker.getMethodIdentify(), beanName);
} }
} }
} }

2
dolphinscheduler-standalone-server/src/main/resources/application.yaml

@ -325,4 +325,4 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8 url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
username: root username: root
password: root password: root@123

4
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/TaskPluginManager.java

@ -60,12 +60,12 @@ public class TaskPluginManager {
String factoryName = entry.getKey(); String factoryName = entry.getKey();
TaskChannelFactory factory = entry.getValue(); TaskChannelFactory factory = entry.getValue();
log.info("Registering task plugin: {} - {}", factoryName, factory.getClass()); log.info("Registering task plugin: {} - {}", factoryName, factory.getClass().getSimpleName());
taskChannelFactoryMap.put(factoryName, factory); taskChannelFactoryMap.put(factoryName, factory);
taskChannelMap.put(factoryName, factory.create()); taskChannelMap.put(factoryName, factory.create());
log.info("Registered task plugin: {} - {}", factoryName, factory.getClass()); log.info("Registered task plugin: {} - {}", factoryName, factory.getClass().getSimpleName());
} }
} }

3
dolphinscheduler-ui/src/locales/en_US/home.ts

@ -38,5 +38,6 @@ export default {
serial_wait: 'SERIAL_WAIT', serial_wait: 'SERIAL_WAIT',
dispatch: 'DISPATCH', dispatch: 'DISPATCH',
ready_block: 'READY_BLOCK', ready_block: 'READY_BLOCK',
block: 'BLOCK' block: 'BLOCK',
wait_to_run: 'WAIT_TO_RUN'
} }

9
dolphinscheduler-ui/src/locales/zh_CN/home.ts

@ -16,9 +16,9 @@
*/ */
export default { export default {
task_state_statistics: '任务状态统计', task_state_statistics: '任务实例状态统计',
process_state_statistics: '流程状态统计', process_state_statistics: '工作流实例状态统计',
process_definition_statistics: '流定义统计', process_definition_statistics: '工作流定义统计',
number: '数量', number: '数量',
state: '状态', state: '状态',
submitted_success: '提交成功', submitted_success: '提交成功',
@ -38,5 +38,6 @@ export default {
serial_wait: '串行等待', serial_wait: '串行等待',
dispatch: '派发', dispatch: '派发',
ready_block: '准备阻断', ready_block: '准备阻断',
block: '阻断' block: '阻断',
wait_to_run: '等待执行'
} }

25
dolphinscheduler-ui/src/service/modules/projects-analysis/types.ts

@ -30,19 +30,29 @@ interface UserList {
count: number count: number
} }
interface TaskCountDto { interface ProcessDefinitionRes {
count: number count: number
taskStateType: string userList: UserList[]
} }
interface ProcessDefinitionRes { interface WorkflowInstanceCountVo {
totalCount: number
workflowInstanceStatusCounts: WorkflowInstanceStatusCountDto[]
}
interface WorkflowInstanceStatusCountDto {
count: number count: number
userList: UserList[] state: string
} }
interface TaskStateRes { interface TaskInstanceCountVo {
totalCount: number totalCount: number
taskCountDtos: TaskCountDto[] taskInstanceStatusCounts: TaskInstanceStatusCountDto[]
}
interface TaskInstanceStatusCountDto {
count: number
state: string
} }
interface TaskQueueRes { interface TaskQueueRes {
@ -60,7 +70,8 @@ export {
CodeReq, CodeReq,
StateReq, StateReq,
ProcessDefinitionRes, ProcessDefinitionRes,
TaskStateRes, WorkflowInstanceCountVo,
TaskInstanceCountVo,
TaskQueueRes, TaskQueueRes,
CommandStateRes CommandStateRes
} }

2
dolphinscheduler-ui/src/views/home/use-process-definition.ts

@ -23,7 +23,7 @@ import type { DefinitionChartData } from './types'
export function useProcessDefinition() { export function useProcessDefinition() {
const getProcessDefinition = () => { const getProcessDefinition = () => {
const { state } = useAsyncState( const { state } = useAsyncState(
countDefinitionByUser({ projectCode: 0 }).then( countDefinitionByUser({}).then(
(res: ProcessDefinitionRes): DefinitionChartData => { (res: ProcessDefinitionRes): DefinitionChartData => {
const xAxisData = res.userList.map((item) => item.userName) const xAxisData = res.userList.map((item) => item.userName)
const seriesData = res.userList.map((item) => item.count) const seriesData = res.userList.map((item) => item.count)

13
dolphinscheduler-ui/src/views/home/use-process-state.ts

@ -20,7 +20,7 @@ import { countProcessInstanceState } from '@/service/modules/projects-analysis'
import { format } from 'date-fns' import { format } from 'date-fns'
import { toLower } from 'lodash' import { toLower } from 'lodash'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import type { TaskStateRes } from '@/service/modules/projects-analysis/types' import type { WorkflowInstanceCountVo } from '@/service/modules/projects-analysis/types'
import type { StateData } from './types' import type { StateData } from './types'
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
@ -37,19 +37,18 @@ export function useProcessState() {
countProcessInstanceState({ countProcessInstanceState({
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'), startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'), endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: 0 }).then((res: WorkflowInstanceCountVo): StateData => {
}).then((res: TaskStateRes): StateData => { const table = res.workflowInstanceStatusCounts.map((item) => {
const table = res.taskCountDtos.map((item) => {
return { return {
state: t('home.' + toLower(item.taskStateType)), state: t('home.' + toLower(item.state)),
number: item.count number: item.count
} }
}) })
const chart = res.taskCountDtos.map((item) => { const chart = res.workflowInstanceStatusCounts.map((item) => {
return { return {
value: item.count, value: item.count,
name: t('home.' + toLower(item.taskStateType)) name: t('home.' + toLower(item.state))
} }
}) })

14
dolphinscheduler-ui/src/views/home/use-task-state.ts

@ -20,7 +20,7 @@ import { format } from 'date-fns'
import { toLower } from 'lodash' import { toLower } from 'lodash'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { countTaskState } from '@/service/modules/projects-analysis' import { countTaskState } from '@/service/modules/projects-analysis'
import type { TaskStateRes } from '@/service/modules/projects-analysis/types' import type {TaskInstanceCountVo} from '@/service/modules/projects-analysis/types'
import type { StateData } from './types' import type { StateData } from './types'
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
@ -37,23 +37,21 @@ export function useTaskState() {
countTaskState({ countTaskState({
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'), startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'), endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: 0 }).then((res: TaskInstanceCountVo): StateData => {
}).then((res: TaskStateRes): StateData => { const table = res.taskInstanceStatusCounts.map((item, unused) => {
const table = res.taskCountDtos.map((item, unused) => {
return { return {
state: t('home.' + toLower(item.taskStateType)), state: t('home.' + toLower(item.state)),
number: item.count number: item.count
} }
}) })
const chart = res.taskCountDtos.map((item) => { const chart = res.taskInstanceStatusCounts.map((item) => {
return { return {
value: item.count, value: item.count,
name: t('home.' + toLower(item.taskStateType)) name: t('home.' + toLower(item.state))
} }
}) })
taskVariables.taskLoadingRef = false taskVariables.taskLoadingRef = false
return { table, chart } return { table, chart }
}), }),
{ table: [], chart: [] } { table: [], chart: [] }

12
dolphinscheduler-ui/src/views/projects/overview/use-process-state.ts

@ -21,7 +21,7 @@ import { countProcessInstanceState } from '@/service/modules/projects-analysis'
import { format } from 'date-fns' import { format } from 'date-fns'
import { toLower } from 'lodash' import { toLower } from 'lodash'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import type { TaskStateRes } from '@/service/modules/projects-analysis/types' import type {WorkflowInstanceCountVo} from '@/service/modules/projects-analysis/types'
import type { StateData } from './types' import type { StateData } from './types'
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
@ -40,18 +40,18 @@ export function useProcessState() {
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'), startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'), endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: Number(route.params.projectCode) projectCode: Number(route.params.projectCode)
}).then((res: TaskStateRes): StateData => { }).then((res: WorkflowInstanceCountVo): StateData => {
const table = res.taskCountDtos.map((item, unused) => { const table = res.workflowInstanceStatusCounts.map((item, unused) => {
return { return {
state: t('home.' + toLower(item.taskStateType)), state: t('home.' + toLower(item.state)),
number: item.count number: item.count
} }
}) })
const chart = res.taskCountDtos.map((item) => { const chart = res.workflowInstanceStatusCounts.map((item) => {
return { return {
value: item.count, value: item.count,
name: t('home.' + toLower(item.taskStateType)) name: t('home.' + toLower(item.state))
} }
}) })
processVariables.processLoadingRef = false processVariables.processLoadingRef = false

12
dolphinscheduler-ui/src/views/projects/overview/use-task-state.ts

@ -21,7 +21,7 @@ import { format } from 'date-fns'
import { toLower } from 'lodash' import { toLower } from 'lodash'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { countTaskState } from '@/service/modules/projects-analysis' import { countTaskState } from '@/service/modules/projects-analysis'
import type { TaskStateRes } from '@/service/modules/projects-analysis/types' import type {TaskInstanceCountVo} from '@/service/modules/projects-analysis/types'
import type { StateData } from './types' import type { StateData } from './types'
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
@ -40,18 +40,18 @@ export function useTaskState() {
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'), startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'), endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: Number(route.params.projectCode) projectCode: Number(route.params.projectCode)
}).then((res: TaskStateRes): StateData => { }).then((res: TaskInstanceCountVo): StateData => {
const table = res.taskCountDtos.map((item, unused) => { const table = res.taskInstanceStatusCounts.map((item, unused) => {
return { return {
state: t('home.' + toLower(item.taskStateType)), state: t('home.' + toLower(item.state)),
number: item.count number: item.count
} }
}) })
const chart = res.taskCountDtos.map((item) => { const chart = res.taskInstanceStatusCounts.map((item) => {
return { return {
value: item.count, value: item.count,
name: t('home.' + toLower(item.taskStateType)) name: t('home.' + toLower(item.state))
} }
}) })
taskVariables.taskLoadingRef = false taskVariables.taskLoadingRef = false

Loading…
Cancel
Save