Search in sources :

Example 16 with TriggerId

use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.

the class AbstractAsynchronousOperationHandlersTest method testCloseShouldFinishOnFirstServedResult.

/**
 * Tests that the future returned by {@link
 * AbstractAsynchronousOperationHandlers.StatusHandler#closeAsync()} completes when the result
 * of the asynchronous operation is served.
 */
@Test
public void testCloseShouldFinishOnFirstServedResult() throws Exception {
    final CompletableFuture<Acknowledge> acknowledgeFuture = new CompletableFuture<>();
    testingTriggerHandler.setGatewayCallback((request, gateway) -> acknowledgeFuture);
    final TriggerId triggerId = testingTriggerHandler.handleRequest(triggerOperationRequest(), DUMMY_GATEWAY).get().getTriggerId();
    final CompletableFuture<Void> closeFuture = testingStatusHandler.closeAsync();
    testingStatusHandler.handleRequest(statusOperationRequest(triggerId), DUMMY_GATEWAY).get();
    assertThat(closeFuture.isDone(), is(false));
    acknowledgeFuture.complete(Acknowledge.get());
    testingStatusHandler.handleRequest(statusOperationRequest(triggerId), DUMMY_GATEWAY).get();
    assertThat(closeFuture.isDone(), is(true));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) Test(org.junit.Test)

Example 17 with TriggerId

use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.

the class SavepointHandlersTest method testQueryStatusOfUnknownOperationReturnsError.

@Test
public void testQueryStatusOfUnknownOperationReturnsError() throws HandlerRequestException, RestHandlerException {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setGetSavepointStatusFunction(key -> FutureUtils.completedExceptionally(new UnknownOperationKeyException(key))).build();
    final CompletableFuture<AsynchronousOperationResult<SavepointInfo>> statusFuture = savepointStatusHandler.handleRequest(savepointStatusRequest(new TriggerId()), testingRestfulGateway);
    assertThat(statusFuture, RestMatchers.respondsWithError(HttpResponseStatus.NOT_FOUND));
}
Also used : AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SavepointTestUtilities.setReferenceToOperationKey(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.setReferenceToOperationKey) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) TriggerIdPathParameter(org.apache.flink.runtime.rest.messages.TriggerIdPathParameter) Assert.assertThat(org.junit.Assert.assertThat) SavepointTestUtilities.getResultIfKeyMatches(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.getResultIfKeyMatches) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Map(java.util.Map) SavepointTriggerRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerRequestBody) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) SavepointStatusMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointStatusMessageParameters) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) HandlerRequestException(org.apache.flink.runtime.rest.handler.HandlerRequestException) RestMatchers(org.apache.flink.runtime.rest.RestMatchers) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) OperationResult(org.apache.flink.runtime.rest.handler.async.OperationResult) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) JobID(org.apache.flink.api.common.JobID) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 18 with TriggerId

use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.

the class RestClusterClient method stopWithSavepoint.

