本文整理汇总了Java中org.apache.hadoop.hbase.security.token.TokenUtil类的典型用法代码示例。如果您正苦于以下问题:Java TokenUtil类的具体用法?Java TokenUtil怎么用?Java TokenUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenUtil类属于org.apache.hadoop.hbase.security.token包,在下文中一共展示了TokenUtil类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initCredentials
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
public static void initCredentials(JobConf job) throws IOException {
UserProvider userProvider = UserProvider.instantiate(job);
if (userProvider.isHadoopSecurityEnabled()) {
// propagate delegation related props from launcher job to MR job
if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
job.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
}
}
if (userProvider.isHBaseSecurityEnabled()) {
Connection conn = ConnectionFactory.createConnection(job);
try {
// login the server principal (if using secure Hadoop)
User user = userProvider.getCurrent();
TokenUtil.addTokenForJob(conn, job, user);
} catch (InterruptedException ie) {
ie.printStackTrace();
Thread.currentThread().interrupt();
} finally {
conn.close();
}
}
}
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:TableMapReduceUtil.java
示例2: initCredentialsForCluster
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
/**
* Obtain an authentication token, for the specified cluster, on behalf of the current user
* and add it to the credentials for the given map reduce job.
*
* @param job The job that requires the permission.
* @param conf The configuration to use in connecting to the peer cluster
* @throws IOException When the authentication token cannot be obtained.
*/
public static void initCredentialsForCluster(Job job, Configuration conf)
throws IOException {
UserProvider userProvider = UserProvider.instantiate(job.getConfiguration());
if (userProvider.isHBaseSecurityEnabled()) {
try {
Connection peerConn = ConnectionFactory.createConnection(conf);
try {
TokenUtil.addTokenForJob(peerConn, userProvider.getCurrent(), job);
} finally {
peerConn.close();
}
} catch (InterruptedException e) {
LOG.info("Interrupted obtaining user authentication token");
Thread.interrupted();
}
}
}
开发者ID:fengchen8086,项目名称:ditb,代码行数:26,代码来源:TableMapReduceUtil.java
示例3: initCredentialsForCluster
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
/**
* Obtain an authentication token, for the specified cluster, on behalf of the current user
* and add it to the credentials for the given map reduce job.
*
* The quorumAddress is the key to the ZK ensemble, which contains:
* hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent
*
* @param job The job that requires the permission.
* @param quorumAddress string that contains the 3 required configuratins
* @throws IOException When the authentication token cannot be obtained.
*/
public static void initCredentialsForCluster(Job job, String quorumAddress)
throws IOException {
UserProvider userProvider = UserProvider.instantiate(job.getConfiguration());
if (userProvider.isHBaseSecurityEnabled()) {
try {
Configuration peerConf = HBaseConfiguration.create(job.getConfiguration());
ZKUtil.applyClusterKeyToConf(peerConf, quorumAddress);
Connection peerConn = ConnectionFactory.createConnection(peerConf);
try {
TokenUtil.addTokenForJob(peerConn, userProvider.getCurrent(), job);
} finally {
peerConn.close();
}
} catch (InterruptedException e) {
LOG.info("Interrupted obtaining user authentication token");
Thread.interrupted();
}
}
}
开发者ID:grokcoder,项目名称:pbase,代码行数:31,代码来源:TableMapReduceUtil.java
示例4: main
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
// vv TokenExample
Token<AuthenticationTokenIdentifier> token =
TokenUtil.obtainToken(connection);
String urlString = token.encodeToUrlString();
File temp = new File(FileUtils.getTempDirectory(), "token");
FileUtils.writeStringToFile(temp, urlString);
System.out.println("Encoded Token: " + urlString);
String strToken = FileUtils.readFileToString(new File("token"));
Token token2 = new Token();
token2.decodeFromUrlString(strToken);
UserGroupInformation.getCurrentUser().addToken(token2);
// ^^ TokenExample
connection.close();
}
开发者ID:lhfei,项目名称:hbase-in-action,代码行数:21,代码来源:TokenExample.java
示例5: initCredentials
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
public static void initCredentials(Job job) throws IOException {
UserProvider userProvider = UserProvider.instantiate(job.getConfiguration());
if (userProvider.isHadoopSecurityEnabled()) {
// propagate delegation related props from launcher job to MR job
if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
job.getConfiguration().set("mapreduce.job.credentials.binary",
System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
}
}
if (userProvider.isHBaseSecurityEnabled()) {
try {
// init credentials for remote cluster
String quorumAddress = job.getConfiguration().get(TableOutputFormat.QUORUM_ADDRESS);
User user = userProvider.getCurrent();
if (quorumAddress != null) {
Configuration peerConf = HBaseConfiguration.createClusterConf(job.getConfiguration(),
quorumAddress, TableOutputFormat.OUTPUT_CONF_PREFIX);
Connection peerConn = ConnectionFactory.createConnection(peerConf);
try {
TokenUtil.addTokenForJob(peerConn, user, job);
} finally {
peerConn.close();
}
}
Connection conn = ConnectionFactory.createConnection(job.getConfiguration());
try {
TokenUtil.addTokenForJob(conn, user, job);
} finally {
conn.close();
}
} catch (InterruptedException ie) {
LOG.info("Interrupted obtaining user authentication token");
Thread.currentThread().interrupt();
}
}
}
开发者ID:fengchen8086,项目名称:ditb,代码行数:39,代码来源:TableMapReduceUtil.java
示例6: initCredentials
import org.apache.hadoop.hbase.security.token.TokenUtil; //导入依赖的package包/类
public static void initCredentials(Job job) throws IOException {
UserProvider userProvider = UserProvider.instantiate(job.getConfiguration());
if (userProvider.isHadoopSecurityEnabled()) {
// propagate delegation related props from launcher job to MR job
if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
job.getConfiguration().set("mapreduce.job.credentials.binary",
System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
}
}
if (userProvider.isHBaseSecurityEnabled()) {
try {
// init credentials for remote cluster
String quorumAddress = job.getConfiguration().get(TableOutputFormat.QUORUM_ADDRESS);
User user = userProvider.getCurrent();
if (quorumAddress != null) {
Configuration peerConf = HBaseConfiguration.create(job.getConfiguration());
ZKUtil.applyClusterKeyToConf(peerConf, quorumAddress);
Connection peerConn = ConnectionFactory.createConnection(peerConf);
try {
TokenUtil.addTokenForJob(peerConn, user, job);
} finally {
peerConn.close();
}
}
Connection conn = ConnectionFactory.createConnection(job.getConfiguration());
try {
TokenUtil.addTokenForJob(conn, user, job);
} finally {
conn.close();
}
} catch (InterruptedException ie) {
LOG.info("Interrupted obtaining user authentication token");
Thread.currentThread().interrupt();
}
}
}
开发者ID:grokcoder,项目名称:pbase,代码行数:39,代码来源:TableMapReduceUtil.java
示例7: 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);
}
}
开发者ID:apache,项目名称:kylin,代码行数:42,代码来源:PingHBaseCLI.java
示例8: 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();
}
}
}
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:48,代码来源:PingHBaseCLI.java
注:本文中的org.apache.hadoop.hbase.security.token.TokenUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论