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));
}
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);
}
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());
}
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");
}
}
Aggregations