@Override
public CompletableFuture<String> stopWithSavepoint(final JobID jobId, final boolean advanceToEndOfTime, @Nullable final String savepointDirectory, final SavepointFormatType formatType) {
    final StopWithSavepointTriggerHeaders stopWithSavepointTriggerHeaders = StopWithSavepointTriggerHeaders.getInstance();
    final SavepointTriggerMessageParameters stopWithSavepointTriggerMessageParameters = stopWithSavepointTriggerHeaders.getUnresolvedMessageParameters();
    stopWithSavepointTriggerMessageParameters.jobID.resolve(jobId);
    final CompletableFuture<TriggerResponse> responseFuture = sendRequest(stopWithSavepointTriggerHeaders, stopWithSavepointTriggerMessageParameters, new StopWithSavepointRequestBody(savepointDirectory, advanceToEndOfTime, formatType, null));
    return responseFuture.thenCompose(savepointTriggerResponseBody -> {
        final TriggerId savepointTriggerId = savepointTriggerResponseBody.getTriggerId();
        return pollSavepointAsync(jobId, savepointTriggerId);
    }).thenApply(savepointInfo -> {
        if (savepointInfo.getFailureCause() != null) {
            throw new CompletionException(savepointInfo.getFailureCause());
        }
        return savepointInfo.getLocation();
    });
}
Also used : JobAccumulatorsHeaders(org.apache.flink.runtime.rest.messages.JobAccumulatorsHeaders) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobAccumulatorsInfo(org.apache.flink.runtime.rest.messages.JobAccumulatorsInfo) SavepointDisposalTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointDisposalTriggerHeaders) AsynchronousOperationInfo(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationInfo) DefaultClientHighAvailabilityServicesFactory(org.apache.flink.runtime.highavailability.DefaultClientHighAvailabilityServicesFactory) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) ExponentialWaitStrategy(org.apache.flink.client.program.rest.retry.ExponentialWaitStrategy) JobSubmitHeaders(org.apache.flink.runtime.rest.messages.job.JobSubmitHeaders) Path(org.apache.flink.core.fs.Path) Map(java.util.Map) ShutdownHeaders(org.apache.flink.runtime.rest.messages.cluster.ShutdownHeaders) ClientCoordinationHeaders(org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationHeaders) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) JobExecutionResultHeaders(org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders) RestConstants(org.apache.flink.runtime.rest.util.RestConstants) JobsOverviewHeaders(org.apache.flink.runtime.rest.messages.JobsOverviewHeaders) Executors(java.util.concurrent.Executors) ConnectTimeoutException(org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) ClusterClient(org.apache.flink.client.program.ClusterClient) Time(org.apache.flink.api.common.time.Time) JobSubmitResponseBody(org.apache.flink.runtime.rest.messages.job.JobSubmitResponseBody) FlinkException(org.apache.flink.util.FlinkException) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) JobStatus(org.apache.flink.api.common.JobStatus) AccumulatorHelper(org.apache.flink.api.common.accumulators.AccumulatorHelper) Supplier(java.util.function.Supplier) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) ArrayList(java.util.ArrayList) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) StopWithSavepointRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.stop.StopWithSavepointRequestBody) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) ObjectOutputStream(java.io.ObjectOutputStream) SavepointStatusMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointStatusMessageParameters) CheckedSupplier(org.apache.flink.util.function.CheckedSupplier) Nullable(javax.annotation.Nullable) TriggerResponse(org.apache.flink.runtime.rest.handler.async.TriggerResponse) SavepointDisposalStatusMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointDisposalStatusMessageParameters) Files(java.nio.file.Files) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) JobDetailsInfo(org.apache.flink.runtime.rest.messages.job.JobDetailsInfo) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) IOException(java.io.IOException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) ExecutionException(java.util.concurrent.ExecutionException) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) JobID(org.apache.flink.api.common.JobID) Paths(java.nio.file.Paths) TerminationModeQueryParameter(org.apache.flink.runtime.rest.messages.TerminationModeQueryParameter) SavepointStatusHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointStatusHeaders) SavepointDisposalRequest(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointDisposalRequest) MessageParameters(org.apache.flink.runtime.rest.messages.MessageParameters) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) URL(java.net.URL) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ClientCoordinationRequestBody(org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationRequestBody) JobAccumulatorsMessageParameters(org.apache.flink.runtime.rest.messages.JobAccumulatorsMessageParameters) SavepointTriggerRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerRequestBody) RequestBody(org.apache.flink.runtime.rest.messages.RequestBody) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) SavepointDisposalStatusHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointDisposalStatusHeaders) RestClientException(org.apache.flink.runtime.rest.util.RestClientException) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) LeaderRetriever(org.apache.flink.runtime.webmonitor.retriever.LeaderRetriever) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) Predicate(java.util.function.Predicate) Collection(java.util.Collection) CompletionException(java.util.concurrent.CompletionException) SavepointTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerHeaders) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Collectors(java.util.stream.Collectors) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) StopWithSavepointTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.stop.StopWithSavepointTriggerHeaders) ExecutorUtils(org.apache.flink.util.ExecutorUtils) FileUpload(org.apache.flink.runtime.rest.FileUpload) List(java.util.List) SerializedValue(org.apache.flink.util.SerializedValue) CoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) JobCancellationHeaders(org.apache.flink.runtime.rest.messages.JobCancellationHeaders) JobResult(org.apache.flink.runtime.jobmaster.JobResult) WaitStrategy(org.apache.flink.client.program.rest.retry.WaitStrategy) ClientCoordinationMessageParameters(org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationMessageParameters) ClientHighAvailabilityServices(org.apache.flink.runtime.highavailability.ClientHighAvailabilityServices) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) JobDetailsHeaders(org.apache.flink.runtime.rest.messages.job.JobDetailsHeaders) AsynchronouslyCreatedResource(org.apache.flink.runtime.rest.messages.queue.AsynchronouslyCreatedResource) Nonnull(javax.annotation.Nonnull) ExecutorService(java.util.concurrent.ExecutorService) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Configuration(org.apache.flink.configuration.Configuration) ClientHighAvailabilityServicesFactory(org.apache.flink.runtime.highavailability.ClientHighAvailabilityServicesFactory) TimeUnit(java.util.concurrent.TimeUnit) ResponseBody(org.apache.flink.runtime.rest.messages.ResponseBody) JobCancellationMessageParameters(org.apache.flink.runtime.rest.messages.JobCancellationMessageParameters) Collections(java.util.Collections) RestClient(org.apache.flink.runtime.rest.RestClient) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) CompletionException(java.util.concurrent.CompletionException) StopWithSavepointTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.stop.StopWithSavepointTriggerHeaders) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) TriggerResponse(org.apache.flink.runtime.rest.handler.async.TriggerResponse) StopWithSavepointRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.stop.StopWithSavepointRequestBody)

Aggregations

TriggerId (org.apache.flink.runtime.rest.messages.TriggerId)18 Test (org.junit.Test)15 SavepointInfo (org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 JobID (org.apache.flink.api.common.JobID)7 AsynchronousJobOperationKey (org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey)7 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)5 RestServerEndpoint (org.apache.flink.runtime.rest.RestServerEndpoint)4 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)4 Collections (java.util.Collections)3 Map (java.util.Map)3 CompletionException (java.util.concurrent.CompletionException)3 ExecutionException (java.util.concurrent.ExecutionException)3 IOException (java.io.IOException)2 ObjectOutputStream (java.io.ObjectOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Files (java.nio.file.Files)2