@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(); } }
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(); } }
.builder() .aclProvider(aclProvider) .namespace( conf.get(ZK_DTSM_ZNODE_WORKING_PATH, ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT)
public void start() { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); zkClient = builder.connectString(getServerConnectionString()).namespace(ZK_NAMESPACE) .retryPolicy(new RetryOneTime(1)).connectionTimeoutMs(1).sessionTimeoutMs(140).build(); zkClient.start(); RegistryContext.clientCache.putIfAbsent("curatorClient", zkClient); }
@Test public void testCustomCuratorFramework() throws Exception { JsonObject config = zkCluster.getDefaultConfig(); CuratorFramework curator = CuratorFrameworkFactory.builder() .connectString(config.getString("zookeeperHosts")) .namespace(config.getString("rootPath")) .retryPolicy(retryPolicy).build(); curator.start(); ZookeeperClusterManager mgr = new ZookeeperClusterManager(curator); testProgrammatic(mgr, config); }
private void initZk(){ ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(baseSleepTime, maxRetry); zkclient = CuratorFrameworkFactory.builder().namespace(namespace).connectString(connectString) .connectionTimeoutMs(connectTimeout).sessionTimeoutMs(connectTimeout).retryPolicy(retryPolicy).build(); zkclient.start(); logger.info("init zk connection success"); }
private void initZk(){ ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(baseSleepTime, maxRetry); zkclient = CuratorFrameworkFactory.builder().namespace(namespace).connectString(connectString) .connectionTimeoutMs(connectTimeout).sessionTimeoutMs(connectTimeout).retryPolicy(retryPolicy).build(); zkclient.start(); }
@Test public void testCustomCuratorFramework() throws Exception { JsonObject config = zkCluster.getDefaultConfig(); CuratorFramework curator = CuratorFrameworkFactory.builder() .connectString(config.getString("zookeeperHosts")) .namespace(config.getString("rootPath")) .retryPolicy(retryPolicy).build(); curator.start(); ZookeeperClusterManager mgr = new ZookeeperClusterManager(curator); testProgrammatic(mgr, config); }
@Override protected DomainManager createManagerForDomain(String domain) { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(connectString) .namespace(namespace) .retryPolicy(new ExponentialBackoffRetry(1000, 3)); return ZookeeperDomainManager.of(domain, builder); }
public static CuratorFramework create(String connectString, int sessionTimeout, int connectionTimeout, String namespace) { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); return builder.connectString(connectString).sessionTimeoutMs(sessionTimeout).connectionTimeoutMs(30000) .canBeReadOnly(true).namespace(namespace).retryPolicy(new ExponentialBackoffRetry(1000, Integer.MAX_VALUE)) .defaultData(null).build(); }
public static CuratorFramework provideZookeeperClient(String zkCluster) { LOG.info("Creating Zookeeper Client connecting to {}", zkCluster); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); return CuratorFrameworkFactory.builder() .namespace(OMID_NAMESPACE) .connectString(zkCluster) .retryPolicy(retryPolicy) .build(); }
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(); }
private void createClient() throws Exception { // Connect to the ZooKeeper server RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); String zkConnectionString = Services.get().getConf().get("oozie.zookeeper.connection.string", "localhost:2181"); String zkNamespace = Services.get().getConf().get("oozie.zookeeper.namespace", "Oozie"); client = CuratorFrameworkFactory.builder() .namespace(zkNamespace) .connectString(zkConnectionString) .retryPolicy(retryPolicy) .build(); client.start(); }
@Inject public SingularityCuratorProvider(final SingularityConfiguration configuration, final Set<ConnectionStateListener> connectionStateListeners) { checkNotNull(configuration, "configuration is null"); checkNotNull(connectionStateListeners, "connectionStateListeners is null"); ZooKeeperConfiguration zookeeperConfig = configuration.getZooKeeperConfiguration(); this.curatorFramework = CuratorFrameworkFactory.builder() .defaultData(null) .sessionTimeoutMs(zookeeperConfig.getSessionTimeoutMillis()) .connectionTimeoutMs(zookeeperConfig.getConnectTimeoutMillis()) .connectString(zookeeperConfig.getQuorum()) .retryPolicy(new ExponentialBackoffRetry(zookeeperConfig.getRetryBaseSleepTimeMilliseconds(), zookeeperConfig.getRetryMaxTries())) .namespace(zookeeperConfig.getZkNamespace()).build(); for (ConnectionStateListener connectionStateListener : connectionStateListeners) { curatorFramework.getConnectionStateListenable().addListener(connectionStateListener); } }
.connectString(zkConfig.getHosts()) .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMs(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepMs())) .namespace(zkConfig.getNamespace());
.connectString(zkConfig.getServerLists()) .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds())) .namespace(zkConfig.getNamespace()); if (0 != zkConfig.getSessionTimeoutMilliseconds()) { builder.sessionTimeoutMs(zkConfig.getSessionTimeoutMilliseconds());
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(); }
public ZKClusterCoordinator(String connect, String zkRoot, String clusterId, int retryCount, int retryDelayMs, int connectTimeoutMs) throws IOException { logger.debug("ZK connect: " + connect + ", zkRoot: " + zkRoot + ", clusterId: " + clusterId); this.serviceName = clusterId; RetryPolicy rp = new RetryNTimes(retryCount, retryDelayMs); curator = CuratorFrameworkFactory.builder().namespace(zkRoot) .connectionTimeoutMs(connectTimeoutMs).retryPolicy(rp) .connectString(connect).build(); curator.getConnectionStateListenable() .addListener(new InitialConnectionListener()); curator.start(); discovery = newDiscovery(); factory = CachingTransientStoreFactory .of(new ZkTransientStoreFactory(curator)); }
/** * Connect to the test ZK for the simulated Drillbit side of the test. (The AM * side of the test uses the actual AM code, which is what we're testing * here...) * * @param connectString * @return */ public static CuratorFramework connectToZk(String connectString) { CuratorFramework client = CuratorFrameworkFactory.builder() .namespace(ZK_ROOT + "/" + CLUSTER_ID).connectString(connectString) .retryPolicy(new RetryNTimes(3, 1000)).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(); }