Search in sources :

Example 21 with ExponentialBackoffRetry

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

the class HS2ZookeeperURLManagerTest 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();
    String host1 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10001;hive.server2.thrift.bind.host=host1;hive.server2.use.SSL=true";
    String host2 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=foobar;" + "hive.server2.thrift.http.port=10002;hive.server2.thrift.bind.host=host2;hive.server2.use.SSL=false";
    String host3 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10003;hive.server2.thrift.bind.host=host3;hive.server2.use.SSL=false";
    String host4 = "hive.server2.authentication=NONE;hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" + "hive.server2.thrift.http.port=10004;hive.server2.thrift.bind.host=host4;hive.server2.use.SSL=true";
    zooKeeperClient.start();
    zooKeeperClient.create().forPath("/hiveServer2");
    zooKeeperClient.create().forPath("/hiveServer2/host1", host1.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host2", host2.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host3", host3.getBytes());
    zooKeeperClient.create().forPath("/hiveServer2/host4", host4.getBytes());
    zooKeeperClient.close();
    manager = new HS2ZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("HIVE");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    config.setZookeeperNamespace("hiveServer2");
    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 22 with ExponentialBackoffRetry

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

the class SOLRZookeeperURLManagerTest 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("/live_nodes");
    zooKeeperClient.create().forPath("/live_nodes/host1:8983_solr");
    zooKeeperClient.create().forPath("/live_nodes/host2:8983_solr");
    zooKeeperClient.create().forPath("/live_nodes/host3:8983_solr");
    zooKeeperClient.close();
    manager = new SOLRZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("SOLR");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    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 23 with ExponentialBackoffRetry

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

the class AtlasZookeeperURLManager method lookupURLs.

public List<String> lookupURLs() {
    List<String> serverHosts = new ArrayList<>();
    CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    try {
        zooKeeperClient.start();
        byte[] bytes = zooKeeperClient.getData().forPath(zooKeeperNamespace + APACHE_ATLAS_ACTIVE_SERVER_INFO);
        String activeURL = new String(bytes, Charset.forName("UTF-8"));
        serverHosts.add(activeURL);
    } 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)

Example 24 with ExponentialBackoffRetry

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

the class RemoteConfigurationRegistryClientServiceTest method initializeTestClientAndZNodes.

/**
 * Create a ZooKeeper client with SASL digest auth configured, and initialize the test znodes.
 */
private CuratorFramework initializeTestClientAndZNodes(TestingCluster zkCluster, String principal) throws Exception {
    // Create the client for the test cluster
    CuratorFramework setupClient = CuratorFrameworkFactory.builder().connectString(zkCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    assertNotNull(setupClient);
    setupClient.start();
    List<ACL> acls = new ArrayList<>();
    if (principal != null) {
        acls.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", principal)));
    } else {
        acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/descriptors");
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/shared-providers");
    List<ACL> negativeACLs = new ArrayList<>();
    if (principal != null) {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", "notyou")));
    } else {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(negativeACLs).forPath("/someotherconfig");
    return setupClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 25 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project twister2 by DSC-SPIDAL.

the class ZKUtil method connectToServer.

/**
 * connect to ZooKeeper server
 * @param config
 * @return
 */
public static CuratorFramework connectToServer(Config config) {
    String zkServerAddress = ZKContext.zooKeeperServerIP(config);
    String zkServerPort = ZKContext.zooKeeperServerPort(config);
    String zkServer = zkServerAddress + ":" + zkServerPort;
    try {
        CuratorFramework client = CuratorFrameworkFactory.newClient(zkServer, new ExponentialBackoffRetry(1000, 3));
        client.start();
        LOG.log(Level.INFO, "Connected to ZooKeeper server: " + zkServer);
        return client;
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Could not connect to ZooKeeper server" + zkServer, e);
        throw new RuntimeException(e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

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