类org.apache.hadoop.hbase.ZooKeeperConnectionException源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.ZooKeeperConnectionException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: TestMasterNoCluster.java
@After
public void tearDown()
throws KeeperException, ZooKeeperConnectionException, IOException {
  // Make sure zk is clean before we run the next test.
  ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(),
      "@Before", new Abortable() {
    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return false;
    }
  });
  ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode);
  zkw.close();
}
 
源代码2 项目: hbase   文件: ZooKeeperHelper.java
/**
 * Ensure passed zookeeper is connected.
 * @param timeout Time to wait on established Connection
 */
public static ZooKeeper ensureConnectedZooKeeper(ZooKeeper zookeeper, int timeout)
    throws ZooKeeperConnectionException {
  if (zookeeper.getState().isConnected()) {
    return zookeeper;
  }
  Stopwatch stopWatch = Stopwatch.createStarted();
  // Make sure we are connected before we hand it back.
  while(!zookeeper.getState().isConnected()) {
    Threads.sleep(1);
    if (stopWatch.elapsed(TimeUnit.MILLISECONDS) > timeout) {
      throw new ZooKeeperConnectionException("Failed connect after waiting " +
          stopWatch.elapsed(TimeUnit.MILLISECONDS) + "ms (zk session timeout); " +
          zookeeper);
    }
  }
  return zookeeper;
}
 
源代码3 项目: examples   文件: Create2.java
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  // tag::CREATE2[]
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("pages"));
  byte[][] splits = {Bytes.toBytes("b"), Bytes.toBytes("f"),
    Bytes.toBytes("k"), Bytes.toBytes("n"), Bytes.toBytes("t")};
  desc.setValue(Bytes.toBytes("comment"), Bytes.toBytes("Create 10012014"));
  HColumnDescriptor family = new HColumnDescriptor("c");
  family.setCompressionType(Algorithm.GZ);
  family.setMaxVersions(52);
  family.setBloomFilterType(BloomType.ROW);
  desc.addFamily(family);
  admin.createTable(desc, splits);
  // end::CREATE2[]
  admin.close();
}
 
源代码4 项目: examples   文件: Describe.java
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  // Instantiate default HBase configuration object.
  // Configuration file must be in the classpath
  Configuration conf = HBaseConfiguration.create();
  // tag::DESCRIBE
  HBaseAdmin admin = new HBaseAdmin(conf);
  HTableDescriptor desc = admin.getTableDescriptor(TableName.valueOf("crc"));
  Collection<HColumnDescriptor> families = desc.getFamilies();
  System.out.println("Table " + desc.getTableName() + " has " + families.size() + " family(ies)");
  for (Iterator<HColumnDescriptor> iterator = families.iterator(); iterator.hasNext();) {
    HColumnDescriptor family = iterator.next();
    System.out.println("Family details: " + family);
  }
  // end::DESCRIBE
  admin.close();
}
 
源代码5 项目: examples   文件: Merge.java
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  // tag::MERGE1[]
  Configuration conf = HBaseConfiguration.create();
  Connection connection = ConnectionFactory.createConnection(conf);
  HBaseAdmin admin = (HBaseAdmin)connection.getAdmin();
  List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf("t1")); //<1>
  LOG.info("testtable contains " + regions.size() + " regions.");
  for (int index = 0; index < regions.size() / 2; index++) {
    HRegionInfo region1 = regions.get(index*2);
    HRegionInfo region2 = regions.get(index*2+1);
    LOG.info("Merging regions " + region1 + " and " + region2);
    admin.mergeRegions(region1.getEncodedNameAsBytes(), 
                       region2.getEncodedNameAsBytes(), false); //<2>
  }
  admin.close();
  // end::MERGE1[]
}
 
源代码6 项目: examples   文件: CreateTable.java
public static void main(String[] args) throws MasterNotRunningException,
    ZooKeeperConnectionException, IOException {
  try (Connection connection = ConnectionFactory.createConnection();
      Admin admin = connection.getAdmin();) {
    LOG.info("Starting table creation");
    // tag::CREATE[]
    TableName documents = TableName.valueOf("documents");
    HTableDescriptor desc = new HTableDescriptor(documents);
    HColumnDescriptor family = new HColumnDescriptor("c");
    family.setCompressionType(Algorithm.GZ);
    family.setBloomFilterType(BloomType.NONE);
    desc.addFamily(family);
    UniformSplit uniformSplit = new UniformSplit();
    admin.createTable(desc, uniformSplit.split(8));
    // end::CREATE[]
    LOG.info("Table successfuly created");
  }
}
 
