@Override public String decide(StepExecution[] ses) throws Exception { for (StepExecution se : ses) { System.out.println(se.getStepName() + " " + se.getBatchStatus().toString() + " " + se.getExitStatus()); } return "foobar"; }
@Test public void testDecisionUnmappedExitStatus() throws Exception { JobExecution execution = runJob("DecisionStepTests-decisionInvalidExitStatus-context", new Properties(), 10000L); assertEquals(BatchStatus.COMPLETED, execution.getBatchStatus()); List<StepExecution> stepExecutions = BatchRuntime.getJobOperator().getStepExecutions(execution.getExecutionId()); assertEquals(2, stepExecutions.size()); for (StepExecution curExecution : stepExecutions) { assertEquals(BatchStatus.COMPLETED, curExecution.getBatchStatus()); } }
assertEquals(5L, jsrStepExecution.getStepExecutionId()); assertEquals("testStep", jsrStepExecution.getStepName()); assertEquals(javax.batch.runtime.BatchStatus.STARTED, jsrStepExecution.getBatchStatus()); assertEquals(new Date(0), jsrStepExecution.getStartTime()); assertEquals(new Date(10000000), jsrStepExecution.getEndTime());
@Override public String decide(StepExecution[] stepExecutions) throws Exception { if (stepExecutions.length != 2) { throw new IllegalStateException("Expecting stepExecutions array of size 2, found one of size = " + stepExecutions.length); } for (StepExecution stepExec : stepExecutions) { if (stepExec == null) { throw new Exception("Null StepExecution after split."); } if (!stepExec.getBatchStatus().equals(BatchStatus.COMPLETED)) { throw new Exception("All step executions must be compelete before transitioning to a decider."); } } // <end exit-status="ThatsAllFolks" on="DECIDER_EXIT_STATUS*2" /> return DECIDER_EXIT_STATUS + "*" + stepExecutions.length; }
@Override public String decide(StepExecution[] stepExecutions) throws Exception { if (stepExecutions.length != 1) { throw new IllegalStateException("Expecting stepExecutions array of size 1, found one of size = " + stepExecutions.length); } StepExecution stepExecution = stepExecutions[0]; for (StepExecution stepExec : stepExecutions) { if (stepExec == null) { throw new Exception("Null StepExecution after flow."); } if (!stepExec.getBatchStatus().equals(BatchStatus.COMPLETED)) { throw new Exception("All step executions must be compelete before transitioning to a decider."); } } // for our test // <end exit-status="ThatsAllFolks" on="DECIDER_EXIT_STATUS*VERY GOOD INVOCATION" /> return DECIDER_EXIT_STATUS + "*" + stepExecution.getExitStatus(); }
@Override public String decide(StepExecution[] stepExecutions) throws Exception { if (stepExecutions.length != 1) { throw new IllegalStateException("Expecting stepExecutions array of size 1, found one of size = " + stepExecutions.length); } for (StepExecution stepExec : stepExecutions) { if (stepExec == null) { throw new Exception("Null StepExecution from split."); } if (!stepExec.getBatchStatus().equals(BatchStatus.COMPLETED)) { throw new Exception("All step executions must be compelete before transitioning to a decider."); } } StepExecution stepExec = stepExecutions[0]; String coreExitStatus = coreExitStatus(stepExec); Integer count = (Integer)jobCtx.getTransientUserData(); String retVal = count.toString() + ":" + coreExitStatus; return retVal; }
private Object getMainStepStatus(long execId1) { for ( StepExecution stepExec : jobOperator.getStepExecutions( execId1 ) ) { if ( stepExec.getStepName().equals( "produceLuceneDoc" ) ) { return stepExec.getBatchStatus(); } } return null; }
@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()); } } } } }
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; }
@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); } }
private void assertCompletion(long executionId) { List<StepExecution> stepExecutions = jobOperator.getStepExecutions( executionId ); for ( StepExecution stepExecution : stepExecutions ) { BatchStatus batchStatus = stepExecution.getBatchStatus(); log.infof( "step %s executed.", stepExecution.getStepName() ); assertEquals( BatchStatus.COMPLETED, batchStatus ); } }
@Test @org.junit.Test public void testJobOperatorGetStepExecutions() throws Exception { String METHOD = "testJobOperatorGetStepExecutions"; begin(METHOD); try { Reporter.log("Locate job XML file: job_batchlet_1step.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("job_batchlet_1step"); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> stepExecutions = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(1, stepExecutions.size()); for (StepExecution step : stepExecutions) { // make sure all steps finish successfully showStepState(step); Reporter.log("Step status="+step.getBatchStatus()+"<p>"); assertObjEquals(BatchStatus.COMPLETED, step.getBatchStatus()); } Reporter.log("execution #1 JobExecution getBatchStatus()="+jobExec.getBatchStatus()+"<p>"); assertObjEquals(BatchStatus.COMPLETED, jobExec.getBatchStatus()); } catch (Exception e) { handleException(METHOD, e); } }
@Test @org.junit.Test public void testOneStepExecutionStatus() throws Exception { String METHOD = "testOneStepExecutionStatus"; begin(METHOD); try { Reporter.log("Locate job XML file: job_batchlet_1step.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("job_batchlet_1step"); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> steps = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(1, steps.size()); for (StepExecution step : steps) { // make sure all steps finish successfully showStepState(step); Reporter.log("Step status = " + step.getBatchStatus() + "<p>"); assertObjEquals(BatchStatus.COMPLETED, step.getBatchStatus()); } 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 testStepExecutionExitStatus() throws Exception { String METHOD = "testStepExecutionExitStatus"; begin(METHOD); try { Reporter.log("Locate job XML file: job_batchlet_failElement.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("job_batchlet_failElement"); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> steps = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(1, steps.size()); StepExecution step = steps.get(0); showStepState(step); assertWithMessage("Check step exit status", MyBatchletImpl.GOOD_EXIT_STATUS, step.getExitStatus()); assertWithMessage("Check step batch status", BatchStatus.COMPLETED, step.getBatchStatus()); Reporter.log("Job batch status =" + jobExec.getBatchStatus() + "<p>"); Reporter.log("Job exit status =" + jobExec.getExitStatus() + "<p>"); assertWithMessage("Check job batch status", BatchStatus.FAILED, jobExec.getBatchStatus()); assertWithMessage("Check job exit status", "TEST_FAIL", jobExec.getExitStatus()); } catch (Exception e) { handleException(METHOD, e); } }
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>"); }
@Test @org.junit.Test public void testStepInFlowStepExecution() throws Exception { String METHOD = "testStepInFlowStepExecution"; begin(METHOD); try { Reporter.log("Locate job XML file: job_batchlet_failElement.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("flow_transition_to_step"); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> steps = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(4, steps.size()); for (StepExecution step : steps) { showStepState(step); // Conveniently all four steps have same exit and batch status. assertWithMessage("Check step exit status", MyBatchletImpl.GOOD_EXIT_STATUS, step.getExitStatus()); assertWithMessage("Check step batch status", BatchStatus.COMPLETED, step.getBatchStatus()); } // Now check job level status Reporter.log("Job batch status =" + jobExec.getBatchStatus() + "<p>"); Reporter.log("Job exit status =" + jobExec.getExitStatus() + "<p>"); assertWithMessage("Check job batch status", BatchStatus.COMPLETED, jobExec.getBatchStatus()); assertWithMessage("Check job exit status", "flow1step1, flow1step2, flow1step3, step1", jobExec.getExitStatus()); } catch (Exception e) { handleException(METHOD, e); } }
@Test @org.junit.Test public void testStepInFlowInSplitStepExecution() throws Exception { String METHOD = "testStepInFlowInSplitStepExecution"; begin(METHOD); try { Reporter.log("Locate job XML file: split_batchlet_4steps.xml<p>"); Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>"); JobExecution jobExec = jobOp.startJobAndWaitForResult("split_batchlet_4steps"); // Saves debugging time to check these two first in case they fail assertWithMessage("Check job batch status", BatchStatus.COMPLETED, jobExec.getBatchStatus()); assertWithMessage("Check job exit status", "COMPLETED", jobExec.getExitStatus()); Reporter.log("Obtaining StepExecutions for execution id: " + jobExec.getExecutionId() + "<p>"); List<StepExecution> steps = jobOp.getStepExecutions(jobExec.getExecutionId()); assertObjEquals(4, steps.size()); for (StepExecution step : steps) { showStepState(step); // Conveniently all four steps have same exit and batch status. assertWithMessage("Check step exit status", MyBatchletImpl.GOOD_EXIT_STATUS, step.getExitStatus()); assertWithMessage("Check step batch status", BatchStatus.COMPLETED, step.getBatchStatus()); } Reporter.log("Job batch status =" + jobExec.getBatchStatus() + "<p>"); Reporter.log("Job exit status =" + jobExec.getExitStatus() + "<p>"); } catch (Exception e) { handleException(METHOD, e); } }
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("---------------------------"); } }