@ -105,6 +105,7 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper ;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper ;
import org.apache.dolphinscheduler.dao.mapper.UserMapper ;
import org.apache.dolphinscheduler.dao.mapper.UserMapper ;
import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper ;
import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper ;
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao ;
import org.apache.dolphinscheduler.dao.utils.DagHelper ;
import org.apache.dolphinscheduler.dao.utils.DagHelper ;
import org.apache.dolphinscheduler.dao.utils.DqRuleUtils ;
import org.apache.dolphinscheduler.dao.utils.DqRuleUtils ;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct ;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct ;
@ -180,9 +181,13 @@ public class ProcessServiceImpl implements ProcessService {
@Autowired
@Autowired
private ProcessDefinitionLogMapper processDefineLogMapper ;
private ProcessDefinitionLogMapper processDefineLogMapper ;
// todo replace with processInstanceDao
@Autowired
@Autowired
private ProcessInstanceMapper processInstanceMapper ;
private ProcessInstanceMapper processInstanceMapper ;
@Autowired
private ProcessInstanceDao processInstanceDao ;
@Autowired
@Autowired
private DataSourceMapper dataSourceMapper ;
private DataSourceMapper dataSourceMapper ;
@ -301,7 +306,7 @@ public class ProcessServiceImpl implements ProcessService {
return null ;
return null ;
}
}
} else {
} else {
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
}
}
setSubProcessParam ( processInstance ) ;
setSubProcessParam ( processInstance ) ;
deleteCommandWithCheck ( command . getId ( ) ) ;
deleteCommandWithCheck ( command . getId ( ) ) ;
@ -309,10 +314,10 @@ public class ProcessServiceImpl implements ProcessService {
}
}
protected void saveSerialProcess ( ProcessInstance processInstance , ProcessDefinition processDefinition ) {
protected void saveSerialProcess ( ProcessInstance processInstance , ProcessDefinition processDefinition ) {
processInstance . setState ( WorkflowExecutionStatus . SERIAL_WAIT ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . SERIAL_WAIT , "wait by serial_wait strategy" ) ;
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
// serial wait
//serial wait
// when we get the running instance(or waiting instance) only get the priority instance(by id)
//when we get the running instance(or waiting instance) only get the priority instance(by id)
if ( processDefinition . getExecutionType ( ) . typeIsSerialWait ( ) ) {
if ( processDefinition . getExecutionType ( ) . typeIsSerialWait ( ) ) {
List < ProcessInstance > runningProcessInstances =
List < ProcessInstance > runningProcessInstances =
this . processInstanceMapper . queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId (
this . processInstanceMapper . queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId (
@ -320,8 +325,8 @@ public class ProcessServiceImpl implements ProcessService {
processInstance . getProcessDefinitionVersion ( ) , Constants . RUNNING_PROCESS_STATE ,
processInstance . getProcessDefinitionVersion ( ) , Constants . RUNNING_PROCESS_STATE ,
processInstance . getId ( ) ) ;
processInstance . getId ( ) ) ;
if ( CollectionUtils . isEmpty ( runningProcessInstances ) ) {
if ( CollectionUtils . isEmpty ( runningProcessInstances ) ) {
processInstance . setState ( WorkflowExecutionStatus . SUBMITTED_SUCCESS ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . SUBMITTED_SUCCESS , "submit from serial_wait strategy" ) ;
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
}
}
} else if ( processDefinition . getExecutionType ( ) . typeIsSerialDiscard ( ) ) {
} else if ( processDefinition . getExecutionType ( ) . typeIsSerialDiscard ( ) ) {
List < ProcessInstance > runningProcessInstances =
List < ProcessInstance > runningProcessInstances =
@ -330,12 +335,12 @@ public class ProcessServiceImpl implements ProcessService {
processInstance . getProcessDefinitionVersion ( ) , Constants . RUNNING_PROCESS_STATE ,
processInstance . getProcessDefinitionVersion ( ) , Constants . RUNNING_PROCESS_STATE ,
processInstance . getId ( ) ) ;
processInstance . getId ( ) ) ;
if ( CollectionUtils . isNotEmpty ( runningProcessInstances ) ) {
if ( CollectionUtils . isNotEmpty ( runningProcessInstances ) ) {
processInstance . setState ( WorkflowExecutionStatus . STOP ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . STOP , "stop by serial_discard strategy" ) ;
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
return ;
return ;
}
}
processInstance . setState ( WorkflowExecutionStatus . SUBMITTED_SUCCESS ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . SUBMITTED_SUCCESS , "submit from serial_discard strategy" ) ;
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
} else if ( processDefinition . getExecutionType ( ) . typeIsSerialPriority ( ) ) {
} else if ( processDefinition . getExecutionType ( ) . typeIsSerialPriority ( ) ) {
List < ProcessInstance > runningProcessInstances =
List < ProcessInstance > runningProcessInstances =
this . processInstanceMapper . queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId (
this . processInstanceMapper . queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId (
@ -345,8 +350,8 @@ public class ProcessServiceImpl implements ProcessService {
for ( ProcessInstance info : runningProcessInstances ) {
for ( ProcessInstance info : runningProcessInstances ) {
info . setCommandType ( CommandType . STOP ) ;
info . setCommandType ( CommandType . STOP ) ;
info . addHistoryCmd ( CommandType . STOP ) ;
info . addHistoryCmd ( CommandType . STOP ) ;
info . setState ( WorkflowExecutionStatus . READY_STOP ) ;
info . setStateWithDesc ( WorkflowExecutionStatus . READY_STOP , "ready stop by serial_priority strategy" ) ;
int update = updateProcessInstance ( info ) ;
int update = processInstanceDao . updateProcessInstance ( info ) ;
// determine whether the process is normal
// determine whether the process is normal
if ( update > 0 ) {
if ( update > 0 ) {
WorkflowStateEventChangeCommand workflowStateEventChangeCommand =
WorkflowStateEventChangeCommand workflowStateEventChangeCommand =
@ -360,8 +365,8 @@ public class ProcessServiceImpl implements ProcessService {
}
}
}
}
}
}
processInstance . setState ( WorkflowExecutionStatus . SUBMITTED_SUCCESS ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . SUBMITTED_SUCCESS , "submit by serial_priority strategy" ) ;
save ProcessInstance( processInstance ) ;
processInstanceDao . upsert ProcessInstance( processInstance ) ;
}
}
}
}
@ -742,7 +747,7 @@ public class ProcessServiceImpl implements ProcessService {
ProcessInstance processInstance = new ProcessInstance ( processDefinition ) ;
ProcessInstance processInstance = new ProcessInstance ( processDefinition ) ;
processInstance . setProcessDefinitionCode ( processDefinition . getCode ( ) ) ;
processInstance . setProcessDefinitionCode ( processDefinition . getCode ( ) ) ;
processInstance . setProcessDefinitionVersion ( processDefinition . getVersion ( ) ) ;
processInstance . setProcessDefinitionVersion ( processDefinition . getVersion ( ) ) ;
processInstance . setState ( WorkflowExecutionStatus . RUNNING_EXECUTION ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . RUNNING_EXECUTION , "init running" ) ;
processInstance . setRecovery ( Flag . NO ) ;
processInstance . setRecovery ( Flag . NO ) ;
processInstance . setStartTime ( new Date ( ) ) ;
processInstance . setStartTime ( new Date ( ) ) ;
// the new process instance restart time is null.
// the new process instance restart time is null.
@ -1046,7 +1051,7 @@ public class ProcessServiceImpl implements ProcessService {
default :
default :
break ;
break ;
}
}
processInstance . setState ( runStatus ) ;
processInstance . setStateWithDesc ( runStatus , commandType . getDescp ( ) ) ;
return processInstance ;
return processInstance ;
}
}
@ -1158,7 +1163,7 @@ public class ProcessServiceImpl implements ProcessService {
paramMap . put ( CMD_PARAM_SUB_PROCESS , String . valueOf ( subProcessInstance . getId ( ) ) ) ;
paramMap . put ( CMD_PARAM_SUB_PROCESS , String . valueOf ( subProcessInstance . getId ( ) ) ) ;
subProcessInstance . setCommandParam ( JSONUtils . toJsonString ( paramMap ) ) ;
subProcessInstance . setCommandParam ( JSONUtils . toJsonString ( paramMap ) ) ;
subProcessInstance . setIsSubProcess ( Flag . YES ) ;
subProcessInstance . setIsSubProcess ( Flag . YES ) ;
this . save ProcessInstance( subProcessInstance ) ;
processInstanceDao . upsert ProcessInstance( subProcessInstance ) ;
}
}
// copy parent instance user def params to sub process..
// copy parent instance user def params to sub process..
String parentInstanceId = paramMap . get ( CMD_PARAM_SUB_PROCESS_PARENT_INSTANCE_ID ) ;
String parentInstanceId = paramMap . get ( CMD_PARAM_SUB_PROCESS_PARENT_INSTANCE_ID ) ;
@ -1169,7 +1174,7 @@ public class ProcessServiceImpl implements ProcessService {
joinGlobalParams ( parentInstance . getGlobalParams ( ) , subProcessInstance . getGlobalParams ( ) ) ) ;
joinGlobalParams ( parentInstance . getGlobalParams ( ) , subProcessInstance . getGlobalParams ( ) ) ) ;
subProcessInstance
subProcessInstance
. setVarPool ( joinVarPool ( parentInstance . getVarPool ( ) , subProcessInstance . getVarPool ( ) ) ) ;
. setVarPool ( joinVarPool ( parentInstance . getVarPool ( ) , subProcessInstance . getVarPool ( ) ) ) ;
this . save ProcessInstance( subProcessInstance ) ;
processInstanceDao . upsert ProcessInstance( subProcessInstance ) ;
} else {
} else {
logger . error ( "sub process command params error, cannot find parent instance: {} " , cmdParam ) ;
logger . error ( "sub process command params error, cannot find parent instance: {} " , cmdParam ) ;
}
}
@ -1510,8 +1515,8 @@ public class ProcessServiceImpl implements ProcessService {
* /
* /
private void initSubInstanceState ( ProcessInstance childInstance ) {
private void initSubInstanceState ( ProcessInstance childInstance ) {
if ( childInstance ! = null ) {
if ( childInstance ! = null ) {
childInstance . setState ( WorkflowExecutionStatus . RUNNING_EXECUTION ) ;
childInstance . setStateWithDesc ( WorkflowExecutionStatus . RUNNING_EXECUTION , "init sub workflow instance" ) ;
updateProcessInstance ( childInstance ) ;
processInstanceDao . updateProcessInstance ( childInstance ) ;
}
}
}
}
@ -1640,24 +1645,6 @@ public class ProcessServiceImpl implements ProcessService {
return true ;
return true ;
}
}
/ * *
* insert or update work process instance to data base
*
* @param processInstance processInstance
* /
@Override
public void saveProcessInstance ( ProcessInstance processInstance ) {
if ( processInstance = = null ) {
logger . error ( "save error, process instance is null!" ) ;
return ;
}
if ( processInstance . getId ( ) ! = 0 ) {
processInstanceMapper . updateById ( processInstance ) ;
} else {
processInstanceMapper . insert ( processInstance ) ;
}
}
/ * *
/ * *
* insert or update command
* insert or update command
*
*
@ -1940,17 +1927,6 @@ public class ProcessServiceImpl implements ProcessService {
return processInstance ;
return processInstance ;
}
}
/ * *
* update process instance
*
* @param processInstance processInstance
* @return update process instance result
* /
@Override
public int updateProcessInstance ( ProcessInstance processInstance ) {
return processInstanceMapper . updateById ( processInstance ) ;
}
/ * *
/ * *
* for show in page of taskInstance
* for show in page of taskInstance
* /
* /
@ -2121,20 +2097,6 @@ public class ProcessServiceImpl implements ProcessService {
return dataSourceMapper . selectById ( id ) ;
return dataSourceMapper . selectById ( id ) ;
}
}
/ * *
* update process instance state by id
*
* @param processInstanceId processInstanceId
* @param executionStatus executionStatus
* @return update process result
* /
@Override
public int updateProcessInstanceState ( Integer processInstanceId , WorkflowExecutionStatus executionStatus ) {
ProcessInstance instance = processInstanceMapper . selectById ( processInstanceId ) ;
instance . setState ( executionStatus ) ;
return processInstanceMapper . updateById ( instance ) ;
}
/ * *
/ * *
* find process instance by the task id
* find process instance by the task id
*
*
@ -3190,8 +3152,8 @@ public class ProcessServiceImpl implements ProcessService {
. filter ( instance - > instance . getState ( ) . isFailure ( ) | | instance . getState ( ) . isKill ( ) )
. filter ( instance - > instance . getState ( ) . isFailure ( ) | | instance . getState ( ) . isKill ( ) )
. map ( TaskInstance : : getId ) . collect ( Collectors . toList ( ) ) ;
. map ( TaskInstance : : getId ) . collect ( Collectors . toList ( ) ) ;
if ( failTaskList . size ( ) = = 1 & & failTaskList . contains ( taskInstanceId ) ) {
if ( failTaskList . size ( ) = = 1 & & failTaskList . contains ( taskInstanceId ) ) {
processInstance . setState ( WorkflowExecutionStatus . SUCCESS ) ;
processInstance . setStateWithDesc ( WorkflowExecutionStatus . SUCCESS , "success by task force success" ) ;
updateProcessInstance ( processInstance ) ;
processInstanceDao . updateProcessInstance ( processInstance ) ;
}
}
}
}
}
}