源代码7 项目: HBase.MCC   文件: HBaseAdminMultiCluster.java
public HBaseAdminMultiCluster(Configuration c)
    throws MasterNotRunningException, ZooKeeperConnectionException,
    IOException {
  super(HBaseMultiClusterConfigUtil.splitMultiConfigFile(c).get(
      HBaseMultiClusterConfigUtil.PRIMARY_NAME));

  Map<String, Configuration> configs = HBaseMultiClusterConfigUtil
      .splitMultiConfigFile(c);

  for (Entry<String, Configuration> entry : configs.entrySet()) {

    if (!entry.getKey().equals(HBaseMultiClusterConfigUtil.PRIMARY_NAME)) {
      HBaseAdmin admin = new HBaseAdmin(entry.getValue());
      LOG.info("creating HBaseAdmin for : " + entry.getKey());
      failoverAdminMap.put(entry.getKey(), admin);
      LOG.info(" - successfully creating HBaseAdmin for : " + entry.getKey());
    }
  }
  LOG.info("Successful loaded all HBaseAdmins");

}
 
源代码8 项目: hbase-tools   文件: HBaseClient.java
private static void validateAuthentication() throws ZooKeeperConnectionException {
    try {
        // Is there something better?
        admin.isMasterRunning();
    } catch (MasterNotRunningException e) {
        System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n");
    }
}
 
源代码9 项目: hbase-tools   文件: HBaseClient.java
private static void validateAuthentication() throws ZooKeeperConnectionException {
    try {
        // Is there something better?
        admin.isMasterRunning();
    } catch (MasterNotRunningException e) {
        System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n");
    }
}
 
源代码10 项目: hbase-tools   文件: HBaseClient.java
private static void validateAuthentication() throws ZooKeeperConnectionException {
    try {
        // Is there something better?
        admin.isMasterRunning();
    } catch (MasterNotRunningException e) {
        System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n");
    }
}
 
源代码11 项目: hbase-tools   文件: HBaseClient.java
private static void validateAuthentication() throws ZooKeeperConnectionException {
    try {
        // Is there something better?
        admin.isMasterRunning();
    } catch (MasterNotRunningException e) {
        System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n");
    }
}
 
源代码12 项目: hbase-tools   文件: HBaseClient.java
private static void validateAuthentication() throws ZooKeeperConnectionException {
    try {
        // Is there something better?
        admin.isMasterRunning();
    } catch (MasterNotRunningException e) {
        System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n");
    }
}
 
源代码13 项目: hbase   文件: HFileArchiveManager.java
public HFileArchiveManager(Connection connection, Configuration conf)
    throws ZooKeeperConnectionException, IOException {
  this.zooKeeper = new ZKWatcher(conf, "hfileArchiveManager-on-" + connection.toString(),
      connection);
  this.archiveZnode = ZKTableArchiveClient.getArchiveZNode(this.zooKeeper.getConfiguration(),
    this.zooKeeper);
}
 
源代码14 项目: hbase   文件: MockRegionServer.java
/**
 * @param sn Name of this mock regionserver
 * @throws IOException
 * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException
 */
MockRegionServer(final Configuration conf, final ServerName sn)
throws ZooKeeperConnectionException, IOException {
  this.sn = sn;
  this.conf = conf;
  this.zkw = new ZKWatcher(conf, sn.toString(), this, true);
}
 
源代码15 项目: hbase   文件: MockServer.java
/**
 * @param htu Testing utility to use
 * @param zkw If true, create a zkw.
 * @throws ZooKeeperConnectionException
 * @throws IOException
 */
public MockServer(final HBaseTestingUtility htu, final boolean zkw)
throws ZooKeeperConnectionException, IOException {
  this.htu = htu;
  this.zk = zkw?
    new ZKWatcher(htu.getConfiguration(), NAME.toString(), this, true):
    null;
}
 
