use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClient method disposeSavepoint.
@Override
public CompletableFuture<Acknowledge> disposeSavepoint(String savepointPath) {
final SavepointDisposalRequest savepointDisposalRequest = new SavepointDisposalRequest(savepointPath);
final CompletableFuture<TriggerResponse> savepointDisposalTriggerFuture = sendRequest(SavepointDisposalTriggerHeaders.getInstance(), savepointDisposalRequest);
final CompletableFuture<AsynchronousOperationInfo> savepointDisposalFuture = savepointDisposalTriggerFuture.thenCompose((TriggerResponse triggerResponse) -> {
final TriggerId triggerId = triggerResponse.getTriggerId();
final SavepointDisposalStatusHeaders savepointDisposalStatusHeaders = SavepointDisposalStatusHeaders.getInstance();
final SavepointDisposalStatusMessageParameters savepointDisposalStatusMessageParameters = savepointDisposalStatusHeaders.getUnresolvedMessageParameters();
savepointDisposalStatusMessageParameters.triggerIdPathParameter.resolve(triggerId);
return pollResourceAsync(() -> sendRequest(savepointDisposalStatusHeaders, savepointDisposalStatusMessageParameters));
});
return savepointDisposalFuture.thenApply((AsynchronousOperationInfo asynchronousOperationInfo) -> {
if (asynchronousOperationInfo.getFailureCause() == null) {
return Acknowledge.get();
} else {
throw new CompletionException(asynchronousOperationInfo.getFailureCause());
}
});
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClient method triggerSavepoint.
private CompletableFuture<String> triggerSavepoint(final JobID jobId, @Nullable final String savepointDirectory, final boolean cancelJob, final SavepointFormatType formatType) {
final SavepointTriggerHeaders savepointTriggerHeaders = SavepointTriggerHeaders.getInstance();
final SavepointTriggerMessageParameters savepointTriggerMessageParameters = savepointTriggerHeaders.getUnresolvedMessageParameters();
savepointTriggerMessageParameters.jobID.resolve(jobId);
final CompletableFuture<TriggerResponse> responseFuture = sendRequest(savepointTriggerHeaders, savepointTriggerMessageParameters, new SavepointTriggerRequestBody(savepointDirectory, cancelJob, 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();
});
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClientSavepointTriggerTest method testTriggerSavepointRetry.
@Test
public void testTriggerSavepointRetry() throws Exception {
final TriggerId triggerId = new TriggerId();
final String expectedSavepointDir = "hello";
final AtomicBoolean failRequest = new AtomicBoolean(true);
try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> triggerId, trigger -> {
if (failRequest.compareAndSet(true, false)) {
throw new RestHandlerException("expected", HttpResponseStatus.SERVICE_UNAVAILABLE);
} else {
return new SavepointInfo(expectedSavepointDir, null);
}
})) {
final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
assertEquals(expectedSavepointDir, savepointPath);
}
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClientSavepointTriggerTest method testTriggerSavepointDefaultDirectory.
@Test
public void testTriggerSavepointDefaultDirectory() throws Exception {
final TriggerId triggerId = new TriggerId();
final String expectedReturnedSavepointDir = "hello";
try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> {
assertThat(request.getTargetDirectory().isPresent(), is(false));
assertFalse(request.isCancelJob());
return triggerId;
}, trigger -> {
assertEquals(triggerId, trigger);
return new SavepointInfo(expectedReturnedSavepointDir, null);
})) {
final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
assertEquals(expectedReturnedSavepointDir, savepointPath);
}
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class AbstractAsynchronousOperationHandlersTest method testOperationCompletion.
/**
* Tests the triggering and successful completion of an asynchronous operation.
*/
@Test
public void testOperationCompletion() throws Exception {
final CompletableFuture<Acknowledge> acknowledgeFuture = new CompletableFuture<>();
testingTriggerHandler.setGatewayCallback((request, gateway) -> acknowledgeFuture);
// trigger the operation
final TriggerId triggerId = testingTriggerHandler.handleRequest(triggerOperationRequest(), DUMMY_GATEWAY).get().getTriggerId();
AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(statusOperationRequest(triggerId), DUMMY_GATEWAY).get();
assertThat(operationResult.queueStatus().getId(), is(QueueStatus.inProgress().getId()));
// complete the operation
acknowledgeFuture.complete(Acknowledge.get());
operationResult = testingStatusHandler.handleRequest(statusOperationRequest(triggerId), DUMMY_GATEWAY).get();
assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));
assertThat(operationResult.resource().value, is(Acknowledge.get()));
}
Aggregations