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);
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations