Search in sources :

Example 6 with EnsembleProvider

use of org.apache.curator.ensemble.EnsembleProvider in project druid by druid-io.

the class CuratorModuleTest method fixedZkHosts.

@Test
public void fixedZkHosts() {
    Properties props = new Properties();
    props.put(curatorHostKey, "hostA");
    Injector injector = newInjector(props);
    // initialize related components
    injector.getInstance(CuratorFramework.class);
    EnsembleProvider ensembleProvider = injector.getInstance(EnsembleProvider.class);
    Assert.assertTrue("EnsembleProvider should be FixedEnsembleProvider", ensembleProvider instanceof FixedEnsembleProvider);
    Assert.assertEquals("The connectionString should be 'hostA'", "hostA", ensembleProvider.getConnectionString());
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) EnsembleProvider(org.apache.curator.ensemble.EnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) Test(org.junit.Test)

Example 7 with EnsembleProvider

use of org.apache.curator.ensemble.EnsembleProvider 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 8 with EnsembleProvider

use of org.apache.curator.ensemble.EnsembleProvider in project druid by druid-io.

the class CuratorModuleTest method emptyExhibitorHosts.

@Test
public void emptyExhibitorHosts() {
    Properties props = new Properties();
    props.setProperty(CURATOR_HOST_KEY, "hostB");
    props.setProperty(EXHIBITOR_HOSTS_KEY, "[]");
    Injector injector = newInjector(props);
    // initialize related components
    injector.getInstance(CuratorFramework.class);
    EnsembleProvider ensembleProvider = injector.getInstance(EnsembleProvider.class);
    Assert.assertTrue("EnsembleProvider should be FixedEnsembleProvider", ensembleProvider instanceof FixedEnsembleProvider);
    Assert.assertEquals("The connectionString should be 'hostB'", "hostB", ensembleProvider.getConnectionString());
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) EnsembleProvider(org.apache.curator.ensemble.EnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) Test(org.junit.Test)

Example 9 with EnsembleProvider

use of org.apache.curator.ensemble.EnsembleProvider in project druid by druid-io.

the class CuratorModuleTest method fixedZkHosts.

@Test
public void fixedZkHosts() {
    Properties props = new Properties();
    props.setProperty(CURATOR_HOST_KEY, "hostA");
    Injector injector = newInjector(props);
    // initialize related components
    injector.getInstance(CuratorFramework.class);
    EnsembleProvider ensembleProvider = injector.getInstance(EnsembleProvider.class);
    Assert.assertTrue("EnsembleProvider should be FixedEnsembleProvider", ensembleProvider instanceof FixedEnsembleProvider);
    Assert.assertEquals("The connectionString should be 'hostA'", "hostA", ensembleProvider.getConnectionString());
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) EnsembleProvider(org.apache.curator.ensemble.EnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) Test(org.junit.Test)

Example 10 with EnsembleProvider

use of org.apache.curator.ensemble.EnsembleProvider in project druid by druid-io.

the class CuratorModuleTest method defaultEnsembleProvider.

@Test
public void defaultEnsembleProvider() {
    Injector injector = newInjector(new Properties());
    // initialize related components
    injector.getInstance(CuratorFramework.class);
    EnsembleProvider ensembleProvider = injector.getInstance(EnsembleProvider.class);
    Assert.assertTrue("EnsembleProvider should be FixedEnsembleProvider", ensembleProvider instanceof FixedEnsembleProvider);
    Assert.assertEquals("The connectionString should be 'localhost'", "localhost", ensembleProvider.getConnectionString());
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) EnsembleProvider(org.apache.curator.ensemble.EnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) Test(org.junit.Test)

Aggregations

EnsembleProvider (org.apache.curator.ensemble.EnsembleProvider)10 FixedEnsembleProvider (org.apache.curator.ensemble.fixed.FixedEnsembleProvider)9 Injector (com.google.inject.Injector)8 Properties (java.util.Properties)8 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)8 Test (org.junit.Test)8 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RetryPolicy (org.apache.curator.RetryPolicy)1 DefaultExhibitorRestClient (org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient)1 ExhibitorRestClient (org.apache.curator.ensemble.exhibitor.ExhibitorRestClient)1 Exhibitors (org.apache.curator.ensemble.exhibitor.Exhibitors)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1