Example usage for org.springframework.batch.core ExitStatus FAILED

List of usage examples for org.springframework.batch.core ExitStatus FAILED

Introduction

In this page you can find the example usage for org.springframework.batch.core ExitStatus FAILED.

Prototype

ExitStatus FAILED

To view the source code for org.springframework.batch.core ExitStatus FAILED.

Click Source Link

Document

Convenient constant value representing finished processing with an error.

Usage

From source file:org.springframework.batch.core.step.tasklet.SystemCommandTaskletIntegrationTests.java

@Test
public void testExecuteFailure() throws Exception {
    String command = getJavaCommand() + " org.springframework.batch.sample.tasklet.UnknownClass";
    tasklet.setCommand(command);/* www  . j  a va 2 s  . c  o  m*/
    tasklet.setTimeout(200L);
    tasklet.afterPropertiesSet();

    log.info("Executing command: " + command);
    try {
        StepContribution contribution = stepExecution.createStepContribution();
        RepeatStatus exitStatus = tasklet.execute(contribution, null);
        assertEquals(RepeatStatus.FINISHED, exitStatus);
        assertEquals(ExitStatus.FAILED, contribution.getExitStatus());
    } catch (RuntimeException e) {
        // on some platforms the system call does not return
        assertEquals("Execution of system command did not finish within the timeout", e.getMessage());
    }
}

From source file:org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) {
        return ExitStatus.EXECUTING;
    }/*from w w w .  j  ava 2  s  .  c  o m*/
    long expecting = localState.getExpecting();
    boolean timedOut;
    try {
        logger.debug("Waiting for results in step listener...");
        timedOut = !waitForResults();
        logger.debug("Finished waiting for results in step listener.");
    } catch (RuntimeException e) {
        logger.debug("Detected failure waiting for results in step listener.", e);
        stepExecution.setStatus(BatchStatus.FAILED);
        return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage());
    } finally {

        if (logger.isDebugEnabled()) {
            logger.debug("Finished waiting for results in step listener.  Still expecting: "
                    + localState.getExpecting());
        }

        for (StepContribution contribution : getStepContributions()) {
            stepExecution.apply(contribution);
        }
    }
    if (timedOut) {
        stepExecution.setStatus(BatchStatus.FAILED);
        return ExitStatus.FAILED.addExitDescription(
                "Timed out waiting for " + localState.getExpecting() + " backlog at end of step");
    }
    return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results.");
}

From source file:org.springframework.batch.sample.common.SkipCheckingListener.java

@AfterStep
public ExitStatus checkForSkips(StepExecution stepExecution) {
    if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
            && stepExecution.getSkipCount() > 0) {
        return new ExitStatus("COMPLETED WITH SKIPS");
    } else {//from w  w w . jav  a  2 s.  c om
        return null;
    }
}

From source file:org.springframework.cloud.task.app.composedtaskrunner.ComposedTaskStepExecutionListener.java

/**
 * If endTime for task is null then the ExitStatus will be set to  UNKNOWN.
 * If an exitMessage is returned by the TaskExecution then the exit status
 * returned will be the ExitMessage.  If no exitMessage is set for the task execution and the
 * task returns an exitCode ! = to zero an exit status of FAILED is
 * returned.  If no exit message is set and the exit code of the task is
 * zero then the ExitStatus of COMPLETED is returned.
 * @param stepExecution The stepExecution that kicked of the Task.
 * @return ExitStatus of COMPLETED else FAILED.
 *//*  w  w  w  .  j a va2  s .  c  o m*/
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    ExitStatus result = ExitStatus.COMPLETED;
    logger.info(String.format("AfterStep processing for stepExecution %s", stepExecution.getStepName()));

    Long executionId = (Long) stepExecution.getExecutionContext().get("task-execution-id");
    Assert.notNull(executionId,
            "TaskLauncherTasklet did not " + "return a task-execution-id.  Check to see if task " + "exists.");

    TaskExecution resultExecution = this.taskExplorer.getTaskExecution(executionId);

    if (!StringUtils.isEmpty(resultExecution.getExitMessage())) {
        result = new ExitStatus(resultExecution.getExitMessage());
    } else if (resultExecution.getExitCode() != 0) {
        result = ExitStatus.FAILED;
    }

    logger.info(String.format("AfterStep processing complete for " + "stepExecution %s with taskExecution %s",
            stepExecution.getStepName(), executionId));
    return result;
}

From source file:org.springframework.cloud.task.batch.handler.TaskJobLauncherCommandLineRunner.java

protected void execute(Job job, JobParameters jobParameters)
        throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException, JobParametersNotFoundException {
    JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.jobExplorer)
            .getNextJobParameters(job).toJobParameters();
    JobExecution execution = this.jobLauncher.run(job, nextParameters);
    if (this.publisher != null) {
        this.publisher.publishEvent(new JobExecutionEvent(execution));
    }/*  www.  j  a  v a2 s  .  c  om*/
    if (execution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())) {
        String message = String.format(
                "Job %s failed during " + "execution for jobId %s with jobExecutionId of %s",
                execution.getJobInstance().getJobName(), execution.getJobId(), execution.getId());
        logger.error(message);
        throw new TaskException(message);
    }
}