Browse Source

[Feature][JsonSplit-api] Replace projectName with projectCode in ProcessInstance api (#5950)

* check has cycle of ProcessDefinition

* checkProcessNode of processDefinition

* TaskInstance api

* Replace projectName with projectCode in ProcessInstance api

Co-authored-by: JinyLeeChina <297062848@qq.com>
2.0.7-release
JinyLeeChina 3 years ago committed by GitHub
parent
commit
7c1f891a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 88
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
  2. 73
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
  3. 181
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  4. 114
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java
  5. 289
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java

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

@ -73,12 +73,11 @@ import springfox.documentation.annotations.ApiIgnore;
*/ */
@Api(tags = "PROCESS_INSTANCE_TAG") @Api(tags = "PROCESS_INSTANCE_TAG")
@RestController @RestController
@RequestMapping("projects/{projectName}/instance") @RequestMapping("projects/{projectCode}/instance")
public class ProcessInstanceController extends BaseController { public class ProcessInstanceController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class); private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class);
@Autowired @Autowired
ProcessInstanceService processInstanceService; ProcessInstanceService processInstanceService;
@ -86,7 +85,7 @@ public class ProcessInstanceController extends BaseController {
* query process instance list paging * query process instance list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
@ -114,7 +113,7 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessInstanceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessInstanceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId, @RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "executorName", required = false) String executorName, @RequestParam(value = "executorName", required = false) String executorName,
@ -124,14 +123,13 @@ public class ProcessInstanceController extends BaseController {
@RequestParam(value = "endDate", required = false) String endTime, @RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
Map<String, Object> result = checkPageParams(pageNo, pageSize); Map<String, Object> result = checkPageParams(pageNo, pageSize);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = processInstanceService.queryProcessInstanceList( result = processInstanceService.queryProcessInstanceList(loginUser, projectCode, processDefinitionId, startTime, endTime,
loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, executorName, stateType, host, pageNo, pageSize); searchVal, executorName, stateType, host, pageNo, pageSize);
return returnDataListPaging(result); return returnDataListPaging(result);
} }
@ -139,7 +137,7 @@ public class ProcessInstanceController extends BaseController {
* query task list by process instance id * query task list by process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return task list for the process instance * @return task list for the process instance
*/ */
@ -152,10 +150,9 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) @ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskListByProcessId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskListByProcessId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId) throws IOException {
) throws IOException { Map<String, Object> result = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, processInstanceId);
Map<String, Object> result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, processInstanceId);
return returnDataList(result); return returnDataList(result);
} }
@ -163,7 +160,7 @@ public class ProcessInstanceController extends BaseController {
* update process instance * update process instance
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceJson process instance json * @param processInstanceJson process instance json
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @param scheduleTime schedule time * @param scheduleTime schedule time
@ -186,16 +183,15 @@ public class ProcessInstanceController extends BaseController {
@ApiException(UPDATE_PROCESS_INSTANCE_ERROR) @ApiException(UPDATE_PROCESS_INSTANCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result updateProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processInstanceJson", required = false) String processInstanceJson, @RequestParam(value = "processInstanceJson", required = false) String processInstanceJson,
@RequestParam(value = "processInstanceId") Integer processInstanceId, @RequestParam(value = "processInstanceId") Integer processInstanceId,
@RequestParam(value = "scheduleTime", required = false) String scheduleTime, @RequestParam(value = "scheduleTime", required = false) String scheduleTime,
@RequestParam(value = "syncDefine", required = true) Boolean syncDefine, @RequestParam(value = "syncDefine", required = true) Boolean syncDefine,
@RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "flag", required = false) Flag flag @RequestParam(value = "flag", required = false) Flag flag) throws ParseException {
) throws ParseException { Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectCode, processInstanceId,
Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectName, processInstanceJson, scheduleTime, syncDefine, flag, locations);
processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations);
return returnDataList(result); return returnDataList(result);
} }
@ -203,7 +199,7 @@ public class ProcessInstanceController extends BaseController {
* query process instance by id * query process instance by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return process instance detail * @return process instance detail
*/ */
@ -216,10 +212,9 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId) {
) { Map<String, Object> result = processInstanceService.queryProcessInstanceById(loginUser, projectCode, processInstanceId);
Map<String, Object> result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result); return returnDataList(result);
} }
@ -227,7 +222,7 @@ public class ProcessInstanceController extends BaseController {
* query top n process instance order by running duration * query top n process instance order by running duration
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param size number of process instance * @param size number of process instance
* @param startTime start time * @param startTime start time
* @param endTime end time * @param endTime end time
@ -244,14 +239,11 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<ProcessInstance> queryTopNLongestRunningProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<ProcessInstance> queryTopNLongestRunningProcessInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("size") Integer size, @RequestParam("size") Integer size,
@RequestParam(value = "startTime", required = true) String startTime, @RequestParam(value = "startTime", required = true) String startTime,
@RequestParam(value = "endTime", required = true) String endTime @RequestParam(value = "endTime", required = true) String endTime) {
Map<String, Object> result = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime);
) {
projectName = ParameterUtils.handleEscapes(projectName);
Map<String, Object> result = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime);
return returnDataList(result); return returnDataList(result);
} }
@ -260,7 +252,7 @@ public class ProcessInstanceController extends BaseController {
* delete task instance and their mapping relation data * delete task instance and their mapping relation data
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return delete result code * @return delete result code
*/ */
@ -273,11 +265,9 @@ public class ProcessInstanceController extends BaseController {
@ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR) @ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<ProcessInstance> deleteProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<ProcessInstance> deleteProcessInstanceById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId @RequestParam("processInstanceId") Integer processInstanceId) {
) { Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectCode, processInstanceId);
// task queue
Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result); return returnDataList(result);
} }
@ -285,7 +275,7 @@ public class ProcessInstanceController extends BaseController {
* query sub process instance detail info by task id * query sub process instance detail info by task id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskId task id * @param taskId task id
* @return sub process instance detail * @return sub process instance detail
*/ */
@ -298,9 +288,9 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) @ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result querySubProcessInstanceByTaskId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result querySubProcessInstanceByTaskId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("taskId") Integer taskId) { @RequestParam("taskId") Integer taskId) {
Map<String, Object> result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId); Map<String, Object> result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, taskId);
return returnDataList(result); return returnDataList(result);
} }
@ -308,7 +298,7 @@ public class ProcessInstanceController extends BaseController {
* query parent process instance detail info by sub process instance id * query parent process instance detail info by sub process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param subId sub process id * @param subId sub process id
* @return parent instance detail * @return parent instance detail
*/ */
@ -321,9 +311,9 @@ public class ProcessInstanceController extends BaseController {
@ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) @ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR)
@AccessLogAnnotation @AccessLogAnnotation
public Result queryParentInstanceBySubId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryParentInstanceBySubId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("subId") Integer subId) { @RequestParam("subId") Integer subId) {
Map<String, Object> result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId); Map<String, Object> result = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, subId);
return returnDataList(result); return returnDataList(result);
} }
@ -352,7 +342,7 @@ public class ProcessInstanceController extends BaseController {
* encapsulation gantt structure * encapsulation gantt structure
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return gantt tree data * @return gantt tree data
*/ */
@ -365,7 +355,7 @@ public class ProcessInstanceController extends BaseController {
@ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) @ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR)
@AccessLogAnnotation @AccessLogAnnotation
public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId) throws Exception { @RequestParam("processInstanceId") Integer processInstanceId) throws Exception {
Map<String, Object> result = processInstanceService.viewGantt(processInstanceId); Map<String, Object> result = processInstanceService.viewGantt(processInstanceId);
return returnDataList(result); return returnDataList(result);
@ -376,7 +366,7 @@ public class ProcessInstanceController extends BaseController {
* delete task instance and their mapping relation data * delete task instance and their mapping relation data
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceIds process instance id * @param processInstanceIds process instance id
* @return delete result code * @return delete result code
*/ */
@ -390,9 +380,8 @@ public class ProcessInstanceController extends BaseController {
@ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) @ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR)
@AccessLogAnnotation @AccessLogAnnotation
public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName, @PathVariable long projectCode,
@RequestParam("processInstanceIds") String processInstanceIds @RequestParam("processInstanceIds") String processInstanceIds) {
) {
// task queue // task queue
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
List<String> deleteFailedIdList = new ArrayList<>(); List<String> deleteFailedIdList = new ArrayList<>();
@ -402,7 +391,7 @@ public class ProcessInstanceController extends BaseController {
for (String strProcessInstanceId : processInstanceIdArray) { for (String strProcessInstanceId : processInstanceIdArray) {
int processInstanceId = Integer.parseInt(strProcessInstanceId); int processInstanceId = Integer.parseInt(strProcessInstanceId);
try { try {
Map<String, Object> deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId); Map<String, Object> deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectCode, processInstanceId);
if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) {
deleteFailedIdList.add(strProcessInstanceId); deleteFailedIdList.add(strProcessInstanceId);
logger.error((String) deleteResult.get(Constants.MSG)); logger.error((String) deleteResult.get(Constants.MSG));
@ -417,7 +406,6 @@ public class ProcessInstanceController extends BaseController {
} else { } else {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} }
return returnDataList(result); return returnDataList(result);
} }
} }

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

