Search in sources :

Example 11 with Vertex

use of org.apache.tez.dag.app.dag.Vertex in project tez by apache.

the class TestVertexImpl method setupPostDagCreation.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setupPostDagCreation() throws TezException {
    String dagName = "dag0";
    // dispatcher may be created multiple times (setupPostDagCreation may be called multiples)
    if (dispatcher != null) {
        dispatcher.stop();
    }
    dispatcher = new DrainDispatcher();
    appContext = mock(AppContext.class);
    when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
    when(appContext.getContainerLauncherName(anyInt())).thenReturn(TezConstants.getTezYarnServicePluginName());
    thh = mock(TaskHeartbeatHandler.class);
    historyEventHandler = mock(HistoryEventHandler.class);
    TaskSchedulerManager taskScheduler = mock(TaskSchedulerManager.class);
    UserGroupInformation ugi;
    try {
        ugi = UserGroupInformation.getCurrentUser();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    DAG dag = mock(DAG.class);
    doReturn(ugi).when(dag).getDagUGI();
    doReturn(dagName).when(dag).getName();
    Map<String, LocalResource> localResources = new HashMap<>();
    for (PlanLocalResource planLR : dagPlan.getLocalResourceList()) {
        localResources.put(planLR.getName(), DagTypeConverters.convertPlanLocalResourceToLocalResource(planLR));
    }
    when(dag.getLocalResources()).thenReturn(localResources);
    doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(appContext).getApplicationID();
    doReturn(dag).when(appContext).getCurrentDAG();
    execService = mock(ListeningExecutorService.class);
    final ListenableFuture<Void> mockFuture = mock(ListenableFuture.class);
    Mockito.doAnswer(new Answer() {

        public ListenableFuture<Void> answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            CallableEvent e = (CallableEvent) args[0];
            dispatcher.getEventHandler().handle(e);
            return mockFuture;
        }
    }).when(execService).submit((Callable<Void>) any());
    MockClock clock = new MockClock();
    doReturn(execService).when(appContext).getExecService();
    doReturn(conf).when(appContext).getAMConf();
    doReturn(new Credentials()).when(dag).getCredentials();
    doReturn(DAGPlan.getDefaultInstance()).when(dag).getJobPlan();
    doReturn(dagId).when(appContext).getCurrentDAGID();
    doReturn(dagId).when(dag).getID();
    doReturn(taskScheduler).when(appContext).getTaskScheduler();
    doReturn(Resource.newInstance(102400, 60)).when(taskScheduler).getTotalResources(0);
    doReturn(historyEventHandler).when(appContext).getHistoryHandler();
    doReturn(dispatcher.getEventHandler()).when(appContext).getEventHandler();
    doReturn(clock).when(appContext).getClock();
    vertexGroups = Maps.newHashMap();
    for (PlanVertexGroupInfo groupInfo : dagPlan.getVertexGroupsList()) {
        vertexGroups.put(groupInfo.getGroupName(), new VertexGroupInfo(groupInfo));
    }
    // updateTracker may be created multiple times (setupPostDagCreation may be called multiples)
    if (updateTracker != null) {
        updateTracker.stop();
    }
    updateTracker = new StateChangeNotifierForTest(appContext.getCurrentDAG());
    setupVertices();
    when(dag.getVertex(any(TezVertexID.class))).thenAnswer(new Answer<Vertex>() {

        @Override
        public Vertex answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            if (args.length != 1) {
                return null;
            }
            TezVertexID vId = (TezVertexID) args[0];
            return vertexIdMap.get(vId);
        }
    });
    when(dag.getVertex(any(String.class))).thenAnswer(new Answer<Vertex>() {

        @Override
        public Vertex answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            if (args.length != 1) {
                return null;
            }
            String vId = (String) args[0];
            return vertices.get(vId);
        }
    });
    // TODO - this test logic is tightly linked to impl DAGImpl code.
    edges = new HashMap<String, Edge>();
    for (EdgePlan edgePlan : dagPlan.getEdgeList()) {
        EdgeProperty edgeProperty = DagTypeConverters.createEdgePropertyMapFromDAGPlan(edgePlan);
        edges.put(edgePlan.getId(), new Edge(edgeProperty, dispatcher.getEventHandler(), conf));
    }
    parseVertexEdges();
    for (Edge edge : edges.values()) {
        edge.initialize();
    }
    dispatcher.register(CallableEventType.class, new CallableEventDispatcher());
    taskAttemptEventDispatcher = new TaskAttemptEventDispatcher();
    dispatcher.register(TaskAttemptEventType.class, taskAttemptEventDispatcher);
    taskEventDispatcher = new TaskEventDispatcher();
    dispatcher.register(TaskEventType.class, taskEventDispatcher);
    vertexEventDispatcher = new VertexEventDispatcher();
    dispatcher.register(VertexEventType.class, vertexEventDispatcher);
    dagEventDispatcher = new DagEventDispatcher();
    dispatcher.register(DAGEventType.class, dagEventDispatcher);
    amSchedulerEventDispatcher = new AMSchedulerEventDispatcher();
    dispatcher.register(AMSchedulerEventType.class, amSchedulerEventDispatcher);
    dispatcher.init(conf);
    dispatcher.start();
}
Also used : DrainDispatcher(org.apache.tez.common.DrainDispatcher) Vertex(org.apache.tez.dag.app.dag.Vertex) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) DefaultHadoopShim(org.apache.tez.hadoop.shim.DefaultHadoopShim) HistoryEventHandler(org.apache.tez.dag.history.HistoryEventHandler) CallableEvent(org.apache.tez.dag.app.dag.event.CallableEvent) PlanVertexGroupInfo(org.apache.tez.dag.api.records.DAGProtos.PlanVertexGroupInfo) StateChangeNotifierForTest(org.apache.tez.dag.app.dag.TestStateChangeNotifier.StateChangeNotifierForTest) PlanVertexGroupInfo(org.apache.tez.dag.api.records.DAGProtos.PlanVertexGroupInfo) VertexGroupInfo(org.apache.tez.dag.app.dag.impl.DAGImpl.VertexGroupInfo) TaskHeartbeatHandler(org.apache.tez.dag.app.TaskHeartbeatHandler) TezVertexID(org.apache.tez.dag.records.TezVertexID) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AppContext(org.apache.tez.dag.app.AppContext) IOException(java.io.IOException) DAG(org.apache.tez.dag.app.dag.DAG) PlanLocalResource(org.apache.tez.dag.api.records.DAGProtos.PlanLocalResource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) Answer(org.mockito.stubbing.Answer) PlanLocalResource(org.apache.tez.dag.api.records.DAGProtos.PlanLocalResource) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TaskSchedulerManager(org.apache.tez.dag.app.rm.TaskSchedulerManager) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) EdgeProperty(org.apache.tez.dag.api.EdgeProperty) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MockClock(org.apache.tez.dag.app.MockClock) Credentials(org.apache.hadoop.security.Credentials) EdgePlan(org.apache.tez.dag.api.records.DAGProtos.EdgePlan)

