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

The following examples show how to use org.springframework.batch.core.launch.JobExecutionNotRunningException. 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: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException {
	JobExecution jobExecution = getJobExecution(jobExecutionId);
	if (!jobExecution.isRunning()) {
		throw new JobExecutionNotRunningException("JobExecution is not running and therefore cannot be stopped");
	}

	logger.info("Stopping job execution: " + jobExecution);

	Collection<String> jsrJobNames = getJsrJobNames();

	if (jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) {
		jsrJobOperator.stop(jobExecutionId);
		jobExecution = getJobExecution(jobExecutionId);
	}
	else {
		jobExecution.stop();
		jobRepository.update(jobExecution);
	}
	return jobExecution;

}
 
Example #2
Source File: RestControllerAdvice.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Log the exception message at warn level and stack trace as trace level. Return
 * response status HttpStatus.UNPROCESSABLE_ENTITY
 *
 * @param e one of the exceptions, {@link JobNotRestartableException} or
 * {@link JobExecutionNotRunningException}
 * @return the error response in JSON format with media type
 * application/vnd.error+json
 */
@ExceptionHandler({ JobNotRestartableException.class, JobExecutionNotRunningException.class })
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public VndErrors onUnprocessableEntityException(Exception e) {
	String logref = logWarnLevelExceptionMessage(e);
	if (logger.isTraceEnabled()) {
		logTraceLevelStrackTrace(e);
	}
	String msg = getExceptionMessage(e);
	return new VndErrors(logref, msg);
}
 
Example #3
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected = SpringBatchLightminApplicationException.class)
public void stopJobExecutionExceptionTest() throws JobParametersInvalidException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException,
        JobExecutionNotRunningException {
    final Long jobExecutionId = 10L;
    when(this.jobOperator.stop(jobExecutionId)).thenThrow(NoSuchJobExecutionException.class);
    this.jobService.stopJobExecution(jobExecutionId);
}
 
Example #4
Source File: JobOperationsController.java    From spring-boot-starter-batch-web with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/jobs/executions/{executionId}", method = RequestMethod.DELETE)
public String stop(@PathVariable long executionId)
		throws NoSuchJobExecutionException, JobExecutionNotRunningException {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Stop JobExecution with id: {}", executionId);
	}
	Boolean successful = jobOperator.stop(executionId);
	return successful.toString();
}
 
Example #5
Source File: DefaultTaskJobService.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public void stopJobExecution(long jobExecutionId)
		throws NoSuchJobExecutionException, JobExecutionNotRunningException {
	this.jobService.stop(jobExecutionId).getStatus();
}
 
Example #6
Source File: JobOperationsController.java    From spring-boot-starter-batch-web with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(JobExecutionNotRunningException.class)
public String handleNotRunning(Exception ex) {
	LOG.warn("JobExecution is not running.", ex);
	return ex.getMessage();
}
 
Example #7
Source File: JobExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * Stop a Job Execution with the given jobExecutionId. Please be aware that you must
 * provide the request parameter {@code stop=true} in order to invoke this endpoint.
 *
 * @param jobExecutionId the executionId of the job execution to stop.
 * @throws JobExecutionNotRunningException if a stop is requested on a job that is not
 *     running.
 * @throws NoSuchJobExecutionException if the job execution id specified does not exist.
 */
@RequestMapping(value = { "/{executionId}" }, method = RequestMethod.PUT, params = "stop=true")
@ResponseStatus(HttpStatus.OK)
public void stopJobExecution(@PathVariable("executionId") long jobExecutionId)
		throws NoSuchJobExecutionException, JobExecutionNotRunningException {
	taskJobService.stopJobExecution(jobExecutionId);
}
 
Example #8
Source File: TaskJobService.java    From spring-cloud-dataflow with Apache License 2.0 2 votes vote down vote up
/**
 * Requests a {@link JobExecution} to stop.
 * <p>
 * Please remember, that calling this method only requests a job execution to stop
 * processing. This method does not guarantee a {@link JobExecution} to stop. It is the
 * responsibility of the implementor of the {@link Job} to react to that request.
 * Furthermore, this method does not interfere with the associated {@link TaskExecution}.
 *
 * @param jobExecutionId The id of the {@link JobExecution} to stop
 * @throws NoSuchJobExecutionException thrown if no job execution exists for the
 *     jobExecutionId.
 * @throws JobExecutionNotRunningException thrown if a stop is requested on a job that is
 *     not running.
 * @see org.springframework.cloud.dataflow.server.batch.JobService#stop(Long)
 */
void stopJobExecution(long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException;
 
Example #9
Source File: JobService.java    From spring-cloud-dataflow with Apache License 2.0 2 votes vote down vote up
/**
 * Send a signal to a job execution to stop processing. This method does not guarantee
 * that the processing will stop, only that the signal will be delivered. It is up to the
 * individual {@link Job} and {@link Step} implementations to ensure that the signal is
 * obeyed. In particular, if users provide a custom {@link Tasklet} to a {@link Step} it
 * must check the signal in the {@link JobExecution} itself.
 * 
 * @param jobExecutionId the job execution id to stop
 * @return the {@link JobExecution} that was stopped
 * @throws NoSuchJobExecutionException thrown if job execution specified does not exist
 * @throws JobExecutionNotRunningException thrown if the job execution specified is not
 *     running
 */
JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException;