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

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

Introduction

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

Prototype

public Long getJobId() 

Source Link

Document

Convenience getter for for the id of the enclosing job.

Usage

From source file:org.seedstack.spring.batch.sample.listeners.AppJobExecutionListener.java

public void afterJob(JobExecution jobExecution) {
    if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
        logger.debug("Job completed with JobId {} ", jobExecution.getJobId());
    } else if (jobExecution.getStatus() == BatchStatus.FAILED) {
        logger.debug("Job failed with JobId {} ", jobExecution.getJobId());
    }//from   ww w  .j a v  a 2 s. c  o m
}

From source file:org.seedstack.spring.batch.sample.listeners.AppJobExecutionListener.java

public void beforeJob(JobExecution jobExecution) {
    if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
        logger.debug("Job completed with JobId {} ", jobExecution.getJobId());
    } else if (jobExecution.getStatus() == BatchStatus.FAILED) {
        logger.debug("Job failed with JobId {} ", jobExecution.getJobId());
    }//w ww .ja v a  2s  . co  m
}

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

@Router
public String route(JobExecution jobExecution) {
    while (jobExecution.getStatus().isRunning()) {
        LOGGER.debug("Still running job {} execution end ...", jobExecution.getJobId());
        try {/*from   w  w  w. j  a  v a  2  s . co  m*/
            Thread.sleep(pollingInterval);
        } catch (InterruptedException e) {
            LOGGER.warn("Router has been interrupted before job execution ending", e);
            return errorChannel;
        }
    }
    LOGGER.debug("Job {} exit status: {}", jobExecution.getJobId(), jobExecution.getExitStatus());
    if (jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) {
        return successChannel;
    }
    return errorChannel;
}

From source file:bamons.process.monitoring.service.BatchMonitoringServiceImpl.java

/**
 *
 * rawdata (json file) restore .//w  ww  .j  a v  a 2  s.  co  m
 *
 * @param filePath ? 
 * @throws Exception
 */
@Async
@Override
public void restoreRawData(String filePath) throws Exception {
    JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
            .addString("filePath", filePath).toJobParameters();
    JobExecution execution = jobLauncher.run(restoreFileJob, jobParameters);
    execution.getJobId();
}

From source file:org.springframework.batch.admin.domain.JobExecutionInfoResource.java

public JobExecutionInfoResource(JobExecution jobExecution, TimeZone timeZone) {

    if (timeZone != null) {
        this.timeZone = timeZone;
    } else {/*from w  w  w. j av a  2 s . c  o m*/
        this.timeZone = TimeZone.getTimeZone("UTC");
    }

    this.executionId = jobExecution.getId();
    this.jobId = jobExecution.getJobId();
    this.stepExecutionCount = jobExecution.getStepExecutions().size();
    this.jobParameters = jobExecution.getJobParameters();
    this.status = jobExecution.getStatus();
    this.exitStatus = jobExecution.getExitStatus();
    this.jobConfigurationName = jobExecution.getJobConfigurationName();
    this.failureExceptions = jobExecution.getFailureExceptions();
    Map<String, Object> executionContextEntires = new HashMap<String, Object>(
            jobExecution.getExecutionContext().size());

    for (Map.Entry<String, Object> stringObjectEntry : jobExecution.getExecutionContext().entrySet()) {
        executionContextEntires.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
    }

    this.executionContext = executionContextEntires;

    this.version = jobExecution.getVersion();

    JobInstance jobInstance = jobExecution.getJobInstance();
    if (jobInstance != null) {
        this.jobName = jobInstance.getJobName();
        BatchStatus status = jobExecution.getStatus();
        this.restartable = status.isGreaterThan(BatchStatus.STOPPING)
                && status.isLessThan(BatchStatus.ABANDONED);
        this.abandonable = status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED;
        this.stoppable = status.isLessThan(BatchStatus.STOPPING) && status != BatchStatus.COMPLETED;
    } else {
        this.jobName = "?";
    }

    this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(timeZone));

    this.createDate = dateFormat.print(jobExecution.getCreateTime().getTime());
    this.lastUpdated = dateFormat.print(jobExecution.getLastUpdated().getTime());

    if (jobExecution.getStartTime() != null) {
        this.startTime = dateFormat.print(jobExecution.getStartTime().getTime());
        this.endTime = dateFormat.print(jobExecution.getEndTime().getTime());
    }
}

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

private void sendEmail(JobExecution jobExecution, String report) {

    final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    final MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage);
    String[] recipients = emailRecipients.split(",");
    String EOL = System.getProperty("line.separator");

    try {//from  w  w w  .j  av a  2 s  .  co  m
        for (String recipient : recipients) {
            mimeMessageHelper.addTo(recipient);

            if (!StringUtils.isEmpty(replyTo)) {
                mimeMessageHelper.setReplyTo(replyTo);
            }
            mimeMessageHelper.setSubject("Data Import Report for SSP Instance: " + batchTitle + " JobId: "
                    + jobExecution.getJobId());
            mimeMessageHelper.setText(report);
            javaMailSender.send(mimeMessage);

        }
        logger.info("Report emailed" + EOL);
    } catch (MessagingException e) {
        logger.error(e.toString());
    }
    ;
}

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  a  va  2s.co m*/
        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.repository.dao.JdbcJobExecutionDao.java

/**
 *
 * SQL implementation using Sequences via the Spring incrementer
 * abstraction. Once a new id has been obtained, the JobExecution is saved
 * via a SQL INSERT statement./*from   www  .j  av a2s  .  c  o  m*/
 *
 * @see JobExecutionDao#saveJobExecution(JobExecution)
 * @throws IllegalArgumentException if jobExecution is null, as well as any
 * of it's fields to be persisted.
 */
@Override
public void saveJobExecution(JobExecution jobExecution) {

    validateJobExecution(jobExecution);

    jobExecution.incrementVersion();

    jobExecution.setId(jobExecutionIncrementer.nextLongValue());
    Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(),
            jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(),
            jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(),
            jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(),
            jobExecution.getJobConfigurationName() };
    getJdbcTemplate().update(getQuery(SAVE_JOB_EXECUTION), parameters,
            new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR,
                    Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP,
                    Types.VARCHAR });

    insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters());
}

From source file:org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.java

/**
 * Validate JobExecution. At a minimum, JobId, StartTime, EndTime, and
 * Status cannot be null./*ww  w .j  a va 2  s  .c  o m*/
 *
 * @param jobExecution
 * @throws IllegalArgumentException
 */
private void validateJobExecution(JobExecution jobExecution) {

    Assert.notNull(jobExecution);
    Assert.notNull(jobExecution.getJobId(), "JobExecution Job-Id cannot be null.");
    Assert.notNull(jobExecution.getStatus(), "JobExecution status cannot be null.");
    Assert.notNull(jobExecution.getCreateTime(), "JobExecution create time cannot be null");
}

From source file:org.springframework.batch.core.repository.support.SimpleJobRepository.java

@Override
public void update(JobExecution jobExecution) {

    Assert.notNull(jobExecution, "JobExecution cannot be null.");
    Assert.notNull(jobExecution.getJobId(), "JobExecution must have a Job ID set.");
    Assert.notNull(jobExecution.getId(), "JobExecution must be already saved (have an id assigned).");

    jobExecution.setLastUpdated(new Date(System.currentTimeMillis()));

    jobExecutionDao.synchronizeStatus(jobExecution);
    jobExecutionDao.updateJobExecution(jobExecution);
}