use of org.apache.flink.core.execution.SavepointFormatType 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.core.execution.SavepointFormatType in project flink by apache.
the class CliFrontend method cancel.
/**
* Executes the CANCEL action.
*
* @param args Command line arguments for the cancel action.
*/
protected void cancel(String[] args) throws Exception {
LOG.info("Running 'cancel' command.");
final Options commandOptions = CliFrontendParser.getCancelCommandOptions();
final CommandLine commandLine = getCommandLine(commandOptions, args, false);
CancelOptions cancelOptions = new CancelOptions(commandLine);
// evaluate help flag
if (cancelOptions.isPrintHelp()) {
CliFrontendParser.printHelpForCancel(customCommandLines);
return;
}
final CustomCommandLine activeCommandLine = validateAndGetActiveCommandLine(commandLine);
final String[] cleanedArgs = cancelOptions.getArgs();
if (cancelOptions.isWithSavepoint()) {
logAndSysout("DEPRECATION WARNING: Cancelling a job with savepoint is deprecated. Use \"stop\" instead.");
final JobID jobId;
final String targetDirectory;
if (cleanedArgs.length > 0) {
jobId = parseJobId(cleanedArgs[0]);
targetDirectory = cancelOptions.getSavepointTargetDirectory();
} else {
jobId = parseJobId(cancelOptions.getSavepointTargetDirectory());
targetDirectory = null;
}
final SavepointFormatType formatType = cancelOptions.getFormatType();
if (targetDirectory == null) {
logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to default savepoint directory.");
} else {
logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to " + targetDirectory + '.');
}
runClusterAction(activeCommandLine, commandLine, clusterClient -> {
final String savepointPath;
try {
savepointPath = clusterClient.cancelWithSavepoint(jobId, targetDirectory, formatType).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new FlinkException("Could not cancel job " + jobId + '.', e);
}
logAndSysout("Cancelled job " + jobId + ". Savepoint stored in " + savepointPath + '.');
});
} else {
final JobID jobId;
if (cleanedArgs.length > 0) {
jobId = parseJobId(cleanedArgs[0]);
} else {
throw new CliArgsException("Missing JobID. Specify a JobID to cancel a job.");
}
logAndSysout("Cancelling job " + jobId + '.');
runClusterAction(activeCommandLine, commandLine, clusterClient -> {
try {
clusterClient.cancel(jobId).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new FlinkException("Could not cancel job " + jobId + '.', e);
}
});
logAndSysout("Cancelled job " + jobId + '.');
}
}
use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class EventSerializer method decodeSavepointType.
private static SavepointType decodeSavepointType(byte checkpointTypeCode, ByteBuffer buffer) throws IOException {
final byte formatTypeCode = buffer.get();
final SavepointFormatType formatType;
if (formatTypeCode == SAVEPOINT_FORMAT_CANONICAL) {
formatType = SavepointFormatType.CANONICAL;
} else if (formatTypeCode == SAVEPOINT_FORMAT_NATIVE) {
formatType = SavepointFormatType.NATIVE;
} else {
throw new IOException("Unknown savepoint format type code: " + formatTypeCode);
}
if (checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT) {
return SavepointType.savepoint(formatType);
} else if (checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT_SUSPEND) {
return SavepointType.suspend(formatType);
} else if (checkpointTypeCode == CHECKPOINT_TYPE_SAVEPOINT_TERMINATE) {
return SavepointType.terminate(formatType);
} else {
throw new IOException("Unknown savepoint type code: " + checkpointTypeCode);
}
}
use of org.apache.flink.core.execution.SavepointFormatType in project flink by apache.
the class StopWithSavepointHandlersTest method testTriggerSavepointNoDirectory.
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setStopWithSavepointFunction((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 [targetDirectory] 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 StopWithSavepointHandlersTest method testTriggerSavepointWithDefaultDirectory.
@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setStopWithSavepointFunction((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.StopWithSavepointHandler savepointTriggerHandler = savepointHandlers.new StopWithSavepointHandler(leaderRetriever, TIMEOUT, Collections.emptyMap());
savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
Aggregations