Java Code Examples for org.apache.hadoop.hbase.ZooKeeperConnectionException

The following examples show how to use org.apache.hadoop.hbase.ZooKeeperConnectionException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hbase   Source File: TestMasterNoCluster.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source Project: hbase   Source File: ZooKeeperHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source Project: examples   Source File: Create2.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source Project: examples   Source File: Describe.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 5
Source Project: examples   Source File: Merge.java    License: Apache License 2.0 6 votes vote down vote up
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[]
}
 
Example 6
Source Project: examples   Source File: CreateTable.java    License: Apache License 2.0 6 votes vote down vote up
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");
  }
}
 
Example 7
Source Project: HBase.MCC   Source File: HBaseAdminMultiCluster.java    License: Apache License 2.0 6 votes vote down vote up
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");

}
 
Example 8
Source Project: hbase-tools   Source File: HBaseClient.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 9
Source Project: hbase-tools   Source File: HBaseClient.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 10
Source Project: hbase-tools   Source File: HBaseClient.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 11
Source Project: hbase-tools   Source File: HBaseClient.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 12
Source Project: hbase-tools   Source File: HBaseClient.java    License: Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 13
Source Project: hbase   Source File: HFileArchiveManager.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source Project: hbase   Source File: MockRegionServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 15
Source Project: hbase   Source File: MockServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 16
Source Project: hbase   Source File: ZKWatcher.java    License: Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 17
Source Project: examples   Source File: Create1.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 18
Source Project: examples   Source File: Create3.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 19
Source Project: examples   Source File: Create4.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 20
Source Project: DistributedCrawler   Source File: HBasePool.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 21
Source Project: DistributedCrawler   Source File: HBasePool.java    License: Apache License 2.0 5 votes vote down vote up
protected synchronized static HBasePool getInstance()
		throws ZooKeeperConnectionException {
	if (instance == null) {
		instance = new HBasePool();
	}
	return instance;
}
 
Example 22
Source Project: DistributedCrawler   Source File: TestHBaseDAO.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 23
Source Project: spliceengine   Source File: ZkUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 24
Source Project: spliceengine   Source File: ZkUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @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);
    }
}
 
Example 25
public <T> T execute(Command<T> command) throws InterruptedException, KeeperException{
    try{
        return command.execute(getRecoverableZooKeeper());
    }catch(ZooKeeperConnectionException e){
        throw new KeeperException.SessionExpiredException();
    }
}
 
Example 26
Source Project: hbase   Source File: TestLogsCleaner.java    License: Apache License 2.0 4 votes vote down vote up
public FaultyZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable)
    throws ZooKeeperConnectionException, IOException {
  super(conf, identifier, abortable);
}
 
Example 27
Source Project: hbase   Source File: TestReplicationHFileCleaner.java    License: Apache License 2.0 4 votes vote down vote up
public FaultyZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable)
    throws ZooKeeperConnectionException, IOException {
  super(conf, identifier, abortable);
}
 
Example 28
Source Project: hbase   Source File: MockServer.java    License: Apache License 2.0 4 votes vote down vote up
public MockServer() throws ZooKeeperConnectionException, IOException {
  // Shutdown default constructor by making it private.
  this(null);
}
 
Example 29
Source Project: hbase   Source File: MockServer.java    License: Apache License 2.0 4 votes vote down vote up
public MockServer(final HBaseTestingUtility htu)
throws ZooKeeperConnectionException, IOException {
  this(htu, true);
}
 
Example 30
Source Project: hbase   Source File: TestSplitTransactionOnCluster.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}