You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2014/01/18 09:17:21 UTC
git commit: BATCHEE-3 JobContext/StepContext id info are internals
Updated Branches:
refs/heads/master 05ce7124b -> 349bccfe7
BATCHEE-3 JobContext/StepContext id info are internals
Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/349bccfe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/349bccfe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/349bccfe
Branch: refs/heads/master
Commit: 349bccfe70e898a479a33de0aa90983c2c6aea58
Parents: 05ce712
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sat Jan 18 09:16:57 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sat Jan 18 09:16:57 2014 +0100
----------------------------------------------------------------------
.../batchee/container/ThreadRootController.java | 2 +
.../batchee/container/impl/StepContextImpl.java | 19 +++--
.../impl/controller/BaseStepController.java | 13 ++-
.../impl/controller/ExecutionTransitioner.java | 8 ++
.../controller/JobThreadRootController.java | 9 ++
.../controller/PartitionedStepController.java | 10 +--
.../impl/jobinstance/RuntimeJobExecution.java | 5 ++
.../container/services/BatchKernelService.java | 4 +-
.../services/kernel/DefaultBatchKernel.java | 6 +-
.../persistence/JDBCPersistenceManager.java | 2 +-
.../persistence/JPAPersistenceService.java | 2 +-
.../persistence/MemoryPersistenceManager.java | 2 +-
.../container/util/BatchPartitionWorkUnit.java | 6 +-
.../apache/batchee/test/id/PartitionIdTest.java | 90 ++++++++++++++++++++
.../META-INF/batch-jobs/partition-execId.xml | 37 ++++++++
.../org/apache/batchee/test/StepLauncher.java | 2 +-
16 files changed, 198 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/ThreadRootController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/ThreadRootController.java b/jbatch/src/main/java/org/apache/batchee/container/ThreadRootController.java
index d45241f..1419fb3 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/ThreadRootController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/ThreadRootController.java
@@ -16,8 +16,10 @@
*/
package org.apache.batchee.container;
+import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.status.ExecutionStatus;
public interface ThreadRootController extends Controller {
ExecutionStatus originateExecutionOnThread();
+ void setParentStepContext(StepContextImpl stepContext);
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/StepContextImpl.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/StepContextImpl.java b/jbatch/src/main/java/org/apache/batchee/container/impl/StepContextImpl.java
index 5408d6b..df266e7 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/StepContextImpl.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/StepContextImpl.java
@@ -37,14 +37,14 @@ public class StepContextImpl implements StepContext {
private Timestamp starttime = null;
private Timestamp endtime = null;
- private long stepExecID = 0;
+ private long stepExecID = Integer.MIN_VALUE;
+ private long stepInternalExecID = 0;
- private Properties properties = new Properties();
+ private final Properties properties = new Properties();
private String batchletProcessRetVal = null;
-
- private ConcurrentHashMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
+ private final ConcurrentHashMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
public StepContextImpl(String stepId) {
this.stepId = stepId;
@@ -140,9 +140,18 @@ public class StepContextImpl implements StepContext {
return stepExecID;
}
+ public long getStepInternalExecID() {
+ return stepInternalExecID;
+ }
public void setStepExecutionId(long stepExecutionId) {
- stepExecID = stepExecutionId;
+ if (stepExecID == Integer.MIN_VALUE) {
+ stepExecID = stepExecutionId;
+ }
+ }
+
+ public void setInternalStepExecutionId(long stepExecutionId) {
+ stepInternalExecID = stepExecutionId;
}
public void setStartTime(Timestamp startTS) {
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
index d261598..16ed31d 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
@@ -281,6 +281,7 @@ public abstract class BaseStepController implements ExecutionElementController {
final StepExecutionImpl stepExecution = getNewStepExecution(rootJobExecutionId, stepContext);
// create new step status for this run
stepStatus = statusManagerService.createStepStatus(stepExecution.getStepExecutionId());
+ stepContext.setInternalStepExecutionId(stepExecution.getStepExecutionId());
stepContext.setStepExecutionId(stepExecution.getStepExecutionId());
return true;
} else {
@@ -293,8 +294,10 @@ public abstract class BaseStepController implements ExecutionElementController {
stepStatus.incrementStartCount();
// create new step execution
final StepExecutionImpl stepExecution = getNewStepExecution(rootJobExecutionId, stepContext);
- this.stepStatus.setLastRunStepExecutionId(stepExecution.getStepExecutionId());
- stepContext.setStepExecutionId(stepExecution.getStepExecutionId());
+ final long stepExecutionId = stepExecution.getStepExecutionId();
+ this.stepStatus.setLastRunStepExecutionId(stepExecutionId);
+ stepContext.setStepExecutionId(stepExecutionId);
+ stepContext.setInternalStepExecutionId(stepExecutionId);
return true;
}
return false;
@@ -422,4 +425,10 @@ public abstract class BaseStepController implements ExecutionElementController {
public String toString() {
return "BaseStepController for step = " + step.getId();
}
+
+ public void setParentStepContext(final StepContextImpl parentStepContext) {
+ if (parentStepContext != null) {
+ stepContext.setStepExecutionId(parentStepContext.getStepExecutionId());
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/controller/ExecutionTransitioner.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/ExecutionTransitioner.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/ExecutionTransitioner.java
index faf7669..b2c4436 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/ExecutionTransitioner.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/ExecutionTransitioner.java
@@ -62,6 +62,7 @@ public class ExecutionTransitioner {
private BlockingQueue<PartitionDataWrapper> analyzerQueue = null;
private List<Long> stepExecIds;
+ private StepContextImpl parentStepContext;
public ExecutionTransitioner(final RuntimeJobExecution jobExecution, final long rootJobExecutionId, final ModelNavigator<?> modelNavigator,
final ServicesManager servicesManager) {
@@ -99,6 +100,9 @@ public class ExecutionTransitioner {
final ExecutionElementController currentElementController = getNextElementController();
currentStoppableElementController = currentElementController;
+ if (BaseStepController.class.isInstance(currentElementController)) {
+ BaseStepController.class.cast(currentElementController).setParentStepContext(parentStepContext);
+ }
final ExecutionStatus status = currentElementController.execute();
// Nothing special for decision or step except to get exit status. For flow and split we want to bubble up though.
@@ -238,4 +242,8 @@ public class ExecutionTransitioner {
public List<Long> getStepExecIds() {
return stepExecIds;
}
+
+ public void setParentStepContext(final StepContextImpl parentStepContext) {
+ this.parentStepContext = parentStepContext;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/controller/JobThreadRootController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/JobThreadRootController.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/JobThreadRootController.java
index feb3f1c..ece942f 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/JobThreadRootController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/JobThreadRootController.java
@@ -19,6 +19,7 @@ package org.apache.batchee.container.impl.controller;
import org.apache.batchee.container.Controller;
import org.apache.batchee.container.ThreadRootController;
import org.apache.batchee.container.impl.JobContextImpl;
+import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
import org.apache.batchee.container.navigator.ModelNavigator;
import org.apache.batchee.container.proxy.InjectionReferences;
@@ -55,6 +56,8 @@ public abstract class JobThreadRootController implements ThreadRootController {
protected final PersistenceManagerService persistenceService;
protected final ServicesManager manager;
+ protected StepContextImpl parentStepContext = null;
+
private ExecutionTransitioner transitioner;
private BlockingQueue<PartitionDataWrapper> analyzerQueue;
@@ -102,6 +105,7 @@ public abstract class JobThreadRootController implements ThreadRootController {
// within the job !!!
// --------------------
transitioner = new ExecutionTransitioner(jobExecution, rootJobExecutionId, jobNavigator, analyzerQueue, manager);
+ transitioner.setParentStepContext(parentStepContext);
retVal = transitioner.doExecutionLoop();
ExtendedBatchStatus extBatchStatus = retVal.getExtendedBatchStatus();
switch (extBatchStatus) {
@@ -276,4 +280,9 @@ public abstract class JobThreadRootController implements ThreadRootController {
public List<Long> getLastRunStepExecutions() {
return this.transitioner.getStepExecIds();
}
+
+ @Override
+ public void setParentStepContext(final StepContextImpl parentStepContext) {
+ this.parentStepContext = parentStepContext;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/controller/PartitionedStepController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/PartitionedStepController.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/PartitionedStepController.java
index b673e3d..2d1dd24 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/PartitionedStepController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/PartitionedStepController.java
@@ -290,7 +290,7 @@ public class PartitionedStepController extends BaseStepController {
if (stepStatus.getStartCount() > 1 && !plan.getPartitionsOverride()) {
parallelBatchWorkUnits = kernelService.buildOnRestartParallelPartitions(config);
} else {
- parallelBatchWorkUnits = kernelService.buildNewParallelPartitions(config);
+ parallelBatchWorkUnits = kernelService.buildNewParallelPartitions(config, jobExecutionImpl.getJobContext(), stepContext);
}
// NOTE: At this point I might not have as many work units as I had partitions, since some may have already completed.
@@ -364,13 +364,13 @@ public class PartitionedStepController extends BaseStepController {
for (final BatchWorkUnit subJob : completedWork) {
final List<StepExecution> steps = persistenceManagerService.getStepExecutionsForJobExecution(subJob.getJobExecutionImpl().getExecutionId());
- if (steps.size() != 1) {
- // TODO: possible?
- } else {
+ if (steps.size() == 1) {
for (final Metric metric : steps.iterator().next().getMetrics()) {
stepContext.getMetric(metric.getType()).incValueBy(metric.getValue());
}
- }
+ }/* else {
+ // TODO: possible?
+ }*/
final BatchStatus batchStatus = subJob.getJobExecutionImpl().getJobContext().getBatchStatus();
if (batchStatus.equals(BatchStatus.FAILED)) {
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/impl/jobinstance/RuntimeJobExecution.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/jobinstance/RuntimeJobExecution.java b/jbatch/src/main/java/org/apache/batchee/container/impl/jobinstance/RuntimeJobExecution.java
index b1b81c4..184fe02 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/jobinstance/RuntimeJobExecution.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/jobinstance/RuntimeJobExecution.java
@@ -69,6 +69,11 @@ public class RuntimeJobExecution {
prepareForExecution(jobContext, null);
}
+ public void inheritJobContext(final JobContextImpl jc) {
+ jobContext.setExecutionId(jc.getExecutionId());
+ jobContext.setInstanceId(jc.getInstanceId());
+ }
+
public void setRestartOn(final String restartOn) {
this.restartOn = restartOn;
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java b/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
index e423c18..99c8abe 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/BatchKernelService.java
@@ -16,6 +16,8 @@
*/
package org.apache.batchee.container.services;
+import org.apache.batchee.container.impl.JobContextImpl;
+import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
import org.apache.batchee.container.util.BatchFlowInSplitWorkUnit;
import org.apache.batchee.container.util.BatchPartitionWorkUnit;
@@ -49,7 +51,7 @@ public interface BatchKernelService extends BatchService {
JobInstance getJobInstance(long instanceId);
- List<BatchPartitionWorkUnit> buildNewParallelPartitions(PartitionsBuilderConfig config) throws JobRestartException, JobStartException;
+ List<BatchPartitionWorkUnit> buildNewParallelPartitions(PartitionsBuilderConfig config, JobContextImpl jc, StepContextImpl sc) throws JobRestartException, JobStartException;
List<BatchPartitionWorkUnit> buildOnRestartParallelPartitions(PartitionsBuilderConfig config) throws JobRestartException, JobExecutionAlreadyCompleteException, JobExecutionNotMostRecentException;
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/services/kernel/DefaultBatchKernel.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/kernel/DefaultBatchKernel.java b/jbatch/src/main/java/org/apache/batchee/container/services/kernel/DefaultBatchKernel.java
index f69ad95..39ab4dc 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/services/kernel/DefaultBatchKernel.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/kernel/DefaultBatchKernel.java
@@ -18,6 +18,8 @@ package org.apache.batchee.container.services.kernel;
import org.apache.batchee.container.ThreadRootController;
import org.apache.batchee.container.exception.BatchContainerServiceException;
+import org.apache.batchee.container.impl.JobContextImpl;
+import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.jobinstance.JobExecutionHelper;
import org.apache.batchee.container.impl.jobinstance.RuntimeFlowInSplitExecution;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
@@ -156,7 +158,7 @@ public class DefaultBatchKernel implements BatchKernelService {
*/
@Override
- public List<BatchPartitionWorkUnit> buildNewParallelPartitions(final PartitionsBuilderConfig config)
+ public List<BatchPartitionWorkUnit> buildNewParallelPartitions(final PartitionsBuilderConfig config, final JobContextImpl jc, final StepContextImpl sc)
throws JobRestartException, JobStartException {
final List<JSLJob> jobModels = config.getJobModels();
@@ -167,9 +169,11 @@ public class DefaultBatchKernel implements BatchKernelService {
for (final JSLJob parallelJob : jobModels) {
final Properties partitionProps = (partitionPropertiesArray == null) ? null : partitionPropertiesArray[instance];
final RuntimeJobExecution jobExecution = JobExecutionHelper.startPartition(servicesManager, parallelJob, partitionProps);
+ jobExecution.inheritJobContext(jc);
jobExecution.setPartitionInstance(instance);
final BatchPartitionWorkUnit batchWork = new BatchPartitionWorkUnit(jobExecution, config, servicesManager);
+ batchWork.inheritStepContext(sc);
registerCurrentInstanceAndExecution(jobExecution, batchWork.getController());
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JDBCPersistenceManager.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JDBCPersistenceManager.java b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JDBCPersistenceManager.java
index 056b05e..4fd158b 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JDBCPersistenceManager.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JDBCPersistenceManager.java
@@ -1297,7 +1297,7 @@ public class JDBCPersistenceManager implements PersistenceManagerService {
@Override
public void updateStepExecution(final long rootJobExecId, final StepContextImpl stepContext) {
- final long stepExecutionId = stepContext.getStepExecutionId();
+ final long stepExecutionId = stepContext.getStepInternalExecID();
final String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name();
final String exitStatus = stepContext.getExitStatus();
final String stepName = stepContext.getStepName();
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JPAPersistenceService.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JPAPersistenceService.java b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JPAPersistenceService.java
index 5d8a4fe..1026d3c 100644
--- a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JPAPersistenceService.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/JPAPersistenceService.java
@@ -216,7 +216,7 @@ public class JPAPersistenceService implements PersistenceManagerService {
try {
final Object tx = txProvider.start(em);
try {
- final StepExecutionEntity entity = em.find(StepExecutionEntity.class, stepContext.getStepExecutionId());
+ final StepExecutionEntity entity = em.find(StepExecutionEntity.class, stepContext.getStepInternalExecID());
setStepData(em, jobExecId, stepContext,
stepContext.metricsAsMap().get(Metric.MetricType.READ_COUNT.name()).getValue(),
stepContext.metricsAsMap().get(Metric.MetricType.WRITE_COUNT.name()).getValue(),
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/services/persistence/MemoryPersistenceManager.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/MemoryPersistenceManager.java b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/MemoryPersistenceManager.java
index 0fbc623..0f80ba0 100644
--- a/jbatch/src/main/java/org/apache/batchee/container/services/persistence/MemoryPersistenceManager.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/persistence/MemoryPersistenceManager.java
@@ -446,7 +446,7 @@ public class MemoryPersistenceManager implements PersistenceManagerService {
@Override
public void updateStepExecution(final long jobExecId, final StepContextImpl stepContext) {
- final long stepExecutionId = stepContext.getStepExecutionId();
+ final long stepExecutionId = stepContext.getStepInternalExecID();
final String batchStatus = stepContext.getBatchStatus() == null ? BatchStatus.STARTING.name() : stepContext.getBatchStatus().name();
final String exitStatus = stepContext.getExitStatus();
final String stepName = stepContext.getStepName();
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/main/java/org/apache/batchee/container/util/BatchPartitionWorkUnit.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/util/BatchPartitionWorkUnit.java b/jbatch/src/main/java/org/apache/batchee/container/util/BatchPartitionWorkUnit.java
index cde223f..0a6a88f 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/util/BatchPartitionWorkUnit.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/util/BatchPartitionWorkUnit.java
@@ -16,9 +16,9 @@
*/
package org.apache.batchee.container.util;
+import org.apache.batchee.container.impl.StepContextImpl;
import org.apache.batchee.container.impl.controller.PartitionThreadRootController;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
-import org.apache.batchee.container.services.BatchKernelService;
import org.apache.batchee.container.services.ServicesManager;
import java.util.concurrent.BlockingQueue;
@@ -40,4 +40,8 @@ public class BatchPartitionWorkUnit extends BatchParallelWorkUnit {
completedThreadQueue.add(this);
}
}
+
+ public void inheritStepContext(final StepContextImpl sc) {
+ this.controller.setParentStepContext(sc);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/test/java/org/apache/batchee/test/id/PartitionIdTest.java
----------------------------------------------------------------------
diff --git a/jbatch/src/test/java/org/apache/batchee/test/id/PartitionIdTest.java b/jbatch/src/test/java/org/apache/batchee/test/id/PartitionIdTest.java
new file mode 100644
index 0000000..6652afa
--- /dev/null
+++ b/jbatch/src/test/java/org/apache/batchee/test/id/PartitionIdTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.test.id;
+
+import org.apache.batchee.util.Batches;
+import org.testng.annotations.Test;
+
+import javax.batch.api.BatchProperty;
+import javax.batch.api.chunk.AbstractItemReader;
+import javax.batch.api.chunk.AbstractItemWriter;
+import javax.batch.operations.JobOperator;
+import javax.batch.runtime.BatchRuntime;
+import javax.batch.runtime.Metric;
+import javax.batch.runtime.StepExecution;
+import javax.batch.runtime.context.JobContext;
+import javax.batch.runtime.context.StepContext;
+import javax.inject.Inject;
+import java.io.FileNotFoundException;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import static org.testng.Assert.assertEquals;
+
+public class PartitionIdTest {
+ @Test
+ public void run() {
+ final JobOperator op = BatchRuntime.getJobOperator();
+ final long id = op.start("partition-execId", null);
+ Batches.waitForEnd(op, id);
+
+ final long stepId = op.getStepExecutions(id).iterator().next().getStepExecutionId();
+
+ assertEquals(2, Reader.jobIds.size());
+ assertEquals(2, Reader.stepIds.size());
+ assertEquals(id, Reader.jobIds.get(1).longValue());
+ assertEquals(Reader.jobIds.get(0), Reader.jobIds.get(1));
+ assertEquals(stepId, Reader.stepIds.get(0).longValue());
+ assertEquals(Reader.stepIds.get(0), Reader.stepIds.get(1));
+ }
+
+ public static class Reader extends AbstractItemReader {
+ private static final List<Long> jobIds = new CopyOnWriteArrayList<Long>();
+ private static final List<Long> stepIds = new CopyOnWriteArrayList<Long>();
+
+ @Inject
+ @BatchProperty
+ private Integer idx;
+
+ @Inject
+ private StepContext stepContext;
+
+ @Inject
+ private JobContext jobContext;
+
+ @Override
+ public Object readItem() throws Exception {
+ if (idx != null) {
+ jobIds.add(jobContext.getExecutionId());
+ stepIds.add(stepContext.getStepExecutionId());
+ }
+ try {
+ return idx;
+ } finally {
+ idx = null;
+ }
+ }
+ }
+
+ public static class Writer extends AbstractItemWriter {
+ @Override
+ public void writeItems(final List<Object> items) throws Exception {
+ // no-op
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/jbatch/src/test/resources/META-INF/batch-jobs/partition-execId.xml
----------------------------------------------------------------------
diff --git a/jbatch/src/test/resources/META-INF/batch-jobs/partition-execId.xml b/jbatch/src/test/resources/META-INF/batch-jobs/partition-execId.xml
new file mode 100644
index 0000000..4ac9f0f
--- /dev/null
+++ b/jbatch/src/test/resources/META-INF/batch-jobs/partition-execId.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ See the NOTICE file distributed with this work for additional information
+ regarding copyright ownership. Licensed under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<job id="partition-id" version="1.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
+ <step id="part-step">
+ <chunk>
+ <reader ref="org.apache.batchee.test.id.PartitionIdTest$Reader">
+ <properties>
+ <property name="idx" value="#{partitionPlan['idx']}" />
+ </properties>
+ </reader>
+ <writer ref="org.apache.batchee.test.id.PartitionIdTest$Writer" />
+ </chunk>
+ <partition>
+ <plan partitions="2" threads="2">
+ <properties partition="0">
+ <property name="idx" value="1" />
+ </properties>
+ <properties partition="1">
+ <property name="idx" value="2" />
+ </properties>
+ </plan>
+ </partition>
+ </step>
+</job>
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/349bccfe/test/src/main/java/org/apache/batchee/test/StepLauncher.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/batchee/test/StepLauncher.java b/test/src/main/java/org/apache/batchee/test/StepLauncher.java
index 5224254..0f7543c 100644
--- a/test/src/main/java/org/apache/batchee/test/StepLauncher.java
+++ b/test/src/main/java/org/apache/batchee/test/StepLauncher.java
@@ -98,7 +98,7 @@ public class StepLauncher {
.execute();
}
- return persistenceManagerService.getStepExecutionByStepExecutionId(stepContext.getStepExecutionId());
+ return persistenceManagerService.getStepExecutionByStepExecutionId(stepContext.getStepInternalExecID());
}
private StepLauncher() {