use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class CommandsTest method testConsCommandSecureOnly.
@Test
public void testConsCommandSecureOnly() {
// Arrange
Commands.ConsCommand cmd = new Commands.ConsCommand();
ZooKeeperServer zkServer = mock(ZooKeeperServer.class);
ServerCnxnFactory cnxnFactory = mock(ServerCnxnFactory.class);
when(zkServer.getSecureServerCnxnFactory()).thenReturn(cnxnFactory);
// Act
CommandResponse response = cmd.run(zkServer, null);
// Assert
assertThat(response.toMap().containsKey("connections"), is(true));
assertThat(response.toMap().containsKey("secure_connections"), is(true));
}
use of org.apache.zookeeper.server.ZooKeeperServer in project hive by apache.
the class MiniZooKeeperCluster method startup.
/**
* @param baseDir
* @param numZooKeeperServers
* @return ClientPort server bound to, -1 if there was a
* binding problem and we couldn't pick another port.
* @throws IOException
* @throws InterruptedException
*/
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException {
if (numZooKeeperServers <= 0) {
return -1;
}
setupTestEnv(sslEnabled);
shutdown();
// the seed port
int tentativePort = -1;
int currentClientPort;
// running all the ZK servers
for (int i = 0; i < numZooKeeperServers; i++) {
File dir = new File(baseDir, "zookeeper_" + i).getAbsoluteFile();
createDir(dir);
int tickTimeToUse;
if (this.tickTime > 0) {
tickTimeToUse = this.tickTime;
} else {
tickTimeToUse = TICK_TIME;
}
// Set up client port - if we have already had a list of valid ports, use it.
if (hasValidClientPortInList(i)) {
currentClientPort = clientPortList.get(i);
} else {
// update the seed
tentativePort = selectClientPort(tentativePort);
currentClientPort = tentativePort;
}
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse);
// Setting {min,max}SessionTimeout defaults to be the same as in Zookeeper
server.setMinSessionTimeout(configuration.getInt("hbase.zookeeper.property.minSessionTimeout", -1));
server.setMaxSessionTimeout(configuration.getInt("hbase.zookeeper.property.maxSessionTimeout", -1));
ServerCnxnFactory standaloneServerFactory;
while (true) {
try {
standaloneServerFactory = createServerCnxnFactory(currentClientPort);
} catch (BindException e) {
LOG.debug("Failed binding ZK Server to client port: " + currentClientPort, e);
// We're told to use some port but it's occupied, fail
if (hasValidClientPortInList(i)) {
return -1;
}
// This port is already in use, try to use another.
tentativePort = selectClientPort(tentativePort);
currentClientPort = tentativePort;
continue;
}
break;
}
// Start up this ZK server
standaloneServerFactory.startup(server);
// Runs a 'stat' against the servers.
if (!sslEnabled && !waitForServerUp(currentClientPort, connectionTimeout)) {
throw new IOException("Waiting for startup of standalone server");
}
// We have selected a port as a client port. Update clientPortList if necessary.
if (clientPortList.size() <= i) {
// it is not in the list, add the port
clientPortList.add(currentClientPort);
} else if (clientPortList.get(i) <= 0) {
// the list has invalid port, update with valid port
clientPortList.remove(i);
clientPortList.add(i, currentClientPort);
}
standaloneServerFactoryList.add(standaloneServerFactory);
zooKeeperServers.add(server);
}
// set the first one to be active ZK; Others are backups
activeZKServerIndex = 0;
started = true;
int clientPort = clientPortList.get(activeZKServerIndex);
LOG.info("Started MiniZooKeeperCluster and ran successful 'stat' " + "on client port=" + clientPort);
return clientPort;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project hive by apache.
the class MiniZooKeeperCluster method shutdown.
/**
* @throws IOException
*/
public void shutdown() throws IOException {
// shut down all the zk servers
for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
ServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(i);
int clientPort = clientPortList.get(i);
standaloneServerFactory.shutdown();
if (!waitForServerDown(clientPort, connectionTimeout)) {
throw new IOException("Waiting for shutdown of standalone server");
}
}
standaloneServerFactoryList.clear();
for (ZooKeeperServer zkServer : zooKeeperServers) {
// explicitly close ZKDatabase since ZookeeperServer does not close them
zkServer.getZKDatabase().close();
zkServer.shutdown(true);
}
zooKeeperServers.clear();
// clear everything
if (started) {
started = false;
activeZKServerIndex = 0;
clientPortList.clear();
LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project jstorm by alibaba.
the class Zookeeper method mkInprocessZookeeper.
public static Factory mkInprocessZookeeper(String localDir, int port) throws IOException, InterruptedException {
LOG.info("Starting in-process zookeeper at port " + port + " and dir " + localDir);
File localFile = new File(localDir);
ZooKeeperServer zk = new ZooKeeperServer(localFile, localFile, 2000);
Factory factory = new Factory(new InetSocketAddress(port), 0);
factory.startup(zk);
return factory;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project KeptCollections by anthonyu.
the class KeptTestBase method init.
@BeforeClass
public static void init() throws IOException, InterruptedException {
final File dir = new File(System.getProperty("java.io.tmpdir"), "zookeeper").getAbsoluteFile();
final ZooKeeperServer server = new ZooKeeperServer(dir, dir, 2000);
KeptTestBase.nioServerCnxnFactory = new NIOServerCnxnFactory();
KeptTestBase.nioServerCnxnFactory.configure(new InetSocketAddress(KeptTestBase.CLIENT_PORT), 5000);
KeptTestBase.nioServerCnxnFactory.startup(server);
}
Aggregations