gpt4 book ai didi

org.apache.hadoop.hbase.zookeeper.ZKMainServer类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 18:19:31 25 4
gpt4 key购买 nike

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

ZKMainServer介绍

[英]Tool for running ZookeeperMain from HBase by reading a ZooKeeper server from HBase XML configuration.
[中]通过从HBase XML配置读取ZooKeeper服务器,从HBase运行ZookeeperMain的工具。

代码示例

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

/**
  * Run the tool.
  * @param args Command line arguments. First arg is path to zookeepers file.
  */
 public static void main(String[] args) throws Exception {
  String [] newArgs = args;
  if (!hasServer(args)) {
   // Add the zk ensemble from configuration if none passed on command-line.
   Configuration conf = HBaseConfiguration.create();
   String hostport = new ZKMainServer().parse(conf);
   if (hostport != null && hostport.length() > 0) {
    newArgs = new String[args.length + 2];
    System.arraycopy(args, 0, newArgs, 2, args.length);
    newArgs[0] = "-server";
    newArgs[1] = hostport;
   }
  }
  // If command-line arguments, run our hack so they are executed.
  // ZOOKEEPER-1897 was committed to zookeeper-3.4.6 but elsewhere in this class we say
  // 3.4.6 breaks command-processing; TODO.
  if (hasCommandLineArguments(args)) {
   HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain zkm =
    new HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain(newArgs);
   zkm.runCmdLine();
  } else {
   ZooKeeperMain.main(newArgs);
  }
 }
}

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

@Test
public void testHostPortParse() {
 ZKMainServer parser = new ZKMainServer();
 Configuration c = HBaseConfiguration.create();
 assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
 final String port = "1234";
 c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
 c.set("hbase.zookeeper.quorum", "example.com");
 assertEquals("example.com:" + port, parser.parse(c));
 c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
 String ensemble = parser.parse(c);
 assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));
 ensemble = parser.parse(c);
 assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456");
 ensemble = parser.parse(c);
 assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port);
 ensemble = parser.parse(c);
 assertEquals("[2001:db8:1::242:ac11:2]:2181," +
        "[2001:db8:1::242:ac11:3]:5678", ensemble);
 ensemble = parser.parse(c);
 assertEquals("[1001:db8:1::242:ac11:8]:1234, [2001:db8:1::242:df23:2]:9876," +
        "[2001:db8:1::242:ac11:3]:5678", ensemble);
  ensemble = parser.parse(c);
  Assert.fail("IPv6 address should be 8 groups.");
 } catch (IllegalArgumentException e) {

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

/**
 * We need delete of a znode to work at least.
 */
@Test
public void testCommandLineWorks() throws Exception {
 System.setSecurityManager(new NoExitSecurityManager());
 HBaseZKTestingUtility htu = new HBaseZKTestingUtility();
 // Make it long so for sure succeeds.
 htu.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 30000);
 htu.startMiniZKCluster();
 try {
  ZKWatcher zkw = htu.getZooKeeperWatcher();
  String znode = "/testCommandLineWorks";
  ZKUtil.createWithParents(zkw, znode, HConstants.EMPTY_BYTE_ARRAY);
  ZKUtil.checkExists(zkw, znode);
  boolean exception = false;
  try {
   ZKMainServer.main(new String [] {"-server",
    "localhost:" + htu.getZkCluster().getClientPort(), "delete", znode});
  } catch (ExitException ee) {
   // ZKMS calls System.exit which should trigger this exception.
   exception = true;
  }
  assertTrue(exception);
  assertEquals(-1, ZKUtil.checkExists(zkw, znode));
 } finally {
  htu.shutdownMiniZKCluster();
  System.setSecurityManager(null); // or save and restore original
 }
}

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

/**
 * @param args the arguments to check for command-line arguments
 * @return True if command-line arguments were passed.
 */
private static boolean hasCommandLineArguments(final String[] args) {
 if (hasServer(args)) {
  if (args.length < 2) {
   throw new IllegalStateException("-server param but no value");
  }
  return args.length > 2;
 }
 return args.length > 0;
}

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

@Test
 public void testHostPortParse() {
  ZKMainServer parser = new ZKMainServer();
  Configuration c = HBaseConfiguration.create();
  assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
  final String port = "1234";
  c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
  c.set("hbase.zookeeper.quorum", "example.com");
  assertEquals("example.com:" + port, parser.parse(c));
  c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
  String ensemble = parser.parse(c);
  assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));

  // multiple servers with its own port
  c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456");
  ensemble = parser.parse(c);
  assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456");

  // some servers without its own port, which will be assigned the default client port
  c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com");
  ensemble = parser.parse(c);
  assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port);
 }
}

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

