org.springframework.batch.core.job.flow.Flow Java Examples

The following examples show how to use org.springframework.batch.core.job.flow.Flow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 6 votes vote down vote up
private Flow processSplitNode(Deque<LabelledTaskNode> visitorDeque, SplitNode splitNode) {
	Deque<Flow> flows = new LinkedList<>();
	//For each node in the split process it as a DSL flow.
	for (LabelledTaskNode taskNode : splitNode.getSeries()) {
		Deque<Flow> resultFlowDeque = new LinkedList<>();
		flows.addAll(processSplitFlow(taskNode, resultFlowDeque));
	}
	removeProcessedNodes(visitorDeque, splitNode);
	Flow nestedSplitFlow = new FlowBuilder.SplitBuilder<>(
			new FlowBuilder<Flow>("Split" + UUID.randomUUID().toString()),
			taskExecutor)
			.add(flows.toArray(new Flow[flows.size()]))
			.build();
	FlowBuilder<Flow> taskAppFlowBuilder =
			new FlowBuilder<>("Flow" + UUID.randomUUID().toString());
	if (this.hasNestedSplit) {
		this.splitFlows = flows.size();
		int threadCorePoolSize = this.composedTaskProperties.getSplitThreadCorePoolSize();
		Assert.isTrue(threadCorePoolSize >= this.splitFlows,
				"Split thread core pool size " + threadCorePoolSize + " should be equal or greater "
						+ "than the depth of split flows " + (this.splitFlows +1) + "."
						+ " Try setting the composed task property `splitThreadCorePoolSize`");
	}
	return taskAppFlowBuilder.start(nestedSplitFlow).end();
}
 
Example #2
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private Flow processSplitNode(Deque<LabelledTaskNode> visitorDeque, SplitNode splitNode) {
	Deque<Flow> flows = new LinkedList<>();
	//For each node in the split process it as a DSL flow.
	for (LabelledTaskNode taskNode : splitNode.getSeries()) {
		Deque<Flow> resultFlowDeque = new LinkedList<>();
		flows.addAll(processSplitFlow(taskNode, resultFlowDeque));
	}
	removeProcessedNodes(visitorDeque, splitNode);
	Flow nestedSplitFlow = new FlowBuilder.SplitBuilder<>(
			new FlowBuilder<Flow>("Split" + UUID.randomUUID().toString()),
			taskExecutor)
			.add(flows.toArray(new Flow[flows.size()]))
			.build();
	FlowBuilder<Flow> taskAppFlowBuilder =
			new FlowBuilder<>("Flow" + UUID.randomUUID().toString());
	if (this.hasNestedSplit) {
		this.splitFlows = flows.size();
		int threadCorePoolSize = this.composedTaskProperties.getSplitThreadCorePoolSize();
		Assert.isTrue(threadCorePoolSize >= this.splitFlows,
				"Split thread core pool size " + threadCorePoolSize + " should be equal or greater "
						+ "than the depth of split flows " + (this.splitFlows +1) + "."
						+ " Try setting the composed task property `splitThreadCorePoolSize`");
	}
	return taskAppFlowBuilder.start(nestedSplitFlow).end();
}
 
Example #3
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
private Flow postReleaseFlow(TasksToRun tasksToRun, ReleaserProperties properties,
		ProjectsToRun projectsToRun) {
	Iterator<? extends ReleaserTask> iterator = tasksToRun.iterator();
	if (!iterator.hasNext()) {
		return null;
	}
	ReleaserTask task = iterator.next();
	Flow flow = flow(properties, projectsToRun, task);
	FlowBuilder<Flow> flowBuilder = new FlowBuilder<Flow>(
			"parallelPostRelease_" + System.currentTimeMillis()).start(flow);
	if (!iterator.hasNext()) {
		return flowBuilder.build();
	}
	FlowBuilder.SplitBuilder<Flow> builder = flowBuilder.split(taskExecutor());
	List<Flow> flows = new LinkedList<>();
	while (iterator.hasNext()) {
		flows.add(flow(properties, projectsToRun, iterator.next()));
	}
	Flow[] objects = flows.toArray(new Flow[0]);
	return builder.add(objects).build();
}
 
