List of usage examples for org.apache.zookeeper.server ServerCnxnFactory startup
public void startup(ZooKeeperServer zkServer) throws IOException, InterruptedException
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationConnectionTest.java
License:Apache License
@Before public void setUp() throws Exception { int tickTime = 2000; int numConnections = 100; File dir = temp.newFolder("zkHome"); server = new ZooKeeperServer(dir, dir, tickTime); ServerCnxnFactory serverFactory = ServerCnxnFactory.createFactory(0, numConnections); serverFactory.startup(server); zkConnection = "localhost:" + server.getClientPort(); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
License:Apache License
@Before public void setUp() throws Exception { int tickTime = 2000; int numConnections = 100; File dir = temp.newFolder("zkHome"); server = new ZooKeeperServer(dir, dir, tickTime); ServerCnxnFactory serverFactory = ServerCnxnFactory.createFactory(0, numConnections); serverFactory.startup(server); zkConnection = "localhost:" + server.getClientPort(); }
From source file:co.paralleluniverse.galaxy.test.GalaxyTestingUtils.java
License:Open Source License
public static ServerCnxnFactory startZookeeper(final String configResource, final String dataDirName) throws IOException, QuorumPeerConfig.ConfigException { ServerConfig sc = new ServerConfig(); sc.parse(pathToResource(configResource)); deleteDir(dataDirName);//from ww w. j a v a 2 s. c o m new File(dataDirName).mkdirs(); FileTxnSnapLog txnLog = null; try { ZooKeeperServer zkServer = new ZooKeeperServer(); txnLog = new FileTxnSnapLog(new File(sc.getDataDir()), new File(sc.getDataDir())); zkServer.setTxnLogFactory(txnLog); zkServer.setTickTime(sc.getTickTime()); zkServer.setMinSessionTimeout(sc.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout()); ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(sc.getClientPortAddress(), sc.getMaxClientCnxns()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (InterruptedException e) { throw new RuntimeException(e); } finally { if (txnLog != null) { txnLog.close(); } } }
From source file:com.hmaimi.jodis.ZooKeeperServerWapper.java
License:Open Source License
public void start() throws IOException, InterruptedException { ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(baseDir, "zookeeper"), new File(baseDir, "zookeeper")); zkServer.setTxnLogFactory(ftxn);/*from ww w . ja v a 2s. c om*/ zkServer.setTickTime(1000); ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(port, 100); cnxnFactory.startup(zkServer); this.cnxnFactory = cnxnFactory; this.zkServer = zkServer; this.ftxn = ftxn; }
From source file:com.msd.gin.halyard.common.HBaseServerTestInstance.java
License:Apache License
public static synchronized Configuration getInstanceConfig() throws Exception { if (conf == null) { File zooRoot = File.createTempFile("hbase-zookeeper", ""); zooRoot.delete();/*from ww w .j a v a 2 s . co m*/ ZooKeeperServer zookeper = new ZooKeeperServer(zooRoot, zooRoot, 2000); ServerCnxnFactory factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", 0), 5000); factory.startup(zookeper); YarnConfiguration yconf = new YarnConfiguration(); String argLine = System.getProperty("argLine"); if (argLine != null) { yconf.set("yarn.app.mapreduce.am.command-opts", argLine.replace("jacoco.exec", "jacocoMR.exec")); } yconf.setBoolean(MRConfig.MAPREDUCE_MINICLUSTER_CONTROL_RESOURCE_MONITORING, false); yconf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class); MiniMRYarnCluster miniCluster = new MiniMRYarnCluster("testCluster"); miniCluster.init(yconf); yconf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true); miniCluster.start(); File hbaseRoot = File.createTempFile("hbase-root", ""); hbaseRoot.delete(); conf = HBaseConfiguration.create(miniCluster.getConfig()); conf.set(HConstants.HBASE_DIR, hbaseRoot.toURI().toURL().toString()); conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, factory.getLocalPort()); conf.set("hbase.master.hostname", "localhost"); conf.set("hbase.regionserver.hostname", "localhost"); conf.setInt("hbase.master.info.port", -1); conf.set("hbase.fs.tmp.dir", new File(System.getProperty("java.io.tmpdir")).toURI().toURL().toString()); LocalHBaseCluster cluster = new LocalHBaseCluster(conf); cluster.startup(); } return conf; }
From source file:com.palantir.curatortestrule.DefaultZooKeeperRuleConfig.java
License:Open Source License
@Override public ServerCnxnFactory getServer(int port) { ZooKeeperServer zkServer = new NoJMXZooKeeperServer(); FileTxnSnapLog ftxn;/* w ww .j av a2 s.c om*/ try { File dataDir = Files.createTempDir(); File snapDir = Files.createTempDir(); if (cleanupOnExit) { directoriesToCleanup.add(dataDir); directoriesToCleanup.add(snapDir); } ftxn = new FileTxnSnapLog(dataDir, snapDir); } catch (IOException e) { throw new RuntimeException(e); } zkServer.setTxnLogFactory(ftxn); try { ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(new InetSocketAddress(port), cnxnFactory.getMaxClientCnxnsPerHost()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } }
From source file:io.datalayer.zookeeper.AosZookeeperServerLauncher.java
License:Apache License
public static void main(String... args) throws InterruptedException, IOException { File dir = new File(DATA_DIRECTORY, "zookeeper").getAbsoluteFile(); final ZooKeeperServer server = new ZooKeeperServer(dir, dir, TICK_TIME); final ServerCnxnFactory standaloneServerFactory = NIOServerCnxnFactory .createFactory(new InetSocketAddress(CLIENT_PORT), NUM_CONNECTIONS); new Thread() { public void run() { try { standaloneServerFactory.startup(server); while (true) { try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException e) { LOGGER.error("ZooKeeper Failed", e); throw new RuntimeException("ZooKeeper Failed", e); }/*w w w . j a v a 2 s . co m*/ } } catch (InterruptedException e) { LOGGER.error("ZooKeeper Failed", e); throw new RuntimeException("ZooKeeper Interrupted", e); } catch (IOException e) { LOGGER.error("ZooKeeper Failed", e); throw new RuntimeException("ZooKeeper Failed", e); } } }.start(); LOGGER.info("Zookeeper Server is started."); // TimeUnit.MINUTES.sleep(3); }
From source file:org.apache.airavata.common.utils.AiravataZKUtils.java
License:Apache License
public static void runZKFromConfig(ServerConfig config, ServerCnxnFactory cnxnFactory) throws IOException { AiravataZKUtils.logger.info("Starting Zookeeper server..."); FileTxnSnapLog txnLog = null;/* w ww. ja v a2s. c o m*/ try { // Note that this thread isn't going to be doing anything else, // so rather than spawning another thread, we will just call // run() in this thread. // create a file logger url from the command line args ZooKeeperServer zkServer = new ZooKeeperServer(); txnLog = new FileTxnSnapLog(new File(config.getDataDir()), new File(config.getDataDir())); zkServer.setTxnLogFactory(txnLog); zkServer.setTickTime(config.getTickTime()); zkServer.setMinSessionTimeout(config.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer); cnxnFactory.join(); if (zkServer.isRunning()) { zkServer.shutdown(); } } catch (InterruptedException e) { // warn, but generally this is ok AiravataZKUtils.logger.warn("Server interrupted", e); System.exit(1); } finally { if (txnLog != null) { txnLog.close(); } } }
From source file:org.apache.hadoop.ha.ClientBaseWithFixes.java
License:Apache License
static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); final int PORT = getPort(hostPort); if (factory == null) { factory = ServerCnxnFactory.createFactory(PORT, maxCnxns); }/*w w w . j av a 2 s . c o m*/ factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); return factory; }
From source file:org.apache.nifi.atlas.emulator.EmbeddedKafka.java
License:Apache License
/** * Will start Zookeeper server via {@link ServerCnxnFactory} *//*from w ww .ja v a2s . c om*/ 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); } }