|
|
|
@ -17,12 +17,17 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service.impl; |
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import org.apache.commons.beanutils.BeanUtils; |
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
import org.apache.commons.collections.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_START; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_END_DATE; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_START_DATE; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_NODES; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_PARAMS; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.COMMA; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.MAX_TASK_TIMEOUT; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.SCHEDULE_TIME_MAX_LENGTH; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; |
|
|
|
|
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
@ -66,16 +71,18 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus;
|
|
|
|
|
import org.apache.dolphinscheduler.remote.command.StateEventChangeCommand; |
|
|
|
|
import org.apache.dolphinscheduler.remote.processor.StateEventCallbackService; |
|
|
|
|
import org.apache.dolphinscheduler.remote.utils.Host; |
|
|
|
|
import org.apache.dolphinscheduler.service.corn.CronUtils; |
|
|
|
|
import org.apache.dolphinscheduler.service.cron.CronUtils; |
|
|
|
|
import org.apache.dolphinscheduler.service.exceptions.CronParseException; |
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.beanutils.BeanUtils; |
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
import org.apache.commons.collections.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.time.ZonedDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
@ -83,16 +90,13 @@ import java.util.Map;
|
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_START; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_END_DATE; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_START_DATE; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_NODES; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_PARAMS; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.COMMA; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.MAX_TASK_TIMEOUT; |
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.SCHEDULE_TIME_MAX_LENGTH; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* executor service impl |
|
|
|
@ -155,18 +159,19 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @return execute process instance code |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> execProcessInstance(User loginUser, long projectCode, |
|
|
|
|
long processDefinitionCode, String cronTime, CommandType commandType, |
|
|
|
|
public Map<String, Object> execProcessInstance(User loginUser, long projectCode, long processDefinitionCode, |
|
|
|
|
String cronTime, CommandType commandType, |
|
|
|
|
FailureStrategy failureStrategy, String startNodeList, |
|
|
|
|
TaskDependType taskDependType, WarningType warningType, int warningGroupId, |
|
|
|
|
RunMode runMode, |
|
|
|
|
Priority processInstancePriority, String workerGroup, Long environmentCode,Integer timeout, |
|
|
|
|
TaskDependType taskDependType, WarningType warningType, |
|
|
|
|
int warningGroupId, RunMode runMode, |
|
|
|
|
Priority processInstancePriority, String workerGroup, |
|
|
|
|
Long environmentCode, Integer timeout, |
|
|
|
|
Map<String, String> startParams, Integer expectedParallelismNumber, |
|
|
|
|
int dryRun, |
|
|
|
|
ComplementDependentMode complementDependentMode) { |
|
|
|
|
int dryRun, ComplementDependentMode complementDependentMode) { |
|
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
|
|
//check user access for project
|
|
|
|
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START); |
|
|
|
|
Map<String, Object> result = |
|
|
|
|
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START); |
|
|
|
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -202,10 +207,10 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
/** |
|
|
|
|
* create command |
|
|
|
|
*/ |
|
|
|
|
int create = this.createCommand(commandType, processDefinition.getCode(), |
|
|
|
|
taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(), |
|
|
|
|
warningGroupId, runMode, processInstancePriority, workerGroup, environmentCode, startParams, |
|
|
|
|
expectedParallelismNumber, dryRun, complementDependentMode); |
|
|
|
|
int create = |
|
|
|
|
this.createCommand(commandType, processDefinition.getCode(), taskDependType, failureStrategy, startNodeList, |
|
|
|
|
cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority, workerGroup, |
|
|
|
|
environmentCode, startParams, expectedParallelismNumber, dryRun, complementDependentMode); |
|
|
|
|
|
|
|
|
|
if (create > 0) { |
|
|
|
|
processDefinition.setWarningGroupId(warningGroupId); |
|
|
|
@ -236,7 +241,6 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param complementData |
|
|
|
|
* @param cronTime |
|
|
|
|
* @return CommandType is COMPLEMENT_DATA and cronTime's number is not greater than 100 return true , otherwise return false |
|
|
|
@ -268,7 +272,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @return check result code |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> checkProcessDefinitionValid(long projectCode, ProcessDefinition processDefinition, long processDefineCode, Integer version) { |
|
|
|
|
public Map<String, Object> checkProcessDefinitionValid(long projectCode, ProcessDefinition processDefinition, |
|
|
|
|
long processDefineCode, Integer version) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
if (processDefinition == null || projectCode != processDefinition.getProjectCode()) { |
|
|
|
|
// check process definition exists
|
|
|
|
@ -287,31 +292,37 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* check if the current process has subprocesses and all subprocesses are valid |
|
|
|
|
* |
|
|
|
|
* @param processDefinition |
|
|
|
|
* @return check result |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean checkSubProcessDefinitionValid(ProcessDefinition processDefinition) { |
|
|
|
|
// query all subprocesses under the current process
|
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryDownstreamByProcessDefinitionCode(processDefinition.getCode()); |
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = |
|
|
|
|
processTaskRelationMapper.queryDownstreamByProcessDefinitionCode(processDefinition.getCode()); |
|
|
|
|
if (processTaskRelations.isEmpty()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
Set<Long> relationCodes = processTaskRelations.stream().map(ProcessTaskRelation::getPostTaskCode).collect(Collectors.toSet()); |
|
|
|
|
Set<Long> relationCodes = |
|
|
|
|
processTaskRelations.stream().map(ProcessTaskRelation::getPostTaskCode).collect(Collectors.toSet()); |
|
|
|
|
List<TaskDefinition> taskDefinitions = taskDefinitionMapper.queryByCodeList(relationCodes); |
|
|
|
|
|
|
|
|
|
// find out the process definition code
|
|
|
|
|
Set<Long> processDefinitionCodeSet = new HashSet<>(); |
|
|
|
|
taskDefinitions.stream() |
|
|
|
|
.filter(task -> TaskConstants.TASK_TYPE_SUB_PROCESS.equalsIgnoreCase(task.getTaskType())) |
|
|
|
|
.forEach(taskDefinition -> processDefinitionCodeSet.add(Long.valueOf(JSONUtils.getNodeString(taskDefinition.getTaskParams(), Constants.CMD_PARAM_SUB_PROCESS_DEFINE_CODE)))); |
|
|
|
|
.filter(task -> TaskConstants.TASK_TYPE_SUB_PROCESS.equalsIgnoreCase(task.getTaskType())).forEach( |
|
|
|
|
taskDefinition -> processDefinitionCodeSet.add(Long.valueOf( |
|
|
|
|
JSONUtils.getNodeString(taskDefinition.getTaskParams(), Constants.CMD_PARAM_SUB_PROCESS_DEFINE_CODE)))); |
|
|
|
|
if (processDefinitionCodeSet.isEmpty()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check sub releaseState
|
|
|
|
|
List<ProcessDefinition> processDefinitions = processDefinitionMapper.queryByCodes(processDefinitionCodeSet); |
|
|
|
|
return processDefinitions.stream().filter(definition -> definition.getReleaseState().equals(ReleaseState.OFFLINE)).collect(Collectors.toSet()).isEmpty(); |
|
|
|
|
return processDefinitions.stream() |
|
|
|
|
.filter(definition -> definition.getReleaseState().equals(ReleaseState.OFFLINE)).collect(Collectors.toSet()) |
|
|
|
|
.isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -329,7 +340,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
Project project = projectMapper.queryByCode(projectCode); |
|
|
|
|
//check user access for project
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode, ApiFuncIdentificationConstant.map.get(executeType)); |
|
|
|
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode, |
|
|
|
|
ApiFuncIdentificationConstant.map.get(executeType)); |
|
|
|
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -345,10 +357,13 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), |
|
|
|
|
ProcessDefinition processDefinition = |
|
|
|
|
processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), |
|
|
|
|
processInstance.getProcessDefinitionVersion()); |
|
|
|
|
if (executeType != ExecuteType.STOP && executeType != ExecuteType.PAUSE) { |
|
|
|
|
result = checkProcessDefinitionValid(projectCode, processDefinition, processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionVersion()); |
|
|
|
|
result = |
|
|
|
|
checkProcessDefinitionValid(projectCode, processDefinition, processInstance.getProcessDefinitionCode(), |
|
|
|
|
processInstance.getProcessDefinitionVersion()); |
|
|
|
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -365,7 +380,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//get the startParams user specified at the first starting while repeat running is needed
|
|
|
|
|
Map<String, Object> commandMap = JSONUtils.parseObject(processInstance.getCommandParam(), new TypeReference<Map<String, Object>>() {}); |
|
|
|
|
Map<String, Object> commandMap = |
|
|
|
|
JSONUtils.parseObject(processInstance.getCommandParam(), new TypeReference<Map<String, Object>>() { |
|
|
|
|
}); |
|
|
|
|
String startParams = null; |
|
|
|
|
if (MapUtils.isNotEmpty(commandMap) && executeType == ExecuteType.REPEAT_RUNNING) { |
|
|
|
|
Object startParamsJson = commandMap.get(Constants.CMD_PARAM_START_PARAMS); |
|
|
|
@ -376,19 +393,24 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
|
|
|
|
|
switch (executeType) { |
|
|
|
|
case REPEAT_RUNNING: |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), processDefinition.getVersion(), CommandType.REPEAT_RUNNING, startParams); |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), |
|
|
|
|
processDefinition.getVersion(), CommandType.REPEAT_RUNNING, startParams); |
|
|
|
|
break; |
|
|
|
|
case RECOVER_SUSPENDED_PROCESS: |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), processDefinition.getVersion(), CommandType.RECOVER_SUSPENDED_PROCESS, startParams); |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), |
|
|
|
|
processDefinition.getVersion(), CommandType.RECOVER_SUSPENDED_PROCESS, startParams); |
|
|
|
|
break; |
|
|
|
|
case START_FAILURE_TASK_PROCESS: |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), processDefinition.getVersion(), CommandType.START_FAILURE_TASK_PROCESS, startParams); |
|
|
|
|
result = insertCommand(loginUser, processInstanceId, processDefinition.getCode(), |
|
|
|
|
processDefinition.getVersion(), CommandType.START_FAILURE_TASK_PROCESS, startParams); |
|
|
|
|
break; |
|
|
|
|
case STOP: |
|
|
|
|
if (processInstance.getState() == ExecutionStatus.READY_STOP) { |
|
|
|
|
putMsg(result, Status.PROCESS_INSTANCE_ALREADY_CHANGED, processInstance.getName(), processInstance.getState()); |
|
|
|
|
putMsg(result, Status.PROCESS_INSTANCE_ALREADY_CHANGED, processInstance.getName(), |
|
|
|
|
processInstance.getState()); |
|
|
|
|
} else { |
|
|
|
|
result = updateProcessInstancePrepare(processInstance, CommandType.STOP, ExecutionStatus.READY_STOP); |
|
|
|
|
result = |
|
|
|
|
updateProcessInstancePrepare(processInstance, CommandType.STOP, ExecutionStatus.READY_STOP); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case PAUSE: |
|
|
|
@ -432,8 +454,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @return true if tenant suitable, otherwise return false |
|
|
|
|
*/ |
|
|
|
|
private boolean checkTenantSuitable(ProcessDefinition processDefinition) { |
|
|
|
|
Tenant tenant = processService.getTenantForProcess(processDefinition.getTenantId(), |
|
|
|
|
processDefinition.getUserId()); |
|
|
|
|
Tenant tenant = |
|
|
|
|
processService.getTenantForProcess(processDefinition.getTenantId(), processDefinition.getUserId()); |
|
|
|
|
return tenant != null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -475,7 +497,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!checkResult) { |
|
|
|
|
putMsg(result, Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), executionStatus.toString(), executeType.toString()); |
|
|
|
|
putMsg(result, Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstance.getName(), |
|
|
|
|
executionStatus.toString(), executeType.toString()); |
|
|
|
|
} else { |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
} |
|
|
|
@ -490,7 +513,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @param executionStatus execute status |
|
|
|
|
* @return update result |
|
|
|
|
*/ |
|
|
|
|
private Map<String, Object> updateProcessInstancePrepare(ProcessInstance processInstance, CommandType commandType, ExecutionStatus executionStatus) { |
|
|
|
|
private Map<String, Object> updateProcessInstancePrepare(ProcessInstance processInstance, CommandType commandType, |
|
|
|
|
ExecutionStatus executionStatus) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
processInstance.setCommandType(commandType); |
|
|
|
@ -528,8 +552,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
|
|
|
|
|
taskGroupQueue.setForceStart(Flag.YES.getCode()); |
|
|
|
|
processService.updateTaskGroupQueue(taskGroupQueue); |
|
|
|
|
processService.sendStartTask2Master(processInstance, taskGroupQueue.getTaskId() |
|
|
|
|
,org.apache.dolphinscheduler.remote.command.CommandType.TASK_FORCE_STATE_EVENT_REQUEST); |
|
|
|
|
processService.sendStartTask2Master(processInstance, taskGroupQueue.getTaskId(), |
|
|
|
|
org.apache.dolphinscheduler.remote.command.CommandType.TASK_FORCE_STATE_EVENT_REQUEST); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -544,7 +568,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @param commandType command type |
|
|
|
|
* @return insert result code |
|
|
|
|
*/ |
|
|
|
|
private Map<String, Object> insertCommand(User loginUser, Integer instanceId, long processDefinitionCode, int processVersion, CommandType commandType, String startParams) { |
|
|
|
|
private Map<String, Object> insertCommand(User loginUser, Integer instanceId, long processDefinitionCode, |
|
|
|
|
int processVersion, CommandType commandType, String startParams) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
//To add startParams only when repeat running is needed
|
|
|
|
@ -607,8 +632,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
*/ |
|
|
|
|
if (processDefinitionTmp.getReleaseState() != ReleaseState.ONLINE) { |
|
|
|
|
putMsg(result, Status.PROCESS_DEFINE_NOT_RELEASE, processDefinitionTmp.getName()); |
|
|
|
|
logger.info("not release process definition id: {} , name : {}", |
|
|
|
|
processDefinitionTmp.getId(), processDefinitionTmp.getName()); |
|
|
|
|
logger.info("not release process definition id: {} , name : {}", processDefinitionTmp.getId(), |
|
|
|
|
processDefinitionTmp.getName()); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -636,12 +661,12 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @param environmentCode environmentCode |
|
|
|
|
* @return command id |
|
|
|
|
*/ |
|
|
|
|
private int createCommand(CommandType commandType, long processDefineCode, |
|
|
|
|
TaskDependType nodeDep, FailureStrategy failureStrategy, |
|
|
|
|
String startNodeList, String schedule, WarningType warningType, |
|
|
|
|
int executorId, int warningGroupId, |
|
|
|
|
RunMode runMode, Priority processInstancePriority, String workerGroup, Long environmentCode, |
|
|
|
|
Map<String, String> startParams, Integer expectedParallelismNumber, int dryRun, ComplementDependentMode complementDependentMode) { |
|
|
|
|
private int createCommand(CommandType commandType, long processDefineCode, TaskDependType nodeDep, |
|
|
|
|
FailureStrategy failureStrategy, String startNodeList, String schedule, |
|
|
|
|
WarningType warningType, int executorId, int warningGroupId, RunMode runMode, |
|
|
|
|
Priority processInstancePriority, String workerGroup, Long environmentCode, |
|
|
|
|
Map<String, String> startParams, Integer expectedParallelismNumber, int dryRun, |
|
|
|
|
ComplementDependentMode complementDependentMode) { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* instantiate command schedule instance |
|
|
|
@ -689,11 +714,17 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
if (schedule == null || StringUtils.isEmpty(schedule)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int check = checkScheduleTime(schedule); |
|
|
|
|
if(check == 0){ |
|
|
|
|
if (!isValidateScheduleTime(schedule)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
return createComplementCommandList(schedule, runMode, command, expectedParallelismNumber, |
|
|
|
|
complementDependentMode); |
|
|
|
|
} catch (CronParseException cronParseException) { |
|
|
|
|
// this just make compile happy, since we already validate the cron before
|
|
|
|
|
logger.error("Parse cron error", cronParseException); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return createComplementCommandList(schedule, runMode, command, expectedParallelismNumber, complementDependentMode); |
|
|
|
|
} else { |
|
|
|
|
command.setCommandParam(JSONUtils.toJsonString(cmdParam)); |
|
|
|
|
return processService.createCommand(command); |
|
|
|
@ -709,7 +740,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
protected int createComplementCommandList(String scheduleTimeParam, RunMode runMode, Command command, |
|
|
|
|
Integer expectedParallelismNumber, ComplementDependentMode complementDependentMode) { |
|
|
|
|
Integer expectedParallelismNumber, |
|
|
|
|
ComplementDependentMode complementDependentMode) |
|
|
|
|
throws CronParseException { |
|
|
|
|
int createCount = 0; |
|
|
|
|
String startDate = null; |
|
|
|
|
String endDate = null; |
|
|
|
@ -722,7 +755,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
dateList = scheduleParam.get(CMDPARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST); |
|
|
|
|
dateList = removeDuplicates(dateList); |
|
|
|
|
} |
|
|
|
|
if(scheduleParam.containsKey(CMDPARAM_COMPLEMENT_DATA_START_DATE) && scheduleParam.containsKey(CMDPARAM_COMPLEMENT_DATA_END_DATE)){ |
|
|
|
|
if (scheduleParam.containsKey(CMDPARAM_COMPLEMENT_DATA_START_DATE) && scheduleParam.containsKey( |
|
|
|
|
CMDPARAM_COMPLEMENT_DATA_END_DATE)) { |
|
|
|
|
startDate = scheduleParam.get(CMDPARAM_COMPLEMENT_DATA_START_DATE); |
|
|
|
|
endDate = scheduleParam.get(CMDPARAM_COMPLEMENT_DATA_END_DATE); |
|
|
|
|
} |
|
|
|
@ -740,7 +774,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
createCount = processService.createCommand(command); |
|
|
|
|
|
|
|
|
|
// dependent process definition
|
|
|
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionCode(command.getProcessDefinitionCode()); |
|
|
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionCode( |
|
|
|
|
command.getProcessDefinitionCode()); |
|
|
|
|
|
|
|
|
|
if (schedules.isEmpty() || complementDependentMode == ComplementDependentMode.OFF_MODE) { |
|
|
|
|
logger.info("process code: {} complement dependent in off mode or schedule's size is 0, skip " |
|
|
|
@ -753,9 +788,11 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
} |
|
|
|
|
case RUN_MODE_PARALLEL: { |
|
|
|
|
if (startDate != null && endDate != null) { |
|
|
|
|
List<Date> listDate = new ArrayList<>(); |
|
|
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionCode(command.getProcessDefinitionCode()); |
|
|
|
|
listDate.addAll(CronUtils.getSelfFireDateList(DateUtils.getScheduleDate(startDate), DateUtils.getScheduleDate(endDate), schedules)); |
|
|
|
|
List<Schedule> schedules = processService.queryReleaseSchedulerListByProcessDefinitionCode( |
|
|
|
|
command.getProcessDefinitionCode()); |
|
|
|
|
List<ZonedDateTime> listDate = new ArrayList<>( |
|
|
|
|
CronUtils.getSelfFireDateList(DateUtils.stringToZoneDateTime(startDate), |
|
|
|
|
DateUtils.stringToZoneDateTime(endDate), schedules)); |
|
|
|
|
int listDateSize = listDate.size(); |
|
|
|
|
createCount = listDate.size(); |
|
|
|
|
if (!CollectionUtils.isEmpty(listDate)) { |
|
|
|
@ -791,10 +828,12 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
processService.createCommand(command); |
|
|
|
|
|
|
|
|
|
if (schedules.isEmpty() || complementDependentMode == ComplementDependentMode.OFF_MODE) { |
|
|
|
|
logger.info("process code: {} complement dependent in off mode or schedule's size is 0, skip " |
|
|
|
|
logger.info( |
|
|
|
|
"process code: {} complement dependent in off mode or schedule's size is 0, skip " |
|
|
|
|
+ "dependent complement data", command.getProcessDefinitionCode()); |
|
|
|
|
} else { |
|
|
|
|
dependentProcessDefinitionCreateCount += createComplementDependentCommand(schedules, command); |
|
|
|
|
dependentProcessDefinitionCreateCount += |
|
|
|
|
createComplementDependentCommand(schedules, command); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -823,8 +862,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
logger.info("create complement command count: {}, create dependent complement command count: {}", createCount |
|
|
|
|
, dependentProcessDefinitionCreateCount); |
|
|
|
|
logger.info("create complement command count: {}, create dependent complement command count: {}", createCount, |
|
|
|
|
dependentProcessDefinitionCreateCount); |
|
|
|
|
return createCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -844,8 +883,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
|
|
|
|
|
List<DependentProcessDefinition> dependentProcessDefinitionList = |
|
|
|
|
getComplementDependentDefinitionList(dependentCommand.getProcessDefinitionCode(), |
|
|
|
|
CronUtils.getMaxCycle(schedules.get(0).getCrontab()), |
|
|
|
|
dependentCommand.getWorkerGroup()); |
|
|
|
|
CronUtils.getMaxCycle(schedules.get(0).getCrontab()), dependentCommand.getWorkerGroup()); |
|
|
|
|
|
|
|
|
|
dependentCommand.setTaskDependType(TaskDependType.TASK_POST); |
|
|
|
|
for (DependentProcessDefinition dependentProcessDefinition : dependentProcessDefinitionList) { |
|
|
|
@ -869,7 +907,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
List<DependentProcessDefinition> dependentProcessDefinitionList = |
|
|
|
|
processService.queryDependentProcessDefinitionByProcessDefinitionCode(processDefinitionCode); |
|
|
|
|
|
|
|
|
|
return checkDependentProcessDefinitionValid(dependentProcessDefinitionList,processDefinitionCycle,workerGroup); |
|
|
|
|
return checkDependentProcessDefinitionValid(dependentProcessDefinitionList, processDefinitionCycle, |
|
|
|
|
workerGroup); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -877,20 +916,22 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
* the dependent process definition and if there is no worker group in the schedule, use the complement selection's |
|
|
|
|
* worker group |
|
|
|
|
*/ |
|
|
|
|
private List<DependentProcessDefinition> checkDependentProcessDefinitionValid(List<DependentProcessDefinition> dependentProcessDefinitionList, |
|
|
|
|
CycleEnum processDefinitionCycle, |
|
|
|
|
private List<DependentProcessDefinition> checkDependentProcessDefinitionValid( |
|
|
|
|
List<DependentProcessDefinition> dependentProcessDefinitionList, CycleEnum processDefinitionCycle, |
|
|
|
|
String workerGroup) { |
|
|
|
|
List<DependentProcessDefinition> validDependentProcessDefinitionList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
List<Long> processDefinitionCodeList = dependentProcessDefinitionList.stream() |
|
|
|
|
.map(DependentProcessDefinition::getProcessDefinitionCode) |
|
|
|
|
List<Long> processDefinitionCodeList = |
|
|
|
|
dependentProcessDefinitionList.stream().map(DependentProcessDefinition::getProcessDefinitionCode) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
Map<Long, String> processDefinitionWorkerGroupMap = processService.queryWorkerGroupByProcessDefinitionCodes(processDefinitionCodeList); |
|
|
|
|
Map<Long, String> processDefinitionWorkerGroupMap = |
|
|
|
|
processService.queryWorkerGroupByProcessDefinitionCodes(processDefinitionCodeList); |
|
|
|
|
|
|
|
|
|
for (DependentProcessDefinition dependentProcessDefinition : dependentProcessDefinitionList) { |
|
|
|
|
if (dependentProcessDefinition.getDependentCycle() == processDefinitionCycle) { |
|
|
|
|
if (processDefinitionWorkerGroupMap.get(dependentProcessDefinition.getProcessDefinitionCode()) == null) { |
|
|
|
|
if (processDefinitionWorkerGroupMap.get(dependentProcessDefinition.getProcessDefinitionCode()) |
|
|
|
|
== null) { |
|
|
|
|
dependentProcessDefinition.setWorkerGroup(workerGroup); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -902,45 +943,44 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param schedule |
|
|
|
|
* @return check error return 0 otherwish 1 |
|
|
|
|
*/ |
|
|
|
|
private int checkScheduleTime(String schedule){ |
|
|
|
|
Date start = null; |
|
|
|
|
Date end = null; |
|
|
|
|
private boolean isValidateScheduleTime(String schedule) { |
|
|
|
|
Map<String, String> scheduleResult = JSONUtils.toMap(schedule); |
|
|
|
|
if (scheduleResult == null) { |
|
|
|
|
return 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (scheduleResult.containsKey(CMDPARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST)) { |
|
|
|
|
if (scheduleResult.get(CMDPARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST) == null) { |
|
|
|
|
return 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (scheduleResult.containsKey(CMDPARAM_COMPLEMENT_DATA_START_DATE)) { |
|
|
|
|
String startDate = scheduleResult.get(CMDPARAM_COMPLEMENT_DATA_START_DATE); |
|
|
|
|
String endDate = scheduleResult.get(CMDPARAM_COMPLEMENT_DATA_END_DATE); |
|
|
|
|
if (startDate == null || endDate == null) { |
|
|
|
|
return 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
start = DateUtils.getScheduleDate(startDate); |
|
|
|
|
end = DateUtils.getScheduleDate(endDate); |
|
|
|
|
try { |
|
|
|
|
ZonedDateTime start = DateUtils.stringToZoneDateTime(startDate); |
|
|
|
|
ZonedDateTime end = DateUtils.stringToZoneDateTime(endDate); |
|
|
|
|
if (start == null || end == null) { |
|
|
|
|
return 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (start.after(end)) { |
|
|
|
|
logger.error("complement data error, wrong date start:{} and end date:{} ", |
|
|
|
|
start, end |
|
|
|
|
); |
|
|
|
|
return 0; |
|
|
|
|
if (start.isAfter(end)) { |
|
|
|
|
logger.error("complement data error, wrong date start:{} and end date:{} ", start, end); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
logger.warn("Parse schedule time error, startDate: {}, endDate: {}", startDate, endDate); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 1; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param scheduleTimeList |
|
|
|
|
* @return remove duplicate date list |
|
|
|
|
*/ |
|
|
|
|