Example #4
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Flow createFlow() {

		while (!this.visitorDeque.isEmpty()) {

			if (this.visitorDeque.peek() instanceof TaskAppNode) {
				TaskAppNode taskAppNode = (TaskAppNode) this.visitorDeque.pop();

				if (taskAppNode.hasTransitions()) {
					handleTransition(this.executionDeque, taskAppNode);
				}
				else {
					this.executionDeque.push(getTaskAppFlow(taskAppNode));
				}
			}
			//When end marker of a split is found, process the split
			else if (this.visitorDeque.peek() instanceof SplitNode) {
				Deque<LabelledTaskNode> splitNodeDeque = new LinkedList<>();
				SplitNode splitNode = (SplitNode) this.visitorDeque.pop();
				splitNodeDeque.push(splitNode);
				while (!this.visitorDeque.isEmpty() && !this.visitorDeque.peek().equals(splitNode)) {
					splitNodeDeque.push(this.visitorDeque.pop());
				}
				splitNodeDeque.push(this.visitorDeque.pop());
				handleSplit(splitNodeDeque, splitNode);
			}
			//When start marker of a DSL flow is found, process it.
			else if (this.visitorDeque.peek() instanceof FlowNode) {
				handleFlow(this.executionDeque);
			}
		}

		return this.jobDeque.pop();
	}
 
Example #5
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void handleTransition(Deque<Flow> resultFlowDeque,
		TaskAppNode taskAppNode) {
	String beanName = getBeanName(taskAppNode);
	Step currentStep = this.context.getBean(beanName, Step.class);
	FlowBuilder<Flow> builder = new FlowBuilder<Flow>(beanName)
			.from(currentStep);

	boolean wildCardPresent = false;

	for (TransitionNode transitionNode : taskAppNode.getTransitions()) {
		String transitionBeanName = getBeanName(transitionNode);

		wildCardPresent = transitionNode.getStatusToCheck().equals(WILD_CARD);

		Step transitionStep = this.context.getBean(transitionBeanName,
				Step.class);
		builder.on(transitionNode.getStatusToCheck()).to(transitionStep)
				.from(currentStep);
	}

	if (wildCardPresent && !resultFlowDeque.isEmpty()) {
		throw new IllegalStateException(
				"Invalid flow following '*' specifier.");
	}
	else {
		//if there are nodes are in the execution Deque.  Make sure that
		//they are processed as a target of the wildcard instead of the
		//whole transition.
		if (!resultFlowDeque.isEmpty()) {
			builder.on(WILD_CARD).to(handleFlowForSegment(resultFlowDeque)).from(currentStep);
		}
	}

	resultFlowDeque.push(builder.end());
}
 
Example #6
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private Flow createFlow() {

		while (!this.visitorDeque.isEmpty()) {

			if (this.visitorDeque.peek() instanceof TaskAppNode) {
				TaskAppNode taskAppNode = (TaskAppNode) this.visitorDeque.pop();

				if (taskAppNode.hasTransitions()) {
					handleTransition(this.executionDeque, taskAppNode);
				}
				else {
					this.executionDeque.push(getTaskAppFlow(taskAppNode));
				}
			}
			//When end marker of a split is found, process the split
			else if (this.visitorDeque.peek() instanceof SplitNode) {
				Deque<LabelledTaskNode> splitNodeDeque = new LinkedList<>();
				SplitNode splitNode = (SplitNode) this.visitorDeque.pop();
				splitNodeDeque.push(splitNode);
				while (!this.visitorDeque.isEmpty() && !this.visitorDeque.peek().equals(splitNode)) {
					splitNodeDeque.push(this.visitorDeque.pop());
				}
				splitNodeDeque.push(this.visitorDeque.pop());
				handleSplit(splitNodeDeque, splitNode);
			}
			//When start marker of a DSL flow is found, process it.
			else if (this.visitorDeque.peek() instanceof FlowNode) {
				handleFlow(this.executionDeque);
			}
		}

		return this.jobDeque.pop();
	}
 
