use of org.apache.curator.retry.RetryNTimes in project cas by apereo.
the class ZooKeeperCloudConfigBootstrapConfigurationTests method setup.
@BeforeAll
public static void setup() throws Exception {
FunctionUtils.doAndRetry(List.of(KeeperException.ConnectionLossException.class), context -> {
val curator = CuratorFrameworkFactory.newClient("localhost:2181", 5000, 5000, new RetryNTimes(2, 100));
curator.start();
val path = "/config/cas/cas/server/name";
val zk = curator.getZookeeperClient().getZooKeeper();
if (zk.exists(path, false) != null) {
curator.delete().forPath(path);
}
curator.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(path, "apereocas".getBytes(StandardCharsets.UTF_8));
curator.close();
return null;
});
}
use of org.apache.curator.retry.RetryNTimes in project ignite by apache.
the class ZookeeperDiscoverySpiTestBase method waitForZkClusterReady.
/**
* Wait for Zookeeper testing cluster ready for communications.
*
* @param zkCluster Zk cluster.
*/
static void waitForZkClusterReady(TestingCluster zkCluster) throws InterruptedException {
try (CuratorFramework curator = CuratorFrameworkFactory.newClient(zkCluster.getConnectString(), new RetryNTimes(10, 1_000))) {
curator.start();
assertTrue("Failed to wait for Zookeeper testing cluster ready.", curator.blockUntilConnected(30, SECONDS));
}
}
use of org.apache.curator.retry.RetryNTimes in project Saturn by vipshop.
the class NestedZkUtils method createClient.
public CuratorFramework createClient(String namespace) throws InterruptedException {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
CuratorFramework curatorFramework = // long
builder.connectString("127.0.0.1:" + port).sessionTimeoutMs(600 * 1000).retryPolicy(new RetryNTimes(3, 1000)).namespace(namespace).build();
curatorFramework.start();
curatorFramework.blockUntilConnected();
return curatorFramework;
}
use of org.apache.curator.retry.RetryNTimes in project BRFS by zhangnianli.
the class InitTaskManager method createMetaTaskManager.
/**
* 概述:创建集群任务管理服务
* @param manager
* @param zkPaths
* @param config
* @throws Exception
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void createMetaTaskManager(SchedulerManagerInterface manager, ZookeeperPaths zkPaths, ResourceTaskConfig config, String serverId) throws Exception {
MetaTaskLeaderManager leader = new MetaTaskLeaderManager(manager, config);
RetryPolicy retryPolicy = new RetryNTimes(3, 1000);
String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
CuratorFramework client = CuratorFrameworkFactory.newClient(zkAddresses, retryPolicy);
client.start();
leaderLatch = new LeaderLatch(client, zkPaths.getBaseLocksPath() + "/TaskManager/MetaTaskLeaderLock", serverId);
leaderLatch.addListener(leader);
leaderLatch.start();
}
use of org.apache.curator.retry.RetryNTimes in project camel by apache.
the class GroupTest method testOrder.
@Test
public void testOrder() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
final String path = "/singletons/test/Order" + System.currentTimeMillis();
ArrayList<ZooKeeperGroup> members = new ArrayList<ZooKeeperGroup>();
for (int i = 0; i < 4; i++) {
ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, path, NodeState.class);
group.add(listener);
members.add(group);
}
for (ZooKeeperGroup group : members) {
assertFalse(group.isConnected());
assertFalse(group.isMaster());
}
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// first to start should be master if members are ordered...
int i = 0;
for (ZooKeeperGroup group : members) {
group.start();
group.update(new NodeState("foo" + i));
i++;
// wait for registration
while (group.getId() == null) {
TimeUnit.MILLISECONDS.sleep(100);
}
}
boolean firsStartedIsMaster = members.get(0).isMaster();
for (ZooKeeperGroup group : members) {
group.close();
}
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
assertTrue("first started is master", firsStartedIsMaster);
}
Aggregations