源代码16 项目: hbase   文件: ZKWatcher.java
private void createBaseZNodes() throws ZooKeeperConnectionException {
  try {
    // Create all the necessary "directories" of znodes
    ZKUtil.createWithParents(this, znodePaths.baseZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.rsZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.drainingZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.tableZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.splitLogZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.backupMasterAddressesZNode);
    ZKUtil.createAndFailSilent(this, znodePaths.masterMaintZNode);
  } catch (KeeperException e) {
    throw new ZooKeeperConnectionException(
        prefix("Unexpected KeeperException creating base node"), e);
  }
}
 
源代码17 项目: examples   文件: Create1.java
public static void main(String[] args)
  throws MasterNotRunningException, ZooKeeperConnectionException,
         IOException {
  // tag::CREATE1[]
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  HTableDescriptor desc = 
    new HTableDescriptor(TableName.valueOf("testtable_create1"));
  HColumnDescriptor family = new HColumnDescriptor("f1");
  desc.addFamily(family);
  admin.createTable(desc);
  // end::CREATE1[]
  admin.close();
}
 
源代码18 项目: examples   文件: Create3.java
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  // tag::CREATE3[]
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("crc"));
  desc.setMaxFileSize((long)20*1024*1024*1024);
  desc.setConfiguration("hbase.hstore.compaction.min", "5");
  HColumnDescriptor family = new HColumnDescriptor("c");
  family.setInMemory(true);
  desc.addFamily(family);
  UniformSplit uniformSplit = new UniformSplit();
  admin.createTable(desc, uniformSplit.split(64));
  // end::CREATE3[]
  admin.close();
}
 
源代码19 项目: examples   文件: Create4.java
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
  Configuration conf = HBaseConfiguration.create();
  HBaseAdmin admin = new HBaseAdmin(conf);
  // tag::CREATE4[]
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("access"));
  HColumnDescriptor family = new HColumnDescriptor("d");
  family.setValue("comment", "Last user access date");
  family.setMaxVersions(10);
  family.setMinVersions(2);
  family.setTimeToLive(2678400);
  desc.addFamily(family);
  admin.createTable(desc);
  // end::CREATE4[]
  admin.close();
}
 
源代码20 项目: DistributedCrawler   文件: HBasePool.java
private HBasePool() throws ZooKeeperConnectionException {
	Configuration conf = new Configuration();
	conf.set("hbase.zookeeper.property.clientPort", "2181");
	conf.set("hbase.zookeeper.quorum", "gs-pc");
	conf.set("hbase.master", "gs-pc:60000");
	this.conf = conf;
	connection = HConnectionManager.createConnection(conf);
}
 
源代码21 项目: DistributedCrawler   文件: HBasePool.java
protected synchronized static HBasePool getInstance()
		throws ZooKeeperConnectionException {
	if (instance == null) {
		instance = new HBasePool();
	}
	return instance;
}
 
源代码22 项目: DistributedCrawler   文件: TestHBaseDAO.java
@Test
public void testSave() throws ZooKeeperConnectionException, IOException, SQLException{
	PagePOJO pojo = new PagePOJO("http://haha",3,"XIXIX","ppppp");
	PageDAO dao = new PageDAOHBaseImpl("page");
	dao.save(pojo);
	dao.close();
}
 
源代码23 项目: spliceengine   文件: ZkUtils.java
/**
 * Gets a direct interface to a ZooKeeper instance.
 *
 * @return a direct interface to ZooKeeper.
 */
public static RecoverableZooKeeper getRecoverableZooKeeper(){
    try{
        return zkManager.getRecoverableZooKeeper();
    }catch(ZooKeeperConnectionException e){
        LOG.error("Unable to connect to zookeeper, aborting",e);
        throw new RuntimeException(e);
    }
}
 
源代码24 项目: spliceengine   文件: ZkUtils.java
/**
 * @return direct interface to a ZooKeeperWatcher
 */
public static ZKWatcher getZooKeeperWatcher(){
    try{
        return zkManager.getZooKeeperWatcher();
    }catch(ZooKeeperConnectionException e){
        LOG.error("Unable to connect to zookeeper, aborting",e);
        throw new RuntimeException(e);
    }
}
 
