Browse Source

[feat][API] New restful API for workflow state (#13031)

3.2.0-release
insist777 2 years ago committed by GitHub
parent
commit
1064680ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 206
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/StatisticsV2Controller.java
  2. 60
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/StatisticsStateRequest.java
  3. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  4. 57
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java
  5. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java
  6. 275
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java
  7. 45
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  8. 171
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/StatisticsV2ControllerTest.java
  9. 5
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java
  10. 27
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java
  11. 14
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  12. 22
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java
  13. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java
  14. 7
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java
  15. 35
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java
  16. 18
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  17. 24
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
  18. 7
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml
  19. 10
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml
  20. 57
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

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

@ -0,0 +1,206 @@
/*
* 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.controller;
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;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKFLOW_STATES_COUNT_ERROR;
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
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.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;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* StatisticsV2 controller
*/
@Tag(name = "STATISTICS_V2")
@RestController
@RequestMapping("/v2/statistics")
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)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
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
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return workflow states count
*/
@Operation(summary = "queryAllWorkflowStatesCount", description = "QUERY_ALL_WORKFLOW_STATES_COUNT")
@GetMapping(value = "/workflows/states/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_WORKFLOW_STATES_COUNT_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryWorkflowStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
Map<String, Object> result =
dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest);
return returnDataList(result);
}
/**
* query one workflow states count
* @param loginUser login user
* @param workflowCode workflowCode
* @return workflow states count
*/
@Operation(summary = "queryOneWorkflowStatesCount", description = "QUERY_One_WORKFLOW_STATES_COUNT")
@GetMapping(value = "/{workflowCode}/states/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryOneWorkflowStates(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("workflowCode") Long workflowCode) {
Map<String, Object> result =
dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode);
return returnDataList(result);
}
/**
* query all task states count
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return tasks states count
*/
@Operation(summary = "queryAllTaskStatesCount", description = "QUERY_ALL_TASK_STATES_COUNT")
@GetMapping(value = "/tasks/states/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_TASK_STATES_COUNT_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
Map<String, Object> result =
dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest);
return returnDataList(result);
}
/**
* query one task states count
* @param loginUser login user
* @param taskCode taskCode
* @return tasks states count
*/
@Operation(summary = "queryOneTaskStatesCount", description = "QUERY_ONE_TASK_STATES_COUNT")
@GetMapping(value = "/tasks/{taskCode}/states/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_ONE_TASK_STATES_COUNT_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryOneTaskStatesCounts(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("taskCode") Long taskCode) {
Map<String, Object> result =
dataAnalysisService.countOneTaskStates(loginUser, taskCode);
return returnDataList(result);
}
/**
* statistics the workflow quantities of certain user
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return workflow count in project code
*/
@Operation(summary = "countDefinitionV2ByUserId", description = "COUNT_PROCESS_DEFINITION_V2_BY_USERID_NOTES")
@GetMapping(value = "/workflows/users/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result countDefinitionByUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestBody(required = false) StatisticsStateRequest statisticsStateRequest) {
String projectName = statisticsStateRequest.getProjectName();
Long projectCode = statisticsStateRequest.getProjectCode();
if (null == projectCode && !StringUtils.isBlank(projectName)) {
projectCode = dataAnalysisService.getProjectCodeByName(projectName);
}
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, projectCode, null, null);
return returnDataList(result);
}
/**
* statistics the workflow quantities of certain userId
* @param loginUser login user
* @param userId userId
* @return workflow count in project code
*/
@Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
@GetMapping(value = "/workflows/users/{userId}/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result countDefinitionByUserId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("userId") Integer userId) {
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null);
return returnDataList(result);
}
/**
* statistics the workflow quantities of certain userId and releaseState
* @param loginUser login user
* @param userId userId
* @param releaseState releaseState
* @return workflow count in project code
*/
@Operation(summary = "countDefinitionV2ByUser", description = "COUNT_PROCESS_DEFINITION_V2_BY_USER_NOTES")
@GetMapping(value = "/workflows/users/{userId}/{releaseState}/count")
@ResponseStatus(HttpStatus.OK)
@ApiException(COUNT_PROCESS_DEFINITION_USER_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result countDefinitionByUserState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("userId") Integer userId,
@PathVariable("releaseState") Integer releaseState) {
Map<String, Object> result = dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, releaseState);
return returnDataList(result);
}
}

