use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class SavepointHandlersTest method testTriggerSavepointNoDirectory.
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction((AsynchronousJobOperationKey operationKey, String directory, SavepointFormatType formatType) -> CompletableFuture.completedFuture(Acknowledge.get())).build();
try {
savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
fail("Expected exception not thrown.");
} catch (RestHandlerException rhe) {
assertThat(rhe.getMessage(), equalTo("Config key [state.savepoints.dir] is not set. " + "Property [target-directory] must be provided."));
assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
}
}
use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class SavepointHandlersTest method testTriggerSavepointWithDefaultDirectory.
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction((AsynchronousJobOperationKey operationKey, String targetDirectory, SavepointFormatType formatType) -> {
targetDirectoryFuture.complete(targetDirectory);
return CompletableFuture.completedFuture(Acknowledge.get());
}).build();
final String defaultSavepointDir = "/other/dir";
final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
final SavepointHandlers.SavepointTriggerHandler savepointTriggerHandler = savepointHandlers.new SavepointTriggerHandler(leaderRetriever, TIMEOUT, Collections.emptyMap());
savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class JobMasterTest method testTriggerSavepointTimeout.
/**
* Tests that the timeout in {@link JobMasterGateway#triggerSavepoint(String, boolean,
* SavepointFormatType, Time)} is respected.
*/
@Test
public void testTriggerSavepointTimeout() throws Exception {
final TestingSchedulerNG testingSchedulerNG = TestingSchedulerNG.newBuilder().setTriggerSavepointFunction((ignoredA, ignoredB, formatType) -> new CompletableFuture<>()).build();
final JobMaster jobMaster = new JobMasterBuilder(jobGraph, rpcService).withFatalErrorHandler(testingFatalErrorHandler).withSlotPoolServiceSchedulerFactory(DefaultSlotPoolServiceSchedulerFactory.create(TestingSlotPoolServiceBuilder.newBuilder(), new TestingSchedulerNGFactory(testingSchedulerNG))).createJobMaster();
try {
jobMaster.start();
final JobMasterGateway jobMasterGateway = jobMaster.getSelfGateway(JobMasterGateway.class);
final CompletableFuture<String> savepointFutureLowTimeout = jobMasterGateway.triggerSavepoint("/tmp", false, SavepointFormatType.CANONICAL, Time.milliseconds(1));
final CompletableFuture<String> savepointFutureHighTimeout = jobMasterGateway.triggerSavepoint("/tmp", false, SavepointFormatType.CANONICAL, RpcUtils.INF_TIMEOUT);
try {
savepointFutureLowTimeout.get(testingTimeout.getSize(), testingTimeout.getUnit());
fail();
} catch (final ExecutionException e) {
final Throwable cause = ExceptionUtils.stripExecutionException(e);
assertThat(cause, instanceOf(TimeoutException.class));
}
assertThat(savepointFutureHighTimeout.isDone(), is(equalTo(false)));
} finally {
RpcUtils.terminateRpcEndpoint(jobMaster, testingTimeout);
}
}
use of org.apache.flink.core.execution.SavepointFormatType 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();
});
}
use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class CliFrontend method stop.
/**
* Executes the STOP action.
*
* @param args Command line arguments for the stop action.
*/
protected void stop(String[] args) throws Exception {
LOG.info("Running 'stop-with-savepoint' command.");
final Options commandOptions = CliFrontendParser.getStopCommandOptions();
final CommandLine commandLine = getCommandLine(commandOptions, args, false);
final StopOptions stopOptions = new StopOptions(commandLine);
if (stopOptions.isPrintHelp()) {
CliFrontendParser.printHelpForStop(customCommandLines);
return;
}
final String[] cleanedArgs = stopOptions.getArgs();
final String targetDirectory = stopOptions.hasSavepointFlag() && cleanedArgs.length > 0 ? stopOptions.getTargetDirectory() : // the default savepoint location is going to be used in this case.
null;
final JobID jobId = cleanedArgs.length != 0 ? parseJobId(cleanedArgs[0]) : parseJobId(stopOptions.getTargetDirectory());
final boolean advanceToEndOfEventTime = stopOptions.shouldAdvanceToEndOfEventTime();
final SavepointFormatType formatType = stopOptions.getFormatType();
logAndSysout((advanceToEndOfEventTime ? "Draining job " : "Suspending job ") + "\"" + jobId + "\" with a " + formatType + " savepoint.");
final CustomCommandLine activeCommandLine = validateAndGetActiveCommandLine(commandLine);
runClusterAction(activeCommandLine, commandLine, clusterClient -> {
final String savepointPath;
try {
savepointPath = clusterClient.stopWithSavepoint(jobId, advanceToEndOfEventTime, targetDirectory, formatType).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new FlinkException("Could not stop with a savepoint job \"" + jobId + "\".", e);
}
logAndSysout("Savepoint completed. Path: " + savepointPath);
});
}
Aggregations