// This code is compatible with HBase 2.1+ // hbase-client, and hbase-common are required dependencies for this code // imports... import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Admin; // hbase-common import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; // Create an HBase configuration object, this object subclasses Properties Configuration hconf = HBaseConfiguration.create(); hconf.addResource("hbase-site.xml"); hconf.addResource("core-site.xml"); hconf.set("hbase.client.retries.number", Integer.toString(HBASE_CLIENT_RETRIES)); hconf.set("zookeeper.session.timeout", Integer.toString(HBASE_ZK_TIMEOUT)); hconf.set("zookeeper.recovery.retry", Integer.toString(HBASE_ZK_RETRIES)); // Create our connection, an exception will be thrown here if HBase cannot connect Connection connection = ConnectionFactory.createConnection(hconf); // To verify the master is truly reachable, we'll use the `HBaseAdmin` class via `getAdmin()` // to contact the hbase master. Admin admin = connection.getAdmin(); ClusterMetrics metrics = admin.getClusterMetrics(); ServerName master = metrics.getMasterName(); // print the hostname of the current HBase Master System.out.println(String.format("HBase Master: %s", master.getHostname()));