use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project helios by spotify.
the class MasterService method setupZookeeperClient.
/**
* Create a Zookeeper client and create the control and state nodes if needed.
*
* @param config The service configuration.
*
* @return A zookeeper client.
*/
private ZooKeeperClient setupZookeeperClient(final MasterConfig config) {
ACLProvider aclProvider = null;
List<AuthInfo> authorization = null;
final String masterUser = config.getZookeeperAclMasterUser();
final String masterPassword = config.getZooKeeperAclMasterPassword();
final String agentUser = config.getZookeeperAclAgentUser();
final String agentDigest = config.getZooKeeperAclAgentDigest();
if (!isNullOrEmpty(masterPassword)) {
if (isNullOrEmpty(masterUser)) {
throw new HeliosRuntimeException("Master username must be set if a password is set");
}
authorization = Lists.newArrayList(new AuthInfo("digest", String.format("%s:%s", masterUser, masterPassword).getBytes()));
}
if (config.isZooKeeperEnableAcls()) {
if (isNullOrEmpty(masterUser) || isNullOrEmpty(masterPassword)) {
throw new HeliosRuntimeException("ZooKeeper ACLs enabled but master username and/or password not set");
}
if (isNullOrEmpty(agentUser) || isNullOrEmpty(agentDigest)) {
throw new HeliosRuntimeException("ZooKeeper ACLs enabled but agent username and/or digest not set");
}
aclProvider = heliosAclProvider(masterUser, digest(masterUser, masterPassword), agentUser, agentDigest);
}
final RetryPolicy zooKeeperRetryPolicy = new ExponentialBackoffRetry(1000, 3);
final CuratorFramework curator = curatorClientFactory.newClient(config.getZooKeeperConnectionString(), config.getZooKeeperSessionTimeoutMillis(), config.getZooKeeperConnectionTimeoutMillis(), zooKeeperRetryPolicy, aclProvider, authorization);
final ZooKeeperClient client = new DefaultZooKeeperClient(curator, config.getZooKeeperClusterId());
client.start();
zkRegistrar = ZooKeeperRegistrarService.newBuilder().setZooKeeperClient(client).setZooKeeperRegistrar(new MasterZooKeeperRegistrar(config.getName())).build();
// place where we have access to the ACL provider.
if (aclProvider != null) {
// effects are limited to a spurious log line.
try {
final List<ACL> curAcls = client.getAcl("/");
final List<ACL> wantedAcls = aclProvider.getAclForPath("/");
if (!Sets.newHashSet(curAcls).equals(Sets.newHashSet(wantedAcls))) {
log.info("Current ACL's on the zookeeper root node differ from desired, updating: {} -> {}", curAcls, wantedAcls);
client.getCuratorFramework().setACL().withACL(wantedAcls).forPath("/");
}
} catch (Exception e) {
log.error("Failed to get/set ACLs on the zookeeper root node", e);
}
}
return client;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project helios by spotify.
the class DeploymentGroupTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
zkServer = new TestingServer(true);
final CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(zkServer.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
client = new DefaultZooKeeperClient(curatorFramework);
client.start();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project exhibitor by soabase.
the class Exhibitor method getLocalConnection.
/**
* 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;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZKTools method testTreeCache.
public static void testTreeCache() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
CountDownLatch latch = new CountDownLatch(1);
TreeCache treeCache = TreeCache.newBuilder(client, "/dubbo/config").setCacheData(true).build();
treeCache.start();
treeCache.getListenable().addListener(new TreeCacheListener() {
@Override
public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
TreeCacheEvent.Type type = event.getType();
ChildData data = event.getData();
if (type == TreeCacheEvent.Type.INITIALIZED) {
latch.countDown();
}
System.out.println(data.getPath() + "\n");
if (data.getPath().split("/").length == 5) {
byte[] value = data.getData();
String stringValue = new String(value, StandardCharsets.UTF_8);
// fire event to all listeners
Map<String, Object> added = null;
Map<String, Object> changed = null;
Map<String, Object> deleted = null;
switch(type) {
case NODE_ADDED:
added = new HashMap<>(1);
added.put(pathToKey(data.getPath()), stringValue);
added.forEach((k, v) -> System.out.println(k + " " + v));
break;
case NODE_REMOVED:
deleted = new HashMap<>(1);
deleted.put(pathToKey(data.getPath()), stringValue);
deleted.forEach((k, v) -> System.out.println(k + " " + v));
break;
case NODE_UPDATED:
changed = new HashMap<>(1);
changed.put(pathToKey(data.getPath()), stringValue);
changed.forEach((k, v) -> System.out.println(k + " " + v));
}
}
}
});
latch.await();
/* Map<String, ChildData> dataMap = treeCache.getCurrentChildren("/dubbo/config");
dataMap.forEach((k, v) -> {
System.out.println(k);
treeCache.getCurrentChildren("/dubbo/config/" + k).forEach((ck, cv) -> {
System.out.println(ck);
});
});*/
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZKTools method main.
public static void main(String[] args) throws Exception {
client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
client.getCuratorListenable().addListener(new CuratorListener() {
@Override
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception {
System.out.println("event notification: " + event.getPath());
System.out.println(event);
}
}, executor);
testMigrationRule();
// tesConditionRule();
// testStartupConfig();
// testProviderConfig();
// testPathCache();
// testTreeCache();
// testCuratorListener();
// Thread.sleep(100000);
}
Aggregations