@ -38,23 +38,29 @@ public interface ProcessInstanceService {
/** /**
* return top n SUCCESS process instance order by running time which started between startTime and endTime * return top n SUCCESS process instance order by running time which started between startTime and endTime
*/ */
Map<String, Object> queryTopNLongestRunningProcessInstance(User loginUser, String projectName, int size, String startTime, String endTime); Map<String, Object> queryTopNLongestRunningProcessInstance(User loginUser,
long projectCode,
int size,
String startTime,
String endTime);
/** /**
* query process instance by id * query process instance by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processId process instance id * @param processId process instance id
* @return process instance detail * @return process instance detail
*/ */
Map<String, Object> queryProcessInstanceById(User loginUser, String projectName, Integer processId); Map<String, Object> queryProcessInstanceById(User loginUser,
long projectCode,
Integer processId);
/** /**
* paging query process instance list, filtering according to project, process definition, time range, keyword, process status * paging query process instance list, filtering according to project, process definition, time range, keyword, process status
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param processDefineId process definition id * @param processDefineId process definition id
@ -65,21 +71,30 @@ public interface ProcessInstanceService {
* @param endDate end time * @param endDate end time
* @return process instance list * @return process instance list
*/ */
Map<String, Object> queryProcessInstanceList(User loginUser, String projectName, Integer processDefineId, Map<String, Object> queryProcessInstanceList(User loginUser,
String startDate, String endDate, long projectCode,
String searchVal, String executorName, ExecutionStatus stateType, String host, Integer processDefineId,
Integer pageNo, Integer pageSize); String startDate,
String endDate,
String searchVal,
String executorName,
ExecutionStatus stateType,
String host,
Integer pageNo,
Integer pageSize);
/** /**
* query task list by process instance id * query task list by process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processId process instance id * @param processId process instance id
* @return task list for the process instance * @return task list for the process instance
* @throws IOException io exception * @throws IOException io exception
*/ */
Map<String, Object> queryTaskListByProcessId(User loginUser, String projectName, Integer processId) throws IOException; Map<String, Object> queryTaskListByProcessId(User loginUser,
long projectCode,
Integer processId) throws IOException;
Map<String, DependResult> parseLogForDependentResult(String log) throws IOException; Map<String, DependResult> parseLogForDependentResult(String log) throws IOException;
@ -87,17 +102,19 @@ public interface ProcessInstanceService {
* query sub process instance detail info by task id * query sub process instance detail info by task id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskId task id * @param taskId task id
* @return sub process instance detail * @return sub process instance detail
*/ */
Map<String, Object> querySubProcessInstanceByTaskId(User loginUser, String projectName, Integer taskId); Map<String, Object> querySubProcessInstanceByTaskId(User loginUser,
long projectCode,
Integer taskId);
/** /**
* update process instance * update process instance
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceJson process instance json * @param processInstanceJson process instance json
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @param scheduleTime schedule time * @param scheduleTime schedule time
@ -107,29 +124,38 @@ public interface ProcessInstanceService {
* @return update result code * @return update result code
* @throws ParseException parse exception for json parse * @throws ParseException parse exception for json parse
*/ */
Map<String, Object> updateProcessInstance(User loginUser, String projectName, Integer processInstanceId, Map<String, Object> updateProcessInstance(User loginUser,
String processInstanceJson, String scheduleTime, Boolean syncDefine, long projectCode,
Flag flag, String locations) throws ParseException; Integer processInstanceId,
String processInstanceJson,
String scheduleTime,
Boolean syncDefine,
Flag flag,
String locations) throws ParseException;
/** /**
* query parent process instance detail info by sub process instance id * query parent process instance detail info by sub process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param subId sub process id * @param subId sub process id
* @return parent instance detail * @return parent instance detail
*/ */
Map<String, Object> queryParentInstanceBySubId(User loginUser, String projectName, Integer subId); Map<String, Object> queryParentInstanceBySubId(User loginUser,
long projectCode,
Integer subId);
/** /**
* delete process instance by id, at the same timedelete task instance and their mapping relation data * delete process instance by id, at the same timedelete task instance and their mapping relation data
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return delete result code * @return delete result code
*/ */
Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId); Map<String, Object> deleteProcessInstanceById(User loginUser,
long projectCode,
Integer processInstanceId);
/** /**
* view process instance variables * view process instance variables
@ -155,7 +181,8 @@ public interface ProcessInstanceService {
* @param states states array * @param states states array
* @return process instance list * @return process instance list
*/ */
List<ProcessInstance> queryByProcessDefineCodeAndStatus(Long processDefinitionCode, int[] states); List<ProcessInstance> queryByProcessDefineCodeAndStatus(Long processDefinitionCode,
int[] states);
/** /**
* query process instance by processDefinitionCode * query process instance by processDefinitionCode
@ -164,6 +191,6 @@ public interface ProcessInstanceService {
* @param size size * @param size size
* @return process instance list * @return process instance list
*/ */
List<ProcessInstance> queryByProcessDefineCode(Long processDefinitionCode,int size); List<ProcessInstance> queryByProcessDefineCode(Long processDefinitionCode,
int size);
} }

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

