Search in sources :

Example 46 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project hadoop by apache.

the class TestZKClient method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    System.setProperty("zookeeper.preAllocSize", "100");
    FileTxnLog.setPreallocSize(100 * 1024);
    if (!BASETEST.exists()) {
        BASETEST.mkdirs();
    }
    File dataDir = createTmpDir(BASETEST);
    zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);
    if (factory == null) {
        factory = new NIOServerCnxnFactory();
        factory.configure(new InetSocketAddress(PORT), maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up", waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Before(org.junit.Before)

Example 47 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project pulsar by yahoo.

the class ZooKeeperUtil method startServer.

public void startServer() throws Exception {
    // create a ZooKeeper server(dataDir, dataLogDir, port)
    LOG.debug("Running ZK server");
    // ServerStats.registerAsConcrete();
    ClientBase.setupTestEnv();
    ZkTmpDir = File.createTempFile("zookeeper", "test");
    ZkTmpDir.delete();
    ZkTmpDir.mkdir();
    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(zkaddr, 100);
    serverFactory.startup(zks);
    boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
    LOG.debug("Server up: " + b);
    // create a zookeeper client
    LOG.debug("Instantiate ZK Client");
    ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
    zkc = ZkUtils.createConnectedZookeeperClient(getZooKeeperConnectString(), w);
    // initialize the zk client with values
    zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
Also used : ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 48 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project pulsar by yahoo.

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)

Example 49 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)

Aggregations

ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)49 File (java.io.File)28 Test (org.junit.Test)24 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)22 ZooKeeper (org.apache.zookeeper.ZooKeeper)21 IOException (java.io.IOException)15 InetSocketAddress (java.net.InetSocketAddress)15 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)13 Stat (org.apache.zookeeper.data.Stat)8 ArrayList (java.util.ArrayList)5 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)4 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)4 BindException (java.net.BindException)3 KeeperException (org.apache.zookeeper.KeeperException)3 InterruptedIOException (java.io.InterruptedIOException)2 PrintWriter (java.io.PrintWriter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ACL (org.apache.zookeeper.data.ACL)2 FileTxnLog (org.apache.zookeeper.server.persistence.FileTxnLog)2 FileTxnIterator (org.apache.zookeeper.server.persistence.FileTxnLog.FileTxnIterator)2