Java Code Examples for org.apache.hadoop.yarn.event.EventHandler#handle()

The following examples show how to use org.apache.hadoop.yarn.event.EventHandler#handle() . 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: TestSchedulerUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static SchedulerApplication<SchedulerApplicationAttempt>
    verifyAppAddedAndRemovedFromScheduler(
        Map<ApplicationId, SchedulerApplication<SchedulerApplicationAttempt>> applications,
        EventHandler<SchedulerEvent> handler, String queueName)
        throws Exception {
  ApplicationId appId =
      ApplicationId.newInstance(System.currentTimeMillis(), 1);
  AppAddedSchedulerEvent appAddedEvent =
      new AppAddedSchedulerEvent(appId, queueName, "user");
  handler.handle(appAddedEvent);
  SchedulerApplication<SchedulerApplicationAttempt> app =
      applications.get(appId);
  // verify application is added.
  Assert.assertNotNull(app);
  Assert.assertEquals("user", app.getUser());

  AppRemovedSchedulerEvent appRemoveEvent =
      new AppRemovedSchedulerEvent(appId, RMAppState.FINISHED);
  handler.handle(appRemoveEvent);
  Assert.assertNull(applications.get(appId));
  return app;
}
 
Example 2
Source File: TestSchedulerUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static SchedulerApplication<SchedulerApplicationAttempt>
    verifyAppAddedAndRemovedFromScheduler(
        Map<ApplicationId, SchedulerApplication<SchedulerApplicationAttempt>> applications,
        EventHandler<SchedulerEvent> handler, String queueName)
        throws Exception {
  ApplicationId appId =
      ApplicationId.newInstance(System.currentTimeMillis(), 1);
  AppAddedSchedulerEvent appAddedEvent =
      new AppAddedSchedulerEvent(appId, queueName, "user");
  handler.handle(appAddedEvent);
  SchedulerApplication<SchedulerApplicationAttempt> app =
      applications.get(appId);
  // verify application is added.
  Assert.assertNotNull(app);
  Assert.assertEquals("user", app.getUser());

  AppRemovedSchedulerEvent appRemoveEvent =
      new AppRemovedSchedulerEvent(appId, RMAppState.FINISHED);
  handler.handle(appRemoveEvent);
  Assert.assertNull(applications.get(appId));
  return app;
}
 
Example 3
Source File: QueryMasterTask.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
public void serviceStop() throws Exception {
  isStopped = true;

  LOG.info("Stopping QueryMasterTask:" + queryId);

  //release QM resource
  EventHandler handler = getQueryTaskContext().getQueryMasterContext().getWorkerContext().
      getNodeResourceManager().getDispatcher().getEventHandler();

  handler.handle(new NodeResourceDeallocateEvent(new Allocation(allocation),
      NodeResourceEvent.ResourceType.QUERY_MASTER));

  //flush current node resource
  handler.handle(new NodeStatusEvent(NodeStatusEvent.EventType.FLUSH_REPORTS));

  if (!queryContext.getBool(SessionVars.DEBUG_ENABLED)) {
    cleanupQuery(getQueryId());
  }

  super.serviceStop();
  LOG.info("Stopped QueryMasterTask:" + queryId);
}
 
Example 4
Source File: TajoAsyncDispatcher.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void dispatch(Event event) {
  //all events go thru this loop
  if (LOG.isDebugEnabled()) {
    LOG.debug("Dispatching the event " + event.getClass().getName() + "."
        + event.toString());
  }
  Class<? extends Enum> type = event.getType().getDeclaringClass();

  try{
    EventHandler handler = eventDispatchers.get(type);
    if(handler != null) {
      handler.handle(event);
    } else {
      throw new Exception("No handler for registered for " + type);
    }
  } catch (Throwable t) {
    //TODO Maybe log the state of the queue
    LOG.fatal("Error in dispatcher thread:" + event.getType(), t);
    if (exitOnDispatchException && (ShutdownHookManager.get().isShutdownInProgress()) == false) {
      LOG.info("Exiting, bye..");
      System.exit(-1);
    }
  } finally {
  }
}
 
Example 5
Source File: ContainerImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendFinishedEvents() {
  // Inform the application
  @SuppressWarnings("rawtypes")
  EventHandler eventHandler = dispatcher.getEventHandler();
  eventHandler.handle(new ApplicationContainerFinishedEvent(containerId));
  // Remove the container from the resource-monitor
  eventHandler.handle(new ContainerStopMonitoringEvent(containerId));
  // Tell the logService too
  eventHandler.handle(new LogHandlerContainerFinishedEvent(
    containerId, exitCode));
}
 
