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. 77
      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. 83
      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. 318
      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. 16
      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. 285
      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. 10
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  28. 10
      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. 8
      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)

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)

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

77
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java

@ -24,11 +24,12 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUEUE_COUNT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.TASK_INSTANCE_STATE_COUNT_ERROR;
import org.apache.dolphinscheduler.api.dto.CommandStateCount;
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User;
@ -59,17 +60,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
public class DataAnalysisController extends BaseController {
@Autowired
DataAnalysisService dataAnalysisService;
private DataAnalysisService dataAnalysisService;
/**
* statistical task instance status data
*
* @param loginUser login user
* @param startDate count start date
* @param endDate count end date
* @param projectCode project code
* @return task instance count data
*/
@Operation(summary = "countTaskState", description = "COUNT_TASK_STATE_NOTES")
@Parameters({
@Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)),
@ -79,25 +71,17 @@ public class DataAnalysisController extends BaseController {
@GetMapping(value = "/task-state-count")
@ResponseStatus(HttpStatus.OK)
@ApiException(TASK_INSTANCE_STATE_COUNT_ERROR)
public Result<TaskCountDto> countTaskState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
TaskCountDto taskCountDto =
dataAnalysisService.countTaskStateByProject(loginUser, projectCode, startDate, endDate);
return Result.success(taskCountDto);
public Result<TaskInstanceCountVo> getTaskInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
return Result.success(dataAnalysisService.getAllTaskInstanceStateCount(loginUser, startDate, endDate));
}
return Result.success(
dataAnalysisService.getTaskInstanceStateCountByProject(loginUser, projectCode, startDate, endDate));
}
/**
* statistical process instance status data
*
* @param loginUser login user
* @param startDate start date
* @param endDate end date
* @param projectCode project code
* @return process instance data
*/
@Operation(summary = "countProcessInstanceState", description = "COUNT_PROCESS_INSTANCE_NOTES")
@Parameters({
@Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)),
@ -107,23 +91,17 @@ public class DataAnalysisController extends BaseController {
@GetMapping(value = "/process-state-count")
@ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_INSTANCE_STATE_ERROR)
public Result<TaskCountDto> countProcessInstanceState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
TaskCountDto taskCountDto =
dataAnalysisService.countProcessInstanceStateByProject(loginUser, projectCode, startDate, endDate);
return Result.success(taskCountDto);
public Result<WorkflowInstanceCountVo> getWorkflowInstanceStateCount(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
return Result.success(dataAnalysisService.getAllWorkflowInstanceStateCount(loginUser, startDate, endDate));
}
return Result.success(
dataAnalysisService.getWorkflowInstanceStateCountByProject(loginUser, projectCode, startDate, endDate));
}
/**
* statistics the process definition quantities of certain person
*
* @param loginUser login user
* @param projectCode project code
* @return definition count in project code
*/
@Operation(summary = "countDefinitionByUser", description = "COUNT_PROCESS_DEFINITION_BY_USER_NOTES")
@Parameters({
@Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "100"))
@ -131,11 +109,12 @@ public class DataAnalysisController extends BaseController {
@GetMapping(value = "/define-user-count")
@ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) {
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUser(loginUser, projectCode);
return Result.success(defineUserDto);
public Result<WorkflowDefinitionCountVo> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "projectCode", required = false) Long projectCode) {
if (projectCode == null) {
return Result.success(dataAnalysisService.getAllWorkflowDefinitionCount(loginUser));
}
return Result.success(dataAnalysisService.getWorkflowDefinitionCountByProject(loginUser, projectCode));
}
/**

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;
import static org.apache.dolphinscheduler.api.enums.Status.COUNT_PROCESS_DEFINITION_USER_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_WORKFLOW_COUNT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_TASK_STATES_COUNT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_STATES_COUNT_ERROR;
@ -34,10 +33,6 @@ import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@ -62,20 +57,6 @@ public class StatisticsV2Controller extends BaseController {
@Autowired
private DataAnalysisService dataAnalysisService;
/**
* query all workflow count
* @param loginUser login user
* @return workflow count
*/
@Operation(summary = "queryAllWorkflowCount", description = "QUERY_ALL_WORKFLOW_COUNT")
@GetMapping(value = "/workflows/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ALL_WORKFLOW_COUNT_ERROR)
public Result queryWorkflowInstanceCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
Map<String, Object> result = dataAnalysisService.queryAllWorkflowCounts(loginUser);
return returnDataList(result);
}
/**
* query all workflow states count
*
@ -157,13 +138,8 @@ public class StatisticsV2Controller extends BaseController {
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
String projectName = statisticsStateRequest.getProjectName();
Long projectCode = statisticsStateRequest.getProjectCode();
if (null == projectCode && !StringUtils.isBlank(projectName)) {
projectCode = dataAnalysisService.getProjectCodeByName(projectName);
}
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
return Result.success(defineUserDto);
// todo: directly use StatisticsStateRequest
throw new UnsupportedOperationException("not supported");
}
/**
@ -179,7 +155,7 @@ public class StatisticsV2Controller extends BaseController {
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
public Result<DefineUserDto> countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("userId") Integer userId) {
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
DefineUserDto defineUserDto = dataAnalysisService.countDefinitionByUserV2(loginUser, userId, null);
return Result.success(defineUserDto);
}
@ -199,7 +175,7 @@ public class StatisticsV2Controller extends BaseController {
@PathVariable("userId") Integer userId,
@PathVariable("releaseState") Integer releaseState) {
DefineUserDto defineUserDto =
dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState);
dataAnalysisService.countDefinitionByUserV2(loginUser, userId, releaseState);
return Result.success(defineUserDto);
}
}

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

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

83
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java

@ -21,12 +21,11 @@ import org.apache.dolphinscheduler.api.dto.CommandStateCount;
import org.apache.dolphinscheduler.api.dto.DefineUserDto;
import org.apache.dolphinscheduler.api.dto.TaskCountDto;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -35,51 +34,39 @@ import java.util.Map;
*/
public interface DataAnalysisService {
/**
* statistical task instance status data
*
* @param loginUser login user
* @param projectCode project code
* @param startDate start date
* @param endDate end date
* @return task state count data
*/
TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate);
TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser,
Long projectCode,
String startDate,
String endDate);
/**
* statistical process instance status data
*
* @param loginUser login user
* @param projectCode project code
* @param startDate start date
* @param endDate end date
* @return process instance state count data
*/
TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
String endDate);
TaskInstanceCountVo getAllTaskInstanceStateCount(User loginUser,
String startDate,
String endDate);
WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser,
Long projectCodes,
String startDate,
String endDate);
WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser,
String startDate,
String endDate);
WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode);
WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser);
/**
* statistics the process definition quantities of a certain person
* <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 workflow count data
*/
DefineUserDto countDefinitionByUser(User loginUser, long projectCode);
/**
* statistics the workflow quantities of certain user
* <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
* @param userId userId
* @param releaseState releaseState
* @return workflow count data
*/
DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, Integer releaseState);
DefineUserDto countDefinitionByUserV2(User loginUser, Integer userId, Integer releaseState);
/**
* statistical command status data
@ -97,27 +84,6 @@ public interface DataAnalysisService {
*/
Map<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
* @param loginUser login user
@ -151,5 +117,4 @@ public interface DataAnalysisService {
*/
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.User;
import java.util.List;
import java.util.Map;
/**
@ -70,7 +71,7 @@ public interface ProjectService {
void checkProjectAndAuthThrowException(User loginUser, Project project, String permission) throws ServiceException;
void checkProjectAndAuthThrowException(User loginUser, long projectCode, String permission) throws ServiceException;
void checkProjectAndAuthThrowException(User loginUser, Long projectCode, String permission) throws ServiceException;
boolean hasProjectAndPerm(User loginUser, Project project, Map<String, Object> result, String perm);
@ -213,4 +214,6 @@ public interface ProjectService {
* @return project list
*/
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) {
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;
}
}