Example 12 with Vertex

use of org.apache.tez.dag.app.dag.Vertex in project tez by apache.

the class TestDAGSchedulerNaturalOrderControlled method createMockDag.

// Test parallelism updated form -1
// Reduce parallelism
// Different attempts scheduled for a single task.
private DAG createMockDag() {
    DAG dag = mock(DAG.class);
    /*
    v0             v1
      \            /
       \          /
        v2       v3
         \      /
          \    /
           \  /
            v4
     v0 - Root
     v1 - Root with 0 tasks.
     v2 - can simulate AutoReduce. Parallelism goes down. Slow schedule.
     v3 - can simulate ImmediateStart
     v4 - Simulate one shuffle input, one broadcast input.
     */
    int numVertices = 5;
    Vertex[] vertices = new Vertex[numVertices];
    vertices[0] = createMockVertex("vertex0", 0, 10, 0);
    vertices[1] = createMockVertex("vertex1", 1, 0, 0);
    vertices[2] = createMockVertex("vertex2", 2, 10, 1);
    vertices[3] = createMockVertex("vertex3", 3, 10, 1);
    vertices[4] = createMockVertex("vertex4", 4, 10, 2);
    for (int i = 0; i < numVertices; i++) {
        String name = vertices[i].getName();
        TezVertexID vertexId = vertices[i].getVertexId();
        doReturn(vertices[i]).when(dag).getVertex(name);
        doReturn(vertices[i]).when(dag).getVertex(vertexId);
    }
    updateMockVertexWithConnections(vertices[0], createConnectionMap((Vertex[]) null), createConnectionMap(vertices[2]));
    updateMockVertexWithConnections(vertices[1], createConnectionMap((Vertex[]) null), createConnectionMap(vertices[3]));
    updateMockVertexWithConnections(vertices[2], createConnectionMap(vertices[0]), createConnectionMap(vertices[4]));
    updateMockVertexWithConnections(vertices[3], createConnectionMap(vertices[1]), createConnectionMap(vertices[4]));
    updateMockVertexWithConnections(vertices[4], createConnectionMap(vertices[2], vertices[3]), createConnectionMap((Vertex[]) null));
    return dag;
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) DAG(org.apache.tez.dag.app.dag.DAG) TezVertexID(org.apache.tez.dag.records.TezVertexID)

