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:com.javaetmoi.elasticsearch.musicbrainz.batch.IndexBatchMain.java

public static void main(String... args) {
    AbstractApplicationContext context = null;
    try {/*from w  ww . java  2s  . co m*/
        context = new ClassPathXmlApplicationContext(new String[] {
                "com/javaetmoi/elasticsearch/musicbrainz/batch/applicationContext-datasource.xml",
                "com/javaetmoi/elasticsearch/musicbrainz/batch/applicationContext-elasticsearch.xml",
                "com/javaetmoi/elasticsearch/musicbrainz/batch/applicationContext-batch.xml" });

        JobLauncher jobLauncher = context.getBean(JobLauncher.class);
        Job musicAlbumJob = context.getBean("musicAlbumJob", Job.class);
        jobLauncher.run(musicAlbumJob, new JobParameters());
    } catch (Throwable e) {
        String message = "Job Terminated in error: " + e.getMessage();
        LOG.error(message, e);
        systemExiter.exit(exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()));
    } finally {
        if (context != null) {
            context.close();
        }
    }
    systemExiter.exit(exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()));
}

From source file:com.javaetmoi.core.batch.integration.TestJobExitStatusRouter.java

@Test
public void routeToErrorChannel() {
    JobExitStatusRouter router = new JobExitStatusRouter();
    router.init();//  w  w w . j  a v a 2  s  .  c  o  m
    JobExecution jobExecution = new JobExecution(1L);
    jobExecution.setExitStatus(ExitStatus.FAILED);
    jobExecution.setStatus(BatchStatus.FAILED);
    assertEquals("job-error", router.route(jobExecution));
}

From source file:lcn.module.batch.web.guide.support.SkipCheckingDecider.java

/**
 * skip? step ?? ? FlowExecution? Status .
 *//*w w  w  .ja v a 2  s . c o  m*/
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
    if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
            && stepExecution.getSkipCount() > 0) {
        return new FlowExecutionStatus("COMPLETED WITH SKIPS");
    } else {
        return new FlowExecutionStatus(ExitStatus.COMPLETED.getExitCode());
    }
}

From source file:fr.acxio.tools.agia.common.NoReadStepExecutionListener.java

@Override
public ExitStatus afterStep(StepExecution sStepExecution) {
    if (!ExitStatus.FAILED.getExitCode().equals(sStepExecution.getExitStatus().getExitCode())
            && sStepExecution.getReadCount() == 0) {
        return new ExitStatus("NOREAD");
    }//from  w w  w.  j  a  va2s  .c  om
    return null;
}

From source file:lcn.module.batch.web.guide.listener.SkipCheckingListener.java

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

From source file:fr.acxio.tools.agia.admin.StaleRunningJobsService.java

public void forceRunningJobsToFail() {
    if (logger.isInfoEnabled()) {
        logger.info("Reseting jobs...");
    }//  ww  w  .  j  a  v a 2s. co  m

    List<String> aJobNames = jobExplorer.getJobNames();
    for (String aJobName : aJobNames) {
        Set<JobExecution> aJobExecutions = jobExplorer.findRunningJobExecutions(aJobName);
        for (JobExecution aJobExecution : aJobExecutions) {
            if (logger.isInfoEnabled()) {
                logger.info("  " + aJobName + " (" + aJobExecution.getId() + ")");
            }
            aJobExecution.setEndTime(new Date());
            aJobExecution.setStatus(BatchStatus.FAILED);
            aJobExecution.setExitStatus(ExitStatus.FAILED);
            jobRepository.update(aJobExecution);
            for (StepExecution aStepExecution : aJobExecution.getStepExecutions()) {
                if (aStepExecution.getStatus().isGreaterThan(BatchStatus.COMPLETED)) {
                    if (logger.isInfoEnabled()) {
                        logger.info("    " + aStepExecution.getStepName());
                    }
                    aStepExecution.setEndTime(new Date());
                    aStepExecution.setStatus(BatchStatus.FAILED);
                    aStepExecution.setExitStatus(ExitStatus.FAILED);
                    jobRepository.update(aStepExecution);
                }
            }
        }
    }
    if (logger.isInfoEnabled()) {
        logger.info("Done.");
    }
}

