Skip to content

Commit 9088e42

Browse files
authored
Merge 94301ee into 9e6f4d2
2 parents 9e6f4d2 + 94301ee commit 9088e42

10 files changed

Lines changed: 410 additions & 44 deletions

File tree

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
3333
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
3434

35-
import java.util.Map;
36-
3735
import org.springframework.beans.factory.annotation.Autowired;
3836
import org.springframework.http.HttpStatus;
3937
import org.springframework.web.bind.annotation.GetMapping;
@@ -141,11 +139,10 @@ public Result queryTaskListPaging(@Parameter(hidden = true) @RequestAttribute(va
141139
@ResponseStatus(HttpStatus.OK)
142140
@ApiException(FORCE_TASK_SUCCESS_ERROR)
143141
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
144-
public Result<Object> forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
145-
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
146-
@PathVariable(value = "id") Integer id) {
147-
Map<String, Object> result = taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
148-
return returnDataList(result);
142+
public Result forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
143+
@Schema(name = "projectCode", required = true) @PathVariable long projectCode,
144+
@PathVariable(value = "id") Integer id) {
145+
return taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
149146
}
150147

151148
/**
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.dto.taskInstance;
19+
20+
import org.apache.dolphinscheduler.api.utils.PageInfo;
21+
import org.apache.dolphinscheduler.api.utils.Result;
22+
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
23+
24+
import lombok.Data;
25+
26+
/**
27+
* task instance list paging response
28+
*/
29+
@Data
30+
public class TaskInstanceListPagingResponse extends Result {
31+
32+
private PageInfo<TaskInstance> data;
33+
34+
public TaskInstanceListPagingResponse(Result result) {
35+
super();
36+
this.setCode(result.getCode());
37+
this.setMsg(result.getMsg());
38+
this.setData(result.getData());
39+
}
40+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.dto.taskInstance;
19+
20+
import org.apache.dolphinscheduler.api.dto.PageQueryDto;
21+
import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
22+
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
23+
24+
import lombok.Data;
25+
26+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
27+
import com.fasterxml.jackson.annotation.JsonInclude;
28+
import io.swagger.v3.oas.annotations.media.Schema;
29+
30+
/**
31+
* task instance request
32+
*/
33+
@JsonIgnoreProperties(ignoreUnknown = true)
34+
@JsonInclude(JsonInclude.Include.NON_NULL)
35+
@Data
36+
public class TaskInstanceQueryRequest extends PageQueryDto {
37+
38+
@Schema(name = "processInstanceId", example = "PROCESS_INSTANCE_ID", defaultValue = "0")
39+
Integer processInstanceId;
40+
41+
@Schema(name = "processInstanceName", example = "PROCESS-INSTANCE-NAME")
42+
String processInstanceName;
43+
44+
@Schema(name = "processDefinitionName", example = "PROCESS-DEFINITION-NAME")
45+
String processDefinitionName;
46+
47+
@Schema(name = "searchVal", example = "SEARCH-VAL")
48+
String searchVal;
49+
50+
@Schema(name = "taskName", example = "TASK-NAME")
51+
String taskName;
52+
53+
@Schema(name = "executorName", example = "EXECUTOR-NAME")
54+
String executorName;
55+
56+
@Schema(name = "stateType", example = "STATE-TYPE")
57+
TaskExecutionStatus stateType;
58+
59+
@Schema(name = "host", example = "HOST")
60+
String host;
61+
62+
@Schema(name = "startDate", example = "START-TIME")
63+
String startTime;
64+
65+
@Schema(name = "endDate", example = "END-DATE")
66+
String endTime;
67+
68+
@Schema(name = "taskExecuteType", example = "EXECUTE-TYPE", defaultValue = "BATCH")
69+
TaskExecuteType taskExecuteType;
70+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.dto.taskInstance;
19+
20+
import org.apache.dolphinscheduler.api.utils.Result;
21+
22+
import lombok.Data;
23+
24+
/**
25+
* task instance success response
26+
*/
27+
@Data
28+
public class TaskInstanceSuccessResponse extends Result {
29+
30+
public TaskInstanceSuccessResponse(Result result) {
31+
super();
32+
this.setCode(result.getCode());
33+
this.setMsg(result.getMsg());
34+
this.setData(result.getData());
35+
}
36+
}

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.apache.dolphinscheduler.dao.entity.User;
2323
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
2424

25-
import java.util.Map;
26-
2725
/**
2826
* task instance service
2927
*/
@@ -70,9 +68,9 @@ Result queryTaskListPaging(User loginUser,
7068
* @param taskInstanceId task instance id
7169
* @return the result code and msg
7270
*/
73-
Map<String, Object> forceTaskSuccess(User loginUser,
74-
long projectCode,
75-
Integer taskInstanceId);
71+
Result forceTaskSuccess(User loginUser,
72+
long projectCode,
73+
Integer taskInstanceId);
7674

7775
/**
7876
* task savepoint

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
9696
/**
9797
* query task list by project, process instance, task name, task start time, task end time, task status, keyword paging
9898
*
99-
* @param loginUser login user
100-
* @param projectCode project code
99+
* @param loginUser login user
100+
* @param projectCode project code
101101
* @param processInstanceId process instance id
102-
* @param searchVal search value
103-
* @param taskName task name
104-
* @param stateType state type
105-
* @param host host
106-
* @param startDate start time
107-
* @param endDate end time
108-
* @param pageNo page number
109-
* @param pageSize page size
102+
* @param searchVal search value
103+
* @param taskName task name
104+
* @param stateType state type
105+
* @param host host
106+
* @param startDate start time
107+
* @param endDate end time
108+
* @param pageNo page number
109+
* @param pageSize page size
110110
* @return task list page
111111
*/
112112
@Override
@@ -186,19 +186,22 @@ public Result queryTaskListPaging(User loginUser,
186186
/**
187187
* change one task instance's state from failure to forced success
188188
*
189-
* @param loginUser login user
190-
* @param projectCode project code
189+
* @param loginUser login user
190+
* @param projectCode project code
191191
* @param taskInstanceId task instance id
192192
* @return the result code and msg
193193
*/
194194
@Transactional
195195
@Override
196-
public Map<String, Object> forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {
196+
public Result forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {
197+
Result result = new Result();
197198
Project project = projectMapper.queryByCode(projectCode);
198199
// check user access for project
199-
Map<String, Object> result =
200+
Map<String, Object> checkResult =
200201
projectService.checkProjectAndAuth(loginUser, project, projectCode, FORCED_SUCCESS);
201-
if (result.get(Constants.STATUS) != Status.SUCCESS) {
202+
Status status = (Status) checkResult.get(Constants.STATUS);
203+
if (status != Status.SUCCESS) {
204+
putMsg(result, status);
202205
return result;
203206
}
204207

0 commit comments

Comments
 (0)