private CuratorFramework createCurator(final String connectString) { final ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); final CuratorFramework curator = CuratorFrameworkFactory.builder() .connectString(connectString) .retryPolicy(retryPolicy) .authorization("digest", (SUPER_USER + ":" + SUPER_PASSWORD).getBytes()) .build(); curator.start(); return curator; }
CuratorFramework getCurator(String zkConnectString) { return CuratorFrameworkFactory .builder() .connectString(zkConnectString) .retryPolicy(new ExponentialBackoffRetry(zkBaseSleepMillis, zkMaxRetries, zkSleepMillis)) .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 static CuratorFramework getZkClient(JdbcConnectionParams connParams) throws Exception { String zooKeeperEnsemble = connParams.getZooKeeperEnsemble(); CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); zooKeeperClient.start(); return zooKeeperClient; }
/** * 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; }
public ZooKeeperTestingServerManager() { this.dataDir = Files.createTempDir(); final ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); final Builder builder = CuratorFrameworkFactory.builder() .connectString(endpoint) .retryPolicy(retryPolicy) .authorization("digest", (SUPER_USER + ":" + SUPER_PASSWORD).getBytes()); curator = builder.build(); log.info("starting CuratorFramework connected to {}", endpoint); curator.start(); start(); }
/** * 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); } }
private void startClient() { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); curator = builder.connectString(zkServers).retryPolicy(new ExponentialBackoffRetry(1000,100)).build(); curator.getConnectionStateListenable().addListener(this); curator.start(); }
@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(); } }
@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(); } }
.builder() .connectString(connectString) .retryPolicy(retryPolicy); if ( exhibitorPort > 0 ) return builder.build();
private void reset() { ReentrantReadWriteLock.WriteLock lock = this.readWriteLock.writeLock(); lock.lock(); try { if (this.zooKeeper != null) { this.zooKeeper.close(); } this.zooKeeper = CuratorFrameworkFactory.builder().retryPolicy(new ExponentialBackoffRetry(100, 3)) .connectString(this.zkConnectString).build(); this.zooKeeper.start(); if (!this.zooKeeper.blockUntilConnected(1, TimeUnit.SECONDS)) { throw new RuntimeException("Could not connect to Zookeeper."); } String nodePath = this.zooKeeper.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL) .forPath(this.leaderElectionNode + "/p_"); this.nodeId = nodePath.substring(nodePath.lastIndexOf("/") + 1); determineLeadership(); } catch (Throwable exc) { throw new RuntimeException(exc); } finally { lock.unlock(); } }
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 CuratorZookeeperClient(URL url) { super(url); try { int timeout = url.getParameter(Constants.TIMEOUT_KEY, 5000); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(url.getBackupAddress()) .retryPolicy(new RetryNTimes(1, 1000)) .connectionTimeoutMs(timeout); String authority = url.getAuthority(); if (authority != null && authority.length() > 0) { builder = builder.authorization("digest", authority.getBytes()); } client = builder.build(); client.getConnectionStateListenable().addListener(new ConnectionStateListener() { @Override public void stateChanged(CuratorFramework client, ConnectionState state) { if (state == ConnectionState.LOST) { CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED); } else if (state == ConnectionState.CONNECTED) { CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED); } else if (state == ConnectionState.RECONNECTED) { CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED); } } }); client.start(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
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(); }
public CuratorZookeeperClient(URL url) { super(url); try { int timeout = url.getParameter(Constants.TIMEOUT_KEY, 5000); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(url.getBackupAddress()) .retryPolicy(new RetryNTimes(1, 1000)) .connectionTimeoutMs(timeout); String authority = url.getAuthority(); if (authority != null && authority.length() > 0) { builder = builder.authorization("digest", authority.getBytes()); } client = builder.build(); client.getConnectionStateListenable().addListener(new ConnectionStateListener() { @Override public void stateChanged(CuratorFramework client, ConnectionState state) { if (state == ConnectionState.LOST) { CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED); } else if (state == ConnectionState.CONNECTED) { CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED); } else if (state == ConnectionState.RECONNECTED) { CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED); } } }); client.start(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
.builder() .connectString(zkConfig.getHosts()) .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMs(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepMs())) .namespace(zkConfig.getNamespace()); client = builder.build(); Logs.RSD.info("init zk client, config={}", zkConfig.toString());
private CuratorFramework getSession() { if (zkSession == null || zkSession.getState() == CuratorFrameworkState.STOPPED) { synchronized (this) { if (zkSession == null || zkSession.getState() == CuratorFrameworkState.STOPPED) { zkSession = CuratorFrameworkFactory.builder().connectString(zkConnectString) .connectionTimeoutMs(connectTimeoutMillis).aclProvider(aclDefaultProvider) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); zkSession.start(); } } } return zkSession; }
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(); }
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); }