Search in sources :

Example 6 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project elastic-job by dangdangdotcom.

the class ZookeeperRegistryCenterModifyTest method assertPersistSequential.

@Test
public void assertPersistSequential() throws Exception {
    assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
    assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    List<String> actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertThat(actual.size(), is(2));
    for (String each : actual) {
        assertThat(each, startsWith("test_sequential"));
        assertThat(zkRegCenter.get("/sequential/" + each), startsWith("test_value"));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Test(org.junit.Test)

Example 7 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project storm by apache.

the class Zookeeper method zkLeaderElectorImpl.

protected ILeaderElector zkLeaderElectorImpl(Map conf, BlobStore blobStore) throws UnknownHostException {
    List<String> servers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
    Object port = conf.get(Config.STORM_ZOOKEEPER_PORT);
    CuratorFramework zk = mkClientImpl(conf, servers, port, "", conf);
    String leaderLockPath = conf.get(Config.STORM_ZOOKEEPER_ROOT) + "/leader-lock";
    String id = NimbusInfo.fromConf(conf).toHostPortString();
    AtomicReference<LeaderLatch> leaderLatchAtomicReference = new AtomicReference<>(new LeaderLatch(zk, leaderLockPath, id));
    AtomicReference<LeaderLatchListener> leaderLatchListenerAtomicReference = new AtomicReference<>(leaderLatchListenerImpl(conf, zk, blobStore, leaderLatchAtomicReference.get()));
    return new LeaderElectorImp(conf, servers, zk, leaderLockPath, id, leaderLatchAtomicReference, leaderLatchListenerAtomicReference, blobStore);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) LeaderLatchListener(org.apache.curator.framework.recipes.leader.LeaderLatchListener)

Example 8 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project storm by apache.

the class Utils method newCuratorStarted.

public static CuratorFramework newCuratorStarted(Map conf, List<String> servers, Object port, ZookeeperAuthInfo auth) {
    CuratorFramework ret = newCurator(conf, servers, port, auth);
    LOG.info("Starting Utils Curator (2)...");
    ret.start();
    return ret;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 9 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project storm by apache.

the class KafkaOffsetLagUtil method getOldConsumerOffsetsFromZk.

private static Map<String, Map<Integer, Long>> getOldConsumerOffsetsFromZk(Map<String, List<Integer>> topicPartitions, OldKafkaSpoutOffsetQuery oldKafkaSpoutOffsetQuery) throws Exception {
    Map<String, Map<Integer, Long>> result = new HashMap<>();
    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(oldKafkaSpoutOffsetQuery.getZkServers(), 20000, 15000, new RetryOneTime(1000));
    curatorFramework.start();
    String partitionPrefix = "partition_";
    String zkPath = oldKafkaSpoutOffsetQuery.getZkPath();
    if (zkPath.endsWith("/")) {
        zkPath = zkPath.substring(0, zkPath.length() - 1);
    }
    if (curatorFramework.checkExists().forPath(zkPath) == null) {
        throw new IllegalArgumentException(OPTION_ZK_COMMITTED_NODE_LONG + " '" + zkPath + "' dose not exists.");
    }
    byte[] zkData;
    try {
        if (topicPartitions != null) {
            for (Map.Entry<String, List<Integer>> topicEntry : topicPartitions.entrySet()) {
                Map<Integer, Long> partitionOffsets = new HashMap<>();
                for (Integer partition : topicEntry.getValue()) {
                    String path = zkPath + "/" + (oldKafkaSpoutOffsetQuery.isWildCardTopic() ? topicEntry.getKey() + "/" : "") + partitionPrefix + partition;
                    if (curatorFramework.checkExists().forPath(path) != null) {
                        zkData = curatorFramework.getData().forPath(path);
                        Map<Object, Object> offsetData = (Map<Object, Object>) JSONValue.parseWithException(new String(zkData, "UTF-8"));
                        partitionOffsets.put(partition, (Long) offsetData.get("offset"));
                    }
                }
                result.put(topicEntry.getKey(), partitionOffsets);
            }
        }
    } finally {
        if (curatorFramework != null) {
            curatorFramework.close();
        }
    }
    return result;
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) HashMap(java.util.HashMap) CuratorFramework(org.apache.curator.framework.CuratorFramework) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project storm by apache.

the class BlobStoreUtils method createZKClient.

public static CuratorFramework createZKClient(Map<String, Object> conf) {
    @SuppressWarnings("unchecked") List<String> zkServers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
    Object port = conf.get(Config.STORM_ZOOKEEPER_PORT);
    ZookeeperAuthInfo zkAuthInfo = new ZookeeperAuthInfo(conf);
    CuratorFramework zkClient = Utils.newCurator(conf, zkServers, port, (String) conf.get(Config.STORM_ZOOKEEPER_ROOT), zkAuthInfo);
    zkClient.start();
    return zkClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ZookeeperAuthInfo(org.apache.storm.utils.ZookeeperAuthInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)924 Test (org.testng.annotations.Test)290 RetryOneTime (org.apache.curator.retry.RetryOneTime)271 Test (org.junit.Test)199 Timing (org.apache.curator.test.Timing)147 CountDownLatch (java.util.concurrent.CountDownLatch)124 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)114 KeeperException (org.apache.zookeeper.KeeperException)93 IOException (java.io.IOException)79 ConnectionState (org.apache.curator.framework.state.ConnectionState)71 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)58 ExecutorService (java.util.concurrent.ExecutorService)55 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)53 ArrayList (java.util.ArrayList)51 RetryNTimes (org.apache.curator.retry.RetryNTimes)51 RetryPolicy (org.apache.curator.RetryPolicy)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)38 Cleanup (lombok.Cleanup)37 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)37 Stat (org.apache.zookeeper.data.Stat)36