Java Code Examples for org.apache.hadoop.yarn.event.AsyncDispatcher#register()

The following examples show how to use org.apache.hadoop.yarn.event.AsyncDispatcher#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMStateStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceInit(Configuration conf) throws Exception{
  // create async handler
  dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.register(RMStateStoreEventType.class, 
                      new ForwardingEventHandler());
  dispatcher.setDrainEventsOnStop();
  initInternal(conf);
}
 
Example 2
Source File: TestJobImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobNoTasks() {
  Configuration conf = new Configuration();
  conf.setInt(MRJobConfig.NUM_REDUCES, 0);
  conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
  conf.set(MRJobConfig.WORKFLOW_ID, "testId");
  conf.set(MRJobConfig.WORKFLOW_NAME, "testName");
  conf.set(MRJobConfig.WORKFLOW_NODE_NAME, "testNodeName");
  conf.set(MRJobConfig.WORKFLOW_ADJACENCY_PREFIX_STRING + "key1", "value1");
  conf.set(MRJobConfig.WORKFLOW_ADJACENCY_PREFIX_STRING + "key2", "value2");
  conf.set(MRJobConfig.WORKFLOW_TAGS, "tag1,tag2");
  
 
  AsyncDispatcher dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.start();
  OutputCommitter committer = mock(OutputCommitter.class);
  CommitterEventHandler commitHandler =
      createCommitterEventHandler(dispatcher, committer);
  commitHandler.init(conf);
  commitHandler.start();

  JobSubmittedEventHandler jseHandler = new JobSubmittedEventHandler("testId",
      "testName", "testNodeName", "\"key2\"=\"value2\" \"key1\"=\"value1\" ",
      "tag1,tag2");
  dispatcher.register(EventType.class, jseHandler);
  JobImpl job = createStubbedJob(conf, dispatcher, 0, null);
  job.handle(new JobEvent(job.getID(), JobEventType.JOB_INIT));
  assertJobState(job, JobStateInternal.INITED);
  job.handle(new JobStartEvent(job.getID()));
  assertJobState(job, JobStateInternal.SUCCEEDED);
  dispatcher.stop();
  commitHandler.stop();
  try {
    Assert.assertTrue(jseHandler.getAssertValue());
  } catch (InterruptedException e) {
    Assert.fail("Workflow related attributes are not tested properly");
  }
}
 
Example 3
Source File: RMStateStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceInit(Configuration conf) throws Exception{
  // create async handler
  dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.register(RMStateStoreEventType.class, 
                      new ForwardingEventHandler());
  dispatcher.setDrainEventsOnStop();
  initInternal(conf);
}
 
Example 4
Source File: TestJobImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobNoTasks() {
  Configuration conf = new Configuration();
  conf.setInt(MRJobConfig.NUM_REDUCES, 0);
  conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
  conf.set(MRJobConfig.WORKFLOW_ID, "testId");
  conf.set(MRJobConfig.WORKFLOW_NAME, "testName");
  conf.set(MRJobConfig.WORKFLOW_NODE_NAME, "testNodeName");
  conf.set(MRJobConfig.WORKFLOW_ADJACENCY_PREFIX_STRING + "key1", "value1");
  conf.set(MRJobConfig.WORKFLOW_ADJACENCY_PREFIX_STRING + "key2", "value2");
  conf.set(MRJobConfig.WORKFLOW_TAGS, "tag1,tag2");
  
 
  AsyncDispatcher dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.start();
  OutputCommitter committer = mock(OutputCommitter.class);
  CommitterEventHandler commitHandler =
      createCommitterEventHandler(dispatcher, committer);
  commitHandler.init(conf);
  commitHandler.start();

  JobSubmittedEventHandler jseHandler = new JobSubmittedEventHandler("testId",
      "testName", "testNodeName", "\"key2\"=\"value2\" \"key1\"=\"value1\" ",
      "tag1,tag2");
  dispatcher.register(EventType.class, jseHandler);
  JobImpl job = createStubbedJob(conf, dispatcher, 0, null);
  job.handle(new JobEvent(job.getID(), JobEventType.JOB_INIT));
  assertJobState(job, JobStateInternal.INITED);
  job.handle(new JobStartEvent(job.getID()));
  assertJobState(job, JobStateInternal.SUCCEEDED);
  dispatcher.stop();
  commitHandler.stop();
  try {
    Assert.assertTrue(jseHandler.getAssertValue());
  } catch (InterruptedException e) {
    Assert.fail("Workflow related attributes are not tested properly");
  }
}
 
