Search in sources :

Example 26 with RetryNTimes

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;
    });
}
Also used : lombok.val(lombok.val) RetryNTimes(org.apache.curator.retry.RetryNTimes) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 27 with RetryNTimes

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));
    }
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 28 with RetryNTimes

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;
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory)

Example 29 with RetryNTimes

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();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) RetryPolicy(org.apache.curator.RetryPolicy)

Example 30 with RetryNTimes

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);
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ArrayList(java.util.ArrayList) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Aggregations

RetryNTimes (org.apache.curator.retry.RetryNTimes)68 CuratorFramework (org.apache.curator.framework.CuratorFramework)51 Test (org.junit.Test)20 RetryPolicy (org.apache.curator.RetryPolicy)12 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)12 Test (org.testng.annotations.Test)11 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 IOException (java.io.IOException)6 ZooKeeperGroup (org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup)6 Before (org.junit.Before)6 ArrayList (java.util.ArrayList)5 TestingServer (org.apache.curator.test.TestingServer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ConnectionState (org.apache.curator.framework.state.ConnectionState)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)3 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)3