use of org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo 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.job.savepoints.SavepointInfo 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.job.savepoints.SavepointInfo 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.job.savepoints.SavepointInfo in project flink by apache.
the class SavepointHandlersTest method testProvidedTriggerId.
@Test
public void testProvidedTriggerId() throws Exception {
final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
final TriggerId providedTriggerId = new TriggerId();
final TriggerId returnedTriggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(DEFAULT_REQUESTED_SAVEPOINT_TARGET_DIRECTORY, SavepointFormatType.CANONICAL, providedTriggerId), testingRestfulGateway).get().getTriggerId();
assertEquals(providedTriggerId, returnedTriggerId);
AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(providedTriggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
use of org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo in project flink by apache.
the class SavepointHandlersTest method testSavepointCompletedSuccessfully.
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
final AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
final TriggerId triggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(), testingRestfulGateway).get().getTriggerId();
AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(triggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
Aggregations