use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project Dempsy by Dempsy.
the class ZookeeperTestServer method startZookeeper.
private static TestZookeeperServerIntern startZookeeper(Properties zkConfig) {
logger.debug("Starting the test zookeeper server on port " + zkConfig.get("clientPort"));
final TestZookeeperServerIntern server = new TestZookeeperServerIntern();
try {
QuorumPeerConfig qpConfig = new QuorumPeerConfig();
qpConfig.parseProperties(zkConfig);
final ServerConfig sConfig = new ServerConfig();
sConfig.readFrom(qpConfig);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
server.runFromConfig(sConfig);
} catch (IOException ioe) {
logger.error(MarkerFactory.getMarker("FATAL"), "", ioe);
fail("can't start zookeeper");
}
}
});
t.start();
// give the server time to start
Thread.sleep(2000);
} catch (Exception e) {
logger.error("Can't start zookeeper", e);
fail("Can't start zookeeper");
}
return server;
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project nifi by apache.
the class EmbeddedKafka method startZookeeper.
/**
* Will start Zookeeper server via {@link ServerCnxnFactory}
*/
private void startZookeeper() {
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
quorumConfiguration.parseProperties(this.zookeeperConfig);
ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
FileTxnSnapLog txnLog = new FileTxnSnapLog(new File(configuration.getDataLogDir()), new File(configuration.getDataDir()));
zkServer.setTxnLogFactory(txnLog);
zkServer.setTickTime(configuration.getTickTime());
zkServer.setMinSessionTimeout(configuration.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(configuration.getMaxSessionTimeout());
ServerCnxnFactory zookeeperConnectionFactory = ServerCnxnFactory.createFactory();
zookeeperConnectionFactory.configure(configuration.getClientPortAddress(), configuration.getMaxClientCnxns());
zookeeperConnectionFactory.startup(zkServer);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
throw new IllegalStateException("Failed to start Zookeeper server", e);
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project zookeeper by apache.
the class ServerConfig method parse.
/**
* Parse a ZooKeeper configuration file
* @param path the patch of the configuration file
* @return ServerConfig configured wrt arguments
* @throws ConfigException error processing configuration
*/
public void parse(String path) throws ConfigException {
QuorumPeerConfig config = new QuorumPeerConfig();
config.parse(path);
// let qpconfig parse the file and then pull the stuff we are
// interested in
readFrom(config);
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project fabric8 by jboss-fuse.
the class ZooKeeperServerFactory method activateInternal.
private Destroyable activateInternal(BundleContext context, Map<String, ?> configuration) throws Exception {
LOGGER.info("Creating zookeeper server with: {}", configuration);
Properties props = new Properties();
for (Entry<String, ?> entry : configuration.entrySet()) {
props.put(entry.getKey(), entry.getValue());
}
// Remove the dependency on the current dir from dataDir
String dataDir = props.getProperty("dataDir");
if (dataDir != null && !Paths.get(dataDir).isAbsolute()) {
dataDir = runtimeProperties.get().getDataPath().resolve(dataDir).toFile().getAbsolutePath();
props.setProperty("dataDir", dataDir);
}
props.put("clientPortAddress", bootstrapConfiguration.get().getBindAddress());
// Create myid file
String serverId = (String) props.get("server.id");
if (serverId != null) {
props.remove("server.id");
File myId = new File(dataDir, "myid");
if (myId.exists() && !myId.delete()) {
throw new IOException("Failed to delete " + myId);
}
if (myId.getParentFile() == null || (!myId.getParentFile().exists() && !myId.getParentFile().mkdirs())) {
throw new IOException("Failed to create " + myId.getParent());
}
FileOutputStream fos = new FileOutputStream(myId);
try {
fos.write((serverId + "\n").getBytes());
} finally {
fos.close();
}
}
QuorumPeerConfig peerConfig = getPeerConfig(props);
if (!peerConfig.getServers().isEmpty()) {
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(peerConfig.getClientPortAddress(), peerConfig.getMaxClientCnxns());
QuorumPeer quorumPeer = new QuorumPeer();
quorumPeer.setClientPortAddress(peerConfig.getClientPortAddress());
quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(peerConfig.getDataLogDir()), new File(peerConfig.getDataDir())));
quorumPeer.setQuorumPeers(peerConfig.getServers());
quorumPeer.setElectionType(peerConfig.getElectionAlg());
quorumPeer.setMyid(peerConfig.getServerId());
quorumPeer.setTickTime(peerConfig.getTickTime());
quorumPeer.setMinSessionTimeout(peerConfig.getMinSessionTimeout());
quorumPeer.setMaxSessionTimeout(peerConfig.getMaxSessionTimeout());
quorumPeer.setInitLimit(peerConfig.getInitLimit());
quorumPeer.setSyncLimit(peerConfig.getSyncLimit());
quorumPeer.setQuorumVerifier(peerConfig.getQuorumVerifier());
quorumPeer.setCnxnFactory(cnxnFactory);
quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
quorumPeer.setLearnerType(peerConfig.getPeerType());
try {
LOGGER.debug("Starting quorum peer \"{}\" on address {}", quorumPeer.getMyid(), peerConfig.getClientPortAddress());
quorumPeer.start();
LOGGER.debug("Started quorum peer \"{}\"", quorumPeer.getMyid());
} catch (Exception e) {
LOGGER.warn("Failed to start quorum peer \"{}\", reason : {} ", quorumPeer.getMyid(), e.getMessage());
quorumPeer.shutdown();
throw e;
}
// Register stats provider
ClusteredServer server = new ClusteredServer(quorumPeer);
registration = context.registerService(QuorumStats.Provider.class, server, null);
return server;
} else {
ServerConfig serverConfig = getServerConfig(peerConfig);
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(serverConfig.getTickTime());
zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {
protected void configureSaslLogin() throws IOException {
}
};
cnxnFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
try {
LOGGER.debug("Starting ZooKeeper server on address {}", peerConfig.getClientPortAddress());
cnxnFactory.startup(zkServer);
LOGGER.debug("Started ZooKeeper server");
} catch (Exception e) {
LOGGER.warn("Failed to start ZooKeeper server, reason : {}", e);
cnxnFactory.shutdown();
throw e;
}
// Register stats provider
SimpleServer server = new SimpleServer(zkServer, cnxnFactory);
registration = context.registerService(ServerStats.Provider.class, server, null);
startCleanupManager(serverConfig, props);
return server;
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project carbondata by apache.
the class ZooKeeperLockingTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
Properties startupProperties = new Properties();
startupProperties.setProperty("dataDir", (new File("./target").getAbsolutePath()));
startupProperties.setProperty("dataLogDir", (new File("./target").getAbsolutePath()));
freePort = findFreePort();
startupProperties.setProperty("clientPort", "" + freePort);
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
quorumConfiguration.parseProperties(startupProperties);
} catch (Exception e) {
throw new RuntimeException(e);
}
final ZooKeeperServerMain zooKeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
new Thread() {
public void run() {
try {
zooKeeperServer.runFromConfig(configuration);
} catch (IOException e) {
System.out.println("ZooKeeper failure");
}
}
}.start();
}
Aggregations