|
@@ -39,6 +39,7 @@ import org.apache.dolphinscheduler.api.service.MonitorService;
|
|
|
import org.apache.dolphinscheduler.api.service.ProjectService;
|
|
|
import org.apache.dolphinscheduler.api.service.WorkerGroupService;
|
|
|
import org.apache.dolphinscheduler.common.constants.Constants;
|
|
|
+import org.apache.dolphinscheduler.common.enums.ApiTriggerType;
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType;
|
|
|
import org.apache.dolphinscheduler.common.enums.ComplementDependentMode;
|
|
|
import org.apache.dolphinscheduler.common.enums.CycleEnum;
|
|
@@ -52,6 +53,7 @@ import org.apache.dolphinscheduler.common.enums.TaskGroupQueueStatus;
|
|
|
import org.apache.dolphinscheduler.common.enums.WarningType;
|
|
|
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
|
|
|
import org.apache.dolphinscheduler.common.model.Server;
|
|
|
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
|
|
import org.apache.dolphinscheduler.dao.entity.Command;
|
|
@@ -85,6 +87,7 @@ import org.apache.dolphinscheduler.service.command.CommandService;
|
|
|
import org.apache.dolphinscheduler.service.cron.CronUtils;
|
|
|
import org.apache.dolphinscheduler.service.exceptions.CronParseException;
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService;
|
|
|
+import org.apache.dolphinscheduler.service.process.TriggerRelationService;
|
|
|
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -106,6 +109,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.google.common.collect.Lists;
|
|
@@ -164,6 +168,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
@Autowired
|
|
|
private WorkerGroupService workerGroupService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TriggerRelationService triggerRelationService;
|
|
|
|
|
|
* execute process instance
|
|
|
*
|
|
@@ -188,6 +194,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
* @return execute process instance code
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> execProcessInstance(User loginUser, long projectCode, long processDefinitionCode,
|
|
|
String cronTime, CommandType commandType,
|
|
|
FailureStrategy failureStrategy, String startNodeList,
|
|
@@ -239,11 +246,15 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
if (!checkMasterExists(result)) {
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ long triggerCode = CodeGenerateUtils.getInstance().genCode();
|
|
|
+
|
|
|
|
|
|
* create command
|
|
|
*/
|
|
|
int create =
|
|
|
- this.createCommand(commandType, processDefinition.getCode(), taskDependType, failureStrategy,
|
|
|
+ this.createCommand(triggerCode, commandType, processDefinition.getCode(), taskDependType,
|
|
|
+ failureStrategy,
|
|
|
startNodeList,
|
|
|
cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority,
|
|
|
workerGroup,
|
|
@@ -255,6 +266,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
processDefinitionMapper.updateById(processDefinition);
|
|
|
logger.info("Create command complete, processDefinitionCode:{}, commandCount:{}.",
|
|
|
processDefinition.getCode(), create);
|
|
|
+ result.put(Constants.DATA_LIST, triggerCode);
|
|
|
putMsg(result, Status.SUCCESS);
|
|
|
} else {
|
|
|
logger.error("Start process instance failed because create command error, processDefinitionCode:{}.",
|
|
@@ -878,7 +890,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
* @param environmentCode environmentCode
|
|
|
* @return command id
|
|
|
*/
|
|
|
- private int createCommand(CommandType commandType, long processDefineCode, TaskDependType nodeDep,
|
|
|
+ private int createCommand(Long triggerCode, CommandType commandType, long processDefineCode, TaskDependType nodeDep,
|
|
|
FailureStrategy failureStrategy, String startNodeList, String schedule,
|
|
|
WarningType warningType, int executorId, Integer warningGroupId, RunMode runMode,
|
|
|
Priority processInstancePriority, String workerGroup, Long environmentCode,
|
|
@@ -940,7 +952,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
try {
|
|
|
logger.info("Start to create {} command, processDefinitionCode:{}.",
|
|
|
command.getCommandType().getDescp(), processDefineCode);
|
|
|
- return createComplementCommandList(schedule, runMode, command, expectedParallelismNumber,
|
|
|
+ return createComplementCommandList(triggerCode, schedule, runMode, command, expectedParallelismNumber,
|
|
|
complementDependentMode);
|
|
|
} catch (CronParseException cronParseException) {
|
|
|
|
|
@@ -949,8 +961,11 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
}
|
|
|
} else {
|
|
|
command.setCommandParam(JSONUtils.toJsonString(cmdParam));
|
|
|
- logger.info("Creating command, commandInfo:{}.", command);
|
|
|
- return commandService.createCommand(command);
|
|
|
+ int count = commandService.createCommand(command);
|
|
|
+ if (count > 0) {
|
|
|
+ triggerRelationService.saveTriggerToDb(ApiTriggerType.COMMAND, triggerCode, command.getId());
|
|
|
+ }
|
|
|
+ return count;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -962,7 +977,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
* @param runMode
|
|
|
* @return
|
|
|
*/
|
|
|
- protected int createComplementCommandList(String scheduleTimeParam, RunMode runMode, Command command,
|
|
|
+ protected int createComplementCommandList(Long triggerCode, String scheduleTimeParam, RunMode runMode,
|
|
|
+ Command command,
|
|
|
Integer expectedParallelismNumber,
|
|
|
ComplementDependentMode complementDependentMode) throws CronParseException {
|
|
|
int createCount = 0;
|
|
@@ -1027,6 +1043,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
dependentProcessDefinitionCreateCount += createComplementDependentCommand(schedules, command);
|
|
|
}
|
|
|
}
|
|
|
+ if (createCount > 0) {
|
|
|
+ triggerRelationService.saveTriggerToDb(ApiTriggerType.COMMAND, triggerCode, command.getId());
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
case RUN_MODE_PARALLEL: {
|
|
@@ -1075,6 +1094,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
|
|
|
if (commandService.createCommand(command) > 0) {
|
|
|
logger.info("Create {} command complete, processDefinitionCode:{}",
|
|
|
command.getCommandType().getDescp(), command.getProcessDefinitionCode());
|
|
|
+ triggerRelationService.saveTriggerToDb(ApiTriggerType.COMMAND, triggerCode,
|
|
|
+ command.getId());
|
|
|
} else {
|
|
|
logger.error("Create {} command error, processDefinitionCode:{}",
|
|
|
command.getCommandType().getDescp(), command.getProcessDefinitionCode());
|