Example 5
Source File: ContainerManagerImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public ContainerManagerImpl(Context context, ContainerExecutor exec,
    DeletionService deletionContext, NodeStatusUpdater nodeStatusUpdater,
    NodeManagerMetrics metrics, ApplicationACLsManager aclsManager,
    LocalDirsHandlerService dirsHandler) {
  super(ContainerManagerImpl.class.getName());
  this.context = context;
  this.dirsHandler = dirsHandler;

  // ContainerManager level dispatcher.
  dispatcher = new AsyncDispatcher();
  this.deletionService = deletionContext;
  this.metrics = metrics;

  rsrcLocalizationSrvc =
      createResourceLocalizationService(exec, deletionContext, context);
  addService(rsrcLocalizationSrvc);

  containersLauncher = createContainersLauncher(context, exec);
  addService(containersLauncher);

  this.nodeStatusUpdater = nodeStatusUpdater;
  this.aclsManager = aclsManager;

  // Start configurable services
  auxiliaryServices = new AuxServices();
  auxiliaryServices.registerServiceListener(this);
  addService(auxiliaryServices);

  this.containersMonitor =
      new ContainersMonitorImpl(exec, dispatcher, this.context);
  addService(this.containersMonitor);

  dispatcher.register(ContainerEventType.class,
      new ContainerEventDispatcher());
  dispatcher.register(ApplicationEventType.class,
      new ApplicationEventDispatcher());
  dispatcher.register(LocalizationEventType.class, rsrcLocalizationSrvc);
  dispatcher.register(AuxServicesEventType.class, auxiliaryServices);
  dispatcher.register(ContainersMonitorEventType.class, containersMonitor);
  dispatcher.register(ContainersLauncherEventType.class, containersLauncher);
  
  addService(dispatcher);

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
}
 
Example 6
Source File: SystemMetricsPublisher.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void register(Class<? extends Enum> eventType, EventHandler handler) {
  for (AsyncDispatcher dispatcher : dispatchers) {
    dispatcher.register(eventType, handler);
  }
}
 
Example 7
Source File: RMApplicationHistoryWriter.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void register(Class<? extends Enum> eventType, EventHandler handler) {
  for (AsyncDispatcher dispatcher : dispatchers) {
    dispatcher.register(eventType, handler);
  }
}
 
