public void start() { zkClient.startAndWait(); }
@Override public void close() throws IOException { zkClient.stopAndWait(); }
@Override public Supplier<ZooKeeper> getZooKeeperSupplier() { return delegate.getZooKeeperSupplier(); }
@Override public Cancellable register(Discoverable discoverable) { if (!zkClient.isRunning()) { zkClient.startAndWait(); } return delegate.register(discoverable); } };
@Override protected final void startUp() throws Exception { zkClientService.startAndWait(); try { delegate.startAndWait(); } catch (Exception e) { try { zkClientService.stopAndWait(); } catch (Exception se) { e.addSuppressed(se); } throw e; } }
for (int i = 0; i < 2; i++) { ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); KillZKSession.kill(zkClients.get(follower).getZooKeeperSupplier().get(), zkClients.get(follower).getConnectString(), 10000); } finally { for (ZKClientService zkClient : zkClients) { zkClient.stopAndWait();
zkClientService.startAndWait(); Assert.assertTrue(zkClientService.isRunning()); Assert.assertTrue(zkClientService.isRunning()); zkClientService.stopAndWait();
@Test public void testCreateOrSet() throws Exception { String path = "/parent/testCreateOrSet"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.createOrSet(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue()); // Should get "1" back Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); // Set with "2" Assert.assertEquals(2, ZKExtOperations.createOrSet(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue()); // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); zkClient.stopAndWait(); }
@Before public void beforeTest() throws Exception { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); CConfiguration cConf = CConfiguration.create(); String kafkaZKNamespace = cConf.get(KafkaConstants.ConfigKeys.ZOOKEEPER_NAMESPACE_CONFIG); kafkaZKConnect = zkServer.getConnectionStr(); if (kafkaZKNamespace != null) { ZKClientService zkClient = new DefaultZKClientService(zkServer.getConnectionStr(), 2000, null, ImmutableMultimap.<String, byte[]>of()); zkClient.startAndWait(); zkClient.create("/" + kafkaZKNamespace, null, CreateMode.PERSISTENT); zkClient.stopAndWait(); kafkaZKConnect += "/" + kafkaZKNamespace; } kafkaServer = createKafkaServer(kafkaZKConnect, TEMP_FOLDER.newFolder()); kafkaServer.startAndWait(); }
private void startUp() throws Exception { zkClientService.startAndWait(); ZKOperations.ignoreError(zkClientService.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();
client.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, path).get(); client.stopAndWait(); zkConnectStr = String.format("%s/%s", zkConnectStr, zkNamespace); } catch (Exception e) { throw Throwables.propagate(e); } finally { client.stopAndWait();
private void expireZkSession(ZKClientService zkClientService) throws Exception { ZooKeeper zooKeeper = zkClientService.getZooKeeperSupplier().get(); final SettableFuture<?> connectFuture = SettableFuture.create(); Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.SyncConnected) { connectFuture.set(null); } } }; // Create another Zookeeper session with the same sessionId so that the original one expires. final ZooKeeper dupZookeeper = new ZooKeeper(zkClientService.getConnectString(), zooKeeper.getSessionTimeout(), watcher, zooKeeper.getSessionId(), zooKeeper.getSessionPasswd()); connectFuture.get(30, TimeUnit.SECONDS); Assert.assertEquals("Failed to re-create current session", dupZookeeper.getState(), ZooKeeper.States.CONNECTED); dupZookeeper.close(); }
@Override public boolean isRunning() { return delegate.isRunning(); }
return new YarnTwillPreparer(config, twillSpec, runId, zkClientService.getConnectString(), appLocation, jvmOptions, locationCache, new YarnTwillControllerFactory() { @Override
@Override public void start() throws Exception { logAppenderInitializer.initialize(); resetShutdownTime(); createDirectory("twill"); createSystemHBaseNamespace(); updateConfigurationTable(); Services.startAndWait(zkClient, cConf.getLong(Constants.Zookeeper.CLIENT_STARTUP_TIMEOUT_MILLIS), TimeUnit.MILLISECONDS, String.format("Connection timed out while trying to start ZooKeeper client. Please " + "verify that the ZooKeeper quorum settings are correct in cdap-site.xml. " + "Currently configured as: %s", cConf.get(Constants.Zookeeper.QUORUM))); // Tries to create the ZK root node (which can be namespaced through the zk connection string) Futures.getUnchecked(ZKOperations.ignoreError(zkClient.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null)); electionInfoService.startAndWait(); leaderElection.startAndWait(); }
@Override protected final void startUp() throws Exception { zkClientService.startAndWait(); try { delegate.startAndWait(); } catch (Exception e) { try { zkClientService.stopAndWait(); } catch (Exception se) { e.addSuppressed(se); } throw e; } }
zkClient1.startAndWait(); zkClient2.startAndWait(); KillZKSession.kill(zkClient1.getZooKeeperSupplier().get(), zkClient1.getConnectString(), 10000); zkClient1.stopAndWait(); zkClient2.stopAndWait();
zkClientService.startAndWait(); Assert.assertTrue(zkClientService.isRunning()); Assert.assertTrue(zkClientService.isRunning()); zkClientService.stopAndWait();
@Override public Cancellable register(Discoverable discoverable) { if (!zkClient.isRunning()) { zkClient.startAndWait(); } return delegate.register(discoverable); } };
@Test public void testSetOrCreate() throws Exception { String path = "/parent/testSetOrCreate"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue()); // Should get "1" back Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); // Set with "2" Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue()); // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); zkClient.stopAndWait(); }