Search in sources :

Example 1 with EdgePlan

use of org.apache.tez.dag.api.records.DAGProtos.EdgePlan in project tez by apache.

the class DAGImpl method createDAGEdges.

private void createDAGEdges(DAGImpl dag) throws TezException {
    for (EdgePlan edgePlan : dag.getJobPlan().getEdgeList()) {
        EdgeProperty edgeProperty = DagTypeConverters.createEdgePropertyMapFromDAGPlan(edgePlan);
        // edge manager may be also set via API when using custom edge type
        dag.edges.put(edgePlan.getId(), new Edge(edgeProperty, dag.getEventHandler(), dagConf));
    }
}
Also used : EdgeProperty(org.apache.tez.dag.api.EdgeProperty) EdgePlan(org.apache.tez.dag.api.records.DAGProtos.EdgePlan)

Example 2 with EdgePlan

use of org.apache.tez.dag.api.records.DAGProtos.EdgePlan 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 3 with EdgePlan

use of org.apache.tez.dag.api.records.DAGProtos.EdgePlan in project tez by apache.

the class TestDAGPlan method userVertexOrderingIsMaintained.

@Test(timeout = 5000)
public void userVertexOrderingIsMaintained() {
    DAG dag = DAG.create("testDag");
    ProcessorDescriptor pd1 = ProcessorDescriptor.create("processor1").setUserPayload(UserPayload.create(ByteBuffer.wrap("processor1Bytes".getBytes())));
    ProcessorDescriptor pd2 = ProcessorDescriptor.create("processor2").setUserPayload(UserPayload.create(ByteBuffer.wrap("processor2Bytes".getBytes())));
    ProcessorDescriptor pd3 = ProcessorDescriptor.create("processor3").setUserPayload(UserPayload.create(ByteBuffer.wrap("processor3Bytes".getBytes())));
    Vertex v1 = Vertex.create("v1", pd1, 10, Resource.newInstance(1024, 1));
    Vertex v2 = Vertex.create("v2", pd2, 1, Resource.newInstance(1024, 1));
    Vertex v3 = Vertex.create("v3", pd3, 1, Resource.newInstance(1024, 1));
    v1.setTaskLaunchCmdOpts("").setTaskEnvironment(new HashMap<String, String>()).addTaskLocalFiles(new HashMap<String, LocalResource>());
    v2.setTaskLaunchCmdOpts("").setTaskEnvironment(new HashMap<String, String>()).addTaskLocalFiles(new HashMap<String, LocalResource>());
    v3.setTaskLaunchCmdOpts("").setTaskEnvironment(new HashMap<String, String>()).addTaskLocalFiles(new HashMap<String, LocalResource>());
    InputDescriptor inputDescriptor = InputDescriptor.create("input").setUserPayload(UserPayload.create(ByteBuffer.wrap("inputBytes".getBytes())));
    OutputDescriptor outputDescriptor = OutputDescriptor.create("output").setUserPayload(UserPayload.create(ByteBuffer.wrap("outputBytes".getBytes())));
    Edge edge = Edge.create(v1, v2, EdgeProperty.create(DataMovementType.SCATTER_GATHER, DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL, outputDescriptor, inputDescriptor));
    dag.addVertex(v1).addVertex(v2).addEdge(edge).addVertex(v3);
    DAGPlan dagProto = dag.createDag(new TezConfiguration(), null, null, null, true);
    assertEquals(3, dagProto.getVertexCount());
    assertEquals(1, dagProto.getEdgeCount());
    VertexPlan v1Proto = dagProto.getVertex(0);
    VertexPlan v2Proto = dagProto.getVertex(1);
    VertexPlan v3Proto = dagProto.getVertex(2);
    EdgePlan edgeProto = dagProto.getEdge(0);
    // either v1 or v2 will be on top based on topological order
    String v1ProtoPayload = new String(v1Proto.getProcessorDescriptor().getTezUserPayload().getUserPayload().toByteArray());
    String v2ProtoPayload = new String(v2Proto.getProcessorDescriptor().getTezUserPayload().getUserPayload().toByteArray());
    assertTrue(v1ProtoPayload.equals("processor1Bytes") || v1ProtoPayload.equals("processor3Bytes"));
    assertTrue(v2ProtoPayload.equals("processor1Bytes") || v2ProtoPayload.equals("processor3Bytes"));
    assertTrue(v1Proto.getProcessorDescriptor().getClassName().equals("processor1") || v1Proto.getProcessorDescriptor().getClassName().equals("processor3"));
    assertTrue(v2Proto.getProcessorDescriptor().getClassName().equals("processor1") || v2Proto.getProcessorDescriptor().getClassName().equals("processor3"));
    assertEquals("processor2Bytes", new String(v3Proto.getProcessorDescriptor().getTezUserPayload().getUserPayload().toByteArray()));
    assertEquals("processor2", v3Proto.getProcessorDescriptor().getClassName());
    assertEquals("inputBytes", new String(edgeProto.getEdgeDestination().getTezUserPayload().getUserPayload().toByteArray()));
    assertEquals("input", edgeProto.getEdgeDestination().getClassName());
    assertEquals("outputBytes", new String(edgeProto.getEdgeSource().getTezUserPayload().getUserPayload().toByteArray()));
    assertEquals("output", edgeProto.getEdgeSource().getClassName());
    EdgeProperty edgeProperty = DagTypeConverters.createEdgePropertyMapFromDAGPlan(dagProto.getEdgeList().get(0));
    byte[] ib = edgeProperty.getEdgeDestination().getUserPayload().deepCopyAsArray();
    assertEquals("inputBytes", new String(ib));
    assertEquals("input", edgeProperty.getEdgeDestination().getClassName());
    byte[] ob = edgeProperty.getEdgeSource().getUserPayload().deepCopyAsArray();
    assertEquals("outputBytes", new String(ob));
    assertEquals("output", edgeProperty.getEdgeSource().getClassName());
}
Also used : HashMap(java.util.HashMap) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) DAGPlan(org.apache.tez.dag.api.records.DAGProtos.DAGPlan) VertexPlan(org.apache.tez.dag.api.records.DAGProtos.VertexPlan) EdgePlan(org.apache.tez.dag.api.records.DAGProtos.EdgePlan) Test(org.junit.Test)