@ -141,14 +141,12 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* return top n SUCCESS process instance order by running time which started between startTime and endTime * return top n SUCCESS process instance order by running time which started between startTime and endTime
*/ */
@Override @Override
public Map<String, Object> queryTopNLongestRunningProcessInstance(User loginUser, String projectName, int size, String startTime, String endTime) { public Map<String, Object> queryTopNLongestRunningProcessInstance(User loginUser, long projectCode, int size, String startTime, String endTime) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
if (0 > size) { if (0 > size) {
@ -184,24 +182,22 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* query process instance by id * query process instance by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processId process instance id * @param processId process instance id
* @return process instance detail * @return process instance detail
*/ */
@Override @Override
public Map<String, Object> queryProcessInstanceById(User loginUser, String projectName, Integer processId) { public Map<String, Object> queryProcessInstanceById(User loginUser, long projectCode, Integer processId) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId);
ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion()); processInstance.getProcessDefinitionVersion());
if (processDefinition == null) { if (processDefinition == null) {
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId);
@ -222,7 +218,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* paging query process instance list, filtering according to project, process definition, time range, keyword, process status * paging query process instance list, filtering according to project, process definition, time range, keyword, process status
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param processDefineId process definition id * @param processDefineId process definition id
@ -234,18 +230,22 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* @return process instance list * @return process instance list
*/ */
@Override @Override
public Map<String, Object> queryProcessInstanceList(User loginUser, String projectName, Integer processDefineId, public Map<String, Object> queryProcessInstanceList(User loginUser,
String startDate, String endDate, long projectCode,
String searchVal, String executorName, ExecutionStatus stateType, String host, Integer processDefineId,
Integer pageNo, Integer pageSize) { String startDate,
String endDate,
Map<String, Object> result = new HashMap<>(); String searchVal,
Project project = projectMapper.queryByName(projectName); String executorName,
ExecutionStatus stateType,
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); String host,
Status resultEnum = (Status) checkResult.get(Constants.STATUS); Integer pageNo,
if (resultEnum != Status.SUCCESS) { Integer pageSize) {
return checkResult; Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
} }
int[] statusArray = null; int[] statusArray = null;
@ -268,8 +268,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefineId); ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefineId);
IPage<ProcessInstance> processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(page, IPage<ProcessInstance> processInstanceList = processInstanceMapper.queryProcessInstanceListPaging(page,
project.getCode(), processDefinition == null ? 0L : processDefinition.getCode(), searchVal, project.getCode(), processDefinition == null ? 0L : processDefinition.getCode(), searchVal,
executorId, statusArray, host, start, end); executorId, statusArray, host, start, end);
List<ProcessInstance> processInstances = processInstanceList.getRecords(); List<ProcessInstance> processInstances = processInstanceList.getRecords();
List<Integer> userIds = CollectionUtils.transformToList(processInstances, ProcessInstance::getExecutorId); List<Integer> userIds = CollectionUtils.transformToList(processInstances, ProcessInstance::getExecutorId);
@ -294,20 +294,18 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* query task list by process instance id * query task list by process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processId process instance id * @param processId process instance id
* @return task list for the process instance * @return task list for the process instance
* @throws IOException io exception * @throws IOException io exception
*/ */
@Override @Override
public Map<String, Object> queryTaskListByProcessId(User loginUser, String projectName, Integer processId) throws IOException { public Map<String, Object> queryTaskListByProcessId(User loginUser, long projectCode, Integer processId) throws IOException {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId);
List<TaskInstance> taskInstanceList = processService.findValidTaskListByProcessId(processId); List<TaskInstance> taskInstanceList = processService.findValidTaskListByProcessId(processId);
@ -328,7 +326,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
for (TaskInstance taskInstance : taskInstanceList) { for (TaskInstance taskInstance : taskInstanceList) {
if (TaskType.DEPENDENT.getDesc().equalsIgnoreCase(taskInstance.getTaskType())) { if (TaskType.DEPENDENT.getDesc().equalsIgnoreCase(taskInstance.getTaskType())) {
Result<String> logResult = loggerService.queryLog( Result<String> logResult = loggerService.queryLog(
taskInstance.getId(), Constants.LOG_QUERY_SKIP_LINE_NUMBER, Constants.LOG_QUERY_LIMIT); taskInstance.getId(), Constants.LOG_QUERY_SKIP_LINE_NUMBER, Constants.LOG_QUERY_LIMIT);
if (logResult.getCode() == Status.SUCCESS.ordinal()) { if (logResult.getCode() == Status.SUCCESS.ordinal()) {
String log = logResult.getData(); String log = logResult.getData();
Map<String, DependResult> resultMap = parseLogForDependentResult(log); Map<String, DependResult> resultMap = parseLogForDependentResult(log);
@ -346,7 +344,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
} }
BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(log.getBytes( BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(log.getBytes(
StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
if (line.contains(DEPENDENT_SPLIT)) { if (line.contains(DEPENDENT_SPLIT)) {
@ -371,19 +369,17 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* query sub process instance detail info by task id * query sub process instance detail info by task id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskId task id * @param taskId task id
* @return sub process instance detail * @return sub process instance detail
*/ */
@Override @Override
public Map<String, Object> querySubProcessInstanceByTaskId(User loginUser, String projectName, Integer taskId) { public Map<String, Object> querySubProcessInstanceByTaskId(User loginUser, long projectCode, Integer taskId) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
TaskInstance taskInstance = processService.findTaskInstanceById(taskId); TaskInstance taskInstance = processService.findTaskInstanceById(taskId);
@ -397,7 +393,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
} }
ProcessInstance subWorkflowInstance = processService.findSubProcessInstance( ProcessInstance subWorkflowInstance = processService.findSubProcessInstance(
taskInstance.getProcessInstanceId(), taskInstance.getId()); taskInstance.getProcessInstanceId(), taskInstance.getId());
if (subWorkflowInstance == null) { if (subWorkflowInstance == null) {
putMsg(result, Status.SUB_PROCESS_INSTANCE_NOT_EXIST, taskId); putMsg(result, Status.SUB_PROCESS_INSTANCE_NOT_EXIST, taskId);
return result; return result;
@ -413,7 +409,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* update process instance * update process instance
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceJson process instance json * @param processInstanceJson process instance json
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @param scheduleTime schedule time * @param scheduleTime schedule time
@ -424,16 +420,14 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
*/ */
@Transactional @Transactional
@Override @Override
public Map<String, Object> updateProcessInstance(User loginUser, String projectName, Integer processInstanceId, public Map<String, Object> updateProcessInstance(User loginUser, long projectCode, Integer processInstanceId,
String processInstanceJson, String scheduleTime, Boolean syncDefine, String processInstanceJson, String scheduleTime, Boolean syncDefine,
Flag flag, String locations) { Flag flag, String locations) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
//check project permission Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
//check process instance exists //check process instance exists
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId); ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId);
@ -444,11 +438,11 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
//check process instance status //check process instance status
if (!processInstance.getState().typeIsFinished()) { if (!processInstance.getState().typeIsFinished()) {
putMsg(result, Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, putMsg(result, Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR,
processInstance.getName(), processInstance.getState().toString(), "update"); processInstance.getName(), processInstance.getState().toString(), "update");
return result; return result;
} }
ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion()); processInstance.getProcessDefinitionVersion());
ProcessData processData = JSONUtils.parseObject(processInstanceJson, ProcessData.class); ProcessData processData = JSONUtils.parseObject(processInstanceJson, ProcessData.class);
//check workflow json is valid TODO processInstanceJson --> processTaskRelationJson //check workflow json is valid TODO processInstanceJson --> processTaskRelationJson
result = processDefinitionService.checkProcessNodeList(processInstanceJson); result = processDefinitionService.checkProcessNodeList(processInstanceJson);
@ -456,7 +450,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
return result; return result;
} }
Tenant tenant = processService.getTenantForProcess(processData.getTenantId(), Tenant tenant = processService.getTenantForProcess(processData.getTenantId(),
processDefinition.getUserId()); processDefinition.getUserId());
setProcessInstance(processInstance, tenant, scheduleTime, processData); setProcessInstance(processInstance, tenant, scheduleTime, processData);
int updateDefine = 1; int updateDefine = 1;
if (Boolean.TRUE.equals(syncDefine)) { if (Boolean.TRUE.equals(syncDefine)) {
@ -464,7 +458,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
updateDefine = syncDefinition(loginUser, project, locations, processInstance, processDefinition, processData); updateDefine = syncDefinition(loginUser, project, locations, processInstance, processDefinition, processData);
processInstance.setProcessDefinitionVersion(processDefinitionLogMapper. processInstance.setProcessDefinitionVersion(processDefinitionLogMapper.
queryMaxVersionForDefinition(processInstance.getProcessDefinitionCode())); queryMaxVersionForDefinition(processInstance.getProcessDefinitionCode()));
} }
int update = processService.updateProcessInstance(processInstance); int update = processService.updateProcessInstance(processInstance);
@ -489,7 +483,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
return processService.saveProcessDefinition(loginUser, project, processDefinition.getName(), return processService.saveProcessDefinition(loginUser, project, processDefinition.getName(),
processDefinition.getDescription(), locations, processData, processDefinition, false); processDefinition.getDescription(), locations, processData, processDefinition, false);
} }
/** /**
@ -504,11 +498,11 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
processInstance.setScheduleTime(schedule); processInstance.setScheduleTime(schedule);
List<Property> globalParamList = processData.getGlobalParams(); List<Property> globalParamList = processData.getGlobalParams();
Map<String, String> globalParamMap = Optional.ofNullable(globalParamList) Map<String, String> globalParamMap = Optional.ofNullable(globalParamList)
.orElse(Collections.emptyList()) .orElse(Collections.emptyList())
.stream() .stream()
.collect(Collectors.toMap(Property::getProp, Property::getValue)); .collect(Collectors.toMap(Property::getProp, Property::getValue));
String globalParams = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, String globalParams = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList,
processInstance.getCmdTypeIfComplement(), schedule); processInstance.getCmdTypeIfComplement(), schedule);
processInstance.setTimeout(processData.getTimeout()); processInstance.setTimeout(processData.getTimeout());
if (tenant != null) { if (tenant != null) {
processInstance.setTenantCode(tenant.getTenantCode()); processInstance.setTenantCode(tenant.getTenantCode());
@ -520,19 +514,17 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* query parent process instance detail info by sub process instance id * query parent process instance detail info by sub process instance id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param subId sub process id * @param subId sub process id
* @return parent instance detail * @return parent instance detail
*/ */
@Override @Override
public Map<String, Object> queryParentInstanceBySubId(User loginUser, String projectName, Integer subId) { public Map<String, Object> queryParentInstanceBySubId(User loginUser, long projectCode, Integer subId) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessInstance subInstance = processService.findProcessInstanceDetailById(subId); ProcessInstance subInstance = processService.findProcessInstanceDetailById(subId);
@ -561,21 +553,18 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
* delete process instance by id, at the same timedelete task instance and their mapping relation data * delete process instance by id, at the same timedelete task instance and their mapping relation data
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return delete result code * @return delete result code
*/ */
@Override @Override
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) { public Map<String, Object> deleteProcessInstanceById(User loginUser, long projectCode, Integer processInstanceId) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId); ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId);
if (null == processInstance) { if (null == processInstance) {
@ -616,8 +605,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
} }
Map<String, String> timeParams = BusinessTimeUtils Map<String, String> timeParams = BusinessTimeUtils
.getBusinessTime(processInstance.getCmdTypeIfComplement(), .getBusinessTime(processInstance.getCmdTypeIfComplement(),
processInstance.getScheduleTime()); processInstance.getScheduleTime());
String userDefinedParams = processInstance.getGlobalParams(); String userDefinedParams = processInstance.getGlobalParams();
// global params // global params
List<Property> globalParams = new ArrayList<>(); List<Property> globalParams = new ArrayList<>();
@ -653,7 +642,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
List<TaskInstance> taskInstanceList = taskInstanceMapper.findValidTaskListByProcessId(processInstance.getId(), Flag.YES); List<TaskInstance> taskInstanceList = taskInstanceMapper.findValidTaskListByProcessId(processInstance.getId(), Flag.YES);
for (TaskInstance taskInstance : taskInstanceList) { for (TaskInstance taskInstance : taskInstanceList) {
TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion( TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(
taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion()); taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion());
String localParams = JSONUtils.getNodeString(taskDefinitionLog.getTaskParams(), LOCAL_PARAMS); String localParams = JSONUtils.getNodeString(taskDefinitionLog.getTaskParams(), LOCAL_PARAMS);
if (StringUtils.isNotEmpty(localParams)) { if (StringUtils.isNotEmpty(localParams)) {
@ -689,8 +678,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
} }
ProcessDefinition processDefinition = processDefinitionLogMapper.queryByDefinitionCodeAndVersion( ProcessDefinition processDefinition = processDefinitionLogMapper.queryByDefinitionCodeAndVersion(
processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion() processInstance.getProcessDefinitionVersion()
); );
GanttDto ganttDto = new GanttDto(); GanttDto ganttDto = new GanttDto();
DAG<String, TaskNode, TaskNodeRelation> dag = processService.genDagGraph(processDefinition); DAG<String, TaskNode, TaskNodeRelation> dag = processService.genDagGraph(processDefinition);

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

@ -51,12 +51,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("pageNo", "2"); paramsMap.add("pageNo", "2");
paramsMap.add("pageSize", "2"); paramsMap.add("pageSize", "2");
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/list-paging", "cxc_1113") MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/list-paging", "cxc_1113")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
@ -64,12 +64,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testQueryTaskListByProcessId() throws Exception { public void testQueryTaskListByProcessId() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/task-list-by-process-id", "cxc_1113") MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/task-list-by-process-id", "cxc_1113")
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)
.param("processInstanceId", "1203")) .param("processInstanceId", "1203"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -88,12 +88,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("syncDefine", "false"); paramsMap.add("syncDefine", "false");
paramsMap.add("locations", locations); paramsMap.add("locations", locations);
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/instance/update", "cxc_1113") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/instance/update", "cxc_1113")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
@ -101,13 +101,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testQueryProcessInstanceById() throws Exception { public void testQueryProcessInstanceById() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-by-id", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-by-id", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("processInstanceId", "1203"))
.param("processInstanceId", "1203")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -117,13 +116,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testQuerySubProcessInstanceByTaskId() throws Exception { public void testQuerySubProcessInstanceByTaskId() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-sub-process", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-sub-process", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("taskId", "1203"))
.param("taskId", "1203")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -132,13 +130,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testQueryParentInstanceBySubId() throws Exception { public void testQueryParentInstanceBySubId() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/select-parent-process", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/select-parent-process", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("subId", "1204"))
.param("subId", "1204")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -148,13 +145,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testViewVariables() throws Exception { public void testViewVariables() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/view-variables", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/view-variables", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("processInstanceId", "1204"))
.param("processInstanceId", "1204")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -164,13 +160,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testDeleteProcessInstanceById() throws Exception { public void testDeleteProcessInstanceById() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/delete", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/delete", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("processInstanceId", "1204"))
.param("processInstanceId", "1204")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);
@ -179,13 +174,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest {
@Test @Test
public void testBatchDeleteProcessInstanceByIds() throws Exception { public void testBatchDeleteProcessInstanceByIds() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/instance/batch-delete", "cxc_1113")
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/batch-delete", "cxc_1113") .header(SESSION_ID, sessionId)
.header(SESSION_ID, sessionId) .param("processInstanceIds", "1205,1206"))
.param("processInstanceIds", "1205,1206")) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn();
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertNotNull(result); Assert.assertNotNull(result);

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

@ -109,24 +109,25 @@ public class ProcessInstanceServiceTest {
UsersService usersService; UsersService usersService;
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\"," private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\","
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," + "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"},"
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\","
+ "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\","
+ "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; + "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}";
@Test @Test
public void testQueryProcessInstanceList() { public void testQueryProcessInstanceList() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, "project_test1")).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 46, "2020-01-01 00:00:00", Map<String, Object> proejctAuthFailRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 46, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", "test_user", ExecutionStatus.SUBMITTED_SUCCESS, "2020-01-02 00:00:00", "", "test_user", ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00"); Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00");
@ -138,67 +139,67 @@ public class ProcessInstanceServiceTest {
pageReturn.setRecords(processInstanceList); pageReturn.setRecords(processInstanceList);
// data parameter check // data parameter check
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Project project = getProject(projectName); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition()); when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition());
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class) when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class)
, Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), , Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn);
Map<String, Object> dataParameterRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "20200101 00:00:00", Map<String, Object> dataParameterRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "20200101 00:00:00",
"20200102 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, "20200102 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, dataParameterRes.get(Constants.STATUS)); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, dataParameterRes.get(Constants.STATUS));
//project auth success //project auth success
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId());
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(), when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(),
eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn);
when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser);
Map<String, Object> successRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", Map<String, Object> successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, "2020-01-02 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
// data parameter empty // data parameter empty
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(), when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(),
eq("192.168.xx.xx"), eq(null), eq(null))).thenReturn(pageReturn); eq("192.168.xx.xx"), eq(null), eq(null))).thenReturn(pageReturn);
successRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "", successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "",
"", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS, "", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
//executor null //executor null
when(usersService.queryUser(loginUser.getId())).thenReturn(null); when(usersService.queryUser(loginUser.getId())).thenReturn(null);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1);
Map<String, Object> executorExistRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", Map<String, Object> executorExistRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", "admin", ExecutionStatus.SUBMITTED_SUCCESS, "2020-01-02 00:00:00", "", "admin", ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS, executorExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, executorExistRes.get(Constants.STATUS));
//executor name empty //executor name empty
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(0), Mockito.any(), when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(0), Mockito.any(),
eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn);
Map<String, Object> executorEmptyRes = processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "2020-01-01 00:00:00", Map<String, Object> executorEmptyRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", "", ExecutionStatus.SUBMITTED_SUCCESS, "2020-01-02 00:00:00", "", "", ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10); "192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS, executorEmptyRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, executorEmptyRes.get(Constants.STATUS));
} }
@Test @Test
public void testQueryTopNLongestRunningProcessInstance() { public void testQueryTopNLongestRunningProcessInstance() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
int size = 10; int size = 10;
String startTime = "2020-01-01 00:00:00"; String startTime = "2020-01-01 00:00:00";
String endTime = "2020-08-02 00:00:00"; String endTime = "2020-08-02 00:00:00";
@ -206,77 +207,76 @@ public class ProcessInstanceServiceTest {
Date end = DateUtils.getScheduleDate(endTime); Date end = DateUtils.getScheduleDate(endTime);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); Map<String, Object> proejctAuthFailRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//project auth success //project auth success
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Project project = getProject(projectName);
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser);
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId());
when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser);
Map<String, Object> successRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectName, size, startTime, endTime); Map<String, Object> successRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testQueryProcessInstanceById() { public void testQueryProcessInstanceById() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); Map<String, Object> proejctAuthFailRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//project auth success //project auth success
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Project project = getProject(projectName);
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance);
when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition);
Map<String, Object> successRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); Map<String, Object> successRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
//worker group null //worker group null
Map<String, Object> workerNullRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); Map<String, Object> workerNullRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, workerNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, workerNullRes.get(Constants.STATUS));
//worker group exist //worker group exist
WorkerGroup workerGroup = getWorkGroup(); WorkerGroup workerGroup = getWorkGroup();
Map<String, Object> workerExistRes = processInstanceService.queryProcessInstanceById(loginUser, projectName, 1); Map<String, Object> workerExistRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, workerExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, workerExistRes.get(Constants.STATUS));
} }
@Test @Test
public void testQueryTaskListByProcessId() throws IOException { public void testQueryTaskListByProcessId() throws IOException {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.queryTaskListByProcessId(loginUser, projectName, 1); Map<String, Object> proejctAuthFailRes = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//project auth success //project auth success
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Project project = getProject(projectName);
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
processInstance.setState(ExecutionStatus.SUCCESS); processInstance.setState(ExecutionStatus.SUCCESS);
TaskInstance taskInstance = new TaskInstance(); TaskInstance taskInstance = new TaskInstance();
@ -286,103 +286,107 @@ public class ProcessInstanceServiceTest {
Result res = new Result(); Result res = new Result();
res.setCode(Status.SUCCESS.ordinal()); res.setCode(Status.SUCCESS.ordinal());
res.setData("xxx"); res.setData("xxx");
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance);
when(processService.findValidTaskListByProcessId(processInstance.getId())).thenReturn(taskInstanceList); when(processService.findValidTaskListByProcessId(processInstance.getId())).thenReturn(taskInstanceList);
when(loggerService.queryLog(taskInstance.getId(), 0, 4098)).thenReturn(res); when(loggerService.queryLog(taskInstance.getId(), 0, 4098)).thenReturn(res);
Map<String, Object> successRes = processInstanceService.queryTaskListByProcessId(loginUser, projectName, 1); Map<String, Object> successRes = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testParseLogForDependentResult() throws IOException { public void testParseLogForDependentResult() throws IOException {
String logString = "[INFO] 2019-03-19 17:11:08.475 org.apache.dolphinscheduler.server.worker.log.TaskLogger:[172]" String logString = "[INFO] 2019-03-19 17:11:08.475 org.apache.dolphinscheduler.server.worker.log.TaskLogger:[172]"
+ " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n" + " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n"
+ "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]" + "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]"
+ " - task : 223_10739_452334 exit status code : 0\n" + " - task : 223_10739_452334 exit status code : 0\n"
+ "[root@node2 current]# "; + "[root@node2 current]# ";
Map<String, DependResult> resultMap = Map<String, DependResult> resultMap =
processInstanceService.parseLogForDependentResult(logString); processInstanceService.parseLogForDependentResult(logString);
Assert.assertEquals(1, resultMap.size()); Assert.assertEquals(1, resultMap.size());
} }
@Test @Test
public void testQuerySubProcessInstanceByTaskId() { public void testQuerySubProcessInstanceByTaskId() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); Map<String, Object> proejctAuthFailRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//task null //task null
Project project = getProject(projectName); putMsg(result, Status.SUCCESS, projectCode);
putMsg(result, Status.SUCCESS, projectName); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
when(processService.findTaskInstanceById(1)).thenReturn(null); when(processService.findTaskInstanceById(1)).thenReturn(null);
Map<String, Object> taskNullRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); Map<String, Object> taskNullRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1);
Assert.assertEquals(Status.TASK_INSTANCE_NOT_EXISTS, taskNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.TASK_INSTANCE_NOT_EXISTS, taskNullRes.get(Constants.STATUS));
//task not sub process //task not sub process
TaskInstance taskInstance = getTaskInstance(); TaskInstance taskInstance = getTaskInstance();
taskInstance.setTaskType(TaskType.HTTP.getDesc()); taskInstance.setTaskType(TaskType.HTTP.getDesc());
taskInstance.setProcessInstanceId(1); taskInstance.setProcessInstanceId(1);
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findTaskInstanceById(1)).thenReturn(taskInstance); when(processService.findTaskInstanceById(1)).thenReturn(taskInstance);
Map<String, Object> notSubprocessRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); Map<String, Object> notSubprocessRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1);
Assert.assertEquals(Status.TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE, notSubprocessRes.get(Constants.STATUS)); Assert.assertEquals(Status.TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE, notSubprocessRes.get(Constants.STATUS));
//sub process not exist //sub process not exist
TaskInstance subTask = getTaskInstance(); TaskInstance subTask = getTaskInstance();
subTask.setTaskType(TaskType.SUB_PROCESS.getDesc()); subTask.setTaskType(TaskType.SUB_PROCESS.getDesc());
subTask.setProcessInstanceId(1); subTask.setProcessInstanceId(1);
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findTaskInstanceById(subTask.getId())).thenReturn(subTask); when(processService.findTaskInstanceById(subTask.getId())).thenReturn(subTask);
when(processService.findSubProcessInstance(subTask.getProcessInstanceId(), subTask.getId())).thenReturn(null); when(processService.findSubProcessInstance(subTask.getProcessInstanceId(), subTask.getId())).thenReturn(null);
Map<String, Object> subprocessNotExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); Map<String, Object> subprocessNotExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subprocessNotExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subprocessNotExistRes.get(Constants.STATUS));
//sub process exist //sub process exist
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findSubProcessInstance(taskInstance.getProcessInstanceId(), taskInstance.getId())).thenReturn(processInstance); when(processService.findSubProcessInstance(taskInstance.getProcessInstanceId(), taskInstance.getId())).thenReturn(processInstance);
Map<String, Object> subprocessExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, 1); Map<String, Object> subprocessExistRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, subprocessExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, subprocessExistRes.get(Constants.STATUS));
} }
@Test @Test
public void testUpdateProcessInstance() { public void testUpdateProcessInstance() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, Map<String, Object> proejctAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, "2020-02-21 00:00:00", true, Flag.YES, ""); shellJson, "2020-02-21 00:00:00", true, Flag.YES, "");
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//process instance null //process instance null
Project project = getProject(projectName); putMsg(result, Status.SUCCESS, projectCode);
putMsg(result, Status.SUCCESS, projectName);
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(processService.findProcessInstanceDetailById(1)).thenReturn(null); when(processService.findProcessInstanceDetailById(1)).thenReturn(null);
Map<String, Object> processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, Map<String, Object> processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, "2020-02-21 00:00:00", true, Flag.YES, ""); shellJson, "2020-02-21 00:00:00", true, Flag.YES, "");
Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS));
//process instance not finish //process instance not finish
when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance); when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance);
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); processInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
Map<String, Object> processInstanceNotFinishRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, putMsg(result, Status.SUCCESS, projectCode);
shellJson, "2020-02-21 00:00:00", true, Flag.YES, ""); Map<String, Object> processInstanceNotFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, "2020-02-21 00:00:00", true, Flag.YES, "");
Assert.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstanceNotFinishRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstanceNotFinishRes.get(Constants.STATUS));
//process instance finish //process instance finish
@ -402,82 +406,79 @@ public class ProcessInstanceServiceTest {
when(processService.updateProcessInstance(processInstance)).thenReturn(1); when(processService.updateProcessInstance(processInstance)).thenReturn(1);
when(processDefinitionService.checkProcessNodeList(shellJson)).thenReturn(result); when(processDefinitionService.checkProcessNodeList(shellJson)).thenReturn(result);
when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition);
putMsg(result, Status.SUCCESS, projectCode);
Map<String, Object> processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, Map<String, Object> processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, "2020-02-21 00:00:00", true, Flag.YES, ""); shellJson, "2020-02-21 00:00:00", true, Flag.YES, "");
Assert.assertEquals(Status.UPDATE_PROCESS_INSTANCE_ERROR, processInstanceFinishRes.get(Constants.STATUS)); Assert.assertEquals(Status.UPDATE_PROCESS_INSTANCE_ERROR, processInstanceFinishRes.get(Constants.STATUS));
//success //success
when(processService.saveProcessDefinition(Mockito.any(), Mockito.any(), when(processService.saveProcessDefinition(Mockito.any(), Mockito.any(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(1); Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(1);
when(processService.findProcessDefinition(46L, 0)).thenReturn(processDefinition); when(processService.findProcessDefinition(46L, 0)).thenReturn(processDefinition);
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Map<String, Object> successRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1, Map<String, Object> successRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, "2020-02-21 00:00:00", true, Flag.YES, ""); shellJson, "2020-02-21 00:00:00", true, Flag.YES, "");
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testQueryParentInstanceBySubId() { public void testQueryParentInstanceBySubId() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail //project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> proejctAuthFailRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); Map<String, Object> proejctAuthFailRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS));
//process instance null //process instance null
Project project = getProject(projectName); putMsg(result, Status.SUCCESS, projectCode);
putMsg(result, Status.SUCCESS, projectName); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
when(processService.findProcessInstanceDetailById(1)).thenReturn(null); when(processService.findProcessInstanceDetailById(1)).thenReturn(null);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Map<String, Object> processInstanceNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
Map<String, Object> processInstanceNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1);
Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS));
//not sub process //not sub process
ProcessInstance processInstance = getProcessInstance(); ProcessInstance processInstance = getProcessInstance();
processInstance.setIsSubProcess(Flag.NO); processInstance.setIsSubProcess(Flag.NO);
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance); when(processService.findProcessInstanceDetailById(1)).thenReturn(processInstance);
Map<String, Object> notSubProcessRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); Map<String, Object> notSubProcessRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE, notSubProcessRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE, notSubProcessRes.get(Constants.STATUS));
//sub process //sub process
processInstance.setIsSubProcess(Flag.YES); processInstance.setIsSubProcess(Flag.YES);
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findParentProcessInstance(1)).thenReturn(null); when(processService.findParentProcessInstance(1)).thenReturn(null);
Map<String, Object> subProcessNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); Map<String, Object> subProcessNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subProcessNullRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUB_PROCESS_INSTANCE_NOT_EXIST, subProcessNullRes.get(Constants.STATUS));
//success //success
putMsg(result, Status.SUCCESS, projectCode);
when(processService.findParentProcessInstance(1)).thenReturn(processInstance); when(processService.findParentProcessInstance(1)).thenReturn(processInstance);
Map<String, Object> successRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, 1); Map<String, Object> successRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testDeleteProcessInstanceById() { public void testDeleteProcessInstanceById() {
String projectName = "project_test1"; long projectCode = 1L;
User loginUser = getAdminUser(); User loginUser = getAdminUser();
Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project auth fail
when(projectMapper.queryByName(projectName)).thenReturn(null);
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result);
//process instance null //process instance null
Project project = getProject(projectName); putMsg(result, Status.SUCCESS, projectCode);
putMsg(result, Status.SUCCESS, projectName); when(projectMapper.queryByCode(projectCode)).thenReturn(project);
when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
when(processService.findProcessInstanceDetailById(1)).thenReturn(null); when(processService.findProcessInstanceDetailById(1)).thenReturn(null);
} }
@ -503,8 +504,8 @@ public class ProcessInstanceServiceTest {
taskInstance.setStartTime(new Date()); taskInstance.setStartTime(new Date());
when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance);
when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion( when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion(
processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion() processInstance.getProcessDefinitionVersion()
)).thenReturn(new ProcessDefinitionLog()); )).thenReturn(new ProcessDefinitionLog());
when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance);
when(taskInstanceMapper.queryByInstanceIdAndName(Mockito.anyInt(), Mockito.any())).thenReturn(taskInstance); when(taskInstanceMapper.queryByInstanceIdAndName(Mockito.anyInt(), Mockito.any())).thenReturn(taskInstance);
@ -514,7 +515,7 @@ public class ProcessInstanceServiceTest {
} }
when(processService.genDagGraph(Mockito.any(ProcessDefinition.class))) when(processService.genDagGraph(Mockito.any(ProcessDefinition.class)))
.thenReturn(graph); .thenReturn(graph);
Map<String, Object> successRes = processInstanceService.viewGantt(1); Map<String, Object> successRes = processInstanceService.viewGantt(1);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
@ -536,14 +537,14 @@ public class ProcessInstanceServiceTest {
/** /**
* get mock Project * get mock Project
* *
* @param projectName projectName * @param projectCode projectCode
* @return Project * @return Project
*/ */
private Project getProject(String projectName) { private Project getProject(long projectCode) {
Project project = new Project(); Project project = new Project();
project.setCode(1L); project.setCode(projectCode);
project.setId(1); project.setId(1);
project.setName(projectName); project.setName("project_test1");
project.setUserId(1); project.setUserId(1);
return project; return project;
} }

Loading…
Cancel
Save