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;
}
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();
}
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();
}
}
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()));
}
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");
}
Aggregations