Example 4 with EdgePlan

use of org.apache.tez.dag.api.records.DAGProtos.EdgePlan in project tez by apache.

the class TestVertexImpl method parseVertexEdges.

private void parseVertexEdges() {
    LOG.info("Parsing edges from dag plan, edgeCount=" + dagPlan.getEdgeCount());
    int vCnt = dagPlan.getVertexCount();
    Map<String, EdgePlan> edgePlans = DagTypeConverters.createEdgePlanMapFromDAGPlan(dagPlan.getEdgeList());
    // TODO - this test logic is tightly linked to impl DAGImpl code.
    for (int i = 0; i < vCnt; ++i) {
        VertexPlan vertexPlan = dagPlan.getVertex(i);
        Vertex vertex = vertices.get(vertexPlan.getName());
        Map<Vertex, Edge> inVertices = new HashMap<Vertex, Edge>();
        Map<Vertex, Edge> outVertices = new HashMap<Vertex, Edge>();
        for (String inEdgeId : vertexPlan.getInEdgeIdList()) {
            EdgePlan edgePlan = edgePlans.get(inEdgeId);
            Vertex inVertex = this.vertices.get(edgePlan.getInputVertexName());
            Edge edge = this.edges.get(inEdgeId);
            edge.setSourceVertex(inVertex);
            edge.setDestinationVertex(vertex);
            inVertices.put(inVertex, edge);
        }
        for (String outEdgeId : vertexPlan.getOutEdgeIdList()) {
            EdgePlan edgePlan = edgePlans.get(outEdgeId);
            Vertex outVertex = this.vertices.get(edgePlan.getOutputVertexName());
            Edge edge = this.edges.get(outEdgeId);
            edge.setSourceVertex(vertex);
            edge.setDestinationVertex(outVertex);
            outVertices.put(outVertex, edge);
        }
        LOG.info("Setting input vertices for vertex " + vertex.getName() + ", inputVerticesCnt=" + inVertices.size());
        vertex.setInputVertices(inVertices);
        LOG.info("Setting output vertices for vertex " + vertex.getName() + ", outputVerticesCnt=" + outVertices.size());
        vertex.setOutputVertices(outVertices);
    }
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) VertexPlan(org.apache.tez.dag.api.records.DAGProtos.VertexPlan) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint) EdgePlan(org.apache.tez.dag.api.records.DAGProtos.EdgePlan)

Example 5 with EdgePlan

use of org.apache.tez.dag.api.records.DAGProtos.EdgePlan in project tez by apache.

the class DAGImpl method initializeDAG.

