Search in sources :

Example 1 with DAGEventTerminateDag

use of org.apache.tez.dag.app.dag.event.DAGEventTerminateDag in project tez by apache.

the class TestDAGImpl method _testDAGKillPending.

// Vertex KILLED after a DAG_KILLED is issued. Termination reason should be DAG_KILLED
@SuppressWarnings("unchecked")
private void _testDAGKillPending(DAGTerminationCause terminationCause) {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 0), VertexState.SUCCEEDED));
    dispatcher.await();
    Assert.assertEquals(DAGState.RUNNING, dag.getState());
    dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 1), VertexState.SUCCEEDED));
    for (int i = 2; i < 5; ++i) {
        dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, i), VertexState.SUCCEEDED));
    }
    dispatcher.await();
    dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, terminationCause, null));
    dispatcher.await();
    Assert.assertEquals(terminationCause.getFinishedState(), dag.getState());
    dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 5), VertexState.KILLED));
    dispatcher.await();
    Assert.assertEquals(terminationCause.getFinishedState(), dag.getState());
    Assert.assertEquals(5, dag.getSuccessfulVertices());
    Assert.assertEquals(dag.getVertex(TezVertexID.getInstance(dagId, 5)).getTerminationCause(), VertexTerminationCause.DAG_TERMINATED);
    Assert.assertEquals(1, dagFinishEventHandler.dagFinishEvents);
}
Also used : DAGEventVertexCompleted(org.apache.tez.dag.app.dag.event.DAGEventVertexCompleted) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)

Example 2 with DAGEventTerminateDag

use of org.apache.tez.dag.app.dag.event.DAGEventTerminateDag in project tez by apache.

the class TestDAGImpl method runTestGetDAGStatusReturnOnDagFinished.

@SuppressWarnings("unchecked")
public void runTestGetDAGStatusReturnOnDagFinished(DAGStatusBuilder.State testState) throws TezException, InterruptedException {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    // All vertices except one succeed
    for (int i = 0; i < dag.getVertices().size() - 1; ++i) {
        dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 0), VertexState.SUCCEEDED));
    }
    dispatcher.await();
    Assert.assertEquals(DAGState.RUNNING, dag.getState());
    Assert.assertEquals(5, dag.getSuccessfulVertices());
    ReentrantLock lock = new ReentrantLock();
    Condition startCondition = lock.newCondition();
    Condition endCondition = lock.newCondition();
    DagStatusCheckRunnable statusCheckRunnable = new DagStatusCheckRunnable(lock, startCondition, endCondition);
    Thread t1 = new Thread(statusCheckRunnable);
    t1.start();
    lock.lock();
    try {
        while (!statusCheckRunnable.started.get()) {
            startCondition.await();
        }
    } finally {
        lock.unlock();
    }
    // Sleep for 2 seconds. Then mark the last vertex is successful.
    Thread.sleep(2000l);
    if (testState == DAGStatus.State.SUCCEEDED) {
        dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 5), VertexState.SUCCEEDED));
    } else if (testState == DAGStatus.State.FAILED) {
        dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 5), VertexState.FAILED));
    } else if (testState == DAGStatus.State.KILLED) {
        dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, DAGTerminationCause.DAG_KILL, null));
    } else if (testState == DAGStatus.State.ERROR) {
        dispatcher.getEventHandler().handle(new DAGEventStartDag(dagId, new LinkedList<URL>()));
    } else {
        throw new UnsupportedOperationException("Unsupported state for test: " + testState);
    }
    dispatcher.await();
    // Wait for the dag status to return
    lock.lock();
    try {
        while (!statusCheckRunnable.ended.get()) {
            endCondition.await();
        }
    } finally {
        lock.unlock();
    }
    long diff = statusCheckRunnable.dagStatusEndTime - statusCheckRunnable.dagStatusStartTime;
    Assert.assertNotNull(statusCheckRunnable.dagStatus);
    Assert.assertTrue(diff > 1000 && diff < 3500);
    Assert.assertEquals(testState, statusCheckRunnable.dagStatus.getState());
    t1.join();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) DAGEventStartDag(org.apache.tez.dag.app.dag.event.DAGEventStartDag) DAGEventVertexCompleted(org.apache.tez.dag.app.dag.event.DAGEventVertexCompleted) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint) URL(java.net.URL)

Example 3 with DAGEventTerminateDag

use of org.apache.tez.dag.app.dag.event.DAGEventTerminateDag in project tez by apache.

the class TestDAGImpl method _testDAGKillVertexSuccessAfterTerminated.

// Vertices succeed after a DAG kill has been processed. Should be ignored.
@SuppressWarnings("unchecked")
private void _testDAGKillVertexSuccessAfterTerminated(DAGTerminationCause terminationCause) {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 0), VertexState.SUCCEEDED));
    dispatcher.await();
    Assert.assertEquals(DAGState.RUNNING, dag.getState());
    dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, 1), VertexState.SUCCEEDED));
    dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, terminationCause, null));
    dispatcher.await();
    Assert.assertEquals(terminationCause.getFinishedState(), dag.getState());
    // Vertex SUCCESS gets processed after the DAG has reached the KILLED state. Should be ignored.
    for (int i = 2; i < 6; ++i) {
        dispatcher.getEventHandler().handle(new DAGEventVertexCompleted(TezVertexID.getInstance(dagId, i), VertexState.SUCCEEDED));
    }
    dispatcher.await();
    int killedCount = 0;
    for (Map.Entry<TezVertexID, Vertex> vEntry : dag.getVertices().entrySet()) {
        if (vEntry.getValue().getState() == VertexState.KILLED) {
            killedCount++;
        }
    }
    Assert.assertEquals(4, killedCount);
    Assert.assertEquals(terminationCause, dag.getTerminationCause());
    Assert.assertEquals(2, dag.getSuccessfulVertices());
    for (Vertex v : dag.getVertices().values()) {
        Assert.assertEquals(VertexTerminationCause.DAG_TERMINATED, v.getTerminationCause());
    }
    Assert.assertEquals(1, dagFinishEventHandler.dagFinishEvents);
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) DAGEventVertexCompleted(org.apache.tez.dag.app.dag.event.DAGEventVertexCompleted) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) Map(java.util.Map) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint) TezVertexID(org.apache.tez.dag.records.TezVertexID)

