Esempio n. 1
0
 public String parse(final Configuration c) {
   // Note that we do not simply grab the property
   // HConstants.ZOOKEEPER_QUORUM from the HBaseConfiguration because the
   // user may be using a zoo.cfg file.
   Properties zkProps = ZKConfig.makeZKProps(c);
   String clientPort = null;
   List<String> hosts = new ArrayList<String>();
   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(":");
       hosts.add(parts[0]);
     } else if (key.endsWith("clientPort")) {
       clientPort = value;
     }
   }
   if (hosts.isEmpty() || clientPort == null) return null;
   StringBuilder host = new StringBuilder();
   for (int i = 0; i < hosts.size(); i++) {
     if (i > 0) host.append("," + hosts.get(i));
     else host.append(hosts.get(i));
     host.append(":");
     host.append(clientPort);
   }
   return host.toString();
 }
Esempio n. 2
0
 @Test
 public void testZKConfigLoading() throws Exception {
   Configuration conf = HBaseConfiguration.create();
   // Test that we read only from the config instance
   // (i.e. via hbase-default.xml and hbase-site.xml)
   conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181);
   Properties props = ZKConfig.makeZKProps(conf);
   assertEquals(
       "Property client port should have been default from the HBase config",
       "2181",
       props.getProperty("clientPort"));
 }