Java源码示例:org.springframework.batch.core.launch.JobExecutionNotRunningException
示例1
@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;
}
示例2
/**
* 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);
}
示例3
@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);
}
示例4
@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();
}
示例5
@Override
public void stopJobExecution(long jobExecutionId)
throws NoSuchJobExecutionException, JobExecutionNotRunningException {
this.jobService.stop(jobExecutionId).getStatus();
}
示例6
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(JobExecutionNotRunningException.class)
public String handleNotRunning(Exception ex) {
LOG.warn("JobExecution is not running.", ex);
return ex.getMessage();
}
示例7
/**
* 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);
}
示例8
/**
* 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;
示例9
/**
* 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;