Search in sources :

Example 51 with EventHandler

use of org.apache.hadoop.yarn.event.EventHandler in project tez by apache.

the class TestContainerLauncherManager method testContainerLauncherUserError.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testContainerLauncherUserError() throws ServicePluginException {
    ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class);
    doReturn(eventHandler).when(appContext).getEventHandler();
    doReturn("testlauncher").when(appContext).getContainerLauncherName(0);
    Configuration conf = new Configuration(false);
    ContainerLauncherManager containerLauncherManager = new ContainerLauncherManager(appContext);
    containerLauncherManager.setContainerLauncher(containerLauncher);
    try {
        containerLauncherManager.init(conf);
        containerLauncherManager.start();
        // launch container
        doThrow(new RuntimeException("testexception")).when(containerLauncher).launchContainer(any(ContainerLaunchRequest.class));
        ContainerLaunchContext clc1 = mock(ContainerLaunchContext.class);
        Container container1 = mock(Container.class);
        ContainerLauncherLaunchRequestEvent launchRequestEvent = new ContainerLauncherLaunchRequestEvent(clc1, container1, 0, 0, 0);
        containerLauncherManager.handle(launchRequestEvent);
        ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        Event rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        DAGAppMasterEventUserServiceFatalError event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.CONTAINER_LAUNCHER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("testexception"));
        assertTrue(event.getDiagnosticInfo().contains("launching container"));
        assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
        reset(eventHandler);
        // stop container
        doThrow(new RuntimeException("teststopexception")).when(containerLauncher).stopContainer(any(ContainerStopRequest.class));
        ContainerId containerId2 = mock(ContainerId.class);
        NodeId nodeId2 = mock(NodeId.class);
        ContainerLauncherStopRequestEvent stopRequestEvent = new ContainerLauncherStopRequestEvent(containerId2, nodeId2, null, 0, 0, 0);
        argumentCaptor = ArgumentCaptor.forClass(Event.class);
        containerLauncherManager.handle(stopRequestEvent);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertTrue(event.getError().getMessage().contains("teststopexception"));
        assertTrue(event.getDiagnosticInfo().contains("stopping container"));
        assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
    } finally {
        containerLauncherManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) AppContext(org.apache.tez.dag.app.AppContext) EventHandler(org.apache.hadoop.yarn.event.EventHandler) ContainerStopRequest(org.apache.tez.serviceplugins.api.ContainerStopRequest) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ContainerLauncherLaunchRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent) ContainerLauncher(org.apache.tez.serviceplugins.api.ContainerLauncher) Container(org.apache.hadoop.yarn.api.records.Container) ContainerLaunchRequest(org.apache.tez.serviceplugins.api.ContainerLaunchRequest) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ContainerLauncherLaunchRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent) Event(org.apache.hadoop.yarn.event.Event) ContainerLauncherStopRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherStopRequestEvent) ContainerLauncherStopRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherStopRequestEvent) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Example 52 with EventHandler

use of org.apache.hadoop.yarn.event.EventHandler in project tez by apache.

the class TestTaskCommunicatorManager1 method setUp.

@Before
public void setUp() throws TezException {
    appId = ApplicationId.newInstance(1000, 1);
    appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    dag = mock(DAG.class);
    TezDAGID dagID = TezDAGID.getInstance(appId, 1);
    vertexID = TezVertexID.getInstance(dagID, 1);
    taskID = TezTaskID.getInstance(vertexID, 1);
    taskAttemptID = TezTaskAttemptID.getInstance(taskID, 1);
    credentials = new Credentials();
    amContainerMap = mock(AMContainerMap.class);
    Map<ApplicationAccessType, String> appAcls = new HashMap<ApplicationAccessType, String>();
    eventHandler = mock(EventHandler.class);
    MockClock clock = new MockClock();
    appContext = mock(AppContext.class);
    doReturn(eventHandler).when(appContext).getEventHandler();
    doReturn(dag).when(appContext).getCurrentDAG();
    doReturn(appAcls).when(appContext).getApplicationACLs();
    doReturn(amContainerMap).when(appContext).getAllContainers();
    doReturn(clock).when(appContext).getClock();
    doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
    doReturn(credentials).when(appContext).getAppCredentials();
    NodeId nodeId = NodeId.newInstance("localhost", 0);
    AMContainer amContainer = mock(AMContainer.class);
    Container container = mock(Container.class);
    doReturn(nodeId).when(container).getNodeId();
    doReturn(amContainer).when(amContainerMap).get(any(ContainerId.class));
    doReturn(container).when(amContainer).getContainer();
    Configuration conf = new TezConfiguration();
    UserPayload defaultPayload;
    try {
        defaultPayload = TezUtils.createUserPayloadFromConf(conf);
    } catch (IOException e) {
        throw new TezUncheckedException(e);
    }
    taskAttemptListener = new TaskCommunicatorManagerInterfaceImplForTest(appContext, mock(TaskHeartbeatHandler.class), mock(ContainerHeartbeatHandler.class), Lists.newArrayList(new NamedEntityDescriptor(TezConstants.getTezYarnServicePluginName(), null).setUserPayload(defaultPayload)));
    taskSpec = mock(TaskSpec.class);
    doReturn(taskAttemptID).when(taskSpec).getTaskAttemptID();
    amContainerTask = new AMContainerTask(taskSpec, null, null, false, 0);
    containerTask = null;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) UserPayload(org.apache.tez.dag.api.UserPayload) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) HashMap(java.util.HashMap) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) EventHandler(org.apache.hadoop.yarn.event.EventHandler) DAG(org.apache.tez.dag.app.dag.DAG) IOException(java.io.IOException) AMContainerMap(org.apache.tez.dag.app.rm.container.AMContainerMap) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) NamedEntityDescriptor(org.apache.tez.dag.api.NamedEntityDescriptor) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) Container(org.apache.hadoop.yarn.api.records.Container) ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) TezDAGID(org.apache.tez.dag.records.TezDAGID) NodeId(org.apache.hadoop.yarn.api.records.NodeId) AMContainerTask(org.apache.tez.dag.app.rm.container.AMContainerTask) Credentials(org.apache.hadoop.security.Credentials) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Before(org.junit.Before)