60
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/StatisticsStateRequest.java

@ -0,0 +1,60 @@
/*
* 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.dto.project;
import java.util.Date;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StatisticsStateRequest {
@Schema(name = "isAll", example = "true")
boolean isAll;
@Schema(name = "projectName", example = "PROJECT-NAME")
String projectName;
@Schema(name = "projectCode", example = "1234567890")
Long projectCode;
@Schema(name = "workflowName", example = "WORKFLOW-NAME")
String workflowName;
@Schema(name = "workflowCode", example = "1234567890")
Long workflowCode;
@Schema(name = "taskName", example = "TASK-NAME")
String taskName;
@Schema(name = "taskCode", example = "1234567890")
Long taskCode;
@Schema(name = "startDate", example = "2022-01-01 10:01:02")
Date startTime;
@Schema(name = "endDate", example = "2022-01-02 10:01:02")
Date endTime;
}

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@ -171,6 +171,11 @@ public enum Status {
SAVE_ERROR(10136, "save error", "保存错误"), SAVE_ERROR(10136, "save error", "保存错误"),
DELETE_PROJECT_ERROR_DEFINES_NOT_NULL(10137, "please delete the process definitions in project first!", DELETE_PROJECT_ERROR_DEFINES_NOT_NULL(10137, "please delete the process definitions in project first!",
"请先删除全部工作流定义"), "请先删除全部工作流定义"),
QUERY_ALL_WORKFLOW_COUNT_ERROR(10138, "query all workflow count error", "查询所有工作流数量错误"),
QUERY_WORKFLOW_STATES_COUNT_ERROR(10139, "query all workflow states count error", "查询所有工作流状态数量错误"),
QUERY_ONE_WORKFLOW_STATE_COUNT_ERROR(10140, "query one workflow state count error", "查询工作流状态数量错误"),
QUERY_TASK_STATES_COUNT_ERROR(10141, "query all task states count error", "查询所有任务状态数量错误"),
QUERY_ONE_TASK_STATES_COUNT_ERROR(10142, "query one task states count error", "查询任务状态数量错误"),
BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR(10117, "batch delete process instance by ids {0} error", BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR(10117, "batch delete process instance by ids {0} error",
"批量删除工作流实例错误: {0}"), "批量删除工作流实例错误: {0}"),
PREVIEW_SCHEDULE_ERROR(10139, "preview schedule error", "预览调度配置错误"), PREVIEW_SCHEDULE_ERROR(10139, "preview schedule error", "预览调度配置错误"),

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

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
@ -61,9 +62,21 @@ public interface DataAnalysisService {
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @return definition count data * @return workflow count data
*/ */
Map<String, Object> countDefinitionByUser(User loginUser, long projectCode); Map<String, Object> 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
*/
Map<String, Object> countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId, Integer releaseState);
/** /**
* statistical command status data * statistical command status data
@ -94,4 +107,46 @@ public interface DataAnalysisService {
List<ExecuteStatusCount> countTaskInstanceAllStatesByProjectCodes(@Param("startTime") Date startTime, List<ExecuteStatusCount> countTaskInstanceAllStatesByProjectCodes(@Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes); @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
* @param statisticsStateRequest statisticsStateRequest
* @return workflow states count
*/
Map<String, Object> countWorkflowStates(User loginUser,
StatisticsStateRequest statisticsStateRequest);
/**
* query one workflow states count
* @param loginUser login user
* @param workflowCode workflowCode
* @return workflow states count
*/
Map<String, Object> countOneWorkflowStates(User loginUser, Long workflowCode);
/**
* query all task states count
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return tasks states count
*/
Map<String, Object> countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest);
/**
* query one task states count
* @param loginUser login user
* @param taskCode taskCode
* @return tasks states count
*/
Map<String, Object> countOneTaskStates(User loginUser, Long taskCode);
Long getProjectCodeByName(String projectName);
} }

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java

@ -203,5 +203,4 @@ public interface ProjectService {
* @return project list * @return project list
*/ */
Result queryAllProjectListForDependent(); Result queryAllProjectListForDependent();
} }

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

