AM启动--AttemptStoredTransition(四)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhusirong/article/details/83787996

AttemptStoredTransition(基于hadoop 2.7.6)

主要逻辑:
    1.将在AttemptStartedTransition中创建的ClientToken记录到ClientToAMTokenSecretManagerInRM的列表masterKeys中

    2.触发AMLauncherEventType.LAUNCH事件

AttemptStoredTransition转换处理后,RMAppAttemptState状态由ALLOCATED_SAVING转换为ALLOCATED.

代码清单:

/**
   *	1.将在AttemptStartedTransition中创建的ClientToken记录到
   * 		ClientToAMTokenSecretManagerInRM的列表masterKeys中 
   * 	2.触发AMLauncherEventType.LAUNCH事件
   *
   */
  private static final class AttemptStoredTransition extends BaseTransition {
    @Override
    public void transition(RMAppAttemptImpl appAttempt,
                                                    RMAppAttemptEvent event) {
    	/**
    	 * 	将在AttemptStartedTransition中创建的ClientToken记录到
    	 * 	ClientToAMTokenSecretManagerInRM的列表masterKeys中
    	 */
      appAttempt.registerClientToken();
      /**
       * 	触发AMLauncherEventType.LAUNCH事件
       */
      appAttempt.launchAttempt();
    }
  }

触发AMLauncherEventType.LAUNCH事件:

 private void launchAttempt(){
    launchAMStartTime = System.currentTimeMillis();
    // Send event to launch the AM Container
    eventHandler.handle(new AMLauncherEvent(AMLauncherEventType.LAUNCH, this));
  }

怎么去找AMLauncherEventType.LAUNCH类型事件的处理者呢?
我们可以去ResourceManager里AMLauncherEventType类型注册的调度器:

applicationMasterLauncher = createAMLauncher();
      rmDispatcher.register(AMLauncherEventType.class,
          applicationMasterLauncher);
protected ApplicationMasterLauncher createAMLauncher() {
    return new ApplicationMasterLauncher(this.rmContext);
  }

上述通过初始化相关的代码内容,我们知道要去看ApplicationMasterLauncher的handle方法,这里采用了生产者消费者的设计模式.

猜你喜欢

转载自blog.csdn.net/zhusirong/article/details/83787996
am