use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.
the class HBaseAdmin method available.
/**
* Is HBase available? Throw an exception if not.
* @param conf system configuration
* @throws MasterNotRunningException if the master is not running.
* @throws ZooKeeperConnectionException if unable to connect to zookeeper.
* // TODO do not expose ZKConnectionException.
*/
public static void available(final Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
Configuration copyOfConf = HBaseConfiguration.create(conf);
// We set it to make it fail as soon as possible if HBase is not available
copyOfConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
copyOfConf.setInt("zookeeper.recovery.retry", 0);
// If the connection exists, we may have a connection to ZK that does not work anymore
try (ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(copyOfConf)) {
// Check ZK first.
// If the connection exists, we may have a connection to ZK that does not work anymore
ZooKeeperKeepAliveConnection zkw = null;
try {
// This is NASTY. FIX!!!! Dependent on internal implementation! TODO
zkw = ((ConnectionImplementation) connection).getKeepAliveZooKeeperWatcher();
zkw.getRecoverableZooKeeper().getZooKeeper().exists(zkw.znodePaths.baseZNode, false);
} catch (IOException e) {
throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException("Can't connect to ZooKeeper").initCause(e);
} catch (KeeperException e) {
throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
} finally {
if (zkw != null) {
zkw.close();
}
}
// can throw MasterNotRunningException
connection.isMasterRunning();
}
}
use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.
the class TestAdmin2 method testCheckHBaseAvailableWithoutCluster.
/**
* Check that we have an exception if the cluster is not there.
*/
@Test(timeout = 300000)
public void testCheckHBaseAvailableWithoutCluster() {
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
// Change the ZK address to go to something not used.
conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 9999) + 10);
long start = System.currentTimeMillis();
try {
HBaseAdmin.available(conf);
assertTrue(false);
} catch (ZooKeeperConnectionException ignored) {
} catch (IOException ignored) {
}
long end = System.currentTimeMillis();
LOG.info("It took " + (end - start) + " ms to find out that" + " HBase was not available");
}
use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.
the class ZooKeeperWatcher method createBaseZNodes.
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.tableLockZNode);
ZKUtil.createAndFailSilent(this, znodePaths.recoveringRegionsZNode);
ZKUtil.createAndFailSilent(this, znodePaths.masterMaintZNode);
} catch (KeeperException e) {
throw new ZooKeeperConnectionException(prefix("Unexpected KeeperException creating base node"), e);
}
}
use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.
the class HMasterCommandLine method stopMaster.
@SuppressWarnings("resource")
private int stopMaster() {
Configuration conf = getConf();
// Don't try more than once
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);
try (Connection connection = ConnectionFactory.createConnection(conf)) {
try (Admin admin = connection.getAdmin()) {
admin.shutdown();
} catch (Throwable t) {
LOG.error("Failed to stop master", t);
return 1;
}
} catch (MasterNotRunningException e) {
LOG.error("Master not running");
return 1;
} catch (ZooKeeperConnectionException e) {
LOG.error("ZooKeeper not available");
return 1;
} catch (IOException e) {
LOG.error("Got IOException: " + e.getMessage(), e);
return 1;
}
return 0;
}
use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.
the class TestMasterNoCluster method tearDown.
@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;
}
});
// Before fails sometimes so retry.
try {
TESTUTIL.waitFor(10000, (Waiter.Predicate<Exception>) () -> {
try {
ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode);
return true;
} catch (KeeperException.NotEmptyException e) {
LOG.info("Failed delete, retrying", e);
}
return false;
});
} catch (Exception e) {
LOG.info("Failed zk clear", e);
}
zkw.close();
}
Aggregations