org.apache.hadoop.hbase.zookeeper.ZKConfig.makeZKProps()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(13.1k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKConfig.makeZKProps()方法的一些代码示例,展示了ZKConfig.makeZKProps()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKConfig.makeZKProps()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKConfig
类名称:ZKConfig
方法名:makeZKProps

ZKConfig.makeZKProps介绍

[英]Make a Properties object holding ZooKeeper config. Parses the corresponding config options from the HBase XML configs and generates the appropriate ZooKeeper properties.
[中]创建一个包含ZooKeeper配置的属性对象。解析HBase XML配置中相应的配置选项,并生成相应的ZooKeeper属性。

代码示例

代码示例来源:origin: apache/hbase

@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"));
}

代码示例来源:origin: apache/hbase

/**
 * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
 * @param args String[] of command line arguments. Not used.
 */
public static void main(String[] args) {
 Configuration conf = HBaseConfiguration.create();
 try {
  Properties zkProperties = ZKConfig.makeZKProps(conf);
  writeMyID(zkProperties);
  QuorumPeerConfig zkConfig = new QuorumPeerConfig();
  zkConfig.parseProperties(zkProperties);
  // login the zookeeper server principal (if using security)
  ZKUtil.loginServer(conf, HConstants.ZK_SERVER_KEYTAB_FILE,
   HConstants.ZK_SERVER_KERBEROS_PRINCIPAL,
   zkConfig.getClientPortAddress().getHostName());
  runZKServer(zkConfig);
 } catch (Exception e) {
  LOG.error("Failed to start ZKServer", e);
  System.exit(-1);
 }
}

代码示例来源:origin: apache/hbase

@Test public void testShouldAssignDefaultZookeeperClientPort() {
 Configuration config = HBaseConfiguration.create();
 config.clear();
 Properties p = ZKConfig.makeZKProps(config);
 assertNotNull(p);
 assertEquals(2181, p.get("clientPort"));
}

代码示例来源:origin: apache/hbase

@Test public void testMakeZKProps() {
 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
 conf.set(HConstants.ZOOKEEPER_DATA_DIR, this.dataDir.toString());
 Properties properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), (String)properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("localhost:2888:3888", properties.get("server.0"));
 assertEquals(null, properties.get("server.1"));
 String oldValue = conf.get(HConstants.ZOOKEEPER_QUORUM);
 conf.set(HConstants.ZOOKEEPER_QUORUM, "a.foo.bar,b.foo.bar,c.foo.bar");
 properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("a.foo.bar:2888:3888", properties.get("server.0"));
 assertEquals("b.foo.bar:2888:3888", properties.get("server.1"));
 assertEquals("c.foo.bar:2888:3888", properties.get("server.2"));
 assertEquals(null, properties.get("server.3"));
 conf.set(HConstants.ZOOKEEPER_QUORUM, oldValue);
}

代码示例来源:origin: co.cask.hbase/hbase

/**
  * 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));
 }
}

代码示例来源:origin: co.cask.hbase/hbase

/**
  * Run the tool.
  * @param args Command line arguments.
  */
 public static void main(String args[]) {
  Configuration conf = HBaseConfiguration.create();
  // 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(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);
   }
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

public static ServerName[] readZKNodes(Configuration conf) {
 List<ServerName> hosts = new LinkedList<ServerName>();
 // 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(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];
   int port = HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT;
   if (parts.length > 1) {
    port = Integer.parseInt(parts[1]);
   }
   hosts.add(ServerName.valueOf(host, port, -1));
  }
 }
 return hosts.toArray(new ServerName[hosts.size()]);
}

代码示例来源:origin: co.cask.hbase/hbase

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 host = null;
 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;
 for (int i = 0; i < hosts.size(); i++) {
  if (i > 0)
   host += "," + hosts.get(i);
  else
   host = hosts.get(i);
 }
 return host != null ? host + ":" + clientPort : null;
}

代码示例来源:origin: co.cask.hbase/hbase

/**
 * Creates a new connection to ZooKeeper, pulling settings and ensemble config
 * from the specified configuration object using methods from {@link ZKConfig}.
 *
 * Sets the connection status monitoring watcher to the specified watcher.
 *
 * @param conf configuration to pull ensemble and other settings from
 * @param watcher watcher to monitor connection changes
 * @return connection to zookeeper
 * @throws IOException if unable to connect to zk or config problem
 */
public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
throws IOException {
 Properties properties = ZKConfig.makeZKProps(conf);
 String ensemble = ZKConfig.getZKQuorumServersString(properties);
 return connect(conf, ensemble, watcher);
}

代码示例来源:origin: alibaba/wasp

/**
 * Creates a new connection to ZooKeeper, pulling settings and ensemble config
 * from the specified configuration object using methods from {@link org.apache.hadoop.hbase.zookeeper.ZKConfig}
 * .
 *
 * Sets the connection status monitoring watcher to the specified watcher.
 *
 * @param conf
 *          configuration to pull ensemble and other settings from
 * @param watcher
 *          watcher to monitor connection changes
 * @return connection to zookeeper
 * @throws java.io.IOException
 *           if unable to connect to zk or config problem
 */
