Search in sources :

Example 26 with RestHandlerException

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);
}
Also used : AccessExecutionJobVertex(org.apache.flink.runtime.executiongraph.AccessExecutionJobVertex) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 27 with RestHandlerException

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);
        }
    });
}
Also used : ExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.ExecutionGraphCache) Executor(java.util.concurrent.Executor) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) Preconditions(org.apache.flink.util.Preconditions) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) ResponseBody(org.apache.flink.runtime.rest.messages.ResponseBody) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) CompletionException(java.util.concurrent.CompletionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) NotFoundException(org.apache.flink.runtime.rest.NotFoundException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobID(org.apache.flink.api.common.JobID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 28 with RestHandlerException

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);
    }
}
Also used : AccessExecution(org.apache.flink.runtime.executiongraph.AccessExecution) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Example 29 with RestHandlerException

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();
        }
    });
}
Also used : Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) FlinkJobTerminatedWithoutCancellationException(org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException) TerminationModeQueryParameter(org.apache.flink.runtime.rest.messages.TerminationModeQueryParameter) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) CompletionException(java.util.concurrent.CompletionException) JobID(org.apache.flink.api.common.JobID) TimeoutException(java.util.concurrent.TimeoutException)

Example 30 with RestHandlerException

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);
    });
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) JobExecutionResultHeaders(org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) JobStatus(org.apache.flink.api.common.JobStatus) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobID(org.apache.flink.api.common.JobID)

Aggregations

RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)39 Test (org.junit.Test)13 IOException (java.io.IOException)11 CompletionException (java.util.concurrent.CompletionException)11 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 JobID (org.apache.flink.api.common.JobID)7 Time (org.apache.flink.api.common.time.Time)6 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Map (java.util.Map)5 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)5 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5