当前位置: 首页>>代码示例>>Java>>正文


Java RMDelegationTokenIdentifier.getKind方法代码示例

本文整理汇总了Java中org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java RMDelegationTokenIdentifier.getKind方法的具体用法?Java RMDelegationTokenIdentifier.getKind怎么用?Java RMDelegationTokenIdentifier.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier的用法示例。


在下文中一共展示了RMDelegationTokenIdentifier.getKind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddNewTokenSentFromRMForLogAggregation

import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testAddNewTokenSentFromRMForLogAggregation() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
    "kerberos");
  UserGroupInformation.setConfiguration(conf);

  ApplicationId application1 = BuilderUtils.newApplicationId(1234, 1);
  Application mockApp = mock(Application.class);
  when(mockApp.getContainers()).thenReturn(
    new HashMap<ContainerId, Container>());
  this.context.getApplications().put(application1, mockApp);
  @SuppressWarnings("resource")
  LogAggregationService logAggregationService =
      new LogAggregationService(dispatcher, this.context, this.delSrvc,
        super.dirsHandler);
  logAggregationService.init(this.conf);
  logAggregationService.start();
  logAggregationService.handle(new LogHandlerAppStartedEvent(application1,
    this.user, null, ContainerLogsRetentionPolicy.ALL_CONTAINERS, this.acls,
    Records.newRecord(LogAggregationContext.class)));

  // Inject new token for log-aggregation after app log-aggregator init
  Text userText1 = new Text("user1");
  RMDelegationTokenIdentifier dtId1 =
      new RMDelegationTokenIdentifier(userText1, new Text("renewer1"),
        userText1);
  final Token<RMDelegationTokenIdentifier> token1 =
      new Token<RMDelegationTokenIdentifier>(dtId1.getBytes(),
        "password1".getBytes(), dtId1.getKind(), new Text("service1"));
  Credentials credentials = new Credentials();
  credentials.addToken(userText1, token1);
  this.context.getSystemCredentialsForApps().put(application1, credentials);

  logAggregationService.handle(new LogHandlerAppFinishedEvent(application1));

  final UserGroupInformation ugi =
      ((AppLogAggregatorImpl) logAggregationService.getAppLogAggregators()
        .get(application1)).getUgi();

  GenericTestUtils.waitFor(new Supplier<Boolean>() {
    public Boolean get() {
      boolean hasNewToken = false;
      for (Token<?> token : ugi.getCredentials().getAllTokens()) {
        if (token.equals(token1)) {
          hasNewToken = true;
        }
      }
      return hasNewToken;
    }
  }, 1000, 20000);
  logAggregationService.stop();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:54,代码来源:TestLogAggregationService.java

示例2: testAddNewTokenSentFromRMForLogAggregation

import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testAddNewTokenSentFromRMForLogAggregation() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
    "kerberos");
  UserGroupInformation.setConfiguration(conf);

  ApplicationId application1 = BuilderUtils.newApplicationId(1234, 1);
  Application mockApp = mock(Application.class);
  when(mockApp.getContainers()).thenReturn(
    new HashMap<ContainerId, Container>());
  this.context.getApplications().put(application1, mockApp);
  @SuppressWarnings("resource")
  LogAggregationService logAggregationService =
      new LogAggregationService(dispatcher, this.context, this.delSrvc,
        super.dirsHandler);
  logAggregationService.init(this.conf);
  logAggregationService.start();
  logAggregationService.handle(new LogHandlerAppStartedEvent(application1,
    this.user, null, this.acls,
    Records.newRecord(LogAggregationContext.class)));

  // Inject new token for log-aggregation after app log-aggregator init
  Text userText1 = new Text("user1");
  RMDelegationTokenIdentifier dtId1 =
      new RMDelegationTokenIdentifier(userText1, new Text("renewer1"),
        userText1);
  final Token<RMDelegationTokenIdentifier> token1 =
      new Token<RMDelegationTokenIdentifier>(dtId1.getBytes(),
        "password1".getBytes(), dtId1.getKind(), new Text("service1"));
  Credentials credentials = new Credentials();
  credentials.addToken(userText1, token1);
  this.context.getSystemCredentialsForApps().put(application1, credentials);

  logAggregationService.handle(new LogHandlerAppFinishedEvent(application1));

  final UserGroupInformation ugi =
      ((AppLogAggregatorImpl) logAggregationService.getAppLogAggregators()
        .get(application1)).getUgi();

  GenericTestUtils.waitFor(new Supplier<Boolean>() {
    public Boolean get() {
      boolean hasNewToken = false;
      for (Token<?> token : ugi.getCredentials().getAllTokens()) {
        if (token.equals(token1)) {
          hasNewToken = true;
        }
      }
      return hasNewToken;
    }
  }, 1000, 20000);
  logAggregationService.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:54,代码来源:TestLogAggregationService.java

