Search in sources :

Example 1 with BoundedExponentialBackoffRetry

use of org.apache.curator.retry.BoundedExponentialBackoffRetry in project hadoop by apache.

the class CuratorService method createCurator.

/**
   * Create a new curator instance off the root path; using configuration
   * options provided in the service configuration to set timeouts and
   * retry policy.
   * @return the newly created creator
   */
private CuratorFramework createCurator() throws IOException {
    Configuration conf = getConfig();
    createEnsembleProvider();
    int sessionTimeout = conf.getInt(KEY_REGISTRY_ZK_SESSION_TIMEOUT, DEFAULT_ZK_SESSION_TIMEOUT);
    int connectionTimeout = conf.getInt(KEY_REGISTRY_ZK_CONNECTION_TIMEOUT, DEFAULT_ZK_CONNECTION_TIMEOUT);
    int retryTimes = conf.getInt(KEY_REGISTRY_ZK_RETRY_TIMES, DEFAULT_ZK_RETRY_TIMES);
    int retryInterval = conf.getInt(KEY_REGISTRY_ZK_RETRY_INTERVAL, DEFAULT_ZK_RETRY_INTERVAL);
    int retryCeiling = conf.getInt(KEY_REGISTRY_ZK_RETRY_CEILING, DEFAULT_ZK_RETRY_CEILING);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating CuratorService with connection {}", connectionDescription);
    }
    CuratorFramework framework;
    synchronized (CuratorService.class) {
        // set the security options
        // build up the curator itself
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
        builder.ensembleProvider(ensembleProvider).connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).retryPolicy(new BoundedExponentialBackoffRetry(retryInterval, retryCeiling, retryTimes));
        // set up the builder AND any JVM context
        registrySecurity.applySecurityEnvironment(builder);
        //log them
        securityConnectionDiagnostics = buildSecurityDiagnostics();
        framework = builder.build();
        framework.start();
    }
    return framework;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Configuration(org.apache.hadoop.conf.Configuration) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry)

Example 2 with BoundedExponentialBackoffRetry

use of org.apache.curator.retry.BoundedExponentialBackoffRetry in project druid by druid-io.

the class CuratorModule method makeCurator.

@Provides
@LazySingleton
public CuratorFramework makeCurator(CuratorConfig config, EnsembleProvider ensembleProvider, Lifecycle lifecycle) throws IOException {
    final CuratorFramework framework = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider).sessionTimeoutMs(config.getZkSessionTimeoutMs()).retryPolicy(new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES)).compressionProvider(new PotentiallyGzippedCompressionProvider(config.getEnableCompression())).aclProvider(config.getEnableAcl() ? new SecuredACLProvider() : new DefaultACLProvider()).build();
    lifecycle.addHandler(new Lifecycle.Handler() {

        @Override
        public void start() throws Exception {
            log.info("Starting Curator");
            framework.start();
        }

        @Override
        public void stop() {
            log.info("Stopping Curator");
            framework.close();
        }
    });
    return framework;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) IOException(java.io.IOException) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry) LazySingleton(io.druid.guice.LazySingleton) Provides(com.google.inject.Provides)

Example 3 with BoundedExponentialBackoffRetry

use of org.apache.curator.retry.BoundedExponentialBackoffRetry in project spring-integration by spring-projects.

the class ZookeeperTestSupport method createNewClient.

protected static CuratorFramework createNewClient() throws InterruptedException {
    CuratorFramework client = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 3));
    client.start();
    return client;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry)

Example 4 with BoundedExponentialBackoffRetry

use of org.apache.curator.retry.BoundedExponentialBackoffRetry in project registry by hortonworks.

the class ZKLeadershipParticipant method init.

public void init(Map<String, Object> conf, String participantId) {
    Preconditions.checkNotNull(participantId, "participantId can not be null");
    Preconditions.checkNotNull(conf, "conf can not be null");
    this.conf = conf;
    this.serverUrl = participantId;
    this.leaderLatchListener = createLeaderLatchListener();
    LOG.info("Received configuration : [{}]", conf);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    String url = (String) conf.get(CONNECT_URL);
    String rootPrefix = (String) conf.get("root");
    builder.connectString(url);
    builder.connectionTimeoutMs((Integer) conf.getOrDefault(CONNECTION_TIMEOUT_MS, DEFAULT_CONN_TIMOUT));
    builder.sessionTimeoutMs((Integer) conf.getOrDefault(SESSION_TIMEOUT_MS, DEFAULT_SESSION_TIMEOUT));
    builder.retryPolicy(new BoundedExponentialBackoffRetry((Integer) conf.getOrDefault(RETRY_BASE_SLEEP_TIME_MS, DEFAULT_BASE_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_MAX_SLEEP_TIME_MS, DEFAULT_MAX_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_LIMIT, DEFAULT_RETRY_LIMIT)));
    curatorFramework = builder.build();
    leaderLatchPath = rootPrefix + LEADER_LOCK_NODE_PATH;
    leaderLatchRef = new AtomicReference<>(createLeaderLatch());
    curatorFramework.start();
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) BoundedExponentialBackoffRetry(org.apache.curator.retry.BoundedExponentialBackoffRetry)

Example 5 with BoundedExponentialBackoffRetry

use of org.apache.curator.retry.BoundedExponentialBackoffRetry 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)

Aggregations

BoundedExponentialBackoffRetry (org.apache.curator.retry.BoundedExponentialBackoffRetry)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 Provides (com.google.inject.Provides)2 LazySingleton (io.druid.guice.LazySingleton)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)1 IOException (java.io.IOException)1 DefaultExhibitorRestClient (org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient)1 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)1 Exhibitors (org.apache.curator.ensemble.exhibitor.Exhibitors)1 FixedEnsembleProvider (org.apache.curator.ensemble.fixed.FixedEnsembleProvider)1 DefaultACLProvider (org.apache.curator.framework.imps.DefaultACLProvider)1 Configuration (org.apache.hadoop.conf.Configuration)1