Browse Source

[Bug][API] update processInstance bug (#13991)

3.2.0-release
Aaron Wang 2 years ago committed by GitHub
parent
commit
73b505f639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
  3. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  4. 2
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java
  5. 10
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java

7
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java

@ -175,7 +175,6 @@ public class ProcessInstanceController extends BaseController {
@Parameter(name = "globalParams", description = "PROCESS_GLOBAL_PARAMS", schema = @Schema(implementation = String.class, example = "[]")), @Parameter(name = "globalParams", description = "PROCESS_GLOBAL_PARAMS", schema = @Schema(implementation = String.class, example = "[]")),
@Parameter(name = "locations", description = "PROCESS_INSTANCE_LOCATIONS", schema = @Schema(implementation = String.class)), @Parameter(name = "locations", description = "PROCESS_INSTANCE_LOCATIONS", schema = @Schema(implementation = String.class)),
@Parameter(name = "timeout", description = "PROCESS_TIMEOUT", schema = @Schema(implementation = int.class, example = "0")), @Parameter(name = "timeout", description = "PROCESS_TIMEOUT", schema = @Schema(implementation = int.class, example = "0")),
@Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default"))
}) })
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -190,11 +189,9 @@ public class ProcessInstanceController extends BaseController {
@RequestParam(value = "syncDefine", required = true) Boolean syncDefine, @RequestParam(value = "syncDefine", required = true) Boolean syncDefine,
@RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams,
@RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout) {
@RequestParam(value = "tenantCode", required = true) String tenantCode) {
Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectCode, id, Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectCode, id,
taskRelationJson, taskDefinitionJson, scheduleTime, syncDefine, globalParams, locations, timeout, taskRelationJson, taskDefinitionJson, scheduleTime, syncDefine, globalParams, locations, timeout);
tenantCode);
return returnDataList(result); return returnDataList(result);
} }

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java

@ -148,7 +148,6 @@ public interface ProcessInstanceService {
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @return update result code * @return update result code
*/ */
Map<String, Object> updateProcessInstance(User loginUser, Map<String, Object> updateProcessInstance(User loginUser,
@ -160,8 +159,7 @@ public interface ProcessInstanceService {
Boolean syncDefine, Boolean syncDefine,
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout);
String tenantCode);
/** /**
* query parent process instance detail info by sub process instance id * query parent process instance detail info by sub process instance id

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

@ -607,7 +607,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @return update result code * @return update result code
*/ */
@Transactional @Transactional
@ -616,7 +615,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
String taskRelationJson, String taskRelationJson,
String taskDefinitionJson, String scheduleTime, Boolean syncDefine, String taskDefinitionJson, String scheduleTime, Boolean syncDefine,
String globalParams, String globalParams,
String locations, int timeout, String tenantCode) { String locations, int timeout) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
Map<String, Object> result = Map<String, Object> result =
@ -655,7 +654,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
timezoneId = commandParamMap.get(Constants.SCHEDULE_TIMEZONE); timezoneId = commandParamMap.get(Constants.SCHEDULE_TIMEZONE);
} }
setProcessInstance(processInstance, tenantCode, scheduleTime, globalParams, timeout, timezoneId); setProcessInstance(processInstance, scheduleTime, globalParams, timeout, timezoneId);
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class);
if (taskDefinitionLogs.isEmpty()) { if (taskDefinitionLogs.isEmpty()) {
log.warn("Parameter taskDefinitionJson is empty"); log.warn("Parameter taskDefinitionJson is empty");
@ -736,7 +735,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
/** /**
* update process instance attributes * update process instance attributes
*/ */
private void setProcessInstance(ProcessInstance processInstance, String tenantCode, String scheduleTime, private void setProcessInstance(ProcessInstance processInstance, String scheduleTime,
String globalParams, int timeout, String timezone) { String globalParams, int timeout, String timezone) {
Date schedule = processInstance.getScheduleTime(); Date schedule = processInstance.getScheduleTime();
if (scheduleTime != null) { if (scheduleTime != null) {
@ -749,7 +748,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
globalParams = curingGlobalParamsService.curingGlobalParams(processInstance.getId(), globalParamMap, globalParams = curingGlobalParamsService.curingGlobalParams(processInstance.getId(), globalParamMap,
globalParamList, processInstance.getCmdTypeIfComplement(), schedule, timezone); globalParamList, processInstance.getCmdTypeIfComplement(), schedule, timezone);
processInstance.setTimeout(timeout); processInstance.setTimeout(timeout);
processInstance.setTenantCode(tenantCode);
processInstance.setGlobalParams(globalParams); processInstance.setGlobalParams(globalParams);
} }

2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java

@ -108,7 +108,7 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
Mockito.when(processInstanceService Mockito.when(processInstanceService
.updateProcessInstance(Mockito.any(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyString(), .updateProcessInstance(Mockito.any(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyInt(), Mockito.anyString())) Mockito.anyString(), Mockito.anyInt()))
.thenReturn(mockResult); .thenReturn(mockResult);
String json = String json =

10
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java

@ -555,7 +555,7 @@ public class ProcessInstanceServiceTest {
when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result);
Map<String, Object> projectAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, Map<String, Object> projectAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0);
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, projectAuthFailRes.get(Constants.STATUS)); Assertions.assertEquals(Status.PROJECT_NOT_FOUND, projectAuthFailRes.get(Constants.STATUS));
// process instance null // process instance null
@ -566,7 +566,7 @@ public class ProcessInstanceServiceTest {
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty());
Assertions.assertThrows(ServiceException.class, () -> { Assertions.assertThrows(ServiceException.class, () -> {
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0);
}); });
// process instance not finish // process instance not finish
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance));
@ -574,7 +574,7 @@ public class ProcessInstanceServiceTest {
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Map<String, Object> processInstanceNotFinishRes = Map<String, Object> processInstanceNotFinishRes =
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0);
Assertions.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, Assertions.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR,
processInstanceNotFinishRes.get(Constants.STATUS)); processInstanceNotFinishRes.get(Constants.STATUS));
@ -602,7 +602,7 @@ public class ProcessInstanceServiceTest {
when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true);
Map<String, Object> processInstanceFinishRes = Map<String, Object> processInstanceFinishRes =
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", true, "", "", 0, "root"); taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", true, "", "", 0);
Assertions.assertEquals(Status.SUCCESS, processInstanceFinishRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, processInstanceFinishRes.get(Constants.STATUS));
// success // success
@ -612,7 +612,7 @@ public class ProcessInstanceServiceTest {
when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.FALSE, Boolean.FALSE)) when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.FALSE, Boolean.FALSE))
.thenReturn(1); .thenReturn(1);
Map<String, Object> successRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, Map<String, Object> successRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", Boolean.FALSE, "", "", 0, "root"); taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", Boolean.FALSE, "", "", 0);
Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }

Loading…
Cancel
Save