Java Code Examples for org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#PERMANENT_REDIRECT
The following examples show how to use
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#PERMANENT_REDIRECT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobCancellationHandler.java From flink with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<EmptyResponseBody> handleRequest(HandlerRequest<EmptyRequestBody, JobCancellationMessageParameters> 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 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(); } }); }
Example 2
Source File: JobCancellationHandler.java From flink with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<EmptyResponseBody> handleRequest(HandlerRequest<EmptyRequestBody, JobCancellationMessageParameters> 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 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(); } }); }