Example 53 with EventHandler

use of org.apache.hadoop.yarn.event.EventHandler in project tez by apache.

the class TestDAGImpl method _testTerminateRunningDAG.

@SuppressWarnings("unchecked")
private void _testTerminateRunningDAG(DAGTerminationCause terminationCause) {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    TezVertexID vId1 = TezVertexID.getInstance(dagId, 1);
    Vertex v1 = dag.getVertex(vId1);
    ((EventHandler<VertexEvent>) v1).handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId1, 0), TaskState.SUCCEEDED));
    TezVertexID vId0 = TezVertexID.getInstance(dagId, 0);
    Vertex v0 = dag.getVertex(vId0);
    ((EventHandler<VertexEvent>) v0).handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId0, 0), TaskState.SUCCEEDED));
    dispatcher.await();
    Assert.assertEquals(VertexState.SUCCEEDED, v0.getState());
    Assert.assertEquals(VertexState.RUNNING, v1.getState());
    dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, terminationCause, null));
    dispatcher.await();
    Assert.assertEquals(DAGState.TERMINATING, dag.getState());
    Assert.assertEquals(VertexState.SUCCEEDED, v0.getState());
    Assert.assertEquals(VertexState.TERMINATING, v1.getState());
    for (int i = 2; i < 6; ++i) {
        TezVertexID vId = TezVertexID.getInstance(dagId, i);
        Vertex v = dag.getVertex(vId);
        Assert.assertEquals(VertexState.KILLED, v.getState());
    }
    Assert.assertEquals(1, dag.getSuccessfulVertices());
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) EventHandler(org.apache.hadoop.yarn.event.EventHandler) HistoryEventHandler(org.apache.tez.dag.history.HistoryEventHandler) VertexEventTaskCompleted(org.apache.tez.dag.app.dag.event.VertexEventTaskCompleted) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) TezVertexID(org.apache.tez.dag.records.TezVertexID) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)

Example 54 with EventHandler

use of org.apache.hadoop.yarn.event.EventHandler in project tez by apache.

the class DrainDispatcher method getEventHandler.

@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;
            }
        }
    };
}
Also used : EventHandler(org.apache.hadoop.yarn.event.EventHandler) Event(org.apache.hadoop.yarn.event.Event)

Aggregations

EventHandler (org.apache.hadoop.yarn.event.EventHandler)54 Test (org.junit.Test)47 Event (org.apache.hadoop.yarn.event.Event)29 Configuration (org.apache.hadoop.conf.Configuration)20 HashMap (java.util.HashMap)13 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)13 TaskId (org.apache.hadoop.mapreduce.v2.api.records.TaskId)12 TaskAttemptEvent (org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent)12 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)9 ArrayList (java.util.ArrayList)8 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)8 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)8 JobHistoryEvent (org.apache.hadoop.mapreduce.jobhistory.JobHistoryEvent)7 TaskAttemptContainerLaunchedEvent (org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptContainerLaunchedEvent)7 TaskEvent (org.apache.hadoop.mapreduce.v2.app.job.event.TaskEvent)7 NodeId (org.apache.hadoop.yarn.api.records.NodeId)7 SystemClock (org.apache.hadoop.yarn.util.SystemClock)7 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)6 ContainerLauncherEvent (org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherEvent)6 DAG (org.apache.tez.dag.app.dag.DAG)6