public static RecoverableZooKeeper connect(Configuration conf, Watcher watcher)
  throws IOException {
 Properties properties = ZKConfig.makeZKProps(conf);
 String ensemble = ZKConfig.getZKQuorumServersString(properties);
 return connect(conf, ensemble, watcher);
}

代码示例来源:origin: co.cask.hbase/hbase

/**
 * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
 * @param args String[] of command line arguments. Not used.
 */
public static void main(String[] args) {
 Configuration conf = HBaseConfiguration.create();
 try {
  Properties zkProperties = ZKConfig.makeZKProps(conf);
  writeMyID(zkProperties);
  QuorumPeerConfig zkConfig = new QuorumPeerConfig();
  zkConfig.parseProperties(zkProperties);
  // login the zookeeper server principal (if using security)
  ZKUtil.loginServer(conf, "hbase.zookeeper.server.keytab.file",
   "hbase.zookeeper.server.kerberos.principal",
   zkConfig.getClientPortAddress().getHostName());
  runZKServer(zkConfig);
 } catch (Exception e) {
  e.printStackTrace();
  System.exit(-1);
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@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"));
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

/**
 * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
 * @param args String[] of command line arguments. Not used.
 */
public static void main(String[] args) {
 Configuration conf = HBaseConfiguration.create();
 try {
  Properties zkProperties = ZKConfig.makeZKProps(conf);
  writeMyID(zkProperties);
  QuorumPeerConfig zkConfig = new QuorumPeerConfig();
  zkConfig.parseProperties(zkProperties);
  // login the zookeeper server principal (if using security)
  ZKUtil.loginServer(conf, HConstants.ZK_SERVER_KEYTAB_FILE,
   HConstants.ZK_SERVER_KERBEROS_PRINCIPAL,
   zkConfig.getClientPortAddress().getHostName());
  runZKServer(zkConfig);
 } catch (Exception e) {
  e.printStackTrace();
  System.exit(-1);
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

@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"));
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
 * @param args String[] of command line arguments. Not used.
 */
public static void main(String[] args) {
 Configuration conf = HBaseConfiguration.create();
 try {
  Properties zkProperties = ZKConfig.makeZKProps(conf);
  writeMyID(zkProperties);
  QuorumPeerConfig zkConfig = new QuorumPeerConfig();
  zkConfig.parseProperties(zkProperties);
  // login the zookeeper server principal (if using security)
  ZKUtil.loginServer(conf, HConstants.ZK_SERVER_KEYTAB_FILE,
   HConstants.ZK_SERVER_KERBEROS_PRINCIPAL,
   zkConfig.getClientPortAddress().getHostName());
  runZKServer(zkConfig);
 } catch (Exception e) {
  e.printStackTrace();
  System.exit(-1);
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

@Test public void testShouldAssignDefaultZookeeperClientPort() {
 Configuration config = HBaseConfiguration.create();
 config.clear();
 Properties p = ZKConfig.makeZKProps(config);
 assertNotNull(p);
 assertEquals(2181, p.get("clientPort"));
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

@Test public void testMakeZKProps() {
 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
 conf.set(HConstants.ZOOKEEPER_DATA_DIR, this.dataDir.toString());
 Properties properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), (String)properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("localhost:2888:3888", properties.get("server.0"));
 assertEquals(null, properties.get("server.1"));
 String oldValue = conf.get(HConstants.ZOOKEEPER_QUORUM);
 conf.set(HConstants.ZOOKEEPER_QUORUM, "a.foo.bar,b.foo.bar,c.foo.bar");
 properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("a.foo.bar:2888:3888", properties.get("server.0"));
 assertEquals("b.foo.bar:2888:3888", properties.get("server.1"));
 assertEquals("c.foo.bar:2888:3888", properties.get("server.2"));
 assertEquals(null, properties.get("server.3"));
 conf.set(HConstants.ZOOKEEPER_QUORUM, oldValue);
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

@Test public void testShouldAssignDefaultZookeeperClientPort() {
 Configuration config = HBaseConfiguration.create();
 config.clear();
 Properties p = ZKConfig.makeZKProps(config);
 assertNotNull(p);
 assertEquals(2181, p.get("clientPort"));
}

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

@Test public void testMakeZKProps() {
 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
 conf.set(HConstants.ZOOKEEPER_DATA_DIR, this.dataDir.toString());
 Properties properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), (String)properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("localhost:2888:3888", properties.get("server.0"));
 assertEquals(null, properties.get("server.1"));
 String oldValue = conf.get(HConstants.ZOOKEEPER_QUORUM);
 conf.set(HConstants.ZOOKEEPER_QUORUM, "a.foo.bar,b.foo.bar,c.foo.bar");
 properties = ZKConfig.makeZKProps(conf);
 assertEquals(dataDir.toString(), properties.get("dataDir"));
 assertEquals(Integer.valueOf(PORT_NO),
  Integer.valueOf(properties.getProperty("clientPort")));
 assertEquals("a.foo.bar:2888:3888", properties.get("server.0"));
 assertEquals("b.foo.bar:2888:3888", properties.get("server.1"));
 assertEquals("c.foo.bar:2888:3888", properties.get("server.2"));
 assertEquals(null, properties.get("server.3"));
 conf.set(HConstants.ZOOKEEPER_QUORUM, oldValue);
}

相关文章