/** * Return the ZK Quorum servers string given the specified configuration. * @param conf * @return Quorum servers */ public static String getZKQuorumServersString(Configuration conf) { return getZKQuorumServersString(makeZKProps(conf)); } }
public String parse(final Configuration c) { Properties zkProps = ZKConfig.makeZKProps(c); String host = null; String clientPort = null; for (Entry<Object, Object> entry: zkProps.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.") && host == null) { String[] parts = value.split(":"); host = parts[0]; } else if (key.endsWith("clientPort")) { clientPort = value; } if (host != null && clientPort != null) break; } return host != null && clientPort != null? host + ":" + clientPort: null; }
/** * Run the tool. * @param args Command line arguments. */ public static void main(String args[]) { Configuration conf = WaspConfiguration.create(); // Note that we do not simply grab the property // FConstants.ZOOKEEPER_QUORUM from the WaspConfiguration because the // user may be using a zoo.cfg file. Properties zkProps = ZKConfig.makeZKProps(conf); for (Entry<Object, Object> entry : zkProps.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.")) { String[] parts = value.split(":"); String host = parts[0]; System.out.println("ZK host:" + host); } } } }
/** * Parse ZooKeeper configuration from Wasp XML config and run a QuorumPeer. * @param args String[] of command line arguments. Not used. */ public static void main(String[] args) { Configuration conf = WaspConfiguration.create(); try { Properties zkProperties = ZKConfig.makeZKProps(conf); writeMyID(conf, zkProperties); QuorumPeerConfig zkConfig = new QuorumPeerConfig(); zkConfig.parseProperties(zkProperties); runZKServer(zkConfig); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }