@Test public void testGetExceptionMultiple() { stepExecution.addFailureException(new Exception("not me")); stepExecution.addFailureException(new Exception("not me either")); stepExecution.addFailureException(new Exception("me")); assertEquals("me", stepContext.getException().getMessage()); } }
@Test public void testGetExceptionThrowable() { stepExecution.addFailureException(new Throwable("expected")); assertTrue(stepContext.getException().getMessage().endsWith("expected")); }
@Test public void testGetExceptionException() { stepExecution.addFailureException(new Exception("expected")); assertEquals("expected", stepContext.getException().getMessage()); }
@Test public void testAddException() throws Exception{ RuntimeException exception = new RuntimeException(); assertEquals(0, execution.getFailureExceptions().size()); execution.addFailureException(exception); assertEquals(1, execution.getFailureExceptions().size()); assertEquals(exception, execution.getFailureExceptions().get(0)); }
public void testFailureExceptions() { RuntimeException exception = new RuntimeException(); assertEquals(0, execution.getFailureExceptions().size()); execution.addFailureException(exception); assertEquals(1, execution.getFailureExceptions().size()); assertEquals(exception, execution.getFailureExceptions().get(0)); StepExecution stepExecution1 = execution.createStepExecution("execution1"); RuntimeException stepException1 = new RuntimeException(); stepExecution1.addFailureException(stepException1); execution.createStepExecution("execution2"); List<Throwable> allExceptions = execution.getAllFailureExceptions(); assertEquals(2, allExceptions.size()); assertEquals(1, execution.getFailureExceptions().size()); assertTrue(allExceptions.contains(exception)); assertTrue(allExceptions.contains(stepException1)); } }
stepExecution.upgradeStatus(determineBatchStatus(e)); exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e)); stepExecution.addFailureException(e); if (stepExecution.getStatus() == BatchStatus.STOPPED) { logger.info(String.format("Encountered interruption executing step %s in job %s : %s", name, stepExecution.getJobExecution().getJobInstance().getJobName(), e.getMessage())); stepExecution.setStatus(BatchStatus.UNKNOWN); exitStatus = exitStatus.and(ExitStatus.UNKNOWN); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN)); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.addFailureException(e);
@ServiceActivator public StepExecution handle(StepExecutionRequest request) { Long jobExecutionId = request.getJobExecutionId(); Long stepExecutionId = request.getStepExecutionId(); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException("No StepExecution could be located for this request: " + request); } String stepName = request.getStepName(); Step step = stepLocator.getStep(stepName); if (step == null) { throw new NoSuchStepException(String.format("No Step with name [%s] could be located.", stepName)); } try { step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); // The receiver should update the stepExecution in repository } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); // The receiver should update the stepExecution in repository } return stepExecution; }
stepExecution.addFailureException(e); throw e;
stepExecution.setExitStatus(ExitStatus.FAILED); stepExecution.setStatus(((JobInterruptedException) exception).getStatus()); stepExecution.addFailureException(exception); throw (JobInterruptedException) exception; stepExecution.setExitStatus(ExitStatus.FAILED); stepExecution.setStatus(BatchStatus.FAILED); stepExecution.addFailureException(exception); return; stepExecution.setExitStatus(ExitStatus.FAILED); stepExecution.setStatus(BatchStatus.FAILED); stepExecution.addFailureException(exception); return; stepExecution.setExitStatus(ExitStatus.FAILED); stepExecution.setStatus(BatchStatus.FAILED); stepExecution.addFailureException(exception); return;
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { logger.info("Persisting video to S3"); TranscodingModel model = (TranscodingModel) stepExecution.getJobExecution().getExecutionContext().get("model"); if (! model.getDestination().getType().equals(VideoDestination.AWSS3)) { stepExecution.setStatus(BatchStatus.COMPLETED); return; } stepExecution.addFailureException(new Exception("Upload to S3 not implemented yet.")); } }
@Override public void run(String... args) throws Exception { validateRequest(); Long jobExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); Long stepExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException(String.format("No StepExecution could be located for step execution id %s within job execution %s", stepExecutionId, jobExecutionId)); } String stepName = environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME); Step step = stepLocator.getStep(stepName); try { logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s", stepExecution.getStepName(), stepExecutionId, jobExecutionId)); step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); jobRepository.update(stepExecution); } }
@Override public void run(String... args) throws Exception { validateRequest(); Long jobExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); Long stepExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException(String.format("No StepExecution could be located for step execution id %s within job execution %s", stepExecutionId, jobExecutionId)); } String stepName = environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME); Step step = stepLocator.getStep(stepName); try { logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s", stepExecution.getStepName(), stepExecutionId, jobExecutionId)); step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); jobRepository.update(stepExecution); } }
stepExecution.upgradeStatus(determineBatchStatus(e)); exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e)); stepExecution.addFailureException(e); if (stepExecution.getStatus() == BatchStatus.STOPPED) { logger.info(String.format("Encountered interruption executing step %s in job %s : %s", name, stepExecution.getJobExecution().getJobInstance().getJobName(), e.getMessage())); stepExecution.setStatus(BatchStatus.UNKNOWN); exitStatus = exitStatus.and(ExitStatus.UNKNOWN); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN)); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.addFailureException(e);
stepExecution.upgradeStatus(determineBatchStatus(e)); exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e)); stepExecution.addFailureException(e); if (stepExecution.getStatus() == BatchStatus.STOPPED) { logger.info(String.format("Encountered interruption executing step %s in job %s : %s", name, stepExecution.getJobExecution().getJobInstance().getJobName(), e.getMessage())); stepExecution.setStatus(BatchStatus.UNKNOWN); exitStatus = exitStatus.and(ExitStatus.UNKNOWN); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN)); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.addFailureException(e);
stepExecution.upgradeStatus(determineBatchStatus(e)); exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e)); stepExecution.addFailureException(e); if (stepExecution.getStatus() == BatchStatus.STOPPED) { logger.info(String.format("Encountered interruption executing step %s in job %s : %s", name, stepExecution.getJobExecution().getJobInstance().getJobName(), e.getMessage())); stepExecution.setStatus(BatchStatus.UNKNOWN); exitStatus = exitStatus.and(ExitStatus.UNKNOWN); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN)); stepExecution.addFailureException(e); logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. " + "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); stepExecution.addFailureException(e);
stepExecution.upgradeStatus(determineBatchStatus(e)); exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e)); stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.UNKNOWN); exitStatus = exitStatus.and(ExitStatus.UNKNOWN); stepExecution.addFailureException(e); logger.error("Encountered an error saving batch meta data. " + "This job is now in an unknown state and should not be restarted.", e); stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN)); stepExecution.addFailureException(e); logger.error("Encountered an error saving batch meta data. " + "This job is now in an unknown state and should not be restarted.", e); stepExecution.addFailureException(e);
stepExecution.addFailureException(e); throw e;
stepExecution.addFailureException(e); throw e;
stepExecution.addFailureException(e); throw e;