public static CuratorFramework newCurator(Map<String, Object> conf, List<String> servers, Object port, String root, List<ACL> defaultAcl) { return newCurator(conf, servers, port, root, null, defaultAcl); }
public static void testSetupBuilder(CuratorFrameworkFactory.Builder builder, String zkStr, Map<String, Object> conf, ZookeeperAuthInfo auth) { setupBuilder(builder, zkStr, conf, auth); }
protected TransactionalState(Map<String, Object> conf, String id, String subroot) { try { conf = new HashMap<>(conf); String transactionalRoot = (String) conf.get(Config.TRANSACTIONAL_ZOOKEEPER_ROOT); String rootDir = transactionalRoot + "/" + id + "/" + subroot; List<String> servers = (List<String>) getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, Config.STORM_ZOOKEEPER_SERVERS); Object port = getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_PORT, Config.STORM_ZOOKEEPER_PORT); ZookeeperAuthInfo auth = new ZookeeperAuthInfo(conf); CuratorFramework initter = CuratorUtils.newCuratorStarted(conf, servers, port, auth, DaemonType.WORKER.getDefaultZkAcls(conf)); _zkAcls = Utils.getWorkerACL(conf); try { TransactionalState.createNode(initter, transactionalRoot, null, null, null); } catch (KeeperException.NodeExistsException e) { } try { TransactionalState.createNode(initter, rootDir, null, _zkAcls, null); } catch (KeeperException.NodeExistsException e) { } initter.close(); _curator = CuratorUtils.newCuratorStarted(conf, servers, port, rootDir, auth, DaemonType.WORKER.getDefaultZkAcls(conf)); } catch (Exception e) { throw new RuntimeException(e); } }
private CuratorFrameworkFactory.Builder setupBuilder(boolean withExhibitor, boolean withAuth) { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); Map<String, Object> conf = new HashMap<String, Object>(); if (withExhibitor) { conf.put(Config.STORM_EXHIBITOR_SERVERS, "foo"); conf.put(Config.STORM_EXHIBITOR_PORT, 0); conf.put(Config.STORM_EXHIBITOR_URIPATH, "/exhibitor"); conf.put(Config.STORM_EXHIBITOR_POLL, 0); conf.put(Config.STORM_EXHIBITOR_RETRY_INTERVAL, 0); conf.put(Config.STORM_EXHIBITOR_RETRY_INTERVAL_CEILING, 0); conf.put(Config.STORM_EXHIBITOR_RETRY_TIMES, 0); } conf.put(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT, 0); conf.put(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT, 0); conf.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL, 0); conf.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING, 0); conf.put(Config.STORM_ZOOKEEPER_RETRY_TIMES, 0); String zkStr = new String("zk_connection_string"); ZookeeperAuthInfo auth = null; if (withAuth) { auth = new ZookeeperAuthInfo("scheme", "abc".getBytes()); } CuratorUtils.testSetupBuilder(builder, zkStr, conf, auth); return builder; } }
public static CuratorFramework newCurator(Map<String, Object> conf, List<String> servers, Object port, ZookeeperAuthInfo auth, List<ACL> defaultAcl) { return newCurator(conf, servers, port, "", auth, defaultAcl); }
public static CuratorFramework newCurator(Map<String, Object> conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth, final List<ACL> defaultAcl) { List<String> serverPorts = new ArrayList<>(); for (String zkServer : servers) { serverPorts.add(zkServer + ":" + ObjectReader.getInt(port)); } String zkStr = StringUtils.join(serverPorts, ",") + root; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); setupBuilder(builder, zkStr, conf, auth); if (defaultAcl != null) { builder.aclProvider(new ACLProvider() { @Override public List<ACL> getDefaultAcl() { return defaultAcl; } @Override public List<ACL> getAclForPath(String s) { return null; } }); } return builder.build(); }
public static CuratorFramework newCuratorStarted(Map<String, Object> conf, List<String> servers, Object port, ZookeeperAuthInfo auth, List<ACL> defaultAcl) { CuratorFramework ret = newCurator(conf, servers, port, auth, defaultAcl); LOG.info("Starting Utils Curator (2)..."); ret.start(); return ret; } }
public static CuratorFramework newCuratorStarted(Map<String, Object> conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth, List<ACL> defaultAcl) { CuratorFramework ret = newCurator(conf, servers, port, root, auth, defaultAcl); LOG.info("Starting Utils Curator..."); ret.start(); return ret; }
public static CuratorFramework createZKClient(Map<String, Object> conf, DaemonType type) { @SuppressWarnings("unchecked") List<String> zkServers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS); Object port = conf.get(Config.STORM_ZOOKEEPER_PORT); ZookeeperAuthInfo zkAuthInfo = new ZookeeperAuthInfo(conf); CuratorFramework zkClient = CuratorUtils.newCurator(conf, zkServers, port, (String) conf.get(Config.STORM_ZOOKEEPER_ROOT), zkAuthInfo, type.getDefaultZkAcls(conf)); zkClient.start(); return zkClient; }
public CuratorFramework mkClientImpl(Map<String, Object> conf, List<String> servers, Object port, String root, final WatcherCallBack watcher, Map<String, Object> authConf, DaemonType type) { CuratorFramework fk; if (authConf != null) { fk = CuratorUtils.newCurator(conf, servers, port, root, new ZookeeperAuthInfo(authConf), type.getDefaultZkAcls(conf)); } else { fk = CuratorUtils.newCurator(conf, servers, port, root, null, type.getDefaultZkAcls(conf)); } fk.getCuratorListenable().addListener((unused, e) -> { if (e.getType().equals(CuratorEventType.WATCHED)) { WatchedEvent event = e.getWatchedEvent(); watcher.execute(event.getState(), event.getType(), event.getPath()); } }); LOG.info("Starting ZK Curator"); fk.start(); return fk; } }
@Test public void newCuratorUsesExponentialBackoffTest() throws InterruptedException { final int expectedInterval = 2400; final int expectedRetries = 10; final int expectedCeiling = 3000; Map<String, Object> config = Utils.readDefaultConfig(); config.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL, expectedInterval); config.put(Config.STORM_ZOOKEEPER_RETRY_TIMES, expectedRetries); config.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING, expectedCeiling); CuratorFramework curator = CuratorUtils.newCurator(config, Arrays.asList("bogus_server"), 42, "", DaemonType.WORKER.getDefaultZkAcls(config)); StormBoundedExponentialBackoffRetry policy = (StormBoundedExponentialBackoffRetry) curator.getZookeeperClient().getRetryPolicy(); Assert.assertEquals(policy.getBaseSleepTimeMs(), expectedInterval); Assert.assertEquals(policy.getN(), expectedRetries); Assert.assertEquals(policy.getSleepTimeMs(10, 0), expectedCeiling); }