@ -30,6 +30,8 @@ import cn.escheduler.common.graph.DAG;
import cn.escheduler.common.model.TaskNode ;
import cn.escheduler.common.model.TaskNodeRelation ;
import cn.escheduler.common.process.Property ;
import cn.escheduler.common.queue.ITaskQueue ;
import cn.escheduler.common.queue.TaskQueueFactory ;
import cn.escheduler.common.utils.CollectionUtils ;
import cn.escheduler.common.utils.DateUtils ;
import cn.escheduler.common.utils.JSONUtils ;
@ -446,13 +448,13 @@ public class ProcessInstanceService extends BaseDAGService {
/ * *
* delete process instance by id , at the same time , delete task instance and their mapping relation data
*
* @param loginUser
* @param projectName
* @param workflowId
* @param processInstanceId
* @param tasksQueue
* @return
* /
public Map < String , Object > deleteProcessInstanceById ( User loginUser , String projectName , Integer workflowId ) {
public Map < String , Object > deleteProcessInstanceById ( User loginUser , String projectName , Integer processInstanceId , ITaskQueue tasksQueue ) {
Map < String , Object > result = new HashMap < > ( 5 ) ;
Project project = projectMapper . queryByName ( projectName ) ;
@ -462,16 +464,34 @@ public class ProcessInstanceService extends BaseDAGService {
if ( resultEnum ! = Status . SUCCESS ) {
return checkResult ;
}
ProcessInstance processInstance = processDao . findProcessInstanceDetailById ( workflowId ) ;
ProcessInstance processInstance = processDao . findProcessInstanceDetailById ( processInstanceId ) ;
List < TaskInstance > taskInstanceList = processDao . findValidTaskListByProcessId ( processInstanceId ) ;
//process instance priority
int processInstancePriority = processInstance . getProcessInstancePriority ( ) . ordinal ( ) ;
if ( processInstance = = null ) {
putMsg ( result , Status . PROCESS_INSTANCE_NOT_EXIST , workflowId ) ;
putMsg ( result , Status . PROCESS_INSTANCE_NOT_EXIST , processInstance Id) ;
return result ;
}
int delete = processDao . deleteWorkProcessInstanceById ( workflowId ) ;
processDao . deleteAllSubWorkProcessByParentId ( workflowId ) ;
processDao . deleteWorkProcessMapByParentId ( workflowId ) ;
int delete = processDao . deleteWorkProcessInstanceById ( processInstanceId ) ;
processDao . deleteAllSubWorkProcessByParentId ( processInstanceId ) ;
processDao . deleteWorkProcessMapByParentId ( processInstanceId ) ;
if ( delete > 0 ) {
if ( CollectionUtils . isNotEmpty ( taskInstanceList ) ) {
for ( TaskInstance taskInstance : taskInstanceList ) {
// task instance priority
int taskInstancePriority = taskInstance . getTaskInstancePriority ( ) . ordinal ( ) ;
String nodeValue = processInstancePriority + "_" + processInstanceId + "_" + taskInstancePriority + "_" + taskInstance . getId ( ) ;
try {
logger . info ( "delete task queue node : {}" , nodeValue ) ;
tasksQueue . removeNode ( cn . escheduler . common . Constants . SCHEDULER_TASKS_QUEUE , nodeValue ) ;
} catch ( Exception e ) {
logger . error ( "delete task queue node : {}" , nodeValue ) ;
}
}
}
putMsg ( result , Status . SUCCESS ) ;
} else {
putMsg ( result , Status . DELETE_PROCESS_INSTANCE_BY_ID_ERROR ) ;
@ -479,6 +499,50 @@ public class ProcessInstanceService extends BaseDAGService {
return result ;
}
/ * *
* batch delete process instance by ids , at the same time , delete task instance and their mapping relation data
*
* @param loginUser
* @param projectName
* @param processInstanceIds
* @return
* /
public Map < String , Object > batchDeleteProcessInstanceByIds ( User loginUser , String projectName , String processInstanceIds ) {
// task queue
ITaskQueue tasksQueue = TaskQueueFactory . getTaskQueueInstance ( ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
List < Integer > deleteFailedIdList = new ArrayList < Integer > ( ) ;
Project project = projectMapper . queryByName ( projectName ) ;
Map < String , Object > checkResult = projectService . checkProjectAndAuth ( loginUser , project , projectName ) ;
Status resultEnum = ( Status ) checkResult . get ( Constants . STATUS ) ;
if ( resultEnum ! = Status . SUCCESS ) {
return checkResult ;
}
if ( StringUtils . isNotEmpty ( processInstanceIds ) ) {
String [ ] processInstanceIdArray = processInstanceIds . split ( "," ) ;
for ( String strProcessInstanceId : processInstanceIdArray ) {
int processInstanceId = Integer . parseInt ( strProcessInstanceId ) ;
try {
deleteProcessInstanceById ( loginUser , projectName , processInstanceId , tasksQueue ) ;
} catch ( Exception e ) {
deleteFailedIdList . add ( processInstanceId ) ;
}
}
}
if ( deleteFailedIdList . size ( ) > 0 ) {
putMsg ( result , Status . BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR , StringUtils . join ( deleteFailedIdList . toArray ( ) , "," ) ) ;
} else {
putMsg ( result , Status . SUCCESS ) ;
}
return result ;
}
/ * *
* view process instance variables
*