Search in sources :

Example 31 with ExponentialBackoffRetry

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

the class AtlasZookeeperURLManager method lookupURLs.

public List<String> lookupURLs() {
    List<String> serverHosts = new ArrayList<>();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS);
        byte[] bytes = zooKeeperClient.getData().forPath(zooKeeperNamespace + APACHE_ATLAS_ACTIVE_SERVER_INFO);
        String activeURL = new String(bytes, StandardCharsets.UTF_8);
        serverHosts.add(activeURL);
    } catch (Exception e) {
        LOG.failedToGetZookeeperUrls(e);
        throw new RuntimeException(e);
    }
    return serverHosts;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList)

Example 32 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.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<>();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(getZookeeperEnsemble()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS);
        // 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), StandardCharsets.UTF_8);
            String serverURL = constructURL(serverInfo);
            serverHosts.add(serverURL);
        }
    } catch (Exception e) {
        LOG.failedToGetZookeeperUrls(e);
        throw new RuntimeException(e);
    }
    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 33 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.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<>();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(getZookeeperEnsemble()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS);
        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);
    }
    return serverHosts;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList)

Example 34 with ExponentialBackoffRetry

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

the class AtlasZookeeperURLManagerTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new TestingCluster(1);
    cluster.start();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS));
        zooKeeperClient.create().forPath("/apache_atlas");
        zooKeeperClient.create().forPath("/apache_atlas/active_server_info");
        zooKeeperClient.setData().forPath("/apache_atlas/active_server_info", atlasNode1.getBytes(StandardCharsets.UTF_8));
    }
    setAtlasActiveHostURLInZookeeper(atlasNode1);
    manager = new AtlasZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("ATLAS-API");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    config.setZookeeperNamespace("apache_atlas");
    manager.setConfig(config);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Before(org.junit.Before)

Example 35 with ExponentialBackoffRetry

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

the class KafkaZookeeperURLManagerTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new TestingCluster(1);
    cluster.start();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS));
        zooKeeperClient.create().forPath("/brokers");
        zooKeeperClient.create().forPath("/brokers/ids");
    }
}
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)189 CuratorFramework (org.apache.curator.framework.CuratorFramework)113 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)31 TestingCluster (org.apache.curator.test.TestingCluster)28 Test (org.testng.annotations.Test)23 TestingServer (org.apache.curator.test.TestingServer)19 IOException (java.io.IOException)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ArrayList (java.util.ArrayList)14 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 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 HashMap (java.util.HashMap)8 KeeperException (org.apache.zookeeper.KeeperException)8