DAGState initializeDAG() {
    commitAllOutputsOnSuccess = dagConf.getBoolean(TezConfiguration.TEZ_AM_COMMIT_ALL_OUTPUTS_ON_DAG_SUCCESS, TezConfiguration.TEZ_AM_COMMIT_ALL_OUTPUTS_ON_DAG_SUCCESS_DEFAULT);
    // If we have no vertices, fail the dag
    numVertices = getJobPlan().getVertexCount();
    if (numVertices == 0) {
        addDiagnostic("No vertices for dag");
        trySetTerminationCause(DAGTerminationCause.ZERO_VERTICES);
        return finished(DAGState.FAILED);
    }
    if (jobPlan.getVertexGroupsCount() > 0) {
        for (PlanVertexGroupInfo groupInfo : jobPlan.getVertexGroupsList()) {
            vertexGroups.put(groupInfo.getGroupName(), new VertexGroupInfo(groupInfo));
        }
        for (VertexGroupInfo groupInfo : vertexGroups.values()) {
            for (String vertexName : groupInfo.groupMembers) {
                List<VertexGroupInfo> groupList = vertexGroupInfo.get(vertexName);
                if (groupList == null) {
                    groupList = Lists.newLinkedList();
                    vertexGroupInfo.put(vertexName, groupList);
                }
                groupList.add(groupInfo);
            }
        }
    }
    // create the vertices`
    for (int i = 0; i < numVertices; ++i) {
        String vertexName = getJobPlan().getVertex(i).getName();
        VertexImpl v = createVertex(this, vertexName, i);
        addVertex(v);
    }
    // check task resources, only check it in non-local mode
    if (!appContext.isLocal()) {
        for (Vertex v : vertexMap.values()) {
            // TODO TEZ-2003 (post) TEZ-2624 Ideally, this should be per source.
            if (v.getTaskResource().compareTo(appContext.getClusterInfo().getMaxContainerCapability()) > 0) {
                String msg = "Vertex's TaskResource is beyond the cluster container capability," + "Vertex=" + v.getLogIdentifier() + ", Requested TaskResource=" + v.getTaskResource() + ", Cluster MaxContainerCapability=" + appContext.getClusterInfo().getMaxContainerCapability();
                LOG.error(msg);
                addDiagnostic(msg);
                finished(DAGState.FAILED);
                return DAGState.FAILED;
            }
        }
    }
    try {
        createDAGEdges(this);
    } catch (TezException e2) {
        String msg = "Fail to create edges, " + ExceptionUtils.getStackTrace(e2);
        addDiagnostic(msg);
        LOG.error(msg);
        trySetTerminationCause(DAGTerminationCause.INIT_FAILURE);
        finished(DAGState.FAILED);
        return DAGState.FAILED;
    }
    Map<String, EdgePlan> edgePlans = DagTypeConverters.createEdgePlanMapFromDAGPlan(getJobPlan().getEdgeList());
    // setup the dag
    for (Vertex v : vertices.values()) {
        parseVertexEdges(this, edgePlans, v);
    }
    computeVertexDescendants();
    // Initialize the edges, now that the payload and vertices have been set.
    for (Edge e : edges.values()) {
        try {
            e.initialize();
        } catch (AMUserCodeException ex) {
            String msg = "Exception in " + ex.getSource();
            LOG.error(msg, ex);
            addDiagnostic(msg + ", " + ex.getMessage() + ", " + ExceptionUtils.getStackTrace(ex.getCause()));
            finished(DAGState.FAILED);
            return DAGState.FAILED;
        }
    }
    try {
        assignDAGScheduler(this);
    } catch (TezException e1) {
        String msg = "Fail to assign DAGScheduler for dag:" + dagName + " due to " + ExceptionUtils.getStackTrace(e1);
        LOG.error(msg);
        addDiagnostic(msg);
        trySetTerminationCause(DAGTerminationCause.INIT_FAILURE);
        finished(DAGState.FAILED);
        return DAGState.FAILED;
    }
    for (Map.Entry<String, VertexGroupInfo> entry : vertexGroups.entrySet()) {
        String groupName = entry.getKey();
        VertexGroupInfo groupInfo = entry.getValue();
        if (!groupInfo.outputs.isEmpty()) {
            // shared outputs
            for (String vertexName : groupInfo.groupMembers) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Setting shared outputs for group: " + groupName + " on vertex: " + vertexName);
                }
                Vertex v = getVertex(vertexName);
                v.addSharedOutputs(groupInfo.outputs);
            }
        }
    }
    return DAGState.INITED;
}
Also used : TezException(org.apache.tez.dag.api.TezException) VertexEventRecoverVertex(org.apache.tez.dag.app.dag.event.VertexEventRecoverVertex) Vertex(org.apache.tez.dag.app.dag.Vertex) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) PlanVertexGroupInfo(org.apache.tez.dag.api.records.DAGProtos.PlanVertexGroupInfo) PlanVertexGroupInfo(org.apache.tez.dag.api.records.DAGProtos.PlanVertexGroupInfo) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) EdgePlan(org.apache.tez.dag.api.records.DAGProtos.EdgePlan)

Aggregations

EdgePlan (org.apache.tez.dag.api.records.DAGProtos.EdgePlan)7 HashMap (java.util.HashMap)6 VertexPlan (org.apache.tez.dag.api.records.DAGProtos.VertexPlan)4 Vertex (org.apache.tez.dag.app.dag.Vertex)4 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)3 ByteString (com.google.protobuf.ByteString)2 LinkedHashMap (java.util.LinkedHashMap)2 EdgeProperty (org.apache.tez.dag.api.EdgeProperty)2 VertexLocationHint (org.apache.tez.dag.api.VertexLocationHint)2 DAGPlan (org.apache.tez.dag.api.records.DAGProtos.DAGPlan)2 PlanVertexGroupInfo (org.apache.tez.dag.api.records.DAGProtos.PlanVertexGroupInfo)2 VertexEventRecoverVertex (org.apache.tez.dag.app.dag.event.VertexEventRecoverVertex)2 Test (org.junit.Test)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Credentials (org.apache.hadoop.security.Credentials)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 DrainDispatcher (org.apache.tez.common.DrainDispatcher)1