Search in sources :

Example 1 with ContainerInitializationContext

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

the class TestPerNodeTimelineCollectorsAuxService method createCollectorAndAddApplication.

private PerNodeTimelineCollectorsAuxService createCollectorAndAddApplication() {
    PerNodeTimelineCollectorsAuxService service = createCollector();
    // create an AM container
    ContainerId containerId = getAMContainerId();
    ContainerInitializationContext context = mock(ContainerInitializationContext.class);
    when(context.getContainerId()).thenReturn(containerId);
    when(context.getContainerType()).thenReturn(ContainerType.APPLICATION_MASTER);
    service.initializeContainer(context);
    return service;
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerInitializationContext(org.apache.hadoop.yarn.server.api.ContainerInitializationContext)

Example 2 with ContainerInitializationContext

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

the class TestPerNodeTimelineCollectorsAuxService method testAddApplicationNonAMContainer.

@Test
public void testAddApplicationNonAMContainer() throws Exception {
    auxService = createCollector();
    // not an AM
    ContainerId containerId = getContainerId(2L);
    ContainerInitializationContext context = mock(ContainerInitializationContext.class);
    when(context.getContainerId()).thenReturn(containerId);
    auxService.initializeContainer(context);
    // auxService should not have that app
    assertFalse(auxService.hasApplication(appAttemptId.getApplicationId()));
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerInitializationContext(org.apache.hadoop.yarn.server.api.ContainerInitializationContext) Test(org.junit.Test)

Example 3 with ContainerInitializationContext

use of org.apache.hadoop.yarn.server.api.ContainerInitializationContext 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

ContainerInitializationContext (org.apache.hadoop.yarn.server.api.ContainerInitializationContext)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)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 ContainerTerminationContext (org.apache.hadoop.yarn.server.api.ContainerTerminationContext)1 Test (org.junit.Test)1