@Override public FlowExecution call() throws Exception { return flow.start(executor); } });
/** * Constructor for a {@link FlowStep} that sets the flow and of the step * explicitly. * * @param flow the {@link Flow} instance to be associated with this step. */ public FlowStep(Flow flow) { super(flow.getName()); }
private void validateFirstStep(State startState) throws JobExecutionException { while(true) { if(startState instanceof DelegateState) { startState = ((DelegateState) startState).getState(); } else if(startState instanceof JsrStepState) { String stepName = startState.getName().substring(startState.getName().indexOf(".") + 1, startState.getName().length()); Step step = ((JsrStepState) startState).getStep(stepName); if(step instanceof DecisionStep) { throw new JobExecutionException("Decision step is an invalid first step"); } else { break; } } else if(startState instanceof FlowState){ Flow firstFlow = ((FlowState) startState).getFlows().iterator().next(); startState = firstFlow.getStates().iterator().next(); } else { break; } } }
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { return flow.start(executor).getStatus(); }
/** * Ensure that the flow is set. * @see AbstractStep#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { Assert.state(flow != null, "A Flow must be provided"); if (getName()==null) { setName(flow.getName()); } super.afterPropertiesSet(); }
/** * @param flow * @param map */ private void findSteps(Flow flow, Map<String, Step> map) { for (State state : flow.getStates()) { if (state instanceof StepLocator) { StepLocator locator = (StepLocator) state; for (String name : locator.getStepNames()) { map.put(name, locator.getStep(name)); } } else if (state instanceof StepHolder) { Step step = ((StepHolder) state).getStep(); String name = step.getName(); stepMap.put(name, step); } else if (state instanceof FlowHolder) { for (Flow subflow : ((FlowHolder) state).getFlows()) { findSteps(subflow, map); } } } }
@Test public void testBasicHandling() throws Exception { Collection<Flow> flows = new ArrayList<>(); Flow flow1 = mock(Flow.class); Flow flow2 = mock(Flow.class); flows.add(flow1); flows.add(flow2); SplitState state = new SplitState(flows, "foo"); when(flow1.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); when(flow2.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); FlowExecutionStatus result = state.handle(executor); assertEquals(FlowExecutionStatus.COMPLETED, result); }
private State createState(Object input) { State result; if (input instanceof Step) { if (!states.containsKey(input)) { Step step = (Step) input; states.put(input, new StepState(prefix + step.getName(), step)); } result = states.get(input); } else if (input instanceof JobExecutionDecider) { if (!states.containsKey(input)) { states.put(input, new DecisionState((JobExecutionDecider) input, prefix + "decision" + (decisionCounter++))); } result = states.get(input); } else if (input instanceof Flow) { if (!states.containsKey(input)) { states.put(input, new FlowState((Flow) input, prefix + ((Flow) input).getName())); } result = states.get(input); } else { throw new FlowBuilderException("No state can be created for: " + input); } dirty = true; return result; }
private void validateFirstStep(State startState) throws JobExecutionException { while(true) { if(startState instanceof DelegateState) { startState = ((DelegateState) startState).getState(); } else if(startState instanceof JsrStepState) { String stepName = startState.getName().substring(startState.getName().indexOf(".") + 1, startState.getName().length()); Step step = ((JsrStepState) startState).getStep(stepName); if(step instanceof DecisionStep) { throw new JobExecutionException("Decision step is an invalid first step"); } else { break; } } else if(startState instanceof FlowState){ Flow firstFlow = ((FlowState) startState).getFlows().iterator().next(); startState = firstFlow.getStates().iterator().next(); } else { break; } } }
@Test public void testConcurrentHandling() throws Exception { Flow flow1 = mock(Flow.class); Flow flow2 = mock(Flow.class); SplitState state = new SplitState(Arrays.asList(flow1, flow2), "foo"); state.setTaskExecutor(new SimpleAsyncTaskExecutor()); when(flow1.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); when(flow2.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); FlowExecutionStatus result = state.handle(executor); assertEquals(FlowExecutionStatus.COMPLETED, result); }
throw new FlowExecutionException("TaskExecutor rejected task for flow=" + flow.getName());
private void validateFirstStep(State startState) throws JobExecutionException { while(true) { if(startState instanceof DelegateState) { startState = ((DelegateState) startState).getState(); } else if(startState instanceof JsrStepState) { String stepName = startState.getName().substring(startState.getName().indexOf(".") + 1, startState.getName().length()); Step step = ((JsrStepState) startState).getStep(stepName); if(step instanceof DecisionStep) { throw new JobExecutionException("Decision step is an invalid first step"); } else { break; } } else if(startState instanceof FlowState){ Flow firstFlow = ((FlowState) startState).getFlows().iterator().next(); startState = firstFlow.getStates().iterator().next(); } else { break; } } }
/** * @see AbstractJob#doExecute(JobExecution) */ @Override protected void doExecute(final JobExecution execution) throws JobExecutionException { try { JobFlowExecutor executor = new JobFlowExecutor(getJobRepository(), new SimpleStepHandler(getJobRepository()), execution); executor.updateJobExecutionStatus(flow.start(executor).getStatus()); } catch (FlowExecutionException e) { if (e.getCause() instanceof JobExecutionException) { throw (JobExecutionException) e.getCause(); } throw new JobExecutionException("Flow execution ended unexpectedly", e); } }
/** * Constructor for a {@link FlowStep} that sets the flow and of the step * explicitly. */ public FlowStep(Flow flow) { super(flow.getName()); }
private void validateFirstStep(State startState) throws JobExecutionException { while(true) { if(startState instanceof DelegateState) { startState = ((DelegateState) startState).getState(); } else if(startState instanceof JsrStepState) { String stepName = startState.getName().substring(startState.getName().indexOf(".") + 1, startState.getName().length()); Step step = ((JsrStepState) startState).getStep(stepName); if(step instanceof DecisionStep) { throw new JobExecutionException("Decision step is an invalid first step"); } else { break; } } else if(startState instanceof FlowState){ Flow firstFlow = ((FlowState) startState).getFlows().iterator().next(); startState = firstFlow.getStates().iterator().next(); } else { break; } } }
/** * Delegate to the flow provided for the execution of the step. * * @see AbstractStep#doExecute(StepExecution) */ @Override protected void doExecute(StepExecution stepExecution) throws Exception { try { stepExecution.getExecutionContext().put(STEP_TYPE_KEY, this.getClass().getName()); StepHandler stepHandler = new SimpleStepHandler(getJobRepository(), stepExecution.getExecutionContext()); FlowExecutor executor = new JobFlowExecutor(getJobRepository(), stepHandler, stepExecution.getJobExecution()); executor.updateJobExecutionStatus(flow.start(executor).getStatus()); stepExecution.upgradeStatus(executor.getJobExecution().getStatus()); stepExecution.setExitStatus(executor.getJobExecution().getExitStatus()); } catch (FlowExecutionException e) { if (e.getCause() instanceof JobExecutionException) { throw (JobExecutionException) e.getCause(); } throw new JobExecutionException("Flow execution ended unexpectedly", e); } }
/** * Constructor for a {@link FlowStep} that sets the flow and of the step * explicitly. * * @param flow the {@link Flow} instance to be associated with this step. */ public FlowStep(Flow flow) { super(flow.getName()); }
/** * @param flow * @param map */ private void findSteps(Flow flow, Map<String, Step> map) { for (State state : flow.getStates()) { if (state instanceof StepLocator) { StepLocator locator = (StepLocator) state; for (String name : locator.getStepNames()) { map.put(name, locator.getStep(name)); } } else if (state instanceof StepHolder) { Step step = ((StepHolder) state).getStep(); String name = step.getName(); stepMap.put(name, step); } else if (state instanceof FlowHolder) { for (Flow subflow : ((FlowHolder) state).getFlows()) { findSteps(subflow, map); } } } }
/** * @see AbstractJob#doExecute(JobExecution) */ @Override protected void doExecute(final JobExecution execution) throws JobExecutionException { try { JobFlowExecutor executor = new JsrFlowExecutor(getJobRepository(), new JsrStepHandler(getJobRepository(), jobExplorer), execution); State startState = ((JsrFlow)flow).getStartState(); validateFirstStep(startState); executor.updateJobExecutionStatus(flow.start(executor).getStatus()); } catch (FlowExecutionException e) { if (e.getCause() instanceof JobExecutionException) { throw (JobExecutionException) e.getCause(); } throw new JobExecutionException("Flow execution ended unexpectedly", e); } }
/** * Constructor for a {@link FlowStep} that sets the flow and of the step * explicitly. * * @param flow the {@link Flow} instance to be associated with this step. */ public FlowStep(Flow flow) { super(flow.getName()); }