Example 4 with DAGEventTerminateDag

use of org.apache.tez.dag.app.dag.event.DAGEventTerminateDag in project tez by apache.

the class TestContainerLauncherManager method testReportFailureFromContainerLauncher.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testReportFailureFromContainerLauncher() throws ServicePluginException, TezException {
    final String dagName = DAG_NAME;
    final int dagIndex = DAG_INDEX;
    TezDAGID dagId = TezDAGID.getInstance(ApplicationId.newInstance(0, 0), dagIndex);
    DAG dag = mock(DAG.class);
    doReturn(dagName).when(dag).getName();
    doReturn(dagId).when(dag).getID();
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class);
    doReturn(eventHandler).when(appContext).getEventHandler();
    doReturn(dag).when(appContext).getCurrentDAG();
    doReturn("testlauncher").when(appContext).getContainerLauncherName(0);
    NamedEntityDescriptor<TaskCommunicatorDescriptor> taskCommDescriptor = new NamedEntityDescriptor<>("testlauncher", ContainerLauncherForTest.class.getName());
    List<NamedEntityDescriptor> list = new LinkedList<>();
    list.add(taskCommDescriptor);
    ContainerLauncherManager containerLauncherManager = new ContainerLauncherManager(appContext, mock(TaskCommunicatorManagerInterface.class), "", list, false);
    try {
        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.getDiagnosticInfo().contains("ReportedFatalError"));
        assertTrue(event.getDiagnosticInfo().contains(ServicePluginErrorDefaults.INCONSISTENT_STATE.name()));
        assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
        reset(eventHandler);
        // stop container
        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 DAGEventTerminateDag);
        DAGEventTerminateDag killEvent = (DAGEventTerminateDag) rawEvent;
        assertTrue(killEvent.getDiagnosticInfo().contains("ReportError"));
        assertTrue(killEvent.getDiagnosticInfo().contains(ServicePluginErrorDefaults.SERVICE_UNAVAILABLE.name()));
        assertTrue(killEvent.getDiagnosticInfo().contains("[0:testlauncher]"));
    } finally {
        containerLauncherManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) AppContext(org.apache.tez.dag.app.AppContext) EventHandler(org.apache.hadoop.yarn.event.EventHandler) DAG(org.apache.tez.dag.app.dag.DAG) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) TaskCommunicatorManagerInterface(org.apache.tez.dag.app.TaskCommunicatorManagerInterface) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) NamedEntityDescriptor(org.apache.tez.dag.api.NamedEntityDescriptor) LinkedList(java.util.LinkedList) ContainerLauncherLaunchRequestEvent(org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent) TaskCommunicatorDescriptor(org.apache.tez.serviceplugins.api.TaskCommunicatorDescriptor) Container(org.apache.hadoop.yarn.api.records.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) TezDAGID(org.apache.tez.dag.records.TezDAGID) 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 5 with DAGEventTerminateDag

use of org.apache.tez.dag.app.dag.event.DAGEventTerminateDag in project tez by apache.

the class TestDAGImpl method testKillStartedDAG.

@SuppressWarnings("unchecked")
public void testKillStartedDAG() {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, DAGTerminationCause.DAG_KILL, null));
    dispatcher.await();
    Assert.assertEquals(DAGState.KILLED, dag.getState());
    for (int i = 0; i < 6; ++i) {
        TezVertexID vId = TezVertexID.getInstance(dagId, i);
        Vertex v = dag.getVertex(vId);
        Assert.assertEquals(VertexState.KILLED, v.getState());
    }
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint) TezVertexID(org.apache.tez.dag.records.TezVertexID)

Aggregations

DAGEventTerminateDag (org.apache.tez.dag.app.dag.event.DAGEventTerminateDag)15 PlanTaskLocationHint (org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)6 VertexEventTaskCompleted (org.apache.tez.dag.app.dag.event.VertexEventTaskCompleted)6 EventHandler (org.apache.hadoop.yarn.event.EventHandler)4 DAG (org.apache.tez.dag.app.dag.DAG)4 Vertex (org.apache.tez.dag.app.dag.Vertex)4 DAGEventVertexCompleted (org.apache.tez.dag.app.dag.event.DAGEventVertexCompleted)4 TezDAGID (org.apache.tez.dag.records.TezDAGID)4 TezVertexID (org.apache.tez.dag.records.TezVertexID)4 Test (org.junit.Test)4 LinkedList (java.util.LinkedList)3 Event (org.apache.hadoop.yarn.event.Event)3 NamedEntityDescriptor (org.apache.tez.dag.api.NamedEntityDescriptor)3 DAGAppMasterEventUserServiceFatalError (org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError)3 DagInfoImplForTest (org.apache.tez.dag.helpers.DagInfoImplForTest)3 Map (java.util.Map)2 Configuration (org.apache.hadoop.conf.Configuration)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 AppContext (org.apache.tez.dag.app.AppContext)2 TaskCommunicatorDescriptor (org.apache.tez.serviceplugins.api.TaskCommunicatorDescriptor)2