Example 13 with Vertex

use of org.apache.tez.dag.app.dag.Vertex in project tez by apache.

the class TestDAGSchedulerNaturalOrderControlled method testParallelismUpdated.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testParallelismUpdated() {
    EventHandler eventHandler = mock(EventHandler.class);
    DAG dag = createMockDag();
    DAGSchedulerNaturalOrderControlled dagScheduler = new DAGSchedulerNaturalOrderControlled(dag, eventHandler);
    int numVertices = 5;
    Vertex[] vertices = new Vertex[numVertices];
    for (int i = 0; i < numVertices; i++) {
        vertices[i] = dag.getVertex("vertex" + i);
    }
    // Schedule all tasks belonging to v0
    for (int i = 0; i < vertices[0].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[0].getVertexId(), i, 0));
    }
    verify(eventHandler, times(vertices[0].getTotalTasks())).handle(any(Event.class));
    reset(eventHandler);
    assertEquals(10, vertices[2].getTotalTasks());
    // Schedule all tasks belonging to v3
    for (int i = 0; i < vertices[3].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[3].getVertexId(), i, 0));
    }
    verify(eventHandler, times(vertices[3].getTotalTasks())).handle(any(Event.class));
    reset(eventHandler);
    // Schedule all tasks belonging to v4
    for (int i = 0; i < vertices[4].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[4].getVertexId(), i, 0));
    }
    verify(eventHandler, never()).handle(any(Event.class));
    reset(eventHandler);
    // Reset the parallelism for v2.
    updateParallelismOnMockVertex(vertices[2], 3);
    assertEquals(3, vertices[2].getTotalTasks());
    // Schedule all tasks belonging to v2
    for (int i = 0; i < vertices[2].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[2].getVertexId(), i, 0));
    }
    verify(eventHandler, times(vertices[2].getTotalTasks() + vertices[4].getTotalTasks())).handle(any(Event.class));
    reset(eventHandler);
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) EventHandler(org.apache.hadoop.yarn.event.EventHandler) Event(org.apache.hadoop.yarn.event.Event) DAG(org.apache.tez.dag.app.dag.DAG) Test(org.junit.Test)

Example 14 with Vertex

use of org.apache.tez.dag.app.dag.Vertex in project tez by apache.

the class TestDAGSchedulerNaturalOrderControlled method createMockVertex.

private Vertex createMockVertex(String name, int vertexIdInt, int totalTasks, int distanceFromRoot) {
    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexId = TezVertexID.getInstance(dagId, vertexIdInt);
    Vertex vertex = mock(Vertex.class);
    doReturn(name).when(vertex).getName();
    doReturn(totalTasks).when(vertex).getTotalTasks();
    doReturn(vertexId).when(vertex).getVertexId();
    doReturn(distanceFromRoot).when(vertex).getDistanceFromRoot();
    doReturn(vertexId + " [" + name + "]").when(vertex).getLogIdentifier();
    return vertex;
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) TezDAGID(org.apache.tez.dag.records.TezDAGID) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) TezVertexID(org.apache.tez.dag.records.TezVertexID)

Example 15 with Vertex

use of org.apache.tez.dag.app.dag.Vertex in project tez by apache.

