List of usage examples for org.apache.zookeeper.server ZooKeeperServerMain runFromConfig
public void runFromConfig(ServerConfig config) throws IOException, AdminServerException
From source file:com.alibaba.wasp.zookeeper.FQuorumPeer.java
License:Apache License
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException { if (zkConfig.isDistributed()) { QuorumPeerMain qp = new QuorumPeerMain(); qp.runFromConfig(zkConfig);/*from www . j a v a 2s . c o m*/ } else { ZooKeeperServerMain zk = new ZooKeeperServerMain(); ServerConfig serverConfig = new ServerConfig(); serverConfig.readFrom(zkConfig); zk.runFromConfig(serverConfig); } }
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;// w ww .j av a 2 s . c om } 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: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 . ja v a 2 s . c o m try { zk.runFromConfig(config); } catch (Exception e) { FmtLog.warn(logConf, "Failed to run zookeeper: " + e.getMessage(), e); } }); }
From source file:org.apache.carbondata.lcm.locks.ZooKeeperLockingTest.java
License:Apache License
/** * @throws java.lang.Exception// w w w . j ava 2 s .com */ @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(); }
From source file:org.apache.flink.runtime.zookeeper.FlinkZooKeeperQuorumPeer.java
License:Apache License
/** * Runs a ZooKeeper {@link QuorumPeer} if further peers are configured or a single * {@link ZooKeeperServer} if no further peers are configured. * * @param zkConfigFile ZooKeeper config file 'zoo.cfg' * @param peerId ID for the 'myid' file *//*w ww . j a va2 s . c o m*/ public static void runFlinkZkQuorumPeer(String zkConfigFile, int peerId) throws Exception { Properties zkProps = new Properties(); try (InputStream inStream = new FileInputStream(new File(zkConfigFile))) { zkProps.load(inStream); } LOG.info("Configuration: " + zkProps); // Set defaults for required properties setRequiredProperties(zkProps); // Write peer id to myid file writeMyIdToDataDir(zkProps, peerId); // The myid file needs to be written before creating the instance. Otherwise, this // will fail. QuorumPeerConfig conf = new QuorumPeerConfig(); conf.parseProperties(zkProps); if (conf.isDistributed()) { // Run quorum peer LOG.info("Running distributed ZooKeeper quorum peer (total peers: {}).", conf.getServers().size()); QuorumPeerMain qp = new QuorumPeerMain(); qp.runFromConfig(conf); } else { // Run standalone LOG.info("Running standalone ZooKeeper quorum peer."); ZooKeeperServerMain zk = new ZooKeeperServerMain(); ServerConfig sc = new ServerConfig(); sc.readFrom(conf); zk.runFromConfig(sc); } }
From source file:org.giwi.camel.kafka.test.EmbeddedZookeeper.java
License:Apache License
public void start() { final ZooKeeperServerMain zooKeeperServer; Properties startupProperties = new Properties(); startupProperties.put("dataDir", "target/testZookeeper"); startupProperties.put("clientPort", "2181"); startupProperties.put("maxClientCnxns", "0"); QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig(); try {/*from ww w .j a va2 s. c o m*/ quorumConfiguration.parseProperties(startupProperties); } catch (Exception e) { throw new RuntimeException(e); } zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumConfiguration); new Thread() { @Override public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (IOException e) { logger.error("ZooKeeper Failed", e); } } }.start(); }
From source file:test.com.heliosapm.streams.agent.BaseTest.java
License:Apache License
/** * Starts a new zookeeper instance using temp directories and the specified port * @param zooPort The zookeeper port to listen on. If null, uses a random port * @return the assigned port// w ww . j a v a 2 s . c o m */ public static int startZooKeeper(final Integer zooPort) { final QuorumPeerConfig qpc = new QuorumPeerConfig(); final File dataDir = FileHelper.createTempDir("ZooKeeperDataDir", ""); final File logDir = FileHelper.createTempDir("ZooKeeperLogDir", ""); final Properties p = new Properties(); p.setProperty("dataDir", dataDir.getAbsolutePath()); p.setProperty("logDir", logDir.getAbsolutePath()); final int port = zooPort == null ? SocketUtil.acquirePorts(1).nextPort() : zooPort; p.setProperty("clientPort", "" + port); try { qpc.parseProperties(p); final ZooKeeperServerMain zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(qpc); zooKeeperServers.put(port, zooKeeperServer); final Exception[] thr = new Exception[1]; final Thread t = new Thread("TestZooKeeperServer-" + port) { public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (Exception ex) { thr[0] = ex; } } }; t.setDaemon(true); t.start(); return port; } catch (Exception ex) { zooKeeperServers.remove(port); throw new RuntimeException("Failed to start ZooKeeper instance", ex); } }