From source file:org.duracloud.snapshot.service.impl.SyncWriter.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    try {//ww w .  j  av a 2 s  . c o  m
        restoreManager.transitionRestoreStatus(restorationId, RestoreStatus.TRANSFER_TO_DURACLOUD_COMPLETE, "");
    } catch (Exception e) {
        log.error("failed to transition restore status: " + e.getMessage(), e);
        return ExitStatus.FAILED;
    }

    return stepExecution.getExitStatus();
}

From source file:de.langmi.spring.batch.examples.complex.file.renamefile.partition.RenameFileListener.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    // get business key
    String businessKey = (String) stepExecution.getExecutionContext()
            .get(BatchConstants.CONTEXT_NAME_BUSINESS_KEY);
    try {/*  w w  w  .ja  v a 2 s.co  m*/
        String path = this.outputFileResource.getFile().getParent();
        String newFilePathAndName = path + File.separator + businessKey + ".txt";
        FileUtils.copyFile(outputFileResource.getFile(), new File(newFilePathAndName));
        LOG.info("copied:" + this.outputFileResource.getFile().getPath() + " to:" + newFilePathAndName);
        // deletion here is not good, the itemstream will be closed after 
        // this afterStep method is called
        // so get it deleted on jvm exit
        this.outputFileResource.getFile().deleteOnExit();
        LOG.info("deleteOnExit for:" + this.outputFileResource.getFile().getPath());
    } catch (Exception ex) {
        return new ExitStatus(ExitStatus.FAILED.getExitCode(), ex.getMessage());
    }

    return stepExecution.getExitStatus();
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VariantNormalizerStepTest.java

/**
 * This test has to fail because the vcf FILE_WRONG_NO_ALT is malformed:
 * in a variant a reference and a alternate allele are the same
 *//*from ww w  . j  a  v a  2  s.com*/
@Test
public void normalizerStepShouldFailIfVariantsAreMalformed() {
    final String FILE_WRONG_NO_ALT = "/wrong_no_alt.vcf.gz";
    Config.setOpenCGAHome(opencgaHome);

    //Given a malformed VCF input file
    String inputFile = VariantNormalizerStepTest.class.getResource(FILE_WRONG_NO_ALT).getFile();
    jobOptions.getPipelineOptions().put("input.vcf", inputFile);

    String outputFilename = getTransformedOutputPath(Paths.get(FILE_WRONG_NO_ALT).getFileName(), ".gz", "/tmp");

    File file = new File(outputFilename);
    file.delete();
    assertFalse(file.exists());

    //When the execute method in variantsTransform is invoked then a StorageManagerException is thrown
    JobExecution jobExecution = jobLauncherTestUtils.launchStep(GenotypedVcfJob.NORMALIZE_VARIANTS);
    assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.PopulationStatisticsGeneratorStepTest.java

/**
 * This test has to fail because it will try to extract variants from a non-existent DB.
 * Variants not loaded.. so nothing to query!
 *///from   w ww.  j  a v a  2s  . co m
@Test
public void statisticsGeneratorStepShouldFailIfVariantLoadStepIsNotCompleted() throws Exception {
    //Given a valid VCF input file
    String input = SMALL_VCF_FILE;

    pipelineOptions.put("input.vcf", input);
    variantOptions.put(VariantStorageManager.DB_NAME, STATS_DB);

    VariantSource source = new VariantSource(input, "1", "1", "studyName", VariantStudy.StudyType.COLLECTION,
            VariantSource.Aggregation.NONE);

    variantOptions.put(VARIANT_SOURCE, source);

    statsFile = new File(Paths.get(pipelineOptions.getString("output.dir.statistics"))
            .resolve(VariantStorageManager.buildFilename(source)) + ".variants.stats.json.gz");
    statsFile.delete();
    assertFalse(statsFile.exists()); // ensure the stats file doesn't exist from previous executions

    // When the execute method in variantsStatsCreate is executed
    JobExecution jobExecution = jobLauncherTestUtils.launchStep(PopulationStatisticsJob.CALCULATE_STATISTICS);
    assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());
}