use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.
the class JobCancellationHandler method handleRequest.
@Override
public CompletableFuture<EmptyResponseBody> handleRequest(HandlerRequest<EmptyRequestBody> request, RestfulGateway gateway) throws RestHandlerException {
final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
final List<TerminationModeQueryParameter.TerminationMode> terminationModes = request.getQueryParameter(TerminationModeQueryParameter.class);
final TerminationModeQueryParameter.TerminationMode terminationMode;
if (terminationModes.isEmpty()) {
terminationMode = defaultTerminationMode;
} else {
// picking the first termination mode value
terminationMode = terminationModes.get(0);
}
final CompletableFuture<Acknowledge> terminationFuture;
switch(terminationMode) {
case CANCEL:
terminationFuture = gateway.cancelJob(jobId, timeout);
break;
case STOP:
throw new RestHandlerException("The termination mode \"stop\" has been removed. For " + "an ungraceful shutdown, please use \"cancel\" instead. For a graceful shutdown, " + "please use \"jobs/:jobId/stop\" instead.", HttpResponseStatus.PERMANENT_REDIRECT);
default:
terminationFuture = FutureUtils.completedExceptionally(new RestHandlerException("Unknown termination mode " + terminationMode + '.', HttpResponseStatus.BAD_REQUEST));
}
return terminationFuture.handle((Acknowledge ack, Throwable throwable) -> {
if (throwable != null) {
Throwable error = ExceptionUtils.stripCompletionException(throwable);
if (error instanceof FlinkJobTerminatedWithoutCancellationException) {
throw new CompletionException(new RestHandlerException(String.format("Job cancellation failed because the job has already reached another terminal state (%s).", ((FlinkJobTerminatedWithoutCancellationException) error).getJobStatus()), HttpResponseStatus.CONFLICT));
} else if (error instanceof TimeoutException) {
throw new CompletionException(new RestHandlerException("Job cancellation timed out.", HttpResponseStatus.REQUEST_TIMEOUT, error));
} else if (error instanceof FlinkJobNotFoundException) {
throw new CompletionException(new RestHandlerException("Job could not be found.", HttpResponseStatus.NOT_FOUND, error));
} else {
throw new CompletionException(new RestHandlerException("Job cancellation failed: " + error.getMessage(), HttpResponseStatus.INTERNAL_SERVER_ERROR, error));
}
} else {
return EmptyResponseBody.getInstance();
}
});
}
use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.
the class Dispatcher method requestExecutionGraphInfo.
@Override
public CompletableFuture<ExecutionGraphInfo> requestExecutionGraphInfo(JobID jobId, Time timeout) {
Function<Throwable, ExecutionGraphInfo> checkExecutionGraphStoreOnException = throwable -> {
// check whether it is a completed job
final ExecutionGraphInfo executionGraphInfo = executionGraphInfoStore.get(jobId);
if (executionGraphInfo == null) {
throw new CompletionException(ExceptionUtils.stripCompletionException(throwable));
} else {
return executionGraphInfo;
}
};
Optional<JobManagerRunner> maybeJob = getJobManagerRunner(jobId);
return maybeJob.map(job -> job.requestJob(timeout)).orElse(FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).exceptionally(checkExecutionGraphStoreOnException);
}
Aggregations