Example 6
Source File: TestSpeculativeExecutionWithMRApp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static TaskAttempt[] makeFirstAttemptWin(
    EventHandler appEventHandler, Task speculatedTask) {

  // finish 1st TA, 2nd will be killed
  Collection<TaskAttempt> attempts = speculatedTask.getAttempts().values();
  TaskAttempt[] ta = new TaskAttempt[attempts.size()];
  attempts.toArray(ta);
  appEventHandler.handle(
      new TaskAttemptEvent(ta[0].getID(), TaskAttemptEventType.TA_DONE));
  appEventHandler.handle(new TaskAttemptEvent(ta[0].getID(),
      TaskAttemptEventType.TA_CONTAINER_CLEANED));
  return ta;
}
 
Example 7
Source File: ContainerImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendFinishedEvents() {
  // Inform the application
  @SuppressWarnings("rawtypes")
  EventHandler eventHandler = dispatcher.getEventHandler();
  eventHandler.handle(new ApplicationContainerFinishedEvent(containerId));
  // Remove the container from the resource-monitor
  eventHandler.handle(new ContainerStopMonitoringEvent(containerId));
  // Tell the logService too
  eventHandler.handle(new LogHandlerContainerFinishedEvent(
    containerId, exitCode));
}
 
Example 8
Source File: TestSpeculativeExecutionWithMRApp.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static TaskAttempt[] makeFirstAttemptWin(
    EventHandler appEventHandler, Task speculatedTask) {

  // finish 1st TA, 2nd will be killed
  Collection<TaskAttempt> attempts = speculatedTask.getAttempts().values();
  TaskAttempt[] ta = new TaskAttempt[attempts.size()];
  attempts.toArray(ta);
  appEventHandler.handle(
      new TaskAttemptEvent(ta[0].getID(), TaskAttemptEventType.TA_DONE));
  appEventHandler.handle(new TaskAttemptEvent(ta[0].getID(),
      TaskAttemptEventType.TA_CONTAINER_CLEANED));
  return ta;
}
 
Example 9
Source File: AsyncDispatcherConcurrent.java    From tez with Apache License 2.0 5 votes vote down vote up
protected void dispatch(Event event) {
  //all events go thru this loop
  if (LOG.isDebugEnabled()) {
    LOG.debug("Dispatching the event " + event.getClass().getName() + "."
        + event.toString());
  }

  Class<? extends Enum> type = event.getType().getDeclaringClass();

  try{
    EventHandler handler = eventHandlers.get(type);
    if(handler != null) {
      handler.handle(event);
    } else {
      throw new Exception("No handler for registered for " + type);
    }
  } catch (Throwable t) {
    LOG.error("Error in dispatcher thread", t);
    // If serviceStop is called, we should exit this thread gracefully.
    if (exitOnDispatchException
        && (ShutdownHookManager.get().isShutdownInProgress()) == false
        && stopped == false) {
      Thread shutDownThread = new Thread(createShutDownThread());
      shutDownThread.setName("AsyncDispatcher ShutDown handler");
      shutDownThread.start();
    }
  }
}
 
Example 10
Source File: AsyncDispatcher.java    From tez with Apache License 2.0 5 votes vote down vote up
protected void dispatch(Event event) {
  //all events go thru this loop
  if (LOG.isDebugEnabled()) {
    LOG.debug("Dispatching the event " + event.getClass().getName() + "."
        + event.toString());
  }

  Class<? extends Enum> type = event.getType().getDeclaringClass();

  try{
    EventHandler handler = eventHandlers.get(type);
    if(handler != null) {
      handler.handle(event);
    } else {
      throw new Exception("No handler for registered for " + type);
    }
  } catch (Throwable t) {
    LOG.error("Error in dispatcher thread", t);
    // If serviceStop is called, we should exit this thread gracefully.
    if (exitOnDispatchException
        && (ShutdownHookManager.get().isShutdownInProgress()) == false
        && stopped == false) {
      Thread shutDownThread = new Thread(createShutDownThread());
      shutDownThread.setName("AsyncDispatcher ShutDown handler");
      shutDownThread.start();
    }
  }
}
 
Example 11
Source File: DrainDispatcher.java    From tez with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public EventHandler getEventHandler() {
  final EventHandler actual = super.getEventHandler();
  return new EventHandler() {
    @Override
    public void handle(Event event) {
      synchronized (mutex) {
        actual.handle(event);
        drained = false;
      }
    }
  };
}
 
Example 12
Source File: TajoAsyncDispatcher.java    From incubator-tajo with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(Event event) {
  for (EventHandler<Event> handler: listofHandlers) {
    handler.handle(event);
  }
}
 
Example 13
Source File: AsyncDispatcherConcurrent.java    From tez with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(Event event) {
  for (EventHandler<Event> handler: listofHandlers) {
    handler.handle(event);
  }
}
 
Example 14
Source File: AsyncDispatcher.java    From tez with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(Event event) {
  for (EventHandler<Event> handler: listofHandlers) {
    handler.handle(event);
  }
}