org.springframework.batch.core.launch.JobParametersNotFoundException Java Examples

The following examples show how to use org.springframework.batch.core.launch.JobParametersNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResponseExceptionHandler.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@ExceptionHandler(BatchRuntimeException.class)
protected ResponseEntity<Object> handleBatchRuntimeException(BatchRuntimeException e, WebRequest request) {
    log.error("Request {} failed with {}", request, e);
    Throwable cause = e.getCause();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (cause instanceof DuplicateJobException
            || cause instanceof JobExecutionAlreadyRunningException
            || cause instanceof JobInstanceAlreadyCompleteException)
        status = HttpStatus.CONFLICT;
    else if (cause instanceof JobParametersInvalidException
        || cause instanceof JobParametersNotFoundException)
        status = HttpStatus.BAD_REQUEST;
    else if (cause instanceof NoSuchJobException
        || cause instanceof NoSuchJobExecutionException
        || cause instanceof NoSuchJobInstanceException)
        status = HttpStatus.NOT_FOUND;

    ApiError apiError = new ApiError(status.toString(), cause.getMessage(), cause.getClass().getSimpleName(), e.getMessage());
    return handleExceptionInternal(e, apiError, new HttpHeaders(), status, request);
}
 
Example #2
Source File: SingleJobCommandLineRunner.java    From spring-boot-doma2-sample with Apache License 2.0 6 votes vote down vote up
protected BatchStatus execute(Job job, JobParameters jobParameters)
        throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException, JobParametersNotFoundException {

    BatchStatus status = BatchStatus.UNKNOWN;
    val nextParameters = getNextJobParameters(job, jobParameters);

    if (nextParameters != null) {
        val execution = jobLauncher.run(job, nextParameters);

        if (publisher != null) {
            publisher.publishEvent(new JobExecutionEvent(execution));
        }

        status = execution.getStatus();
    }

    return status;
}
 
Example #3
Source File: JobOperationsController.java    From spring-boot-starter-batch-web with Apache License 2.0 6 votes vote down vote up
/**
 * Borrowed from CommandLineJobRunner.
 *
 * @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;
}
 
Example #4
Source File: JobOperationsController.java    From spring-boot-starter-batch-web with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(JobParametersNotFoundException.class)
public String handleNoBootstrapParametersCreatedByIncrementer(Exception ex) {
	LOG.warn("JobParametersIncrementer didn't provide bootstrap parameters.", ex);
	return ex.getMessage();
}