當前位置: 首頁>>代碼示例>>Java>>正文


Java UserGroupInformation.getTokens方法代碼示例

本文整理匯總了Java中org.apache.hadoop.security.UserGroupInformation.getTokens方法的典型用法代碼示例。如果您正苦於以下問題:Java UserGroupInformation.getTokens方法的具體用法?Java UserGroupInformation.getTokens怎麽用?Java UserGroupInformation.getTokens使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.security.UserGroupInformation的用法示例。


在下文中一共展示了UserGroupInformation.getTokens方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAMRMTokenUpdate

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Test
public void testAMRMTokenUpdate() throws Exception {
  Configuration conf = new Configuration();
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      ApplicationId.newInstance(1, 1), 1);
  AMRMTokenIdentifier oldTokenId = new AMRMTokenIdentifier(attemptId, 1);
  AMRMTokenIdentifier newTokenId = new AMRMTokenIdentifier(attemptId, 2);
  Token<AMRMTokenIdentifier> oldToken = new Token<AMRMTokenIdentifier>(
      oldTokenId.getBytes(), "oldpassword".getBytes(), oldTokenId.getKind(),
      new Text());
  Token<AMRMTokenIdentifier> newToken = new Token<AMRMTokenIdentifier>(
      newTokenId.getBytes(), "newpassword".getBytes(), newTokenId.getKind(),
      new Text());

  MockScheduler scheduler = new MockScheduler();
  scheduler.amToken = newToken;

  final LocalContainerAllocator lca =
      new StubbedLocalContainerAllocator(scheduler);
  lca.init(conf);
  lca.start();

  UserGroupInformation testUgi = UserGroupInformation.createUserForTesting(
      "someuser", new String[0]);
  testUgi.addToken(oldToken);
  testUgi.doAs(new PrivilegedExceptionAction<Void>() {
        @Override
        public Void run() throws Exception {
          lca.heartbeat();
          return null;
        }
  });
  lca.close();

  // verify there is only one AMRM token in the UGI and it matches the
  // updated token from the RM
  int tokenCount = 0;
  Token<? extends TokenIdentifier> ugiToken = null;
  for (Token<? extends TokenIdentifier> token : testUgi.getTokens()) {
    if (AMRMTokenIdentifier.KIND_NAME.equals(token.getKind())) {
      ugiToken = token;
      ++tokenCount;
    }
  }

  Assert.assertEquals("too many AMRM tokens", 1, tokenCount);
  Assert.assertArrayEquals("token identifier not updated",
      newToken.getIdentifier(), ugiToken.getIdentifier());
  Assert.assertArrayEquals("token password not updated",
      newToken.getPassword(), ugiToken.getPassword());
  Assert.assertEquals("AMRM token service not updated",
      new Text(ClientRMProxy.getAMRMTokenService(conf)),
      ugiToken.getService());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:55,代碼來源:TestLocalContainerAllocator.java

示例2: testSleepJobWithSecurityOn

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public void testSleepJobWithSecurityOn() throws IOException,
    InterruptedException, ClassNotFoundException {

  LOG.info("\n\n\nStarting testSleepJobWithSecurityOn().");

  if (!(new File(MiniMRYarnCluster.APPJAR)).exists()) {
    return;
  }

  mrCluster.getConfig().set(
      CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  mrCluster.getConfig().set(YarnConfiguration.RM_KEYTAB, "/etc/krb5.keytab");
  mrCluster.getConfig().set(YarnConfiguration.NM_KEYTAB, "/etc/krb5.keytab");
  mrCluster.getConfig().set(YarnConfiguration.RM_PRINCIPAL,
      "rm/[email protected]");
  mrCluster.getConfig().set(YarnConfiguration.NM_PRINCIPAL,
      "nm/[email protected]");
  UserGroupInformation.setConfiguration(mrCluster.getConfig());

  // Keep it in here instead of after RM/NM as multiple user logins happen in
  // the same JVM.
  UserGroupInformation user = UserGroupInformation.getCurrentUser();

  LOG.info("User name is " + user.getUserName());
  for (Token<? extends TokenIdentifier> str : user.getTokens()) {
    LOG.info("Token is " + str.encodeToUrlString());
  }
  user.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {  
      SleepJob sleepJob = new SleepJob();
      sleepJob.setConf(mrCluster.getConfig());
      Job job = sleepJob.createJob(3, 0, 10000, 1, 0, 0);
      // //Job with reduces
      // Job job = sleepJob.createJob(3, 2, 10000, 1, 10000, 1);
      job.addFileToClassPath(APP_JAR); // The AppMaster jar itself.
      job.submit();
      String trackingUrl = job.getTrackingURL();
      String jobId = job.getJobID().toString();
      job.waitForCompletion(true);
      Assert.assertEquals(JobStatus.State.SUCCEEDED, job.getJobState());
      Assert.assertTrue("Tracking URL was " + trackingUrl +
                        " but didn't Match Job ID " + jobId ,
        trackingUrl.endsWith(jobId.substring(jobId.lastIndexOf("_")) + "/"));
      return null;
    }
  });

  // TODO later:  add explicit "isUber()" checks of some sort
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:52,代碼來源:TestMRJobs.java


注:本文中的org.apache.hadoop.security.UserGroupInformation.getTokens方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。