use of org.apache.curator.retry.RetryOneTime in project storm by apache.
the class KafkaOffsetLagUtil method getLeadersAndTopicPartitions.
private static Map<String, List<TopicPartition>> getLeadersAndTopicPartitions(OldKafkaSpoutOffsetQuery oldKafkaSpoutOffsetQuery) throws Exception {
Map<String, List<TopicPartition>> result = new HashMap<>();
// this means that kafka spout was configured with StaticHosts hosts (leader for partition)
if (oldKafkaSpoutOffsetQuery.getPartitions() != null) {
String[] partitions = oldKafkaSpoutOffsetQuery.getPartitions().split(",");
String[] leaders = oldKafkaSpoutOffsetQuery.getLeaders().split(",");
for (int i = 0; i < leaders.length; ++i) {
if (!result.containsKey(leaders[i])) {
result.put(leaders[i], new ArrayList<TopicPartition>());
}
result.get(leaders[i]).add(new TopicPartition(oldKafkaSpoutOffsetQuery.getTopic(), Integer.parseInt(partitions[i])));
}
} else {
// else use zk nodes to figure out partitions and leaders for topics i.e. ZkHosts
CuratorFramework curatorFramework = null;
try {
String brokersZkNode = oldKafkaSpoutOffsetQuery.getBrokersZkPath();
if (!brokersZkNode.endsWith("/")) {
brokersZkNode += "/";
}
String topicsZkPath = brokersZkNode + "topics";
curatorFramework = CuratorFrameworkFactory.newClient(oldKafkaSpoutOffsetQuery.getZkServers(), 20000, 15000, new RetryOneTime(1000));
curatorFramework.start();
List<String> topics = new ArrayList<>();
if (oldKafkaSpoutOffsetQuery.isWildCardTopic()) {
List<String> children = curatorFramework.getChildren().forPath(topicsZkPath);
for (String child : children) {
if (child.matches(oldKafkaSpoutOffsetQuery.getTopic())) {
topics.add(child);
}
}
} else {
topics.add(oldKafkaSpoutOffsetQuery.getTopic());
}
for (String topic : topics) {
String partitionsPath = topicsZkPath + "/" + topic + "/partitions";
List<String> children = curatorFramework.getChildren().forPath(partitionsPath);
for (int i = 0; i < children.size(); ++i) {
byte[] leaderData = curatorFramework.getData().forPath(partitionsPath + "/" + i + "/state");
Map<Object, Object> value = (Map<Object, Object>) JSONValue.parseWithException(new String(leaderData, "UTF-8"));
Integer leader = ((Number) value.get("leader")).intValue();
byte[] brokerData = curatorFramework.getData().forPath(brokersZkNode + "ids/" + leader);
Map<Object, Object> broker = (Map<Object, Object>) JSONValue.parseWithException(new String(brokerData, "UTF-8"));
String host = (String) broker.get("host");
Integer port = ((Long) broker.get("port")).intValue();
String leaderBroker = host + ":" + port;
if (!result.containsKey(leaderBroker)) {
result.put(leaderBroker, new ArrayList<TopicPartition>());
}
result.get(leaderBroker).add(new TopicPartition(topic, i));
}
}
} finally {
if (curatorFramework != null) {
curatorFramework.close();
}
}
}
return result;
}
use of org.apache.curator.retry.RetryOneTime in project hive by apache.
the class TestSlotZnode method newCurator.
private CuratorFramework newCurator() throws IOException {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), 10000, 10000, new RetryOneTime(1));
client.start();
curatorInstances.add(client);
return client;
}
use of org.apache.curator.retry.RetryOneTime in project elastic-job by dangdangdotcom.
the class ZookeeperElectionServiceTest method assertContend.
@Test
public void assertContend() throws Exception {
ElectionCandidate anotherElectionCandidate = mock(ElectionCandidate.class);
CuratorFramework anotherClient = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
ZookeeperElectionService anotherService = new ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH, anotherElectionCandidate);
anotherClient.start();
anotherClient.blockUntilConnected();
anotherService.start();
KillSession.kill(client.getZookeeperClient().getZooKeeper(), EmbedTestingServer.getConnectionString());
service.stop();
verify(anotherElectionCandidate).startLeadership();
}
use of org.apache.curator.retry.RetryOneTime in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenterModifyTest method assertPersistEphemeralSequential.
@Test
public void assertPersistEphemeralSequential() throws Exception {
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_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_ephemeral_sequential"));
}
zkRegCenter.close();
actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
assertTrue(actual.isEmpty());
zkRegCenter.init();
}
use of org.apache.curator.retry.RetryOneTime in project druid by druid-io.
the class OverlordTest method setupServerAndCurator.
private void setupServerAndCurator() throws Exception {
server = new TestingServer();
timing = new Timing();
curator = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).sessionTimeoutMs(timing.session()).connectionTimeoutMs(timing.connection()).retryPolicy(new RetryOneTime(1)).compressionProvider(new PotentiallyGzippedCompressionProvider(true)).build();
}
Aggregations