@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
import org.apache.dolphinscheduler.api.dto.CommandStateCount; import org.apache.dolphinscheduler.api.dto.CommandStateCount;
import org.apache.dolphinscheduler.api.dto.DefineUserDto; import org.apache.dolphinscheduler.api.dto.DefineUserDto;
import org.apache.dolphinscheduler.api.dto.TaskCountDto; import org.apache.dolphinscheduler.api.dto.TaskCountDto;
import org.apache.dolphinscheduler.api.dto.project.StatisticsStateRequest;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.DataAnalysisService; import org.apache.dolphinscheduler.api.service.DataAnalysisService;
import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.ProjectService;
@ -35,21 +36,24 @@ import org.apache.dolphinscheduler.dao.entity.CommandCount;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.CommandMapper; import org.apache.dolphinscheduler.dao.mapper.CommandMapper;
import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper; import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -94,8 +98,10 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
private TaskInstanceMapper taskInstanceMapper; private TaskInstanceMapper taskInstanceMapper;
@Autowired @Autowired
private ProcessService processService; private TaskDefinitionMapper taskDefinitionMapper;
@Autowired
private ProcessTaskRelationMapper relationMapper;
/** /**
* statistical task instance status data * statistical task instance status data
* *
@ -353,4 +359,269 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return startTimeStates.orElse(null); 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(), logger);
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);
}
result.put("data", "AllWorkflowCounts = " + count);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* query all workflow states count
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return workflow states count
*/
@Override
public Map<String, Object> countWorkflowStates(User loginUser,
StatisticsStateRequest statisticsStateRequest) {
Map<String, Object> result = new HashMap<>();
Set<Integer> projectIds = resourcePermissionCheckService
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
if (projectIds.isEmpty()) {
putMsg(result, Status.SUCCESS);
return result;
}
String projectName = statisticsStateRequest.getProjectName();
String workflowName = statisticsStateRequest.getWorkflowName();
Long projectCode = statisticsStateRequest.getProjectCode();
Long workflowCode = statisticsStateRequest.getWorkflowCode();
Integer model = Constants.QUERY_ALL_ON_SYSTEM;
if (!StringUtils.isBlank(projectName) || null != projectCode) {
model = Constants.QUERY_ALL_ON_PROJECT;
}
if (!StringUtils.isBlank(workflowName) || null != workflowCode) {
model = Constants.QUERY_ALL_ON_WORKFLOW;
}
try {
if (null == workflowCode || null == projectCode) {
projectCode = projectMapper.queryByName(projectName).getCode();
workflowCode = processDefinitionMapper.queryByDefineName(projectCode, workflowName).getCode();
}
} catch (Exception e) {
logger.warn(e.getMessage());
}
Date date = new Date();
Date startTime = statisticsStateRequest.getStartTime() == null ? DateUtils.addMonths(date, -1)
: statisticsStateRequest.getStartTime();
Date endTime = statisticsStateRequest.getEndTime() == null ? date : statisticsStateRequest.getEndTime();
List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
startTime, endTime, projectCode, workflowCode, model, projectIds);
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* query one workflow states count
* @param loginUser login user
* @param workflowCode workflowCode
* @return workflow states count
*/
@Override
public Map<String, Object> countOneWorkflowStates(User loginUser, Long workflowCode) {
Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByCode(workflowCode);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) {
return result;
}
List<ExecuteStatusCount> executeStatusCounts = processInstanceMapper.countInstanceStateV2(
null, null, null, workflowCode, Constants.QUERY_ALL_ON_WORKFLOW, null);
if (executeStatusCounts != null) {
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
}
return result;
}
/**
* query all task states count
* @param loginUser login user
* @param statisticsStateRequest statisticsStateRequest
* @return tasks states count
*/
@Override
public Map<String, Object> countTaskStates(User loginUser, StatisticsStateRequest statisticsStateRequest) {
Map<String, Object> result = new HashMap<>();
Set<Integer> projectIds = resourcePermissionCheckService
.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
if (projectIds.isEmpty()) {
putMsg(result, Status.SUCCESS);
return result;
}
String projectName = statisticsStateRequest.getProjectName();
String workflowName = statisticsStateRequest.getWorkflowName();
String taskName = statisticsStateRequest.getTaskName();
Long projectCode = statisticsStateRequest.getProjectCode();
Long workflowCode = statisticsStateRequest.getWorkflowCode();
Long taskCode = statisticsStateRequest.getTaskCode();
Integer model = Constants.QUERY_ALL_ON_SYSTEM;
if (!StringUtils.isBlank(projectName) || null != projectCode) {
model = Constants.QUERY_ALL_ON_PROJECT;
}
if (!StringUtils.isBlank(workflowName) || null != workflowCode) {
model = Constants.QUERY_ALL_ON_WORKFLOW;
}
if (!StringUtils.isBlank(taskName) || null != taskCode) {
model = Constants.QUERY_ALL_ON_TASK;
}
try {
if (null == taskCode || null == workflowCode || null == projectCode) {
projectCode = projectMapper.queryByName(projectName).getCode();
workflowCode = processDefinitionMapper.queryByDefineName(projectCode, workflowName).getCode();
// todo The comment can be canceled after repairing the duplicate taskname of the existing workflow
// taskCode = relationMapper.queryTaskCodeByTaskName(workflowCode, taskName);
}
} catch (Exception e) {
logger.warn(e.getMessage());
}
Date date = new Date();
Date startTime = statisticsStateRequest.getStartTime() == null ? DateUtils.addMonths(date, -1)
: statisticsStateRequest.getStartTime();
Date endTime = statisticsStateRequest.getEndTime() == null ? date : statisticsStateRequest.getEndTime();
Optional<List<ExecuteStatusCount>> startTimeStates = Optional.ofNullable(
taskInstanceMapper.countTaskInstanceStateByProjectIdsV2(startTime, endTime, projectIds));
List<TaskExecutionStatus> needRecountState = setOptional(startTimeStates);
if (needRecountState.size() == 0) {
TaskCountDto taskCountResult = new TaskCountDto(startTimeStates.get());
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
return result;
}
List<ExecuteStatusCount> recounts = this.taskInstanceMapper
.countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2(startTime, endTime, projectCode,
workflowCode, taskCode, model, projectIds,
needRecountState);
startTimeStates.orElseGet(ArrayList::new).addAll(recounts);
List<ExecuteStatusCount> executeStatusCounts = startTimeStates.orElse(null);
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* query one task states count
* @param loginUser login user
* @param taskCode taskCode
* @return tasks states count
*/
@Override
public Map<String, Object> countOneTaskStates(User loginUser, Long taskCode) {
Map<String, Object> result = new HashMap<>();
TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode);
long projectCode = taskDefinition.getProjectCode();
Project project = projectMapper.queryByCode(projectCode);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) {
return result;
}
Set<Integer> projectId = Collections.singleton(project.getId());
Optional<List<ExecuteStatusCount>> startTimeStates = Optional.ofNullable(
taskInstanceMapper.countTaskInstanceStateByProjectIdsV2(null, null, projectId));
List<TaskExecutionStatus> needRecountState = setOptional(startTimeStates);
if (needRecountState.size() == 0) {
TaskCountDto taskCountResult = new TaskCountDto(startTimeStates.get());
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
return result;
}
List<ExecuteStatusCount> recounts = this.taskInstanceMapper
.countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2(null, null, projectCode, null, taskCode,
Constants.QUERY_ALL_ON_TASK, projectId,
needRecountState);
startTimeStates.orElseGet(ArrayList::new).addAll(recounts);
List<ExecuteStatusCount> executeStatusCounts = startTimeStates.orElse(null);
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
return result;
}
/**
* 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 Map<String, Object> countDefinitionByUserV2(User loginUser, Long projectCode, Integer userId,
Integer releaseState) {
Map<String, Object> result = new HashMap<>();
if (null != projectCode) {
Project project = projectMapper.queryByCode(projectCode);
result = projectService.checkProjectAndAuth(loginUser, project, projectCode, PROJECT_OVERVIEW);
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
}
}
List<DefinitionGroupByUser> defineGroupByUsers = new ArrayList<>();
Pair<Set<Integer>, Map<String, Object>> projectIds = getProjectIds(loginUser, result);
if (projectIds.getRight() != null) {
List<DefinitionGroupByUser> emptyList = new ArrayList<>();
DefineUserDto dto = new DefineUserDto(emptyList);
result.put(Constants.DATA_LIST, dto);
putMsg(result, Status.SUCCESS);
return result;
}
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);
}
DefineUserDto dto = new DefineUserDto(defineGroupByUsers);
result.put(Constants.DATA_LIST, dto);
putMsg(result, Status.SUCCESS);
return result;
}
@Override
public Long getProjectCodeByName(String projectName) {
Project project = projectMapper.queryByName(projectName);
return project == null ? 0 : project.getCode();
}
private List<TaskExecutionStatus> setOptional(Optional<List<ExecuteStatusCount>> startTimeStates) {
List<TaskExecutionStatus> allState = Arrays.stream(TaskExecutionStatus.values()).collect(Collectors.toList());
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
return allState.stream().filter(ele -> !instanceState.contains(ele)).collect(Collectors.toList());
} else {
return allState;
}
}
} }

45
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java

@ -17,9 +17,7 @@
package org.apache.dolphinscheduler.api.service.impl; package org.apache.dolphinscheduler.api.service.impl;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.*;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_CREATE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_DELETE;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.exceptions.ServiceException;
@ -90,8 +88,8 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
* create project * create project
* *
* @param loginUser login user * @param loginUser login user
* @param name project name * @param name project name
* @param desc description * @param desc description
* @return returns an error if it exists * @return returns an error if it exists
*/ */
@Override @Override
@ -331,8 +329,8 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
* *
* @param loginUser login user * @param loginUser login user
* @param searchVal search value * @param searchVal search value
* @param pageSize page size * @param pageSize page size
* @param pageNo page number * @param pageNo page number
* @return project list which the login user have permission to see * @return project list which the login user have permission to see
*/ */
@Override @Override
@ -366,11 +364,11 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* admin can view all projects * admin can view all projects
* *
* @param userId user id * @param userId user id
* @param loginUser login user * @param loginUser login user
* @param searchVal search value * @param searchVal search value
* @param pageSize page size * @param pageSize page size
* @param pageNo page number * @param pageNo page number
* @return project list which with the login user's authorized level * @return project list which with the login user's authorized level
*/ */
@Override @Override
@ -417,7 +415,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* delete project by code * delete project by code
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @return delete result code * @return delete result code
*/ */
@ -462,7 +460,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
* get check result * get check result
* *
* @param loginUser login user * @param loginUser login user
* @param project project * @param project project
* @return check result * @return check result
*/ */
private Map<String, Object> getCheckResult(User loginUser, Project project, String perm) { private Map<String, Object> getCheckResult(User loginUser, Project project, String perm) {
@ -478,11 +476,11 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* updateProcessInstance project * updateProcessInstance project
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @param projectName project name * @param projectName project name
* @param desc description * @param desc description
* @param userName project owner * @param userName project owner
* @return update result code * @return update result code
*/ */
@Override @Override
@ -528,6 +526,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* query all project with authorized level * query all project with authorized level
*
* @param loginUser login user * @param loginUser login user
* @return project list * @return project list
*/ */
@ -571,7 +570,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
* query unauthorized project * query unauthorized project
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @return the projects which user have not permission to see * @return the projects which user have not permission to see
*/ */
@Override @Override
@ -606,7 +605,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* get unauthorized project * get unauthorized project
* *
* @param projectSet project set * @param projectSet project set
* @param authedProjectList authed project list * @param authedProjectList authed project list
* @return project list that unauthorized * @return project list that unauthorized
*/ */
@ -625,7 +624,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
* query authorized project * query authorized project
* *
* @param loginUser login user * @param loginUser login user
* @param userId user id * @param userId user id
* @return projects which the user have permission to see, Except for items created by this user * @return projects which the user have permission to see, Except for items created by this user
*/ */
@Override @Override
@ -642,8 +641,8 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* query authorized user * query authorized user
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @return users who have permission for the specified project * @return users who have permission for the specified project
*/ */
@Override @Override
@ -709,7 +708,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* check whether have read permission * check whether have read permission
* *
* @param user user * @param user user
* @param project project * @param project project
* @return true if the user have permission to see the project, otherwise return false * @return true if the user have permission to see the project, otherwise return false
*/ */
@ -721,7 +720,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* query permission id * query permission id
* *
* @param user user * @param user user
* @param project project * @param project project
* @return permission * @return permission
*/ */
@ -746,6 +745,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* query all project list * query all project list
*
* @param user * @param user
* @return project list * @return project list
*/ */
@ -798,5 +798,4 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
} }

