Search in sources :

Example 1 with ZooKeeperStateHandleStore

use of org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore in project flink by apache.

the class ZooKeeperCompletedCheckpointStoreTest method testRecoverFailsIfDownloadFails.

@Test
public void testRecoverFailsIfDownloadFails() {
    final Configuration configuration = new Configuration();
    configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zooKeeperResource.getConnectString());
    final List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> checkpointsInZk = new ArrayList<>();
    final ZooKeeperStateHandleStore<CompletedCheckpoint> checkpointsInZooKeeper = new ZooKeeperStateHandleStore<CompletedCheckpoint>(ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE).asCuratorFramework(), new TestingRetrievableStateStorageHelper<>()) {

        @Override
        public List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> getAllAndLock() {
            return checkpointsInZk;
        }
    };
    checkpointsInZk.add(createHandle(1, id -> {
        throw new ExpectedTestException();
    }));
    final Exception exception = assertThrows(Exception.class, () -> DefaultCompletedCheckpointStoreUtils.retrieveCompletedCheckpoints(checkpointsInZooKeeper, zooKeeperCheckpointStoreUtil));
    assertThat(exception, FlinkMatchers.containsCause(ExpectedTestException.class));
}
Also used : ZooKeeperUtils(org.apache.flink.runtime.util.ZooKeeperUtils) Tuple2(org.apache.flink.api.java.tuple.Tuple2) CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) JobStatus(org.apache.flink.api.common.JobStatus) Function(java.util.function.Function) NEVER_RETAIN_AFTER_TERMINATION(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION) ArrayList(java.util.ArrayList) TestLogger(org.apache.flink.util.TestLogger) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ClassRule(org.junit.ClassRule) Nonnull(javax.annotation.Nonnull) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) Collections.emptyList(java.util.Collections.emptyList) Configuration(org.apache.flink.configuration.Configuration) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Executors(org.apache.flink.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) JobID(org.apache.flink.api.common.JobID) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) NoOpFatalErrorHandler(org.apache.flink.runtime.rest.util.NoOpFatalErrorHandler) ZooKeeperResource(org.apache.flink.runtime.zookeeper.ZooKeeperResource) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) Assert.assertEquals(org.junit.Assert.assertEquals) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) Configuration(org.apache.flink.configuration.Configuration) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) ArrayList(java.util.ArrayList) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) Test(org.junit.Test)

Example 2 with ZooKeeperStateHandleStore

use of org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore in project flink by apache.

the class ZooKeeperUtils method createJobGraphs.

/**
 * Creates a {@link DefaultJobGraphStore} instance with {@link ZooKeeperStateHandleStore},
 * {@link ZooKeeperJobGraphStoreWatcher} and {@link ZooKeeperJobGraphStoreUtil}.
 *
 * @param client The {@link CuratorFramework} ZooKeeper client to use
 * @param configuration {@link Configuration} object
 * @return {@link DefaultJobGraphStore} instance
 * @throws Exception if the submitted job graph store cannot be created
 */
public static JobGraphStore createJobGraphs(CuratorFramework client, Configuration configuration) throws Exception {
    checkNotNull(configuration, "Configuration");
    RetrievableStateStorageHelper<JobGraph> stateStorage = createFileSystemStateStorage(configuration, HA_STORAGE_SUBMITTED_JOBGRAPH_PREFIX);
    // ZooKeeper submitted jobs root dir
    String zooKeeperJobsPath = configuration.getString(HighAvailabilityOptions.HA_ZOOKEEPER_JOBGRAPHS_PATH);
    // Ensure that the job graphs path exists
    client.newNamespaceAwareEnsurePath(zooKeeperJobsPath).ensure(client.getZookeeperClient());
    // All operations will have the path as root
    CuratorFramework facade = client.usingNamespace(client.getNamespace() + zooKeeperJobsPath);
    final String zooKeeperFullJobsPath = client.getNamespace() + zooKeeperJobsPath;
    final ZooKeeperStateHandleStore<JobGraph> zooKeeperStateHandleStore = new ZooKeeperStateHandleStore<>(facade, stateStorage);
    final PathChildrenCache pathCache = new PathChildrenCache(facade, "/", false);
    return new DefaultJobGraphStore<>(zooKeeperStateHandleStore, new ZooKeeperJobGraphStoreWatcher(pathCache), ZooKeeperJobGraphStoreUtil.INSTANCE);
}
Also used : ZooKeeperJobGraphStoreWatcher(org.apache.flink.runtime.jobmanager.ZooKeeperJobGraphStoreWatcher) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) PathChildrenCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache) DefaultJobGraphStore(org.apache.flink.runtime.jobmanager.DefaultJobGraphStore)

Example 3 with ZooKeeperStateHandleStore

use of org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore in project flink by apache.

the class ZooKeeperJobGraphsStoreITCase method createZooKeeperJobGraphStore.

@Nonnull
private JobGraphStore createZooKeeperJobGraphStore(String fullPath) throws Exception {
    final CuratorFramework client = ZooKeeper.getClient();
    // Ensure that the job graphs path exists
    client.newNamespaceAwareEnsurePath(fullPath).ensure(client.getZookeeperClient());
    // All operations will have the path as root
    CuratorFramework facade = client.usingNamespace(client.getNamespace() + fullPath);
    final ZooKeeperStateHandleStore<JobGraph> zooKeeperStateHandleStore = new ZooKeeperStateHandleStore<>(facade, localStateStorage);
    return new DefaultJobGraphStore<>(zooKeeperStateHandleStore, new ZooKeeperJobGraphStoreWatcher(new PathChildrenCache(facade, "/", false)), ZooKeeperJobGraphStoreUtil.INSTANCE);
}
Also used : CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) PathChildrenCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache) Nonnull(javax.annotation.Nonnull)

Aggregations

ZooKeeperStateHandleStore (org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore)3 CuratorFramework (org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework)3 Nonnull (javax.annotation.Nonnull)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2 PathChildrenCache (org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Function (java.util.function.Function)1 JobID (org.apache.flink.api.common.JobID)1 JobStatus (org.apache.flink.api.common.JobStatus)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Configuration (org.apache.flink.configuration.Configuration)1 HighAvailabilityOptions (org.apache.flink.configuration.HighAvailabilityOptions)1 FlinkMatchers (org.apache.flink.core.testutils.FlinkMatchers)1 NEVER_RETAIN_AFTER_TERMINATION (org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION)1 CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)1 DefaultJobGraphStore (org.apache.flink.runtime.jobmanager.DefaultJobGraphStore)1