Example #7
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private void handleFlow(Deque<Flow> executionDeque) {
	if(!executionDeque.isEmpty()) {
		this.flowBuilder.start(executionDeque.pop());
	}

	while (!executionDeque.isEmpty()) {
			this.flowBuilder.next(executionDeque.pop());
	}

	this.visitorDeque.pop();
	this.jobDeque.push(this.flowBuilder.end());
}
 
Example #8
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Flow handleFlowForSegment(Deque<Flow> resultFlowDeque) {
	FlowBuilder<Flow> localTaskAppFlowBuilder =
			new FlowBuilder<>("Flow" + UUID.randomUUID().toString());

	if(!resultFlowDeque.isEmpty()) {
		localTaskAppFlowBuilder.start(resultFlowDeque.pop());

	}

	while (!resultFlowDeque.isEmpty()) {
		localTaskAppFlowBuilder.next(resultFlowDeque.pop());
	}

	return localTaskAppFlowBuilder.end();
}
 
Example #9
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private Flow handleFlowForSegment(Deque<Flow> resultFlowDeque) {
	FlowBuilder<Flow> localTaskAppFlowBuilder =
			new FlowBuilder<>("Flow" + UUID.randomUUID().toString());

	if(!resultFlowDeque.isEmpty()) {
		localTaskAppFlowBuilder.start(resultFlowDeque.pop());

	}

	while (!resultFlowDeque.isEmpty()) {
		localTaskAppFlowBuilder.next(resultFlowDeque.pop());
	}

	return localTaskAppFlowBuilder.end();
}
 
Example #10
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private void handleTransition(Deque<Flow> resultFlowDeque,
		TaskAppNode taskAppNode) {
	String beanName = getBeanName(taskAppNode);
	Step currentStep = this.context.getBean(beanName, Step.class);
	FlowBuilder<Flow> builder = new FlowBuilder<Flow>(beanName)
			.from(currentStep);

	boolean wildCardPresent = false;

	for (TransitionNode transitionNode : taskAppNode.getTransitions()) {
		String transitionBeanName = getBeanName(transitionNode);

		wildCardPresent = transitionNode.getStatusToCheck().equals(WILD_CARD);

		Step transitionStep = this.context.getBean(transitionBeanName,
				Step.class);
		builder.on(transitionNode.getStatusToCheck()).to(transitionStep)
				.from(currentStep);
	}

	if (wildCardPresent && !resultFlowDeque.isEmpty()) {
		throw new IllegalStateException(
				"Invalid flow following '*' specifier.");
	}
	else {
		//if there are nodes are in the execution Deque.  Make sure that
		//they are processed as a target of the wildcard instead of the
		//whole transition.
		if (!resultFlowDeque.isEmpty()) {
			builder.on(WILD_CARD).to(handleFlowForSegment(resultFlowDeque)).from(currentStep);
		}
	}

	resultFlowDeque.push(builder.end());
}
 
Example #11
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void handleFlow(Deque<Flow> executionDeque) {
	if(!executionDeque.isEmpty()) {
		this.flowBuilder.start(executionDeque.pop());
	}

	while (!executionDeque.isEmpty()) {
			this.flowBuilder.next(executionDeque.pop());
	}

	this.visitorDeque.pop();
	this.jobDeque.push(this.flowBuilder.end());
}
 
