/** * @return true if the server is running, false otherwise. */ boolean isZKServerRunning() { return zkServer != null && zkServer.isRunning(); }
/** * @return true if the server is running, false otherwise. */ boolean isZKServerRunning() { return zkServer != null && zkServer.isRunning(); }
/** * @return true if the server is running, false otherwise. */ boolean isZKServerRunning() { return zkServer != null && zkServer.isRunning(); } }
/** * @return true if the server is running, false otherwise. */ boolean isZKServerRunning() { return zkServer != null && zkServer.isRunning(); } }
/** * Run the registered command with name cmdName. Commands should not produce * any exceptions; any (anticipated) errors should be reported in the * "error" entry of the returned map. Likewise, if no command with the given * name is registered, this will be noted in the "error" entry. * * @param cmdName * @param zkServer * @param kwargs String-valued keyword arguments to the command * (may be null if command requires no additional arguments) * @return Map representing response to command containing at minimum: * - "command" key containing the command's primary name * - "error" key containing a String error message or null if no error */ public static CommandResponse runCommand(String cmdName, ZooKeeperServer zkServer, Map<String, String> kwargs) { if (!commands.containsKey(cmdName)) { return new CommandResponse(cmdName, "Unknown command: " + cmdName); } if (zkServer == null || !zkServer.isRunning()) { return new CommandResponse(cmdName, "This ZooKeeper instance is not currently serving requests"); } return commands.get(cmdName).run(zkServer, kwargs); }
if (zks == null || !zks.isRunning()) { throw new IOException("ZK down");
@Before public void setUp() { outputWriter = new StringWriter(); ServerCnxn serverCnxnMock = mock(ServerCnxn.class); zks = mock(ZooKeeperServer.class); when(zks.isRunning()).thenReturn(true); serverStats = mock(ServerStats.class); when(zks.serverStats()).thenReturn(serverStats); statResetCommand = new StatResetCommand(new PrintWriter(outputWriter), serverCnxnMock); statResetCommand.setZkServer(zks); }
@Test public void testStatResetWithZKNotRunning() { // Arrange when(zks.isRunning()).thenReturn(false); // Act statResetCommand.commandRun(); // Assert String output = outputWriter.toString(); assertEquals(ZK_NOT_SERVING + "\n", output); }
@Test public void testStatResetWithFollower() { // Arrange when(zks.isRunning()).thenReturn(true); when(serverStats.getServerState()).thenReturn("follower"); // Act statResetCommand.commandRun(); // Assert String output = outputWriter.toString(); assertEquals("Server stats reset.\n", output); verify(serverStats, times(1)).reset(); }
@Override public void close() throws IOException { if (started.get() && !stopped.getAndSet(true)) { cnxnFactory.shutdown(); try { cnxnFactory.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (zkServer.isRunning()) { zkServer.shutdown(); } deleteRecursively(zkDataDir.toPath(), ALLOW_INSECURE); } }
if (zks == null || !zks.isRunning()) { throw new IOException("ZK down");
@Override public synchronized void shutdown() { if (started) { started = false; if (transactionLog != null) { try { transactionLog.close(); } catch (final IOException ioe) { logger.warn("Failed to close Transaction Log", ioe); } } if (connectionFactory != null) { connectionFactory.shutdown(); } if (quorumPeer != null && quorumPeer.isRunning()) { quorumPeer.shutdown(); } if (embeddedZkServer != null && embeddedZkServer.isRunning()) { embeddedZkServer.shutdown(); } if (datadirCleanupManager != null) { datadirCleanupManager.shutdown(); } } }
@Override public void run() { try { cnxnFactory.join(); if (zkServer.isRunning()) { zkServer.shutdown(); } } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } } });
@Override protected void destroy() throws DestroyUnitException { thread.interrupt(); if (zkServer.isRunning()) { zkServer.shutdown(); } cnxnFactory.shutdown(); try { txnLog.close(); } catch (IOException e) { throw new DestroyUnitException(e); } }
public void shutdown() throws Exception { try { connectionFactory.shutdown(); connectionFactory.join(); zkServer.shutdown(); while (zkServer.isRunning()) { zkServer.shutdown(); Thread.sleep(100); } } finally { try { cleanZookeeperDir(); } catch (Exception e) { LOG.warn("Error cleaning up ZK data directory {}", e); } } }
public void shutdown() throws Exception { try { connectionFactory.shutdown(); connectionFactory.join(); zkServer.shutdown(); while (zkServer.isRunning()) { zkServer.shutdown(); Thread.sleep(100); } } finally { try { cleanZookeeperDir(); } catch (Exception e) { LOG.warn("Error cleaning up ZK data directory {}", e); } } }
@Override public void close() { if (started.get()) { cnxnFactory.shutdown(); try { cnxnFactory.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (zkServer.isRunning()) { zkServer.shutdown(); } deleteRecursively(zkDataDir); } }
@Override public void close() throws IOException { if (started.get() && !stopped.getAndSet(true)) { cnxnFactory.shutdown(); try { cnxnFactory.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (zkServer.isRunning()) { zkServer.shutdown(); } deleteRecursively(zkDataDir.toPath(), ALLOW_INSECURE); } }
private void runFromConfig(ServerConfig config) throws IOException { zkServer = new ZooKeeperServer(); try { txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); zkServer.setTxnLogFactory(txnLog); zkServer.setTickTime(config.getTickTime()); zkServer.setMinSessionTimeout(config.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer); } catch (InterruptedException e) { if (zkServer.isRunning()) { zkServer.shutdown(); } } }