Search in sources :

Example 31 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project hadoop by apache.

the class TestZKRMStateStore method setupCuratorFramework.

public static CuratorFramework setupCuratorFramework(TestingServer curatorTestingServer) throws Exception {
    CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(curatorTestingServer.getConnectString()).retryPolicy(new RetryNTimes(100, 100)).build();
    curatorFramework.start();
    return curatorFramework;
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 32 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project heron by twitter.

the class ZkState method newCurator.

@SuppressWarnings("unchecked")
private CuratorFramework newCurator(Map<String, Object> stateConf) throws Exception {
    Integer port = (Integer) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_PORT);
    String serverPorts = "";
    for (String server : (List<String>) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS)) {
        serverPorts = serverPorts + server + ":" + port + ",";
    }
    return CuratorFrameworkFactory.newClient(serverPorts, Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)), Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT)), new RetryNTimes(Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)), Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) List(java.util.List)

Example 33 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project hadoop by apache.

the class ResourceManager method createAndStartCurator.

public CuratorFramework createAndStartCurator(Configuration conf) throws IOException {
    String zkHostPort = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
    if (zkHostPort == null) {
        throw new YarnRuntimeException(YarnConfiguration.RM_ZK_ADDRESS + " is not configured.");
    }
    int numRetries = conf.getInt(YarnConfiguration.RM_ZK_NUM_RETRIES, YarnConfiguration.DEFAULT_ZK_RM_NUM_RETRIES);
    int zkSessionTimeout = conf.getInt(YarnConfiguration.RM_ZK_TIMEOUT_MS, YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);
    int zkRetryInterval = conf.getInt(YarnConfiguration.RM_ZK_RETRY_INTERVAL_MS, YarnConfiguration.DEFAULT_RM_ZK_RETRY_INTERVAL_MS);
    // set up zk auths
    List<ZKUtil.ZKAuthInfo> zkAuths = RMZKUtils.getZKAuths(conf);
    List<AuthInfo> authInfos = new ArrayList<>();
    for (ZKUtil.ZKAuthInfo zkAuth : zkAuths) {
        authInfos.add(new AuthInfo(zkAuth.getScheme(), zkAuth.getAuth()));
    }
    if (HAUtil.isHAEnabled(conf) && HAUtil.getConfValueForRMInstance(YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, conf) == null) {
        String zkRootNodeUsername = HAUtil.getConfValueForRMInstance(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, conf);
        byte[] defaultFencingAuth = (zkRootNodeUsername + ":" + zkRootNodePassword).getBytes(Charset.forName("UTF-8"));
        authInfos.add(new AuthInfo(new DigestAuthenticationProvider().getScheme(), defaultFencingAuth));
    }
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkHostPort).sessionTimeoutMs(zkSessionTimeout).retryPolicy(new RetryNTimes(numRetries, zkRetryInterval)).authorization(authInfos).build();
    client.start();
    return client;
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) AuthInfo(org.apache.curator.framework.AuthInfo) ArrayList(java.util.ArrayList) ZKUtil(org.apache.hadoop.util.ZKUtil) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) CuratorFramework(org.apache.curator.framework.CuratorFramework) DigestAuthenticationProvider(org.apache.zookeeper.server.auth.DigestAuthenticationProvider)

Example 34 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project nifi by apache.

the class Cluster method createCuratorClient.

public CuratorFramework createCuratorClient() {
    final RetryPolicy retryPolicy = new RetryNTimes(20, 500);
    final CuratorFramework curatorClient = CuratorFrameworkFactory.builder().connectString(getZooKeeperConnectString()).sessionTimeoutMs(3000).connectionTimeoutMs(3000).retryPolicy(retryPolicy).defaultData(new byte[0]).build();
    curatorClient.start();
    return curatorClient;
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryPolicy(org.apache.curator.RetryPolicy)

Example 35 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project pravega by pravega.

the class ZKStoreHelperTest method testEphemeralNode.

@Test
public void testEphemeralNode() {
    CuratorFramework cli2 = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new RetryNTimes(0, 0));
    cli2.start();
    ZKStoreHelper zkStoreHelper2 = new ZKStoreHelper(cli2, executor);
    Assert.assertTrue(zkStoreHelper2.createEphemeralZNode("/testEphemeral", new byte[0]).join());
    Assert.assertNotNull(zkStoreHelper2.getData("/testEphemeral").join());
    zkStoreHelper2.getClient().close();
    // let session get expired.
    // now read the data again. Verify that node no longer exists
    AssertExtensions.assertThrows("", Futures.delayedFuture(() -> zkStoreHelper.getData("/testEphemeral"), 1000, executor), e -> e instanceof StoreException.DataNotFoundException);
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) 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