@Test public void testBaseValues() { assertEquals(5L, jsrStepExecution.getStepExecutionId()); assertEquals("testStep", jsrStepExecution.getStepName()); assertEquals(javax.batch.runtime.BatchStatus.STARTED, jsrStepExecution.getBatchStatus());
@Override public int compare(StepExecution o1, StepExecution o2) { return Long.compare(o1.getStepExecutionId(), o2.getStepExecutionId()); } });
@Override public int compare(final StepExecution o1, final StepExecution o2) { return new Long(o1.getStepExecutionId()).compareTo(o2.getStepExecutionId()); } }
@Override public void updateStepExecution(final StepExecution stepExecution) { stepExecutionCache.put(stepExecution.getStepExecutionId(), (StepExecutionImpl) stepExecution); }
@Override public void cleanUp(final long instanceId) { final Structures.JobInstanceData jobInstanceData = data.jobInstanceData.remove(instanceId); if (jobInstanceData == null) { return; } synchronized (jobInstanceData.executions) { for (final Structures.ExecutionInstanceData executionInstanceData : jobInstanceData.executions) { data.executionInstanceData.remove(executionInstanceData.execution.getExecutionId()); synchronized (executionInstanceData.stepExecutions) { for (final StepExecution stepExecution : executionInstanceData.stepExecutions) { data.stepExecutionInstanceData.remove(stepExecution.getStepExecutionId()); } } } } synchronized (jobInstanceData.checkpoints) { for (final CheckpointDataKey key : jobInstanceData.checkpoints) { data.checkpointData.remove(key); } } }
private void updateStepExecution(final long stepExecutionId, final long jobExecId, final String batchStatus, final String exitStatus, final String stepName, final long readCount, final long writeCount, final long commitCount, final long rollbackCount, final long readSkipCount, final long processSkipCount, final long filterCount, final long writeSkipCount, final Timestamp startTime, final Timestamp endTime, final Serializable persistentData) { //CHECKSTYLE:ON final Structures.ExecutionInstanceData executionInstanceData = data.executionInstanceData.get(jobExecId); if (executionInstanceData == null) { return; } synchronized (executionInstanceData.stepExecutions) { for (final StepExecution execution : executionInstanceData.stepExecutions) { if (execution.getStepExecutionId() == stepExecutionId) { updateStepExecutionInstanceData(executionInstanceData, batchStatus, exitStatus, stepName, readCount, writeCount, commitCount, rollbackCount, readSkipCount, processSkipCount, filterCount, writeSkipCount, startTime, endTime, persistentData, data.stepExecutionInstanceData.get(stepExecutionId)); break; } } } }
/** * {@inheritDoc} */ @Override public List<WSStepThreadExecutionAggregate> getStepExecutionAggregatesFromJobExecutionId( long jobExecutionId) throws NoSuchJobExecutionException { // Optimize for programming ease rather than a single trip to the database. // We might have to revisit. List<WSStepThreadExecutionAggregate> retVal = new ArrayList<WSStepThreadExecutionAggregate>(); //sorted by start time List<StepExecution> topLevelStepExecutions = getStepExecutionsTopLevelFromJobExecutionId(jobExecutionId); for (StepExecution stepExec : topLevelStepExecutions) { retVal.add(getStepExecutionAggregate(stepExec.getStepExecutionId())); } return retVal; }
stringBuilder.append(stepExecution.getStepExecutionId()); stringBuilder.append(CSV_DELIMITER); stringBuilder.append(stepExecution.getStepName());
@Override public void execute() throws MojoExecutionException, MojoFailureException { final List<StepExecution> executions = getOrCreateOperator().getStepExecutions(executionId); getLog().info("Step executions for job execution #" + executionId + ":"); for (final StepExecution exec : executions) { getLog().info(" - id = " + exec.getStepExecutionId()); getLog().info(" + step = " + exec.getStepName()); getLog().info(" + batch status = " + exec.getBatchStatus()); getLog().info(" + exit status = " + exec.getExitStatus()); getLog().info(" + start time = " + exec.getStartTime()); getLog().info(" + end time = " + exec.getEndTime()); getLog().info(" + metrics"); if (exec.getMetrics() != null) { for (final Metric m : exec.getMetrics()) { getLog().info(" > " + m.getType().name().replace("COUNT", "").replace("_", " ").toLowerCase(Locale.ENGLISH) + " = " + m.getValue()); } } } } }
preparedStatement.setBytes(15, stepExecutionImpl.getWriterCheckpointInfoSerialized()); preparedStatement.setLong(16, stepExecution.getStepExecutionId());
public static StepExecutionEntity create(final StepExecution stepExecution) { final StepExecutionEntity result = new StepExecutionEntity(); result.id = stepExecution.getStepExecutionId(); result.name = stepExecution.getStepName(); result.status = stepExecution.getBatchStatus(); result.exitStatus = stepExecution.getExitStatus(); result.endTime = stepExecution.getEndTime(); result.startTime = stepExecution.getStartTime(); // metrics result.metrics = new HashMap<>(); final Metric[] metricArr = stepExecution.getMetrics(); for (Metric m : metricArr) { result.metrics.put(m.getType().name().toLowerCase(), m.getValue()); } if (stepExecution.getPersistentUserData() != null) { result.setPersistentUserData(stepExecution.getPersistentUserData().toString()); } return result; }
@Override public StepExecutionImpl findOriginalStepExecutionForRestart(final String stepName, final JobExecutionImpl jobExecutionToRestart, final ClassLoader classLoader) { for (final StepExecution stepExecution : jobExecutionToRestart.getStepExecutions()) { if (stepName.equals(stepExecution.getStepName())) { return (StepExecutionImpl) stepExecution; } } StepExecutionImpl result = null; // the same-named StepExecution is not found in the jobExecutionToRestart. It's still possible the same-named // StepExecution may exit in JobExecution earlier than jobExecutionToRestart for the same JobInstance. final long instanceId = jobExecutionToRestart.getJobInstance().getInstanceId(); for (final JobExecutionImpl jobExecutionImpl : jobExecutions.values()) { //skip the JobExecution that has already been checked above if (instanceId == jobExecutionImpl.getJobInstance().getInstanceId() && jobExecutionImpl.getExecutionId() != jobExecutionToRestart.getExecutionId()) { for (final StepExecution stepExecution : jobExecutionImpl.getStepExecutions()) { if (stepExecution.getStepName().equals(stepName)) { if (result == null || result.getStepExecutionId() < stepExecution.getStepExecutionId()) { result = (StepExecutionImpl) stepExecution; } } } } } return result; }
@Test @org.junit.Test public void testFourStepExecutionStatus() throws Exception { String METHOD = "testFourStepExecutionStatus"; begin(METHOD); try { Reporter.log("Locate job XML file: job_batchlet_4steps.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("job_batchlet_4steps"); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> steps = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(4, steps.size()); Set<Long> stepExecutionsSeen = new HashSet<Long>(); for (StepExecution step : steps) { // check that each step completed successfully showStepState(step); Reporter.log("Step status = " + step.getBatchStatus() + "<p>"); assertObjEquals(BatchStatus.COMPLETED, step.getBatchStatus()); // Let's also make sure all four have unique IDs, to make sure the JobExecution id isn't being used say assertWithMessage("New StepExecution id", !stepExecutionsSeen.contains(step.getStepExecutionId())); stepExecutionsSeen.add(step.getStepExecutionId()); } Reporter.log("Job execution status = " + jobExec.getBatchStatus() + "<p>"); assertObjEquals(BatchStatus.COMPLETED, jobExec.getBatchStatus()); } catch (Exception e) { handleException(METHOD, e); } }
@Test @org.junit.Test public void testExamineStepContextInArtifact() throws Exception { String METHOD = "testExamineStepContextInArtifact()"; try { Reporter.log("Locate job XML file: oneArtifactIsJobAndStepListener.xml<p>"); Reporter.log("Create job parameters for execution #1:<p>"); Properties jobParams = new Properties(); Reporter.log("app.timeinterval=10<p>"); jobParams.put("app.timeinterval", "10"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution execution1 = jobOp.startJobAndWaitForResult("StepContextTestBatchlet", jobParams); List<StepExecution> steps = jobOp.getStepExecutions(execution1.getExecutionId()); assertWithMessage("list of step executions == 1", steps.size() == 1); String testString = "StepName=step1;StepExecutionId=" + steps.get(0).getStepExecutionId(); Reporter.log("EXPECTED JobExecution getBatchStatus()=COMPLETED<p>"); Reporter.log("ACTUAL JobExecution getBatchStatus()="+execution1.getBatchStatus()+"<p>"); Reporter.log("EXPECTED JobExecution getExitStatus()="+testString+"<p>"); Reporter.log("ACTUAL JobExecution getExitStatus()="+execution1.getExitStatus()+"<p>"); assertWithMessage("Testing batch status", BatchStatus.COMPLETED, execution1.getBatchStatus()); assertWithMessage("Testing exit status", testString, execution1.getExitStatus()); } catch (Exception e) { handleException(METHOD, e); } }
@Override public StepExecutionImpl findOriginalStepExecutionForRestart(final String stepName, final JobExecutionImpl jobExecutionToRestart0, final ClassLoader classLoader) { final JobExecutionImpl jobExecutionToRestart = jobExecutionCache.get(jobExecutionToRestart0.getExecutionId()); for (final StepExecution stepExecution : jobExecutionToRestart.getStepExecutions()) { if (stepName.equals(stepExecution.getStepName())) { return (StepExecutionImpl) stepExecution; } } StepExecutionImpl result = null; // the same-named StepExecution is not found in the jobExecutionToRestart. It's still possible the same-named // StepExecution may exit in JobExecution earlier than jobExecutionToRestart for the same JobInstance. final long instanceId = jobExecutionToRestart.getJobInstance().getInstanceId(); final JobInstanceImpl jobInstanceToRestart = jobInstanceCache.get(instanceId); for (final JobExecution jobExecution : jobInstanceToRestart.getJobExecutions()) { final JobExecutionImpl jobExecutionImpl = (JobExecutionImpl) jobExecution; //skip the JobExecution that has already been checked above if (jobExecutionImpl.getExecutionId() != jobExecutionToRestart.getExecutionId()) { for (final StepExecution stepExecution : jobExecutionImpl.getStepExecutions()) { if (stepExecution.getStepName().equals(stepName)) { if (result == null || result.getStepExecutionId() < stepExecution.getStepExecutionId()) { result = (StepExecutionImpl) stepExecution; } } } } } return result; }
private static Object[] asArray(final StepExecution n) { return new Object[] { n.getStepExecutionId(), n.getStepName(), n.getBatchStatus().name(), n.getExitStatus(), n.getStartTime() != null ? n.getStartTime().toString() : "", n.getEndTime() != null ? n.getEndTime().toString() : "", metric(n.getMetrics(), Metric.MetricType.READ_COUNT), metric(n.getMetrics(), Metric.MetricType.WRITE_COUNT), metric(n.getMetrics(), Metric.MetricType.COMMIT_COUNT), metric(n.getMetrics(), Metric.MetricType.ROLLBACK_COUNT), metric(n.getMetrics(), Metric.MetricType.READ_SKIP_COUNT), metric(n.getMetrics(), Metric.MetricType.PROCESS_SKIP_COUNT), metric(n.getMetrics(), Metric.MetricType.WRITE_SKIP_COUNT), metric(n.getMetrics(), Metric.MetricType.FILTER_COUNT) }; }
private void showStepState(StepExecution step) { Reporter.log("---------------------------<p>"); Reporter.log("getJobExecutionId(): " + step.getStepExecutionId() + " - "); Metric[] metrics = step.getMetrics(); for (int i = 0; i < metrics.length; i++) { Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - "); } Reporter.log("getStartTime(): " + step.getStartTime() + " - "); Reporter.log("getEndTime(): " + step.getEndTime() + " - "); Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - "); Reporter.log("getExitStatus(): " + step.getExitStatus()); Reporter.log("---------------------------<p>"); }
private void showStepState(StepExecution step) { Reporter.log("---------------------------<p>"); Reporter.log("getStepName(): " + step.getStepName() + " - "); Reporter.log("getStepExecutionId(): " + step.getStepExecutionId() + " - "); Metric[] metrics = step.getMetrics(); for (int i = 0; i < metrics.length; i++) { Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - "); } Reporter.log("getStartTime(): " + step.getStartTime() + " - "); Reporter.log("getEndTime(): " + step.getEndTime() + " - "); Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - "); Reporter.log("getExitStatus(): " + step.getExitStatus()+"<p>"); Reporter.log("---------------------------<p>"); }
private void showStepState(StepExecution step) { Reporter.log("---------------------------"); Reporter.log("getStepName(): " + step.getStepName() + " - "); Reporter.log("getJobExecutionId(): " + step.getStepExecutionId() + " - "); //System.out.print("getStepExecutionId(): " + step.getStepExecutionId() + " - "); Metric[] metrics = step.getMetrics(); for (int i = 0; i < metrics.length; i++) { Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - "); } Reporter.log("getStartTime(): " + step.getStartTime() + " - "); Reporter.log("getEndTime(): " + step.getEndTime() + " - "); //System.out.print("getLastUpdateTime(): " + step.getLastUpdateTime() + " - "); Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - "); Reporter.log("getExitStatus(): " + step.getExitStatus()); Reporter.log("---------------------------"); } }
@Override public void updateStepExecution(final StepExecution stepExecution) { final StepExecutionImpl stepExecutionImpl = (StepExecutionImpl) stepExecution; try { final DBObject update = new BasicDBObject(TableColumns.ENDTIME, stepExecution.getEndTime()); update.put(TableColumns.BATCHSTATUS, stepExecution.getBatchStatus().name()); update.put(TableColumns.EXITSTATUS, stepExecution.getExitStatus()); update.put(TableColumns.EXECUTIONEXCEPTION, TableColumns.formatException(stepExecutionImpl.getException())); update.put(TableColumns.PERSISTENTUSERDATA, stepExecutionImpl.getPersistentUserDataSerialized()); update.put(TableColumns.READCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.READ_COUNT)); update.put(TableColumns.WRITECOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.WRITE_COUNT)); update.put(TableColumns.COMMITCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.COMMIT_COUNT)); update.put(TableColumns.ROLLBACKCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.ROLLBACK_COUNT)); update.put(TableColumns.READSKIPCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.READ_SKIP_COUNT)); update.put(TableColumns.PROCESSSKIPCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.PROCESS_SKIP_COUNT)); update.put(TableColumns.FILTERCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.FILTER_COUNT)); update.put(TableColumns.WRITESKIPCOUNT, stepExecutionImpl.getStepMetrics().get(Metric.MetricType.WRITE_SKIP_COUNT)); update.put(TableColumns.READERCHECKPOINTINFO, stepExecutionImpl.getReaderCheckpointInfoSerialized()); update.put(TableColumns.WRITERCHECKPOINTINFO, stepExecutionImpl.getWriterCheckpointInfoSerialized()); db.getCollection(TableColumns.STEP_EXECUTION).update( new BasicDBObject(TableColumns.STEPEXECUTIONID, stepExecution.getStepExecutionId()), new BasicDBObject("$set", update)); } catch (final Exception e) { throw BatchMessages.MESSAGES.failToRunQuery(e, "updateStepExecution"); } }