Search in sources :

Example 6 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime 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 7 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hive by apache.

the class TestServiceDiscovery method setup.

@BeforeClass
public static void setup() throws Exception {
    server = new TestingServer();
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
    client.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) BeforeClass(org.junit.BeforeClass)

Example 8 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hive by apache.

the class SecretManager method checkRootAcls.

private static void checkRootAcls(Configuration conf, String path, String user) {
    int stime = conf.getInt(ZK_DTSM_ZK_SESSION_TIMEOUT, ZK_DTSM_ZK_SESSION_TIMEOUT_DEFAULT), ctime = conf.getInt(ZK_DTSM_ZK_CONNECTION_TIMEOUT, ZK_DTSM_ZK_CONNECTION_TIMEOUT_DEFAULT);
    CuratorFramework zkClient = CuratorFrameworkFactory.builder().namespace(null).retryPolicy(new RetryOneTime(10)).sessionTimeoutMs(stime).connectionTimeoutMs(ctime).ensembleProvider(new FixedEnsembleProvider(conf.get(ZK_DTSM_ZK_CONNECTION_STRING))).build();
    // Hardcoded from a private field in ZKDelegationTokenSecretManager.
    // We need to check the path under what it sets for namespace, since the namespace is
    // created with world ACLs.
    String nsPath = "/" + path + "/ZKDTSMRoot";
    Id currentUser = new Id("sasl", user);
    try {
        zkClient.start();
        List<String> children = zkClient.getChildren().forPath(nsPath);
        for (String child : children) {
            String childPath = nsPath + "/" + child;
            checkAcls(zkClient, currentUser, childPath);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        zkClient.close();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Id(org.apache.zookeeper.data.Id) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) IOException(java.io.IOException)

Example 9 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project elastic-job by dangdangdotcom.

the class ZookeeperRegistryCenterForAuthTest method assertInitWithDigestSuccess.

@Test
public void assertInitWithDigestSuccess() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(EmbedTestingServer.getConnectionString()).retryPolicy(new RetryOneTime(2000)).authorization("digest", "digest:password".getBytes()).build();
    client.start();
    client.blockUntilConnected();
    assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"), is("deepNested".getBytes()));
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Test(org.junit.Test)

Example 10 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project elastic-job by dangdangdotcom.

the class ZookeeperRegistryCenterForAuthTest method assertInitWithDigestFailure.

@Test(expected = NoAuthException.class)
public void assertInitWithDigestFailure() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Test(org.junit.Test)

Aggregations

RetryOneTime (org.apache.curator.retry.RetryOneTime)25 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 Test (org.junit.Test)10 Timing (org.apache.curator.test.Timing)8 TestingServer (org.apache.curator.test.TestingServer)6 Stat (org.apache.zookeeper.data.Stat)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 TestingCluster (org.apache.curator.test.TestingCluster)2 ElectionCandidate (com.dangdang.ddframe.job.reg.base.ElectionCandidate)1 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 CuratorZKClientBridge (com.netflix.curator.x.zkclientbridge.CuratorZKClientBridge)1 PotentiallyGzippedCompressionProvider (io.druid.curator.PotentiallyGzippedCompressionProvider)1 Random (java.util.Random)1 NodeState (org.apache.camel.component.zookeepermaster.group.NodeState)1