use of org.apache.hadoop.yarn.event.EventDispatcher in project hadoop by apache.
the class ResourceManager method createApplicationMasterService.
protected ApplicationMasterService createApplicationMasterService() {
Configuration config = this.rmContext.getYarnConfiguration();
if (YarnConfiguration.isOpportunisticContainerAllocationEnabled(config) || YarnConfiguration.isDistSchedulingEnabled(config)) {
if (YarnConfiguration.isDistSchedulingEnabled(config) && !YarnConfiguration.isOpportunisticContainerAllocationEnabled(config)) {
throw new YarnRuntimeException("Invalid parameters: opportunistic container allocation has to " + "be enabled when distributed scheduling is enabled.");
}
OpportunisticContainerAllocatorAMService oppContainerAllocatingAMService = new OpportunisticContainerAllocatorAMService(this.rmContext, scheduler);
EventDispatcher oppContainerAllocEventDispatcher = new EventDispatcher(oppContainerAllocatingAMService, OpportunisticContainerAllocatorAMService.class.getName());
// Add an event dispatcher for the
// OpportunisticContainerAllocatorAMService to handle node
// additions, updates and removals. Since the SchedulerEvent is currently
// a super set of theses, we register interest for it.
addService(oppContainerAllocEventDispatcher);
rmDispatcher.register(SchedulerEventType.class, oppContainerAllocEventDispatcher);
this.rmContext.setContainerQueueLimitCalculator(oppContainerAllocatingAMService.getNodeManagerQueueLimitCalculator());
return oppContainerAllocatingAMService;
}
return new ApplicationMasterService(this.rmContext, scheduler);
}
use of org.apache.hadoop.yarn.event.EventDispatcher in project hadoop by apache.
the class TestRMDispatcher method testSchedulerEventDispatcherForPreemptionEvents.
@SuppressWarnings("unchecked")
@Test(timeout = 10000)
public void testSchedulerEventDispatcherForPreemptionEvents() {
AsyncDispatcher rmDispatcher = new AsyncDispatcher();
CapacityScheduler sched = spy(new CapacityScheduler());
YarnConfiguration conf = new YarnConfiguration();
EventDispatcher schedulerDispatcher = new EventDispatcher(sched, sched.getClass().getName());
rmDispatcher.register(SchedulerEventType.class, schedulerDispatcher);
rmDispatcher.init(conf);
rmDispatcher.start();
schedulerDispatcher.init(conf);
schedulerDispatcher.start();
try {
ApplicationAttemptId appAttemptId = mock(ApplicationAttemptId.class);
RMContainer container = mock(RMContainer.class);
ContainerPreemptEvent event1 = new ContainerPreemptEvent(appAttemptId, container, SchedulerEventType.KILL_RESERVED_CONTAINER);
rmDispatcher.getEventHandler().handle(event1);
ContainerPreemptEvent event2 = new ContainerPreemptEvent(appAttemptId, container, SchedulerEventType.MARK_CONTAINER_FOR_KILLABLE);
rmDispatcher.getEventHandler().handle(event2);
ContainerPreemptEvent event3 = new ContainerPreemptEvent(appAttemptId, container, SchedulerEventType.MARK_CONTAINER_FOR_PREEMPTION);
rmDispatcher.getEventHandler().handle(event3);
// Wait for events to be processed by scheduler dispatcher.
Thread.sleep(1000);
verify(sched, times(3)).handle(any(SchedulerEvent.class));
verify(sched).killReservedContainer(container);
verify(sched).markContainerForPreemption(appAttemptId, container);
verify(sched).markContainerForKillable(container);
} catch (InterruptedException e) {
Assert.fail();
} finally {
schedulerDispatcher.stop();
rmDispatcher.stop();
}
}
Aggregations