171
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/StatisticsV2ControllerTest.java

@ -0,0 +1,171 @@
/*
* 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.controller;
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.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
public class StatisticsV2ControllerTest extends AbstractControllerTest {
@InjectMocks
private StatisticsV2Controller statisticsV2Controller;
@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);
Mockito.when(dataAnalysisService.queryAllWorkflowCounts(loginUser)).thenReturn(result);
Result result1 = statisticsV2Controller.queryWorkflowInstanceCounts(loginUser);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testQueryWorkflowStatesCounts() {
User loginUser = getLoginUser();
Map<String, Object> result = new HashMap<>();
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countWorkflowStates(loginUser, statisticsStateRequest)).thenReturn(result);
Result result1 = statisticsV2Controller.queryWorkflowStatesCounts(loginUser, statisticsStateRequest);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testQueryOneWorkflowStates() {
User loginUser = getLoginUser();
Long workflowCode = 1L;
Map<String, Object> result = new HashMap<>();
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countOneWorkflowStates(loginUser, workflowCode)).thenReturn(result);
Result result1 = statisticsV2Controller.queryOneWorkflowStates(loginUser, workflowCode);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testQueryTaskStatesCounts() {
User loginUser = getLoginUser();
Map<String, Object> result = new HashMap<>();
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countTaskStates(loginUser, statisticsStateRequest)).thenReturn(result);
Result result1 = statisticsV2Controller.queryTaskStatesCounts(loginUser, statisticsStateRequest);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testQueryOneTaskStatesCounts() {
User loginUser = getLoginUser();
Long taskCode = 1L;
Map<String, Object> result = new HashMap<>();
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countOneTaskStates(loginUser, taskCode)).thenReturn(result);
Result result1 = statisticsV2Controller.queryOneTaskStatesCounts(loginUser, taskCode);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testCountDefinitionByUser() {
User loginUser = getLoginUser();
Map<String, Object> result = new HashMap<>();
StatisticsStateRequest statisticsStateRequest = new StatisticsStateRequest();
List<ExecuteStatusCount> executeStatusCounts = new ArrayList<>();
TaskCountDto taskCountResult = new TaskCountDto(executeStatusCounts);
result.put(Constants.DATA_LIST, taskCountResult);
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countDefinitionByUserV2(loginUser, statisticsStateRequest.getProjectCode(),
null, null)).thenReturn(result);
Result result1 = statisticsV2Controller.countDefinitionByUser(loginUser, statisticsStateRequest);
Assertions.assertTrue(result1.isSuccess());
}
@Test
public void testCountDefinitionByUserId() {
User loginUser = getLoginUser();
Map<String, Object> result = new HashMap<>();
Integer userId = 1;
putMsg(result, Status.SUCCESS);
Mockito.when(dataAnalysisService.countDefinitionByUserV2(loginUser, null, userId, null)).thenReturn(result);
Result result1 = statisticsV2Controller.countDefinitionByUserId(loginUser, userId);
Assertions.assertTrue(result1.isSuccess());
}
private User getLoginUser() {
User user = new User();
user.setId(1);
user.setUserName("admin");
return user;
}
}

5
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/Constants.java

@ -802,4 +802,9 @@ public final class Constants {
public static final String KERBEROS_KRB5_CONF_PATH = "javaSecurityKrb5Conf"; public static final String KERBEROS_KRB5_CONF_PATH = "javaSecurityKrb5Conf";
public static final String KERBEROS_KEY_TAB_USERNAME = "loginUserKeytabUsername"; public static final String KERBEROS_KEY_TAB_USERNAME = "loginUserKeytabUsername";
public static final String KERBEROS_KEY_TAB_PATH = "loginUserKeytabPath"; public static final String KERBEROS_KEY_TAB_PATH = "loginUserKeytabPath";
public static final Integer QUERY_ALL_ON_SYSTEM = 0;
public static final Integer QUERY_ALL_ON_PROJECT = 1;
public static final Integer QUERY_ALL_ON_WORKFLOW = 2;
public static final Integer QUERY_ALL_ON_TASK = 3;
} }

27
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DefinitionGroupByUser.java

@ -17,9 +17,12 @@
package org.apache.dolphinscheduler.dao.entity; package org.apache.dolphinscheduler.dao.entity;
import lombok.Data;
/** /**
* count definition number group by user * count definition number group by user
*/ */
@Data
public class DefinitionGroupByUser { public class DefinitionGroupByUser {
/** /**
@ -36,28 +39,4 @@ public class DefinitionGroupByUser {
* count number * count number
*/ */
private int count; private int count;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
} }

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

@ -168,6 +168,20 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
*/ */
List<DefinitionGroupByUser> countDefinitionByProjectCodes(@Param("projectCodes") Long[] projectCodes); List<DefinitionGroupByUser> countDefinitionByProjectCodes(@Param("projectCodes") Long[] projectCodes);
/**
* Statistics process definition group by project codes list
* <p>
* We only need project codes to determine whether the definition belongs to the user or not.
*
* @param projectCodes projectCodes
* @param userId userId
* @param releaseState releaseState
* @return definition group by user
*/
List<DefinitionGroupByUser> countDefinitionByProjectCodesV2(@Param("projectCodes") Long[] projectCodes,
@Param("userId") Integer userId,
@Param("releaseState") Integer releaseState);
/** /**
* list all resource ids * list all resource ids
* *

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

@ -25,6 +25,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -287,4 +288,25 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
@Param("state") Integer state, @Param("state") Integer state,
@Param("host") String host); @Param("host") String host);
/**
* Statistics process instance state v2
* <p>
* We only need project codes to determine whether the process instance belongs to the user or not.
*
* @param startTime startTime
* @param endTime endTime
* @param projectCode projectCode
* @param workflowCode workflowCode
* @param model model
* @param projectIds projectIds
* @return ExecuteStatusCount list
*/
List<ExecuteStatusCount> countInstanceStateV2(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCode") Long projectCode,
@Param("workflowCode") Long workflowCode,
@Param("model") Integer model,
@Param("projectIds") Set<Integer> projectIds);
} }

