use of org.apache.zookeeper.server.ZooKeeperServer in project incubator-pulsar by apache.
the class LocalBookkeeperEnsemble method runZookeeper.
/**
* @param args
*/
private void runZookeeper(int maxCC) throws IOException {
// create a ZooKeeper server(dataDir, dataLogDir, port)
LOG.info("Starting ZK server");
// ServerStats.registerAsConcrete();
// ClientBase.setupTestEnv();
File zkDataDir = isNotBlank(zkDataDirName) ? Files.createDirectories(Paths.get(zkDataDirName)).toFile() : Files.createTempDirectory("zktest").toFile();
if (this.clearOldData) {
cleanDirectory(zkDataDir);
}
try {
zks = new ZooKeeperServer(zkDataDir, zkDataDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), maxCC);
serverFactory.startup(zks);
} catch (Exception e) {
// TODO Auto-generated catch block
LOG.error("Exception while instantiating ZooKeeper", e);
}
boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
LOG.info("ZooKeeper server up: {}", b);
LOG.debug("Local ZK started (port: {}, data_directory: {})", ZooKeeperDefaultPort, zkDataDir.getAbsolutePath());
}
use of org.apache.zookeeper.server.ZooKeeperServer in project samza by apache.
the class EmbeddedZookeeper method setup.
public void setup() {
try {
snapshotDir = FileUtil.createFileInTempDir(SNAPSHOT_DIR_RELATIVE_PATH);
logDir = FileUtil.createFileInTempDir(LOG_DIR_RELATIVE_PATH);
} catch (IOException e) {
LOGGER.error("Failed to setup Zookeeper Server Environment", e);
Assert.fail("Failed to setup Zookeeper Server Environment");
}
try {
zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, TICK_TIME);
serverCnxnFactory = NIOServerCnxnFactory.createFactory();
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", RANDOM_PORT);
serverCnxnFactory.configure(addr, MAX_CLIENT_CONNECTIONS);
serverCnxnFactory.startup(zooKeeperServer);
} catch (Exception e) {
LOGGER.error("Zookeeper Server failed to start", e);
Assert.fail("Zookeeper Server failed to start");
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project debezium by debezium.
the class ZookeeperServer method startup.
/**
* Start the embedded Zookeeper server.
*
* @return this instance to allow chaining methods; never null
* @throws IOException if there is an error during startup
* @throws IllegalStateException if the server is already running
*/
public synchronized ZookeeperServer startup() throws IOException {
if (factory != null)
throw new IllegalStateException("" + this + " is already running");
if (this.port == -1)
this.port = IoUtil.getAvailablePort();
this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
if (this.dataDir == null) {
try {
File temp = File.createTempFile("kafka", "suffix");
this.dataDir = temp.getParentFile();
temp.delete();
} catch (IOException e) {
throw new RuntimeException("Unable to create temporary directory", e);
}
}
this.snapshotDir = new File(this.dataDir, "snapshot");
this.logDir = new File(this.dataDir, "log");
this.snapshotDir.mkdirs();
this.logDir.mkdirs();
try {
server = new ZooKeeperServer(snapshotDir, logDir, tickTime);
factory.startup(server);
return this;
} catch (InterruptedException e) {
factory = null;
Thread.interrupted();
throw new IOException(e);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project rest.li by linkedin.
the class ZKServer method restart.
public void restart() throws IOException, InterruptedException {
shutdown(false);
_zk = new ZooKeeperServer(_dataDir, _logDir, 5000);
_factory = new NIOServerCnxnFactory();
_factory.configure(new InetSocketAddress(_port), 60);
startup();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project hbase by apache.
the class MiniZooKeeperCluster method shutdown.
/**
* @throws IOException if waiting for the shutdown of a server fails
*/
public void shutdown() throws IOException {
// 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, connectionTimeout)) {
throw new IOException("Waiting for shutdown of standalone server at port=" + clientPort + ", timeout=" + this.connectionTimeout);
}
}
standaloneServerFactoryList.clear();
for (ZooKeeperServer zkServer : zooKeeperServers) {
// Explicitly close ZKDatabase since ZookeeperServer does not close them
zkServer.getZKDatabase().close();
}
zooKeeperServers.clear();
// clear everything
if (started) {
started = false;
activeZKServerIndex = 0;
clientPortList.clear();
LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
}
Aggregations