TestingServer zkTestServer; @Before public void startZookeeper() throws Exception { zkTestServer = new TestingServer(2181); cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000)); } @After public void stopZookeeper() throws IOException { cli.close(); zkTestServer.stop(); }
public static CuratorFramework createZkClient(TestingServer testingZKServer, Closer closer) throws InterruptedException { CuratorFramework curatorFramework = closer.register(CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); curatorFramework.start(); if (! curatorFramework.blockUntilConnected(60, TimeUnit.SECONDS)) { throw new RuntimeException("Time out waiting to connect to ZK!"); } return curatorFramework; } }
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(); } }
public ZookeeperClient(String zkUrl) { zookeeperConnection = zkUrl; LOG.info("Initialize curator with zkurl:" + zkUrl); curator = CuratorFrameworkFactory.newClient(zookeeperConnection, new RetryOneTime(3000)); curator.start(); }
@Before public void setup() { conf = new HiveConf(); lockObjData = new HiveLockObjectData("1", "10", "SHARED", "show tables", conf); hiveLock = new HiveLockObject(TABLE, lockObjData); zLock = new ZooKeeperHiveLock(TABLE_LOCK_PATH, hiveLock, HiveLockMode.SHARED); while (server == null) { try { server = new TestingServer(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build(); client.start(); } catch (Exception e) { System.err.println("Getting bind exception - retrying to allocate server"); server = null; } } }
public SubPubTest() throws Exception { this.testingServer = new TestingServer(); client = AsyncCuratorFramework.wrap(CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new RetryOneTime(1))); executorService = Executors.newSingleThreadScheduledExecutor(); }
LOG.info("Testing ZK Server listening on: " + testingZKServer.getConnectString()); CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); this.curatorFramework.start(); ConfigValueFactory.fromAnyRef(testingZKServer.getConnectString())) .resolve();
CuratorFramework curator = CuratorFrameworkFactory.newClient("localhost:" + TestConstants.TEST_ZOOKEEPER_PORT, new RetryOneTime(100)); curator.start(); curator.blockUntilConnected();
/** * Instantiates a new Zookeeper config provider. */ public ZookeeperConfigProvider(URI uri) throws Exception { String connectString = uri.getHost() + ":" + (uri.getPort() == -1 ? 2181 : uri.getPort()); String serviceName = uri.getPath().split("/", 2)[1]; client = CuratorFrameworkFactory.newClient(connectString, new RetryOneTime(1000)); client.start(); shutdownFunctions.add(client::close); initProvider(client, serviceName); }
public static CuratorFramework createClient(final TestingServer server) { return CuratorFrameworkFactory.newClient( server.getConnectString(), new RetryOneTime(1)); }
private 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(); }
void start() { try { server = new TestingServer(curatorPort, true); this.curator = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1000)); this.curator.start(); this.curator.blockUntilConnected(10, TimeUnit.SECONDS); initializer.accept(this); } catch (Exception ex) { throw new IllegalStateException("Failed to start Zookeeper", ex); } }
/** * create zookeeper client via config. * @param config The Gondola config * @return The ZookeeperRegistryClient instance */ public static RegistryClient createZookeeperClient(Config config) throws IOException { CuratorFramework client = CuratorFrameworkFactory.builder() .connectString(getZookeeperConnectionString(config)) .retryPolicy(new RetryOneTime(1000)) .build(); client.start(); return new ZookeeperRegistryClient(client, new ObjectMapper(), config); }
private void withZooKeeper(ZooKeeperTask task) throws HekateException { try (CuratorFramework client = CuratorFrameworkFactory.newClient( connectionString, sessionTimeout, connectTimeout, new RetryOneTime(0) )) { client.start(); try { if (!client.blockUntilConnected(connectTimeout, TimeUnit.MILLISECONDS)) { throw new HekateException("Timeout connecting to ZooKeeper [connections-string=" + connectionString + ']'); } } catch (InterruptedException e) { throw new HekateException("Thread got interrupted while connecting to ZooKeeper.", e); } task.execute(client); } }
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(); }
void start() { try { server = new TestingServer(curatorPort, true); this.curator = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1000)); this.curator.start(); this.curator.blockUntilConnected(10, TimeUnit.SECONDS); initializer.accept(this); } catch (Exception ex) { throw new IllegalStateException("Failed to start Zookeeper", ex); } }
public CuratorFramework call() throws Exception { String connectString = System.getProperty("zookeeper.url", "localhost:2181"); String password = System.getProperty("zookeeper.password"); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(connectString) .retryPolicy(new RetryOneTime(1000)) .connectionTimeoutMs(10000); if (password != null && !password.isEmpty()) { builder.authorization("digest", ("fabric:"+password).getBytes()); } CuratorFramework client = builder.build(); LOG.debug("Starting curator " + curator); client.start(); return client; }
/** * Invoke the zookeeper test, ensure zookeeper can be accessed. * The test fails in case zookeeper cannot be accessed. * */ @Test public void zkTest() { log.info("Start execution of ZkTest"); Service zk = Utils.createZookeeperService(); URI zkUri = zk.getServiceDetails().get(0); CuratorFramework curatorFrameworkClient = CuratorFrameworkFactory.newClient(zkUri.getHost() + ":2181", new RetryOneTime(5000)); curatorFrameworkClient.start(); log.info("CuratorFramework status {} ", curatorFrameworkClient.getState()); assertEquals("Connection to zk client ", STARTED, curatorFrameworkClient.getState()); log.info("Zookeeper Service URI : {} ", zkUri); log.info("ZkTest execution completed"); } }
@Override protected void before() throws Throwable { testingServer = new TestingServer(true); zkClient = new CuratorZookeeperClient(testingServer.getConnectString(), 5000, 5000, null, new RetryOneTime(1000)); zkClient.start(); zkClient.blockUntilConnectedOrTimedOut(); }
public static void clear(TestingServer testingServer) throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient( testingServer.getConnectString(), new RetryOneTime(RETRY_DELAY_MS)); client.start(); for (String rootNode : client.getChildren().forPath("/")) { if (!rootNode.equals(ZOOKEEPER_ROOT_NODE_NAME)) { client.delete().deletingChildrenIfNeeded().forPath("/" + rootNode); } } client.close(); } }