Search in sources :

Example 1 with SavepointFormatType

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();
    });
}
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) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) TriggerResponse(org.apache.flink.runtime.rest.handler.async.TriggerResponse) SavepointTriggerRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerRequestBody) SavepointTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerHeaders) StopWithSavepointTriggerHeaders(org.apache.flink.runtime.rest.messages.job.savepoints.stop.StopWithSavepointTriggerHeaders)

Example 2 with SavepointFormatType

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 + '.');
    }
}
Also used : JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) Options(org.apache.commons.cli.Options) RestOptions(org.apache.flink.configuration.RestOptions) CoreOptions(org.apache.flink.configuration.CoreOptions) CommandLine(org.apache.commons.cli.CommandLine) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) JobID(org.apache.flink.api.common.JobID) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) FileNotFoundException(java.io.FileNotFoundException) FlinkException(org.apache.flink.util.FlinkException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) FlinkException(org.apache.flink.util.FlinkException)

Example 3 with SavepointFormatType

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);
    }
}
Also used : IOException(java.io.IOException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType)

Example 4 with SavepointFormatType

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));
    }
}
Also used : AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Example 5 with SavepointFormatType

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));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Aggregations

SavepointFormatType (org.apache.flink.core.execution.SavepointFormatType)11 JobID (org.apache.flink.api.common.JobID)6 IOException (java.io.IOException)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 FlinkException (org.apache.flink.util.FlinkException)5 Test (org.junit.Test)5 List (java.util.List)4 AsynchronousJobOperationKey (org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey)4 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeUnit (java.util.concurrent.TimeUnit)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BiConsumer (java.util.function.BiConsumer)3 Predicate (java.util.function.Predicate)3 Supplier (java.util.function.Supplier)3 Collectors (java.util.stream.Collectors)3