org.apache.flink.runtime.rest.messages.TerminationModeQueryParameter Java Examples
The following examples show how to use
org.apache.flink.runtime.rest.messages.TerminationModeQueryParameter.
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: JobTerminationHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public JobTerminationHandler( GatewayRetriever<? extends RestfulGateway> leaderRetriever, Time timeout, Map<String, String> headers, MessageHeaders<EmptyRequestBody, EmptyResponseBody, JobTerminationMessageParameters> messageHeaders, TerminationModeQueryParameter.TerminationMode defaultTerminationMode) { super(leaderRetriever, timeout, headers, messageHeaders); this.defaultTerminationMode = Preconditions.checkNotNull(defaultTerminationMode); }
Example #2
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void stop(JobID jobID) throws Exception { JobTerminationMessageParameters params = new JobTerminationMessageParameters(); params.jobPathParameter.resolve(jobID); params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.STOP)); CompletableFuture<EmptyResponseBody> responseFuture = sendRequest( JobTerminationHeaders.getInstance(), params); responseFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS); }
Example #3
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void cancel(JobID jobID) throws Exception { JobTerminationMessageParameters params = new JobTerminationMessageParameters(); params.jobPathParameter.resolve(jobID); params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.CANCEL)); CompletableFuture<EmptyResponseBody> responseFuture = sendRequest( JobTerminationHeaders.getInstance(), params); responseFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS); }
Example #4
Source File: RestClusterClientTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, JobTerminationMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException { switch (request.getQueryParameter(TerminationModeQueryParameter.class).get(0)) { case CANCEL: jobCanceled = true; break; case STOP: jobStopped = true; break; } return CompletableFuture.completedFuture(EmptyResponseBody.getInstance()); }
Example #5
Source File: JobCancellationHandler.java From flink with Apache License 2.0 | 5 votes |
public JobCancellationHandler( GatewayRetriever<? extends RestfulGateway> leaderRetriever, Time timeout, Map<String, String> headers, MessageHeaders<EmptyRequestBody, EmptyResponseBody, JobCancellationMessageParameters> messageHeaders, TerminationModeQueryParameter.TerminationMode defaultTerminationMode) { super(leaderRetriever, timeout, headers, messageHeaders); this.defaultTerminationMode = Preconditions.checkNotNull(defaultTerminationMode); }
Example #6
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
@Override public void cancel(JobID jobID) throws Exception { JobCancellationMessageParameters params = new JobCancellationMessageParameters(); params.jobPathParameter.resolve(jobID); params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.CANCEL)); CompletableFuture<EmptyResponseBody> responseFuture = sendRequest( JobCancellationHeaders.getInstance(), params); responseFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS); }
Example #7
Source File: JobCancellationHandler.java From flink with Apache License 2.0 | 5 votes |
public JobCancellationHandler( GatewayRetriever<? extends RestfulGateway> leaderRetriever, Time timeout, Map<String, String> headers, MessageHeaders<EmptyRequestBody, EmptyResponseBody, JobCancellationMessageParameters> messageHeaders, TerminationModeQueryParameter.TerminationMode defaultTerminationMode) { super(leaderRetriever, timeout, headers, messageHeaders); this.defaultTerminationMode = Preconditions.checkNotNull(defaultTerminationMode); }
Example #8
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Acknowledge> cancel(JobID jobID) { JobCancellationMessageParameters params = new JobCancellationMessageParameters(); params.jobPathParameter.resolve(jobID); params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.CANCEL)); CompletableFuture<EmptyResponseBody> responseFuture = sendRequest( JobCancellationHeaders.getInstance(), params); return responseFuture.thenApply(ignore -> Acknowledge.get()); }
Example #9
Source File: JobTerminationHandler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<EmptyResponseBody> handleRequest(HandlerRequest<EmptyRequestBody, JobTerminationMessageParameters> request, RestfulGateway gateway) { 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: terminationFuture = gateway.stopJob(jobId, timeout); break; 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 termination (" + terminationMode + ") 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 termination (" + terminationMode + ") failed: " + error.getMessage(), HttpResponseStatus.INTERNAL_SERVER_ERROR, error)); } } else { return EmptyResponseBody.getInstance(); } }); }
Example #10
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 #11
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(); } }); }