Search in sources :

Example 16 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project Saturn by vipshop.

the class InitSaturnJob method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    String zkConnection = System.getProperty("VIP_SATURN_ZK_CONNECTION");
    System.out.println("zkConnection=" + zkConnection);
    if (zkConnection == null || "".equals(zkConnection.trim())) {
        zkConnection = "localhost:2182";
    }
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkConnection).namespace("saturn-it.vip.com").sessionTimeoutMs(10000).retryPolicy(retryPolicy).build();
    client.start();
    addJavaJob(client, "demoJavaJob");
    System.out.println("done add a java-job.");
    addShellJob(client, "demoShellJob");
    System.out.println("done add a shell-job.");
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 17 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project fabric8 by jboss-fuse.

the class CuratorFactoryBean method getObject.

// FactoryBean interface
// -------------------------------------------------------------------------
public CuratorFramework getObject() throws Exception {
    LOG.debug("Connecting to ZooKeeper on " + connectString);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(connectString).retryPolicy(new ExponentialBackoffRetry(5, 10)).connectionTimeoutMs(getTimeout());
    if (password != null && !password.isEmpty()) {
        builder.aclProvider(new CuratorACLManager());
        builder.authorization("digest", ("fabric:" + password).getBytes("UTF-8"));
    }
    this.curator = builder.build();
    LOG.debug("Starting curator " + curator);
    curator.start();
    return curator;
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

Example 18 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project knox by apache.

the class KafkaZookeeperURLManager method retrieveHosts.

// -------------------------------------------------------------------------------------
// Private methods
// -------------------------------------------------------------------------------------
/**
 * @return Retrieve lists of hosts from ZooKeeper
 */
private List<String> retrieveHosts() {
    List<String> serverHosts = new ArrayList<>();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(getZookeeperEnsemble()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    try {
        zooKeeperClient.start();
        // Retrieve list of host URLs from ZooKeeper
        List<String> brokers = zooKeeperClient.getChildren().forPath(BASE_PATH);
        for (String broker : brokers) {
            String serverInfo = new String(zooKeeperClient.getData().forPath(BASE_PATH + "/" + broker), Charset.forName("UTF-8"));
            String serverURL = constructURL(serverInfo);
            serverHosts.add(serverURL);
        }
    } catch (Exception e) {
        LOG.failedToGetZookeeperUrls(e);
        throw new RuntimeException(e);
    } finally {
        // Close the client connection with ZooKeeper
        if (zooKeeperClient != null) {
            zooKeeperClient.close();
        }
    }
    return serverHosts;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ParseException(net.minidev.json.parser.ParseException)

Example 19 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project knox by apache.

the class SOLRZookeeperURLManager method retrieveHosts.

// -------------------------------------------------------------------------------------
// Private methods
// -------------------------------------------------------------------------------------
/**
 * @return Retrieve lists of hosts from ZooKeeper
 */
private List<String> retrieveHosts() {
    List<String> serverHosts = new ArrayList<>();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(getZookeeperEnsemble()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    try {
        zooKeeperClient.start();
        List<String> serverNodes = zooKeeperClient.getChildren().forPath("/live_nodes");
        for (String serverNode : serverNodes) {
            String serverURL = constructURL(serverNode);
            serverHosts.add(serverURL);
        }
    } catch (Exception e) {
        LOG.failedToGetZookeeperUrls(e);
        throw new RuntimeException(e);
    } finally {
        // Close the client connection with ZooKeeper
        if (zooKeeperClient != null) {
            zooKeeperClient.close();
        }
    }
    return serverHosts;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList)

Example 20 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project knox by apache.

the class HBaseZookeeperURLManagerTest method setup.

@Before
public void setup() throws Exception {
    cluster = new TestingCluster(3);
    cluster.start();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    zooKeeperClient.start();
    zooKeeperClient.create().forPath("/hbase-unsecure");
    zooKeeperClient.create().forPath("/hbase-unsecure/rs");
    zooKeeperClient.close();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Before(org.junit.Before)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)181 CuratorFramework (org.apache.curator.framework.CuratorFramework)107 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)26 TestingCluster (org.apache.curator.test.TestingCluster)23 Test (org.testng.annotations.Test)23 IOException (java.io.IOException)18 TestingServer (org.apache.curator.test.TestingServer)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 KeeperException (org.apache.zookeeper.KeeperException)8 HashMap (java.util.HashMap)7