Search in sources :

Example 6 with SavepointFormatType

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));
    }
}
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 7 with SavepointFormatType

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));
}
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)

Example 8 with SavepointFormatType

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);
    }
}
Also used : TaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway) DefaultSchedulerFactory(org.apache.flink.runtime.scheduler.DefaultSchedulerFactory) TestingTaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway) Arrays(java.util.Arrays) Tuple3(org.apache.flink.api.java.tuple.Tuple3) SlotPoolService(org.apache.flink.runtime.jobmaster.slotpool.SlotPoolService) JobMasterBuilder(org.apache.flink.runtime.jobmaster.utils.JobMasterBuilder) RestartStrategyOptions(org.apache.flink.configuration.RestartStrategyOptions) PerJobCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.PerJobCheckpointRecoveryFactory) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) SettableLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) Duration(java.time.Duration) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) ClassRule(org.junit.ClassRule) SimpleSlotContext(org.apache.flink.runtime.instance.SimpleSlotContext) SlotPoolServiceFactory(org.apache.flink.runtime.jobmaster.slotpool.SlotPoolServiceFactory) AfterClass(org.junit.AfterClass) BlockingQueue(java.util.concurrent.BlockingQueue) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) Category(org.junit.experimental.categories.Category) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TimeUtils(org.apache.flink.util.TimeUtils) Matchers.is(org.hamcrest.Matchers.is) Time(org.apache.flink.api.common.time.Time) InputSplitSource(org.apache.flink.core.io.InputSplitSource) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway) FlinkException(org.apache.flink.util.FlinkException) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) AccessExecution(org.apache.flink.runtime.executiongraph.AccessExecution) JobStatus(org.apache.flink.api.common.JobStatus) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) DefaultInputSplitAssigner(org.apache.flink.api.common.io.DefaultInputSplitAssigner) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DistributionPattern(org.apache.flink.runtime.jobgraph.DistributionPattern) Nullable(javax.annotation.Nullable) CheckpointProperties(org.apache.flink.runtime.checkpoint.CheckpointProperties) Before(org.junit.Before) InputSplitAssigner(org.apache.flink.core.io.InputSplitAssigner) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) LocalUnresolvedTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalUnresolvedTaskManagerLocation) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) InputSplit(org.apache.flink.core.io.InputSplit) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) CheckpointsCleaner(org.apache.flink.runtime.checkpoint.CheckpointsCleaner) Test(org.junit.Test) IOException(java.io.IOException) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) JobID(org.apache.flink.api.common.JobID) StandaloneCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.StandaloneCheckpointRecoveryFactory) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) UnresolvedTaskManagerLocation(org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation) ArrayDeque(java.util.ArrayDeque) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) CheckpointRetentionPolicy(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy) Deadline(org.apache.flink.api.common.time.Deadline) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) RegistrationResponse(org.apache.flink.runtime.registration.RegistrationResponse) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) BiFunction(java.util.function.BiFunction) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TaskExecutorToJobManagerHeartbeatPayload(org.apache.flink.runtime.taskexecutor.TaskExecutorToJobManagerHeartbeatPayload) AggregateFunction(org.apache.flink.api.common.functions.AggregateFunction) InstantiationUtil(org.apache.flink.util.InstantiationUtil) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestingSchedulerNGFactory(org.apache.flink.runtime.scheduler.TestingSchedulerNGFactory) Assert.fail(org.junit.Assert.fail) BlobServerOptions(org.apache.flink.configuration.BlobServerOptions) CompletedCheckpointStorageLocation(org.apache.flink.runtime.state.CompletedCheckpointStorageLocation) Collection(java.util.Collection) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) ResourceManagerId(org.apache.flink.runtime.resourcemanager.ResourceManagerId) UUID(java.util.UUID) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) Collectors(java.util.stream.Collectors) SlotInfoWithUtilization(org.apache.flink.runtime.jobmaster.slotpool.SlotInfoWithUtilization) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) Objects(java.util.Objects) TestingUtils(org.apache.flink.testutils.TestingUtils) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Optional(java.util.Optional) Queue(java.util.Queue) Matchers.anyOf(org.hamcrest.Matchers.anyOf) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) IntStream(java.util.stream.IntStream) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) BeforeClass(org.junit.BeforeClass) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) Function(java.util.function.Function) TaskDeploymentDescriptor(org.apache.flink.runtime.deployment.TaskDeploymentDescriptor) FailoverStrategyFactoryLoader(org.apache.flink.runtime.executiongraph.failover.flip1.FailoverStrategyFactoryLoader) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) TestingJobMasterPartitionTracker(org.apache.flink.runtime.io.network.partition.TestingJobMasterPartitionTracker) FailsWithAdaptiveScheduler(org.apache.flink.testutils.junit.FailsWithAdaptiveScheduler) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestingSlotPoolServiceBuilder(org.apache.flink.runtime.jobmaster.slotpool.TestingSlotPoolServiceBuilder) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Nonnull(javax.annotation.Nonnull) StandaloneCompletedCheckpointStore(org.apache.flink.runtime.checkpoint.StandaloneCompletedCheckpointStore) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) SlotPool(org.apache.flink.runtime.jobmaster.slotpool.SlotPool) Matchers.empty(org.hamcrest.Matchers.empty) JobGraphBuilder(org.apache.flink.runtime.jobgraph.JobGraphBuilder) TestingSchedulerNG(org.apache.flink.runtime.scheduler.TestingSchedulerNG) Configuration(org.apache.flink.configuration.Configuration) TestingHeartbeatServices(org.apache.flink.runtime.heartbeat.TestingHeartbeatServices) Matchers(org.hamcrest.Matchers) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) TimeUnit(java.util.concurrent.TimeUnit) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) ClosureCleaner(org.apache.flink.api.java.ClosureCleaner) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) CommonTestUtils(org.apache.flink.runtime.testutils.CommonTestUtils) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RecipientUnreachableException(org.apache.flink.runtime.rpc.exceptions.RecipientUnreachableException) NoOpInvokable(org.apache.flink.runtime.testtasks.NoOpInvokable) CompletableFuture(java.util.concurrent.CompletableFuture) TestingSchedulerNGFactory(org.apache.flink.runtime.scheduler.TestingSchedulerNGFactory) ExecutionException(java.util.concurrent.ExecutionException) JobMasterBuilder(org.apache.flink.runtime.jobmaster.utils.JobMasterBuilder) TestingSchedulerNG(org.apache.flink.runtime.scheduler.TestingSchedulerNG) Test(org.junit.Test)

Example 9 with SavepointFormatType

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

Example 10 with SavepointFormatType

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);
    });
}
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)

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