本文整理汇总了Java中org.apache.hadoop.hbase.security.token.TokenUtil.obtainAndCacheToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenUtil.obtainAndCacheToken方法的具体用法?Java TokenUtil.obtainAndCacheToken怎么用?Java TokenUtil.obtainAndCacheToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.security.token.TokenUtil
的用法示例。
在下文中一共展示了TokenUtil.obtainAndCacheToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String hbaseTable = args[0];
System.out.println("Hello friend.");
Configuration hconf = HBaseConnection.getCurrentHBaseConfiguration();
if (User.isHBaseSecurityEnabled(hconf)) {
try {
System.out.println("--------------Getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName());
TokenUtil.obtainAndCacheToken(hconf, UserGroupInformation.getCurrentUser());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("--------------Error while getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName());
}
}
Scan scan = new Scan();
int limit = 20;
Connection conn = null;
Table table = null;
ResultScanner scanner = null;
try {
conn = ConnectionFactory.createConnection(hconf);
table = conn.getTable(TableName.valueOf(hbaseTable));
scanner = table.getScanner(scan);
int count = 0;
for (Result r : scanner) {
byte[] rowkey = r.getRow();
System.out.println(Bytes.toStringBinary(rowkey));
count++;
if (count == limit)
break;
}
} finally {
IOUtils.closeQuietly(scanner);
IOUtils.closeQuietly(table);
IOUtils.closeQuietly(conn);
}
}
示例2: main
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String metadataUrl = args[0];
String hbaseTable = args[1];
System.out.println("Hello friend.");
Configuration hconf = HadoopUtil.newHBaseConfiguration(metadataUrl);
if (User.isHBaseSecurityEnabled(hconf)) {
try {
System.out.println("--------------Getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName());
TokenUtil.obtainAndCacheToken(hconf, UserGroupInformation.getCurrentUser());
} catch (InterruptedException e) {
System.out.println("--------------Error while getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName());
}
}
Scan scan = new Scan();
int limit = 20;
HConnection conn = null;
HTableInterface table = null;
ResultScanner scanner = null;
try {
conn = HConnectionManager.createConnection(hconf);
table = conn.getTable(hbaseTable);
scanner = table.getScanner(scan);
int count = 0;
for (Result r : scanner) {
byte[] rowkey = r.getRow();
System.out.println(Bytes.toStringBinary(rowkey));
count++;
if (count == limit)
break;
}
} finally {
if (scanner != null) {
scanner.close();
}
if (table != null) {
table.close();
}
if (conn != null) {
conn.close();
}
}
}