源代码25 项目: spliceengine   文件: SpliceZooKeeperManager.java
public <T> T execute(Command<T> command) throws InterruptedException, KeeperException{
    try{
        return command.execute(getRecoverableZooKeeper());
    }catch(ZooKeeperConnectionException e){
        throw new KeeperException.SessionExpiredException();
    }
}
 
源代码26 项目: hbase   文件: TestLogsCleaner.java
public FaultyZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable)
    throws ZooKeeperConnectionException, IOException {
  super(conf, identifier, abortable);
}
 
源代码27 项目: hbase   文件: TestReplicationHFileCleaner.java
public FaultyZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable)
    throws ZooKeeperConnectionException, IOException {
  super(conf, identifier, abortable);
}
 
源代码28 项目: hbase   文件: MockServer.java
public MockServer() throws ZooKeeperConnectionException, IOException {
  // Shutdown default constructor by making it private.
  this(null);
}
 
源代码29 项目: hbase   文件: MockServer.java
public MockServer(final HBaseTestingUtility htu)
throws ZooKeeperConnectionException, IOException {
  this(htu, true);
}
 
源代码30 项目: hbase   文件: TestSplitTransactionOnCluster.java
/**
 * Ensure single table region is not on same server as the single hbase:meta table
 * region.
 * @return Index of the server hosting the single table region
 * @throws UnknownRegionException
 * @throws MasterNotRunningException
 * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException
 * @throws InterruptedException
 */
private int ensureTableRegionNotOnSameServerAsMeta(final Admin admin,
    final RegionInfo hri)
throws IOException, MasterNotRunningException,
ZooKeeperConnectionException, InterruptedException {
  // Now make sure that the table region is not on same server as that hosting
  // hbase:meta  We don't want hbase:meta replay polluting our test when we later crash
  // the table region serving server.
  int metaServerIndex = cluster.getServerWithMeta();
  boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TESTING_UTIL.getConfiguration());
  if (tablesOnMaster) {
    // Need to check master is supposed to host meta... perhaps it is not.
    throw new UnsupportedOperationException();
    // TODO: assertTrue(metaServerIndex == -1); // meta is on master now
  }
  HRegionServer metaRegionServer = tablesOnMaster?
    cluster.getMaster(): cluster.getRegionServer(metaServerIndex);
  int tableRegionIndex = cluster.getServerWith(hri.getRegionName());
  assertTrue(tableRegionIndex != -1);
  HRegionServer tableRegionServer = cluster.getRegionServer(tableRegionIndex);
  LOG.info("MetaRegionServer=" + metaRegionServer.getServerName() +
    ", other=" + tableRegionServer.getServerName());
  if (metaRegionServer.getServerName().equals(tableRegionServer.getServerName())) {
    HRegionServer hrs = getOtherRegionServer(cluster, metaRegionServer);
    assertNotNull(hrs);
    assertNotNull(hri);
    LOG.info("Moving " + hri.getRegionNameAsString() + " from " +
      metaRegionServer.getServerName() + " to " +
      hrs.getServerName() + "; metaServerIndex=" + metaServerIndex);
    admin.move(hri.getEncodedNameAsBytes(), hrs.getServerName());
  }
  // Wait till table region is up on the server that is NOT carrying hbase:meta.
  for (int i = 0; i < 100; i++) {
    tableRegionIndex = cluster.getServerWith(hri.getRegionName());
    if (tableRegionIndex != -1 && tableRegionIndex != metaServerIndex) break;
    LOG.debug("Waiting on region move off the hbase:meta server; current index " +
      tableRegionIndex + " and metaServerIndex=" + metaServerIndex);
    Thread.sleep(100);
  }
  assertTrue("Region not moved off hbase:meta server, tableRegionIndex=" + tableRegionIndex,
    tableRegionIndex != -1 && tableRegionIndex != metaServerIndex);
  // Verify for sure table region is not on same server as hbase:meta
  tableRegionIndex = cluster.getServerWith(hri.getRegionName());
  assertTrue(tableRegionIndex != -1);
  assertNotSame(metaServerIndex, tableRegionIndex);
  return tableRegionIndex;
}
 
 类所在包
 同包方法