|
|
@ -29,6 +29,8 @@ import org.apache.dolphinscheduler.server.master.registry.ServerNodeManager; |
|
|
|
import org.apache.dolphinscheduler.service.exceptions.CronParseException; |
|
|
|
import org.apache.dolphinscheduler.service.exceptions.CronParseException; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -50,21 +52,22 @@ public class WorkflowExecuteContextFactory { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private MasterConfig masterConfig; |
|
|
|
private MasterConfig masterConfig; |
|
|
|
|
|
|
|
|
|
|
|
public IWorkflowExecuteContext createWorkflowExecuteRunnableContext(Command command) throws Exception { |
|
|
|
public Optional<IWorkflowExecuteContext> createWorkflowExecuteRunnableContext(Command command) throws Exception { |
|
|
|
ProcessInstance workflowInstance = createWorkflowInstance(command); |
|
|
|
Optional<ProcessInstance> workflowInstanceOptional = createWorkflowInstance(command); |
|
|
|
|
|
|
|
if (!workflowInstanceOptional.isPresent()) { |
|
|
|
|
|
|
|
return Optional.empty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ProcessInstance workflowInstance = workflowInstanceOptional.get(); |
|
|
|
ProcessDefinition workflowDefinition = processService.findProcessDefinition( |
|
|
|
ProcessDefinition workflowDefinition = processService.findProcessDefinition( |
|
|
|
workflowInstance.getProcessDefinitionCode(), workflowInstance.getProcessDefinitionVersion()); |
|
|
|
workflowInstance.getProcessDefinitionCode(), workflowInstance.getProcessDefinitionVersion()); |
|
|
|
workflowInstance.setProcessDefinition(workflowDefinition); |
|
|
|
workflowInstance.setProcessDefinition(workflowDefinition); |
|
|
|
|
|
|
|
|
|
|
|
IWorkflowGraph workflowGraph = workflowGraphFactory.createWorkflowGraph(workflowInstance); |
|
|
|
IWorkflowGraph workflowGraph = workflowGraphFactory.createWorkflowGraph(workflowInstance); |
|
|
|
|
|
|
|
|
|
|
|
return new WorkflowExecuteContext( |
|
|
|
return Optional.of(new WorkflowExecuteContext(workflowDefinition, workflowInstance, workflowGraph)); |
|
|
|
workflowDefinition, |
|
|
|
|
|
|
|
workflowInstance, |
|
|
|
|
|
|
|
workflowGraph); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ProcessInstance createWorkflowInstance(Command command) throws CronParseException { |
|
|
|
private Optional<ProcessInstance> createWorkflowInstance(Command command) throws CronParseException { |
|
|
|
long commandTransformStartTime = System.currentTimeMillis(); |
|
|
|
long commandTransformStartTime = System.currentTimeMillis(); |
|
|
|
// Note: this check is not safe, the slot may change after command transform.
|
|
|
|
// Note: this check is not safe, the slot may change after command transform.
|
|
|
|
// We use the database transaction in `handleCommand` so that we can guarantee the command will
|
|
|
|
// We use the database transaction in `handleCommand` so that we can guarantee the command will
|
|
|
@ -76,10 +79,9 @@ public class WorkflowExecuteContextFactory { |
|
|
|
throw new RuntimeException("Slot check failed the current state: " + slotCheckState); |
|
|
|
throw new RuntimeException("Slot check failed the current state: " + slotCheckState); |
|
|
|
} |
|
|
|
} |
|
|
|
ProcessInstance processInstance = processService.handleCommand(masterConfig.getMasterAddress(), command); |
|
|
|
ProcessInstance processInstance = processService.handleCommand(masterConfig.getMasterAddress(), command); |
|
|
|
log.info("Master handle command {} end, create process instance {}", command.getId(), processInstance.getId()); |
|
|
|
|
|
|
|
ProcessInstanceMetrics |
|
|
|
ProcessInstanceMetrics |
|
|
|
.recordProcessInstanceGenerateTime(System.currentTimeMillis() - commandTransformStartTime); |
|
|
|
.recordProcessInstanceGenerateTime(System.currentTimeMillis() - commandTransformStartTime); |
|
|
|
return processInstance; |
|
|
|
return Optional.ofNullable(processInstance); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private SlotCheckState slotCheck(Command command) { |
|
|
|
private SlotCheckState slotCheck(Command command) { |
|
|
|