AM启动--AMContainerAllocatedTransition(二)

AMContainerAllocatedTransition(基于hadoop 2.7.6)

前述RmAppAttempt的状态转换:
AttemptStartedTransition:NEW–>SUBMITTED
ScheduleTransition:SUBMITTED–>SCHEDULED

主要逻辑步骤:
     1.调用scheduler.allocate方法,触发RMContainerEventType.ACQUIRED事件(该事件的处理器AcquiredTransition会将Container加入到containerAllocationExpirer)
     2.触发RMStateStoreEventType.STORE_APP_ATTEMPT事件

AMContainerAllocatedTransition转换器处理后,RmAppAttempt的状态由SCHEDULED转换为ALLOCATED_SAVING.

/**
   *	主要逻辑:
   *		1.调用scheduler.allocate方法
   *		2.触发RMStateStoreEventType.STORE_APP_ATTEMPT事件
   */
  private static final class AMContainerAllocatedTransition
      implements
      MultipleArcTransition<RMAppAttemptImpl, RMAppAttemptEvent, RMAppAttemptState> {
    @Override
    public RMAppAttemptState transition(RMAppAttemptImpl appAttempt,
        RMAppAttemptEvent event) {
      // Acquire the AM container from the scheduler.
    	/**
    	 * 		
    	 * 		1.释放已完成的Container列表
       * 		2.将新需求更新到对应的数据结构中(appSchedulingInfo.requests:Map<Priority, Map<String, ResourceRequest>>)
       * 		3.返回已经为该应用分配的Containers
    	 * 			
    	 */
      Allocation amContainerAllocation =
          appAttempt.scheduler.allocate(appAttempt.applicationAttemptId,
            EMPTY_CONTAINER_REQUEST_LIST, EMPTY_CONTAINER_RELEASE_LIST, null,
            null);
      /**
       * 	存在创建NMToken失败的情况,则重新触发RMAppAttemptEventType.CONTAINER_ALLOCATED用于再次分配资源
       */
      if (amContainerAllocation.getContainers().size() == 0) {
    	  /**
    	   * 	重新触发事件:RMAppAttemptEventType.CONTAINER_ALLOCATED
    	   */
        appAttempt.retryFetchingAMContainer(appAttempt);
        return RMAppAttemptState.SCHEDULED;
      }

      /**
       * 	AM只需要一个Container
       */
      appAttempt.setMasterContainer(amContainerAllocation.getContainers()
          .get(0));
      RMContainerImpl rmMasterContainer = (RMContainerImpl)appAttempt.scheduler
          .getRMContainer(appAttempt.getMasterContainer().getId());
      /**
       * 	设置为AmContainer
       */
      rmMasterContainer.setAMContainer(true);
      appAttempt.rmContext.getNMTokenSecretManager()
  .clearNodeSetForAttempt(appAttempt.applicationAttemptId);
      appAttempt.getSubmissionContext().setResource(
        appAttempt.getMasterContainer().getResource());
      /**
       * 	触发事件:RMStateStoreAppAttemptEvent(RMStateStoreEventType.STORE_APP_ATTEMPT)
       */
      appAttempt.storeAttempt();
      return RMAppAttemptState.ALLOCATED_SAVING;
    }
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值