Search in sources :

Example 26 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class RestoreUpgradedJobITCase method runUpgradedJob.

private void runUpgradedJob(String snapshotPath) throws Exception {
    StreamExecutionEnvironment env;
    Configuration conf = new Configuration();
    conf.set(SavepointConfigOptions.SAVEPOINT_PATH, snapshotPath);
    env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
    env.setParallelism(PARALLELISM);
    env.addSource(new StringSource(allDataEmittedLatch)).map(new StringMap(MAP_1.id())).uid(MAP_1.name()).forward().map(new StringMap(MAP_2.id())).uid(MAP_2.name()).slotSharingGroup("anotherSharingGroup").keyBy((key) -> key).map(new StringMap(MAP_3.id())).uid(MAP_3.name()).map(new StringMap(-1)).uid("new_chained_map").rebalance().map(new StringMap(-2)).uid("new_map2").map(new StringMap(MAP_4.id())).uid(MAP_4.name()).rescale().map(new StringMap(MAP_5.id())).uid(MAP_5.name()).broadcast().map(new StringMap(MAP_6.id())).uid(MAP_6.name()).addSink(new StringSink(result)).setParallelism(1);
    JobClient jobClient = env.executeAsync("Total sum");
    waitForAllTaskRunning(CLUSTER.getMiniCluster(), jobClient.getJobID(), false);
    allDataEmittedLatch.get().await();
    // Using stopWithSavepoint to be sure that all values reached the sink.
    jobClient.stopWithSavepoint(true, temporaryFolder.getRoot().getAbsolutePath(), SavepointFormatType.CANONICAL).get();
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) MAP_1(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_1) RunWith(org.junit.runner.RunWith) MAP_2(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_2) MAP_3(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_3) SavepointConfigOptions(org.apache.flink.runtime.jobgraph.SavepointConfigOptions) MAP_4(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_4) MAP_5(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_5) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MAP_6(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_6) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) CANONICAL_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.CANONICAL_SAVEPOINT) CommonTestUtils.waitForAllTaskRunning(org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) TestLogger(org.apache.flink.util.TestLogger) ALIGNED_CHECKPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.ALIGNED_CHECKPOINT) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ClassRule(org.junit.ClassRule) SharedReference(org.apache.flink.testutils.junit.SharedReference) Parameterized(org.junit.runners.Parameterized) Types(org.apache.flink.api.common.typeinfo.Types) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) Iterator(java.util.Iterator) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) JobClient(org.apache.flink.core.execution.JobClient) ExecutionException(java.util.concurrent.ExecutionException) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) NATIVE_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.NATIVE_SAVEPOINT) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) TemporaryFolder(org.junit.rules.TemporaryFolder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobClient(org.apache.flink.core.execution.JobClient)

Example 27 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class UnalignedCheckpointFailureHandlingITCase method testCheckpointSuccessAfterFailure.

@Test
public void testCheckpointSuccessAfterFailure() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    TestCheckpointStorage storage = new TestCheckpointStorage(new JobManagerCheckpointStorage(), sharedObjects, temporaryFolder);
    configure(env, storage);
    buildGraph(env);
    JobClient jobClient = env.executeAsync();
    JobID jobID = jobClient.getJobID();
    MiniCluster miniCluster = miniClusterResource.getMiniCluster();
    waitForJobStatus(jobClient, singletonList(RUNNING), fromNow(Duration.ofSeconds(30)));
    waitForAllTaskRunning(miniCluster, jobID, false);
    triggerFailingCheckpoint(jobID, TestException.class, miniCluster);
    miniCluster.triggerCheckpoint(jobID).get();
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobManagerCheckpointStorage(org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 28 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class UnalignedCheckpointCompatibilityITCase method runAndTakeExternalCheckpoint.

private Tuple2<String, Map<String, Object>> runAndTakeExternalCheckpoint() throws Exception {
    JobClient jobClient = submitJobInitially(env(startAligned, Integer.MAX_VALUE));
    waitForAllTaskRunning(() -> miniCluster.getMiniCluster().getExecutionGraph(jobClient.getJobID()).get(), false);
    // wait for some backpressure from sink
    Thread.sleep(FIRST_RUN_BACKPRESSURE_MS);
    String checkpointPath = miniCluster.getMiniCluster().triggerCheckpoint(jobClient.getJobID()).get();
    cancelJob(jobClient);
    return new Tuple2<>(checkpointPath, emptyMap());
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobClient(org.apache.flink.core.execution.JobClient)

Example 29 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class ManualCheckpointITCase method testTriggeringWhenPeriodicEnabled.

@Test
public void testTriggeringWhenPeriodicEnabled() throws Exception {
    int parallelism = MINI_CLUSTER_RESOURCE.getNumberSlots();
    final int checkpointingInterval = 500;
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(parallelism);
    env.enableCheckpointing(checkpointingInterval);
    env.getCheckpointConfig().setCheckpointStorage(storageSupplier.apply(temporaryFolder.newFolder().toURI().toString()));
    env.fromSource(MockSource.continuous(parallelism).build(), WatermarkStrategy.noWatermarks(), "generator").keyBy(key -> key % parallelism).flatMap(new StatefulMapper()).addSink(new DiscardingSink<>());
    final JobClient jobClient = env.executeAsync();
    final JobID jobID = jobClient.getJobID();
    final MiniCluster miniCluster = MINI_CLUSTER_RESOURCE.getMiniCluster();
    CommonTestUtils.waitForJobStatus(jobClient, Collections.singletonList(JobStatus.RUNNING), Deadline.fromNow(Duration.ofSeconds(30)));
    CommonTestUtils.waitForAllTaskRunning(miniCluster, jobID, false);
    CommonTestUtils.waitUntilCondition(() -> queryCompletedCheckpoints(miniCluster, jobID) > 0L, Deadline.fromNow(Duration.ofSeconds(30)), checkpointingInterval / 2);
    final long numberOfPeriodicCheckpoints = queryCompletedCheckpoints(miniCluster, jobID);
    // wait for the checkpoint to be taken
    miniCluster.triggerCheckpoint(jobID).get();
    miniCluster.cancelJob(jobID).get();
    queryCompletedCheckpointsUntil(miniCluster, jobID, count -> count >= numberOfPeriodicCheckpoints + 1);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 30 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class ManualCheckpointITCase method testTriggeringWhenPeriodicDisabled.

@Test
public void testTriggeringWhenPeriodicDisabled() throws Exception {
    int parallelism = MINI_CLUSTER_RESOURCE.getNumberSlots();
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(parallelism);
    env.getCheckpointConfig().setCheckpointStorage(storageSupplier.apply(temporaryFolder.newFolder().toURI().toString()));
    env.fromSource(MockSource.continuous(parallelism).build(), WatermarkStrategy.noWatermarks(), "generator").keyBy(key -> key % parallelism).flatMap(new StatefulMapper()).addSink(new DiscardingSink<>());
    final JobClient jobClient = env.executeAsync();
    final JobID jobID = jobClient.getJobID();
    final MiniCluster miniCluster = MINI_CLUSTER_RESOURCE.getMiniCluster();
    CommonTestUtils.waitForJobStatus(jobClient, Collections.singletonList(JobStatus.RUNNING), Deadline.fromNow(Duration.ofSeconds(30)));
    CommonTestUtils.waitForAllTaskRunning(miniCluster, jobID, false);
    // wait for the checkpoint to be taken
    miniCluster.triggerCheckpoint(jobID).get();
    miniCluster.cancelJob(jobID).get();
    queryCompletedCheckpointsUntil(miniCluster, jobID, count -> count == 1);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

JobClient (org.apache.flink.core.execution.JobClient)70 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)36 Test (org.junit.Test)32 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)16 Configuration (org.apache.flink.configuration.Configuration)16 JobListener (org.apache.flink.core.execution.JobListener)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 JobID (org.apache.flink.api.common.JobID)10 ExecutionException (java.util.concurrent.ExecutionException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DEFAULT_COLLECT_DATA_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_COLLECT_DATA_TIMEOUT)8 DEFAULT_JOB_STATUS_CHANGE_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_JOB_STATUS_CHANGE_TIMEOUT)8 IOException (java.io.IOException)7 DisplayName (org.junit.jupiter.api.DisplayName)7 TestTemplate (org.junit.jupiter.api.TestTemplate)7 Iterator (java.util.Iterator)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)6 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)6