the class TestDAGSchedulerNaturalOrderControlled method testSourceRequestDelayed.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testSourceRequestDelayed() {
    // ShuffleVertexHandler - slowstart simulation
    EventHandler eventHandler = mock(EventHandler.class);
    DAG dag = createMockDag();
    DAGSchedulerNaturalOrderControlled dagScheduler = new DAGSchedulerNaturalOrderControlled(dag, eventHandler);
    int numVertices = 5;
    Vertex[] vertices = new Vertex[numVertices];
    for (int i = 0; i < numVertices; i++) {
        vertices[i] = dag.getVertex("vertex" + i);
    }
    // Schedule all tasks belonging to v0
    for (int i = 0; i < vertices[0].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[0].getVertexId(), i, 0));
    }
    verify(eventHandler, times(vertices[0].getTotalTasks())).handle(any(Event.class));
    reset(eventHandler);
    // Schedule all tasks belonging to v3.
    for (int i = 0; i < vertices[3].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[3].getVertexId(), i, 0));
    }
    verify(eventHandler, times(vertices[3].getTotalTasks())).handle(any(Event.class));
    reset(eventHandler);
    // Scheduling all tasks belonging to v4. None should get scheduled.
    for (int i = 0; i < vertices[4].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[4].getVertexId(), i, 0));
    }
    verify(eventHandler, never()).handle(any(Event.class));
    reset(eventHandler);
    // Schedule 3 tasks for v2 initially.
    for (int i = 0; i < 3; i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[2].getVertexId(), i, 0));
    }
    verify(eventHandler, times(3)).handle(any(Event.class));
    reset(eventHandler);
    // Schedule remaining tasks belonging to v2
    for (int i = 3; i < vertices[2].getTotalTasks(); i++) {
        dagScheduler.scheduleTaskEx(createScheduleRequest(vertices[2].getVertexId(), i, 0));
    }
    ArgumentCaptor<Event> args = ArgumentCaptor.forClass(Event.class);
    // All of v2 and v3 should be sent out.
    verify(eventHandler, times(vertices[2].getTotalTasks() - 3 + vertices[4].getTotalTasks())).handle(args.capture());
    int count = 0;
    // Verify the order in which the events were sent out.
    for (Event raw : args.getAllValues()) {
        TaskAttemptEventSchedule event = (TaskAttemptEventSchedule) raw;
        if (count < vertices[2].getTotalTasks() - 3) {
            assertEquals(2, event.getTaskAttemptID().getTaskID().getVertexID().getId());
        } else {
            assertEquals(4, event.getTaskAttemptID().getTaskID().getVertexID().getId());
        }
        count++;
    }
    reset(eventHandler);
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) EventHandler(org.apache.hadoop.yarn.event.EventHandler) Event(org.apache.hadoop.yarn.event.Event) DAG(org.apache.tez.dag.app.dag.DAG) TaskAttemptEventSchedule(org.apache.tez.dag.app.dag.event.TaskAttemptEventSchedule) Test(org.junit.Test)

Aggregations

Vertex (org.apache.tez.dag.app.dag.Vertex)80 Test (org.junit.Test)31 TezVertexID (org.apache.tez.dag.records.TezVertexID)23 DAG (org.apache.tez.dag.app.dag.DAG)22 VertexEventRecoverVertex (org.apache.tez.dag.app.dag.event.VertexEventRecoverVertex)17 HashMap (java.util.HashMap)15 StateChangeNotifierForTest (org.apache.tez.dag.app.dag.TestStateChangeNotifier.StateChangeNotifierForTest)15 PlanTaskLocationHint (org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)13 Map (java.util.Map)12 TezTaskID (org.apache.tez.dag.records.TezTaskID)11 VertexEventTaskCompleted (org.apache.tez.dag.app.dag.event.VertexEventTaskCompleted)9 LinkedHashMap (java.util.LinkedHashMap)8 VertexLocationHint (org.apache.tez.dag.api.VertexLocationHint)8 ArrayList (java.util.ArrayList)7 EventHandler (org.apache.hadoop.yarn.event.EventHandler)7 Task (org.apache.tez.dag.app.dag.Task)7 EdgeProperty (org.apache.tez.dag.api.EdgeProperty)6 TaskAttemptEventSchedule (org.apache.tez.dag.app.dag.event.TaskAttemptEventSchedule)6 OutputCommitter (org.apache.tez.runtime.api.OutputCommitter)6 TreeMap (java.util.TreeMap)5