Example usage for org.springframework.batch.core StepExecution getSummary

List of usage examples for org.springframework.batch.core StepExecution getSummary

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getSummary.

Prototype

public String getSummary() 

Source Link

Usage

From source file:de.langmi.spring.batch.examples.listeners.fileoutput.FileOutputJobConfigurationTest.java

/** Launch Test. */
@Test/*w w w .  j  a v a 2s  .  c  om*/
public void launchJob() throws Exception {
    // Job parameters
    Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
    jobParametersMap.put("time", new JobParameter(System.currentTimeMillis()));
    jobParametersMap.put("output.file", new JobParameter("file:target/test-outputs/file-output/output.txt"));
    // launch the job
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap));

    // assert job run status
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // output step summaries
    for (StepExecution step : jobExecution.getStepExecutions()) {
        LOG.debug(step.getSummary());
        assertTrue("Read Count mismatch.", step.getReadCount() == TestDataFactoryBean.COUNT);
    }
}

From source file:de.langmi.spring.batch.examples.listeners.SimpleJobConfigurationTest.java

/** Launch Test. */
@Test//from ww w.jav  a  2s  . c o  m
public void launchJob() throws Exception {
    // Job parameters
    Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
    jobParametersMap.put("time", new JobParameter(System.currentTimeMillis()));
    jobParametersMap.put("output.file", new JobParameter("file:target/test-outputs/simple/output.txt"));

    // launch the job
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap));

    // assert job run status
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // output step summaries
    for (StepExecution step : jobExecution.getStepExecutions()) {
        LOG.debug(step.getSummary());
        assertTrue("Read Count mismatch.", step.getReadCount() == TestDataFactoryBean.COUNT);
    }
}

From source file:de.langmi.spring.batch.examples.complex.skip.simple.SkipJobListener.java

@Override
public void afterJob(JobExecution jobExecution) {
    LOG.debug("after job");
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        LOG.debug(stepExecution.getSummary());
    }/*from   w  w w . j  ava  2s  .c  om*/
}

From source file:uk.ac.ebi.intact.editor.batch.admin.MailNotifierStepExecutionListener.java

public void beforeStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[Editor_import] Started step: " + stepExecution.getStepName() + "");
    message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    try {// www  .  j a v  a2  s.  c o m
        mailSender.send(message);
    } catch (MailException e) {
        log.error("Impossible to send e-mail", e);
    }
}

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

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    logger.info("End Raw Write Step for " + stepExecution.getExecutionContext().getString("fileName")
            + " lines read: " + stepExecution.getReadCount() + " lines skipped: "
            + stepExecution.getReadSkipCount());
    logger.info(stepExecution.getSummary());
    return ExitStatus.COMPLETED;
}

From source file:uk.ac.ebi.intact.editor.batch.admin.MailNotifierStepExecutionListener.java

public ExitStatus afterStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[Editor_import] Finished step: " + stepExecution.getStepName() + " Exit status: "
            + stepExecution.getExitStatus().getExitCode());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n"
            + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    try {// w  w  w  .jav  a  2s  .c  o  m
        mailSender.send(message);
    } catch (MailException e) {
        log.error("Impossible to send e-mail", e);
    }

    return stepExecution.getExitStatus();
}

From source file:org.springframework.batch.core.step.AbstractStep.java

/**
 * Template method for step execution logic - calls abstract methods for resource initialization (
 * {@link #open(ExecutionContext)}), execution logic ({@link #doExecute(StepExecution)}) and resource closing (
 * {@link #close(ExecutionContext)}).//from   w  w w  .java 2s .  com
 */