318
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java

@ -27,14 +27,14 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowDefinitionCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.common.utils.TriFunction;
import org.apache.dolphinscheduler.dao.entity.CommandCount;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project;
@ -44,14 +44,16 @@ import org.apache.dolphinscheduler.dao.mapper.CommandMapper;
import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.Arrays;
@ -60,7 +62,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -70,6 +71,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.common.collect.Lists;
/**
* data analysis service impl
*/
@ -101,165 +104,94 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
@Autowired
private TaskDefinitionMapper taskDefinitionMapper;
@Autowired
private ProcessTaskRelationMapper relationMapper;
/**
* statistical task instance status data
*
* @param loginUser login user
* @param projectCode project code
* @param startDate start date
* @param endDate end date
* @return task state count data
*/
@Override
public TaskCountDto countTaskStateByProject(User loginUser, long projectCode, String startDate,
String endDate) {
return countStateByProject(
loginUser,
projectCode,
startDate,
endDate,
this::countTaskInstanceAllStatesByProjectCodes);
public TaskInstanceCountVo getTaskInstanceStateCountByProject(User loginUser,
Long projectCode,
String startDate,
String endDate) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
List<TaskInstanceStatusCountDto> taskInstanceStatusCounts =
taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode));
return TaskInstanceCountVo.of(taskInstanceStatusCounts);
}
/**
* statistical process instance status data
*
* @param loginUser login user
* @param projectCode project code
* @param startDate start date
* @param endDate end date
* @return process instance state count data
*/
@Override
public TaskCountDto countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate,
String endDate) {
TaskCountDto taskCountDto = countStateByProject(
loginUser,
projectCode,
startDate,
endDate,
(start, end, projectCodes) -> processInstanceMapper.countInstanceStateByProjectCodes(start, end,
projectCodes));
// process state count needs to remove state of forced success
if (taskCountDto != null) {
taskCountDto.removeStateFromCountList(TaskExecutionStatus.FORCED_SUCCESS);
public TaskInstanceCountVo getAllTaskInstanceStateCount(User loginUser,
String startDate,
String endDate) {
List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
if (CollectionUtils.isEmpty(projectCodes)) {
return TaskInstanceCountVo.empty();
}
return taskCountDto;
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
List<TaskInstanceStatusCountDto> taskInstanceStatusCounts =
taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, projectCodes);
return TaskInstanceCountVo.of(taskInstanceStatusCounts);
}
/**
* Wrapper function of counting process instance state and task state
*
* @param loginUser login user
* @param projectCode project code
* @param startDate start date
* @param endDate end date
*/
private TaskCountDto countStateByProject(User loginUser,
long projectCode,
String startDate,
String endDate,
TriFunction<Date, Date, Long[], List<ExecuteStatusCount>> instanceStateCounter) {
if (projectCode != 0) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
}
Date start = null;
Date end = null;
if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate)) {
start = DateUtils.stringToDate(startDate);
end = DateUtils.stringToDate(endDate);
if (Objects.isNull(start) || Objects.isNull(end)) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE);
}
}
Pair<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<>();
@Override
public WorkflowInstanceCountVo getWorkflowInstanceStateCountByProject(User loginUser,
Long projectCode,
String startDate,
String endDate) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos = processInstanceMapper
.countWorkflowInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode));
return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos);
}
if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) {
processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray);
@Override
public WorkflowInstanceCountVo getAllWorkflowInstanceStateCount(User loginUser,
String startDate,
String endDate) {
List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
if (CollectionUtils.isEmpty(projectCodes)) {
return WorkflowInstanceCountVo.empty();
}
Date start = startDate == null ? null : transformDate(startDate);
Date end = endDate == null ? null : transformDate(endDate);
if (processInstanceStateCounts != null) {
return new TaskCountDto(processInstanceStateCounts);
}
return null;
List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos =
processInstanceMapper.countWorkflowInstanceStateByProjectCodes(start, end, projectCodes);
return WorkflowInstanceCountVo.of(workflowInstanceStatusCountDtos);
}
/**
* 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
public DefineUserDto countDefinitionByUser(User loginUser, long projectCode) {
if (projectCode != 0) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
}
// todo: refactor this method, don't use Pair
Pair<Set<Integer>, TaskCountDto> projectIds = getProjectIds(loginUser);
if (projectIds.getRight() != null) {
List<DefinitionGroupByUser> emptyList = new ArrayList<>();
return new DefineUserDto(emptyList);
}
public WorkflowDefinitionCountVo getWorkflowDefinitionCountByProject(User loginUser, Long projectCode) {
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW);
List<WorkflowDefinitionCountDto> workflowDefinitionCounts =
processDefinitionMapper.countDefinitionByProjectCodes(Lists.newArrayList(projectCode));
return WorkflowDefinitionCountVo.of(workflowDefinitionCounts);
}
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);
@Override
public WorkflowDefinitionCountVo getAllWorkflowDefinitionCount(User loginUser) {
List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
if (CollectionUtils.isEmpty(projectCodes)) {
return WorkflowDefinitionCountVo.empty();
}
return new DefineUserDto(defineGroupByUsers);
return WorkflowDefinitionCountVo.of(processDefinitionMapper.countDefinitionByProjectCodes(projectCodes));
}
/**
* statistical command status data
*
* @param loginUser login user
* @return command state count data
*/
@Override
public List<CommandStateCount> countCommandState(User loginUser) {
/**
* find all the task lists in the project under the user
* statistics based on task status execution, failure, completion, wait, total
*/
Date start = null;
Date end = null;
Pair<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());
List<Long> projectCodes = projectService.getAuthorizedProjectCodes(loginUser);
// count normal command state
Map<CommandType, Integer> normalCountCommandCounts =
commandMapper.countCommandState(start, end, projectCodeArray)
commandMapper.countCommandState(null, null, projectCodes)
.stream()
.collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount));
// count error command state
Map<CommandType, Integer> errorCommandCounts =
errorCommandMapper.countCommandState(start, end, projectCodeArray)
errorCommandMapper.countCommandState(null, null, projectCodes)
.stream()
.collect(Collectors.toMap(CommandCount::getCommandType, CommandCount::getCount));
@ -272,24 +204,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return list;
}
private Pair<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
*
@ -306,59 +220,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
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
*
@ -524,38 +385,27 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
* <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
* @param loginUser login user
* @return definition count data
*/
@Override
public DefineUserDto countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId,
public DefineUserDto countDefinitionByUserV2(User loginUser,
Integer userId,
Integer releaseState) {
if (null != projectCode) {
Project project = projectMapper.queryByCode(projectCode);
projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
}
List<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);
Set<Integer> projectIds = resourcePermissionCheckService
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), log);
if (CollectionUtils.isEmpty(projectIds)) {
return new DefineUserDto(Collections.emptyList());
}
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
public Long getProjectCodeByName(String projectName) {
Project project = projectMapper.queryByName(projectName);
return project == null ? 0 : project.getCode();
return new DefineUserDto(workflowDefinitionCountDtos);
}
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 pageNo,
Integer pageSize) {
Project project = projectMapper.queryByCode(projectCode);
// check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION);
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_DEFINITION);
PageListingResult<ProcessDefinition> processDefinitionsPageListingResult =
processDefinitionDao.listingProcessDefinition(

16
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java

@ -337,10 +337,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
Integer pageSize) {
Result result = new Result();
Project project = projectMapper.queryByCode(projectCode);
// check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project,
ApiFuncIdentificationConstant.WORKFLOW_INSTANCE);
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE);
int[] statusArray = null;
// filter by state
@ -356,7 +354,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
IPage<ProcessInstance> processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(
page,
project.getCode(),
projectCode,
processDefineCode,
searchVal,
executorName,
@ -685,14 +683,10 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
String taskDefinitionJson, String scheduleTime, Boolean syncDefine,
String globalParams,
String locations, int timeout) {
Project project = projectMapper.queryByCode(projectCode);
// check user access for project
Map<String, Object> result =
projectService.checkProjectAndAuth(loginUser, project, projectCode,
ApiFuncIdentificationConstant.INSTANCE_UPDATE);
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
projectService.checkProjectAndAuthThrowException(loginUser, projectCode,
ApiFuncIdentificationConstant.INSTANCE_UPDATE);
Map<String, Object> result = new HashMap<>();
// check process instance exists
ProcessInstance processInstance = processService.findProcessInstanceDetailById(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.UserMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
@ -52,6 +53,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
@ -239,7 +241,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
}
@Override
public void checkProjectAndAuthThrowException(User loginUser, long projectCode, String permission) {
public void checkProjectAndAuthThrowException(User loginUser, Long projectCode, String permission) {
if (projectCode == null) {
throw new ServiceException(Status.PROJECT_NOT_EXIST);
}
Project project = projectMapper.queryByCode(projectCode);
checkProjectAndAuthThrowException(loginUser, project, permission);
}
@ -834,4 +839,20 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
putMsg(result, Status.SUCCESS);
return result;
}
@Override
public List<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 pageSize) {
Result result = new Result();
Project project = projectMapper.queryByCode(projectCode);
// check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, TASK_INSTANCE);
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, TASK_INSTANCE);
int[] statusArray = null;
if (stateType != null) {
statusArray = new int[]{stateType.getCode()};
@ -160,7 +159,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
// stream task without process instance
taskInstanceIPage = taskInstanceMapper.queryStreamTaskInstanceListPaging(
page,
project.getCode(),
projectCode,
processDefinitionName,
searchVal,
taskName,
@ -174,7 +173,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
} else {
taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page,
project.getCode(),
projectCode,
processInstanceId,
processInstanceName,
searchVal,

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.utils.Result;
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVo;
import org.apache.dolphinscheduler.api.vo.WorkflowInstanceCountVo;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
@ -39,6 +41,8 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.fasterxml.jackson.core.type.TypeReference;
/**
* data analysis controller test
*/
@ -60,7 +64,7 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
}
@Test
public void testCountTaskState() throws Exception {
public void testGetTaskInstanceStateCount() throws Exception {
int projectId = createProject();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
@ -73,15 +77,17 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode());
logger.info(mvcResult.getResponse().getContentAsString());
Result<TaskInstanceCountVo> result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(),
new TypeReference<Result<TaskInstanceCountVo>>() {
});
assertThat(result.getCode())
.isNotNull()
.isEqualTo(Status.SUCCESS.getCode());
projectMapper.deleteById(projectId);
}
@Test
public void testCountProcessInstanceState() throws Exception {
public void testGetWorkflowInstanceStateCount() throws Exception {
int projectId = createProject();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
@ -95,9 +101,11 @@ public class DataAnalysisControllerTest extends AbstractControllerTest {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
assertThat(result.getCode().intValue()).isEqualTo(Status.SUCCESS.getCode());
logger.info(mvcResult.getResponse().getContentAsString());
Result<WorkflowInstanceCountVo> result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(),
new TypeReference<Result<WorkflowInstanceCountVo>>() {
});
assertThat(result.getCode())
.isEqualTo(Status.SUCCESS.getCode());
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.TaskCountDto;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
@ -50,21 +46,6 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest {
@Mock
private DataAnalysisServiceImpl dataAnalysisService;
@Test
public void testQueryWorkflowInstanceCounts() {
User loginUser = getLoginUser();
int count = 0;
Map<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
public void testQueryWorkflowStatesCounts() {
User loginUser = getLoginUser();
@ -121,27 +102,14 @@ public class StatisticsV2ControllerTest extends AbstractControllerTest {
assertTrue(result1.isSuccess());
}
@Test
public void testCountDefinitionByUser() {
User loginUser = getLoginUser();
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
List<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
public void testCountDefinitionByUserId() {
User loginUser = getLoginUser();
Integer userId = 1;
DefineUserDto defineUserDto = new DefineUserDto(Collections.emptyList());
when(dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null)).thenReturn(defineUserDto);
when(dataAnalysisService.countDefinitionByUserV2(loginUser, userId, null)).thenReturn(defineUserDto);
assertDoesNotThrow(() -> statisticsV2Controller.countDefinitionByUserId(loginUser, userId));
}

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

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

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

285
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

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

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

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
* @param startTime startTime
* @param endTime endTime
* @param projectCodeArray projectCodeArray
* @param projectCodes projectCodes
* @return CommandCount list
*/
List<CommandCount> countCommandState(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodeArray") Long[] projectCodeArray);
@Param("projectCodes") List<Long> projectCodes);
/**
* 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
* @param startTime startTime
* @param endTime endTime
* @param projectCodeArray projectCodeArray
* @param projectCodes projectCodes
* @return CommandCount list
*/
List<CommandCount> countCommandState(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodeArray") Long[] projectCodeArray);
@Param("projectCodes") List<Long> projectCodes);
}

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

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

10
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java

@ -20,9 +20,11 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
@ -168,10 +170,10 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
* @param projectCodes projectCodes
* @return ExecuteStatusCount list
*/
List<ExecuteStatusCount> countInstanceStateByProjectCodes(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes);
List<WorkflowInstanceStatusCountDto> countWorkflowInstanceStateByProjectCodes(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodes") Collection<Long> projectCodes);
/**
* 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;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
@ -72,7 +72,7 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
* @param projectCodes projectCodes
* @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

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java

@ -21,10 +21,12 @@ import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
@ -77,9 +79,9 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
* @param projectCodes Project codes list to filter
* @return List of ExecuteStatusCount
*/
List<ExecuteStatusCount> countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes);
List<TaskInstanceStatusCountDto> countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodes") Collection<Long> projectCodes);
/**
* 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.
*/
package org.apache.dolphinscheduler.dao.entity;
package org.apache.dolphinscheduler.dao.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* count definition number group by user
*/
@Data
public class DefinitionGroupByUser {
@NoArgsConstructor
@AllArgsConstructor
public class WorkflowDefinitionCountDto {
/**
* user name
*/
private String userName;
/**
* user id
*/
private Integer userId;
/**
* count number
*/
private int count;
}

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
from t_ds_command cmd, t_ds_process_definition process
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
<foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=",">
<foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</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
from t_ds_error_command cmd, t_ds_process_definition process
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
<foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=",">
<foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>

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

@ -131,24 +131,27 @@
#{i}
</foreach>
</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
JOIN t_ds_user tu on tu.id=td.user_id
where 1 = 1
<if test="projectCodes != null and projectCodes.length != 0">
<if test="projectCodes != null and projectCodes.size() != 0">
and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
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
FROM t_ds_process_definition td
JOIN t_ds_user tu on tu.id=td.user_id
where 1 = 1
<if test="projectCodes != null and projectCodes.length != 0">
<if test="projectCodes != null and projectCodes.size() != 0">
and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}

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

@ -170,23 +170,25 @@
where worker_group = #{originWorkerGroupName}
</update>
<select id="countInstanceStateByProjectCodes"
resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select t.state, count(0) as count
from t_ds_process_instance t
join t_ds_process_definition d on d.code=t.process_definition_code
where t.is_sub_process = 0
<if test="startTime != null and endTime != null">
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
<select id="countWorkflowInstanceStateByProjectCodes" resultType="org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto">
select state, count(0) as count
from t_ds_process_instance
where is_sub_process = 0
<if test="startTime != null">
and start_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null">
and start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="projectCodes != null and projectCodes.length != 0">
and d.project_code in
<if test="projectCodes != null and projectCodes.size() != 0">
and project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
group by t.state
group by state
</select>
<select id="queryByProcessDefineCode" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<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
</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
FROM t_ds_task_definition td
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>
</if>
</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
from t_ds_task_instance t
left join t_ds_task_definition_log d on d.code=t.task_code and d.version=t.task_definition_version
left join t_ds_project p on p.code=d.project_code
from t_ds_task_instance
where 1=1
<if test="projectCodes != null and projectCodes.length != 0">
and d.project_code in
<if test="projectCodes != null and projectCodes.size() != 0">
and project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="startTime != null">
and t.start_time <![CDATA[ > ]]> #{startTime}
and start_time <![CDATA[ > ]]> #{startTime}
</if>
<if test="endTime != null">
and t.start_time <![CDATA[ <= ]]> #{endTime}
and start_time <![CDATA[ <= ]]> #{endTime}
</if>
group by t.state
group by state
</select>
<select id="countTaskInstanceStateByProjectIdsV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select state, count(0) as count
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.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Lists;
/**
* command mapper test
*/
@ -147,13 +149,12 @@ public class CommandMapperTest extends BaseDaoTest {
createCommandMap(count, CommandType.START_PROCESS, processDefinition.getCode());
Long[] projectCodeArray = {processDefinition.getProjectCode()};
Date startTime = DateUtils.stringToDate("2019-12-29 00:10:00");
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);
}

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.List;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -75,17 +76,14 @@ public class ErrorCommandMapperTest extends BaseDaoTest {
List<CommandCount> commandCounts = errorCommandMapper.countCommandState(
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(
null,
null,
projectCodeArray);
Lists.newArrayList(processDefinition.getProjectCode(), 200L));
Assertions.assertNotEquals(0, commandCounts.size());
Assertions.assertEquals(0, commandCounts.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.UserType;
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.Project;
import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import java.util.Date;
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.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class ProcessDefinitionMapperTest extends BaseDaoTest {
@ -296,10 +297,8 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest {
processDefinition.setUserId(user.getId());
processDefinitionMapper.updateById(processDefinition);
Long[] projectCodes = new Long[1];
projectCodes[0] = processDefinition.getProjectCode();
List<DefinitionGroupByUser> processDefinitions =
processDefinitionMapper.countDefinitionByProjectCodes(projectCodes);
List<WorkflowDefinitionCountDto> processDefinitions = processDefinitionMapper
.countDefinitionByProjectCodes(Lists.newArrayList(processDefinition.getProjectCode()));
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.WorkflowExecutionStatus;
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.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 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.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
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 end = new Date(2019 - 1900, 1 - 1, 1, 1, 0, 0);
processInstance.setProcessDefinitionCode(1L);
processInstance.setProjectCode(1L);
processInstance.setStartTime(start);
processInstance.setEndTime(end);
processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS);
@ -245,34 +246,14 @@ public class ProcessInstanceMapperTest extends BaseDaoTest {
*/
@Test
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();
int update = processInstanceMapper.updateById(processInstance);
Long[] projectCodes = new Long[]{processDefinition.getProjectCode()};
List<ExecuteStatusCount> executeStatusCounts =
processInstanceMapper.countInstanceStateByProjectCodes(null, null, projectCodes);
List<WorkflowInstanceStatusCountDto> workflowInstanceStatusCountDtos =
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());
}

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.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import java.util.Date;
import java.util.List;
@ -123,7 +123,7 @@ public class TaskDefinitionMapperTest extends BaseDaoTest {
User un = userMapper.queryByUserNameAccurately("un");
TaskDefinition taskDefinition = insertOne(un.getId());
List<DefinitionGroupByUser> users =
List<WorkflowDefinitionCountDto> users =
taskDefinitionMapper.countDefinitionGroupByUser(new Long[]{taskDefinition.getProjectCode()});
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.WorkflowExecutionStatus;
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.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
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.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class TaskInstanceMapperTest extends BaseDaoTest {
@ -72,9 +73,10 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
processInstance.setStartTime(new Date());
processInstance.setEndTime(new Date());
processInstance.setProcessDefinitionCode(1L);
processInstance.setProjectCode(1L);
processInstance.setTestFlag(0);
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.setEndTime(new Date());
taskInstance.setProcessInstanceId(processInstanceId);
taskInstance.setProjectCode(1L);
taskInstance.setTaskType(taskType);
taskInstanceMapper.insert(taskInstance);
return taskInstance;
@ -326,26 +329,19 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
* test count task instance state by user
*/
@Test
public void testCountTaskInstanceStateByUser() {
// insert ProcessInstance
ProcessInstance processInstance = insertProcessInstance();
public void testcountTaskInstanceStateByProjectCodes() {
// insert taskInstance
TaskInstance task = insertTaskInstance(processInstance.getId());
ProcessDefinition definition = new ProcessDefinition();
definition.setCode(1111L);
definition.setProjectCode(1111L);
definition.setCreateTime(new Date());
definition.setUpdateTime(new Date());
processDefinitionMapper.insert(definition);
taskInstanceMapper.updateById(task);
TaskInstance task = insertTaskInstance(1);
List<ExecuteStatusCount> count = taskInstanceMapper.countTaskInstanceStateByProjectCodes(
null, null,
new Long[]{definition.getProjectCode()});
List<TaskInstanceStatusCountDto> taskInstanceStatusCountDtos =
taskInstanceMapper.countTaskInstanceStateByProjectCodes(
null,
null,
Lists.newArrayList(task.getProjectCode()));
Assertions.assertEquals(1, taskInstanceStatusCountDtos.size());
processDefinitionMapper.deleteById(definition.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);
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
url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
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();
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);
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',
dispatch: 'DISPATCH',
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 {
task_state_statistics: '任务状态统计',
process_state_statistics: '流程状态统计',
process_definition_statistics: '流定义统计',
task_state_statistics: '任务实例状态统计',
process_state_statistics: '工作流实例状态统计',
process_definition_statistics: '工作流定义统计',
number: '数量',
state: '状态',
submitted_success: '提交成功',
@ -38,5 +38,6 @@ export default {
serial_wait: '串行等待',
dispatch: '派发',
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
}
interface TaskCountDto {
interface ProcessDefinitionRes {
count: number
taskStateType: string
userList: UserList[]
}
interface ProcessDefinitionRes {
interface WorkflowInstanceCountVo {
totalCount: number
workflowInstanceStatusCounts: WorkflowInstanceStatusCountDto[]
}
interface WorkflowInstanceStatusCountDto {
count: number
userList: UserList[]
state: string
}
interface TaskStateRes {
interface TaskInstanceCountVo {
totalCount: number
taskCountDtos: TaskCountDto[]
taskInstanceStatusCounts: TaskInstanceStatusCountDto[]
}
interface TaskInstanceStatusCountDto {
count: number
state: string
}
interface TaskQueueRes {
@ -60,7 +70,8 @@ export {
CodeReq,
StateReq,
ProcessDefinitionRes,
TaskStateRes,
WorkflowInstanceCountVo,
TaskInstanceCountVo,
TaskQueueRes,
CommandStateRes
}

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

@ -23,7 +23,7 @@ import type { DefinitionChartData } from './types'
export function useProcessDefinition() {
const getProcessDefinition = () => {
const { state } = useAsyncState(
countDefinitionByUser({ projectCode: 0 }).then(
countDefinitionByUser({}).then(
(res: ProcessDefinitionRes): DefinitionChartData => {
const xAxisData = res.userList.map((item) => item.userName)
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 { toLower } from 'lodash'
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 { reactive, ref } from 'vue'
@ -37,19 +37,18 @@ export function useProcessState() {
countProcessInstanceState({
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: 0
}).then((res: TaskStateRes): StateData => {
const table = res.taskCountDtos.map((item) => {
}).then((res: WorkflowInstanceCountVo): StateData => {
const table = res.workflowInstanceStatusCounts.map((item) => {
return {
state: t('home.' + toLower(item.taskStateType)),
state: t('home.' + toLower(item.state)),
number: item.count
}
})
const chart = res.taskCountDtos.map((item) => {
const chart = res.workflowInstanceStatusCounts.map((item) => {
return {
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 { useI18n } from 'vue-i18n'
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 { reactive, ref } from 'vue'
@ -37,23 +37,21 @@ export function useTaskState() {
countTaskState({
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: 0
}).then((res: TaskStateRes): StateData => {
const table = res.taskCountDtos.map((item, unused) => {
}).then((res: TaskInstanceCountVo): StateData => {
const table = res.taskInstanceStatusCounts.map((item, unused) => {
return {
state: t('home.' + toLower(item.taskStateType)),
state: t('home.' + toLower(item.state)),
number: item.count
}
})
const chart = res.taskCountDtos.map((item) => {
const chart = res.taskInstanceStatusCounts.map((item) => {
return {
value: item.count,
name: t('home.' + toLower(item.taskStateType))
name: t('home.' + toLower(item.state))
}
})
taskVariables.taskLoadingRef = false
return { 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 { toLower } from 'lodash'
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 { reactive, ref } from 'vue'
@ -40,18 +40,18 @@ export function useProcessState() {
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: Number(route.params.projectCode)
}).then((res: TaskStateRes): StateData => {
const table = res.taskCountDtos.map((item, unused) => {
}).then((res: WorkflowInstanceCountVo): StateData => {
const table = res.workflowInstanceStatusCounts.map((item, unused) => {
return {
state: t('home.' + toLower(item.taskStateType)),
state: t('home.' + toLower(item.state)),
number: item.count
}
})
const chart = res.taskCountDtos.map((item) => {
const chart = res.workflowInstanceStatusCounts.map((item) => {
return {
value: item.count,
name: t('home.' + toLower(item.taskStateType))
name: t('home.' + toLower(item.state))
}
})
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 { useI18n } from 'vue-i18n'
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 { reactive, ref } from 'vue'
@ -40,18 +40,18 @@ export function useTaskState() {
startDate: !date ? '' : format(date[0], 'yyyy-MM-dd HH:mm:ss'),
endDate: !date ? '' : format(date[1], 'yyyy-MM-dd HH:mm:ss'),
projectCode: Number(route.params.projectCode)
}).then((res: TaskStateRes): StateData => {
const table = res.taskCountDtos.map((item, unused) => {
}).then((res: TaskInstanceCountVo): StateData => {
const table = res.taskInstanceStatusCounts.map((item, unused) => {
return {
state: t('home.' + toLower(item.taskStateType)),
state: t('home.' + toLower(item.state)),
number: item.count
}
})
const chart = res.taskCountDtos.map((item) => {
const chart = res.taskInstanceStatusCounts.map((item) => {
return {
value: item.count,
name: t('home.' + toLower(item.taskStateType))
name: t('home.' + toLower(item.state))
}
})
taskVariables.taskLoadingRef = false

Loading…
Cancel
Save