Example 8
Source File: TestCommitterEventHandler.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testCommitWindow() throws Exception {
  Configuration conf = new Configuration();
  conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
  AsyncDispatcher dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.start();

  TestingJobEventHandler jeh = new TestingJobEventHandler();
  dispatcher.register(JobEventType.class, jeh);

  SystemClock clock = new SystemClock();
  AppContext appContext = mock(AppContext.class);
  ApplicationAttemptId attemptid = 
    ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
  when(appContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
  when(appContext.getApplicationAttemptId()).thenReturn(attemptid);
  when(appContext.getEventHandler()).thenReturn(
      dispatcher.getEventHandler());
  when(appContext.getClock()).thenReturn(clock);
  OutputCommitter committer = mock(OutputCommitter.class);
  TestingRMHeartbeatHandler rmhh =
      new TestingRMHeartbeatHandler();

  CommitterEventHandler ceh = new CommitterEventHandler(appContext,
      committer, rmhh);
  ceh.init(conf);
  ceh.start();

  // verify trying to commit when RM heartbeats are stale does not commit
  ceh.handle(new CommitterJobCommitEvent(null, null));
  long timeToWaitMs = 5000;
  while (rmhh.getNumCallbacks() != 1 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not register a heartbeat callback",
      1, rmhh.getNumCallbacks());
  verify(committer, never()).commitJob(any(JobContext.class));
  Assert.assertEquals("committer should not have committed",
      0, jeh.numCommitCompletedEvents);

  // set a fresh heartbeat and verify commit completes
  rmhh.setLastHeartbeatTime(clock.getTime());
  timeToWaitMs = 5000;
  while (jeh.numCommitCompletedEvents != 1 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not complete commit after RM hearbeat",
      1, jeh.numCommitCompletedEvents);
  verify(committer, times(1)).commitJob(any(JobContext.class));

  //Clean up so we can try to commit again (Don't do this at home)
  cleanup();
  
  // try to commit again and verify it goes through since the heartbeat
  // is still fresh
  ceh.handle(new CommitterJobCommitEvent(null, null));
  timeToWaitMs = 5000;
  while (jeh.numCommitCompletedEvents != 2 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not commit",
      2, jeh.numCommitCompletedEvents);
  verify(committer, times(2)).commitJob(any(JobContext.class));

  ceh.stop();
  dispatcher.stop();
}
 
Example 9
Source File: ContainerManagerImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
public ContainerManagerImpl(Context context, ContainerExecutor exec,
    DeletionService deletionContext, NodeStatusUpdater nodeStatusUpdater,
    NodeManagerMetrics metrics, ApplicationACLsManager aclsManager,
    LocalDirsHandlerService dirsHandler) {
  super(ContainerManagerImpl.class.getName());
  this.context = context;
  this.dirsHandler = dirsHandler;

  // ContainerManager level dispatcher.
  dispatcher = new AsyncDispatcher();
  this.deletionService = deletionContext;
  this.metrics = metrics;

  rsrcLocalizationSrvc =
      createResourceLocalizationService(exec, deletionContext, context);
  addService(rsrcLocalizationSrvc);

  containersLauncher = createContainersLauncher(context, exec);
  addService(containersLauncher);

  this.nodeStatusUpdater = nodeStatusUpdater;
  this.aclsManager = aclsManager;

  // Start configurable services
  auxiliaryServices = new AuxServices();
  auxiliaryServices.registerServiceListener(this);
  addService(auxiliaryServices);

  this.containersMonitor =
      new ContainersMonitorImpl(exec, dispatcher, this.context);
  addService(this.containersMonitor);

  dispatcher.register(ContainerEventType.class,
      new ContainerEventDispatcher());
  dispatcher.register(ApplicationEventType.class,
      new ApplicationEventDispatcher());
  dispatcher.register(LocalizationEventType.class, rsrcLocalizationSrvc);
  dispatcher.register(AuxServicesEventType.class, auxiliaryServices);
  dispatcher.register(ContainersMonitorEventType.class, containersMonitor);
  dispatcher.register(ContainersLauncherEventType.class, containersLauncher);
  
  addService(dispatcher);

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
}
 
Example 10
Source File: SystemMetricsPublisher.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void register(Class<? extends Enum> eventType, EventHandler handler) {
  for (AsyncDispatcher dispatcher : dispatchers) {
    dispatcher.register(eventType, handler);
  }
}
 
Example 11
Source File: RMApplicationHistoryWriter.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void register(Class<? extends Enum> eventType, EventHandler handler) {
  for (AsyncDispatcher dispatcher : dispatchers) {
    dispatcher.register(eventType, handler);
  }
}
 
Example 12
Source File: TestCommitterEventHandler.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testCommitWindow() throws Exception {
  Configuration conf = new Configuration();
  conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
  AsyncDispatcher dispatcher = new AsyncDispatcher();
  dispatcher.init(conf);
  dispatcher.start();

  TestingJobEventHandler jeh = new TestingJobEventHandler();
  dispatcher.register(JobEventType.class, jeh);

  SystemClock clock = new SystemClock();
  AppContext appContext = mock(AppContext.class);
  ApplicationAttemptId attemptid = 
    ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
  when(appContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
  when(appContext.getApplicationAttemptId()).thenReturn(attemptid);
  when(appContext.getEventHandler()).thenReturn(
      dispatcher.getEventHandler());
  when(appContext.getClock()).thenReturn(clock);
  OutputCommitter committer = mock(OutputCommitter.class);
  TestingRMHeartbeatHandler rmhh =
      new TestingRMHeartbeatHandler();

  CommitterEventHandler ceh = new CommitterEventHandler(appContext,
      committer, rmhh);
  ceh.init(conf);
  ceh.start();

  // verify trying to commit when RM heartbeats are stale does not commit
  ceh.handle(new CommitterJobCommitEvent(null, null));
  long timeToWaitMs = 5000;
  while (rmhh.getNumCallbacks() != 1 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not register a heartbeat callback",
      1, rmhh.getNumCallbacks());
  verify(committer, never()).commitJob(any(JobContext.class));
  Assert.assertEquals("committer should not have committed",
      0, jeh.numCommitCompletedEvents);

  // set a fresh heartbeat and verify commit completes
  rmhh.setLastHeartbeatTime(clock.getTime());
  timeToWaitMs = 5000;
  while (jeh.numCommitCompletedEvents != 1 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not complete commit after RM hearbeat",
      1, jeh.numCommitCompletedEvents);
  verify(committer, times(1)).commitJob(any(JobContext.class));

  //Clean up so we can try to commit again (Don't do this at home)
  cleanup();
  
  // try to commit again and verify it goes through since the heartbeat
  // is still fresh
  ceh.handle(new CommitterJobCommitEvent(null, null));
  timeToWaitMs = 5000;
  while (jeh.numCommitCompletedEvents != 2 && timeToWaitMs > 0) {
    Thread.sleep(10);
    timeToWaitMs -= 10;
  }
  Assert.assertEquals("committer did not commit",
      2, jeh.numCommitCompletedEvents);
  verify(committer, times(2)).commitJob(any(JobContext.class));

  ceh.stop();
  dispatcher.stop();
}