use of org.apache.zookeeper.server.ZooKeeperServer in project drill by axbaretto.
the class MiniZooKeeperCluster method startup.
/**
* @param baseDir
* @param numZooKeeperServers
* @return ClientPort server bound to.
* @throws IOException
* @throws InterruptedException
*/
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException {
if (numZooKeeperServers <= 0) {
return -1;
}
setupTestEnv();
shutdown();
int tentativePort = selectClientPort();
// running all the ZK servers
for (int i = 0; i < numZooKeeperServers; i++) {
File dir = new File(baseDir, "zookeeper_" + i).getAbsoluteFile();
recreateDir(dir);
int tickTimeToUse;
if (this.tickTime > 0) {
tickTimeToUse = this.tickTime;
} else {
tickTimeToUse = TICK_TIME;
}
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse);
NIOServerCnxnFactory standaloneServerFactory;
while (true) {
try {
standaloneServerFactory = new NIOServerCnxnFactory();
standaloneServerFactory.configure(new InetSocketAddress(tentativePort), 1000);
} catch (BindException e) {
LOG.debug("Failed binding ZK Server to client port: " + tentativePort);
// This port is already in use, try to use another.
tentativePort++;
continue;
}
try {
standaloneServerFactory.startup(server);
} catch (IOException e) {
LOG.error("Zookeeper startup error", e);
tentativePort++;
continue;
}
if (!waitForServerUp(server, CONNECTION_TIMEOUT)) {
server.shutdown();
server = new ZooKeeperServer(dir, dir, tickTimeToUse);
tentativePort++;
continue;
}
break;
}
// We have selected this port as a client port.
clientPortList.add(tentativePort);
standaloneServerFactoryList.add(standaloneServerFactory);
zooKeeperServers.add(server);
}
// set the first one to be active ZK; Others are backups
activeZKServerIndex = 0;
started = true;
clientPort = clientPortList.get(activeZKServerIndex);
LOG.info("Started MiniZK Cluster and connect 1 ZK server " + "on client port: " + clientPort);
return clientPort;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project atlas by apache.
the class EmbeddedKafkaServer method startZk.
private String startZk() throws IOException, InterruptedException, URISyntaxException {
String zkValue = properties.getProperty("zookeeper.connect");
LOG.info("Starting zookeeper at {}", zkValue);
URL zkAddress = getURL(zkValue);
File snapshotDir = constructDir("zk/txn");
File logDir = constructDir("zk/snap");
factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(zkAddress.getHost(), zkAddress.getPort()), 1024);
factory.startup(new ZooKeeperServer(snapshotDir, logDir, 500));
String ret = factory.getLocalAddress().getAddress().toString();
LOG.info("Embedded zookeeper for Kafka started at {}", ret);
return ret;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project drill by apache.
the class MiniZooKeeperCluster method startup.
/**
* @param baseDir
* @param numZooKeeperServers
* @return ClientPort server bound to.
* @throws IOException
* @throws InterruptedException
*/
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException {
if (numZooKeeperServers <= 0) {
return -1;
}
setupTestEnv();
shutdown();
int tentativePort = selectClientPort();
// running all the ZK servers
for (int i = 0; i < numZooKeeperServers; i++) {
File dir = new File(baseDir, "zookeeper_" + i).getAbsoluteFile();
recreateDir(dir);
int tickTimeToUse;
if (this.tickTime > 0) {
tickTimeToUse = this.tickTime;
} else {
tickTimeToUse = TICK_TIME;
}
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse);
NIOServerCnxnFactory standaloneServerFactory;
while (true) {
try {
standaloneServerFactory = new NIOServerCnxnFactory();
standaloneServerFactory.configure(new InetSocketAddress(tentativePort), 1000);
} catch (BindException e) {
logger.debug("Failed binding ZK Server to client port: {}", tentativePort);
// This port is already in use, try to use another.
tentativePort++;
continue;
}
try {
standaloneServerFactory.startup(server);
} catch (IOException e) {
logger.error("Zookeeper startup error", e);
tentativePort++;
continue;
}
if (!waitForServerUp(server, CONNECTION_TIMEOUT)) {
server.shutdown();
server = new ZooKeeperServer(dir, dir, tickTimeToUse);
tentativePort++;
continue;
}
break;
}
// We have selected this port as a client port.
clientPortList.add(tentativePort);
standaloneServerFactoryList.add(standaloneServerFactory);
zooKeeperServers.add(server);
}
// set the first one to be active ZK; Others are backups
activeZKServerIndex = 0;
started = true;
clientPort = clientPortList.get(activeZKServerIndex);
logger.info("Started MiniZK Cluster and connect 1 ZK server " + "on client port: {}", clientPort);
return clientPort;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project samza by apache.
the class TestZkStreamProcessorBase method expireSession.
// session expiration simulation
// have to use the reflection to get the session id
protected void expireSession(ZkClient zkClient) {
ZkConnection zkConnection = null;
try {
Field privateField = ZkClient.class.getDeclaredField("_connection");
privateField.setAccessible(true);
zkConnection = (ZkConnection) privateField.get(zkClient);
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail(e.toString());
}
ZooKeeper zookeeper = zkConnection.getZookeeper();
long sessionId = zookeeper.getSessionId();
LOG.info("Closing/expiring session:" + sessionId);
ZooKeeperServer zkServer = zookeeper().zookeeper();
zkServer.closeSession(sessionId);
}
use of org.apache.zookeeper.server.ZooKeeperServer in project pinpoint by naver.
the class ZookeeperUnitServer method startup.
public void startup() {
final File snapshotDir;
final File logDir;
try {
snapshotDir = Files.createTempDirectory("zookeeper-snapshot").toFile();
logDir = Files.createTempDirectory("zookeeper-logs").toFile();
} catch (IOException ioe) {
throw new RuntimeException("Unable to start Kafka", ioe);
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
FileUtils.deleteDirectory(snapshotDir);
FileUtils.deleteDirectory(logDir);
} catch (IOException ioe) {
}
}));
try {
int tickTime = 500;
ZooKeeperServer zkServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
factory = NIOServerCnxnFactory.createFactory();
factory.configure(new InetSocketAddress("localhost", port), maxConnections);
factory.startup(zkServer);
} catch (InterruptedException var5) {
Thread.currentThread().interrupt();
} catch (IOException var6) {
throw new RuntimeException("Unable to start ZooKeeper", var6);
}
}
Aggregations