org.apache.zookeeper.server.ZooKeeperServer Java Examples
The following examples show how to use
org.apache.zookeeper.server.ZooKeeperServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MiniZKFCCluster.java From big-c with Apache License 2.0 | 6 votes |
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) { this.conf = conf; // Fast check interval so tests run faster conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50); conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50); conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50); svcs = new DummyHAService[2]; svcs[0] = new DummyHAService(HAServiceState.INITIALIZING, new InetSocketAddress("svc1", 1234)); svcs[0].setSharedResource(sharedResource); svcs[1] = new DummyHAService(HAServiceState.INITIALIZING, new InetSocketAddress("svc2", 1234)); svcs[1].setSharedResource(sharedResource); this.ctx = new TestContext(); this.zks = zks; }
Example #2
Source File: CCEmbeddedZookeeper.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
public CCEmbeddedZookeeper() { int tickTime = 500; try { File snapshotDir = CCKafkaTestUtils.newTempDir(); File logDir = CCKafkaTestUtils.newTempDir(); _zk = new ZooKeeperServer(snapshotDir, logDir, tickTime); _cnxnFactory = new NIOServerCnxnFactory(); InetAddress localHost = InetAddress.getLocalHost(); _hostAddress = localHost.getHostAddress(); InetSocketAddress bindAddress = new InetSocketAddress(localHost, 0); _cnxnFactory.configure(bindAddress, 0); _cnxnFactory.startup(_zk); _port = _zk.getClientPort(); } catch (Exception e) { throw new IllegalStateException(e); } //sanity check if (_zk.getClientPort() != _port) { throw new IllegalStateException(); } }
Example #3
Source File: ZookeeperServerTest.java From pulsar with Apache License 2.0 | 6 votes |
public void start() throws IOException { try { // Allow all commands on ZK control port System.setProperty("zookeeper.4lw.commands.whitelist", "*"); // disable the admin server as to not have any port conflicts System.setProperty("zookeeper.admin.enableServer", "false"); zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME); zks.setMaxSessionTimeout(20000); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(zkPort), 1000); serverFactory.startup(zks); } catch (Exception e) { log.error("Exception while instantiating ZooKeeper", e); } this.zkPort = serverFactory.getLocalPort(); this.hostPort = "127.0.0.1:" + zkPort; LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000); log.info("ZooKeeper started at {}", hostPort); }
Example #4
Source File: EmbeddedZooKeeper.java From ameliant-tools with Apache License 2.0 | 6 votes |
@Override protected void before() throws Throwable { snapshotDir = tempDir(perTest("zk-snapshot")); logDir = tempDir(perTest("zk-log")); log.info("Setting up ZK Server with snapshotDir:{}, logDir:{}", snapshotDir, logDir); int tickTime = 500; try { zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime); cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(new InetSocketAddress("127.0.0.1", port), 0); cnxnFactory.startup(zooKeeperServer); } catch (IOException e) { e.printStackTrace(); } }
Example #5
Source File: ServerHelper.java From xian with Apache License 2.0 | 6 votes |
static Object makeFactory(ZooKeeperServer server, int port) throws Exception { Object factory; if ( nioServerCnxn != null ) { factory = nioServerCnxn.constructor.newInstance(new InetSocketAddress(port)); if ( server != null ) { nioServerCnxn.startupMethod.invoke(factory, server); } } else { factory = serverCnxnFactoryMethods.constructor.newInstance(); serverCnxnFactoryMethods.configureMethod.invoke(factory, new InetSocketAddress(port), 0); if ( server != null ) { serverCnxnFactoryMethods.startupMethod.invoke(factory, server); } } return factory; }
Example #6
Source File: KafkaOperatorTestBase.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
Example #7
Source File: EmbeddedZooKeeper.java From karaf-decanter with Apache License 2.0 | 6 votes |
@Override public void before() throws IOException { snapshotDir = new File("target/test-classes/zk-snapshot"); snapshotDir.mkdirs(); logDir = new File("target/test-classes/zk-log"); logDir.mkdirs(); try { zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime); cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(new InetSocketAddress("localhost", port), 1024); cnxnFactory.startup(zooKeeperServer); } catch (InterruptedException e) { throw new IOException(e); } }
Example #8
Source File: ServerHelper.java From curator with Apache License 2.0 | 6 votes |
static Object makeFactory(ZooKeeperServer server, int port) throws Exception { Object factory; if ( nioServerCnxn != null ) { factory = nioServerCnxn.constructor.newInstance(new InetSocketAddress(port)); if ( server != null ) { nioServerCnxn.startupMethod.invoke(factory, server); } } else { factory = serverCnxnFactoryMethods.constructor.newInstance(); serverCnxnFactoryMethods.configureMethod.invoke(factory, new InetSocketAddress(port), 0); if ( server != null ) { serverCnxnFactoryMethods.startupMethod.invoke(factory, server); } } return factory; }
Example #9
Source File: MiniAvatarCluster.java From RDFS with Apache License 2.0 | 6 votes |
public static void createAndStartZooKeeper() throws IOException, ConfigException, InterruptedException { ServerConfig zkConf = createZooKeeperConf(); zooKeeper = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(zkConf.getDataLogDir()), new File(zkConf.getDataDir())); zooKeeper.setTxnLogFactory(ftxn); zooKeeper.setTickTime(zkConf.getTickTime()); zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout()); zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout()); cnxnFactory = new NIOServerCnxn.Factory(zkConf.getClientPortAddress(), zkConf.getMaxClientCnxns()); cnxnFactory.startup(zooKeeper); }
Example #10
Source File: KafkaOperatorTestBase.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
Example #11
Source File: EmbeddedZooKeeper.java From centraldogma with Apache License 2.0 | 6 votes |
@Nullable private static DataTree dataTree(@Nullable EmbeddedZooKeeper peer) { if (peer == null) { return null; } final ZooKeeperServer activeServer = peer.getActiveServer(); if (activeServer == null) { return null; } final ZKDatabase database = activeServer.getZKDatabase(); if (database == null) { return null; } return database.getDataTree(); }
Example #12
Source File: TestCurrentInprogress.java From hadoop with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { LOG.info("Starting ZK server"); zkTmpDir = File.createTempFile("zookeeper", "test"); zkTmpDir.delete(); zkTmpDir.mkdir(); try { zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example #13
Source File: TestBookKeeperConfiguration.java From hadoop with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.info("Starting ZK server"); ZkTmpDir = File.createTempFile("zookeeper", "test"); ZkTmpDir.delete(); ZkTmpDir.mkdir(); try { zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example #14
Source File: ClientBaseWithFixes.java From hadoop with Apache License 2.0 | 6 votes |
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb; { ZooKeeperServer zs = getServer(factory); zkDb = zs.getZKDatabase(); } factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } }
Example #15
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ private void shutdownServerInstance(ServerCnxnFactory factory) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) zkDb = zs.getZKDatabase(); } factory.shutdown(); try { if (zkDb != null) zkDb.close(); } catch (IOException ie) { // ignore } } }
Example #16
Source File: ClientBaseWithFixes.java From big-c with Apache License 2.0 | 6 votes |
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb; { ZooKeeperServer zs = getServer(factory); zkDb = zs.getZKDatabase(); } factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } }
Example #17
Source File: ClientBaseWithFixes.java From big-c with Apache License 2.0 | 6 votes |
static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); final int PORT = getPort(hostPort); if (factory == null) { factory = ServerCnxnFactory.createFactory(PORT, maxCnxns); } factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); return factory; }
Example #18
Source File: TestBookKeeperConfiguration.java From big-c with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.info("Starting ZK server"); ZkTmpDir = File.createTempFile("zookeeper", "test"); ZkTmpDir.delete(); ZkTmpDir.mkdir(); try { zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example #19
Source File: TestCurrentInprogress.java From big-c with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { LOG.info("Starting ZK server"); zkTmpDir = File.createTempFile("zookeeper", "test"); zkTmpDir.delete(); zkTmpDir.mkdir(); try { zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example #20
Source File: EmbeddedZookeeper.java From li-apache-kafka-clients with BSD 2-Clause "Simplified" License | 6 votes |
/** * starting with ZK 3.4.9 there's a shutdown handler. * if one isnt registered ZK will spew errors at shutdown time, even though * both the handler interface and the method of registering one are not public API. * see https://issues.apache.org/jira/browse/ZOOKEEPER-2795 * such craftsmanship. much wow. * @param zk a ZK server instance * @throws Exception if anything goes wrong */ private void registerShutdownHandler(ZooKeeperServer zk) throws Exception { Class<?> handlerClass; try { handlerClass = Class.forName("org.apache.zookeeper.server.ZooKeeperServerShutdownHandler"); } catch (ClassNotFoundException e) { //older ZK. forget about it return; } Method registerMethod = ZooKeeperServer.class.getDeclaredMethod("registerServerShutdownHandler", handlerClass); Constructor<?> ctr = handlerClass.getDeclaredConstructor(CountDownLatch.class); ctr.setAccessible(true); shutdownLatch = new CountDownLatch(1); Object handlerInstance = ctr.newInstance(shutdownLatch); registerMethod.setAccessible(true); registerMethod.invoke(zk, handlerInstance); }
Example #21
Source File: EmbeddedZookeeper.java From li-apache-kafka-clients with BSD 2-Clause "Simplified" License | 6 votes |
public EmbeddedZookeeper() { try { snapshotDir = KafkaTestUtils.newTempDir(); logDir = KafkaTestUtils.newTempDir(); tickTime = 500; zk = new ZooKeeperServer(snapshotDir, logDir, tickTime); registerShutdownHandler(zk); cnxnFactory = new NIOServerCnxnFactory(); InetAddress localHost = InetAddress.getLocalHost(); hostAddress = localHost.getHostAddress(); InetSocketAddress bindAddress = new InetSocketAddress(localHost, port); cnxnFactory.configure(bindAddress, 0); cnxnFactory.startup(zk); port = zk.getClientPort(); } catch (Exception e) { throw new IllegalStateException(e); } //sanity check if (zk.getClientPort() != port) { throw new IllegalStateException(); } }
Example #22
Source File: ZooKeeperServiceRunner.java From pravega with Apache License 2.0 | 6 votes |
/** * Starts the ZooKeeper Service in process. * * @throws Exception If an exception occurred. */ public void start() throws Exception { Preconditions.checkState(this.tmpDir.get() != null, "Not Initialized."); val s = new ZooKeeperServer(this.tmpDir.get(), this.tmpDir.get(), ZooKeeperServer.DEFAULT_TICK_TIME); if (!this.server.compareAndSet(null, s)) { s.shutdown(); throw new IllegalStateException("Already started."); } this.serverFactory.set(NettyServerCnxnFactory.createFactory()); val address = LOOPBACK_ADDRESS + ":" + this.zkPort; log.info("Starting Zookeeper server at " + address + " ..."); this.serverFactory.get().configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000, secureZK); this.serverFactory.get().startup(s); if (!waitForServerUp(this.zkPort, this.secureZK, this.keyStore, this.keyStorePasswordPath, this.trustStore, this.keyStorePasswordPath)) { throw new IllegalStateException("ZooKeeper server failed to start"); } }
Example #23
Source File: ZooKeeperTestServer.java From vespa with Apache License 2.0 | 6 votes |
private ZooKeeperTestServer(int port) throws IOException { zooKeeperDir = getTempDir(); delete(zooKeeperDir); if (!zooKeeperDir.mkdir()) { throw new IllegalStateException("Failed to create directory " + zooKeeperDir); } zooKeeperDir.deleteOnExit(); server = new ZooKeeperServer(zooKeeperDir, zooKeeperDir, (int)tickTime.toMillis()); final int maxcc = 10000; // max number of connections from the same client factory = new NIOServerCnxnFactory(); factory.configure(new InetSocketAddress(port), maxcc); // Use any port try{ factory.startup(server); } catch (InterruptedException e) { throw (RuntimeException) new IllegalStateException("Interrupted during test startup: ").initCause(e); } }
Example #24
Source File: EmbeddedZookeeper.java From logback-kafka-appender with Apache License 2.0 | 6 votes |
public void startup() throws IOException{ if (this.port == -1) { this.port = TestUtils.getAvailablePort(); } this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024); this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot"); this.logDir = TestUtils.constructTempDir("embeeded-zk/log"); final ZooKeeperServer zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime); try { factory.startup(zooKeeperServer); } catch (InterruptedException e) { throw new IOException(e); } assertEquals("standalone", zooKeeperServer.getState()); assertEquals(this.port, zooKeeperServer.getClientPort()); }
Example #25
Source File: ClientBaseWithFixes.java From hadoop with Apache License 2.0 | 6 votes |
static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); final int PORT = getPort(hostPort); if (factory == null) { factory = ServerCnxnFactory.createFactory(PORT, maxCnxns); } factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); return factory; }
Example #26
Source File: EmbeddedZkServer.java From incubator-sentry with Apache License 2.0 | 5 votes |
public EmbeddedZkServer(int port) throws Exception { snapshotDir = Files.createTempDirectory("zookeeper-snapshot-"); logDir = Files.createTempDirectory("zookeeper-log-"); int tickTime = 500; zookeeper = new ZooKeeperServer(snapshotDir.toFile(), logDir.toFile(), tickTime); factory = new NIOServerCnxnFactory(); InetSocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port); LOGGER.info("Starting Zookeeper at " + addr); factory.configure(addr, 0); factory.startup(zookeeper); }
Example #27
Source File: ZookeeperServer.java From ingestion with Apache License 2.0 | 5 votes |
/** * Set embedded zookeeper up and spawn it in a new thread. * * @throws TTransportException * @throws IOException * @throws InterruptedException */ public void start() throws Exception { File dir = Files.createTempDir(); String dirPath = dir.getAbsolutePath(); System.out.println("Storing ZooKeeper files in " + dirPath); ZooKeeperServer server = new ZooKeeperServer(dir, dir, TICK_TIME); standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure(new InetSocketAddress(CLIENT_PORT), NUM_CONNECTIONS); standaloneServerFactory.startup(server); // start the server. TimeUnit.SECONDS.sleep(WAIT_SECONDS); }
Example #28
Source File: KafkaEmbeddedRule.java From devicehive-java-server with Apache License 2.0 | 5 votes |
public EmbeddedZookeeperInternal(int port) throws IOException, InterruptedException { this.port = port; logDir = TestUtils.tempDir(); snapshotDir = TestUtils.tempDir(); zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, 500); nioServerCnxnFactory = new NIOServerCnxnFactory(); InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", port); nioServerCnxnFactory.configure(inetSocketAddress, 0); nioServerCnxnFactory.startup(zooKeeperServer); }
Example #29
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void startServerInstance(File dataDir, ServerCnxnFactory factory) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); factory.startup(zks); }
Example #30
Source File: MiniZooKeeperCluster.java From hbase-tools with Apache License 2.0 | 5 votes |
/** * @throws IOException */ public void shutdown() throws IOException { if (!started) { return; } // shut down all the zk servers for (int i = 0; i < standaloneServerFactoryList.size(); i++) { NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(i); int clientPort = clientPortList.get(i); standaloneServerFactory.shutdown(); if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for shutdown of standalone server"); } } for (ZooKeeperServer zkServer: zooKeeperServers) { //explicitly close ZKDatabase since ZookeeperServer does not close them zkServer.getZKDatabase().close(); } // clear everything started = false; activeZKServerIndex = 0; standaloneServerFactoryList.clear(); clientPortList.clear(); zooKeeperServers.clear(); LOG.info("Shutdown MiniZK cluster with all ZK servers"); }