Search in sources :

Example 91 with ZooKeeperServer

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) InvalidCookieException(org.apache.bookkeeper.bookie.BookieException.InvalidCookieException)

Example 92 with ZooKeeperServer

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");
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 93 with ZooKeeperServer

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 94 with ZooKeeperServer

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 95 with ZooKeeperServer

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");
    }
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Aggregations

ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)96 File (java.io.File)39 Test (org.junit.jupiter.api.Test)33 ZooKeeper (org.apache.zookeeper.ZooKeeper)31 InetSocketAddress (java.net.InetSocketAddress)28 IOException (java.io.IOException)27 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)26 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)25 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 Stat (org.apache.zookeeper.data.Stat)9 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)8 ArrayList (java.util.ArrayList)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)6 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 ACL (org.apache.zookeeper.data.ACL)3 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)3