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

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

Introduction

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

Prototype

ExitStatus COMPLETED

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

Click Source Link

Document

Convenient constant value representing finished processing.

Usage

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.
 *///  www  .  j  a va2 s . com
@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.xd.integration.test.JobCommandTest.java

@Test
public void testListStepExecutions() {
    String data = UUID.randomUUID().toString();
    String jobName = "tsle" + UUID.randomUUID().toString();

    jdbcSink.getJdbcTemplate().getDataSource();
    FileJdbcJob job = new FileJdbcJob(FileJdbcJob.DEFAULT_DIRECTORY, FileJdbcJob.DEFAULT_FILE_NAME,
            FileJdbcJob.DEFAULT_TABLE_NAME, FileJdbcJob.DEFAULT_NAMES);

    // Create a stream that writes to a file. This file will be used by the job.
    stream("dataSender", sources.http() + XD_DELIMITER
            + sinks.file(FileJdbcJob.DEFAULT_DIRECTORY, DEFAULT_FILE_NAME).toDSL());
    sources.httpSource("dataSender").postData(data);
    job(jobName, job.toDSL(), true);//from www.j  a  v  a 2 s.co m
    jobLaunch(jobName);
    String query = String.format("SELECT data FROM %s", tableName);

    waitForTablePopulation(query, jdbcSink.getJdbcTemplate(), 1);

    List<String> results = jdbcSink.getJdbcTemplate().queryForList(query, String.class);

    assertEquals(1, results.size());

    for (String result : results) {
        assertEquals(data, result);
    }
    List<JobExecutionInfoResource> jobList = this.getJobExecInfoByName(jobName);
    logger.info("testing job executions for: " + jobName);
    assertEquals(1, jobList.size());
    long executionId = jobList.get(0).getExecutionId();
    logger.info("testing step executions for: " + jobName);
    List<StepExecutionInfoResource> stepExecutions = getStepExecutions(executionId);
    Iterator<StepExecutionInfoResource> iter = stepExecutions.iterator();
    assertEquals(2, stepExecutions.size());
    boolean step1MasterFound = false;
    boolean step1MasterPartitionFound = false;
    while (iter.hasNext()) {
        StepExecutionInfoResource resource = iter.next();
        assertEquals(BatchStatus.COMPLETED, resource.getStepExecution().getStatus());
        assertEquals(ExitStatus.COMPLETED, resource.getStepExecution().getExitStatus());
        if (resource.getStepExecution().getStepName().equals("step1-master")) {
            step1MasterFound = true;
        } else if (resource.getStepExecution().getStepName().equals("step1-master:partition0")) {
            step1MasterPartitionFound = true;
        }
    }
    assertTrue("step1-master was not found in step execution list", step1MasterFound);
    assertTrue("step1-master:partition0 was not found in step execution list", step1MasterPartitionFound);

}

From source file:org.springframework.yarn.batch.partition.PrintTasklet.java

public ExitStatus execute() throws Exception {
    log.info("execute1: " + message);
    System.out.print(message);
    return ExitStatus.COMPLETED;
}