@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto proto) throws ServiceException { GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(proto); try { GetDelegationTokenResponse response = real.getDelegationToken(request); return ((GetDelegationTokenResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto proto) throws ServiceException { GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(proto); try { GetDelegationTokenResponse response = real.getDelegationToken(request); return ((GetDelegationTokenResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto proto) throws ServiceException { GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(proto); try { GetDelegationTokenResponse response = real.getDelegationToken(request); return ((GetDelegationTokenResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetDelegationTokenResponseProto getDelegationToken( RpcController controller, GetDelegationTokenRequestProto proto) throws ServiceException { GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(proto); try { GetDelegationTokenResponse response = real.getDelegationToken(request); return ((GetDelegationTokenResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@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()); }
@Override public Void run() throws Exception { yarnRunner = new YARNRunner(conf, null, null); yarnRunner.getDelegationTokenFromHS(hsProxy); verify(hsProxy). getDelegationToken(any(GetDelegationTokenRequest.class)); return null; } });
@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()); }
@Override public Token run() throws IOException { GetDelegationTokenRequest request = Records .newRecord(GetDelegationTokenRequest.class); request.setRenewer(renewerString); return hsService.getDelegationToken(request).getDelegationToken(); }
/** * 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); } }
/** * 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); } }
when(hsProxy.getDelegationToken(any(GetDelegationTokenRequest.class))).thenAnswer( new Answer<GetDelegationTokenResponse>() { public GetDelegationTokenResponse answer(InvocationOnMock invocation) {
doReturn(getDtResponse).when(mockHsProxy).getDelegationToken( any(GetDelegationTokenRequest.class)); verify(mockHsProxy, times(0)).getDelegationToken( any(GetDelegationTokenRequest.class)); verify(mockHsProxy, times(0)).getDelegationToken( any(GetDelegationTokenRequest.class)); verify(mockHsProxy, times(0)).getDelegationToken( any(GetDelegationTokenRequest.class)); verify(mockHsProxy, times(1)).getDelegationToken( any(GetDelegationTokenRequest.class)); verify(mockHsProxy, times(1)).getDelegationToken( any(GetDelegationTokenRequest.class)); } finally {
/** * 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()); }
/** * 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()); }