use of org.apache.curator.RetryPolicy in project hadoop by apache.
the class ZKSignerSecretProvider method createCuratorClient.
/**
* This method creates the Curator client and connects to ZooKeeper.
* @param config configuration properties
* @return A Curator client
* @throws Exception thrown if an error occurred
*/
protected CuratorFramework createCuratorClient(Properties config) throws Exception {
String connectionString = config.getProperty(ZOOKEEPER_CONNECTION_STRING, "localhost:2181");
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
ACLProvider aclProvider;
String authType = config.getProperty(ZOOKEEPER_AUTH_TYPE, "none");
if (authType.equals("sasl")) {
LOG.info("Connecting to ZooKeeper with SASL/Kerberos" + "and using 'sasl' ACLs");
String principal = setJaasConfiguration(config);
System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, JAAS_LOGIN_ENTRY_NAME);
System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
aclProvider = new SASLOwnerACLProvider(principal);
} else {
// "none"
LOG.info("Connecting to ZooKeeper without authentication");
// open to everyone
aclProvider = new DefaultACLProvider();
}
CuratorFramework cf = CuratorFrameworkFactory.builder().connectString(connectionString).retryPolicy(retryPolicy).aclProvider(aclProvider).build();
cf.start();
return cf;
}
use of org.apache.curator.RetryPolicy in project lucene-solr by apache.
the class HadoopAuthFilter method getCuratorClient.
protected CuratorFramework getCuratorClient(SolrZkClient zkClient) {
// should we try to build a RetryPolicy off of the ZkController?
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
if (zkClient == null) {
throw new IllegalArgumentException("zkClient required");
}
String zkHost = zkClient.getZkServerAddress();
String zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : "";
String zkNamespace = zkChroot + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH;
zkNamespace = zkNamespace.startsWith("/") ? zkNamespace.substring(1) : zkNamespace;
String zkConnectionString = zkHost.contains("/") ? zkHost.substring(0, zkHost.indexOf("/")) : zkHost;
SolrZkToCuratorCredentialsACLs curatorToSolrZk = new SolrZkToCuratorCredentialsACLs(zkClient);
// this value is currently hard coded, see SOLR-7561.
final int connectionTimeoutMs = 30000;
curatorFramework = CuratorFrameworkFactory.builder().namespace(zkNamespace).connectString(zkConnectionString).retryPolicy(retryPolicy).aclProvider(curatorToSolrZk.getACLProvider()).authorization(curatorToSolrZk.getAuthInfos()).sessionTimeoutMs(zkClient.getZkClientTimeout()).connectionTimeoutMs(connectionTimeoutMs).build();
curatorFramework.start();
return curatorFramework;
}
use of org.apache.curator.RetryPolicy in project lucene-solr by apache.
the class DelegationTokenKerberosFilter method getCuratorClient.
protected CuratorFramework getCuratorClient(SolrZkClient zkClient) {
// should we try to build a RetryPolicy off of the ZkController?
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
if (zkClient == null) {
throw new IllegalArgumentException("zkClient required");
}
String zkHost = zkClient.getZkServerAddress();
String zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : "";
String zkNamespace = zkChroot + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH;
zkNamespace = zkNamespace.startsWith("/") ? zkNamespace.substring(1) : zkNamespace;
String zkConnectionString = zkHost.contains("/") ? zkHost.substring(0, zkHost.indexOf("/")) : zkHost;
SolrZkToCuratorCredentialsACLs curatorToSolrZk = new SolrZkToCuratorCredentialsACLs(zkClient);
// this value is currently hard coded, see SOLR-7561.
final int connectionTimeoutMs = 30000;
curatorFramework = CuratorFrameworkFactory.builder().namespace(zkNamespace).connectString(zkConnectionString).retryPolicy(retryPolicy).aclProvider(curatorToSolrZk.getACLProvider()).authorization(curatorToSolrZk.getAuthInfos()).sessionTimeoutMs(zkClient.getZkClientTimeout()).connectionTimeoutMs(connectionTimeoutMs).build();
curatorFramework.start();
return curatorFramework;
}
use of org.apache.curator.RetryPolicy in project BRFS by zhangnianli.
the class Test method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, retryPolicy);
client.start();
client.blockUntilConnected();
StorageNameManager snm = new DefaultStorageNameManager(client.usingNamespace("test"));
snm.start();
ZookeeperFileCoordinator coordinator = new ZookeeperFileCoordinator(client.usingNamespace("test"), null);
coordinator.start();
Thread.sleep(3000);
FileNode node = new FileNode();
node.setName("file_node_1");
node.setStorageName("sn_1");
node.setServiceId("me");
node.setDuplicates(new int[] { 1, 2, 3 });
System.out.println("publish---" + coordinator.publish(node));
synchronized (client) {
client.wait();
}
}
use of org.apache.curator.RetryPolicy in project BRFS by zhangnianli.
the class Test method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test"));
sm.start();
sm.addServiceStateListener("g_1", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
System.out.println("remove--" + service);
}
@Override
public void serviceAdded(Service service) {
System.out.println("add--" + service);
}
});
Service s = new Service(UUID.randomUUID().toString(), "g_1", "122", 1);
sm.registerService(s);
synchronized (client) {
client.wait();
}
}
Aggregations