3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java

@ -219,4 +219,7 @@ public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelatio
* @return update num * @return update num
*/ */
int updateProcessTaskRelationTaskVersion(@Param("processTaskRelation") ProcessTaskRelation processTaskRelationList); int updateProcessTaskRelationTaskVersion(@Param("processTaskRelation") ProcessTaskRelation processTaskRelationList);
Long queryTaskCodeByTaskName(@Param("workflowCode") Long workflowCode,
@Param("taskName") String taskName);
} }

7
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java

@ -150,4 +150,11 @@ public interface ProjectMapper extends BaseMapper<Project> {
* @return project * @return project
*/ */
Project queryProjectByTaskInstanceId(@Param("taskInstanceId") int taskInstanceId); Project queryProjectByTaskInstanceId(@Param("taskInstanceId") int taskInstanceId);
/**
* query all workflow count
* @param projectsCodes projectsCodes
* @return workflow count
*/
int queryAllWorkflowCounts(@Param("projectsCodes") List<Long> projectsCodes);
} }

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

@ -27,6 +27,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -76,6 +77,20 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes); @Param("projectCodes") Long[] projectCodes);
/**
* Statistics task instance group by given project ids list by start time
* <p>
* We only need project ids to determine whether the task instance belongs to the user or not.
*
* @param startTime Statistics start time
* @param endTime Statistics end time
* @param projectIds Project ids list to filter
* @return List of ExecuteStatusCount
*/
List<ExecuteStatusCount> countTaskInstanceStateByProjectIdsV2(@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectIds") Set<Integer> projectIds);
/** /**
* Statistics task instance group by given project codes list by submit time * Statistics task instance group by given project codes list by submit time
* <p> * <p>
@ -90,6 +105,26 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
@Param("projectCodes") Long[] projectCodes, @Param("projectCodes") Long[] projectCodes,
@Param("states") List<TaskExecutionStatus> states); @Param("states") List<TaskExecutionStatus> states);
/**
* Statistics task instance group by given project codes list by submit time
* <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 projectCode projectCode
* @param model model
* @param projectIds projectIds
* @return List of ExecuteStatusCount
*/
List<ExecuteStatusCount> countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2(@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCode") Long projectCode,
@Param("workflowCode") Long workflowCode,
@Param("taskCode") Long taskCode,
@Param("model") Integer model,
@Param("projectIds") Set<Integer> projectIds,
@Param("states") List<TaskExecutionStatus> states);
IPage<TaskInstance> queryTaskInstanceListPaging(IPage<TaskInstance> page, IPage<TaskInstance> queryTaskInstanceListPaging(IPage<TaskInstance> page,
@Param("projectCode") Long projectCode, @Param("projectCode") Long projectCode,

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

@ -151,6 +151,24 @@
</foreach> </foreach>
</if> </if>
group by td.user_id,tu.user_name group by td.user_id,tu.user_name
</select><select id="countDefinitionByProjectCodesV2" resultType="org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser">
SELECT 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">
and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="userId != null">
and td.user_id = #{userId}
</if>
<if test="releaseState != null">
and td.release_state = #{releaseState}
</if>
group by td.user_id,tu.user_name
</select> </select>
<select id="queryByDefineId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition"> <select id="queryByDefineId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">

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

@ -308,6 +308,30 @@
</if> </if>
order by instance.start_time desc,instance.id desc order by instance.start_time desc,instance.id desc
</select> </select>
<select id="countInstanceStateV2" 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
join t_ds_project p on p.code=d.project_code
where 1 = 1
and t.is_sub_process = 0
<if test="projectIds != null and projectIds.size() != 0">
and p.id in
<foreach collection="projectIds" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="model >= 1">
and p.code = #{projectCode}
</if>
<if test="model >= 2">
and d.code = #{workflowCode}
</if>
group by t.state
</select>
<update id="updateGlobalParamsById"> <update id="updateGlobalParamsById">
update t_ds_process_instance update t_ds_process_instance
set global_params = #{globalParams} set global_params = #{globalParams}

7
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml

@ -221,6 +221,13 @@
</where> </where>
order by update_time desc, id asc order by update_time desc, id asc
</select> </select>
<select id="queryTaskCodeByTaskName" resultType="java.lang.Long">
select r.post_task_code
from t_ds_process_task_relation r
left join t_ds_task_definition d on d.code = r.post_task_code
where r.process_definition_code = #{workflowCode}
and d.name = #{taskName}
</select>
<update id="updateProcessTaskRelationTaskVersion"> <update id="updateProcessTaskRelationTaskVersion">
update t_ds_process_task_relation update t_ds_process_task_relation
set set

10
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

@ -197,4 +197,14 @@
join t_ds_project p on p.code = pd.project_code join t_ds_project p on p.code = pd.project_code
where ti.id = #{taskInstanceId} where ti.id = #{taskInstanceId}
</select> </select>
<select id="queryAllWorkflowCounts" resultType="java.lang.Integer">
SELECT COUNT(*) FROM t_ds_process_definition
where 1=1
<if test="projectsCodes != null and projectsCodes.size() > 0">
and project_code in
<foreach item="code" index="index" collection="projectsCodes" open="(" separator="," close=")">
#{code}
</foreach>
</if>
</select>
</mapper> </mapper>

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

@ -92,6 +92,26 @@
</if> </if>
group by t.state group by t.state
</select> </select>
<select id="countTaskInstanceStateByProjectIdsV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
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
where 1=1
<if test="projectIds != null and projectIds.size() != 0">
and d.id in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="startTime != null">
and t.start_time <![CDATA[ > ]]> #{startTime}
</if>
<if test="endTime != null">
and t.start_time <![CDATA[ <= ]]> #{endTime}
</if>
group by t.state
</select>
<select id="countTaskInstanceStateByProjectCodesAndStatesBySubmitTime" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount"> <select id="countTaskInstanceStateByProjectCodesAndStatesBySubmitTime" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select select
state, count(0) as count state, count(0) as count
@ -119,6 +139,43 @@
</if> </if>
group by t.state group by t.state
</select> </select>
<select id="countTaskInstanceStateByProjectCodesAndStatesBySubmitTimeV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
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
left join t_ds_process_task_relation r on r.post_task_code = d.code
where 1=1
<if test="states != null and states.size != 0">
and t.state in
<foreach collection="states" index="index" item="state" open="(" separator="," close=")">
#{state.code}
</foreach>
</if>
<if test="projectIds != null and projectIds.size() != 0">
and p.id in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="startTime != null">
and t.submit_time <![CDATA[ > ]]> #{startTime}
</if>
<if test="endTime != null">
and t.submit_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="model == 1 and projectCode !=null">
and p.code = #{projectCode}
</if>
<if test="model == 2 and workflowCode !=null">
and r.process_definition_code = #{workflowCode}
</if>
<if test="model == 3 and taskCode !=null">
and t.task_code = #{taskCode}
</if>
group by t.state
</select>
<select id="queryByInstanceIdAndName" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance"> <select id="queryByInstanceIdAndName" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select select
<include refid="baseSql"/> <include refid="baseSql"/>

Loading…
Cancel
Save