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


Java ContainerId.getApplicationAttemptId方法代碼示例

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


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

示例1: startContainer

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
private StartContainersResponse startContainer(Context context,
    final ContainerManagerImpl cm, ContainerId cid,
    ContainerLaunchContext clc, LogAggregationContext logAggregationContext)
        throws Exception {
  UserGroupInformation user = UserGroupInformation.createRemoteUser(
      cid.getApplicationAttemptId().toString());
  StartContainerRequest scReq = StartContainerRequest.newInstance(
      clc, TestContainerManager.createContainerToken(cid, 0,
          context.getNodeId(), user.getShortUserName(),
          context.getContainerTokenSecretManager(), logAggregationContext));
  final List<StartContainerRequest> scReqList =
      new ArrayList<StartContainerRequest>();
  scReqList.add(scReq);
  NMTokenIdentifier nmToken = new NMTokenIdentifier(
      cid.getApplicationAttemptId(), context.getNodeId(),
      user.getShortUserName(),
      context.getNMTokenSecretManager().getCurrentKey().getKeyId());
  user.addTokenIdentifier(nmToken);
  return user.doAs(new PrivilegedExceptionAction<StartContainersResponse>() {
    @Override
    public StartContainersResponse run() throws Exception {
      return cm.startContainers(
          StartContainersRequest.newInstance(scReqList));
    }
  });
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestContainerManagerRecovery.java

示例2: setupPreviousRunningContainers

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
private void setupPreviousRunningContainers(RegisterApplicationMasterResponse response) {
  String containerIdStr =
      System.getenv(Environment.CONTAINER_ID.name());
  ContainerId containerId = ContainerId.fromString(containerIdStr);
  appAttemptId = containerId.getApplicationAttemptId();
  List<Container> previousAMRunningContainers =
      response.getContainersFromPreviousAttempts();
  LOG.info(appAttemptId + " received " + previousAMRunningContainers.size()
      + " previous attempts' running containers on AM registration.");
  for (Container container : previousAMRunningContainers) {
    launchedContainers.add(container.getId());
  }
  allocatedContainerNum.addAndGet(previousAMRunningContainers.size());
}
 
開發者ID:Intel-bigdata,項目名稱:TensorFlowOnYARN,代碼行數:15,代碼來源:ApplicationMaster.java

示例3: main

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
public static void main(String[] args) {
  // get configuration from config file
  Configuration conf = new Configuration();
  conf.addResource(AngelConf.ANGEL_JOB_CONF_FILE);

  String containerIdStr = System.getenv(Environment.CONTAINER_ID.name());
  ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
  ApplicationAttemptId applicationAttemptId = containerId.getApplicationAttemptId();
  ApplicationId appId = applicationAttemptId.getApplicationId();
  String user = System.getenv(Environment.USER.name());

  // set localDir with enviroment set by nm.
  String[] localSysDirs =
      StringUtils.getTrimmedStrings(System.getenv(Environment.LOCAL_DIRS.name()));
  conf.setStrings(AngelConf.LOCAL_DIR, localSysDirs);
  LOG.info(AngelConf.LOCAL_DIR + " for child: " + conf.get(AngelConf.LOCAL_DIR));

  String psAgentindex = System.getenv(AngelEnvironment.PSAGENT_ID.name());
  String psAgentAttemptIndex = System.getenv(AngelEnvironment.PSAGENT_ATTEMPT_ID.name());
  String masterAddr = System.getenv(AngelEnvironment.LISTEN_ADDR.name());
  String portStr = System.getenv(AngelEnvironment.LISTEN_PORT.name());
  Location masterLocation = new Location(masterAddr, Integer.valueOf(portStr));

  LOG.info("psAgentindex=" + psAgentindex);
  LOG.info("psAgentAttemptIndex=" + psAgentAttemptIndex);
  LOG.info("masterLocation=" + masterLocation);
  LOG.info("user=" + user);
  LOG.info("appId=" + appId);

  PSAgentId psAgentId = new PSAgentId(Integer.valueOf(psAgentindex));
  PSAgentAttemptId psAgentAttemptId =
      new PSAgentAttemptId(psAgentId, Integer.valueOf(psAgentAttemptIndex));

  try {
    PSAgent psAgent =
        new PSAgent(conf, appId, user, psAgentAttemptId, masterAddr, Integer.valueOf(portStr),
            true, null);
    psAgent.initAndStart();
  } catch (Exception e) {
    LOG.fatal("Failed to start worker.", e);
  }
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:43,代碼來源:PSAgent.java

示例4: main

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
public static void main(String[] args) {
  // get configuration from config file
  Configuration conf = new Configuration();
  conf.addResource(AngelConf.ANGEL_JOB_CONF_FILE);

  String containerIdStr = System.getenv(Environment.CONTAINER_ID.name());
  ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
  ApplicationAttemptId applicationAttemptId = containerId.getApplicationAttemptId();
  ApplicationId appId = applicationAttemptId.getApplicationId();
  String user = System.getenv(Environment.USER.name());

  // set localDir with enviroment set by nm.
  String[] localSysDirs =
      StringUtils.getTrimmedStrings(System.getenv(Environment.LOCAL_DIRS.name()));
  conf.setStrings(AngelConf.LOCAL_DIR, localSysDirs);
  LOG.info(
      AngelConf.LOCAL_DIR + " for child: " + conf.get(AngelConf.LOCAL_DIR));
  int workerGroupIndex = Integer.parseInt(System.getenv(AngelEnvironment.WORKER_GROUP_ID.name()));
  int workerIndex = Integer.parseInt(System.getenv(AngelEnvironment.WORKER_ID.name()));
  int attemptIndex = Integer.parseInt(System.getenv(AngelEnvironment.WORKER_ATTEMPT_ID.name()));

  WorkerGroupId workerGroupId = new WorkerGroupId(workerGroupIndex);
  WorkerId workerId = new WorkerId(workerGroupId, workerIndex);
  WorkerAttemptId workerAttemptId = new WorkerAttemptId(workerId, attemptIndex);

  conf.set(AngelConf.ANGEL_WORKERGROUP_ACTUAL_NUM,
      System.getenv(AngelEnvironment.WORKERGROUP_NUMBER.name()));

  conf.set(AngelConf.ANGEL_TASK_ACTUAL_NUM,
      System.getenv(AngelEnvironment.TASK_NUMBER.name()));
  
  conf.set(AngelConf.ANGEL_TASK_USER_TASKCLASS,
      System.getenv(AngelEnvironment.ANGEL_USER_TASK.name()));

  LOG.info(
      "actual workergroup number:" + conf.get(AngelConf.ANGEL_WORKERGROUP_ACTUAL_NUM));
  LOG.info("actual task number:" + conf.get(AngelConf.ANGEL_TASK_ACTUAL_NUM));

  // get master location
  String masterAddr = System.getenv(AngelEnvironment.LISTEN_ADDR.name());
  String portStr = System.getenv(AngelEnvironment.LISTEN_PORT.name());
  Location masterLocation = new Location(masterAddr, Integer.valueOf(portStr));

  String startClock = System.getenv(AngelEnvironment.INIT_MIN_CLOCK.name());
  Worker worker = new Worker(AngelConf.clone(conf), appId, user, workerAttemptId,
      masterLocation, Integer.valueOf(startClock), false);

  try {
    worker.initAndStart();
  } catch (Exception e) {
    LOG.fatal("Failed to start worker.", e);
    worker.error(e.getMessage());
  }
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:55,代碼來源:Worker.java

示例5: testContainerLogs

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
@Test
public void testContainerLogs() throws IOException {
  WebResource r = resource();
  final ContainerId containerId = BuilderUtils.newContainerId(0, 0, 0, 0);
  final String containerIdStr = BuilderUtils.newContainerId(0, 0, 0, 0)
      .toString();
  final ApplicationAttemptId appAttemptId = containerId.getApplicationAttemptId();
  final ApplicationId appId = appAttemptId.getApplicationId();
  final String appIdStr = appId.toString();
  final String filename = "logfile1";
  final String logMessage = "log message\n";
  nmContext.getApplications().put(appId, new ApplicationImpl(null, "user",
      appId, null, nmContext));
  
  MockContainer container = new MockContainer(appAttemptId,
      new AsyncDispatcher(), new Configuration(), "user", appId, 1);
  container.setState(ContainerState.RUNNING);
  nmContext.getContainers().put(containerId, container);
  
  // write out log file
  Path path = dirsHandler.getLogPathForWrite(
      ContainerLaunch.getRelativeContainerLogDir(
          appIdStr, containerIdStr) + "/" + filename, false);
  
  File logFile = new File(path.toUri().getPath());
  logFile.deleteOnExit();
  assertTrue("Failed to create log dir", logFile.getParentFile().mkdirs());
  PrintWriter pw = new PrintWriter(logFile);
  pw.print(logMessage);
  pw.close();

  // ask for it
  ClientResponse response = r.path("ws").path("v1").path("node")
      .path("containerlogs").path(containerIdStr).path(filename)
      .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
  String responseText = response.getEntity(String.class);
  assertEquals(logMessage, responseText);
  
  // ask for file that doesn't exist
  response = r.path("ws").path("v1").path("node")
      .path("containerlogs").path(containerIdStr).path("uhhh")
      .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
  Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  responseText = response.getEntity(String.class);
  assertTrue(responseText.contains("Cannot find this log on the local disk."));
  
  // After container is completed, it is removed from nmContext
  nmContext.getContainers().remove(containerId);
  Assert.assertNull(nmContext.getContainers().get(containerId));
  response =
      r.path("ws").path("v1").path("node").path("containerlogs")
          .path(containerIdStr).path(filename).accept(MediaType.TEXT_PLAIN)
          .get(ClientResponse.class);
  responseText = response.getEntity(String.class);
  assertEquals(logMessage, responseText);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:57,代碼來源:TestNMWebServices.java

示例6: getContainerReport

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
@Override
public GetContainerReportResponse getContainerReport(
    GetContainerReportRequest request) throws YarnException, IOException {
  ContainerId containerId = request.getContainerId();
  ApplicationAttemptId appAttemptId = containerId.getApplicationAttemptId();
  ApplicationId appId = appAttemptId.getApplicationId();
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }
  RMApp application = this.rmContext.getRMApps().get(appId);
  if (application == null) {
    // If the RM doesn't have the application, throw
    // ApplicationNotFoundException and let client to handle.
    throw new ApplicationNotFoundException("Application with id '" + appId
        + "' doesn't exist in RM.");
  }
  boolean allowAccess = checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.VIEW_APP, application);
  GetContainerReportResponse response = null;
  if (allowAccess) {
    RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
    if (appAttempt == null) {
      throw new ApplicationAttemptNotFoundException(
          "ApplicationAttempt with id '" + appAttemptId +
          "' doesn't exist in RM.");
    }
    RMContainer rmConatiner = this.rmContext.getScheduler().getRMContainer(
        containerId);
    if (rmConatiner == null) {
      throw new ContainerNotFoundException("Container with id '" + containerId
          + "' doesn't exist in RM.");
    }
    response = GetContainerReportResponse.newInstance(rmConatiner
        .createContainerReport());
  } else {
    throw new YarnException("User " + callerUGI.getShortUserName()
        + " does not have privilage to see this aplication " + appId);
  }
  return response;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:45,代碼來源:ClientRMService.java

示例7: main

import org.apache.hadoop.yarn.api.records.ContainerId; //導入方法依賴的package包/類
public static void main(String[] args) {
  try {
    Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler());
    String containerIdStr =
        System.getenv(Environment.CONTAINER_ID.name());
    String nodeHostString = System.getenv(Environment.NM_HOST.name());
    String nodePortString = System.getenv(Environment.NM_PORT.name());
    String nodeHttpPortString =
        System.getenv(Environment.NM_HTTP_PORT.name());
    String appSubmitTimeStr =
        System.getenv(ApplicationConstants.APP_SUBMIT_TIME_ENV);
    
    validateInputParam(containerIdStr,
        Environment.CONTAINER_ID.name());
    validateInputParam(nodeHostString, Environment.NM_HOST.name());
    validateInputParam(nodePortString, Environment.NM_PORT.name());
    validateInputParam(nodeHttpPortString,
        Environment.NM_HTTP_PORT.name());
    validateInputParam(appSubmitTimeStr,
        ApplicationConstants.APP_SUBMIT_TIME_ENV);

    ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
    ApplicationAttemptId applicationAttemptId =
        containerId.getApplicationAttemptId();
    long appSubmitTime = Long.parseLong(appSubmitTimeStr);
    
    
    MRAppMaster appMaster =
        new MRAppMaster(applicationAttemptId, containerId, nodeHostString,
            Integer.parseInt(nodePortString),
            Integer.parseInt(nodeHttpPortString), appSubmitTime);
    ShutdownHookManager.get().addShutdownHook(
      new MRAppMasterShutdownHook(appMaster), SHUTDOWN_HOOK_PRIORITY);
    JobConf conf = new JobConf(new YarnConfiguration());
    conf.addResource(new Path(MRJobConfig.JOB_CONF_FILE));
    
    MRWebAppUtil.initialize(conf);
    String jobUserName = System
        .getenv(ApplicationConstants.Environment.USER.name());
    conf.set(MRJobConfig.USER_NAME, jobUserName);
    initAndStartAppMaster(appMaster, conf, jobUserName);
  } catch (Throwable t) {
    LOG.fatal("Error starting MRAppMaster", t);
    ExitUtil.terminate(1, t);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:47,代碼來源:MRAppMaster.java


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