Search in sources :

Example 6 with JobHistoryServer

use of org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer in project cdap by caskdata.

the class JobHistoryServerTokenUtils method obtainToken.

/**
   * Gets a JHS delegation token and stores it in the given Credentials.
   *
   * @return the same Credentials instance as the one given in parameter.
   */
public static Credentials obtainToken(Configuration configuration, Credentials credentials) {
    if (!UserGroupInformation.isSecurityEnabled()) {
        return credentials;
    }
    String historyServerAddress = configuration.get("mapreduce.jobhistory.address");
    HostAndPort hostAndPort = HostAndPort.fromString(historyServerAddress);
    try {
        ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(new YarnConfiguration(configuration));
        MRClientCache clientCache = new MRClientCache(configuration, resourceMgrDelegate);
        MRClientProtocol hsProxy = clientCache.getInitializedHSProxy();
        GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl();
        request.setRenewer(YarnUtils.getYarnTokenRenewer(configuration));
        InetSocketAddress address = new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
        Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(hsProxy.getDelegationToken(request).getDelegationToken(), address);
        credentials.addToken(new Text(token.getService()), token);
        LOG.debug("Adding JobHistoryServer delegation token {}.", token);
        return credentials;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) InetSocketAddress(java.net.InetSocketAddress) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) MRClientProtocol(org.apache.hadoop.mapreduce.v2.api.MRClientProtocol) HostAndPort(com.google.common.net.HostAndPort) GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest) ResourceMgrDelegate(org.apache.hadoop.mapred.ResourceMgrDelegate) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) GetDelegationTokenRequestPBImpl(org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetDelegationTokenRequestPBImpl)

Aggregations

IOException (java.io.IOException)5 Configuration (org.apache.hadoop.conf.Configuration)3 MRClientProtocol (org.apache.hadoop.mapreduce.v2.api.MRClientProtocol)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 Test (org.junit.Test)3 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)2 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)2 HostAndPort (com.google.common.net.HostAndPort)1 InetSocketAddress (java.net.InetSocketAddress)1 Path (org.apache.hadoop.fs.Path)1 FsPermission (org.apache.hadoop.fs.permission.FsPermission)1 Text (org.apache.hadoop.io.Text)1 JobConf (org.apache.hadoop.mapred.JobConf)1 ResourceMgrDelegate (org.apache.hadoop.mapred.ResourceMgrDelegate)1 GetDelegationTokenRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest)1 GetDiagnosticsRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsRequest)1 GetDiagnosticsResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsResponse)1 GetJobReportRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetJobReportRequest)1 GetTaskAttemptCompletionEventsRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsRequest)1 GetTaskAttemptCompletionEventsResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsResponse)1