public static boolean waitForServerUp(int zkPort) { return waitForServerUp(zkPort, false, "", "", "", ""); }
/** * 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.trustStore, this.keyStore, this.keyStorePassword, this.keyStorePassword)) { throw new IllegalStateException("ZooKeeper server failed to start"); } }
private void startZooKeeper() throws Exception { Preconditions.checkState(this.zooKeeperProcess.get() == null, "ZooKeeper is already started."); this.zooKeeperProcess.set(ProcessStarter .forClass(ZooKeeperServiceRunner.class) .sysProp(ZooKeeperServiceRunner.PROPERTY_ZK_PORT, this.testConfig.getZkPort()) .stdOut(ProcessBuilder.Redirect.to(new File(this.testConfig.getComponentOutLogPath("zk", 0)))) .stdErr(ProcessBuilder.Redirect.to(new File(this.testConfig.getComponentErrLogPath("zk", 0)))) .start()); if (!ZooKeeperServiceRunner.waitForServerUp(this.testConfig.getZkPort())) { throw new RuntimeException("Unable to start ZooKeeper at port " + this.testConfig.getZkPort()); } log("ZooKeeper started (Port = %s).", this.testConfig.getZkPort()); }
/** * Starts a BookKeeper (using a number of bookies) along with a ZooKeeper out-of-process. * * @param config The Test Config to use. This indicates the BK Port(s), ZK Port, as well as Bookie counts. * @param logId A String to use for logging purposes. * @return A Process referring to the newly started Bookie process. * @throws IOException If an error occurred. */ static Process startBookKeeperOutOfProcess(TestConfig config, String logId) throws IOException { int bookieCount = config.getBookieCount(); Process p = ProcessStarter .forClass(BookKeeperServiceRunner.class) .sysProp(BookKeeperServiceRunner.PROPERTY_BASE_PORT, config.getBkPort(0)) .sysProp(BookKeeperServiceRunner.PROPERTY_BOOKIE_COUNT, bookieCount) .sysProp(BookKeeperServiceRunner.PROPERTY_ZK_PORT, config.getZkPort()) .sysProp(BookKeeperServiceRunner.PROPERTY_LEDGERS_PATH, TestConfig.BK_LEDGER_PATH) .sysProp(BookKeeperServiceRunner.PROPERTY_START_ZK, true) .stdOut(ProcessBuilder.Redirect.to(new File(config.getComponentOutLogPath("bk", 0)))) .stdErr(ProcessBuilder.Redirect.to(new File(config.getComponentErrLogPath("bk", 0)))) .start(); ZooKeeperServiceRunner.waitForServerUp(config.getZkPort()); TestLogger.log(logId, "Zookeeper (Port %s) and BookKeeper (Ports %s-%s) started.", config.getZkPort(), config.getBkPort(0), config.getBkPort(bookieCount - 1)); return p; } }