本文整理汇总了Java中org.apache.hadoop.mapreduce.security.TokenCache.loadTokens方法的典型用法代码示例。如果您正苦于以下问题:Java TokenCache.loadTokens方法的具体用法?Java TokenCache.loadTokens怎么用?Java TokenCache.loadTokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.mapreduce.security.TokenCache
的用法示例。
在下文中一共展示了TokenCache.loadTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJobToken
import org.apache.hadoop.mapreduce.security.TokenCache; //导入方法依赖的package包/类
/**
* Obtain JobToken, which we'll use as a credential for SASL authentication
* when connecting to other Giraph BSPWorkers.
*
* @param conf Configuration
* @return a JobToken containing username and password so that client can
* authenticate with a server.
*/
private Token<JobTokenIdentifier> createJobToken(Configuration conf)
throws IOException {
String localJobTokenFile = System.getenv().get(
UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
if (localJobTokenFile != null) {
JobConf jobConf = new JobConf(conf);
Credentials credentials =
TokenCache.loadTokens(localJobTokenFile, jobConf);
return TokenCache.getJobToken(credentials);
} else {
throw new IOException("createJobToken: Cannot obtain authentication " +
"credentials for job: file: '" +
UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION + "' not found");
}
}
示例2: setupSecretManager
import org.apache.hadoop.mapreduce.security.TokenCache; //导入方法依赖的package包/类
/**
* Load Hadoop Job Token into secret manager.
*
* @param conf Configuration
* @throws IOException
*/
private void setupSecretManager(Configuration conf) throws IOException {
secretManager = new JobTokenSecretManager();
String localJobTokenFile = System.getenv().get(
UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
if (localJobTokenFile == null) {
throw new IOException("Could not find job credentials: environment " +
"variable: " + UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION +
" was not defined.");
}
JobConf jobConf = new JobConf(conf);
// Find the JobTokenIdentifiers among all the tokens available in the
// jobTokenFile and store them in the secretManager.
Credentials credentials =
TokenCache.loadTokens(localJobTokenFile, jobConf);
Collection<Token<? extends TokenIdentifier>> collection =
credentials.getAllTokens();
for (Token<? extends TokenIdentifier> token: collection) {
TokenIdentifier tokenIdentifier = decodeIdentifier(token,
JobTokenIdentifier.class);
if (tokenIdentifier instanceof JobTokenIdentifier) {
Token<JobTokenIdentifier> theToken =
(Token<JobTokenIdentifier>) token;
JobTokenIdentifier jobTokenIdentifier =
(JobTokenIdentifier) tokenIdentifier;
secretManager.addTokenForJob(
jobTokenIdentifier.getJobId().toString(), theToken);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("loaded JobToken credentials: " + credentials + " from " +
"localJobTokenFile: " + localJobTokenFile);
}
}
示例3: localizeJobFiles
import org.apache.hadoop.mapreduce.security.TokenCache; //导入方法依赖的package包/类
/**
* Localize the job on this tasktracker. Specifically
* <ul>
* <li>Cleanup and create job directories on all disks</li>
* <li>Download the job config file job.xml from the FS</li>
* <li>Create the job work directory and set {@link TaskTracker#JOB_LOCAL_DIR}
* in the configuration.
* <li>Download the job jar file job.jar from the FS, unjar it and set jar
* file in the configuration.</li>
* </ul>
*
* @param t task whose job has to be localized on this TT
* @return the modified job configuration to be used for all the tasks of this
* job as a starting point.
* @throws IOException
*/
JobConf localizeJobFiles(Task t, RunningJob rjob)
throws IOException, InterruptedException {
JobID jobId = t.getJobID();
String userName = t.getUser();
// Initialize the job directories
FileSystem localFs = FileSystem.getLocal(fConf);
getLocalizer().initializeJobDirs(userName, jobId);
// save local copy of JobToken file
String localJobTokenFile = localizeJobTokenFile(t.getUser(), jobId);
rjob.ugi = UserGroupInformation.createRemoteUser(t.getUser());
Credentials ts = TokenCache.loadTokens(localJobTokenFile, fConf);
Token<JobTokenIdentifier> jt = TokenCache.getJobToken(ts);
if (jt != null) { //could be null in the case of some unit tests
getJobTokenSecretManager().addTokenForJob(jobId.toString(), jt);
}
for (Token<? extends TokenIdentifier> token : ts.getAllTokens()) {
rjob.ugi.addToken(token);
}
// Download the job.xml for this job from the system FS
Path localJobFile =
localizeJobConfFile(new Path(t.getJobFile()), userName, jobId);
JobConf localJobConf = new JobConf(localJobFile);
//WE WILL TRUST THE USERNAME THAT WE GOT FROM THE JOBTRACKER
//AS PART OF THE TASK OBJECT
localJobConf.setUser(userName);
// set the location of the token file into jobConf to transfer
// the name to TaskRunner
localJobConf.set(TokenCache.JOB_TOKENS_FILENAME,
localJobTokenFile);
// create the 'job-work' directory: job-specific shared directory for use as
// scratch space by all tasks of the same job running on this TaskTracker.
Path workDir =
lDirAlloc.getLocalPathForWrite(getJobWorkDir(userName, jobId
.toString()), fConf);
if (!localFs.mkdirs(workDir)) {
throw new IOException("Mkdirs failed to create "
+ workDir.toString());
}
System.setProperty(JOB_LOCAL_DIR, workDir.toUri().getPath());
localJobConf.set(JOB_LOCAL_DIR, workDir.toUri().getPath());
// Download the job.jar for this job from the system FS
localizeJobJarFile(userName, jobId, localFs, localJobConf);
return localJobConf;
}