@ -17,13 +17,19 @@
package org.apache.dolphinscheduler.service.process ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.fasterxml.jackson.core.type.TypeReference ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import com.google.common.collect.Lists ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.math.NumberUtils ;
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_END_DATE ;
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_START_DATE ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_EMPTY_SUB_PROCESS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_FATHER_PARAMS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_DEFINE_CODE ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_PARENT_INSTANCE_ID ;
import static org.apache.dolphinscheduler.common.Constants.LOCAL_PARAMS ;
import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TASK_INSTANCE_ID ;
import static java.util.stream.Collectors.toSet ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.enums.AuthorizationType ;
import org.apache.dolphinscheduler.common.enums.CommandType ;
@ -124,11 +130,10 @@ import org.apache.dolphinscheduler.service.log.LogClientService;
import org.apache.dolphinscheduler.service.quartz.cron.CronUtils ;
import org.apache.dolphinscheduler.service.task.TaskPluginManager ;
import org.apache.dolphinscheduler.spi.enums.ResourceType ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Component ;
import org.springframework.transaction.annotation.Transactional ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.math.NumberUtils ;
import java.util.ArrayList ;
import java.util.Arrays ;
@ -143,17 +148,16 @@ import java.util.Objects;
import java.util.Set ;
import java.util.stream.Collectors ;
import static java.util.stream.Collectors.toSet ;
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_END_DATE ;
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_START_DATE ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_EMPTY_SUB_PROCESS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_FATHER_PARAMS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_DEFINE_CODE ;
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_PARENT_INSTANCE_ID ;
import static org.apache.dolphinscheduler.common.Constants.LOCAL_PARAMS ;
import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TASK_INSTANCE_ID ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Component ;
import org.springframework.transaction.annotation.Transactional ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.fasterxml.jackson.core.type.TypeReference ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import com.google.common.collect.Lists ;
/ * *
* process relative dao that some mappers in this .
@ -164,6 +168,7 @@ public class ProcessService {
private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ;
private final int [ ] stateArray = new int [ ] { ExecutionStatus . SUBMITTED_SUCCESS . ordinal ( ) ,
ExecutionStatus . DISPATCH . ordinal ( ) ,
ExecutionStatus . RUNNING_EXECUTION . ordinal ( ) ,
ExecutionStatus . DELAY_EXECUTION . ordinal ( ) ,
ExecutionStatus . READY_PAUSE . ordinal ( ) ,
@ -266,8 +271,8 @@ public class ProcessService {
/ * *
* handle Command ( construct ProcessInstance from Command ) , wrapped in transaction
*
* @param logger logger
* @param host host
* @param logger logger
* @param host host
* @param command found command
* @return process instance
* /
@ -368,7 +373,7 @@ public class ProcessService {
/ * *
* set process waiting thread
*
* @param command command
* @param command command
* @param processInstance processInstance
* @return process instance
* /
@ -581,8 +586,6 @@ public class ProcessService {
/ * *
* recursive delete all task instance by process instance id
*
* @param processInstanceId
* /
public void deleteWorkTaskInstanceByProcessInstanceId ( int processInstanceId ) {
List < TaskInstance > taskInstanceList = findValidTaskListByProcessId ( processInstanceId ) ;
@ -603,7 +606,7 @@ public class ProcessService {
* recursive query sub process definition id by parent id .
*
* @param parentCode parentCode
* @param ids ids
* @param ids ids
* /
public void recurseFindSubProcess ( long parentCode , List < Long > ids ) {
List < TaskDefinition > taskNodeList = this . getTaskNodeListByDefinition ( parentCode ) ;
@ -628,7 +631,7 @@ public class ProcessService {
* create recovery waiting thread command and delete origin command at the same time .
* if the recovery command is exists , only update the field update_time
*
* @param originCommand originCommand
* @param originCommand originCommand
* @param processInstance processInstance
* /
public void createRecoveryWaitingThreadCommand ( Command originCommand , ProcessInstance processInstance ) {
@ -684,7 +687,7 @@ public class ProcessService {
/ * *
* get schedule time from command
*
* @param command command
* @param command command
* @param cmdParam cmdParam map
* @return date
* /
@ -713,8 +716,8 @@ public class ProcessService {
* generate a new work process instance from command .
*
* @param processDefinition processDefinition
* @param command command
* @param cmdParam cmdParam map
* @param command command
* @param cmdParam cmdParam map
* @return process instance
* /
private ProcessInstance generateNewProcessInstance ( ProcessDefinition processDefinition ,
@ -799,7 +802,7 @@ public class ProcessService {
* use definition creator ' s tenant .
*
* @param tenantId tenantId
* @param userId userId
* @param userId userId
* @return tenant
* /
public Tenant getTenantForProcess ( int tenantId , int userId ) {
@ -837,7 +840,7 @@ public class ProcessService {
/ * *
* check command parameters is valid
*
* @param command command
* @param command command
* @param cmdParam cmdParam map
* @return whether command param is valid
* /
@ -857,7 +860,7 @@ public class ProcessService {
* construct process instance according to one command .
*
* @param command command
* @param host host
* @param host host
* @return process instance
* /
protected ProcessInstance constructProcessInstance ( Command command , String host ) {
@ -1036,7 +1039,7 @@ public class ProcessService {
* return complement data if the process start with complement data
*
* @param processInstance processInstance
* @param command command
* @param command command
* @return command type
* /
private CommandType getCommandTypeIfComplement ( ProcessInstance processInstance , Command command ) {
@ -1051,8 +1054,8 @@ public class ProcessService {
* initialize complement data parameters
*
* @param processDefinition processDefinition
* @param processInstance processInstance
* @param cmdParam cmdParam
* @param processInstance processInstance
* @param cmdParam cmdParam
* /
private void initComplementDataParam ( ProcessDefinition processDefinition ,
ProcessInstance processInstance ,
@ -1125,7 +1128,7 @@ public class ProcessService {
* only the keys doesn ' t in sub process global would be joined .
*
* @param parentGlobalParams parentGlobalParams
* @param subGlobalParams subGlobalParams
* @param subGlobalParams subGlobalParams
* @return global params join
* /
private String joinGlobalParams ( String parentGlobalParams , String subGlobalParams ) {
@ -1192,7 +1195,7 @@ public class ProcessService {
* submit sub process to command
*
* @param processInstance processInstance
* @param taskInstance taskInstance
* @param taskInstance taskInstance
* @return task instance
* /
@Transactional ( rollbackFor = Exception . class )
@ -1223,7 +1226,7 @@ public class ProcessService {
* set map { parent instance id , task instance id , 0 ( child instance id ) }
*
* @param parentInstance parentInstance
* @param parentTask parentTask
* @param parentTask parentTask
* @return process instance map
* /
private ProcessInstanceMap setProcessInstanceMap ( ProcessInstance parentInstance , TaskInstance parentTask ) {
@ -1252,7 +1255,7 @@ public class ProcessService {
* find previous task work process map .
*
* @param parentProcessInstance parentProcessInstance
* @param parentTask parentTask
* @param parentTask parentTask
* @return process instance map
* /
private ProcessInstanceMap findPreviousTaskProcessMap ( ProcessInstance parentProcessInstance ,
@ -1278,7 +1281,7 @@ public class ProcessService {
* create sub work process command
*
* @param parentProcessInstance parentProcessInstance
* @param task task
* @param task task
* /
public void createSubWorkProcess ( ProcessInstance parentProcessInstance , TaskInstance task ) {
if ( ! task . isSubProcess ( ) ) {
@ -1412,7 +1415,7 @@ public class ProcessService {
* update sub process definition
*
* @param parentProcessInstance parentProcessInstance
* @param childDefinitionCode childDefinitionId
* @param childDefinitionCode childDefinitionId
* /
private void updateSubProcessDefinitionByParent ( ProcessInstance parentProcessInstance , long childDefinitionCode ) {
ProcessDefinition fatherDefinition = this . findProcessDefinition ( parentProcessInstance . getProcessDefinitionCode ( ) ,
@ -1427,7 +1430,7 @@ public class ProcessService {
/ * *
* submit task to mysql
*
* @param taskInstance taskInstance
* @param taskInstance taskInstance
* @param processInstance processInstance
* @return task instance
* /
@ -1463,7 +1466,7 @@ public class ProcessService {
* return stop if work process state is ready stop
* if all of above are not satisfied , return submit success
*
* @param taskInstance taskInstance
* @param taskInstance taskInstance
* @param processInstance processInstance
* @return process instance state
* /
@ -1476,6 +1479,7 @@ public class ProcessService {
state = = ExecutionStatus . RUNNING_EXECUTION
| | state = = ExecutionStatus . DELAY_EXECUTION
| | state = = ExecutionStatus . KILL
| | state = = ExecutionStatus . DISPATCH
) {
return state ;
}
@ -1689,7 +1693,7 @@ public class ProcessService {
* get id list by task state
*
* @param instanceId instanceId
* @param state state
* @param state state
* @return task instance states
* /
public List < Integer > findTaskIdByInstanceState ( int instanceId , ExecutionStatus state ) {
@ -1744,7 +1748,7 @@ public class ProcessService {
* find work process map by parent process id and parent task id .
*
* @param parentWorkProcessId parentWorkProcessId
* @param parentTaskId parentTaskId
* @param parentTaskId parentTaskId
* @return process instance map
* /
public ProcessInstanceMap findWorkProcessMapByParent ( Integer parentWorkProcessId , Integer parentTaskId ) {
@ -1766,7 +1770,7 @@ public class ProcessService {
* find sub process instance
*
* @param parentProcessId parentProcessId
* @param parentTaskId parentTaskId
* @param parentTaskId parentTaskId
* @return process instance
* /
public ProcessInstance findSubProcessInstance ( Integer parentProcessId , Integer parentTaskId ) {
@ -1795,29 +1799,6 @@ public class ProcessService {
return processInstance ;
}
/ * *
* change task state
*
* @param state state
* @param startTime startTime
* @param host host
* @param executePath executePath
* @param logPath logPath
* /
public void changeTaskState ( TaskInstance taskInstance ,
ExecutionStatus state ,
Date startTime ,
String host ,
String executePath ,
String logPath ) {
taskInstance . setState ( state ) ;
taskInstance . setStartTime ( startTime ) ;
taskInstance . setHost ( host ) ;
taskInstance . setExecutePath ( executePath ) ;
taskInstance . setLogPath ( logPath ) ;
saveTaskInstance ( taskInstance ) ;
}
/ * *
* update process instance
*
@ -1828,27 +1809,6 @@ public class ProcessService {
return processInstanceMapper . updateById ( processInstance ) ;
}
/ * *
* change task state
*
* @param state state
* @param endTime endTime
* @param varPool varPool
* /
public void changeTaskState ( TaskInstance taskInstance , ExecutionStatus state ,
Date endTime ,
int processId ,
String appIds ,
String varPool ) {
taskInstance . setPid ( processId ) ;
taskInstance . setAppLink ( appIds ) ;
taskInstance . setState ( state ) ;
taskInstance . setEndTime ( endTime ) ;
taskInstance . setVarPool ( varPool ) ;
changeOutParam ( taskInstance ) ;
saveTaskInstance ( taskInstance ) ;
}
/ * *
* for show in page of taskInstance
* /
@ -2006,7 +1966,7 @@ public class ProcessService {
* update process instance state by id
*
* @param processInstanceId processInstanceId
* @param executionStatus executionStatus
* @param executionStatus executionStatus
* @return update process result
* /
public int updateProcessInstanceState ( Integer processInstanceId , ExecutionStatus executionStatus ) {
@ -2042,7 +2002,7 @@ public class ProcessService {
/ * *
* find tenant code by resource name
*
* @param resName resource name
* @param resName resource name
* @param resourceType resource type
* @return tenant code
* /
@ -2080,7 +2040,7 @@ public class ProcessService {
* find last scheduler process instance in the date interval
*
* @param definitionCode definitionCode
* @param dateInterval dateInterval
* @param dateInterval dateInterval
* @return process instance
* /
public ProcessInstance findLastSchedulerProcessInterval ( Long definitionCode , DateInterval dateInterval ) {
@ -2093,7 +2053,7 @@ public class ProcessService {
* find last manual process instance interval
*
* @param definitionCode process definition code
* @param dateInterval dateInterval
* @param dateInterval dateInterval
* @return process instance
* /
public ProcessInstance findLastManualProcessInterval ( Long definitionCode , DateInterval dateInterval ) {
@ -2106,8 +2066,8 @@ public class ProcessService {
* find last running process instance
*
* @param definitionCode process definition code
* @param startTime start time
* @param endTime end time
* @param startTime start time
* @param endTime end time
* @return process instance
* /
public ProcessInstance findLastRunningProcess ( Long definitionCode , Date startTime , Date endTime ) {
@ -2191,7 +2151,7 @@ public class ProcessService {
/ * *
* list unauthorized udf function
*
* @param userId user id
* @param userId user id
* @param needChecks data source id array
* @return unauthorized udf function list
* /
@ -2599,7 +2559,7 @@ public class ProcessService {
* add authorized resources
*
* @param ownResources own resources
* @param userId userId
* @param userId userId
* /
private void addAuthorizedResources ( List < Resource > ownResources , int userId ) {
List < Integer > relationResourceIds = resourceUserMapper . queryResourcesIdListByUserIdAndPerm ( userId , 7 ) ;
@ -2742,12 +2702,7 @@ public class ProcessService {
/ * *
* the first time ( when submit the task ) get the resource of the task group
*
* @param taskId task id
* @param taskName
* @param groupId
* @param processId
* @param priority
* @return
* @param taskId task id
* /
public boolean acquireTaskGroup ( int taskId ,
String taskName , int groupId ,
@ -2788,9 +2743,6 @@ public class ProcessService {
/ * *
* try to get the task group resource ( when other task release the resource )
*
* @param taskGroupQueue
* @return
* /
public boolean robTaskGroupResouce ( TaskGroupQueue taskGroupQueue ) {
TaskGroup taskGroup = taskGroupMapper . selectById ( taskGroupQueue . getGroupId ( ) ) ;
@ -2877,11 +2829,11 @@ public class ProcessService {
/ * *
* insert into task group queue
*
* @param taskId task id
* @param taskName task name
* @param groupId group id
* @param taskId task id
* @param taskName task name
* @param groupId group id
* @param processId process id
* @param priority priority
* @param priority priority
* @return result and msg code
* /
public TaskGroupQueue insertIntoTaskGroupQueue ( Integer taskId ,