@Override
public final void execute(StepExecution stepExecution)
        throws JobInterruptedException, UnexpectedJobExecutionException {

    if (logger.isDebugEnabled()) {
        logger.debug("Executing: id=" + stepExecution.getId());
    }
    stepExecution.setStartTime(new Date());
    stepExecution.setStatus(BatchStatus.STARTED);
    getJobRepository().update(stepExecution);

    // Start with a default value that will be trumped by anything
    ExitStatus exitStatus = ExitStatus.EXECUTING;

    doExecutionRegistration(stepExecution);

    try {
        getCompositeListener().beforeStep(stepExecution);
        open(stepExecution.getExecutionContext());

        try {
            doExecute(stepExecution);
        } catch (RepeatException e) {
            throw e.getCause();
        }
        exitStatus = ExitStatus.COMPLETED.and(stepExecution.getExitStatus());

        // Check if someone is trying to stop us
        if (stepExecution.isTerminateOnly()) {
            throw new JobInterruptedException("JobExecution interrupted.");
        }

        // Need to upgrade here not set, in case the execution was stopped
        stepExecution.upgradeStatus(BatchStatus.COMPLETED);
        if (logger.isDebugEnabled()) {
            logger.debug("Step execution success: id=" + stepExecution.getId());
        }
    } catch (Throwable e) {
        stepExecution.upgradeStatus(determineBatchStatus(e));
        exitStatus = exitStatus.and(getDefaultExitStatusForFailure(e));
        stepExecution.addFailureException(e);
        if (stepExecution.getStatus() == BatchStatus.STOPPED) {
            logger.info(String.format("Encountered interruption executing step %s in job %s : %s", name,
                    stepExecution.getJobExecution().getJobInstance().getJobName(), e.getMessage()));
            if (logger.isDebugEnabled()) {
                logger.debug("Full exception", e);
            }
        } else {
            logger.error(String.format("Encountered an error executing step %s in job %s", name,
                    stepExecution.getJobExecution().getJobInstance().getJobName()), e);
        }
    } finally {

        try {
            // Update the step execution to the latest known value so the
            // listeners can act on it
            exitStatus = exitStatus.and(stepExecution.getExitStatus());
            stepExecution.setExitStatus(exitStatus);
            exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
        } catch (Exception e) {
            logger.error(String.format("Exception in afterStep callback in step %s in job %s", name,
                    stepExecution.getJobExecution().getJobInstance().getJobName()), e);
        }

        try {
            getJobRepository().updateExecutionContext(stepExecution);
        } catch (Exception e) {
            stepExecution.setStatus(BatchStatus.UNKNOWN);
            exitStatus = exitStatus.and(ExitStatus.UNKNOWN);
            stepExecution.addFailureException(e);
            logger.error(String.format(
                    "Encountered an error saving batch meta data for step %s in job %s. "
                            + "This job is now in an unknown state and should not be restarted.",
                    name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
        }

        stepExecution.setEndTime(new Date());
        stepExecution.setExitStatus(exitStatus);

        try {
            getJobRepository().update(stepExecution);
        } catch (Exception e) {
            stepExecution.setStatus(BatchStatus.UNKNOWN);
            stepExecution.setExitStatus(exitStatus.and(ExitStatus.UNKNOWN));
            stepExecution.addFailureException(e);
            logger.error(String.format(
                    "Encountered an error saving batch meta data for step %s in job %s. "
                            + "This job is now in an unknown state and should not be restarted.",
                    name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
        }

        try {
            close(stepExecution.getExecutionContext());
        } catch (Exception e) {
            logger.error(String.format("Exception while closing step execution resources in step %s in job %s",
                    name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
            stepExecution.addFailureException(e);
        }

        doExecutionRelease();

        if (logger.isDebugEnabled()) {
            logger.debug("Step execution complete: " + stepExecution.getSummary());
        }
    }
}

From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java

public void beforeStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_import] Started step: " + stepExecution.getStepName() + "");
    message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    //        try{
    //            mailSender.send(message);
    //        }//www.  j a  va  2 s .  c  o  m
    //        catch (MailException e){
    //            log.error("Impossible to send e-mail", e);
    //        }
}

From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java

public ExitStatus afterStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_import] Finished step: " + stepExecution.getStepName() + " Exit status: "
            + stepExecution.getExitStatus().getExitCode());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext());
    message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n"
            + stepExecution.getJobExecution());
    message.setTo(stepExecution.getJobParameters().getString("email.recipient"));

    //        try{
    //            mailSender.send(message);
    //        }/* w  w w.  j  a v  a2 s. c  o m*/
    //        catch (MailException e){
    //            log.error("Impossible to send e-mail", e);
    //        }

    return stepExecution.getExitStatus();
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.listener.MailNotifierStepExecutionListener.java

public void beforeStep(StepExecution stepExecution) {

    SimpleMailMessage message = newSimpleMessage();
    message.setSubject("[IntAct_export] Started step: " + stepExecution.getStepName() + "");
    message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution());
    message.setTo(recipients);//from  w w w .  ja v a  2 s . co  m

    try {
        mailSender.send(message);
    } catch (MailException e) {
        log.error("Impossible to send e-mail", e);
    }
}