use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class ZKSegmentContainerManagerTest method startClient.
private CuratorFramework startClient() {
val client = CuratorFrameworkFactory.newClient(zkUrl, new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY));
client.start();
return client;
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class BookKeeperRunner method initialize.
public void initialize() throws Exception {
// BookKeeper
// Pick random ports to reduce chances of collisions during concurrent test executions.
int zkPort = TestUtils.getAvailableListenPort();
val bookiePorts = new ArrayList<Integer>();
for (int i = 0; i < this.bookieCount; i++) {
bookiePorts.add(TestUtils.getAvailableListenPort());
}
this.bkRunner = BookKeeperServiceRunner.builder().startZk(true).zkPort(zkPort).secureZK(false).secureBK(false).ledgersPath("/ledgers/" + zkPort).bookiePorts(bookiePorts).build();
this.bkRunner.startAll();
// Create a ZKClient with a base namespace.
String baseNamespace = "pravega/" + zkPort;
this.zkClient = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).namespace(baseNamespace).retryPolicy(new ExponentialBackoffRetry(1000, 5)).connectionTimeoutMs(5000).sessionTimeoutMs(5000).build();
this.zkClient.start();
// Attach a sub-namespace for the Container Metadata.
String logMetaNamespace = "segmentstore/containers";
this.configBuilder.include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + zkPort).with(BookKeeperConfig.ZK_METADATA_PATH, logMetaNamespace).with(BookKeeperConfig.BK_LEDGER_PATH, "/ledgers/" + zkPort).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, this.bookieCount).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, this.bookieCount).with(BookKeeperConfig.BK_ENSEMBLE_SIZE, this.bookieCount));
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class InProcPravegaCluster method cleanUpZK.
private void cleanUpZK() {
String[] pathsTobeCleaned = { "/pravega", "/hostIndex", "/store", "/taskIndex" };
RetryPolicy rp = new ExponentialBackoffRetry(1000, 3);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zkUrl).connectionTimeoutMs(5000).sessionTimeoutMs(5000).retryPolicy(rp);
if (secureZK) {
ZKTLSUtils.setSecureZKClientProperties(jksTrustFile, "1111_aaaa");
}
@Cleanup CuratorFramework zclient = builder.build();
zclient.start();
for (String path : pathsTobeCleaned) {
try {
zclient.delete().guaranteed().deletingChildrenIfNeeded().forPath(path);
} catch (Exception e) {
log.warn("Not able to delete path {} . Exception {}", path, e.getMessage());
}
}
zclient.close();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project sofa-ark by alipay.
the class ZookeeperConfigActivator method start.
@Override
public void start(final PluginContext context) {
if (!enableZkServer) {
LOGGER.warn("config server is disabled.");
return;
}
String config = ArkConfigs.getStringValue(Constants.CONFIG_SERVER_ADDRESS);
RegistryConfig registryConfig = ZookeeperConfigurator.buildConfig(config);
String address = registryConfig.getAddress();
int idx = address.indexOf(Constants.ZOOKEEPER_CONTEXT_SPLIT);
if (idx != -1) {
rootPath = address.substring(idx);
if (!rootPath.endsWith(Constants.ZOOKEEPER_CONTEXT_SPLIT)) {
rootPath += Constants.ZOOKEEPER_CONTEXT_SPLIT;
}
address = address.substring(0, idx);
}
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFrameworkFactory.Builder zkClientBuilder = CuratorFrameworkFactory.builder().connectString(address).sessionTimeoutMs(3 * registryConfig.getConnectTimeout()).connectionTimeoutMs(registryConfig.getConnectTimeout()).canBeReadOnly(false).retryPolicy(retryPolicy).defaultData(null);
List<AuthInfo> authInfos = buildAuthInfo(registryConfig);
if (!authInfos.isEmpty()) {
zkClientBuilder = zkClientBuilder.aclProvider(getDefaultAclProvider()).authorization(authInfos);
}
zkClient = zkClientBuilder.build();
zkClient.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
LOGGER.info("Reconnect to zookeeper, re-register config resource.");
if (newState == ConnectionState.RECONNECTED) {
unSubscribeIpConfig();
registryResource(ipResourcePath, CreateMode.EPHEMERAL);
subscribeIpConfig();
}
}
});
zkClient.start();
registryResource(bizResourcePath, CreateMode.PERSISTENT);
registryResource(ipResourcePath, CreateMode.EPHEMERAL);
subscribeIpConfig();
subscribeBizConfig();
registerEventHandler(context);
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project hive by apache.
the class TestZooKeeperTokenStore method setUp.
@Override
protected void setUp() throws Exception {
File zkDataDir = new File(System.getProperty("test.tmp.dir"));
if (this.zkCluster != null) {
throw new IOException("Cluster already running");
}
this.zkCluster = new MiniZooKeeperCluster();
this.zkPort = this.zkCluster.startup(zkDataDir);
this.zkClient = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
this.zkClient.start();
}
Aggregations