Search in sources :

Example 1 with ContainerTerminationContext

use of org.apache.hadoop.yarn.server.api.ContainerTerminationContext in project hadoop by apache.

the class TestPerNodeTimelineCollectorsAuxService method testRemoveApplication.

@Test
public void testRemoveApplication() throws Exception {
    auxService = createCollectorAndAddApplication();
    // auxService should have a single app
    assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
    ContainerId containerId = getAMContainerId();
    ContainerTerminationContext context = mock(ContainerTerminationContext.class);
    when(context.getContainerId()).thenReturn(containerId);
    when(context.getContainerType()).thenReturn(ContainerType.APPLICATION_MASTER);
    auxService.stopContainer(context);
    // auxService should have the app's collector and need to remove only after
    // a configured period
    assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
    for (int i = 0; i < 4; i++) {
        Thread.sleep(500L);
        if (!auxService.hasApplication(appAttemptId.getApplicationId())) {
            break;
        }
    }
    // auxService should not have that app
    assertFalse(auxService.hasApplication(appAttemptId.getApplicationId()));
    auxService.close();
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerTerminationContext(org.apache.hadoop.yarn.server.api.ContainerTerminationContext) Test(org.junit.Test)

Example 2 with ContainerTerminationContext

use of org.apache.hadoop.yarn.server.api.ContainerTerminationContext in project hadoop by apache.

the class TestPerNodeTimelineCollectorsAuxService method testRemoveApplicationNonAMContainer.

@Test
public void testRemoveApplicationNonAMContainer() throws Exception {
    auxService = createCollectorAndAddApplication();
    // auxService should have a single app
    assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
    // not an AM
    ContainerId containerId = getContainerId(2L);
    ContainerTerminationContext context = mock(ContainerTerminationContext.class);
    when(context.getContainerId()).thenReturn(containerId);
    auxService.stopContainer(context);
    // auxService should still have that app
    assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
    auxService.close();
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerTerminationContext(org.apache.hadoop.yarn.server.api.ContainerTerminationContext) Test(org.junit.Test)

Example 3 with ContainerTerminationContext

use of org.apache.hadoop.yarn.server.api.ContainerTerminationContext in project hadoop by apache.

the class AuxServices method handle.

@Override
public void handle(AuxServicesEvent event) {
    LOG.info("Got event " + event.getType() + " for appId " + event.getApplicationID());
    switch(event.getType()) {
        case APPLICATION_INIT:
            LOG.info("Got APPLICATION_INIT for service " + event.getServiceID());
            AuxiliaryService service = null;
            try {
                service = serviceMap.get(event.getServiceID());
                service.initializeApplication(new ApplicationInitializationContext(event.getUser(), event.getApplicationID(), event.getServiceData()));
            } catch (Throwable th) {
                logWarningWhenAuxServiceThrowExceptions(service, AuxServicesEventType.APPLICATION_INIT, th);
            }
            break;
        case APPLICATION_STOP:
            for (AuxiliaryService serv : serviceMap.values()) {
                try {
                    serv.stopApplication(new ApplicationTerminationContext(event.getApplicationID()));
                } catch (Throwable th) {
                    logWarningWhenAuxServiceThrowExceptions(serv, AuxServicesEventType.APPLICATION_STOP, th);
                }
            }
            break;
        case CONTAINER_INIT:
            for (AuxiliaryService serv : serviceMap.values()) {
                try {
                    serv.initializeContainer(new ContainerInitializationContext(event.getUser(), event.getContainer().getContainerId(), event.getContainer().getResource(), event.getContainer().getContainerTokenIdentifier().getContainerType()));
                } catch (Throwable th) {
                    logWarningWhenAuxServiceThrowExceptions(serv, AuxServicesEventType.CONTAINER_INIT, th);
                }
            }
            break;
        case CONTAINER_STOP:
            for (AuxiliaryService serv : serviceMap.values()) {
                try {
                    serv.stopContainer(new ContainerTerminationContext(event.getUser(), event.getContainer().getContainerId(), event.getContainer().getResource(), event.getContainer().getContainerTokenIdentifier().getContainerType()));
                } catch (Throwable th) {
                    logWarningWhenAuxServiceThrowExceptions(serv, AuxServicesEventType.CONTAINER_STOP, th);
                }
            }
            break;
        default:
            throw new RuntimeException("Unknown type: " + event.getType());
    }
}
Also used : AuxiliaryService(org.apache.hadoop.yarn.server.api.AuxiliaryService) ContainerTerminationContext(org.apache.hadoop.yarn.server.api.ContainerTerminationContext) ContainerInitializationContext(org.apache.hadoop.yarn.server.api.ContainerInitializationContext) ApplicationInitializationContext(org.apache.hadoop.yarn.server.api.ApplicationInitializationContext) ApplicationTerminationContext(org.apache.hadoop.yarn.server.api.ApplicationTerminationContext)

Aggregations

ContainerTerminationContext (org.apache.hadoop.yarn.server.api.ContainerTerminationContext)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 Test (org.junit.Test)2 ApplicationInitializationContext (org.apache.hadoop.yarn.server.api.ApplicationInitializationContext)1 ApplicationTerminationContext (org.apache.hadoop.yarn.server.api.ApplicationTerminationContext)1 AuxiliaryService (org.apache.hadoop.yarn.server.api.AuxiliaryService)1 ContainerInitializationContext (org.apache.hadoop.yarn.server.api.ContainerInitializationContext)1