Example #12
Source File: SettleJobConfiguration.java    From seed with Apache License 2.0 5 votes vote down vote up
private Flow splitFlow(){
    Flow flow04 = new FlowBuilder<SimpleFlow>("flow04").start(step0004).build();
    Flow flow05 = new FlowBuilder<SimpleFlow>("flow05").start(step0005).build();
    Flow flow06 = new FlowBuilder<SimpleFlow>("flow06").start(step0006).build();
    return new FlowBuilder<SimpleFlow>("splitFlow")
            .split(new SimpleAsyncTaskExecutor("springbatch_seedboot"))
            .add(flow04, flow05, flow06)
            .build();
}
 
Example #13
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionResult runPostReleaseTrainTasks(Options options,
		ReleaserProperties properties, String taskName, TasksToRun tasksToRun) {
	ProjectsToRun projectsToRun = postReleaseTrainProjects(
			new OptionsAndProperties(properties, options));
	Flow flow = postReleaseFlow(tasksToRun, properties, projectsToRun);
	String name = taskName + "_" + System.currentTimeMillis();
	if (flow == null) {
		log.info("No release train post release tasks to run, will do nothing");
		return ExecutionResult.success();
	}
	Job job = this.jobBuilderFactory.get(name).start(flow).build().build();
	return runJob(job);
}
 
Example #14
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Flow toFlowOfTasks(TasksToRun tasksToRun, NamedArgumentsSupplier args,
		FlowBuilder<Flow> flowBuilder) {
	Iterator<? extends ReleaserTask> iterator = tasksToRun.iterator();
	ReleaserTask task = iterator.next();
	flowBuilder.start(createStep(task, args));
	while (iterator.hasNext()) {
		flowBuilder.next(createStep(iterator.next(), args));
	}
	return flowBuilder.build();
}
 
Example #15
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Flow flow(ReleaserProperties properties, ProjectsToRun projectsToRun,
		ReleaserTask task) {
	return new FlowBuilder<Flow>(task.name() + "Flow")
			.start(createStep(task, new NamedArgumentsSupplier("postRelease",
					() -> Arguments.forPostRelease(properties, projectsToRun))))
			.build();
}
 
Example #16
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
/**
 * Processes each node in split as a  DSL Flow.
 * @param node represents a single node in the split.
 * @return Deque of Job Flows that was obtained from the Node.
 */
private Deque<Flow> processSplitFlow(LabelledTaskNode node, Deque<Flow> resultFlowDeque) {
	TaskParser taskParser = new TaskParser("split_flow" + UUID.randomUUID().toString(), node.stringify(),
			false, true);
	ComposedRunnerVisitor splitElementVisitor = new ComposedRunnerVisitor();
	taskParser.parse().accept(splitElementVisitor);

	Deque splitElementDeque = splitElementVisitor.getFlow();
	Deque<Flow> elementFlowDeque = new LinkedList<>();

	while (!splitElementDeque.isEmpty()) {

		if (splitElementDeque.peek() instanceof TaskAppNode) {

			TaskAppNode taskAppNode = (TaskAppNode) splitElementDeque.pop();

			if (taskAppNode.hasTransitions()) {
				handleTransition(elementFlowDeque, taskAppNode);
			}
			else {
				elementFlowDeque.push(
						getTaskAppFlow(taskAppNode));
			}
		}
		else if (splitElementDeque.peek() instanceof FlowNode) {
			resultFlowDeque.push(handleFlowForSegment(elementFlowDeque));
			splitElementDeque.pop();
		}
		else if (splitElementDeque.peek() instanceof SplitNode) {
			this.hasNestedSplit = true;
			Deque splitNodeDeque = new LinkedList<>();
			SplitNode splitNode = (SplitNode) splitElementDeque.pop();
			splitNodeDeque.push(splitNode);
			while (!splitElementDeque.isEmpty() && !splitElementDeque.peek().equals(splitNode)) {
				splitNodeDeque.push(splitElementDeque.pop());
			}
			splitNodeDeque.push(splitElementDeque.pop());
			elementFlowDeque.push(processSplitNode(splitNodeDeque, splitNode));
		}
	}
	return resultFlowDeque;
}
 
