Search in sources :

Example 46 with RetryPolicy

use of org.apache.curator.RetryPolicy in project drill by axbaretto.

the class TestEphemeralStore method setUp.

@Before
public void setUp() throws Exception {
    ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
    server = new TestingServer();
    final RetryPolicy policy = new RetryNTimes(2, 1000);
    curator = CuratorFrameworkFactory.newClient(server.getConnectString(), policy);
    config = Mockito.mock(TransientStoreConfig.class);
    Mockito.when(config.getName()).thenReturn(root);
    Mockito.when(config.getSerializer()).thenReturn(new InstanceSerializer<String>() {

        @Override
        public byte[] serialize(final String instance) throws IOException {
            if (instance == null) {
                return null;
            }
            return instance.getBytes();
        }

        @Override
        public String deserialize(final byte[] raw) throws IOException {
            if (raw == null) {
                return null;
            }
            return new String(raw);
        }
    });
    store = new ZkEphemeralStore<>(config, curator);
    server.start();
    curator.start();
    store.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryNTimes(org.apache.curator.retry.RetryNTimes) TransientStoreConfig(org.apache.drill.exec.coord.store.TransientStoreConfig) IOException(java.io.IOException) RetryPolicy(org.apache.curator.RetryPolicy) Before(org.junit.Before)

Example 47 with RetryPolicy

use of org.apache.curator.RetryPolicy in project drill by axbaretto.

the class TestZookeeperClient method setUp.

@Before
public void setUp() throws Exception {
    ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
    server = new TestingServer();
    final RetryPolicy policy = new RetryNTimes(1, 1000);
    curator = CuratorFrameworkFactory.newClient(server.getConnectString(), policy);
    client = new ClientWithMockCache(curator, root, mode);
    server.start();
    curator.start();
    client.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryNTimes(org.apache.curator.retry.RetryNTimes) RetryPolicy(org.apache.curator.RetryPolicy) Before(org.junit.Before)

Example 48 with RetryPolicy

use of org.apache.curator.RetryPolicy in project oozie by apache.

the class ZKUtils method createClient.

private void createClient() throws Exception {
    // Connect to the ZooKeeper server
    RetryPolicy retryPolicy = ZKUtils.getRetryPolicy();
    String zkConnectionString = ConfigurationService.get(ZK_CONNECTION_STRING);
    String zkNamespace = getZKNameSpace();
    int zkConnectionTimeout = ConfigurationService.getInt(ZK_CONNECTION_TIMEOUT);
    int zkSessionTimeout = ConfigurationService.getInt(ZK_SESSION_TIMEOUT, 300);
    ACLProvider aclProvider;
    if (Services.get().getConf().getBoolean(ZK_SECURE, false)) {
        log.info("Connecting to ZooKeeper with SASL/Kerberos and using 'sasl' ACLs");
        setJaasConfiguration();
        System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client");
        System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
        saslACL = Collections.singletonList(new ACL(Perms.ALL, new Id("sasl", getServicePrincipal())));
        aclProvider = new SASLOwnerACLProvider();
    } else {
        log.info("Connecting to ZooKeeper without authentication");
        // open to everyone
        aclProvider = new DefaultACLProvider();
    }
    client = CuratorFrameworkFactory.builder().namespace(zkNamespace).connectString(zkConnectionString).retryPolicy(retryPolicy).aclProvider(aclProvider).connectionTimeoutMs(// in ms
    zkConnectionTimeout * 1000).sessionTimeoutMs(// in ms
    zkSessionTimeout * 1000).build();
    client.start();
    client.getConnectionStateListenable().addListener(new ZKConnectionListener());
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) ACL(org.apache.zookeeper.data.ACL) ZKConnectionListener(org.apache.oozie.event.listener.ZKConnectionListener) Id(org.apache.zookeeper.data.Id) RetryPolicy(org.apache.curator.RetryPolicy)

Example 49 with RetryPolicy

use of org.apache.curator.RetryPolicy in project nakadi by zalando.

the class ZooKeeperHolder method initExhibitor.

private void initExhibitor() throws Exception {
    final RetryPolicy retryPolicy = new ExponentialBackoffRetry(EXHIBITOR_RETRY_TIME, EXHIBITOR_RETRY_MAX);
    final EnsembleProvider ensembleProvider;
    if (exhibitorAddresses != null) {
        final Collection<String> exhibitorHosts = Arrays.asList(exhibitorAddresses.split("\\s*,\\s*"));
        final Exhibitors exhibitors = new Exhibitors(exhibitorHosts, exhibitorPort, () -> zookeeperBrokers + zookeeperKafkaNamespace);
        final ExhibitorRestClient exhibitorRestClient = new DefaultExhibitorRestClient();
        ensembleProvider = new ExhibitorEnsembleProvider(exhibitors, exhibitorRestClient, "/exhibitor/v1/cluster/list", EXHIBITOR_POLLING_MS, retryPolicy);
        ((ExhibitorEnsembleProvider) ensembleProvider).pollForInitialEnsemble();
    } else {
        ensembleProvider = new FixedEnsembleProvider(zookeeperBrokers + zookeeperKafkaNamespace);
    }
    zooKeeper = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider).retryPolicy(retryPolicy).build();
    zooKeeper.start();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Exhibitors(org.apache.curator.ensemble.exhibitor.Exhibitors) DefaultExhibitorRestClient(org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient) ExhibitorRestClient(org.apache.curator.ensemble.exhibitor.ExhibitorRestClient) DefaultExhibitorRestClient(org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient) RetryPolicy(org.apache.curator.RetryPolicy) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) EnsembleProvider(org.apache.curator.ensemble.EnsembleProvider)

Example 50 with RetryPolicy

use of org.apache.curator.RetryPolicy in project oozie by apache.

the class ZKXTestCase method createClient.

private void createClient() throws Exception {
    RetryPolicy retryPolicy = ZKUtils.getRetryPolicy();
    String zkConnectionString = Services.get().getConf().get("oozie.zookeeper.connection.string", zkServer.getConnectString());
    String zkNamespace = Services.get().getConf().get("oozie.zookeeper.namespace", "oozie");
    client = CuratorFrameworkFactory.builder().namespace(zkNamespace).connectString(zkConnectionString).retryPolicy(retryPolicy).build();
    client.start();
}
Also used : 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