List of usage examples for org.apache.zookeeper.server ServerConfig parse
public void parse(String path) throws ConfigException
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 w ww . java 2 s . c om*/ 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.comcast.viper.flume2storm.zookeeper.ZkTestServer.java
License:Apache License
/** * Starts the test ZooKeeper server/*from w w w .j a va2 s.com*/ */ public void start() { if (started) { LOG.debug("Already started"); return; } try { LOG.debug("Starting..."); ServerConfig config = new ServerConfig(); config.parse(new String[] { port.toString(), ZK_DIR.getCanonicalPath(), ticktime.toString() }); zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(config.getTickTime()); zkServer.setMinSessionTimeout(config.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer); started = true; LOG.info("Started, {}", getConnectString()); } catch (Exception e) { LOG.error("Failed to start: " + e.getMessage(), e); } }
From source file:com.huawei.streaming.cql.LocalTaskCommons.java
License:Apache License
/** * ?zookeeper?/* www .ja va 2s .c o m*/ */ public static void startZookeeperServer() throws ConfigException, IOException { String classPath = ApplicationParseTest.class.getResource("/").getPath(); String[] args = { classPath + File.separator + "zoo.cfg" }; ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } LOG.info("start to startup zookeeper server"); runFromConfig(config); }
From source file:com.jkoolcloud.tnt4j.streams.inputs.KafkaStream.java
License:Apache License
/** * Starts ZooKeeper server instance.// w w w.j ava2 s. c om * * @throws Exception * if an error occurred wile starting ZooKeeper server */ protected void startZooKeeper() throws Exception { logger().log(OpLevel.DEBUG, StreamsResources.getString(KafkaStreamConstants.RESOURCE_BUNDLE_NAME, "KafkaStream.zookeeper.server.starting")); // ZooKeeperServerMain.main(); ServerConfig sc = new ServerConfig(); sc.parse(System.getProperty(ZK_PROP_FILE_KEY)); ZooKeeperServer zkServer = new ZooKeeperServer(); zLog = new FileTxnSnapLog(new File(sc.getDataLogDir()), new File(sc.getDataDir())); zkServer.setTxnLogFactory(zLog); zkServer.setTickTime(sc.getTickTime()); zkServer.setMinSessionTimeout(sc.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout()); zkCnxnFactory = ServerCnxnFactory.createFactory(sc.getClientPortAddress(), sc.getMaxClientCnxns()); zkCnxnFactory.startup(zkServer); logger().log(OpLevel.DEBUG, StreamsResources.getString(KafkaStreamConstants.RESOURCE_BUNDLE_NAME, "KafkaStream.zookeeper.server.started")); }
From source file:com.sodec.embeddedZk.ZooKeeperServerMain.java
License:Apache License
protected void initializeAndRun(String[] args) throws ConfigException, IOException { try {/*w w w . j av a 2s .c o m*/ ManagedUtil.registerLog4jMBeans(); } catch (JMException e) { LOG.warn("Unable to register log4j JMX control", e); } ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } runFromConfig(config); }
From source file:conf2.build.Lz2BuildZk.java
License:Apache License
public static void zookeeper(ConfZookeeper confZookeeper) { if (confZookeeper.isEphemeral()) { FmtLog.info(logConf, "Zookeeper (ephemeral): %d", confZookeeper.port); zookeeperSimple(confZookeeper.port); return;//from w w w .ja va 2 s.c o m } FmtLog.info(logConf, "Zookeeper %s : %d", confZookeeper.zkConfDir, confZookeeper.port); ServerConfig config = new ServerConfig(); config.parse(new String[] { Integer.toString(confZookeeper.port), confZookeeper.zkConfDir }); ZooKeeperServerMain zk = new ZooKeeperServerMain(); L.async(() -> { try { zk.runFromConfig(config); } catch (Exception e) { FmtLog.warn(logConf, "Failed to run zookeeper: " + e.getMessage(), e); } }); }
From source file:io.fabric8.groups.GroupTest.java
License:Apache License
private NIOServerCnxnFactory startZooKeeper(int port) throws Exception { ServerConfig cfg = new ServerConfig(); cfg.parse(new String[] { Integer.toString(port), "target/zk/data" }); ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir())); zkServer.setTxnLogFactory(ftxn);//from w ww .j a v a 2 s . c o m zkServer.setTickTime(cfg.getTickTime()); zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout()); NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns()); cnxnFactory.startup(zkServer); return cnxnFactory; }
From source file:io.fabric8.process.spring.boot.registry.ZooKeeperProcessRegistries.java
License:Apache License
public static NIOServerCnxnFactory zooKeeperServer(int port) { try {//from www .j ava 2 s . c o m ServerConfig cfg = new ServerConfig(); String zkData = "target/zk/data/" + randomUUID(); cfg.parse(new String[] { Integer.toString(port), zkData }); ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir())); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(cfg.getTickTime()); zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout()); NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (InterruptedException | IOException e) { throw new RuntimeException(e); } }
From source file:lizard.build.LzBuildZk.java
License:Apache License
/** Run a full Zookeepr here */ public static void zookeeper(int port, String zkConfDir) { FmtLog.info(logConf, "Start Zookeeper %s : %d", zkConfDir, port); ServerConfig config = new ServerConfig(); config.parse(new String[] { Integer.toString(port), zkConfDir }); ZooKeeperServerMain zk = new ZooKeeperServerMain(); L.async(() -> {/*w w w . j a va2 s . com*/ try { zk.runFromConfig(config); } catch (Exception e) { FmtLog.warn(logConf, "Failed to run zookeeper: " + e.getMessage(), e); } }); }
From source file:org.apache.airavata.common.utils.AiravataZKUtils.java
License:Apache License
public static void startEmbeddedZK(ServerCnxnFactory cnxnFactory) { if (ServerSettings.isEmbeddedZK()) { ServerConfig serverConfig = new ServerConfig(); URL resource = AiravataZKUtils.class.getClassLoader().getResource("zoo.cfg"); if (resource == null) { logger.error("There is no zoo.cfg file in the classpath... Failed to start Zookeeper Server"); System.exit(1);/*from ww w . java 2 s . c o m*/ } try { serverConfig.parse(resource.getPath()); } catch (QuorumPeerConfig.ConfigException e) { logger.error("Error while starting embedded Zookeeper", e); System.exit(2); } final ServerConfig fServerConfig = serverConfig; final ServerCnxnFactory fserverCnxnFactory = cnxnFactory; (new Thread() { public void run() { try { AiravataZKUtils.runZKFromConfig(fServerConfig, fserverCnxnFactory); } catch (IOException e) { logger.error("Error while starting embedded Zookeeper", e); System.exit(3); } } }).start(); } else { logger.info("Skipping Zookeeper embedded startup ..."); } }