Search in sources :

Example 1 with GetDelegationTokenRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest in project hadoop by apache.

the class TestYARNRunner method testHistoryServerToken.

@Test(timeout = 20000)
public void testHistoryServerToken() throws Exception {
    //Set the master principal in the config
    conf.set(YarnConfiguration.RM_PRINCIPAL, "foo@LOCAL");
    final String masterPrincipal = Master.getMasterPrincipal(conf);
    final MRClientProtocol hsProxy = mock(MRClientProtocol.class);
    when(hsProxy.getDelegationToken(any(GetDelegationTokenRequest.class))).thenAnswer(new Answer<GetDelegationTokenResponse>() {

        public GetDelegationTokenResponse answer(InvocationOnMock invocation) {
            GetDelegationTokenRequest request = (GetDelegationTokenRequest) invocation.getArguments()[0];
            // check that the renewer matches the cluster's RM principal
            assertEquals(masterPrincipal, request.getRenewer());
            org.apache.hadoop.yarn.api.records.Token token = recordFactory.newRecordInstance(org.apache.hadoop.yarn.api.records.Token.class);
            // none of these fields matter for the sake of the test
            token.setKind("");
            token.setService("");
            token.setIdentifier(ByteBuffer.allocate(0));
            token.setPassword(ByteBuffer.allocate(0));
            GetDelegationTokenResponse tokenResponse = recordFactory.newRecordInstance(GetDelegationTokenResponse.class);
            tokenResponse.setDelegationToken(token);
            return tokenResponse;
        }
    });
    UserGroupInformation.createRemoteUser("someone").doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws Exception {
            yarnRunner = new YARNRunner(conf, null, null);
            yarnRunner.getDelegationTokenFromHS(hsProxy);
            verify(hsProxy).getDelegationToken(any(GetDelegationTokenRequest.class));
            return null;
        }
    });
}
Also used : GetDelegationTokenResponse(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenResponse) Token(org.apache.hadoop.security.token.Token) IOException(java.io.IOException) MRClientProtocol(org.apache.hadoop.mapreduce.v2.api.MRClientProtocol) GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 2 with GetDelegationTokenRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest in project incubator-gobblin by apache.

the class TokenUtils method getDelegationTokenFromHS.

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());
}
Also used : GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest)

Example 3 with GetDelegationTokenRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest in project oozie by apache.

the class JHSCredentials method getDelegationTokenFromJHS.

/**
 * Get a Delegation token from the JHS.
 * 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());
}
Also used : GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest)

Example 4 with GetDelegationTokenRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest in project hadoop by apache.

the class YARNRunner method getDelegationTokenFromHS.

@VisibleForTesting
Token<?> getDelegationTokenFromHS(MRClientProtocol 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());
}
Also used : GetDelegationTokenRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with GetDelegationTokenRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest 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

GetDelegationTokenRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenRequest)5 IOException (java.io.IOException)2 MRClientProtocol (org.apache.hadoop.mapreduce.v2.api.MRClientProtocol)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HostAndPort (com.google.common.net.HostAndPort)1 InetSocketAddress (java.net.InetSocketAddress)1 Text (org.apache.hadoop.io.Text)1 ResourceMgrDelegate (org.apache.hadoop.mapred.ResourceMgrDelegate)1 GetDelegationTokenResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDelegationTokenResponse)1 GetDelegationTokenRequestPBImpl (org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetDelegationTokenRequestPBImpl)1 Token (org.apache.hadoop.security.token.Token)1 TokenIdentifier (org.apache.hadoop.security.token.TokenIdentifier)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1