示例3: testGetHSDelegationToken

import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; //导入方法依赖的package包/类
@Test(timeout=20000)
public void testGetHSDelegationToken() throws Exception {
  try {
    Configuration conf = new Configuration();

    // Setup mock service
    InetSocketAddress mockRmAddress = new InetSocketAddress("localhost", 4444);
    Text rmTokenSevice = SecurityUtil.buildTokenService(mockRmAddress);

    InetSocketAddress mockHsAddress = new InetSocketAddress("localhost", 9200);
    Text hsTokenSevice = SecurityUtil.buildTokenService(mockHsAddress);

    // Setup mock rm token
    RMDelegationTokenIdentifier tokenIdentifier = new RMDelegationTokenIdentifier(
        new Text("owner"), new Text("renewer"), new Text("real"));
    Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(
        new byte[0], new byte[0], tokenIdentifier.getKind(), rmTokenSevice);
    token.setKind(RMDelegationTokenIdentifier.KIND_NAME);

    // Setup mock history token
    org.apache.hadoop.yarn.api.records.Token historyToken =
        org.apache.hadoop.yarn.api.records.Token.newInstance(new byte[0],
          MRDelegationTokenIdentifier.KIND_NAME.toString(), new byte[0],
          hsTokenSevice.toString());
    GetDelegationTokenResponse getDtResponse =
        Records.newRecord(GetDelegationTokenResponse.class);
    getDtResponse.setDelegationToken(historyToken);

    // mock services
    MRClientProtocol mockHsProxy = mock(MRClientProtocol.class);
    doReturn(mockHsAddress).when(mockHsProxy).getConnectAddress();
    doReturn(getDtResponse).when(mockHsProxy).getDelegationToken(
        any(GetDelegationTokenRequest.class));

    ResourceMgrDelegate rmDelegate = mock(ResourceMgrDelegate.class);
    doReturn(rmTokenSevice).when(rmDelegate).getRMDelegationTokenService();

    ClientCache clientCache = mock(ClientCache.class);
    doReturn(mockHsProxy).when(clientCache).getInitializedHSProxy();

    Credentials creds = new Credentials();

    YARNRunner yarnRunner = new YARNRunner(conf, rmDelegate, clientCache);

    // No HS token if no RM token
    yarnRunner.addHistoryToken(creds);
    verify(mockHsProxy, times(0)).getDelegationToken(
        any(GetDelegationTokenRequest.class));

    // No HS token if RM token, but secirity disabled.
    creds.addToken(new Text("rmdt"), token);
    yarnRunner.addHistoryToken(creds);
    verify(mockHsProxy, times(0)).getDelegationToken(
        any(GetDelegationTokenRequest.class));

    conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION,
        "kerberos");
    UserGroupInformation.setConfiguration(conf);
    creds = new Credentials();

    // No HS token if no RM token, security enabled
    yarnRunner.addHistoryToken(creds);
    verify(mockHsProxy, times(0)).getDelegationToken(
        any(GetDelegationTokenRequest.class));

    // HS token if RM token present, security enabled
    creds.addToken(new Text("rmdt"), token);
    yarnRunner.addHistoryToken(creds);
    verify(mockHsProxy, times(1)).getDelegationToken(
        any(GetDelegationTokenRequest.class));

    // No additional call to get HS token if RM and HS token present
    yarnRunner.addHistoryToken(creds);
    verify(mockHsProxy, times(1)).getDelegationToken(
        any(GetDelegationTokenRequest.class));
  } finally {
    // Back to defaults.
    UserGroupInformation.setConfiguration(new Configuration());
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:81,代码来源:TestYARNRunner.java


注:本文中的org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier.getKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。