org.springframework.batch.core.job.builder.FlowBuilder Java Examples

The following examples show how to use org.springframework.batch.core.job.builder.FlowBuilder. 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 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 #5
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
public ComposedRunnerJobFactory(ComposedTaskProperties properties) {
	this.composedTaskProperties = properties;
	Assert.notNull(properties.getGraph(), "The DSL must not be null");
	this.dsl = properties.getGraph();
	this.incrementInstanceEnabled = properties.isIncrementInstanceEnabled();
	this.flowBuilder = new FlowBuilder<>(UUID.randomUUID().toString());
}
 
Example #6
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 #7
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 #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: 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 #10
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 #11
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 #12
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
public ComposedRunnerJobFactory(ComposedTaskProperties properties) {
	this.composedTaskProperties = properties;
	Assert.notNull(properties.getGraph(), "The DSL must not be null");
	this.dsl = properties.getGraph();
	this.incrementInstanceEnabled = properties.isIncrementInstanceEnabled();
	this.flowBuilder = new FlowBuilder<>(UUID.randomUUID().toString());
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
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();
}