/**
 * We need delete of a znode to work at least.
 */
@Test
public void testCommandLineWorks() throws Exception {
 System.setSecurityManager(new NoExitSecurityManager());
 HBaseZKTestingUtility htu = new HBaseZKTestingUtility();
 // Make it long so for sure succeeds.
 htu.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 30000);
 htu.startMiniZKCluster();
 try {
  ZKWatcher zkw = htu.getZooKeeperWatcher();
  String znode = "/testCommandLineWorks";
  ZKUtil.createWithParents(zkw, znode, HConstants.EMPTY_BYTE_ARRAY);
  ZKUtil.checkExists(zkw, znode);
  boolean exception = false;
  try {
   ZKMainServer.main(new String [] {"-server",
    "localhost:" + htu.getZkCluster().getClientPort(), "delete", znode});
  } catch (ExitException ee) {
   // ZKMS calls System.exit which should trigger this exception.
   exception = true;
  }
  assertTrue(exception);
  assertEquals(-1, ZKUtil.checkExists(zkw, znode));
 } finally {
  htu.shutdownMiniZKCluster();
  System.setSecurityManager(null); // or save and restore original
 }
}

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

/**
 * @param args the arguments to check for command-line arguments
 * @return True if command-line arguments were passed.
 */
private static boolean hasCommandLineArguments(final String[] args) {
 if (hasServer(args)) {
  if (args.length < 2) {
   throw new IllegalStateException("-server param but no value");
  }
  return args.length > 2;
 }
 return args.length > 0;
}

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

/**
  * Run the tool.
  * @param args Command line arguments. First arg is path to zookeepers file.
  */
 public static void main(String[] args) throws Exception {
  String [] newArgs = args;
  if (!hasServer(args)) {
   // Add the zk ensemble from configuration if none passed on command-line.
   Configuration conf = HBaseConfiguration.create();
   String hostport = new ZKMainServer().parse(conf);
   if (hostport != null && hostport.length() > 0) {
    newArgs = new String[args.length + 2];
    System.arraycopy(args, 0, newArgs, 2, args.length);
    newArgs[0] = "-server";
    newArgs[1] = hostport;
   }
  }
  // If command-line arguments, run our hack so they are executed.
  // ZOOKEEPER-1897 was committed to zookeeper-3.4.6 but elsewhere in this class we say
  // 3.4.6 breaks command-processing; TODO.
  if (hasCommandLineArguments(args)) {
   HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain zkm =
    new HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain(newArgs);
   zkm.runCmdLine();
  } else {
   ZooKeeperMain.main(newArgs);
  }
 }
}

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

@Test
 public void testHostPortParse() {
  ZKMainServer parser = new ZKMainServer();
  Configuration c = HBaseConfiguration.create();
  assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
  final String port = "1234";
  c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
  c.set("hbase.zookeeper.quorum", "example.com");
  assertEquals("example.com:" + port, parser.parse(c));
  c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
  String ensemble = parser.parse(c);
  assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));

  // multiple servers with its own port
  c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456");
  ensemble = parser.parse(c);
  assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456");

  // some servers without its own port, which will be assigned the default client port
  c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com");
  ensemble = parser.parse(c);
  assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port);
 }
}

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

/**
 * We need delete of a znode to work at least.
 */
@Test
public void testCommandLineWorks() throws Exception {
 System.setSecurityManager(new NoExitSecurityManager());
 HBaseZKTestingUtility htu = new HBaseZKTestingUtility();
 // Make it long so for sure succeeds.
 htu.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 30000);
 htu.startMiniZKCluster();
 try {
  ZKWatcher zkw = htu.getZooKeeperWatcher();
  String znode = "/testCommandLineWorks";
  ZKUtil.createWithParents(zkw, znode, HConstants.EMPTY_BYTE_ARRAY);
  ZKUtil.checkExists(zkw, znode);
  boolean exception = false;
  try {
   ZKMainServer.main(new String [] {"-server",
    "localhost:" + htu.getZkCluster().getClientPort(), "delete", znode});
  } catch (ExitException ee) {
   // ZKMS calls System.exit which should trigger this exception.
   exception = true;
  }
  assertTrue(exception);
  assertEquals(-1, ZKUtil.checkExists(zkw, znode));
 } finally {
  htu.shutdownMiniZKCluster();
  System.setSecurityManager(null); // or save and restore original
 }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com