Example usage for org.springframework.batch.core StepContribution getExitStatus

List of usage examples for org.springframework.batch.core StepContribution getExitStatus

Introduction

In this page you can find the example usage for org.springframework.batch.core StepContribution getExitStatus.

Prototype

public ExitStatus getExitStatus() 

Source Link

Document

Public getter for the status.

Usage

From source file:es.fcs.batch.integration.chunk.MyRemoteChunkHandlerFactoryBean.java

/**
 * Update a StepContribution with all the data from a StepContributionSource. The filter and write conuts plus the
 * exit status will be updated to reflect the data in the source.
 * //w  w  w .  j  a va2  s. c o m
 * @param contribution the current contribution
 * @param stepContributionSource a source of StepContributions
 */
protected void updateStepContribution(StepContribution contribution,
        StepContributionSource stepContributionSource) {
    for (StepContribution result : stepContributionSource.getStepContributions()) {
        contribution.incrementFilterCount(result.getFilterCount());
        contribution.incrementWriteCount(result.getWriteCount());
        for (int i = 0; i < result.getProcessSkipCount(); i++) {
            contribution.incrementProcessSkipCount();
        }
        for (int i = 0; i < result.getWriteSkipCount(); i++) {
            contribution.incrementWriteSkipCount();
        }
        contribution.setExitStatus(contribution.getExitStatus().and(result.getExitStatus()));
    }
}

From source file:uk.ac.ebi.intact.task.mitab.index.OntologyPopulatorTasklet.java

public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    if (ontologiesSolrUrl == null) {
        throw new NullPointerException("ontologiesSolrUrl is null");
    }/*  w w w .ja va  2 s .  c  o  m*/
    HttpSolrServer ontologiesSolrServer = createSolrServer();

    OntologyIndexer ontologyIndexer = new OntologyIndexer(ontologiesSolrServer);

    if (taxonomyOntologyMappings != null) {
        indexUniprotTaxonomy = true;
    }

    if (indexUniprotTaxonomy) {
        if (taxonomyOntologyMappings == null) {
            ontologyIndexer.indexUniprotTaxonomy();
        } else {
            for (OntologyMapping om : taxonomyOntologyMappings) {
                ontologyIndexer.indexOntology(new UniprotTaxonomyOntologyIterator(om.getUrl()));
            }
        }
    }

    ontologyIndexer.indexObo(oboOntologyMappings.toArray(new OntologyMapping[oboOntologyMappings.size()]));

    long count = countDocs(ontologiesSolrServer);
    contribution.getExitStatus().addExitDescription("Total docs in index: " + count);

    ontologiesSolrServer.shutdown();

    return RepeatStatus.FINISHED;
}

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);/*  w w  w . ja v a2  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.core.step.tasklet.SystemCommandTaskletIntegrationTests.java

@Test
public void testStopped() throws Exception {
    initializeTasklet();//from   w  w  w  .j a  v a2  s.  co m
    tasklet.setJobExplorer(jobExplorer);
    tasklet.afterPropertiesSet();
    tasklet.beforeStep(stepExecution);

    JobExecution stoppedJobExecution = new JobExecution(stepExecution.getJobExecution());
    stoppedJobExecution.setStatus(BatchStatus.STOPPING);

    when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(),
            stepExecution.getJobExecution(), stoppedJobExecution);

    String command = System.getProperty("os.name").toLowerCase().contains("win") ? "ping 1.1.1.1 -n 1 -w 5000"
            : "sleep 15";
    tasklet.setCommand(command);
    tasklet.setTerminationCheckInterval(10);
    tasklet.afterPropertiesSet();

    StepContribution contribution = stepExecution.createStepContribution();
    StepContext stepContext = new StepContext(stepExecution);
    ChunkContext chunkContext = new ChunkContext(stepContext);
    tasklet.execute(contribution, chunkContext);

    assertEquals(contribution.getExitStatus().getExitCode(), ExitStatus.STOPPED.getExitCode());
}