Search in sources :

Example 11 with FlinkJobNotFoundException

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();
        }
    });
}
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 12 with FlinkJobNotFoundException

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);
}
Also used : JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ClusterOptions(org.apache.flink.configuration.ClusterOptions) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) RpcServiceUtils(org.apache.flink.runtime.rpc.RpcServiceUtils) ExceptionUtils(org.apache.flink.util.ExceptionUtils) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) ClusterOverview(org.apache.flink.runtime.messages.webmonitor.ClusterOverview) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Map(java.util.Map) PermanentlyFencedRpcEndpoint(org.apache.flink.runtime.rpc.PermanentlyFencedRpcEndpoint) Checkpoints(org.apache.flink.runtime.checkpoint.Checkpoints) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) JobGraphWriter(org.apache.flink.runtime.jobmanager.JobGraphWriter) JobsOverview(org.apache.flink.runtime.messages.webmonitor.JobsOverview) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) DispatcherResourceCleanerFactory(org.apache.flink.runtime.dispatcher.cleanup.DispatcherResourceCleanerFactory) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails) Collection(java.util.Collection) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) FlinkJobTerminatedWithoutCancellationException(org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) MetricNames(org.apache.flink.runtime.metrics.MetricNames) MetricGroup(org.apache.flink.metrics.MetricGroup) List(java.util.List) SerializedValue(org.apache.flink.util.SerializedValue) CoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobManagerSharedServices(org.apache.flink.runtime.jobmaster.JobManagerSharedServices) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Optional(java.util.Optional) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) ResourceCleanerFactory(org.apache.flink.runtime.dispatcher.cleanup.ResourceCleanerFactory) Time(org.apache.flink.api.common.time.Time) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway) ClusterEntryPointExceptionUtils(org.apache.flink.runtime.entrypoint.ClusterEntryPointExceptionUtils) FlinkException(org.apache.flink.util.FlinkException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) BlobServer(org.apache.flink.runtime.blob.BlobServer) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) DefaultJobManagerJobMetricGroupFactory(org.apache.flink.runtime.jobmaster.factories.DefaultJobManagerJobMetricGroupFactory) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JobMasterGateway(org.apache.flink.runtime.jobmaster.JobMasterGateway) HashSet(java.util.HashSet) JobResult(org.apache.flink.runtime.jobmaster.JobResult) RpcService(org.apache.flink.runtime.rpc.RpcService) CleanupRunnerFactory(org.apache.flink.runtime.dispatcher.cleanup.CleanupRunnerFactory) ResourceOverview(org.apache.flink.runtime.resourcemanager.ResourceOverview) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) JobManagerRunnerResult(org.apache.flink.runtime.jobmaster.JobManagerRunnerResult) Executor(java.util.concurrent.Executor) OperationResult(org.apache.flink.runtime.rest.handler.async.OperationResult) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) ThreadDumpInfo(org.apache.flink.runtime.rest.messages.ThreadDumpInfo) IOException(java.io.IOException) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) JobID(org.apache.flink.api.common.JobID) ResourceCleaner(org.apache.flink.runtime.dispatcher.cleanup.ResourceCleaner) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) Collections(java.util.Collections) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) JobManagerMetricGroup(org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) CompletionException(java.util.concurrent.CompletionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner)

Aggregations

FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)12 JobID (org.apache.flink.api.common.JobID)9 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 JobStatus (org.apache.flink.api.common.JobStatus)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 Collections (java.util.Collections)4 Time (org.apache.flink.api.common.time.Time)4 JobResult (org.apache.flink.runtime.jobmaster.JobResult)4 FlinkException (org.apache.flink.util.FlinkException)4 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)4 Optional (java.util.Optional)3 CompletionException (java.util.concurrent.CompletionException)3 Configuration (org.apache.flink.configuration.Configuration)3 DuplicateJobSubmissionException (org.apache.flink.runtime.client.DuplicateJobSubmissionException)3 ApplicationStatus (org.apache.flink.runtime.clusterframework.ApplicationStatus)3 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)3 FlinkJobTerminatedWithoutCancellationException (org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException)3 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)3 Test (org.junit.Test)3