Examples of ExitStatus


Examples of org.springframework.batch.core.ExitStatus

  // Test to ensure the exit status returned by the last step is returned
  @Test
  public void testExitStatusReturned() throws JobExecutionException {

    final ExitStatus customStatus = new ExitStatus("test");

    Step testStep = new Step() {

      @Override
      public void execute(StepExecution stepExecution) throws JobInterruptedException {
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

  @Test
  public void testNoSteps() throws Exception {
    job.setSteps(new ArrayList<Step>());

    job.execute(jobExecution);
    ExitStatus exitStatus = jobExecution.getExitStatus();
    assertTrue("Wrong message in execution: " + exitStatus, exitStatus.getExitDescription().indexOf(
        "no steps configured") >= 0);
  }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

    jobExecution.stop();
    job.execute(jobExecution);

    assertEquals(0, list.size());
    checkRepository(BatchStatus.STOPPED, ExitStatus.NOOP);
    ExitStatus exitStatus = jobExecution.getExitStatus();
    assertEquals(ExitStatus.NOOP.getExitCode(), exitStatus.getExitCode());
  }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

    when(delegate.process()).thenReturn("my exit status");

    assertEquals(RepeatStatus.FINISHED, adapter.execute(contribution, new ChunkContext(null)));

    verify(delegate).process();
    verify(contribution).setExitStatus(new ExitStatus("my exit status"));
  }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

    stepExecution.setStartTime(new Date());
    stepExecution.setStatus(BatchStatus.STARTED);
    getJobRepository().update(stepExecution);

    // Start with a default value that will be trumped by anything
    ExitStatus exitStatus = ExitStatus.EXECUTING;

    doExecutionRegistration(stepExecution);

    try {
      getCompositeListener().beforeStep(stepExecution);
      open(stepExecution.getExecutionContext());

      try {
        doExecute(stepExecution);
      }
      catch (RepeatException e) {
        throw e.getCause();
      }
      exitStatus = ExitStatus.COMPLETED.and(stepExecution.getExitStatus());

      // Check if someone is trying to stop us
      if (stepExecution.isTerminateOnly()) {
        throw new JobInterruptedException("JobExecution interrupted.");
      }

      // Need to upgrade here not set, in case the execution was stopped
      stepExecution.upgradeStatus(BatchStatus.COMPLETED);
      logger.debug("Step execution success: id=" + stepExecution.getId());
    }
    catch (Throwable 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()));
        if (logger.isDebugEnabled()) {
          logger.debug("Full exception", e);
        }
      }
      else {
        logger.error(String.format("Encountered an error executing step %s in job %s", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
      }
    }
    finally {

      try {
        // Update the step execution to the latest known value so the
        // listeners can act on it
        exitStatus = exitStatus.and(stepExecution.getExitStatus());
        stepExecution.setExitStatus(exitStatus);
        exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
      }
      catch (Exception e) {
        logger.error(String.format("Exception in afterStep callback in step %s in job %s", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
      }

      try {
        getJobRepository().updateExecutionContext(stepExecution);
      }
      catch (Exception e) {
        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.setEndTime(new Date());
      stepExecution.setExitStatus(exitStatus);

      try {
        getJobRepository().update(stepExecution);
      }
      catch (Exception 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);
      }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

   */
  @Override
  public ExitStatus afterStep(StepExecution stepExecution) {
    for (Iterator<StepExecutionListener> iterator = list.reverse(); iterator.hasNext();) {
      StepExecutionListener listener = iterator.next();
      ExitStatus close = listener.afterStep(stepExecution);
      stepExecution.setExitStatus(stepExecution.getExitStatus().and(close));
    }
    return stepExecution.getExitStatus();
  }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

   *
   * @param ex the cause of the failure
   * @return an {@link ExitStatus}
   */
  private ExitStatus getDefaultExitStatusForFailure(Throwable ex) {
    ExitStatus exitStatus;
    if (ex instanceof JobInterruptedException || ex.getCause() instanceof JobInterruptedException) {
      exitStatus = ExitStatus.STOPPED.addExitDescription(JobInterruptedException.class.getName());
    }
    else if (ex instanceof NoSuchJobException || ex.getCause() instanceof NoSuchJobException) {
      exitStatus = new ExitStatus(ExitCodeMapper.NO_SUCH_JOB, ex.getClass().getName());
    }
    else {
      exitStatus = ExitStatus.FAILED.addExitDescription(ex);
    }

View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

    Set<MethodInvoker> invokers = invokerMap.get(methodName);

    if (invokers == null) {
      return null;
    }
    ExitStatus status = null;
    for (MethodInvoker invoker : invokers) {
      Object retVal = invoker.invokeMethod(invocation.getArguments());
      if (retVal instanceof ExitStatus) {
        if (status != null) {
          status = status.and((ExitStatus) retVal);
        }
        else {
          status = (ExitStatus) retVal;
        }
      }
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

    ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
    listener.setStrict(true);

    JobExecution jobExecution = new JobExecution(1L);
    StepExecution stepExecution = jobExecution.createStepExecution("step1");
    stepExecution.setExitStatus(new ExitStatus(status));

    Assert.state(jobExecution.getExecutionContext().isEmpty());
    Assert.state(stepExecution.getExecutionContext().isEmpty());

    stepExecution.getExecutionContext().putString(key, value);
View Full Code Here

Examples of org.springframework.batch.core.ExitStatus

  public void promoteEntryStatusNotFound() throws Exception {
    ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();

    JobExecution jobExecution = new JobExecution(1L);
    StepExecution stepExecution = jobExecution.createStepExecution("step1");
    stepExecution.setExitStatus(new ExitStatus(status2));

    Assert.state(jobExecution.getExecutionContext().isEmpty());
    Assert.state(stepExecution.getExecutionContext().isEmpty());

    stepExecution.getExecutionContext().putString(key, value);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.