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

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

Introduction

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

Prototype

public Long getId() 

Source Link

Usage

From source file:org.my.spring.batch.java.config.demo.Main.java

public static void main(String[] args) {
    //System.exit(SpringApplication.exit(SpringApplication.run(MyBatchConfiguration.class, args)));
    logger.log(Level.INFO, "extracting  job parameters from command line arguments {0}", args);
    JobParameters jobParameters = parseJobParameters(args);
    String basePackage = Main.class.getPackage().getName();
    logger.log(Level.INFO, "scanning {0} for classes with bean definitions", basePackage);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(basePackage);
    Job job1 = context.getBean("job1", Job.class);
    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    try {/*from   ww  w  . j  av  a2 s.co  m*/
        JobExecution jobExecution = jobLauncher.run(job1, jobParameters);
        logger.log(Level.INFO, "job execution {0} ended with status: {1}",
                new Object[] { jobExecution.getId(), jobExecution.getStatus() });
    } catch (Exception ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java

/**
 * Returns a copy of {@link JobExecution}, by adding new Objects for every field(no references are passed)
 * //w w w .j  a va 2 s  .c o  m
 * @param original JobExecution to be copied
 * @return JobExecution copy
 */
private static JobExecution copy(JobExecution original) {
    JobInstance jobInstance = original.getJobInstance();
    JobExecution copy;
    if (jobInstance == null) {
        copy = new JobExecution(original.getId());
    }
    copy = new JobExecution(jobInstance, original.getId());
    if (original.getStartTime() != null) {
        copy.setStartTime((Date) original.getStartTime().clone());
    }
    if (original.getEndTime() != null) {
        copy.setEndTime((Date) original.getEndTime().clone());
    }
    if (original.getStatus() != null) {
        copy.setStatus(BatchStatus.valueOf(original.getStatus().name()));
    }
    if (original.getExitStatus() != null) {
        copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(),
                original.getExitStatus().getExitDescription()));
    }
    if (original.getCreateTime() != null) {
        copy.setCreateTime((Date) original.getCreateTime().clone());
    }
    if (original.getLastUpdated() != null) {
        copy.setLastUpdated((Date) original.getLastUpdated().clone());
    }
    copy.setVersion(original.getVersion());
    return copy;
}

From source file:de.codecentric.batch.listener.RunningExecutionTrackerListener.java

@Override
public void afterJob(JobExecution jobExecution) {
    runningExecutionTracker.removeRunningExecution(jobExecution.getId());
}

From source file:de.codecentric.batch.logging.DefaultJobLogFileNameCreator.java

@Override
public String getBaseName(JobExecution jobExecution) {
    return "batch-" + jobExecution.getJobInstance().getJobName() + "-" + Long.toString(jobExecution.getId());
}

From source file:de.codecentric.batch.listener.RunningExecutionTrackerListener.java

@Override
public void beforeJob(JobExecution jobExecution) {
    runningExecutionTracker.addRunningExecution(jobExecution.getJobInstance().getJobName(),
            jobExecution.getId());
}

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

public void forceRunningJobsToFail() {
    if (logger.isInfoEnabled()) {
        logger.info("Reseting jobs...");
    }/*from w  ww  .  java2  s  .c  o  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.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java

@Override
public void saveJobExecution(JobExecution jobExecution) {
    Assert.isTrue(jobExecution.getId() == null);
    Long newId = currentId.getAndIncrement();
    jobExecution.setId(newId);//from  w  w w.j  ava  2  s  .co  m
    jobExecution.incrementVersion();
    this.addNewExecution(newId, copy(jobExecution));
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobExecutionDao.java

@Override
public void updateJobExecution(JobExecution jobExecution) {
    Long id = jobExecution.getId();
    Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)");
    JobExecution persistedExecution = executionsById.get(id);
    Assert.notNull(persistedExecution, "JobExecution must already be saved");

    synchronized (jobExecution) {
        if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) {
            throw new OptimisticLockingFailureException("Attempt to update step execution id=" + id
                    + " with wrong version (" + jobExecution.getVersion() + "), where current version is "
                    + persistedExecution.getVersion());
        }/*  w  ww . jav a2  s  .co m*/
        jobExecution.incrementVersion();
        this.addNewExecution(id, copy(jobExecution));
    }
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java

/**
 * Removes all the executionContexts for given jobExecution (Including all the stepExecutions
 * related to the jobExecution)//from  w w w.j a  v a  2 s  .c om
 * @param jobExecution
 */
public void removeExecutionContext(JobExecution jobExecution) {
    contexts.remove(ContextKey.job(jobExecution.getId()));
    //No point storing StepExecutionCOntext if jobexecutioncontext have been deleted
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        this.removeExecutionContext(stepExecution);
    }
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java

@Override
public ExecutionContext getExecutionContext(JobExecution jobExecution) {
    return copy(contexts.get(ContextKey.job(jobExecution.getId())));
}