@PostConstruct public void init() { if (adapterCanalConfig.getZookeeperHosts() != null) { curator = CuratorFrameworkFactory.builder() .connectString(adapterCanalConfig.getZookeeperHosts()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .sessionTimeoutMs(6000) .connectionTimeoutMs(3000) .namespace("canal-adapter") .build(); curator.start(); } }
/** * A ZooKeeper server listener, which registers server into ZooKeeper. * * @deprecated Use {@link ZooKeeperUpdatingListenerBuilder}. * * @param zkConnectionStr ZooKeeper connection string * @param zNodePath ZooKeeper node path(under which this server will be registered) * @param sessionTimeout session timeout * @param endpoint the endpoint of the server being registered */ @Deprecated public ZooKeeperUpdatingListener(String zkConnectionStr, String zNodePath, int sessionTimeout, @Nullable Endpoint endpoint) { requireNonNull(zkConnectionStr, "zkConnectionStr"); checkArgument(!zkConnectionStr.isEmpty(), "zkConnectionStr can't be empty"); client = CuratorFrameworkFactory.builder() .connectString(zkConnectionStr) .retryPolicy(ZooKeeperDefaults.DEFAULT_RETRY_POLICY) .sessionTimeoutMs(sessionTimeout) .build(); this.zNodePath = requireNonNull(zNodePath, "zNodePath"); nodeValueCodec = NodeValueCodec.DEFAULT; this.endpoint = endpoint; closeClientOnStop = true; }
private void create() throws Exception { client = CuratorFrameworkFactory.builder().connectString(ensemble).sessionTimeoutMs(sessionTimeout) .retryPolicy(new RetryForever(1000)).canBeReadOnly(true).build(); client.start(); cache = new NodeCache(client, NODE); cache.start(true); }
builder.sessionTimeoutMs(zkConfig.getSessionTimeout());
.sessionTimeoutMs(sessionTimeout) .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)); if (zooKeeperAclProvider != null) {
/** * Return a connection ot the ZK instance (creating it if needed) * * @return connection * @throws IOException errors */ public synchronized CuratorFramework getLocalConnection() throws IOException { if ( localConnection == null ) { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + configManager.getConfig().getInt(IntConfigs.CLIENT_PORT)) .sessionTimeoutMs(arguments.connectionTimeOutMs * 10) .connectionTimeoutMs(arguments.connectionTimeOutMs) .retryPolicy(new ExponentialBackoffRetry(1000, 3)); if ( arguments.aclProvider != null ) { builder = builder.aclProvider(arguments.aclProvider); } localConnection = builder.build(); localConnection.start(); } return localConnection; }
.namespace(zkConfig.getNamespace()); if (0 != zkConfig.getSessionTimeoutMilliseconds()) { builder.sessionTimeoutMs(zkConfig.getSessionTimeoutMilliseconds());
public static synchronized CuratorFramework getInstance(HiveConf hiveConf) { if (sharedClient == null) { // Create a client instance if (hiveConf == null) { conf = new HiveConf(); } else { conf = hiveConf; } int sessionTimeout = (int) conf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS); int baseSleepTime = (int) conf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS); int maxRetries = conf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES); String quorumServers = ZooKeeperHiveHelper.getQuorumServers(conf); sharedClient = CuratorFrameworkFactory.builder().connectString(quorumServers) .sessionTimeoutMs(sessionTimeout) .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)) .build(); sharedClient.start(); } return sharedClient; }
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(); } }
.sessionTimeoutMs(config.getZkSessionTimeoutMs()) .retryPolicy(new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES)) .compressionProvider(new PotentiallyGzippedCompressionProvider(config.getEnableCompression()))
private CuratorFramework getZookeeperClient(Configuration conf, String namespace, ACLProvider zooKeeperAclProvider) { String zkEnsemble = getQuorumServers(conf); int sessionTimeout = (int) HiveConf.getTimeVar(conf, ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS); int connectionTimeout = (int) HiveConf.getTimeVar(conf, ConfVars.HIVE_ZOOKEEPER_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); int baseSleepTime = (int) HiveConf.getTimeVar(conf, ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS); int maxRetries = HiveConf.getIntVar(conf, ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES); LOG.info("Creating curator client with connectString: {} sessionTimeoutMs: {} connectionTimeoutMs: {}" + " namespace: {} exponentialBackoff - sleepTime: {} maxRetries: {}", zkEnsemble, sessionTimeout, connectionTimeout, namespace, baseSleepTime, maxRetries); // Create a CuratorFramework instance to be used as the ZooKeeper client // Use the zooKeeperAclProvider to create appropriate ACLs return CuratorFrameworkFactory.builder() .connectString(zkEnsemble) .sessionTimeoutMs(sessionTimeout) .connectionTimeoutMs(connectionTimeout) .aclProvider(zooKeeperAclProvider) .namespace(namespace) .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)) .build(); }
/** * Returns a newly-created {@link ZooKeeperUpdatingListener} instance that registers the server to * ZooKeeper when the server starts. */ public ZooKeeperUpdatingListener build() { final boolean internalClient; if (client == null) { client = CuratorFrameworkFactory.builder() .connectString(connectionStr) .retryPolicy(ZooKeeperDefaults.DEFAULT_RETRY_POLICY) .connectionTimeoutMs(connectTimeoutMillis) .sessionTimeoutMs(sessionTimeoutMillis) .build(); internalClient = true; } else { internalClient = false; } return new ZooKeeperUpdatingListener(client, zNodePath, nodeValueCodec, endpoint, internalClient); } }
@Override public CuratorFramework newClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, RetryPolicy retryPolicy, final ACLProvider aclProvider, final List<AuthInfo> authorization) { final Builder builder = CuratorFrameworkFactory.builder() .connectString(connectString) .sessionTimeoutMs(sessionTimeoutMs) .connectionTimeoutMs(connectionTimeoutMs) .retryPolicy(retryPolicy); if (aclProvider != null) { builder.aclProvider(aclProvider); } if (authorization != null && !authorization.isEmpty()) { builder.authorization(authorization); } return builder.build(); } }
private static CuratorFramework getZKClient(KylinConfig config) { CuratorFramework zkClient = CACHE.get(config); if (zkClient == null) { synchronized (ZookeeperDistributedLock.class) { zkClient = CACHE.get(config); if (zkClient == null) { RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); String zkConnectString = getZKConnectString(config); ZookeeperAclBuilder zookeeperAclBuilder = new ZookeeperAclBuilder().invoke(); zkClient = zookeeperAclBuilder.setZKAclBuilder(CuratorFrameworkFactory.builder()).connectString(zkConnectString).sessionTimeoutMs(120000).connectionTimeoutMs(15000).retryPolicy(retryPolicy).build(); zkClient.start(); CACHE.put(config, zkClient); if (CACHE.size() > 1) { logger.warn("More than one singleton exist"); } } } } return zkClient; }
public static synchronized CuratorFramework getInstance(HiveConf hiveConf) { if (sharedClient == null) { // Create a client instance if (hiveConf == null) { conf = new HiveConf(); } else { conf = hiveConf; } int sessionTimeout = (int) conf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS); int baseSleepTime = (int) conf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS); int maxRetries = conf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES); String quorumServers = conf.getZKConfig().getQuorumServers(); sharedClient = CuratorFrameworkFactory.builder().connectString(quorumServers) .sessionTimeoutMs(sessionTimeout) .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)) .build(); sharedClient.start(); } return sharedClient; }
private CuratorFramework createClient() { // Create a new client because we don't want to try indefinitely for this to occur. final RetryPolicy retryPolicy = new RetryNTimes(1, 100); final CuratorACLProviderFactory aclProviderFactory = new CuratorACLProviderFactory(); final CuratorFramework client = CuratorFrameworkFactory.builder() .connectString(zkConfig.getConnectString()) .sessionTimeoutMs(zkConfig.getSessionTimeoutMillis()) .connectionTimeoutMs(zkConfig.getConnectionTimeoutMillis()) .retryPolicy(retryPolicy) .aclProvider(aclProviderFactory.create(zkConfig)) .defaultData(new byte[0]) .build(); client.start(); return client; }
private CuratorFramework buildCuratorClient(final RegistryCenterConfiguration config) { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(config.getServerLists()) .retryPolicy(new ExponentialBackoffRetry(config.getRetryIntervalMilliseconds(), config.getMaxRetries(), config.getRetryIntervalMilliseconds() * config.getMaxRetries())) .namespace(config.getNamespace()); if (0 != config.getTimeToLiveSeconds()) { builder.sessionTimeoutMs(config.getTimeToLiveSeconds() * 1000); } if (0 != config.getOperationTimeoutMilliseconds()) { builder.connectionTimeoutMs(config.getOperationTimeoutMilliseconds()); } if (!Strings.isNullOrEmpty(config.getDigest())) { builder.authorization("digest", config.getDigest().getBytes(Charsets.UTF_8)) .aclProvider(new ACLProvider() { @Override public List<ACL> getDefaultAcl() { return ZooDefs.Ids.CREATOR_ALL_ACL; } @Override public List<ACL> getAclForPath(final String path) { return ZooDefs.Ids.CREATOR_ALL_ACL; } }); } return builder.build(); }
protected static void setupBuilder(CuratorFrameworkFactory.Builder builder, String zkStr, Map conf, ZookeeperAuthInfo auth) { builder.connectString(zkStr) .connectionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT))) .sessionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT))) .retryPolicy( new StormBoundedExponentialBackoffRetry(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL)), Utils.getInt(conf .get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING)), Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)))); if (auth != null && auth.scheme != null && auth.payload != null) { builder = builder.authorization(auth.scheme, auth.payload); } }
private void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }
protected void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }