You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zi...@apache.org on 2022/11/16 10:32:52 UTC
[dolphinscheduler] branch dev updated: [Feature][Api] Refactor org.apache.dolphinscheduler.api.controller.TaskInstanceController (#11747)
This is an automated email from the ASF dual-hosted git repository.
zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 0186413a9f [Feature][Api] Refactor org.apache.dolphinscheduler.api.controller.TaskInstanceController (#11747)
0186413a9f is described below
commit 0186413a9f752bbe015f804a165b5f587232653a
Author: Zzih <46...@qq.com>
AuthorDate: Wed Nov 16 18:32:42 2022 +0800
[Feature][Api] Refactor org.apache.dolphinscheduler.api.controller.TaskInstanceController (#11747)
* Feature :Refactor org.apache.dolphinscheduler.api.controller.TaskInstanceController
---
.../api/controller/TaskInstanceController.java | 11 +-
.../api/controller/TaskInstanceV2Controller.java | 130 +++++++++++++++++++++
.../TaskInstanceListPagingResponse.java | 40 +++++++
.../dto/taskInstance/TaskInstanceQueryRequest.java | 70 +++++++++++
.../taskInstance/TaskInstanceSuccessResponse.java | 36 ++++++
.../api/service/TaskInstanceService.java | 8 +-
.../api/service/impl/TaskInstanceServiceImpl.java | 33 +++---
.../api/controller/TaskInstanceControllerTest.java | 9 +-
.../controller/TaskInstanceV2ControllerTest.java | 95 +++++++++++++++
.../api/service/TaskInstanceServiceTest.java | 22 ++--
10 files changed, 410 insertions(+), 44 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java
index 18b697a4df..b9fabb0f32 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java
@@ -32,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
-import java.util.Map;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@@ -141,11 +139,10 @@ public class TaskInstanceController extends BaseController {
@ResponseStatus(HttpStatus.OK)
@ApiException(FORCE_TASK_SUCCESS_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
- public Result<Object> forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
- @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
- @PathVariable(value = "id") Integer id) {
- Map<String, Object> result = taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
- return returnDataList(result);
+ public Result forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+ @Schema(name = "projectCode", required = true) @PathVariable long projectCode,
+ @PathVariable(value = "id") Integer id) {
+ return taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
}
/**
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2Controller.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2Controller.java
new file mode 100644
index 0000000000..8d416da1bb
--- /dev/null
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2Controller.java
@@ -0,0 +1,130 @@
+/*
+ * 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.FORCE_TASK_SUCCESS_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceListPagingResponse;
+import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceQueryRequest;
+import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceSuccessResponse;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.TaskInstanceService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
+
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+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.Parameters;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+/**
+ * task instance controller
+ */
+@Tag(name = "TASK_INSTANCE_TAG")
+@RestController
+@RequestMapping("/v2/projects/{projectCode}/task-instances")
+public class TaskInstanceV2Controller extends BaseController {
+
+ @Autowired
+ private TaskInstanceService taskInstanceService;
+
+ /**
+ * query task list paging
+ *
+ * @param loginUser login user
+ * @param projectCode project code
+ * @param taskInstanceQueryReq taskInstanceQueryReq
+ * @return task list page
+ */
+ @Operation(summary = "queryTaskListPaging", description = "QUERY_TASK_INSTANCE_LIST_PAGING_NOTES")
+ @Parameters({
+ @Parameter(name = "processInstanceId", description = "PROCESS_INSTANCE_ID", schema = @Schema(implementation = int.class), example = "100"),
+ @Parameter(name = "processInstanceName", description = "PROCESS_INSTANCE_NAME", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "searchVal", description = "SEARCH_VAL", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "taskName", description = "TASK_NAME", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "executorName", description = "EXECUTOR_NAME", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "stateType", description = "EXECUTION_STATUS", schema = @Schema(implementation = TaskExecutionStatus.class)),
+ @Parameter(name = "host", description = "HOST", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "endDate", description = "END_DATE", schema = @Schema(implementation = String.class)),
+ @Parameter(name = "taskExecuteType", description = "TASK_EXECUTE_TYPE", schema = @Schema(implementation = int.class), example = "STREAM"),
+ @Parameter(name = "pageNo", description = "PAGE_NO", required = true, schema = @Schema(implementation = int.class), example = "1"),
+ @Parameter(name = "pageSize", description = "PAGE_SIZE", required = true, schema = @Schema(implementation = int.class), example = "20"),
+ })
+ @GetMapping(consumes = {"application/json"})
+ @ResponseStatus(HttpStatus.OK)
+ @ApiException(QUERY_TASK_LIST_PAGING_ERROR)
+ @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+ public TaskInstanceListPagingResponse queryTaskListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+ @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
+ TaskInstanceQueryRequest taskInstanceQueryReq) {
+ Result result = checkPageParams(taskInstanceQueryReq.getPageNo(), taskInstanceQueryReq.getPageSize());
+ if (!result.checkResult()) {
+ return new TaskInstanceListPagingResponse(result);
+ }
+ String searchVal = ParameterUtils.handleEscapes(taskInstanceQueryReq.getSearchVal());
+ result = taskInstanceService.queryTaskListPaging(loginUser, projectCode,
+ taskInstanceQueryReq.getProcessInstanceId(), taskInstanceQueryReq.getProcessInstanceName(),
+ taskInstanceQueryReq.getProcessDefinitionName(),
+ taskInstanceQueryReq.getTaskName(), taskInstanceQueryReq.getExecutorName(),
+ taskInstanceQueryReq.getStartTime(), taskInstanceQueryReq.getEndTime(), searchVal,
+ taskInstanceQueryReq.getStateType(), taskInstanceQueryReq.getHost(),
+ taskInstanceQueryReq.getTaskExecuteType(), taskInstanceQueryReq.getPageNo(),
+ taskInstanceQueryReq.getPageSize());
+ return new TaskInstanceListPagingResponse(result);
+ }
+
+ /**
+ * change one task instance's state from FAILURE to FORCED_SUCCESS
+ *
+ * @param loginUser login user
+ * @param projectCode project code
+ * @param id task instance id
+ * @return the result code and msg
+ */
+ @Operation(summary = "force-success", description = "FORCE_TASK_SUCCESS")
+ @Parameters({
+ @Parameter(name = "id", description = "TASK_INSTANCE_ID", required = true, schema = @Schema(implementation = int.class), example = "12")
+ })
+ @PostMapping(value = "/{id}/force-success", consumes = {"application/json"})
+ @ResponseStatus(HttpStatus.OK)
+ @ApiException(FORCE_TASK_SUCCESS_ERROR)
+ @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+ public TaskInstanceSuccessResponse forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+ @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
+ @PathVariable(value = "id") Integer id) {
+ Result result = taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
+ return new TaskInstanceSuccessResponse(result);
+ }
+}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceListPagingResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceListPagingResponse.java
new file mode 100644
index 0000000000..66d31facdc
--- /dev/null
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceListPagingResponse.java
@@ -0,0 +1,40 @@
+/*
+ * 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.taskInstance;
+
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+
+import lombok.Data;
+
+/**
+ * task instance list paging response
+ */
+@Data
+public class TaskInstanceListPagingResponse extends Result {
+
+ private PageInfo<TaskInstance> data;
+
+ public TaskInstanceListPagingResponse(Result result) {
+ super();
+ this.setCode(result.getCode());
+ this.setMsg(result.getMsg());
+ this.setData(result.getData());
+ }
+}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceQueryRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceQueryRequest.java
new file mode 100644
index 0000000000..8181b3916c
--- /dev/null
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceQueryRequest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.taskInstance;
+
+import org.apache.dolphinscheduler.api.dto.PageQueryDto;
+import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+
+import lombok.Data;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.v3.oas.annotations.media.Schema;
+
+/**
+ * task instance request
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Data
+public class TaskInstanceQueryRequest extends PageQueryDto {
+
+ @Schema(name = "processInstanceId", example = "PROCESS_INSTANCE_ID", defaultValue = "0")
+ Integer processInstanceId;
+
+ @Schema(name = "processInstanceName", example = "PROCESS-INSTANCE-NAME")
+ String processInstanceName;
+
+ @Schema(name = "processDefinitionName", example = "PROCESS-DEFINITION-NAME")
+ String processDefinitionName;
+
+ @Schema(name = "searchVal", example = "SEARCH-VAL")
+ String searchVal;
+
+ @Schema(name = "taskName", example = "TASK-NAME")
+ String taskName;
+
+ @Schema(name = "executorName", example = "EXECUTOR-NAME")
+ String executorName;
+
+ @Schema(name = "stateType", example = "STATE-TYPE")
+ TaskExecutionStatus stateType;
+
+ @Schema(name = "host", example = "HOST")
+ String host;
+
+ @Schema(name = "startDate", example = "START-TIME")
+ String startTime;
+
+ @Schema(name = "endDate", example = "END-DATE")
+ String endTime;
+
+ @Schema(name = "taskExecuteType", example = "EXECUTE-TYPE", defaultValue = "BATCH")
+ TaskExecuteType taskExecuteType;
+}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceSuccessResponse.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceSuccessResponse.java
new file mode 100644
index 0000000000..914ad92026
--- /dev/null
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskInstance/TaskInstanceSuccessResponse.java
@@ -0,0 +1,36 @@
+/*
+ * 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.taskInstance;
+
+import org.apache.dolphinscheduler.api.utils.Result;
+
+import lombok.Data;
+
+/**
+ * task instance success response
+ */
+@Data
+public class TaskInstanceSuccessResponse extends Result {
+
+ public TaskInstanceSuccessResponse(Result result) {
+ super();
+ this.setCode(result.getCode());
+ this.setMsg(result.getMsg());
+ this.setData(result.getData());
+ }
+}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
index b86d4d757e..d5d05faa14 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
@@ -22,8 +22,6 @@ import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
-import java.util.Map;
-
/**
* task instance service
*/
@@ -70,9 +68,9 @@ public interface TaskInstanceService {
* @param taskInstanceId task instance id
* @return the result code and msg
*/
- Map<String, Object> forceTaskSuccess(User loginUser,
- long projectCode,
- Integer taskInstanceId);
+ Result forceTaskSuccess(User loginUser,
+ long projectCode,
+ Integer taskInstanceId);
/**
* task savepoint
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
index 43eccf2054..d830db5bf2 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
@@ -96,17 +96,17 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
/**
* query task list by project, process instance, task name, task start time, task end time, task status, keyword paging
*
- * @param loginUser login user
- * @param projectCode project code
+ * @param loginUser login user
+ * @param projectCode project code
* @param processInstanceId process instance id
- * @param searchVal search value
- * @param taskName task name
- * @param stateType state type
- * @param host host
- * @param startDate start time
- * @param endDate end time
- * @param pageNo page number
- * @param pageSize page size
+ * @param searchVal search value
+ * @param taskName task name
+ * @param stateType state type
+ * @param host host
+ * @param startDate start time
+ * @param endDate end time
+ * @param pageNo page number
+ * @param pageSize page size
* @return task list page
*/
@Override
@@ -186,19 +186,22 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst
/**
* change one task instance's state from failure to forced success
*
- * @param loginUser login user
- * @param projectCode project code
+ * @param loginUser login user
+ * @param projectCode project code
* @param taskInstanceId task instance id
* @return the result code and msg
*/
@Transactional
@Override
- public Map<String, Object> forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {
+ public Result forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {
+ Result result = new Result();
Project project = projectMapper.queryByCode(projectCode);
// check user access for project
- Map<String, Object> result =
+ Map<String, Object> checkResult =
projectService.checkProjectAndAuth(loginUser, project, projectCode, FORCED_SUCCESS);
- if (result.get(Constants.STATUS) != Status.SUCCESS) {
+ Status status = (Status) checkResult.get(Constants.STATUS);
+ if (status != Status.SUCCESS) {
+ putMsg(result, status);
return result;
}
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
index 0a7868a332..961f828c8d 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
@@ -30,16 +30,12 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.TaskInstanceService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
-import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
-import java.util.HashMap;
-import java.util.Map;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -85,9 +81,8 @@ public class TaskInstanceControllerTest extends AbstractControllerTest {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("taskInstanceId", "104");
- Map<String, Object> mockResult = new HashMap<>(5);
- mockResult.put(Constants.STATUS, Status.SUCCESS);
- mockResult.put(Constants.MSG, Status.SUCCESS.getMsg());
+ Result mockResult = new Result();
+ putMsg(mockResult, Status.SUCCESS);
when(taskInstanceService.forceTaskSuccess(any(User.class), anyLong(), anyInt())).thenReturn(mockResult);
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/task-instance/force-success", "cxc_1113")
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java
new file mode 100644
index 0000000000..3aed7ecb44
--- /dev/null
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.when;
+
+import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceQueryRequest;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.TaskInstanceService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+
+import java.util.Collections;
+
+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 TaskInstanceV2ControllerTest extends AbstractControllerTest {
+
+ @InjectMocks
+ private TaskInstanceV2Controller taskInstanceV2Controller;
+
+ @Mock
+ private TaskInstanceService taskInstanceService;
+
+ @Test
+ public void testQueryTaskListPaging() {
+
+ TaskInstanceQueryRequest taskInstanceQueryReq = new TaskInstanceQueryRequest();
+ taskInstanceQueryReq.setProcessInstanceId(1);
+ taskInstanceQueryReq.setProcessInstanceName("");
+ taskInstanceQueryReq.setProcessDefinitionName("");
+ taskInstanceQueryReq.setTaskName("");
+ taskInstanceQueryReq.setExecutorName("");
+ taskInstanceQueryReq.setStartTime("2022-06-01 00:00:00");
+ taskInstanceQueryReq.setEndTime("2022-09-01 00:00:00");
+ taskInstanceQueryReq.setSearchVal("");
+ taskInstanceQueryReq.setStateType(TaskExecutionStatus.SUCCESS);
+ taskInstanceQueryReq.setHost("127.0.0.1");
+ taskInstanceQueryReq.setTaskExecuteType(TaskExecuteType.BATCH);
+ taskInstanceQueryReq.setPageNo(1);
+ taskInstanceQueryReq.setPageSize(20);
+
+ Result result = new Result();
+ PageInfo<TaskInstance> pageInfo =
+ new PageInfo<>(taskInstanceQueryReq.getPageNo(), taskInstanceQueryReq.getPageSize());
+ pageInfo.setTotalList(Collections.singletonList(new TaskInstance()));
+ result.setData(pageInfo);
+ putMsg(result, Status.SUCCESS);
+
+ when(taskInstanceService.queryTaskListPaging(any(), eq(1L), eq(taskInstanceQueryReq.getProcessInstanceId()),
+ eq(taskInstanceQueryReq.getProcessInstanceName()), eq(taskInstanceQueryReq.getProcessInstanceName()),
+ eq(taskInstanceQueryReq.getTaskName()), eq(taskInstanceQueryReq.getExecutorName()), any(), any(),
+ eq(taskInstanceQueryReq.getSearchVal()), Mockito.any(), eq(taskInstanceQueryReq.getHost()),
+ eq(taskInstanceQueryReq.getTaskExecuteType()), any(), any())).thenReturn(result);
+ Result taskResult = taskInstanceV2Controller.queryTaskListPaging(null, 1L, taskInstanceQueryReq);
+ Assertions.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), taskResult.getCode());
+ }
+
+ @Test
+ public void testForceTaskSuccess() {
+
+ Result mockResult = new Result();
+ putMsg(mockResult, Status.SUCCESS);
+
+ when(taskInstanceService.forceTaskSuccess(any(), Mockito.anyLong(), Mockito.anyInt())).thenReturn(mockResult);
+
+ Result taskResult = taskInstanceV2Controller.forceTaskSuccess(null, 1L, 1);
+ Assertions.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), taskResult.getCode());
+
+ }
+
+}
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
index 934c93a1a5..0482ab7ef4 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
@@ -299,8 +299,8 @@ public class TaskInstanceServiceTest {
Map<String, Object> mockFailure = new HashMap<>(5);
putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode);
when(projectService.checkProjectAndAuth(user, project, projectCode, FORCED_SUCCESS)).thenReturn(mockFailure);
- Map<String, Object> authFailRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
- Assertions.assertNotSame(Status.SUCCESS, authFailRes.get(Constants.STATUS));
+ Result authFailRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
+ Assertions.assertNotSame(Status.SUCCESS.getCode(), authFailRes.getCode());
// test task not found
when(projectService.checkProjectAndAuth(user, project, projectCode, FORCED_SUCCESS)).thenReturn(mockSuccess);
@@ -308,8 +308,8 @@ public class TaskInstanceServiceTest {
TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.setProjectCode(projectCode);
when(taskDefinitionMapper.queryByCode(task.getTaskCode())).thenReturn(taskDefinition);
- Map<String, Object> taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
- Assertions.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS));
+ Result taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
+ Assertions.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(), taskNotFoundRes.getCode().intValue());
// test task instance state error
task.setState(TaskExecutionStatus.SUCCESS);
@@ -318,8 +318,9 @@ public class TaskInstanceServiceTest {
putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(user, project, projectCode, FORCED_SUCCESS)).thenReturn(result);
- Map<String, Object> taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
- Assertions.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskStateErrorRes.get(Constants.STATUS));
+ Result taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
+ Assertions.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR.getCode(),
+ taskStateErrorRes.getCode().intValue());
// test error
task.setState(TaskExecutionStatus.FAILURE);
@@ -327,8 +328,8 @@ public class TaskInstanceServiceTest {
putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(user, project, projectCode, FORCED_SUCCESS)).thenReturn(result);
- Map<String, Object> errorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
- Assertions.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR, errorRes.get(Constants.STATUS));
+ Result errorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
+ Assertions.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR.getCode(), errorRes.getCode().intValue());
// test success
task.setState(TaskExecutionStatus.FAILURE);
@@ -336,7 +337,8 @@ public class TaskInstanceServiceTest {
putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(user, project, projectCode, FORCED_SUCCESS)).thenReturn(result);
- Map<String, Object> successRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
- Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
+ Result successRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId);
+ Assertions.assertEquals(Status.SUCCESS.getCode(), successRes.getCode().intValue());
+
}
}