@Test public void testBaseValues() { 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()); assertEquals("customExitStatus", jsrStepExecution.getExitStatus()); assertEquals("persisted data", jsrStepExecution.getPersistentUserData()); Metric[] metrics = jsrStepExecution.getMetrics();
@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 testStepGetsFailedTransitionWhenNextAttributePresent() throws Exception { JobExecution jobExecution = runJob("FlowParserTestsStepGetsFailedTransitionWhenNextAttributePresent", new Properties(), 10000L); assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus()); JobOperator jobOperator = BatchRuntime.getJobOperator(); List<StepExecution> stepExecutions = jobOperator.getStepExecutions(jobExecution.getExecutionId()); assertEquals(1, stepExecutions.size()); StepExecution failedStep = stepExecutions.get(0); assertTrue("failedExitStatusStep".equals(failedStep.getStepName())); assertTrue("FAILED".equals(failedStep.getExitStatus())); }
private Object getMainStepStatus(long execId1) { for ( StepExecution stepExec : jobOperator.getStepExecutions( execId1 ) ) { if ( stepExec.getStepName().equals( "produceLuceneDoc" ) ) { return stepExec.getBatchStatus(); } } return null; }
try { preparedStatement = connection.prepareStatement(update); preparedStatement.setTimestamp(1, createTimestamp(stepExecution.getEndTime())); preparedStatement.setString(2, stepExecution.getBatchStatus().name()); preparedStatement.setString(3, stepExecution.getExitStatus()); preparedStatement.setString(4, TableColumns.formatException(stepExecutionImpl.getException())); preparedStatement.setBytes(5, stepExecutionImpl.getPersistentUserDataSerialized()); preparedStatement.setBytes(15, stepExecutionImpl.getWriterCheckpointInfoSerialized()); preparedStatement.setLong(16, stepExecution.getStepExecutionId());
if (stepNameTest.equals(stepEx.getStepName())) { step = stepEx; assertWithMessage("Testing execution #1", BatchStatus.COMPLETED, execution1.getBatchStatus()); Metric[] metrics = step.getMetrics();
@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[] executions) throws Exception { for(StepExecution stepExecution : executions) { if ("customFailTest".equals(stepExecution.getStepName())) { return "CustomFail"; } } return "next"; } }
String newStepExitStatus = stepExecution.getExitStatus(); if (newStepExitStatus == null) { newStepExitStatus = BatchStatus.FAILED.name(); logger.fine(methodName + ": marking [step execution=" + stepExecution.getStepExecutionId() + ",old batchStatus=" + stepExecution.getBatchStatus().name() + " to new batchStatus=FAILED, new step exitStatus=" + newStepExitStatus + "]"); persistenceManagerService.updateStepExecutionOnRecovery(psu, stepExecution.getStepExecutionId(), BatchStatus.FAILED, newStepExitStatus, markFailedTime);
stringBuilder.append(stepExecution.getStepExecutionId()); stringBuilder.append(CSV_DELIMITER); stringBuilder.append(stepExecution.getStepName()); stringBuilder.append(CSV_DELIMITER); Metric[] metricsArray = stepExecution.getMetrics(); Map<Metric.MetricType, Metric> sourceMap = new HashMap<Metric.MetricType, Metric>(); for (Metric metric : metricsArray) {
@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; }
if (stepNameTest.equals(stepEx.getStepName())) { step = stepEx; Reporter.log("AJM: step start time: " + step.getStartTime() + "<p>"); Reporter.log("AJM: step end time: " + step.getEndTime() + "<p>"); assertWithMessage("Start time of test occurs approximately before start time of step", roughlyOrdered(ts, step.getStartTime())); assertWithMessage("Start time of step occurs approximately before end time of step", roughlyOrdered(step.getStartTime(), step.getEndTime())); } catch (Exception e) { handleException(METHOD, e);
@Override public int compare(StepExecution o1, StepExecution o2) { return Long.compare(o1.getStepExecutionId(), o2.getStepExecutionId()); } });
/** * After the job is done, generate a report */ @Override public void afterJob() throws Exception { //TODO add notifications to job failure? if (jobContext.getExitStatus() != null && jobContext.getExitStatus().equals("FAILED")) { getJobLogger().log(Level.SEVERE, "Job Failed. See Log for more information."); closeJobLoggerHandlers(); return; } // run reporting and notifications doReport(); // report any unused checksums HashMap checksumHashMap = (HashMap<String, String>) jobContext.getTransientUserData(); for (Object key : checksumHashMap.keySet()) { getJobLogger().log(Level.SEVERE, "File listed in checksum manifest not found: " + key); } // job step info JobOperator jobOperator = BatchRuntime.getJobOperator(); StepExecution step = jobOperator.getStepExecutions(jobContext.getInstanceId()).get(0); getJobLogger().log(Level.INFO, "Job start = " + step.getStartTime()); getJobLogger().log(Level.INFO, "Job end = " + step.getEndTime()); getJobLogger().log(Level.INFO, "Job exit status = " + step.getExitStatus()); closeJobLoggerHandlers(); }
@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()); } }
private StepProgress getMainStepProgress(long executionId) { List<StepExecution> stepExecutions = jobOperator.getStepExecutions( executionId ); for ( StepExecution stepExecution : stepExecutions ) { switch ( stepExecution.getStepName() ) { case MAIN_STEP_NAME: return (StepProgress) stepExecution.getPersistentUserData(); default: break; } } throw new AssertionFailure( "Missing step progress for step '" + MAIN_STEP_NAME + "'" ); }
@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); } }
assertObjEquals(BatchStatus.FAILED, stepExec.getBatchStatus()); assertObjEquals(4, ((MyPersistentUserData)stepExec.getPersistentUserData()).getData()); assertObjEquals(BatchStatus.COMPLETED, stepExec.getBatchStatus()); assertObjEquals(5, ((MyPersistentUserData)stepExec.getPersistentUserData()).getData());
@Nullable public static Metric getMetric(StepExecution stepExecution, Metric.MetricType type) { Metric[] metrics = stepExecution.getMetrics(); for (Metric metric : metrics) { if(metric.getType() == type) { return metric; } } return null; }
private String coreExitStatus(StepExecution stepExec) { String action = (String)stepExec.getPersistentUserData(); String currentExitStatus = stepExec.getExitStatus(); // "Normally" we just pass set 'normalExitStatus' as exit status. if (currentExitStatus.equals(GOOD_STEP_EXIT_STATUS)) { return action; // But if it's the magic number then we return our "SpecialExitStatus". } else { return specialExitStatus; } }