Example usage for org.springframework.batch.core JobExecution getAllFailureExceptions

List of usage examples for org.springframework.batch.core JobExecution getAllFailureExceptions

Introduction

In this page you can find the example usage for org.springframework.batch.core JobExecution getAllFailureExceptions.

Prototype

public synchronized List<Throwable> getAllFailureExceptions() 

Source Link

Document

Return all failure causing exceptions for this JobExecution, including step executions.

Usage

From source file:uk.ac.ebi.intact.editor.controller.admin.AdminJobController.java

public List<Throwable> getFailureExceptions(JobExecution jobExecution) {

    return new ArrayList<Throwable>(jobExecution.getAllFailureExceptions());
}

From source file:org.jasig.ssp.util.importer.job.tasklet.BatchFinalizer.java

@Override
public void afterJob(JobExecution jobExecution) {
    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();

    if (failureExceptions != null) {
        for (Throwable failureException : failureExceptions) {
            if (ExceptionUtils.indexOfThrowable(failureException, JobInterruptedException.class) >= 0) {
                return;
            }/* w w  w. ja v a  2  s . c o  m*/
        }
    }
    logger.info("Files deleted and archived");
    Long diff = TimeUnit.MILLISECONDS
            .toMinutes(jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime());

    logger.info("Job Duration in minutes: " + diff.toString());

    try {
        if (!archiveFiles.equals(ArchiveType.NONE)) {
            try {
                archive();
            } catch (Exception e) {
                logger.error("Error Archiving. Proceeding with file cleanup anyway.", e);
            }
        }
        // Always want to at least attempt clean up. Else behavior of next upload probably isn't what you expect.
        cleanDirectoryQuietly(processDirectory.getFile());
        cleanDirectoryQuietly(upsertDirectory.getFile());
        if (!retainInputFiles) {
            cleanCsvFilesQuietly(inputDirectory.getFile());
        }
    } catch (Exception e) {
        logger.error("Error Delete Process, Upsert And Input Directory", e);
    }
}

From source file:org.jasig.ssp.util.importer.job.BatchInitializerHeaderFailTest.java

@Test
public void testHeaderFailTest() throws Exception {

    deleteDirectory(processDirectoryPath);
    deleteDirectory(upsertDirectoryPath);

    Assert.assertTrue(!directoryExists(processDirectoryPath));
    Assert.assertTrue(!directoryExists(upsertDirectoryPath));

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    Assert.assertEquals(BatchStatus.FAILED, jobExecution.getStatus());

    @SuppressWarnings("unchecked")
    Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext()
            .get("report");
    Assert.assertNull(report);/*from w w  w .jav  a  2 s.  co  m*/

    @SuppressWarnings("unchecked")
    List<ErrorEntry> errors = (List<ErrorEntry>) jobExecution.getExecutionContext().get("errors");
    Assert.assertNull(errors);

    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    Assert.assertEquals(new Integer(1), new Integer(failureExceptions.size()));

    Assert.assertEquals(PartialUploadGuardException.class, failureExceptions.get(0).getClass());

}

From source file:org.jasig.ssp.util.importer.job.report.ReportGenerator.java

@SuppressWarnings("unchecked")
private String buildReport(JobExecution jobExecution) {
    StringBuffer emailMessage = new StringBuffer();
    String EOL = System.getProperty("line.separator");
    SimpleDateFormat dt = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
    long diff = jobExecution.getEndTime().getTime() - jobExecution.getCreateTime().getTime();//as given

    emailMessage.append("Start Time:    " + dt.format(jobExecution.getCreateTime()) + EOL);
    emailMessage.append("End Time:      " + dt.format(jobExecution.getEndTime()) + EOL);
    emailMessage.append("Duration:      " + DurationFormatUtils.formatDurationWords(diff, true, true) + " ("
            + DurationFormatUtils.formatDurationHMS(diff) + ")" + EOL);
    emailMessage.append("Job Id:        " + jobExecution.getJobId() + EOL);
    emailMessage.append("Job Paramters: " + jobExecution.getJobParameters() + EOL);
    emailMessage.append("Job Status:    " + jobExecution.getExitStatus().getExitCode() + EOL);

    emailMessage.append(EOL).append(EOL);

    emailMessage.append("Job Details: " + EOL);
    Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext()
            .get("report");
    if (report != null) {
        Set<Entry<String, ReportEntry>> entrySet = report.entrySet();
        for (Entry<String, ReportEntry> entry : entrySet) {
            emailMessage.append(entry.getValue().toString() + EOL);
        }/*from   w  w  w. j ava 2  s.com*/
        if (entrySet.size() > 0)
            emailReport = true;
    } else {
        emailMessage.append("NO FILES PROCESSED." + EOL);
    }

    emailMessage.append(EOL).append(EOL);

    emailMessage.append("Errors: " + EOL);
    List<ErrorEntry> errors = (List<ErrorEntry>) jobExecution.getExecutionContext().get("errors");
    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    if (errors != null) {
        for (ErrorEntry errorEntry : errors) {
            emailMessage.append(errorEntry.toString() + EOL);
            emailMessage.append(EOL);
        }
    } else if (failureExceptions == null || failureExceptions.size() == 0) {
        emailMessage.append("No Errors Found." + EOL);
    }

    if (failureExceptions != null) {
        for (Throwable failureException : failureExceptions) {
            if (ExceptionUtils.indexOfThrowable(failureException, PartialUploadGuardException.class) >= 0
                    || ExceptionUtils.indexOfThrowable(failureException, BeanCreationException.class) >= 0) {
                emailReport = true;
                logger.info("emailReport:" + emailReport);
            }
            logger.info("failureException:" + failureException.getClass().getName());
            emailMessage.append(failureException.getMessage() + EOL);
        }
    }

    String validations = (String) jobExecution.getExecutionContext().get("databaseValidations");
    if (validations != null) {
        emailMessage.append("Database Validations:" + EOL + validations);
    }

    logger.info(emailMessage.toString());
    return emailMessage.toString();
}

From source file:org.springframework.batch.core.jsr.configuration.xml.RetryListenerTests.java

@Test
@SuppressWarnings("resource")
public void testReadRetryExhausted() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerExhausted.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    assertTrue("Expected 1 failure exceptions", failureExceptions.size() == 1);
    assertTrue("Failure exception must be of type RetryException",
            (failureExceptions.get(0) instanceof RetryException));
    assertTrue("Exception cause must be of type IllegalArgumentException",
            (failureExceptions.get(0).getCause() instanceof IllegalArgumentException));

    assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
}

From source file:org.springframework.batch.core.jsr.configuration.xml.RetryListenerTests.java

@Test
@SuppressWarnings("resource")
public void testReadRetryExceptionInListener() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerListenerException.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    assertTrue("Failure exceptions must equal one", failureExceptions.size() == 1);
    assertTrue("Failure exception must be of type RetryException",
            (failureExceptions.get(0) instanceof RetryException));
    assertTrue("Exception cause must be of type BatchRuntimeException",
            (failureExceptions.get(0).getCause() instanceof BatchRuntimeException));

    assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
}