Search in sources :

Example 36 with RetryPolicy

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;
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) RetryPolicy(org.apache.curator.RetryPolicy)

Example 37 with RetryPolicy

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;
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 38 with RetryPolicy

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;
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 39 with RetryPolicy

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();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) StorageNameManager(com.bonree.brfs.duplication.storagename.StorageNameManager) DefaultStorageNameManager(com.bonree.brfs.duplication.storagename.DefaultStorageNameManager) DefaultStorageNameManager(com.bonree.brfs.duplication.storagename.DefaultStorageNameManager) RetryPolicy(org.apache.curator.RetryPolicy) ZookeeperFileCoordinator(com.bonree.brfs.duplication.coordinator.zk.ZookeeperFileCoordinator)

Example 40 with RetryPolicy

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();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

RetryPolicy (org.apache.curator.RetryPolicy)69 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)47 CuratorFramework (org.apache.curator.framework.CuratorFramework)42 RetryNTimes (org.apache.curator.retry.RetryNTimes)12 IOException (java.io.IOException)10 ACLProvider (org.apache.curator.framework.api.ACLProvider)7 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)6 TestingServer (org.apache.curator.test.TestingServer)5 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)4 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)4 SimpleEventListener (org.apache.metron.zookeeper.SimpleEventListener)4 ZKCache (org.apache.metron.zookeeper.ZKCache)4 ACL (org.apache.zookeeper.data.ACL)4 Before (org.junit.Before)4 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)3 AuthInfo (org.apache.curator.framework.AuthInfo)3 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)3 Test (org.junit.Test)3 Service (com.bonree.brfs.common.service.Service)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2