Example usage for org.apache.hadoop.mapreduce.v2.api.protocolrecords GetDelegationTokenRequest setRenewer

List of usage examples for org.apache.hadoop.mapreduce.v2.api.protocolrecords GetDelegationTokenRequest setRenewer

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.v2.api.protocolrecords GetDelegationTokenRequest setRenewer.

Prototype

void setRenewer(String renewer);

Source Link

Usage

From source file:azkaban.security.HadoopSecurityManager_H_2_0.java

License:Apache License

private Token<?> getDelegationTokenFromHS(HSClientProtocol hsProxy) throws IOException, InterruptedException {
    GetDelegationTokenRequest request = recordFactory.newRecordInstance(GetDelegationTokenRequest.class);
    request.setRenewer(Master.getMasterPrincipal(conf));
    org.apache.hadoop.yarn.api.records.Token mrDelegationToken;
    mrDelegationToken = hsProxy.getDelegationToken(request).getDelegationToken();
    return ConverterUtils.convertFromYarn(mrDelegationToken, hsProxy.getConnectAddress());
}

From source file:co.cask.cdap.explore.security.JobHistoryServerTokenUtils.java

License:Apache License

/**
 * Gets a JHS delegation token and stores it in the given Credentials.
 *
 * @return the same Credentials instance as the one given in parameter.
 *///from   w ww . java2 s . co m
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 {
        LOG.info("Obtaining delegation token for JHS");

        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);
        return credentials;
    } catch (Exception e) {
        LOG.error("Failed to get secure token for JHS at {}.", hostAndPort, e);
        throw Throwables.propagate(e);
    }
}

From source file:gobblin.hadoop.token.TokenUtils.java

License:Open Source License

private static Token<?> getDelegationTokenFromHS(HSClientProtocol hsProxy, Configuration conf)
        throws IOException, InterruptedException {
    GetDelegationTokenRequest request = RecordFactoryProvider.getRecordFactory(null)
            .newRecordInstance(GetDelegationTokenRequest.class);
    request.setRenewer(Master.getMasterPrincipal(conf));
    org.apache.hadoop.yarn.api.records.Token mrDelegationToken;
    mrDelegationToken = hsProxy.getDelegationToken(request).getDelegationToken();
    return ConverterUtils.convertFromYarn(mrDelegationToken, hsProxy.getConnectAddress());
}

From source file:gobblin.util.hadoop.TokenUtils.java

License:Apache License

private static Token<?> getDelegationTokenFromHS(HSClientProtocol hsProxy, Configuration conf)
        throws IOException {
    GetDelegationTokenRequest request = RecordFactoryProvider.getRecordFactory(null)
            .newRecordInstance(GetDelegationTokenRequest.class);
    request.setRenewer(Master.getMasterPrincipal(conf));
    org.apache.hadoop.yarn.api.records.Token mrDelegationToken;
    mrDelegationToken = hsProxy.getDelegationToken(request).getDelegationToken();
    return ConverterUtils.convertFromYarn(mrDelegationToken, hsProxy.getConnectAddress());
}

From source file:org.apache.oozie.action.hadoop.JHSCredentials.java

License:Apache License

/**
 * Get a Delegation token from the JHS./*from   ww w  . j av  a  2s  .c om*/
 * Copied over from YARNRunner in Hadoop.
 * @param hsProxy protcol used to get the token
 * @return The RM_DELEGATION_TOKEN that can be used to talk to JHS
 * @throws IOException
 * @throws InterruptedException
 */
private Token<?> getDelegationTokenFromJHS(final MRClientProtocol hsProxy, final String renewer)
        throws IOException, InterruptedException {
    GetDelegationTokenRequest request = RecordFactoryProvider.getRecordFactory(null)
            .newRecordInstance(GetDelegationTokenRequest.class);
    LOG.debug("Creating requsest to JHS using renewer [{0}]", renewer);
    request.setRenewer(renewer);
    org.apache.hadoop.yarn.api.records.Token mrDelegationToken = hsProxy.getDelegationToken(request)
            .getDelegationToken();
    LOG.debug("Got token to JHS : {0}. Converting token.", mrDelegationToken);
    return ConverterUtils.convertFromYarn(mrDelegationToken, hsProxy.getConnectAddress());
}