Search in sources :

Example 1 with AuxServicesEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent in project hadoop by apache.

the class ApplicationImpl method handleAppFinishWithContainersCleanedup.

@SuppressWarnings("unchecked")
void handleAppFinishWithContainersCleanedup() {
    // Delete Application level resources
    this.dispatcher.getEventHandler().handle(new ApplicationLocalizationEvent(LocalizationEventType.DESTROY_APPLICATION_RESOURCES, this));
    // tell any auxiliary services that the app is done 
    this.dispatcher.getEventHandler().handle(new AuxServicesEvent(AuxServicesEventType.APPLICATION_STOP, appId));
// TODO: Trigger the LogsManager
}
Also used : ApplicationLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent) AuxServicesEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent)

Example 2 with AuxServicesEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent in project hadoop by apache.

the class TestApplication method testAppFinishedOnRunningContainers.

@Test
@SuppressWarnings("unchecked")
public void testAppFinishedOnRunningContainers() {
    WrappedApplication wa = null;
    try {
        wa = new WrappedApplication(4, 314159265358979L, "yak", 3);
        wa.initApplication();
        wa.initContainer(-1);
        assertEquals(ApplicationState.INITING, wa.app.getApplicationState());
        wa.applicationInited();
        assertEquals(ApplicationState.RUNNING, wa.app.getApplicationState());
        wa.containerFinished(0);
        assertEquals(ApplicationState.RUNNING, wa.app.getApplicationState());
        assertEquals(2, wa.app.getContainers().size());
        wa.appFinished();
        assertEquals(ApplicationState.FINISHING_CONTAINERS_WAIT, wa.app.getApplicationState());
        assertEquals(2, wa.app.getContainers().size());
        for (int i = 1; i < wa.containers.size(); i++) {
            verify(wa.containerBus).handle(argThat(new ContainerKillMatcher(wa.containers.get(i).getContainerId())));
        }
        wa.containerFinished(1);
        assertEquals(ApplicationState.FINISHING_CONTAINERS_WAIT, wa.app.getApplicationState());
        assertEquals(1, wa.app.getContainers().size());
        reset(wa.localizerBus);
        wa.containerFinished(2);
        // All containers finished. Cleanup should be called.
        assertEquals(ApplicationState.APPLICATION_RESOURCES_CLEANINGUP, wa.app.getApplicationState());
        assertEquals(0, wa.app.getContainers().size());
        verify(wa.localizerBus).handle(refEq(new ApplicationLocalizationEvent(LocalizationEventType.DESTROY_APPLICATION_RESOURCES, wa.app)));
        verify(wa.auxBus).handle(refEq(new AuxServicesEvent(AuxServicesEventType.APPLICATION_STOP, wa.appId)));
        wa.appResourcesCleanedup();
        for (Container container : wa.containers) {
            ContainerTokenIdentifier identifier = wa.getContainerTokenIdentifier(container.getContainerId());
            waitForContainerTokenToExpire(identifier);
            Assert.assertTrue(wa.context.getContainerTokenSecretManager().isValidStartContainerRequest(identifier));
        }
        assertEquals(ApplicationState.FINISHED, wa.app.getApplicationState());
    } finally {
        if (wa != null)
            wa.finished();
    }
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ApplicationLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent) AuxServicesEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent) ContainerTokenIdentifier(org.apache.hadoop.yarn.security.ContainerTokenIdentifier) Test(org.junit.Test)

Example 3 with AuxServicesEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent in project hadoop by apache.

the class TestContainer method testServiceData.

/**
   * Verify serviceData correctly sent.
   */
@Test
public void testServiceData() throws Exception {
    WrappedContainer wc = null;
    try {
        wc = new WrappedContainer(9, 314159265358979L, 4344, "yak", false, true);
        assertEquals(ContainerState.NEW, wc.c.getContainerState());
        wc.initContainer();
        for (final Map.Entry<String, ByteBuffer> e : wc.serviceData.entrySet()) {
            ArgumentMatcher<AuxServicesEvent> matchesServiceReq = new ArgumentMatcher<AuxServicesEvent>() {

                @Override
                public boolean matches(Object o) {
                    AuxServicesEvent evt = (AuxServicesEvent) o;
                    return e.getKey().equals(evt.getServiceID()) && 0 == e.getValue().compareTo(evt.getServiceData());
                }
            };
            verify(wc.auxBus).handle(argThat(matchesServiceReq));
        }
        final WrappedContainer wcf = wc;
        // verify launch on empty resource request
        ArgumentMatcher<ContainersLauncherEvent> matchesLaunchReq = new ArgumentMatcher<ContainersLauncherEvent>() {

            @Override
            public boolean matches(Object o) {
                ContainersLauncherEvent evt = (ContainersLauncherEvent) o;
                return evt.getType() == ContainersLauncherEventType.LAUNCH_CONTAINER && wcf.cId.equals(evt.getContainer().getContainerId());
            }
        };
        verify(wc.launcherBus).handle(argThat(matchesLaunchReq));
    } finally {
        if (wc != null) {
            wc.finished();
        }
    }
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) AuxServicesEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent) ContainersLauncherEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEvent) Test(org.junit.Test)

Aggregations

AuxServicesEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent)3 ApplicationLocalizationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ContainerTokenIdentifier (org.apache.hadoop.yarn.security.ContainerTokenIdentifier)1 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)1 ContainersLauncherEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEvent)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1