Search in sources :

Example 1 with FixedEnsembleProvider

use of org.apache.curator.ensemble.fixed.FixedEnsembleProvider in project hive by apache.

the class SecretManager method checkRootAcls.

private static void checkRootAcls(Configuration conf, String path, String user) {
    int stime = conf.getInt(ZK_DTSM_ZK_SESSION_TIMEOUT, ZK_DTSM_ZK_SESSION_TIMEOUT_DEFAULT), ctime = conf.getInt(ZK_DTSM_ZK_CONNECTION_TIMEOUT, ZK_DTSM_ZK_CONNECTION_TIMEOUT_DEFAULT);
    CuratorFramework zkClient = CuratorFrameworkFactory.builder().namespace(null).retryPolicy(new RetryOneTime(10)).sessionTimeoutMs(stime).connectionTimeoutMs(ctime).ensembleProvider(new FixedEnsembleProvider(conf.get(ZK_DTSM_ZK_CONNECTION_STRING))).build();
    // Hardcoded from a private field in ZKDelegationTokenSecretManager.
    // We need to check the path under what it sets for namespace, since the namespace is
    // created with world ACLs.
    String nsPath = "/" + path + "/ZKDTSMRoot";
    Id currentUser = new Id("sasl", user);
    try {
        zkClient.start();
        List<String> children = zkClient.getChildren().forPath(nsPath);
        for (String child : children) {
            String childPath = nsPath + "/" + child;
            checkAcls(zkClient, currentUser, childPath);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        zkClient.close();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Id(org.apache.zookeeper.data.Id) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) IOException(java.io.IOException)

Example 2 with FixedEnsembleProvider

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

the class CuratorModuleTest method defaultEnsembleProvider.

@Test
public void defaultEnsembleProvider() throws NoSuchFieldException, IllegalAccessException {
    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)

Example 3 with FixedEnsembleProvider

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

the class CuratorModuleTest method emptyExhibitorHosts.

@Test
public void emptyExhibitorHosts() {
    Properties props = new Properties();
    props.put(curatorHostKey, "hostB");
    props.put(exhibitorHostsKey, "[]");
    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 4 with FixedEnsembleProvider

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

the class CuratorModule method makeEnsembleProvider.

@Provides
@LazySingleton
public EnsembleProvider makeEnsembleProvider(CuratorConfig config, ExhibitorConfig exConfig) {
    if (exConfig.getHosts().isEmpty()) {
        return new FixedEnsembleProvider(config.getZkHosts());
    }
    return new ExhibitorEnsembleProvider(new Exhibitors(exConfig.getHosts(), exConfig.getRestPort(), newBackupProvider(config.getZkHosts())), new DefaultExhibitorRestClient(exConfig.getUseSsl()), exConfig.getRestUriPath(), exConfig.getPollingMs(), new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES)) {

        @Override
        public void start() throws Exception {
            log.info("Poll the list of zookeeper servers for initial ensemble");
            this.pollForInitialEnsemble();
            super.start();
        }
    };
}
Also used : Exhibitors(org.apache.curator.ensemble.exhibitor.Exhibitors) DefaultExhibitorRestClient(org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) FixedEnsembleProvider(org.apache.curator.ensemble.fixed.FixedEnsembleProvider) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry) LazySingleton(io.druid.guice.LazySingleton) Provides(com.google.inject.Provides)

Example 5 with FixedEnsembleProvider

use of org.apache.curator.ensemble.fixed.FixedEnsembleProvider 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)

Aggregations

FixedEnsembleProvider (org.apache.curator.ensemble.fixed.FixedEnsembleProvider)7 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)4 Injector (com.google.inject.Injector)3 Properties (java.util.Properties)3 EnsembleProvider (org.apache.curator.ensemble.EnsembleProvider)3 Test (org.junit.Test)3 Provides (com.google.inject.Provides)1 LazySingleton (io.druid.guice.LazySingleton)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 DefaultExhibitorRestClient (org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient)1 Exhibitors (org.apache.curator.ensemble.exhibitor.Exhibitors)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 BoundedExponentialBackoffRetry (org.apache.curator.retry.BoundedExponentialBackoffRetry)1 RetryOneTime (org.apache.curator.retry.RetryOneTime)1 BindingInformation (org.apache.hadoop.registry.client.impl.zk.BindingInformation)1 Id (org.apache.zookeeper.data.Id)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)1