Example usage for org.apache.hadoop.mapreduce.security TokenCache loadTokens

List of usage examples for org.apache.hadoop.mapreduce.security TokenCache loadTokens

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.security TokenCache loadTokens.

Prototype

@InterfaceAudience.Private
@Deprecated
public static Credentials loadTokens(String jobTokenFile, Configuration conf) throws IOException 

Source Link

Document

load job token from a file

Usage

From source file:org.apache.giraph.comm.netty.handler.SaslServerHandler.java

License:Apache License

/**
 * Load Hadoop Job Token into secret manager.
 *
 * @param conf Configuration//from  w w w  .  j  av a2 s  .  c  o  m
 * @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);
    }
}

From source file:org.apache.giraph.comm.netty.SaslNettyClient.java

License:Apache License

/**
 * Obtain JobToken, which we'll use as a credential for SASL authentication
 * when connecting to other Giraph BSPWorkers.
 *
 * @param conf Configuration/*from ww  w.ja  v a  2 s  . c o  m*/
 * @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");
    }
}

From source file:org.apache.giraph.comm.RPCCommunications.java

License:Apache License

/**
  * Create the job token.//from  w  w  w  . jav a 2 s.com
  *
  * @return Job token.
  */
protected

        Token<JobTokenIdentifier> createJobToken() 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);
    }

    return null;
}