/** * 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; }
if (inputStream != null) { try { return parseZooCfg(conf, inputStream); } catch (IOException e) { LOG.warn("Cannot read " + FConstants.ZOOKEEPER_CONFIG_NAME +
/** * Instantiate a ZooKeeper connection and watcher. * @param descriptor Descriptive string that is added to zookeeper sessionid * and used as identifier for this instance. * @throws java.io.IOException * @throws com.alibaba.wasp.ZooKeeperConnectionException */ public ZooKeeperWatcher(Configuration conf, String descriptor, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException { this.conf = conf; // Capture a stack trace now. Will print it out later if problem so we can // distingush amongst the myriad ZKWs. try { throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING"); } catch (Exception e) { this.constructorCaller = e; } this.quorum = ZKConfig.getZKQuorumServersString(conf); // Identifier will get the session id appended later below down when we // handle the sync connect event. this.identifier = descriptor; this.abortable = abortable; setNodeNames(conf); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, descriptor); if (canCreateBaseZNode) { createBaseZNodes(); } }
/** * 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); } }