Example usage for org.springframework.batch.core JobParametersIncrementer getNext

List of usage examples for org.springframework.batch.core JobParametersIncrementer getNext

Introduction

In this page you can find the example usage for org.springframework.batch.core JobParametersIncrementer getNext.

Prototype

JobParameters getNext(@Nullable JobParameters parameters);

Source Link

Document

Increment the provided parameters.

Usage

From source file:de.codecentric.batch.web.JobOperationsController.java

/**
 * Borrowed from CommandLineJobRunner.//www.j a  v a 2 s .c  o  m
 * @param job the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException if there is a problem
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();

    if (lastInstances.isEmpty()) {
        jobParameters = incrementer.getNext(new JobParameters());
        if (jobParameters == null) {
            throw new JobParametersNotFoundException(
                    "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
        }
    } else {
        List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
        jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }
    return jobParameters;
}

From source file:egovframework.rte.bat.core.launch.support.EgovCommandLineRunner.java

/**
 * ?  ? Batch Job? Job Parameter ?./*from  w  ww .  j  a v a 2  s. c o  m*/
 * 
 * @param job
 * @return JobParameters
 * @throws JobParametersNotFoundException 
 */
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
        throw new JobParametersNotFoundException(
                "No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
        jobParameters = incrementer.getNext(new JobParameters());
        if (jobParameters == null) {
            throw new JobParametersNotFoundException(
                    "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
        }
    } else {
        jobParameters = incrementer.getNext(lastInstances.get(0).getJobParameters());
    }
    return jobParameters;
}

From source file:org.springframework.batch.core.launch.support.CommandLineJobRunner.java

/**
 * @param job the job that we need to find the next parameters for
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException if there is a problem
 *///from ww  w  . ja va2s .  c o m
private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
        throw new JobParametersNotFoundException(
                "No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
        jobParameters = incrementer.getNext(new JobParameters());
        if (jobParameters == null) {
            throw new JobParametersNotFoundException(
                    "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
        }
    } else {
        List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
        jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }
    return jobParameters;
}

From source file:org.springframework.batch.core.launch.support.SimpleJobOperator.java

@Override
public Long startNextInstance(String jobName) throws NoSuchJobException, JobParametersNotFoundException,
        UnexpectedJobExecutionException, JobParametersInvalidException {

    logger.info("Locating parameters for next instance of job with name=" + jobName);

    Job job = jobRegistry.getJob(jobName);
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobName, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
        throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobName);
    }/* w  w w.  j a va  2 s. c  o m*/

    JobParameters parameters;
    if (lastInstances.isEmpty()) {
        parameters = incrementer.getNext(new JobParameters());
        if (parameters == null) {
            throw new JobParametersNotFoundException("No bootstrap parameters found for job=" + jobName);
        }
    } else {
        List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
        parameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }

    logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters));
    try {
        return jobLauncher.run(job, parameters).getId();
    } catch (JobExecutionAlreadyRunningException e) {
        throw new UnexpectedJobExecutionException(
                String.format(ILLEGAL_STATE_MSG, "job already running", jobName, parameters), e);
    } catch (JobRestartException e) {
        throw new UnexpectedJobExecutionException(
                String.format(ILLEGAL_STATE_MSG, "job not restartable", jobName, parameters), e);
    } catch (JobInstanceAlreadyCompleteException e) {
        throw new UnexpectedJobExecutionException(
                String.format(ILLEGAL_STATE_MSG, "job instance already complete", jobName, parameters), e);
    }

}

From source file:org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.java

private JobParameters getNextJobParameters(Job job, JobParameters additionalParameters) {
    String name = job.getName();/*from w  ww. ja  v  a2s . c om*/
    JobParameters parameters = new JobParameters();
    List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(name, 0, 1);
    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    Map<String, JobParameter> additionals = additionalParameters.getParameters();
    if (lastInstances.isEmpty()) {
        // Start from a completely clean sheet
        if (incrementer != null) {
            parameters = incrementer.getNext(new JobParameters());
        }
    } else {
        List<JobExecution> previousExecutions = this.jobExplorer.getJobExecutions(lastInstances.get(0));
        JobExecution previousExecution = previousExecutions.get(0);
        if (previousExecution == null) {
            // Normally this will not happen - an instance exists with no executions
            if (incrementer != null) {
                parameters = incrementer.getNext(new JobParameters());
            }
        } else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
            // Retry a failed or stopped execution
            parameters = previousExecution.getJobParameters();
            // Non-identifying additional parameters can be removed to a retry
            removeNonIdentifying(additionals);
        } else if (incrementer != null) {
            // New instance so increment the parameters if we can
            parameters = incrementer.getNext(previousExecution.getJobParameters());
        }
    }
    return merge(parameters, additionals);
}

From source file:org.springframework.yarn.batch.support.YarnJobLauncher.java

/**
 * Get next job parameters for a job using {@link JobParametersIncrementer}.
 *
 * @param job the job that we need to find the next parameters for
 * @param fail suppress exception/*from  w w w  .  j a va2s  . c o  m*/
 * @return the next job parameters if they can be located
 * @throws JobParametersNotFoundException if there is a problem
 */
private JobParameters getNextJobParameters(Job job, boolean fail) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
        throw new JobParametersNotFoundException(
                "No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
        jobParameters = incrementer.getNext(new JobParameters());
        if (jobParameters == null) {
            throw new JobParametersNotFoundException(
                    "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
        }
    } else {
        List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
        jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }
    return jobParameters;
}