XD-1622: Add tasklet and step type to Step's ExecutionContext for XD usage
This commit is contained in:
@@ -24,6 +24,7 @@ package org.springframework.batch.core;
|
||||
*/
|
||||
public interface Step {
|
||||
|
||||
static final String STEP_TYPE_KEY = "batch.stepType";
|
||||
/**
|
||||
* @return the name of this step.
|
||||
*/
|
||||
|
||||
@@ -84,6 +84,7 @@ public class FlowStep extends AbstractStep {
|
||||
@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());
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.batch.core.partition.support;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecutionException;
|
||||
import org.springframework.batch.core.Step;
|
||||
@@ -28,6 +26,8 @@ import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Step} which partitions the execution and spreads the
|
||||
* load using a {@link PartitionHandler}.
|
||||
@@ -100,6 +100,7 @@ public class PartitionStep extends AbstractStep {
|
||||
*/
|
||||
@Override
|
||||
protected void doExecute(StepExecution stepExecution) throws Exception {
|
||||
stepExecution.getExecutionContext().put(STEP_TYPE_KEY, this.getClass().getName());
|
||||
|
||||
// Wait for task completion and then aggregate the results
|
||||
Collection<StepExecution> executions = partitionHandler.handle(stepExecutionSplitter, stepExecution);
|
||||
|
||||
@@ -103,6 +103,8 @@ public class JobStep extends AbstractStep {
|
||||
|
||||
ExecutionContext executionContext = stepExecution.getExecutionContext();
|
||||
|
||||
executionContext.put(STEP_TYPE_KEY, this.getClass().getName());
|
||||
|
||||
JobParameters jobParameters;
|
||||
if (executionContext.containsKey(JOB_PARAMETERS_KEY)) {
|
||||
jobParameters = (JobParameters) executionContext.get(JOB_PARAMETERS_KEY);
|
||||
|
||||
@@ -100,6 +100,8 @@ public class TaskletStep extends AbstractStep {
|
||||
|
||||
private Tasklet tasklet;
|
||||
|
||||
public static final String TASKLET_TYPE_KEY = "batch.taskletType";
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@@ -242,6 +244,8 @@ public class TaskletStep extends AbstractStep {
|
||||
*/
|
||||
@Override
|
||||
protected void doExecute(StepExecution stepExecution) throws Exception {
|
||||
stepExecution.getExecutionContext().put(TASKLET_TYPE_KEY, tasklet.getClass().getName());
|
||||
stepExecution.getExecutionContext().put(STEP_TYPE_KEY, this.getClass().getName());
|
||||
|
||||
stream.update(stepExecution.getExecutionContext());
|
||||
getJobRepository().updateExecutionContext(stepExecution);
|
||||
|
||||
@@ -15,16 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.batch.core.BatchStatus.COMPLETED;
|
||||
import static org.springframework.batch.core.BatchStatus.FAILED;
|
||||
import static org.springframework.batch.core.BatchStatus.STOPPED;
|
||||
import static org.springframework.batch.core.BatchStatus.UNKNOWN;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
@@ -32,6 +22,7 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
@@ -54,6 +45,16 @@ import org.springframework.transaction.UnexpectedRollbackException;
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.batch.core.BatchStatus.COMPLETED;
|
||||
import static org.springframework.batch.core.BatchStatus.FAILED;
|
||||
import static org.springframework.batch.core.BatchStatus.STOPPED;
|
||||
import static org.springframework.batch.core.BatchStatus.UNKNOWN;
|
||||
|
||||
/**
|
||||
* Tests for the behavior of TaskletStep in a failure scenario.
|
||||
*
|
||||
@@ -245,7 +246,9 @@ public class TaskletStepExceptionTests {
|
||||
assertEquals(1, stepExecution.getRollbackCount()); // Failed transaction
|
||||
// counts as
|
||||
// rollback
|
||||
assertEquals(0, stepExecution.getExecutionContext().size());
|
||||
assertEquals(2, stepExecution.getExecutionContext().size());
|
||||
assertTrue(stepExecution.getExecutionContext().containsKey(Step.STEP_TYPE_KEY));
|
||||
assertTrue(stepExecution.getExecutionContext().containsKey(TaskletStep.TASKLET_TYPE_KEY));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -278,7 +281,9 @@ public class TaskletStepExceptionTests {
|
||||
assertEquals(1, stepExecution.getRollbackCount()); // Failed transaction
|
||||
// counts as
|
||||
// rollback
|
||||
assertEquals(0, stepExecution.getExecutionContext().size());
|
||||
assertEquals(2, stepExecution.getExecutionContext().size());
|
||||
assertTrue(stepExecution.getExecutionContext().containsKey(Step.STEP_TYPE_KEY));
|
||||
assertTrue(stepExecution.getExecutionContext().containsKey(TaskletStep.TASKLET_TYPE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user