|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.dolphinscheduler.api.controller; |
| 19 | + |
| 20 | +import static org.apache.dolphinscheduler.api.enums.Status.FORCE_TASK_SUCCESS_ERROR; |
| 21 | +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR; |
| 22 | + |
| 23 | +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
| 24 | +import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceListPagingResponse; |
| 25 | +import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceQueryRequest; |
| 26 | +import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceSuccessResponse; |
| 27 | +import org.apache.dolphinscheduler.api.exceptions.ApiException; |
| 28 | +import org.apache.dolphinscheduler.api.service.TaskInstanceService; |
| 29 | +import org.apache.dolphinscheduler.api.utils.Result; |
| 30 | +import org.apache.dolphinscheduler.common.constants.Constants; |
| 31 | +import org.apache.dolphinscheduler.dao.entity.User; |
| 32 | +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; |
| 33 | +import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils; |
| 34 | + |
| 35 | +import org.springframework.beans.factory.annotation.Autowired; |
| 36 | +import org.springframework.http.HttpStatus; |
| 37 | +import org.springframework.web.bind.annotation.GetMapping; |
| 38 | +import org.springframework.web.bind.annotation.PathVariable; |
| 39 | +import org.springframework.web.bind.annotation.PostMapping; |
| 40 | +import org.springframework.web.bind.annotation.RequestAttribute; |
| 41 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 42 | +import org.springframework.web.bind.annotation.ResponseStatus; |
| 43 | +import org.springframework.web.bind.annotation.RestController; |
| 44 | + |
| 45 | +import io.swagger.v3.oas.annotations.Operation; |
| 46 | +import io.swagger.v3.oas.annotations.Parameter; |
| 47 | +import io.swagger.v3.oas.annotations.Parameters; |
| 48 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 49 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 50 | + |
| 51 | +/** |
| 52 | + * task instance controller |
| 53 | + */ |
| 54 | +@Tag(name = "TASK_INSTANCE_TAG") |
| 55 | +@RestController |
| 56 | +@RequestMapping("/v2/projects/{projectCode}/task-instances") |
| 57 | +public class TaskInstanceV2Controller extends BaseController { |
| 58 | + |
| 59 | + @Autowired |
| 60 | + private TaskInstanceService taskInstanceService; |
| 61 | + |
| 62 | + /** |
| 63 | + * query task list paging |
| 64 | + * |
| 65 | + * @param loginUser login user |
| 66 | + * @param projectCode project code |
| 67 | + * @param taskInstanceQueryReq taskInstanceQueryReq |
| 68 | + * @return task list page |
| 69 | + */ |
| 70 | + @Operation(summary = "queryTaskListPaging", description = "QUERY_TASK_INSTANCE_LIST_PAGING_NOTES") |
| 71 | + @Parameters({ |
| 72 | + @Parameter(name = "processInstanceId", description = "PROCESS_INSTANCE_ID", schema = @Schema(implementation = int.class), example = "100"), |
| 73 | + @Parameter(name = "processInstanceName", description = "PROCESS_INSTANCE_NAME", schema = @Schema(implementation = String.class)), |
| 74 | + @Parameter(name = "searchVal", description = "SEARCH_VAL", schema = @Schema(implementation = String.class)), |
| 75 | + @Parameter(name = "taskName", description = "TASK_NAME", schema = @Schema(implementation = String.class)), |
| 76 | + @Parameter(name = "executorName", description = "EXECUTOR_NAME", schema = @Schema(implementation = String.class)), |
| 77 | + @Parameter(name = "stateType", description = "EXECUTION_STATUS", schema = @Schema(implementation = TaskExecutionStatus.class)), |
| 78 | + @Parameter(name = "host", description = "HOST", schema = @Schema(implementation = String.class)), |
| 79 | + @Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)), |
| 80 | + @Parameter(name = "endDate", description = "END_DATE", schema = @Schema(implementation = String.class)), |
| 81 | + @Parameter(name = "taskExecuteType", description = "TASK_EXECUTE_TYPE", schema = @Schema(implementation = int.class), example = "STREAM"), |
| 82 | + @Parameter(name = "pageNo", description = "PAGE_NO", required = true, schema = @Schema(implementation = int.class), example = "1"), |
| 83 | + @Parameter(name = "pageSize", description = "PAGE_SIZE", required = true, schema = @Schema(implementation = int.class), example = "20"), |
| 84 | + }) |
| 85 | + @GetMapping(consumes = {"application/json"}) |
| 86 | + @ResponseStatus(HttpStatus.OK) |
| 87 | + @ApiException(QUERY_TASK_LIST_PAGING_ERROR) |
| 88 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 89 | + public TaskInstanceListPagingResponse queryTaskListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 90 | + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
| 91 | + TaskInstanceQueryRequest taskInstanceQueryReq) { |
| 92 | + Result result = checkPageParams(taskInstanceQueryReq.getPageNo(), taskInstanceQueryReq.getPageSize()); |
| 93 | + if (!result.checkResult()) { |
| 94 | + return new TaskInstanceListPagingResponse(result); |
| 95 | + } |
| 96 | + String searchVal = ParameterUtils.handleEscapes(taskInstanceQueryReq.getSearchVal()); |
| 97 | + result = taskInstanceService.queryTaskListPaging(loginUser, projectCode, |
| 98 | + taskInstanceQueryReq.getProcessInstanceId(), taskInstanceQueryReq.getProcessInstanceName(), |
| 99 | + taskInstanceQueryReq.getProcessDefinitionName(), |
| 100 | + taskInstanceQueryReq.getTaskName(), taskInstanceQueryReq.getExecutorName(), |
| 101 | + taskInstanceQueryReq.getStartTime(), taskInstanceQueryReq.getEndTime(), searchVal, |
| 102 | + taskInstanceQueryReq.getStateType(), taskInstanceQueryReq.getHost(), |
| 103 | + taskInstanceQueryReq.getTaskExecuteType(), taskInstanceQueryReq.getPageNo(), |
| 104 | + taskInstanceQueryReq.getPageSize()); |
| 105 | + return new TaskInstanceListPagingResponse(result); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * change one task instance's state from FAILURE to FORCED_SUCCESS |
| 110 | + * |
| 111 | + * @param loginUser login user |
| 112 | + * @param projectCode project code |
| 113 | + * @param id task instance id |
| 114 | + * @return the result code and msg |
| 115 | + */ |
| 116 | + @Operation(summary = "force-success", description = "FORCE_TASK_SUCCESS") |
| 117 | + @Parameters({ |
| 118 | + @Parameter(name = "id", description = "TASK_INSTANCE_ID", required = true, schema = @Schema(implementation = int.class), example = "12") |
| 119 | + }) |
| 120 | + @PostMapping(value = "/{id}/force-success", consumes = {"application/json"}) |
| 121 | + @ResponseStatus(HttpStatus.OK) |
| 122 | + @ApiException(FORCE_TASK_SUCCESS_ERROR) |
| 123 | + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
| 124 | + public TaskInstanceSuccessResponse forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
| 125 | + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
| 126 | + @PathVariable(value = "id") Integer id) { |
| 127 | + Result result = taskInstanceService.forceTaskSuccess(loginUser, projectCode, id); |
| 128 | + return new TaskInstanceSuccessResponse(result); |
| 129 | + } |
| 130 | +} |
0 commit comments