use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class AbstractJobVertexHandler method handleRequest.
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody> request, AccessExecutionGraph executionGraph) throws RestHandlerException {
final JobVertexID jobVertexID = request.getPathParameter(JobVertexIdPathParameter.class);
final AccessExecutionJobVertex jobVertex = executionGraph.getJobVertex(jobVertexID);
if (jobVertex == null) {
throw new RestHandlerException("No vertex with ID '" + jobVertexID + "' exists.", HttpResponseStatus.NOT_FOUND);
}
return handleRequest(request, jobVertex);
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class AbstractExecutionGraphHandler method handleRequest.
@Override
protected CompletableFuture<R> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
JobID jobId = request.getPathParameter(JobIDPathParameter.class);
CompletableFuture<ExecutionGraphInfo> executionGraphFuture = executionGraphCache.getExecutionGraphInfo(jobId, gateway);
return executionGraphFuture.thenApplyAsync(executionGraph -> {
try {
return handleRequest(request, executionGraph);
} catch (RestHandlerException rhe) {
throw new CompletionException(rhe);
}
}, executor).exceptionally(throwable -> {
throwable = ExceptionUtils.stripCompletionException(throwable);
if (throwable instanceof FlinkJobNotFoundException) {
throw new CompletionException(new NotFoundException(String.format("Job %s not found", jobId), throwable));
} else {
throw new CompletionException(throwable);
}
});
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class AbstractSubtaskAttemptHandler method handleRequest.
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody> request, AccessExecutionVertex executionVertex) throws RestHandlerException {
final Integer attemptNumber = request.getPathParameter(SubtaskAttemptPathParameter.class);
final AccessExecution currentAttempt = executionVertex.getCurrentExecutionAttempt();
if (attemptNumber == currentAttempt.getAttemptNumber()) {
return handleRequest(request, currentAttempt);
} else if (attemptNumber >= 0 && attemptNumber < currentAttempt.getAttemptNumber()) {
final AccessExecution execution = executionVertex.getPriorExecutionAttempt(attemptNumber);
if (execution != null) {
return handleRequest(request, execution);
} else {
throw new RestHandlerException("Attempt " + attemptNumber + " not found in subtask " + executionVertex.getTaskNameWithSubtaskIndex(), HttpResponseStatus.NOT_FOUND);
}
} else {
throw new RestHandlerException("Invalid attempt num " + attemptNumber, HttpResponseStatus.NOT_FOUND);
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException 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.rest.handler.RestHandlerException in project flink by apache.
the class JobExecutionResultHandler method handleRequest.
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);
return jobStatusFuture.thenCompose(jobStatus -> {
if (jobStatus.isGloballyTerminalState()) {
return gateway.requestJobResult(jobId, timeout).thenApply(JobExecutionResultResponseBody::created);
} else {
return CompletableFuture.completedFuture(JobExecutionResultResponseBody.inProgress());
}
}).exceptionally(throwable -> {
throw propagateException(throwable);
});
}
Aggregations