I`m looking for an example to connect to secure hbase using java.
Any Pointers will be helpful.
I tried to do it as follows but I`m unsuccessfull.
System.setProperty(CommonConstants.KRB_REALM, krbRealmValue);
System.setProperty(CommonConstants.KRB_KDC, krbKdcValue);
System.setProperty(CommonConstants.KRB_DEBUG, krbDebug);
hbaseConf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
AUTH_KRB);
hbaseConf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION,
AUTHORIZATION);
hbaseConf.set(CommonConfigurationKeysPublic.FS_AUTOMATIC_CLOSE_KEY, AUTO_CLOSE);
hbaseConf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
defaultFS);
//hbaseConf.set("dfs.namenode.kerberos.principal", nnPrincipal);
hbaseConf.set("hbase.zookeeper.quorum",
ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.host"));
hbaseConf.set("hbase.zookeeper.property.clientPort",
ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.port"));
Configuration conf = HBaseConfiguration.create(hbaseConf);
conf.set("hbase.connection.timeout", "1200");
//conf.set("zookeeper.znode.parent", "/hbase-secure");
conf.set("hbase.master", "gauravt-namenode.pbi.global.pvt:60000");
conf.set("hbase.client.retries.number", Integer.toString(0));
conf.set("zookeeper.session.timeout", Integer.toString(0));
conf.set("hbase.rpc.engine",
"org.apache.hadoop.hbase.ipc.SecureRpcEngine");
conf.set("zookeeper.recovery.retry", Integer.toString(0));
conf.set("hbase.security.authentication", AUTH_KRB);
conf.set("hbase.security.authorization", AUTHORIZATION);
conf.set("hbase.master.kerberos.principal", "hbaseprincipal");
conf.set("hbase.regionserver.kerberos.principal",
"hbaseprincipal");
hbaseConf = conf;
UserGroupInformation.setConfiguration(hbaseConf);
userGroupInformation =
UserGroupInformation.loginUserFromKeytabAndReturnUGI(domainUser,
keytabFilePath);
UserGroupInformation.setLoginUser(userGroupInformation);
HBaseAdmin admins = new HBaseAdmin(hbaseConf)
if(admins.isTableAvailable("ambarismoketest")) {
System.out.println("Table is available");
};
HConnection connection =
HConnectionManager.createConnection(client.getConfig());
HTableInterface table =
connection.getTable("ambarismoketest");
byte [] family = Bytes.toBytes("fammily");
byte [] col01 = Bytes.toBytes("col01");
Scan scan = new Scan();
scan.addColumn(family, col01);
ResultScanner rs = table.getScanner(scan);
for (Result r = rs.next(); r != null; r = rs.next()) {
byte[] valueObj = r.getValue(family, col01);
String value = new String(valueObj);
System.out.println(value);
}
System.out.println(table.get(new Get(null)));
This fail at the time of trying to create a connection.
Thanks
gaurav
________________________________