Example #17
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
private Flow getTaskAppFlow(TaskAppNode taskApp) {
	String beanName = getBeanName(taskApp);
	Step currentStep = this.context.getBean(beanName, Step.class);

	return new FlowBuilder<Flow>(beanName).from(currentStep).end();
}
 
Example #18
Source File: FlowJobDemo.java    From SpringAll with MIT License 4 votes vote down vote up
private Flow flow() {
    return new FlowBuilder<Flow>("flow")
            .start(step1())
            .next(step2())
            .build();
}
 
Example #19
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
StuffToRun(ReleaseGroup releaseGroup, Flow flow) {
	this.releaseGroup = releaseGroup;
	this.flow = flow;
	this.task = null;
}
 
Example #20
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
private FlowBuilder<Flow> flowBuilder(String projectName) {
	return new FlowBuilder<>(projectName + "_Flow_" + System.currentTimeMillis());
}
 
Example #21
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 4 votes vote down vote up
private Flow getTaskAppFlow(TaskAppNode taskApp) {
	String beanName = getBeanName(taskApp);
	Step currentStep = this.context.getBean(beanName, Step.class);

	return new FlowBuilder<Flow>(beanName).from(currentStep).end();
}
 
Example #22
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 4 votes vote down vote up
/**
 * Processes each node in split as a  DSL Flow.
 * @param node represents a single node in the split.
 * @return Deque of Job Flows that was obtained from the Node.
 */
private Deque<Flow> processSplitFlow(LabelledTaskNode node, Deque<Flow> resultFlowDeque) {
	TaskParser taskParser = new TaskParser("split_flow" + UUID.randomUUID().toString(), node.stringify(),
			false, true);
	ComposedRunnerVisitor splitElementVisitor = new ComposedRunnerVisitor();
	taskParser.parse().accept(splitElementVisitor);

	Deque splitElementDeque = splitElementVisitor.getFlow();
	Deque<Flow> elementFlowDeque = new LinkedList<>();

	while (!splitElementDeque.isEmpty()) {

		if (splitElementDeque.peek() instanceof TaskAppNode) {

			TaskAppNode taskAppNode = (TaskAppNode) splitElementDeque.pop();

			if (taskAppNode.hasTransitions()) {
				handleTransition(elementFlowDeque, taskAppNode);
			}
			else {
				elementFlowDeque.push(
						getTaskAppFlow(taskAppNode));
			}
		}
		else if (splitElementDeque.peek() instanceof FlowNode) {
			resultFlowDeque.push(handleFlowForSegment(elementFlowDeque));
			splitElementDeque.pop();
		}
		else if (splitElementDeque.peek() instanceof SplitNode) {
			this.hasNestedSplit = true;
			Deque splitNodeDeque = new LinkedList<>();
			SplitNode splitNode = (SplitNode) splitElementDeque.pop();
			splitNodeDeque.push(splitNode);
			while (!splitElementDeque.isEmpty() && !splitElementDeque.peek().equals(splitNode)) {
				splitNodeDeque.push(splitElementDeque.pop());
			}
			splitNodeDeque.push(splitElementDeque.pop());
			elementFlowDeque.push(processSplitNode(splitNodeDeque, splitNode));
		}
	}
	return resultFlowDeque;
}
 
Example #23
Source File: SplitJobDemo.java    From SpringAll with MIT License 4 votes vote down vote up
private Flow flow2() {
    return new FlowBuilder<Flow>("flow2")
            .start(step3())
            .build();
}
 
Example #24
Source File: SplitJobDemo.java    From SpringAll with MIT License 4 votes vote down vote up
private Flow flow1() {
    return new FlowBuilder<Flow>("flow1")
            .start(step1())
            .next(step2())
            .build();
}