org.apache.zookeeper.server.quorum.QuorumPeerMain Java Examples

The following examples show how to use org.apache.zookeeper.server.quorum.QuorumPeerMain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Matrix.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
public static String startZooQ(boolean clean) {
    ZkS.zkSystemProps();
    String connectionString = format("localhost:2181,localhost:2182,localhost:2183");
    String [] args1 = {"./../zk/zk1/zoo.cfg"};
    String [] args2 = {"./../zk/zk2/zoo.cfg"};
    String [] args3 = {"./../zk/zk3/zoo.cfg"};

    // Port 2180
    //ZkS.runZookeeperServer("./../zk/single/zoo.cfg");

    //System.out.println("Server1 ...");
    async(()->QuorumPeerMain.main(args1));
    //System.out.println("Server2 ...");
    async(()->QuorumPeerMain.main(args2));
    //System.out.println("Server3 ...");
    async(()->QuorumPeerMain.main(args3));
    return connectionString;
}
 
Example #2
Source File: ZooKeeperStarter.java    From pulsar with Apache License 2.0 6 votes vote down vote up
protected static void start(String[] args, String defaultStatsPort) throws Exception {
    // Register basic JVM metrics
    DefaultExports.initialize();

    // Start Jetty to serve stats
    int port = Integer.parseInt(System.getProperties().getProperty("stats_server_port", defaultStatsPort));

    log.info("Starting ZK stats HTTP server at port {}", port);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", port);

    Server server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        log.error("Failed to start HTTP server at port {}. Use \"-Dstats_server_port=1234\" to change port number",
                port, e);
        throw e;
    }

    // Start the regular ZooKeeper server
    QuorumPeerMain.main(args);
}
 
Example #3
Source File: FlinkZooKeeperQuorumPeer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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);
	}
}
 
Example #4
Source File: FlinkZooKeeperQuorumPeer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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);
	}
}
 
Example #5
Source File: ZkServer.java    From redant with Apache License 2.0 5 votes vote down vote up
/**
 * 通过官方的QuorumPeerMain启动类启动真集群模式
 * 会执行quorumPeer.join();
 * 需要在不同的服务器上执行
 * @param zkConfig 配置对象
 * @throws ConfigException 配置异常
 * @throws IOException IO异常
 */
public void startCluster(ZkConfig zkConfig) throws ConfigException, IOException {
	Properties zkProp = zkConfig.toProp();
	QuorumPeerConfig config = new QuorumPeerConfig();
	config.parseProperties(zkProp);

	QuorumPeerMain main = new QuorumPeerMain();
	main.runFromConfig(config);
}
 
Example #6
Source File: Matrix.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
/** One external zoo keeper */
public static String startZooQ_single(boolean clean) {
    ZkS.zkSystemProps();
    String connectionString = format("localhost:2180");
    if ( clean )
        FileOps.clearDirectory("./../zk/single/zk-data/version-2");
    String [] args1 = {"./../zk/single/zoo.cfg"};
    async(()->QuorumPeerMain.main(args1));
    return connectionString;
}
 
Example #7
Source File: ZooKeeperClientTest.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	String[] args = new String[2];
	args[0] = port;
	args[1] = "./zk_test_data/zkdata" + this.getId();
	QuorumPeerMain.main(args);
}
 
Example #8
Source File: ZooKeeperClusterTest.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	String[] args = new String[2];
	args[0] = port;
	args[1] = "./zk_test_data/zkdata" + this.getId();
	QuorumPeerMain.main(args);
}
 
Example #9
Source File: ZooKeeperStateTest.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	String[] args = new String[2];
	args[0] = port;
	args[1] = "./zk_test_data/zkdata" + this.getId();
	QuorumPeerMain.main(args);
}
 
Example #10
Source File: HQuorumPeer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void runZKServer(QuorumPeerConfig zkConfig)
        throws IOException, AdminServer.AdminServerException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
 
Example #11
Source File: SolrZkServer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void start() {
  if (zkRun == null) return;

  if (System.getProperty(ZK_WHITELIST_PROPERTY) == null) {
    System.setProperty(ZK_WHITELIST_PROPERTY, "ruok, mntr, conf");
  }
  zkThread = new Thread() {
    @Override
    public void run() {
      try {
        if (zkProps.getServers().size() > 1) {
          QuorumPeerMain zkServer = new QuorumPeerMain();
          zkServer.runFromConfig(zkProps);
        } else {
          ServerConfig sc = new ServerConfig();
          sc.readFrom(zkProps);
          ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
          zkServer.runFromConfig(sc);
        }
        log.info("ZooKeeper Server exited.");
      } catch (Exception e) {
        log.error("ZooKeeper Server ERROR", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  };

  if (zkProps.getServers().size() > 1) {
    if (log.isInfoEnabled()) {
      log.info("STARTING EMBEDDED ENSEMBLE ZOOKEEPER SERVER at port {}", zkProps.getClientPortAddress().getPort());
    }
  } else {
    if (log.isInfoEnabled()) {
      log.info("STARTING EMBEDDED STANDALONE ZOOKEEPER SERVER at port {}", zkProps.getClientPortAddress().getPort());
    }
  }

  log.warn("Embedded Zookeeper is not recommended in production environments. See Reference Guide for details.");

  zkThread.setDaemon(true);
  zkThread.start();
  try {
    Thread.sleep(500); // pause for ZooKeeper to start
  } catch (Exception e) {
    log.error("STARTING ZOOKEEPER", e);
  }
}
 
Example #12
Source File: ZooServer.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public static void quorumServer(String confFile) {
    // No join.
    async(() -> QuorumPeerMain.main(new String[] {confFile}) );
}