I want to write a UDF to get something from HBase,I use this to set token to hiveconf,but I cannot connect to HBase with hiveconf,it will throw NullPointException
I tried many ways,like that : https://www.programcreek.com/java-api-examples/index.php?api=org.apache.hadoop.hbase.security.token.TokenUtil
but it still throw NullPointException
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier;
import org.apache.hadoop.hbase.security.token.TokenUtil;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.hooks.ExecuteWithHookContext;
import org.apache.hadoop.hive.ql.hooks.HookContext;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
public class HbaseTokenFetcherHook implements ExecuteWithHookContext{
private static final Log LOG = LogFactory.getLog(HbaseTokenFetcherHook.class);
@Override
public void run(HookContext hookContext) throws Exception {
HiveConf hiveConf = hookContext.getConf();
/* If required */
hiveConf.set(“zookeeper.znode.parent”, "/hbase-secure");
try {
UserGroupInformation.setConfiguration(hiveConf);
Connection tokenConnection = ConnectionFactory.createConnection(hiveConf);
Token<AuthenticationTokenIdentifier> token = TokenUtil.obtainToken(tokenConnection, User.getCurrent());
String urlString = token.encodeToUrlString();
hiveConf.set(“HBASE_AUTH_TOKEN”, urlString);
} catch (IOException | InterruptedException e) {
LOG.error("Error while fetching token for hbase"
+ e.getMessage(), e);
}
}
}
it throw exception in:
Token<AuthenticationTokenIdentifier> token = TokenUtil.obtainToken(tokenConnection, User.getCurrent());
Error message : Caused by: java.lang.NullPointException at org.apache.hadoop.hbase.zookeeper.ZookeeperWatcher.getMetaReplicaNodes(ZookeeperWatcher.java:497) at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:558)