You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tez.apache.org by bi...@apache.org on 2014/01/12 21:04:18 UTC

[1/2] TEZ-582. Refactor and abstract out VertexManager to enable users to plugin their own logic (bikas)

Updated Branches:
  refs/heads/master d3e98876d -> fb9488cd5


http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexManager.java b/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexManager.java
deleted file mode 100644
index 916bf27..0000000
--- a/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexManager.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tez.dag.app.dag.impl;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.yarn.event.EventHandler;
-import org.apache.tez.dag.api.EdgeProperty;
-import org.apache.tez.dag.api.InputDescriptor;
-import org.apache.tez.dag.api.OutputDescriptor;
-import org.apache.tez.dag.api.TezConfiguration;
-import org.apache.tez.dag.api.TezUncheckedException;
-import org.apache.tez.dag.api.EdgeProperty.SchedulingType;
-import org.apache.tez.dag.app.dag.EdgeManager;
-import org.apache.tez.dag.app.dag.Task;
-import org.apache.tez.dag.app.dag.Vertex;
-import org.apache.tez.dag.records.TezDAGID;
-import org.apache.tez.dag.records.TezTaskAttemptID;
-import org.apache.tez.dag.records.TezTaskID;
-import org.apache.tez.dag.records.TezVertexID;
-import org.apache.tez.runtime.api.events.DataMovementEvent;
-import org.apache.tez.runtime.api.events.VertexManagerEvent;
-import org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.VertexManagerEventPayloadProto;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import com.google.common.collect.Lists;
-
-import static org.mockito.Mockito.*;
-
-public class TestVertexManager {
-
-  @SuppressWarnings({ "unchecked", "rawtypes" })
-  @Test(timeout = 5000)
-  public void testShuffleVertexManagerAutoParallelism() throws IOException {
-    Configuration conf = new Configuration();
-    conf.setBoolean(
-        TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL,
-        true);
-    conf.setLong(TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE, 1000L);
-    ShuffleVertexManager manager = null;
-    EventHandler mockEventHandler = mock(EventHandler.class);
-    TezDAGID dagId = TezDAGID.getInstance("1", 1, 1);
-    HashMap<Vertex, Edge> mockInputVertices = 
-        new HashMap<Vertex, Edge>();
-    Vertex mockSrcVertex1 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId1 = TezVertexID.getInstance(dagId, 1);
-    EdgeProperty eProp1 = new EdgeProperty(
-        EdgeProperty.DataMovementType.SCATTER_GATHER,
-        EdgeProperty.DataSourceType.PERSISTED,
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex1.getVertexId()).thenReturn(mockSrcVertexId1);
-    Vertex mockSrcVertex2 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId2 = TezVertexID.getInstance(dagId, 2);
-    EdgeProperty eProp2 = new EdgeProperty(
-        EdgeProperty.DataMovementType.SCATTER_GATHER,
-        EdgeProperty.DataSourceType.PERSISTED,
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex2.getVertexId()).thenReturn(mockSrcVertexId2);
-    Vertex mockSrcVertex3 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId3 = TezVertexID.getInstance(dagId, 3);
-    EdgeProperty eProp3 = new EdgeProperty(
-        EdgeProperty.DataMovementType.BROADCAST,
-        EdgeProperty.DataSourceType.PERSISTED, 
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex3.getVertexId()).thenReturn(mockSrcVertexId3);
-    
-    Vertex mockManagedVertex = mock(Vertex.class);
-    TezVertexID mockManagedVertexId = TezVertexID.getInstance(dagId, 4);
-    when(mockManagedVertex.getVertexId()).thenReturn(mockManagedVertexId);
-    when(mockManagedVertex.getInputVertices()).thenReturn(mockInputVertices);
-    
-    mockInputVertices.put(mockSrcVertex1, new Edge(eProp1, mockEventHandler));
-    mockInputVertices.put(mockSrcVertex2, new Edge(eProp2, mockEventHandler));
-    mockInputVertices.put(mockSrcVertex3, new Edge(eProp3, mockEventHandler));
-
-    // check initialization
-    manager = createManager(conf, mockManagedVertex, 0.1f, 0.1f);
-    Assert.assertTrue(manager.bipartiteSources.size() == 2);
-    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId1));
-    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId2));
-    
-    final HashMap<TezTaskID, Task> managedTasks = new HashMap<TezTaskID, Task>();
-    final TezTaskID mockTaskId1 = TezTaskID.getInstance(mockManagedVertexId, 0);
-    managedTasks.put(mockTaskId1, null);
-    final TezTaskID mockTaskId2 = TezTaskID.getInstance(mockManagedVertexId, 1);
-    managedTasks.put(mockTaskId2, null);
-    final TezTaskID mockTaskId3 = TezTaskID.getInstance(mockManagedVertexId, 2);
-    managedTasks.put(mockTaskId3, null);
-    final TezTaskID mockTaskId4 = TezTaskID.getInstance(mockManagedVertexId, 3);
-    managedTasks.put(mockTaskId4, null);
-    
-    when(mockManagedVertex.getTotalTasks()).thenReturn(managedTasks.size());
-    when(mockManagedVertex.getTasks()).thenReturn(managedTasks);
-    
-    final HashSet<TezTaskID> scheduledTasks = new HashSet<TezTaskID>();
-    doAnswer(new Answer() {
-      public Object answer(InvocationOnMock invocation) {
-          Object[] args = invocation.getArguments();
-          scheduledTasks.clear();
-          scheduledTasks.addAll((Collection<TezTaskID>)args[0]); 
-          return null;
-      }}).when(mockManagedVertex).scheduleTasks(anyCollection());
-    
-    final Map<Vertex, EdgeManager> newEdgeManagers = new HashMap<Vertex, EdgeManager>();
-    
-    doAnswer(new Answer() {
-      public Object answer(InvocationOnMock invocation) {
-          managedTasks.remove(mockTaskId3);
-          managedTasks.remove(mockTaskId4);
-          newEdgeManagers.clear();
-          newEdgeManagers.putAll((Map<Vertex, EdgeManager>)invocation.getArguments()[1]);
-          return null;
-      }}).when(mockManagedVertex).setParallelism(eq(2), anyMap());
-    
-    // source vertices have 0 tasks. immediate start of all managed tasks
-    when(mockSrcVertex1.getTotalTasks()).thenReturn(0);
-    when(mockSrcVertex2.getTotalTasks()).thenReturn(0);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 4); // all tasks scheduled
-    scheduledTasks.clear();
-    
-    when(mockSrcVertex1.getTotalTasks()).thenReturn(2);
-    when(mockSrcVertex2.getTotalTasks()).thenReturn(2);
-
-    TezTaskAttemptID mockSrcAttemptId11 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId1, 0), 0);
-    TezTaskAttemptID mockSrcAttemptId12 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId1, 1), 0);
-    TezTaskAttemptID mockSrcAttemptId21 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId2, 0), 0);
-    TezTaskAttemptID mockSrcAttemptId31 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId3, 0), 0);
-
-    byte[] payload =
-        VertexManagerEventPayloadProto.newBuilder().setOutputSize(5000L).build().toByteArray();
-    VertexManagerEvent vmEvent = new VertexManagerEvent("Vertex", payload);
-    // parallelism not change due to large data size
-    manager = createManager(conf, mockManagedVertex, 0.1f, 0.1f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 4); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    manager.onVertexManagerEventReceived(vmEvent);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    // managedVertex tasks reduced
-    verify(mockManagedVertex, times(0)).setParallelism(anyInt(), anyMap());
-    Assert.assertEquals(0, manager.pendingTasks.size()); // all tasks scheduled
-    Assert.assertEquals(4, scheduledTasks.size());
-    Assert.assertEquals(1, manager.numSourceTasksCompleted); // TODO
-    Assert.assertEquals(5000L, manager.completedSourceTasksOutputSize);
-    
-    
-    // parallelism changed due to small data size
-    scheduledTasks.clear();
-    payload =
-        VertexManagerEventPayloadProto.newBuilder().setOutputSize(500L).build().toByteArray();
-    vmEvent = new VertexManagerEvent("Vertex", payload);
-    
-    manager = createManager(conf, mockManagedVertex, 0.5f, 0.5f);
-    manager.onVertexStarted(null);
-    Assert.assertEquals(4, manager.pendingTasks.size()); // no tasks scheduled
-    Assert.assertEquals(4, manager.numSourceTasks);
-    // task completion from non-bipartite stage does nothing
-    manager.onSourceTaskCompleted(mockSrcAttemptId31);
-    Assert.assertEquals(4, manager.pendingTasks.size()); // no tasks scheduled
-    Assert.assertEquals(4, manager.numSourceTasks);
-    Assert.assertEquals(0, manager.numSourceTasksCompleted);
-    manager.onVertexManagerEventReceived(vmEvent);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    Assert.assertEquals(4, manager.pendingTasks.size());
-    Assert.assertEquals(0, scheduledTasks.size()); // no tasks scheduled
-    Assert.assertEquals(1, manager.numSourceTasksCompleted);
-    Assert.assertEquals(1, manager.numVertexManagerEventsReceived);
-    Assert.assertEquals(500L, manager.completedSourceTasksOutputSize);
-    // ignore duplicate completion
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    Assert.assertEquals(4, manager.pendingTasks.size());
-    Assert.assertEquals(0, scheduledTasks.size()); // no tasks scheduled
-    Assert.assertEquals(1, manager.numSourceTasksCompleted);
-    Assert.assertEquals(500L, manager.completedSourceTasksOutputSize);
-    
-    manager.onVertexManagerEventReceived(vmEvent);
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    // managedVertex tasks reduced
-    verify(mockManagedVertex).setParallelism(eq(2), anyMap());
-    Assert.assertEquals(2, newEdgeManagers.size());
-    // TODO improve tests for parallelism
-    Assert.assertEquals(0, manager.pendingTasks.size()); // all tasks scheduled
-    Assert.assertEquals(2, scheduledTasks.size());
-    Assert.assertTrue(scheduledTasks.contains(mockTaskId1));
-    Assert.assertTrue(scheduledTasks.contains(mockTaskId2));
-    Assert.assertEquals(2, manager.numSourceTasksCompleted);
-    Assert.assertEquals(2, manager.numVertexManagerEventsReceived);
-    Assert.assertEquals(1000L, manager.completedSourceTasksOutputSize);
-    
-    // more completions dont cause recalculation of parallelism
-    manager.onSourceTaskCompleted(mockSrcAttemptId21);
-    verify(mockManagedVertex).setParallelism(eq(2), anyMap());
-    Assert.assertEquals(2, newEdgeManagers.size());
-    
-    EdgeManager edgeManager = newEdgeManagers.values().iterator().next();
-    List<Integer> targets = Lists.newArrayList();
-    DataMovementEvent dmEvent = new DataMovementEvent(1, new byte[0]);
-    edgeManager.routeEventToDestinationTasks(dmEvent, 1, 2, targets);
-    Assert.assertEquals(3, dmEvent.getTargetIndex());
-    Assert.assertEquals(0, targets.get(0).intValue());
-    targets.clear();
-    dmEvent = new DataMovementEvent(2, new byte[0]);
-    edgeManager.routeEventToDestinationTasks(dmEvent, 0, 2, targets);
-    Assert.assertEquals(0, dmEvent.getTargetIndex());
-    Assert.assertEquals(1, targets.get(0).intValue());    
-  }
-  
-  @SuppressWarnings({ "unchecked", "rawtypes" })
-  @Test(timeout = 5000)
-  public void testShuffleVertexManagerSlowStart() {
-    Configuration conf = new Configuration();
-    ShuffleVertexManager manager = null;
-    EventHandler mockEventHandler = mock(EventHandler.class);
-    TezDAGID dagId = TezDAGID.getInstance("1", 1, 1);
-    HashMap<Vertex, Edge> mockInputVertices = 
-        new HashMap<Vertex, Edge>();
-    Vertex mockSrcVertex1 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId1 = TezVertexID.getInstance(dagId, 1);
-    EdgeProperty eProp1 = new EdgeProperty(
-        EdgeProperty.DataMovementType.SCATTER_GATHER,
-        EdgeProperty.DataSourceType.PERSISTED, 
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex1.getVertexId()).thenReturn(mockSrcVertexId1);
-    Vertex mockSrcVertex2 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId2 = TezVertexID.getInstance(dagId, 2);
-    EdgeProperty eProp2 = new EdgeProperty(
-        EdgeProperty.DataMovementType.SCATTER_GATHER,
-        EdgeProperty.DataSourceType.PERSISTED,
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex2.getVertexId()).thenReturn(mockSrcVertexId2);
-    Vertex mockSrcVertex3 = mock(Vertex.class);
-    TezVertexID mockSrcVertexId3 = TezVertexID.getInstance(dagId, 3);
-    EdgeProperty eProp3 = new EdgeProperty(
-        EdgeProperty.DataMovementType.BROADCAST,
-        EdgeProperty.DataSourceType.PERSISTED, 
-        SchedulingType.SEQUENTIAL, 
-        new OutputDescriptor("out"),
-        new InputDescriptor("in"));
-    when(mockSrcVertex3.getVertexId()).thenReturn(mockSrcVertexId3);
-    
-    Vertex mockManagedVertex = mock(Vertex.class);
-    TezVertexID mockManagedVertexId = TezVertexID.getInstance(dagId, 3);
-    when(mockManagedVertex.getVertexId()).thenReturn(mockManagedVertexId);
-    when(mockManagedVertex.getInputVertices()).thenReturn(mockInputVertices);
-    
-    // fail if there is no bipartite src vertex
-    mockInputVertices.put(mockSrcVertex3, new Edge(eProp3, mockEventHandler));
-    try {
-      manager = createManager(conf, mockManagedVertex, 0.1f, 0.1f);
-     Assert.assertFalse(true);
-    } catch (TezUncheckedException e) {
-      Assert.assertTrue(e.getMessage().contains(
-          "Atleast 1 bipartite source should exist"));
-    }
-    
-    mockInputVertices.put(mockSrcVertex1, new Edge(eProp1, mockEventHandler));
-    mockInputVertices.put(mockSrcVertex2, new Edge(eProp2, mockEventHandler));
-    
-    // check initialization
-    manager = createManager(conf, mockManagedVertex, 0.1f, 0.1f);
-    Assert.assertTrue(manager.bipartiteSources.size() == 2);
-    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId1));
-    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId2));
-    
-    HashMap<TezTaskID, Task> managedTasks = new HashMap<TezTaskID, Task>();
-    TezTaskID mockTaskId1 = TezTaskID.getInstance(mockManagedVertexId, 0);
-    managedTasks.put(mockTaskId1, null);
-    TezTaskID mockTaskId2 = TezTaskID.getInstance(mockManagedVertexId, 1);
-    managedTasks.put(mockTaskId2, null);
-    TezTaskID mockTaskId3 = TezTaskID.getInstance(mockManagedVertexId, 2);
-    managedTasks.put(mockTaskId3, null);
-    
-    when(mockManagedVertex.getTotalTasks()).thenReturn(3);
-    when(mockManagedVertex.getTasks()).thenReturn(managedTasks);
-    
-    final HashSet<TezTaskID> scheduledTasks = new HashSet<TezTaskID>();
-    doAnswer(new Answer() {
-      public Object answer(InvocationOnMock invocation) {
-          Object[] args = invocation.getArguments();
-          scheduledTasks.clear();
-          scheduledTasks.addAll((Collection<TezTaskID>)args[0]); 
-          return null;
-      }}).when(mockManagedVertex).scheduleTasks(anyCollection());
-    
-    // source vertices have 0 tasks. immediate start of all managed tasks
-    when(mockSrcVertex1.getTotalTasks()).thenReturn(0);
-    when(mockSrcVertex2.getTotalTasks()).thenReturn(0);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
-    
-    when(mockSrcVertex1.getTotalTasks()).thenReturn(2);
-    when(mockSrcVertex2.getTotalTasks()).thenReturn(2);
-
-    try {
-      // source vertex have some tasks. min < 0.
-      manager = createManager(conf, mockManagedVertex, -0.1f, 0);
-      Assert.assertTrue(false); // should not come here
-    } catch (IllegalArgumentException e) {
-      Assert.assertTrue(e.getMessage().contains(
-          "Invalid values for slowStartMinSrcCompletionFraction"));
-    }
-    
-    try {
-      // source vertex have some tasks. min > max
-      manager = createManager(conf, mockManagedVertex, 0.5f, 0.3f);
-      Assert.assertTrue(false); // should not come here
-    } catch (IllegalArgumentException e) {
-      Assert.assertTrue(e.getMessage().contains(
-          "Invalid values for slowStartMinSrcCompletionFraction"));
-    }
-    
-    // source vertex have some tasks. min, max == 0
-    manager = createManager(conf, mockManagedVertex, 0, 0);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    Assert.assertTrue(manager.totalTasksToSchedule == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
-
-    TezTaskAttemptID mockSrcAttemptId11 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId1, 0), 0);
-    TezTaskAttemptID mockSrcAttemptId12 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId1, 1), 0);
-    TezTaskAttemptID mockSrcAttemptId21 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId2, 0), 0);
-    TezTaskAttemptID mockSrcAttemptId22 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId2, 1), 0);
-    TezTaskAttemptID mockSrcAttemptId31 = 
-        TezTaskAttemptID.getInstance(TezTaskID.getInstance(mockSrcVertexId3, 0), 0);
-    
-    // min, max > 0 and min == max
-    manager = createManager(conf, mockManagedVertex, 0.25f, 0.25f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    // task completion from non-bipartite stage does nothing
-    manager.onSourceTaskCompleted(mockSrcAttemptId31);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
-    
-    // min, max > 0 and min == max == absolute max 1.0
-    manager = createManager(conf, mockManagedVertex, 1.0f, 1.0f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    // task completion from non-bipartite stage does nothing
-    manager.onSourceTaskCompleted(mockSrcAttemptId31);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
-    manager.onSourceTaskCompleted(mockSrcAttemptId21);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
-    manager.onSourceTaskCompleted(mockSrcAttemptId22);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
-    
-    // min, max > 0 and min == max
-    manager = createManager(conf, mockManagedVertex, 1.0f, 1.0f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    // task completion from non-bipartite stage does nothing
-    manager.onSourceTaskCompleted(mockSrcAttemptId31);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
-    manager.onSourceTaskCompleted(mockSrcAttemptId21);
-    Assert.assertTrue(manager.pendingTasks.size() == 3);
-    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
-    manager.onSourceTaskCompleted(mockSrcAttemptId22);
-    Assert.assertTrue(manager.pendingTasks.isEmpty());
-    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
-    
-    // min, max > and min < max
-    manager = createManager(conf, mockManagedVertex, 0.25f, 0.75f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    Assert.assertTrue(manager.pendingTasks.size() == 2);
-    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
-    // completion of same task again should not get counted
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    Assert.assertTrue(manager.pendingTasks.size() == 2);
-    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
-    manager.onSourceTaskCompleted(mockSrcAttemptId21);
-    Assert.assertTrue(manager.pendingTasks.size() == 0);
-    Assert.assertTrue(scheduledTasks.size() == 2); // 2 tasks scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
-    scheduledTasks.clear();
-    manager.onSourceTaskCompleted(mockSrcAttemptId22); // we are done. no action
-    Assert.assertTrue(manager.pendingTasks.size() == 0);
-    Assert.assertTrue(scheduledTasks.size() == 0); // no task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
-
-    // min, max > and min < max
-    manager = createManager(conf, mockManagedVertex, 0.25f, 1.0f);
-    manager.onVertexStarted(null);
-    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
-    Assert.assertTrue(manager.numSourceTasks == 4);
-    manager.onSourceTaskCompleted(mockSrcAttemptId11);
-    manager.onSourceTaskCompleted(mockSrcAttemptId12);
-    Assert.assertTrue(manager.pendingTasks.size() == 2);
-    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
-    manager.onSourceTaskCompleted(mockSrcAttemptId21);
-    Assert.assertTrue(manager.pendingTasks.size() == 1);
-    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
-    manager.onSourceTaskCompleted(mockSrcAttemptId22);
-    Assert.assertTrue(manager.pendingTasks.size() == 0);
-    Assert.assertTrue(scheduledTasks.size() == 1); // no task scheduled
-    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
-
-  }
-  
-  private ShuffleVertexManager createManager(Configuration conf, 
-      Vertex vertex, float min, float max) {
-    ShuffleVertexManager manager = new ShuffleVertexManager(vertex);
-    conf.setFloat(TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION, min);
-    conf.setFloat(TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION, max);
-    manager.initialize(conf);
-    return manager;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-mapreduce/src/main/java/org/apache/tez/mapreduce/client/YARNRunner.java
----------------------------------------------------------------------
diff --git a/tez-mapreduce/src/main/java/org/apache/tez/mapreduce/client/YARNRunner.java b/tez-mapreduce/src/main/java/org/apache/tez/mapreduce/client/YARNRunner.java
index cc4d1ed..bca96cf 100644
--- a/tez-mapreduce/src/main/java/org/apache/tez/mapreduce/client/YARNRunner.java
+++ b/tez-mapreduce/src/main/java/org/apache/tez/mapreduce/client/YARNRunner.java
@@ -92,8 +92,10 @@ import org.apache.tez.dag.api.TezConfiguration;
 import org.apache.tez.dag.api.TezException;
 import org.apache.tez.dag.api.Vertex;
 import org.apache.tez.dag.api.VertexLocationHint.TaskLocationHint;
+import org.apache.tez.dag.api.VertexManagerPluginDescriptor;
 import org.apache.tez.dag.api.client.DAGClient;
 import org.apache.tez.dag.api.client.DAGStatus;
+import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager;
 import org.apache.tez.mapreduce.hadoop.DeprecatedKeys;
 import org.apache.tez.mapreduce.hadoop.MRHelpers;
 import org.apache.tez.mapreduce.hadoop.MRJobConfig;
@@ -428,6 +430,11 @@ public class YARNRunner implements ClientProtocol {
         .setTaskLocalResources(taskLocalResources)
         .setTaskLocationsHint(locations)
         .setJavaOpts(taskJavaOpts);
+    
+    if (!isMap) {
+      vertex.setVertexManagerPlugin(new VertexManagerPluginDescriptor(
+          ShuffleVertexManager.class.getName()));
+    }
 
     if (LOG.isDebugEnabled()) {
       LOG.debug("Adding vertex to DAG" + ", vertexName="

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-runtime-library/pom.xml
----------------------------------------------------------------------
diff --git a/tez-runtime-library/pom.xml b/tez-runtime-library/pom.xml
index 8868400..422ab66 100644
--- a/tez-runtime-library/pom.xml
+++ b/tez-runtime-library/pom.xml
@@ -40,6 +40,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java b/tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java
new file mode 100644
index 0000000..15275f7
--- /dev/null
+++ b/tez-runtime-library/src/main/java/org/apache/tez/dag/library/vertexmanager/ShuffleVertexManager.java
@@ -0,0 +1,498 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.tez.dag.library.vertexmanager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.tez.common.TezUtils;
+import org.apache.tez.dag.api.EdgeManager;
+import org.apache.tez.dag.api.EdgeProperty;
+import org.apache.tez.dag.api.InputDescriptor;
+import org.apache.tez.dag.api.TezUncheckedException;
+import org.apache.tez.dag.api.VertexManagerPlugin;
+import org.apache.tez.dag.api.VertexManagerPluginContext;
+import org.apache.tez.dag.api.EdgeProperty.DataMovementType;
+import org.apache.tez.runtime.api.Event;
+import org.apache.tez.runtime.api.events.DataMovementEvent;
+import org.apache.tez.runtime.api.events.InputFailedEvent;
+import org.apache.tez.runtime.api.events.InputReadErrorEvent;
+import org.apache.tez.runtime.api.events.VertexManagerEvent;
+import org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.VertexManagerEventPayloadProto;
+
+import com.google.common.collect.Maps;
+import com.google.protobuf.InvalidProtocolBufferException;
+
+/**
+ * Starts scheduling tasks when number of completed source tasks crosses 
+ * <code>slowStartMinSrcCompletionFraction</code> and schedules all tasks 
+ *  when <code>slowStartMaxSrcCompletionFraction</code> is reached
+ */
+public class ShuffleVertexManager implements VertexManagerPlugin {
+  
+  private static final String TEZ_AM_PREFIX = "tez.am.";
+  
+  public static final String
+  TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION = TEZ_AM_PREFIX
+  + "shuffle-vertex-manager.min-src-fraction";
+  public static final float
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION_DEFAULT = 0.25f;
+  
+  public static final String
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION = TEZ_AM_PREFIX
+    + "shuffle-vertex-manager.max-src-fraction";
+  public static final float
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION_DEFAULT = 0.75f;
+  
+  public static final String
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL = TEZ_AM_PREFIX +
+    "shuffle-vertex-manager.enable.auto-parallel";
+  public static final boolean
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL_DEFAULT = false;
+  
+  public static final String
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE = TEZ_AM_PREFIX +
+    "shuffle-vertex-manager.desired-task-input-size";
+  public static final long
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE_DEFAULT =
+    1024*1024*100L;
+  
+  public static final String
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM = TEZ_AM_PREFIX +
+    "shuffle-vertex-manager.min-task-parallelism";
+  public static final int
+    TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM_DEFAULT = 1;
+
+  
+  private static final Log LOG = 
+                   LogFactory.getLog(ShuffleVertexManager.class);
+
+  VertexManagerPluginContext context;
+  float slowStartMinSrcCompletionFraction;
+  float slowStartMaxSrcCompletionFraction;
+  long desiredTaskInputDataSize = 1024*1024*100L;
+  int minTaskParallelism = 1;
+  boolean enableAutoParallelism = false;
+  boolean parallelismDetermined = false;
+  
+  int numSourceTasks = 0;
+  int numSourceTasksCompleted = 0;
+  int numVertexManagerEventsReceived = 0;
+  ArrayList<Integer> pendingTasks;
+  int totalTasksToSchedule = 0;
+  
+  Map<String, Set<Integer>> bipartiteSources = Maps.newHashMap();
+  long completedSourceTasksOutputSize = 0;
+  
+  public ShuffleVertexManager() {
+  }
+  
+  
+  public class CustomShuffleEdgeManager implements EdgeManager {
+    int numSourceTaskOutputs;
+    int numDestinationTasks;
+    int basePartitionRange;
+    int remainderRangeForLastShuffler;
+    
+    CustomShuffleEdgeManager(int numSourceTaskOutputs, int numDestinationTasks,
+        int basePartitionRange, int remainderPartitionForLastShuffler) {
+      this.numSourceTaskOutputs = numSourceTaskOutputs;
+      this.numDestinationTasks = numDestinationTasks;
+      this.basePartitionRange = basePartitionRange;
+      this.remainderRangeForLastShuffler = remainderPartitionForLastShuffler;
+    }
+
+    @Override
+    public int getNumDestinationTaskInputs(int numSourceTasks, 
+        int destinationTaskIndex) {
+      int partitionRange = 1;
+      if(destinationTaskIndex < numDestinationTasks-1) {
+        partitionRange = basePartitionRange;
+      } else {
+        partitionRange = remainderRangeForLastShuffler;
+      }
+      return numSourceTasks * partitionRange;
+    }
+
+    @Override
+    public int getNumSourceTaskOutputs(int numDestinationTasks, 
+        int sourceTaskIndex) {
+      return numSourceTaskOutputs;
+    }
+    
+    @Override
+    public void routeEventToDestinationTasks(DataMovementEvent event,
+        int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices) {
+      int sourceIndex = event.getSourceIndex();
+      int destinationTaskIndex = sourceIndex/basePartitionRange;
+      int partitionRange = 1;
+      if(destinationTaskIndex < numDestinationTasks-1) {
+        partitionRange = basePartitionRange;
+      } else {
+        partitionRange = remainderRangeForLastShuffler;
+      }
+      
+      // all inputs from a source task are next to each other in original order
+      int targetIndex = 
+          sourceTaskIndex * partitionRange 
+          + sourceIndex % partitionRange;
+      
+      event.setTargetIndex(targetIndex);
+      taskIndices.add(new Integer(destinationTaskIndex));
+    }
+
+    @Override
+    public void routeEventToDestinationTasks(InputFailedEvent event,
+        int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices) {
+      int sourceIndex = event.getSourceIndex();
+      int destinationTaskIndex = sourceIndex/basePartitionRange;
+      int partitionRange = 1;
+      if(destinationTaskIndex < numDestinationTasks-1) {
+        partitionRange = basePartitionRange;
+      } else {
+        partitionRange = remainderRangeForLastShuffler;
+      }
+      int targetIndex = 
+          sourceTaskIndex * partitionRange 
+          + sourceIndex % partitionRange;
+      
+      event.setTargetIndex(targetIndex);
+      taskIndices.add(new Integer(destinationTaskIndex));
+    }
+
+    @Override
+    public int routeEventToSourceTasks(int destinationTaskIndex,
+        InputReadErrorEvent event) {
+      int partitionRange = 1;
+      if(destinationTaskIndex < numDestinationTasks-1) {
+        partitionRange = basePartitionRange;
+      } else {
+        partitionRange = remainderRangeForLastShuffler;
+      }
+      return event.getIndex()/partitionRange;
+    }
+
+    @Override
+    public int getDestinationConsumerTaskNumber(int sourceTaskIndex,
+        int numDestTasks) {
+      return numDestTasks;
+    }
+  }
+
+  
+  @Override
+  public void onVertexStarted(Map<String, List<Integer>> completions) {
+    pendingTasks = new ArrayList<Integer>(
+        context.getVertexNumTasks(context.getVertexName()));
+    // track the tasks in this vertex
+    updatePendingTasks();
+    updateSourceTaskCount();
+    
+    LOG.info("OnVertexStarted vertex: " + context.getVertexName() + 
+             " with " + numSourceTasks + " source tasks and " + 
+             totalTasksToSchedule + " pending tasks");
+    
+    if (completions != null) {
+      for (Map.Entry<String, List<Integer>> entry : completions.entrySet()) {
+        for (Integer taskId : entry.getValue()) {
+          onSourceTaskCompleted(entry.getKey(), taskId);
+        }
+      }
+    }
+    // for the special case when source has 0 tasks or min fraction == 0
+    schedulePendingTasks();
+  }
+
+  @Override
+  public void onSourceTaskCompleted(String srcVertexName, Integer srcTaskId) {
+    updateSourceTaskCount();
+    Set<Integer> completedSourceTasks = bipartiteSources.get(srcVertexName);
+    if (completedSourceTasks != null) {
+      // duplicate notifications tracking
+      if (completedSourceTasks.add(srcTaskId)) {
+        // source task has completed
+        ++numSourceTasksCompleted;
+      }
+      schedulePendingTasks();
+    }
+  }
+  
+  @Override
+  public void onVertexManagerEventReceived(VertexManagerEvent vmEvent) {
+    // TODO handle duplicates from retries
+    if (enableAutoParallelism) {
+      // save output size
+      VertexManagerEventPayloadProto proto;
+      try {
+        proto = VertexManagerEventPayloadProto.parseFrom(vmEvent.getUserPayload());
+      } catch (InvalidProtocolBufferException e) {
+        throw new TezUncheckedException(e);
+      }
+      long sourceTaskOutputSize = proto.getOutputSize();
+      numVertexManagerEventsReceived++;
+      completedSourceTasksOutputSize += sourceTaskOutputSize;
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Received info of output size: " + sourceTaskOutputSize 
+            + " numInfoReceived: " + numVertexManagerEventsReceived
+            + " total output size: " + completedSourceTasksOutputSize);
+      }
+    }
+    
+  }
+  
+  void updatePendingTasks() {
+    pendingTasks.clear();
+    for (int i=0; i<context.getVertexNumTasks(context.getVertexName()); ++i) {
+      pendingTasks.add(new Integer(i));
+    }
+    totalTasksToSchedule = pendingTasks.size();
+  }
+  
+  void updateSourceTaskCount() {
+    // track source vertices
+    int numSrcTasks = 0;
+    for(String vertex : bipartiteSources.keySet()) {
+      numSrcTasks += context.getVertexNumTasks(vertex);
+    }
+    numSourceTasks = numSrcTasks;
+  }
+
+  void determineParallelismAndApply() {
+    if(numSourceTasksCompleted == 0) {
+      return;
+    }
+    
+    if(numVertexManagerEventsReceived == 0) {
+      return;
+    }
+    
+    int currentParallelism = pendingTasks.size();
+    long expectedTotalSourceTasksOutputSize = 
+        (numSourceTasks*completedSourceTasksOutputSize)/numVertexManagerEventsReceived;
+    int desiredTaskParallelism = 
+        (int)(
+            (expectedTotalSourceTasksOutputSize+desiredTaskInputDataSize-1)/
+            desiredTaskInputDataSize);
+    if(desiredTaskParallelism < minTaskParallelism) {
+      desiredTaskParallelism = minTaskParallelism;
+    }
+    
+    if(desiredTaskParallelism >= currentParallelism) {
+      return;
+    }
+    
+    // most shufflers will be assigned this range
+    int basePartitionRange = currentParallelism/desiredTaskParallelism;
+    
+    if (basePartitionRange <= 1) {
+      // nothing to do if range is equal 1 partition. shuffler does it by default
+      return;
+    }
+    
+    int numShufflersWithBaseRange = currentParallelism / basePartitionRange;
+    int remainderRangeForLastShuffler = currentParallelism % basePartitionRange; 
+    
+    int finalTaskParallelism = (remainderRangeForLastShuffler > 0) ?
+          (numShufflersWithBaseRange + 1) : (numShufflersWithBaseRange);
+
+    LOG.info("Reduce auto parallelism for vertex: " + context.getVertexName() 
+        + " to " + finalTaskParallelism + " from " + pendingTasks.size() 
+        + " . Expected output: " + expectedTotalSourceTasksOutputSize 
+        + " based on actual output: " + completedSourceTasksOutputSize
+        + " from " + numVertexManagerEventsReceived + " vertex manager events. "
+        + " desiredTaskInputSize: " + desiredTaskInputDataSize);
+          
+    if(finalTaskParallelism < currentParallelism) {
+      // final parallelism is less than actual parallelism
+      Map<String, EdgeManager> edgeManagers = new HashMap<String, EdgeManager>(
+          bipartiteSources.size());
+      for(String vertex : bipartiteSources.keySet()) {
+        // use currentParallelism for numSourceTasks to maintain original state
+        // for the source tasks
+        edgeManagers.put(vertex, new CustomShuffleEdgeManager(
+            currentParallelism, finalTaskParallelism, basePartitionRange,
+            ((remainderRangeForLastShuffler > 0) ?
+                remainderRangeForLastShuffler : basePartitionRange)));
+      }
+      
+      context.setVertexParallelism(finalTaskParallelism, edgeManagers);
+      updatePendingTasks();      
+    }
+  }
+  
+  void schedulePendingTasks(int numTasksToSchedule) {
+    // determine parallelism before scheduling the first time
+    // this is the latest we can wait before determining parallelism.
+    // currently this depends on task completion and so this is the best time
+    // to do this. This is the max time we have until we have to launch tasks 
+    // as specified by the user. If/When we move to some other method of 
+    // calculating parallelism or change parallelism while tasks are already
+    // running then we can create other parameters to trigger this calculation.
+    if(enableAutoParallelism && !parallelismDetermined) {
+      // do this once
+      parallelismDetermined = true;
+      determineParallelismAndApply();
+    }
+    ArrayList<Integer> scheduledTasks = new ArrayList<Integer>(numTasksToSchedule);
+    while(!pendingTasks.isEmpty() && numTasksToSchedule > 0) {
+      numTasksToSchedule--;
+      scheduledTasks.add(pendingTasks.get(0));
+      pendingTasks.remove(0);
+    }
+    context.scheduleVertexTasks(scheduledTasks);
+  }
+  
+  void schedulePendingTasks() {    
+    int numPendingTasks = pendingTasks.size();
+    if (numPendingTasks == 0) {
+      return;
+    }
+    
+    if (numSourceTasksCompleted == numSourceTasks && numPendingTasks > 0) {
+      LOG.info("All source tasks assigned. " +
+          "Ramping up " + numPendingTasks + 
+          " remaining tasks for vertex: " + context.getVertexName());
+      schedulePendingTasks(numPendingTasks);
+      return;
+    }
+
+    float completedSourceTaskFraction = 0f;
+    if (numSourceTasks != 0) { // support for 0 source tasks
+      completedSourceTaskFraction = (float)numSourceTasksCompleted/numSourceTasks;
+    } else {
+      completedSourceTaskFraction = 1;
+    }
+    
+    // start scheduling when source tasks completed fraction is more than min.
+    // linearly increase the number of scheduled tasks such that all tasks are 
+    // scheduled when source tasks completed fraction reaches max
+    float tasksFractionToSchedule = 1; 
+    float percentRange = slowStartMaxSrcCompletionFraction - 
+                          slowStartMinSrcCompletionFraction;
+    if (percentRange > 0) {
+      tasksFractionToSchedule = 
+            (completedSourceTaskFraction - slowStartMinSrcCompletionFraction)/
+            percentRange;
+    } else {
+      // min and max are equal. schedule 100% on reaching min
+      if(completedSourceTaskFraction < slowStartMinSrcCompletionFraction) {
+        tasksFractionToSchedule = 0;
+      }
+    }
+    
+    if (tasksFractionToSchedule > 1) {
+      tasksFractionToSchedule = 1;
+    } else if (tasksFractionToSchedule < 0) {
+      tasksFractionToSchedule = 0;
+    }
+    
+    int numTasksToSchedule = 
+        ((int)(tasksFractionToSchedule * totalTasksToSchedule) - 
+         (totalTasksToSchedule - numPendingTasks));
+    
+    if (numTasksToSchedule > 0) {
+      // numTasksToSchedule can be -ve if numSourceTasksCompleted does not 
+      // does not increase monotonically
+      LOG.info("Scheduling " + numTasksToSchedule + " tasks for vertex: " + 
+               context.getVertexName() + " with totalTasks: " + 
+               totalTasksToSchedule + ". " + numSourceTasksCompleted + 
+               " source tasks completed out of " + numSourceTasks + 
+               ". SourceTaskCompletedFraction: " + completedSourceTaskFraction + 
+               " min: " + slowStartMinSrcCompletionFraction + 
+               " max: " + slowStartMaxSrcCompletionFraction);
+      schedulePendingTasks(numTasksToSchedule);
+    }
+  }
+
+  @Override
+  public void initialize(byte[] payload, VertexManagerPluginContext context) {
+    Configuration conf;
+    try {
+      conf = TezUtils.createConfFromUserPayload(payload);
+    } catch (IOException e) {
+      throw new TezUncheckedException(e);
+    }
+    
+    this.context = context;
+    
+    this.slowStartMinSrcCompletionFraction = conf
+        .getFloat(
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION,
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION_DEFAULT);
+    this.slowStartMaxSrcCompletionFraction = conf
+        .getFloat(
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION,
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION_DEFAULT);
+
+    if (slowStartMinSrcCompletionFraction < 0
+        || slowStartMaxSrcCompletionFraction < slowStartMinSrcCompletionFraction) {
+      throw new IllegalArgumentException(
+          "Invalid values for slowStartMinSrcCompletionFraction"
+              + "/slowStartMaxSrcCompletionFraction. Min cannot be < 0 and "
+              + "max cannot be < min.");
+    }
+
+    enableAutoParallelism = conf
+        .getBoolean(
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL,
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL_DEFAULT);
+    desiredTaskInputDataSize = conf
+        .getLong(
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE,
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE_DEFAULT);
+    minTaskParallelism = conf
+        .getInt(
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM,
+            ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM_DEFAULT);
+    LOG.info("Shuffle Vertex Manager: settings" + " minFrac:"
+        + slowStartMinSrcCompletionFraction + " maxFrac:"
+        + slowStartMaxSrcCompletionFraction + " auto:" + enableAutoParallelism
+        + " desiredTaskIput:" + desiredTaskInputDataSize + " minTasks:"
+        + minTaskParallelism);
+    
+    Map<String, EdgeProperty> inputs = context.getInputVertexEdgeProperties();
+    for(Map.Entry<String, EdgeProperty> entry : inputs.entrySet()) {
+      if (entry.getValue().getDataMovementType() == DataMovementType.SCATTER_GATHER) {
+        String vertex = entry.getKey();
+        bipartiteSources.put(vertex, new HashSet<Integer>());
+      }
+    }
+    if(bipartiteSources.isEmpty()) {
+      throw new TezUncheckedException("Atleast 1 bipartite source should exist");
+    }
+    // dont track the source tasks here since those tasks may themselves be
+    // dynamically changed as the DAG progresses.
+
+  }
+
+  @Override
+  public void onRootVertexInitialized(String inputName,
+      InputDescriptor inputDescriptor, List<Event> events) {
+    // Not allowing this for now. Nothing to do.
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-runtime-library/src/test/java/org/apache/tez/dag/library/vertexmanager/TestShuffleVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-runtime-library/src/test/java/org/apache/tez/dag/library/vertexmanager/TestShuffleVertexManager.java b/tez-runtime-library/src/test/java/org/apache/tez/dag/library/vertexmanager/TestShuffleVertexManager.java
new file mode 100644
index 0000000..a4fbeda
--- /dev/null
+++ b/tez-runtime-library/src/test/java/org/apache/tez/dag/library/vertexmanager/TestShuffleVertexManager.java
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tez.dag.library.vertexmanager;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.tez.common.TezUtils;
+import org.apache.tez.dag.api.EdgeManager;
+import org.apache.tez.dag.api.EdgeProperty;
+import org.apache.tez.dag.api.InputDescriptor;
+import org.apache.tez.dag.api.OutputDescriptor;
+import org.apache.tez.dag.api.TezUncheckedException;
+import org.apache.tez.dag.api.EdgeProperty.SchedulingType;
+import org.apache.tez.dag.api.VertexManagerPluginContext;
+import org.apache.tez.runtime.api.events.DataMovementEvent;
+import org.apache.tez.runtime.api.events.VertexManagerEvent;
+import org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.VertexManagerEventPayloadProto;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import com.google.common.collect.Lists;
+
+import static org.mockito.Mockito.*;
+
+public class TestShuffleVertexManager {
+
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  @Test(timeout = 5000)
+  public void testShuffleVertexManagerAutoParallelism() throws IOException {
+    Configuration conf = new Configuration();
+    conf.setBoolean(
+        ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL,
+        true);
+    conf.setLong(ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE, 1000L);
+    ShuffleVertexManager manager = null;
+    
+    HashMap<String, EdgeProperty> mockInputVertices = 
+        new HashMap<String, EdgeProperty>();
+    String mockSrcVertexId1 = "Vertex1";
+    EdgeProperty eProp1 = new EdgeProperty(
+        EdgeProperty.DataMovementType.SCATTER_GATHER,
+        EdgeProperty.DataSourceType.PERSISTED,
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    String mockSrcVertexId2 = "Vertex2";
+    EdgeProperty eProp2 = new EdgeProperty(
+        EdgeProperty.DataMovementType.SCATTER_GATHER,
+        EdgeProperty.DataSourceType.PERSISTED,
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    String mockSrcVertexId3 = "Vertex3";
+    EdgeProperty eProp3 = new EdgeProperty(
+        EdgeProperty.DataMovementType.BROADCAST,
+        EdgeProperty.DataSourceType.PERSISTED, 
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    
+    final String mockManagedVertexId = "Vertex4";
+    
+    mockInputVertices.put(mockSrcVertexId1, eProp1);
+    mockInputVertices.put(mockSrcVertexId2, eProp2);
+    mockInputVertices.put(mockSrcVertexId3, eProp3);
+
+    final VertexManagerPluginContext mockContext = mock(VertexManagerPluginContext.class);
+    when(mockContext.getInputVertexEdgeProperties()).thenReturn(mockInputVertices);
+    when(mockContext.getVertexName()).thenReturn(mockManagedVertexId);
+    when(mockContext.getVertexNumTasks(mockManagedVertexId)).thenReturn(4);
+    
+    // check initialization
+    manager = createManager(conf, mockContext, 0.1f, 0.1f);
+    Assert.assertTrue(manager.bipartiteSources.size() == 2);
+    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId1));
+    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId2));
+    
+    final HashSet<Integer> scheduledTasks = new HashSet<Integer>();
+    doAnswer(new Answer() {
+      public Object answer(InvocationOnMock invocation) {
+          Object[] args = invocation.getArguments();
+          scheduledTasks.clear();
+          scheduledTasks.addAll((List<Integer>)args[0]); 
+          return null;
+      }}).when(mockContext).scheduleVertexTasks(anyList());
+    
+    final Map<String, EdgeManager> newEdgeManagers = new HashMap<String, EdgeManager>();
+    
+    doAnswer(new Answer() {
+      public Object answer(InvocationOnMock invocation) {
+          when(mockContext.getVertexNumTasks(mockManagedVertexId)).thenReturn(2);
+          newEdgeManagers.clear();
+          newEdgeManagers.putAll((Map<String, EdgeManager>)invocation.getArguments()[1]);
+          return null;
+      }}).when(mockContext).setVertexParallelism(eq(2), anyMap());
+    
+    // source vertices have 0 tasks. immediate start of all managed tasks
+    when(mockContext.getVertexNumTasks(mockSrcVertexId1)).thenReturn(0);
+    when(mockContext.getVertexNumTasks(mockSrcVertexId2)).thenReturn(0);
+    when(mockContext.getVertexNumTasks(mockSrcVertexId3)).thenReturn(1);
+
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 4); // all tasks scheduled
+    scheduledTasks.clear();
+    
+    when(mockContext.getVertexNumTasks(mockSrcVertexId1)).thenReturn(2);
+    when(mockContext.getVertexNumTasks(mockSrcVertexId2)).thenReturn(2);
+
+    byte[] payload =
+        VertexManagerEventPayloadProto.newBuilder().setOutputSize(5000L).build().toByteArray();
+    VertexManagerEvent vmEvent = new VertexManagerEvent("Vertex", payload);
+    // parallelism not change due to large data size
+    manager = createManager(conf, mockContext, 0.1f, 0.1f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 4); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    manager.onVertexManagerEventReceived(vmEvent);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    // managedVertex tasks reduced
+    verify(mockContext, times(0)).setVertexParallelism(anyInt(), anyMap());
+    Assert.assertEquals(0, manager.pendingTasks.size()); // all tasks scheduled
+    Assert.assertEquals(4, scheduledTasks.size());
+    Assert.assertEquals(1, manager.numSourceTasksCompleted);
+    Assert.assertEquals(5000L, manager.completedSourceTasksOutputSize);
+    
+    
+    // parallelism changed due to small data size
+    scheduledTasks.clear();
+    payload =
+        VertexManagerEventPayloadProto.newBuilder().setOutputSize(500L).build().toByteArray();
+    vmEvent = new VertexManagerEvent("Vertex", payload);
+    
+    manager = createManager(conf, mockContext, 0.5f, 0.5f);
+    manager.onVertexStarted(null);
+    Assert.assertEquals(4, manager.pendingTasks.size()); // no tasks scheduled
+    Assert.assertEquals(4, manager.numSourceTasks);
+    // task completion from non-bipartite stage does nothing
+    manager.onSourceTaskCompleted(mockSrcVertexId3, new Integer(0));
+    Assert.assertEquals(4, manager.pendingTasks.size()); // no tasks scheduled
+    Assert.assertEquals(4, manager.numSourceTasks);
+    Assert.assertEquals(0, manager.numSourceTasksCompleted);
+    manager.onVertexManagerEventReceived(vmEvent);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    Assert.assertEquals(4, manager.pendingTasks.size());
+    Assert.assertEquals(0, scheduledTasks.size()); // no tasks scheduled
+    Assert.assertEquals(1, manager.numSourceTasksCompleted);
+    Assert.assertEquals(1, manager.numVertexManagerEventsReceived);
+    Assert.assertEquals(500L, manager.completedSourceTasksOutputSize);
+    // ignore duplicate completion
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    Assert.assertEquals(4, manager.pendingTasks.size());
+    Assert.assertEquals(0, scheduledTasks.size()); // no tasks scheduled
+    Assert.assertEquals(1, manager.numSourceTasksCompleted);
+    Assert.assertEquals(500L, manager.completedSourceTasksOutputSize);
+    
+    manager.onVertexManagerEventReceived(vmEvent);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    // managedVertex tasks reduced
+    verify(mockContext).setVertexParallelism(eq(2), anyMap());
+    Assert.assertEquals(2, newEdgeManagers.size());
+    // TODO improve tests for parallelism
+    Assert.assertEquals(0, manager.pendingTasks.size()); // all tasks scheduled
+    Assert.assertEquals(2, scheduledTasks.size());
+    Assert.assertTrue(scheduledTasks.contains(new Integer(0)));
+    Assert.assertTrue(scheduledTasks.contains(new Integer(1)));
+    Assert.assertEquals(2, manager.numSourceTasksCompleted);
+    Assert.assertEquals(2, manager.numVertexManagerEventsReceived);
+    Assert.assertEquals(1000L, manager.completedSourceTasksOutputSize);
+    
+    // more completions dont cause recalculation of parallelism
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(0));
+    verify(mockContext).setVertexParallelism(eq(2), anyMap());
+    Assert.assertEquals(2, newEdgeManagers.size());
+    
+    EdgeManager edgeManager = newEdgeManagers.values().iterator().next();
+    List<Integer> targets = Lists.newArrayList();
+    DataMovementEvent dmEvent = new DataMovementEvent(1, new byte[0]);
+    edgeManager.routeEventToDestinationTasks(dmEvent, 1, 2, targets);
+    Assert.assertEquals(3, dmEvent.getTargetIndex());
+    Assert.assertEquals(0, targets.get(0).intValue());
+    targets.clear();
+    dmEvent = new DataMovementEvent(2, new byte[0]);
+    edgeManager.routeEventToDestinationTasks(dmEvent, 0, 2, targets);
+    Assert.assertEquals(0, dmEvent.getTargetIndex());
+    Assert.assertEquals(1, targets.get(0).intValue());    
+  }
+  
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  @Test//(timeout = 5000)
+  public void testShuffleVertexManagerSlowStart() {
+    Configuration conf = new Configuration();
+    ShuffleVertexManager manager = null;
+    HashMap<String, EdgeProperty> mockInputVertices = 
+        new HashMap<String, EdgeProperty>();
+    String mockSrcVertexId1 = "Vertex1";
+    EdgeProperty eProp1 = new EdgeProperty(
+        EdgeProperty.DataMovementType.SCATTER_GATHER,
+        EdgeProperty.DataSourceType.PERSISTED,
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    String mockSrcVertexId2 = "Vertex2";
+    EdgeProperty eProp2 = new EdgeProperty(
+        EdgeProperty.DataMovementType.SCATTER_GATHER,
+        EdgeProperty.DataSourceType.PERSISTED,
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    String mockSrcVertexId3 = "Vertex3";
+    EdgeProperty eProp3 = new EdgeProperty(
+        EdgeProperty.DataMovementType.BROADCAST,
+        EdgeProperty.DataSourceType.PERSISTED, 
+        SchedulingType.SEQUENTIAL, 
+        new OutputDescriptor("out"),
+        new InputDescriptor("in"));
+    
+    String mockManagedVertexId = "Vertex4";
+    
+    VertexManagerPluginContext mockContext = mock(VertexManagerPluginContext.class);
+    when(mockContext.getInputVertexEdgeProperties()).thenReturn(mockInputVertices);
+    when(mockContext.getVertexName()).thenReturn(mockManagedVertexId);
+    when(mockContext.getVertexNumTasks(mockManagedVertexId)).thenReturn(3);
+    
+    // fail if there is no bipartite src vertex
+    mockInputVertices.put(mockSrcVertexId3, eProp3);
+    try {
+      manager = createManager(conf, mockContext, 0.1f, 0.1f);
+      Assert.assertFalse(true);
+    } catch (TezUncheckedException e) {
+      Assert.assertTrue(e.getMessage().contains(
+          "Atleast 1 bipartite source should exist"));
+    }
+    
+    mockInputVertices.put(mockSrcVertexId1, eProp1);
+    mockInputVertices.put(mockSrcVertexId2, eProp2);
+    
+    // check initialization
+    manager = createManager(conf, mockContext, 0.1f, 0.1f);
+    Assert.assertTrue(manager.bipartiteSources.size() == 2);
+    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId1));
+    Assert.assertTrue(manager.bipartiteSources.containsKey(mockSrcVertexId2));
+        
+    final HashSet<Integer> scheduledTasks = new HashSet<Integer>();
+    doAnswer(new Answer() {
+      public Object answer(InvocationOnMock invocation) {
+          Object[] args = invocation.getArguments();
+          scheduledTasks.clear();
+          scheduledTasks.addAll((List<Integer>)args[0]); 
+          return null;
+      }}).when(mockContext).scheduleVertexTasks(anyList());
+    
+    // source vertices have 0 tasks. immediate start of all managed tasks
+    when(mockContext.getVertexNumTasks(mockSrcVertexId1)).thenReturn(0);
+    when(mockContext.getVertexNumTasks(mockSrcVertexId2)).thenReturn(0);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
+    
+    when(mockContext.getVertexNumTasks(mockSrcVertexId1)).thenReturn(2);
+    when(mockContext.getVertexNumTasks(mockSrcVertexId2)).thenReturn(2);
+
+    try {
+      // source vertex have some tasks. min < 0.
+      manager = createManager(conf, mockContext, -0.1f, 0);
+      Assert.assertTrue(false); // should not come here
+    } catch (IllegalArgumentException e) {
+      Assert.assertTrue(e.getMessage().contains(
+          "Invalid values for slowStartMinSrcCompletionFraction"));
+    }
+    
+    try {
+      // source vertex have some tasks. min > max
+      manager = createManager(conf, mockContext, 0.5f, 0.3f);
+      Assert.assertTrue(false); // should not come here
+    } catch (IllegalArgumentException e) {
+      Assert.assertTrue(e.getMessage().contains(
+          "Invalid values for slowStartMinSrcCompletionFraction"));
+    }
+    
+    // source vertex have some tasks. min, max == 0
+    manager = createManager(conf, mockContext, 0, 0);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    Assert.assertTrue(manager.totalTasksToSchedule == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
+    
+    // min, max > 0 and min == max
+    manager = createManager(conf, mockContext, 0.25f, 0.25f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    // task completion from non-bipartite stage does nothing
+    manager.onSourceTaskCompleted(mockSrcVertexId3, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
+    
+    // min, max > 0 and min == max == absolute max 1.0
+    manager = createManager(conf, mockContext, 1.0f, 1.0f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    // task completion from non-bipartite stage does nothing
+    manager.onSourceTaskCompleted(mockSrcVertexId3, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
+    
+    // min, max > 0 and min == max
+    manager = createManager(conf, mockContext, 1.0f, 1.0f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    // task completion from non-bipartite stage does nothing
+    manager.onSourceTaskCompleted(mockSrcVertexId3, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 0);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 1);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 3);
+    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.isEmpty());
+    Assert.assertTrue(scheduledTasks.size() == 3); // all tasks scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
+    
+    // min, max > and min < max
+    manager = createManager(conf, mockContext, 0.25f, 0.75f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 2);
+    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
+    // completion of same task again should not get counted
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 2);
+    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 0);
+    Assert.assertTrue(scheduledTasks.size() == 2); // 2 tasks scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
+    scheduledTasks.clear();
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(1)); // we are done. no action
+    Assert.assertTrue(manager.pendingTasks.size() == 0);
+    Assert.assertTrue(scheduledTasks.size() == 0); // no task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
+
+    // min, max > and min < max
+    manager = createManager(conf, mockContext, 0.25f, 1.0f);
+    manager.onVertexStarted(null);
+    Assert.assertTrue(manager.pendingTasks.size() == 3); // no tasks scheduled
+    Assert.assertTrue(manager.numSourceTasks == 4);
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(0));
+    manager.onSourceTaskCompleted(mockSrcVertexId1, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 2);
+    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 2);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(0));
+    Assert.assertTrue(manager.pendingTasks.size() == 1);
+    Assert.assertTrue(scheduledTasks.size() == 1); // 1 task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 3);
+    manager.onSourceTaskCompleted(mockSrcVertexId2, new Integer(1));
+    Assert.assertTrue(manager.pendingTasks.size() == 0);
+    Assert.assertTrue(scheduledTasks.size() == 1); // no task scheduled
+    Assert.assertTrue(manager.numSourceTasksCompleted == 4);
+
+  }
+  
+  private ShuffleVertexManager createManager(Configuration conf, 
+      VertexManagerPluginContext context, float min, float max) {
+    conf.setFloat(ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION, min);
+    conf.setFloat(ShuffleVertexManager.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION, max);    
+    ShuffleVertexManager manager = new ShuffleVertexManager();
+    byte[] payload;
+    try {
+      payload = TezUtils.createUserPayloadFromConf(conf);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    manager.initialize(payload, context);
+    return manager;
+  }
+}


[2/2] git commit: TEZ-582. Refactor and abstract out VertexManager to enable users to plugin their own logic (bikas)

Posted by bi...@apache.org.
TEZ-582. Refactor and abstract out VertexManager to enable users to plugin their own logic (bikas)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tez/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tez/commit/fb9488cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tez/tree/fb9488cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tez/diff/fb9488cd

Branch: refs/heads/master
Commit: fb9488cd5320b07adbfe93c51e7f1d4e99223c47
Parents: d3e9887
Author: Bikas Saha <bi...@apache.org>
Authored: Sun Jan 12 12:03:59 2014 -0800
Committer: Bikas Saha <bi...@apache.org>
Committed: Sun Jan 12 12:03:59 2014 -0800

----------------------------------------------------------------------
 .../main/java/org/apache/tez/dag/api/DAG.java   |   5 +
 .../apache/tez/dag/api/DagTypeConverters.java   |  10 +
 .../org/apache/tez/dag/api/EdgeManager.java     |  94 ++++
 .../apache/tez/dag/api/TezConfiguration.java    |  31 --
 .../java/org/apache/tez/dag/api/Vertex.java     |  19 +
 .../apache/tez/dag/api/VertexManagerPlugin.java |  69 +++
 .../tez/dag/api/VertexManagerPluginContext.java |  81 +++
 .../dag/api/VertexManagerPluginDescriptor.java  |  39 ++
 tez-api/src/main/proto/DAGApiRecords.proto      |   1 +
 .../org/apache/tez/dag/app/DAGAppMaster.java    |   1 -
 .../org/apache/tez/dag/app/dag/EdgeManager.java |  52 --
 .../java/org/apache/tez/dag/app/dag/Vertex.java |   6 +-
 .../apache/tez/dag/app/dag/VertexManager.java   |  40 --
 .../dag/app/dag/impl/BroadcastEdgeManager.java  |   4 +-
 .../org/apache/tez/dag/app/dag/impl/Edge.java   |   2 +-
 .../dag/impl/ImmediateStartVertexManager.java   |  30 +-
 .../dag/app/dag/impl/OneToOneEdgeManager.java   |   4 +-
 .../app/dag/impl/RootInputVertexManager.java    |  79 +--
 .../app/dag/impl/ScatterGatherEdgeManager.java  |   4 +-
 .../dag/app/dag/impl/ShuffleVertexManager.java  | 453 -----------------
 .../apache/tez/dag/app/dag/impl/VertexImpl.java |  96 ++--
 .../tez/dag/app/dag/impl/VertexManager.java     | 174 +++++++
 .../tez/dag/app/dag/impl/TestVertexImpl.java    |  38 +-
 .../tez/dag/app/dag/impl/TestVertexManager.java | 491 ------------------
 .../apache/tez/mapreduce/client/YARNRunner.java |   7 +
 tez-runtime-library/pom.xml                     |   5 +
 .../vertexmanager/ShuffleVertexManager.java     | 498 +++++++++++++++++++
 .../vertexmanager/TestShuffleVertexManager.java | 436 ++++++++++++++++
 28 files changed, 1594 insertions(+), 1175 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/DAG.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/DAG.java b/tez-api/src/main/java/org/apache/tez/dag/api/DAG.java
index 3d0a910..6440378 100644
--- a/tez-api/src/main/java/org/apache/tez/dag/api/DAG.java
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/DAG.java
@@ -413,6 +413,11 @@ public class DAG { // FIXME rename to Topology
           }
         }
       }
+      
+      if (vertex.getVertexManagerPlugin() != null) {
+        vertexBuilder.setVertexManagerPlugin(DagTypeConverters
+            .convertToDAGPlan(vertex.getVertexManagerPlugin()));
+      }
 
       for (String inEdgeId : vertex.getInputEdgeIds()) {
         vertexBuilder.addInEdgeId(inEdgeId);

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/DagTypeConverters.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/DagTypeConverters.java b/tez-api/src/main/java/org/apache/tez/dag/api/DagTypeConverters.java
index 098a201..f80f1db 100644
--- a/tez-api/src/main/java/org/apache/tez/dag/api/DagTypeConverters.java
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/DagTypeConverters.java
@@ -290,6 +290,16 @@ public class DagTypeConverters {
     }
     return new OutputDescriptor(className).setUserPayload(bb);
   }
+  
+  public static VertexManagerPluginDescriptor convertVertexManagerPluginDescriptorFromDAGPlan(
+      TezEntityDescriptorProto proto) {
+    String className = proto.getClassName();
+    byte[] bb = null;
+    if (proto.hasUserPayload()) {
+      bb = proto.getUserPayload().toByteArray();
+    }
+    return new VertexManagerPluginDescriptor(className).setUserPayload(bb);
+  }
 
   public static ProcessorDescriptor convertProcessorDescriptorFromDAGPlan(
       TezEntityDescriptorProto proto) {

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/EdgeManager.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/EdgeManager.java b/tez-api/src/main/java/org/apache/tez/dag/api/EdgeManager.java
new file mode 100644
index 0000000..c623264
--- /dev/null
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/EdgeManager.java
@@ -0,0 +1,94 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.tez.dag.api;
+
+import java.util.List;
+
+import org.apache.tez.runtime.api.events.DataMovementEvent;
+import org.apache.tez.runtime.api.events.InputFailedEvent;
+import org.apache.tez.runtime.api.events.InputReadErrorEvent;
+
+/**
+ * This interface defines the routing of the event between tasks of producer and 
+ * consumer vertices. The routing is bi-directional. Users can customize the 
+ * routing by providing an implementation of this interface.
+ */
+public interface EdgeManager {
+  
+  /**
+   * Get the number of inputs on the destination task
+   * @param numSourceTasks Total number of source tasks
+   * @param destinationTaskIndex Index of destination task for which number of 
+   * inputs is needed
+   * @return Number of inputs on the destination task
+   */
+  public int getNumDestinationTaskInputs(int numSourceTasks, 
+      int destinationTaskIndex);
+
+  /**
+   * Get the number of outputs on the source task
+   * @param numDestinationTasks Total number of destination tasks
+   * @param sourceTaskIndex Index of the source task for which number of outputs 
+   * is needed
+   * @return Number of outputs on the source task
+   */
+  public int getNumSourceTaskOutputs(int numDestinationTasks, 
+      int sourceTaskIndex);
+  
+  /**
+   * Return the destination task indeces that need to be sent an input available 
+   * event because the source task output is now available
+   * @param event Data movement event
+   * @param sourceTaskIndex Source task
+   * @param numDestinationTasks Total number of destination tasks
+   * @param taskIndices List into which the destination task indices is to be 
+   * returned
+   */
+  public void routeEventToDestinationTasks(DataMovementEvent event,
+      int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices);
+  
+  /**
+   * Return the destination task indeces that need to be sent an input failed 
+   * event because the source task output is no longer available
+   * @param event Input failed event
+   * @param sourceTaskIndex Failed source task
+   * @param numDestinationTasks Total number of destination tasks
+   * @param taskIndices List into which the destination task indices is to be 
+   * returned
+   */
+  public void routeEventToDestinationTasks(InputFailedEvent event,
+      int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices);
+
+  /**
+   * Get the number of destination tasks that consume data from the source task
+   * @sourceTaskIndex Source task index
+   * @numDestinationTasks Total number of destination tasks
+   */
+  public int getDestinationConsumerTaskNumber(int sourceTaskIndex, int numDestinationTasks);
+  
+  /**
+   * Return the source task index to which to send the input error event
+   * @param destinationTaskIndex Destination task that reported the error
+   * @param event Input read error event. Has more information about the error
+   * @return Index of the source task that created the unavailable input
+   */
+  public int routeEventToSourceTasks(int destinationTaskIndex,
+      InputReadErrorEvent event);
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java b/tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java
index 55bcedc..8561467 100644
--- a/tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java
@@ -104,37 +104,6 @@ public class TezConfiguration extends Configuration {
   public static final int TEZ_AM_RESOURCE_CPU_VCORES_DEFAULT = 1;
 
   public static final String
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION = TEZ_AM_PREFIX
-          + "shuffle-vertex-manager.min-src-fraction";
-  public static final float
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION_DEFAULT = 0.25f;
-
-  public static final String
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION = TEZ_AM_PREFIX
-          + "shuffle-vertex-manager.max-src-fraction";
-  public static final float
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION_DEFAULT = 0.75f;
-
-  public static final String
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL = TEZ_AM_PREFIX +
-          "shuffle-vertex-manager.enable.auto-parallel";
-  public static final boolean
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL_DEFAULT = false;
-
-  public static final String
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE = TEZ_AM_PREFIX +
-          "shuffle-vertex-manager.desired-task-input-size";
-  public static final long
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE_DEFAULT =
-          1024*1024*100L;
-
-  public static final String
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM = TEZ_AM_PREFIX +
-          "shuffle-vertex-manager.min-task-parallelism";
-  public static final int
-          TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM_DEFAULT = 1;
-
-  public static final String
           TEZ_AM_SLOWSTART_DAG_SCHEDULER_MIN_SHUFFLE_RESOURCE_FRACTION = TEZ_AM_PREFIX
           + "slowstart-dag-scheduler.min-resource-fraction";
   public static final float

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/Vertex.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/Vertex.java b/tez-api/src/main/java/org/apache/tez/dag/api/Vertex.java
index 4037fe5..7f1226b 100644
--- a/tez-api/src/main/java/org/apache/tez/dag/api/Vertex.java
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/Vertex.java
@@ -45,6 +45,7 @@ public class Vertex {
                       = new ArrayList<RootInputLeafOutput<InputDescriptor>>();
   private final List<RootInputLeafOutput<OutputDescriptor>> additionalOutputs 
                       = new ArrayList<RootInputLeafOutput<OutputDescriptor>>();
+  private VertexManagerPluginDescriptor vertexManagerPlugin;
 
   private final List<Vertex> inputVertices = new ArrayList<Vertex>();
   private final List<Vertex> outputVertices = new ArrayList<Vertex>();
@@ -191,6 +192,20 @@ public class Vertex {
   public Vertex addOutput(String outputName, OutputDescriptor outputDescriptor) {
     return addOutput(outputName, outputDescriptor, null);
   }
+  
+  /**
+   * Specifies a {@link VertexManagerPlugin} for the vertex. This plugin can be
+   * used to modify the parallelism or reconfigure the vertex at runtime using
+   * user defined code embedded in the plugin
+   * 
+   * @param vertexManagerPluginDescriptor
+   * @return Vertex
+   */
+  public Vertex setVertexManagerPlugin(
+      VertexManagerPluginDescriptor vertexManagerPluginDescriptor) {
+    this.vertexManagerPlugin = vertexManagerPluginDescriptor;
+    return this;
+  }
 
   public String getJavaOpts(){
 	  return javaOpts;
@@ -200,6 +215,10 @@ public class Vertex {
   public String toString() {
     return "[" + vertexName + " : " + processorDescriptor.getClassName() + "]";
   }
+  
+  VertexManagerPluginDescriptor getVertexManagerPlugin() {
+    return vertexManagerPlugin;
+  }
 
   void addInputVertex(Vertex inputVertex, String edgeId) {
     inputVertices.add(inputVertex);

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPlugin.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPlugin.java b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPlugin.java
new file mode 100644
index 0000000..602da3d
--- /dev/null
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPlugin.java
@@ -0,0 +1,69 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.tez.dag.api;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tez.runtime.api.Event;
+import org.apache.tez.runtime.api.events.VertexManagerEvent;
+
+/**
+ * Interface to plugin user logic into the VertexManager to implement runtime 
+ * scheduling optimizations and graph reconfiguration.
+ * The plugin will be notified of interesting events in the vertex execution life
+ * cycle and can respond to them by via the context object
+ */
+public interface VertexManagerPlugin {
+  /**
+   * Initialize the plugin. Called when the vertex is initializing. This happens 
+   * after all source vertices and inputs have initialized
+   * @param payload
+   * @param context
+   */
+  public void initialize(byte[] payload, VertexManagerPluginContext context);
+
+  /**
+   * Notification that the vertex is ready to start running tasks
+   * @param completions Source vertices and all their tasks that have already completed
+   */
+  public void onVertexStarted(Map<String, List<Integer>> completions);
+
+  /**
+   * Notification of a source vertex completion.
+   * @param srcVertexName
+   * @param taskId Index of the task that completed
+   */
+  public void onSourceTaskCompleted(String srcVertexName, Integer taskId);
+
+  /**
+   * Notification of an event directly sent to this vertex manager
+   * @param vmEvent
+   */
+  public void onVertexManagerEventReceived(VertexManagerEvent vmEvent);
+
+  /**
+   * Notification that the inputs of this vertex have initialized
+   * @param inputName
+   * @param inputDescriptor
+   * @param events
+   */
+  public void onRootVertexInitialized(String inputName,
+      InputDescriptor inputDescriptor, List<Event> events);
+ }

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginContext.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginContext.java b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginContext.java
new file mode 100644
index 0000000..47d2a22
--- /dev/null
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginContext.java
@@ -0,0 +1,81 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.tez.dag.api;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Object with API's to interact with the Tez execution engine
+ */
+public interface VertexManagerPluginContext {
+  
+  /**
+   * Get the edge properties on the input edges of this vertex. The input edge 
+   * is represented by the source vertex name
+   * @return Map of source vertex name and edge property
+   */
+  public Map<String, EdgeProperty> getInputVertexEdgeProperties();
+  
+  /**
+   * Get the name of the vertex
+   * @return Vertex name
+   */
+  public String getVertexName();
+  
+  /**
+   * Get the number of tasks in the given vertex
+   * @param vertexName
+   * @return Total number of tasks in this vertex
+   */
+  public int getVertexNumTasks(String vertexName);
+  
+  /**
+   * Set the new parallelism (number of tasks) of this vertex.
+   * Map of source (input) vertices and edge managers to change the event routing
+   * between the source tasks and the new destination tasks.
+   * This API can change the parallelism only once. Subsequent attempts will be 
+   * disallowed
+   * @param parallelism New number of tasks in the vertex
+   * @param sourceEdgeManagers
+   * @return true if the operation was allowed.
+   */
+  public boolean setVertexParallelism(int parallelism, 
+      Map<String, EdgeManager> sourceEdgeManagers);
+  
+  /**
+   * Notify the vertex to start the given tasks
+   * @param taskIDs Indices of the tasks to be started
+   */
+  public void scheduleVertexTasks(List<Integer> taskIDs);
+
+  /**
+   * Get the names of the non-vertex inputs of this vertex. These are primary 
+   * sources of data.
+   * @return Names of inputs to this vertex. Maybe null if there are no inputs
+   */
+  public Set<String> getVertexInputNames();
+  
+  /**
+   * Set the placement hint for tasks in this vertex
+   * @param locationHint
+   */
+  public void setVertexLocationHint(VertexLocationHint locationHint);
+}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginDescriptor.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginDescriptor.java b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginDescriptor.java
new file mode 100644
index 0000000..807b7bb
--- /dev/null
+++ b/tez-api/src/main/java/org/apache/tez/dag/api/VertexManagerPluginDescriptor.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tez.dag.api;
+
+import org.apache.hadoop.classification.InterfaceAudience.Private;
+
+public class VertexManagerPluginDescriptor extends TezEntityDescriptor {
+
+  @Private // for Writable
+  public VertexManagerPluginDescriptor() {
+    super();
+  }
+  
+  public VertexManagerPluginDescriptor(String outputClassName) {
+    super(outputClassName);
+  }
+
+  @Override
+  public VertexManagerPluginDescriptor setUserPayload(byte[] userPayload) {
+    this.userPayload = userPayload;
+    return this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-api/src/main/proto/DAGApiRecords.proto
----------------------------------------------------------------------
diff --git a/tez-api/src/main/proto/DAGApiRecords.proto b/tez-api/src/main/proto/DAGApiRecords.proto
index 9ce51a1..aae4e63 100644
--- a/tez-api/src/main/proto/DAGApiRecords.proto
+++ b/tez-api/src/main/proto/DAGApiRecords.proto
@@ -118,6 +118,7 @@ message VertexPlan {
   repeated string outEdgeId = 7;
   repeated RootInputLeafOutputProto inputs = 8;
   repeated RootInputLeafOutputProto outputs = 9;
+  optional TezEntityDescriptorProto vertex_manager_plugin = 10;
 }
 
 message EdgePlan {

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
index 6469a78..116bf17 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
@@ -35,7 +35,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/EdgeManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/EdgeManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/EdgeManager.java
deleted file mode 100644
index 86d155f..0000000
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/EdgeManager.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tez.dag.app.dag;
-
-import java.util.List;
-
-import org.apache.tez.runtime.api.events.DataMovementEvent;
-import org.apache.tez.runtime.api.events.InputFailedEvent;
-import org.apache.tez.runtime.api.events.InputReadErrorEvent;
-
-public abstract class EdgeManager {
-  
-  public abstract int getNumDestinationTaskInputs(int numSourceTasks, 
-      int destinationTaskIndex);
-
-  public abstract int getNumSourceTaskOutputs(int numDestinationTasks, 
-      int sourceTaskIndex);
-  
-  /**
-   * Return the destination task indeces to which to send the event
-   */
-  public abstract void routeEventToDestinationTasks(DataMovementEvent event,
-      int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices);
-  
-  public abstract void routeEventToDestinationTasks(InputFailedEvent event,
-      int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices);
-
-  public abstract int getDestinationConsumerTaskNumber(int sourceTaskIndex, int numDestTasks);
-  
-  /**
-   * Return the source task index to which to send the event
-   */
-  public abstract int routeEventToSourceTasks(int destinationTaskIndex,
-      InputReadErrorEvent event);
-  
-}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/Vertex.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/Vertex.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/Vertex.java
index 737091a..9503058 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/Vertex.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/Vertex.java
@@ -18,13 +18,13 @@
 
 package org.apache.tez.dag.app.dag;
 
-import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.tez.common.counters.TezCounters;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.dag.api.InputDescriptor;
 import org.apache.tez.dag.api.OutputDescriptor;
 import org.apache.tez.dag.api.ProcessorDescriptor;
@@ -73,7 +73,7 @@ public interface Vertex extends Comparable<Vertex> {
   VertexStatusBuilder getVertexStatus(Set<StatusGetOpts> statusOptions);
 
 
-  void setParallelism(int parallelism, Map<Vertex, EdgeManager> sourceEdgeManagers);
+  boolean setParallelism(int parallelism, Map<String, EdgeManager> sourceEdgeManagers);
   void setVertexLocationHint(VertexLocationHint vertexLocationHint);
 
   // CHANGE THESE TO LISTS AND MAINTAIN ORDER?
@@ -94,7 +94,7 @@ public interface Vertex extends Comparable<Vertex> {
 
   int getInputVerticesCount();
   int getOutputVerticesCount();
-  void scheduleTasks(Collection<TezTaskID> taskIDs);
+  void scheduleTasks(List<Integer> taskIDs);
   Resource getTaskResource();
 
   ProcessorDescriptor getProcessorDescriptor();

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/VertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/VertexManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/VertexManager.java
deleted file mode 100644
index 80b6f69..0000000
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/VertexManager.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tez.dag.app.dag;
-
-import java.util.List;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.tez.dag.api.InputDescriptor;
-import org.apache.tez.dag.records.TezTaskAttemptID;
-import org.apache.tez.runtime.api.Event;
-import org.apache.tez.runtime.api.events.VertexManagerEvent;
-
-public abstract class VertexManager {
-  public abstract void initialize(Configuration conf);
-
-  public abstract void onVertexStarted(List<TezTaskAttemptID> completions);
-
-  public abstract void onSourceTaskCompleted(TezTaskAttemptID attemptId);
-
-  public abstract void onVertexManagerEventReceived(VertexManagerEvent vmEvent);
-
-  public abstract void onRootVertexInitialized(String inputName, 
-      InputDescriptor inputDescriptor, List<Event> events);
-}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/BroadcastEdgeManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/BroadcastEdgeManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/BroadcastEdgeManager.java
index fedc630..5893a74 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/BroadcastEdgeManager.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/BroadcastEdgeManager.java
@@ -20,12 +20,12 @@ package org.apache.tez.dag.app.dag.impl;
 
 import java.util.List;
 
-import org.apache.tez.dag.app.dag.EdgeManager;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.runtime.api.events.DataMovementEvent;
 import org.apache.tez.runtime.api.events.InputReadErrorEvent;
 import org.apache.tez.runtime.api.events.InputFailedEvent;
 
-public class BroadcastEdgeManager extends EdgeManager {
+public class BroadcastEdgeManager implements EdgeManager {
 
   @Override
   public int getNumDestinationTaskInputs(int numSourceTasks, 

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/Edge.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/Edge.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/Edge.java
index 0e480d4..9073966 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/Edge.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/Edge.java
@@ -23,9 +23,9 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.dag.api.EdgeProperty;
 import org.apache.tez.dag.api.TezUncheckedException;
-import org.apache.tez.dag.app.dag.EdgeManager;
 import org.apache.tez.dag.app.dag.Task;
 import org.apache.tez.dag.app.dag.Vertex;
 import org.apache.tez.dag.app.dag.event.TaskAttemptEventOutputFailed;

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ImmediateStartVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ImmediateStartVertexManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ImmediateStartVertexManager.java
index 9c6b0bf..92c1938 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ImmediateStartVertexManager.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ImmediateStartVertexManager.java
@@ -18,37 +18,43 @@
 
 package org.apache.tez.dag.app.dag.impl;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
-import org.apache.hadoop.conf.Configuration;
 import org.apache.tez.dag.api.InputDescriptor;
-import org.apache.tez.dag.app.dag.Vertex;
-import org.apache.tez.dag.app.dag.VertexManager;
-import org.apache.tez.dag.records.TezTaskAttemptID;
+import org.apache.tez.dag.api.VertexManagerPlugin;
+import org.apache.tez.dag.api.VertexManagerPluginContext;
 import org.apache.tez.runtime.api.Event;
 import org.apache.tez.runtime.api.events.VertexManagerEvent;
 
 /**
  * Starts all tasks immediately on vertex start
  */
-public class ImmediateStartVertexManager extends VertexManager {
-  final Vertex managedVertex;
+public class ImmediateStartVertexManager implements VertexManagerPlugin {
   
-  ImmediateStartVertexManager(Vertex vertex) {
-    managedVertex = vertex;
+  private VertexManagerPluginContext context;
+  
+  ImmediateStartVertexManager() {
   }
   
   @Override
-  public void onVertexStarted(List<TezTaskAttemptID> completions) {
-    managedVertex.scheduleTasks(managedVertex.getTasks().keySet());
+  public void onVertexStarted(Map<String, List<Integer>> completions) {
+    int numTasks = context.getVertexNumTasks(context.getVertexName());
+    List<Integer> scheduledTasks = new ArrayList<Integer>(numTasks);
+    for (int i=0; i<numTasks; ++i) {
+      scheduledTasks.add(new Integer(i));
+    }
+    context.scheduleVertexTasks(scheduledTasks);
   }
 
   @Override
-  public void onSourceTaskCompleted(TezTaskAttemptID attemptId) {
+  public void onSourceTaskCompleted(String srcVertexName, Integer attemptId) {
   }
 
   @Override
-  public void initialize(Configuration conf) {    
+  public void initialize(byte[] payload, VertexManagerPluginContext context) {
+    this.context = context;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/OneToOneEdgeManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/OneToOneEdgeManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/OneToOneEdgeManager.java
index 1ec9451..cb5feb2 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/OneToOneEdgeManager.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/OneToOneEdgeManager.java
@@ -20,12 +20,12 @@ package org.apache.tez.dag.app.dag.impl;
 
 import java.util.List;
 
-import org.apache.tez.dag.app.dag.EdgeManager;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.runtime.api.events.DataMovementEvent;
 import org.apache.tez.runtime.api.events.InputReadErrorEvent;
 import org.apache.tez.runtime.api.events.InputFailedEvent;
 
-public class OneToOneEdgeManager extends EdgeManager {
+public class OneToOneEdgeManager implements EdgeManager {
 
   @Override
   public int getNumDestinationTaskInputs(int numDestinationTasks, 

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/RootInputVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/RootInputVertexManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/RootInputVertexManager.java
index ca27c87..fec97d2 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/RootInputVertexManager.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/RootInputVertexManager.java
@@ -18,19 +18,18 @@
 
 package org.apache.tez.dag.app.dag.impl;
 
-import java.util.EnumSet;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
-import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.yarn.event.EventHandler;
 import org.apache.tez.dag.api.InputDescriptor;
 import org.apache.tez.dag.api.VertexLocationHint;
+import org.apache.tez.dag.api.VertexManagerPlugin;
+import org.apache.tez.dag.api.VertexManagerPluginContext;
 import org.apache.tez.dag.app.dag.Vertex;
-import org.apache.tez.dag.app.dag.VertexManager;
-import org.apache.tez.dag.app.dag.VertexState;
 import org.apache.tez.dag.app.dag.event.TaskEventAddTezEvent;
-import org.apache.tez.dag.records.TezTaskAttemptID;
 import org.apache.tez.dag.records.TezTaskID;
 import org.apache.tez.runtime.api.Event;
 import org.apache.tez.runtime.api.events.RootInputConfigureVertexTasksEvent;
@@ -44,42 +43,48 @@ import org.apache.tez.runtime.api.impl.TezEvent;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 
-public class RootInputVertexManager extends VertexManager {
+@SuppressWarnings("rawtypes")
+public class RootInputVertexManager implements VertexManagerPlugin {
+
+  VertexManagerPluginContext context;
+  private EventMetaData sourceInfo;
+  private Map<String, EventMetaData> destInfoMap;
   
-  private final Vertex managedVertex;
-  private final EventMetaData sourceInfo;
-  private final Map<String, EventMetaData> destInfoMap;
-  @SuppressWarnings("rawtypes")
-  private final EventHandler eventHandler;
+  Vertex deleteVertex;
+  EventHandler deleteHandler;
   
-  @SuppressWarnings("rawtypes")
-  public RootInputVertexManager(Vertex vertex, EventHandler eventHandler) {
-    this.managedVertex = vertex;
-    this.eventHandler = eventHandler;
-    this.sourceInfo = new EventMetaData(EventProducerConsumerType.INPUT,
-        vertex.getName(), "NULL", null);
-    Map<String, RootInputLeafOutputDescriptor<InputDescriptor>> inputs = this.managedVertex
-        .getAdditionalInputs();
-    this.destInfoMap = Maps.newHashMapWithExpectedSize(inputs.size());
-    for (RootInputLeafOutputDescriptor input : inputs.values()) {
-      EventMetaData destInfo = new EventMetaData(
-          EventProducerConsumerType.INPUT, vertex.getName(),
-          input.getEntityName(), null);
-      destInfoMap.put(input.getEntityName(), destInfo);
-    }
+  public RootInputVertexManager(Vertex v, EventHandler h) {
+    deleteVertex = v;
+    deleteHandler = h;
   }
 
   @Override
-  public void initialize(Configuration conf) {
+  public void initialize(byte[] payload, VertexManagerPluginContext context) {
+    this.context = context;
+    Set<String> inputs = this.context.getVertexInputNames();
+    this.destInfoMap = Maps.newHashMapWithExpectedSize(inputs.size());
+    for (String inputName : inputs) {
+      EventMetaData destInfo = new EventMetaData(
+          EventProducerConsumerType.INPUT, context.getVertexName(),
+          inputName, null);
+      destInfoMap.put(inputName, destInfo);
+    }
+    this.sourceInfo = new EventMetaData(EventProducerConsumerType.INPUT,
+        context.getVertexName(), "NULL", null);
   }
 
   @Override
-  public void onVertexStarted(List<TezTaskAttemptID> completions) {
-    managedVertex.scheduleTasks(managedVertex.getTasks().keySet());
+  public void onVertexStarted(Map<String, List<Integer>> completions) {
+    int numTasks = context.getVertexNumTasks(context.getVertexName());
+    List<Integer> scheduledTasks = new ArrayList<Integer>(numTasks);
+    for (int i=0; i<numTasks; ++i) {
+      scheduledTasks.add(new Integer(i));
+    }
+    context.scheduleVertexTasks(scheduledTasks);
   }
 
   @Override
-  public void onSourceTaskCompleted(TezTaskAttemptID attemptId) {
+  public void onSourceTaskCompleted(String srcVertexName, Integer attemptId) {
   }
 
   @Override
@@ -90,20 +95,18 @@ public class RootInputVertexManager extends VertexManager {
   public void onRootVertexInitialized(String inputName,
       InputDescriptor inputDescriptor, List<Event> events) {
     boolean dataInformationEventSeen = false;
-    Preconditions.checkState(EnumSet.of(VertexState.INITIALIZING,
-        VertexState.NEW).contains(managedVertex.getState()));
     for (Event event : events) {
       if (event instanceof RootInputConfigureVertexTasksEvent) {
         // No tasks should have been started yet. Checked by initial state check.
         Preconditions.checkState(dataInformationEventSeen == false);
         Preconditions
             .checkState(
-                managedVertex.getTotalTasks() == -1,
+                context.getVertexNumTasks(context.getVertexName()) == -1,
                 "Parallelism for the vertex should be set to -1 if the InputInitializer is setting parallelism");
         RootInputConfigureVertexTasksEvent cEvent = (RootInputConfigureVertexTasksEvent) event;
-        managedVertex.setVertexLocationHint(new VertexLocationHint(cEvent
+        context.setVertexLocationHint(new VertexLocationHint(cEvent
             .getNumTasks(), cEvent.getTaskLocationHints()));
-        managedVertex.setParallelism(cEvent.getNumTasks(), null);
+        context.setVertexParallelism(cEvent.getNumTasks(), null);
       }
       if (event instanceof RootInputUpdatePayloadEvent) {
         // No tasks should have been started yet. Checked by initial state check.
@@ -113,10 +116,10 @@ public class RootInputVertexManager extends VertexManager {
       } else if (event instanceof RootInputDataInformationEvent) {
         dataInformationEventSeen = true;
         // # Tasks should have been set by this point.
-        Preconditions.checkState(managedVertex.getTasks().size() != 0);
+        Preconditions.checkState(context.getVertexNumTasks(context.getVertexName()) != 0);
         TezEvent tezEvent = new TezEvent(event, sourceInfo);
         tezEvent.setDestinationInfo(destInfoMap.get(inputName));
-        sendEventToTask(TezTaskID.getInstance(managedVertex.getVertexId(),
+        sendEventToTask(TezTaskID.getInstance(deleteVertex.getVertexId(),
             ((RootInputDataInformationEvent) event).getIndex()), tezEvent);
       }
     }
@@ -124,7 +127,7 @@ public class RootInputVertexManager extends VertexManager {
 
   @SuppressWarnings("unchecked")
   private void sendEventToTask(TezTaskID taskId, TezEvent tezEvent) {
-    eventHandler.handle(new TaskEventAddTezEvent(taskId, tezEvent));
+    deleteHandler.handle(new TaskEventAddTezEvent(taskId, tezEvent));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ScatterGatherEdgeManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ScatterGatherEdgeManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ScatterGatherEdgeManager.java
index b1dd475..c9f0503 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ScatterGatherEdgeManager.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ScatterGatherEdgeManager.java
@@ -20,12 +20,12 @@ package org.apache.tez.dag.app.dag.impl;
 
 import java.util.List;
 
-import org.apache.tez.dag.app.dag.EdgeManager;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.runtime.api.events.DataMovementEvent;
 import org.apache.tez.runtime.api.events.InputReadErrorEvent;
 import org.apache.tez.runtime.api.events.InputFailedEvent;
 
-public class ScatterGatherEdgeManager extends EdgeManager {
+public class ScatterGatherEdgeManager implements EdgeManager {
 
   @Override
   public int getNumDestinationTaskInputs(int numSourceTasks,

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ShuffleVertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ShuffleVertexManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ShuffleVertexManager.java
deleted file mode 100644
index f9e6a89..0000000
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/ShuffleVertexManager.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/**
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tez.dag.app.dag.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.tez.dag.api.InputDescriptor;
-import org.apache.tez.dag.api.TezConfiguration;
-import org.apache.tez.dag.api.TezUncheckedException;
-import org.apache.tez.dag.api.EdgeProperty.DataMovementType;
-import org.apache.tez.dag.app.dag.EdgeManager;
-import org.apache.tez.dag.app.dag.Vertex;
-import org.apache.tez.dag.app.dag.VertexManager;
-import org.apache.tez.dag.records.TezTaskAttemptID;
-import org.apache.tez.dag.records.TezTaskID;
-import org.apache.tez.dag.records.TezVertexID;
-import org.apache.tez.runtime.api.Event;
-import org.apache.tez.runtime.api.events.DataMovementEvent;
-import org.apache.tez.runtime.api.events.InputFailedEvent;
-import org.apache.tez.runtime.api.events.InputReadErrorEvent;
-import org.apache.tez.runtime.api.events.VertexManagerEvent;
-import org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.VertexManagerEventPayloadProto;
-
-import com.google.protobuf.InvalidProtocolBufferException;
-
-/**
- * Starts scheduling tasks when number of completed source tasks crosses 
- * <code>slowStartMinSrcCompletionFraction</code> and schedules all tasks 
- *  when <code>slowStartMaxSrcCompletionFraction</code> is reached
- */
-public class ShuffleVertexManager extends VertexManager {
-  
-  private static final Log LOG = 
-                   LogFactory.getLog(ShuffleVertexManager.class);
-
-  final Vertex managedVertex;
-  float slowStartMinSrcCompletionFraction;
-  float slowStartMaxSrcCompletionFraction;
-  long desiredTaskInputDataSize = 1024*1024*100L;
-  int minTaskParallelism = 1;
-  boolean enableAutoParallelism = false;
-  boolean parallelismDetermined = false;
-  
-  int numSourceTasks = 0;
-  int numSourceTasksCompleted = 0;
-  int numVertexManagerEventsReceived = 0;
-  ArrayList<TezTaskID> pendingTasks;
-  int totalTasksToSchedule = 0;
-  HashMap<TezVertexID, Vertex> bipartiteSources = 
-                                            new HashMap<TezVertexID, Vertex>();
-  
-  Set<TezTaskID> completedSourceTasks = new HashSet<TezTaskID>();
-  long completedSourceTasksOutputSize = 0;
-  
-  public ShuffleVertexManager(Vertex managedVertex) {
-    this.managedVertex = managedVertex;
-    Map<Vertex, Edge> inputs = managedVertex.getInputVertices();
-    for(Map.Entry<Vertex, Edge> entry : inputs.entrySet()) {
-      if (entry.getValue().getEdgeProperty().getDataMovementType() == 
-          DataMovementType.SCATTER_GATHER) {
-        Vertex vertex = entry.getKey();
-        bipartiteSources.put(vertex.getVertexId(), vertex);
-      }
-    }
-    if(bipartiteSources.isEmpty()) {
-      throw new TezUncheckedException("Atleast 1 bipartite source should exist");
-    }
-    // dont track the source tasks here since those tasks may themselves be
-    // dynamically changed as the DAG progresses.
-  }
-  
-  
-  public class CustomShuffleEdgeManager extends EdgeManager {
-    int numSourceTaskOutputs;
-    int numDestinationTasks;
-    int basePartitionRange;
-    int remainderRangeForLastShuffler;
-    
-    CustomShuffleEdgeManager(int numSourceTaskOutputs, int numDestinationTasks,
-        int basePartitionRange, int remainderPartitionForLastShuffler) {
-      this.numSourceTaskOutputs = numSourceTaskOutputs;
-      this.numDestinationTasks = numDestinationTasks;
-      this.basePartitionRange = basePartitionRange;
-      this.remainderRangeForLastShuffler = remainderPartitionForLastShuffler;
-    }
-
-    @Override
-    public int getNumDestinationTaskInputs(int numSourceTasks, 
-        int destinationTaskIndex) {
-      int partitionRange = 1;
-      if(destinationTaskIndex < numDestinationTasks-1) {
-        partitionRange = basePartitionRange;
-      } else {
-        partitionRange = remainderRangeForLastShuffler;
-      }
-      return numSourceTasks * partitionRange;
-    }
-
-    @Override
-    public int getNumSourceTaskOutputs(int numDestinationTasks, 
-        int sourceTaskIndex) {
-      return numSourceTaskOutputs;
-    }
-    
-    @Override
-    public void routeEventToDestinationTasks(DataMovementEvent event,
-        int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices) {
-      int sourceIndex = event.getSourceIndex();
-      int destinationTaskIndex = sourceIndex/basePartitionRange;
-      int partitionRange = 1;
-      if(destinationTaskIndex < numDestinationTasks-1) {
-        partitionRange = basePartitionRange;
-      } else {
-        partitionRange = remainderRangeForLastShuffler;
-      }
-      
-      // all inputs from a source task are next to each other in original order
-      int targetIndex = 
-          sourceTaskIndex * partitionRange 
-          + sourceIndex % partitionRange;
-      
-      event.setTargetIndex(targetIndex);
-      taskIndices.add(new Integer(destinationTaskIndex));
-    }
-
-    @Override
-    public void routeEventToDestinationTasks(InputFailedEvent event,
-        int sourceTaskIndex, int numDestinationTasks, List<Integer> taskIndices) {
-      int sourceIndex = event.getSourceIndex();
-      int destinationTaskIndex = sourceIndex/basePartitionRange;
-      int partitionRange = 1;
-      if(destinationTaskIndex < numDestinationTasks-1) {
-        partitionRange = basePartitionRange;
-      } else {
-        partitionRange = remainderRangeForLastShuffler;
-      }
-      int targetIndex = 
-          sourceTaskIndex * partitionRange 
-          + sourceIndex % partitionRange;
-      
-      event.setTargetIndex(targetIndex);
-      taskIndices.add(new Integer(destinationTaskIndex));
-    }
-
-    @Override
-    public int routeEventToSourceTasks(int destinationTaskIndex,
-        InputReadErrorEvent event) {
-      int partitionRange = 1;
-      if(destinationTaskIndex < numDestinationTasks-1) {
-        partitionRange = basePartitionRange;
-      } else {
-        partitionRange = remainderRangeForLastShuffler;
-      }
-      return event.getIndex()/partitionRange;
-    }
-
-    @Override
-    public int getDestinationConsumerTaskNumber(int sourceTaskIndex,
-        int numDestTasks) {
-      return numDestTasks;
-    }
-  }
-
-  
-  @Override
-  public void onVertexStarted(List<TezTaskAttemptID> completions) {
-    pendingTasks = new ArrayList<TezTaskID>(managedVertex.getTotalTasks());
-    // track the tasks in this vertex
-    updatePendingTasks();
-    updateSourceTaskCount();
-    
-    LOG.info("OnVertexStarted vertex: " + managedVertex.getVertexId() + 
-             " with " + numSourceTasks + " source tasks and " + 
-             totalTasksToSchedule + " pending tasks");
-    
-    if (completions != null) {
-      for (TezTaskAttemptID srcAttemptId : completions) {
-        onSourceTaskCompleted(srcAttemptId);
-      }
-    }
-    // for the special case when source has 0 tasks or min fraction == 0
-    schedulePendingTasks();
-  }
-
-  @Override
-  public void onSourceTaskCompleted(TezTaskAttemptID srcAttemptId) {
-    updateSourceTaskCount();
-    TezTaskID srcTaskId = srcAttemptId.getTaskID();
-    TezVertexID srcVertexId = srcTaskId.getVertexID();
-    if (bipartiteSources.containsKey(srcVertexId)) {
-      // duplicate notifications tracking
-      if (completedSourceTasks.add(srcTaskId)) {
-        // source task has completed
-        ++numSourceTasksCompleted;
-      }
-      schedulePendingTasks();
-    }
-  }
-  
-  @Override
-  public void onVertexManagerEventReceived(VertexManagerEvent vmEvent) {
-    // TODO handle duplicates from retries
-    if (enableAutoParallelism) {
-      // save output size
-      VertexManagerEventPayloadProto proto;
-      try {
-        proto = VertexManagerEventPayloadProto.parseFrom(vmEvent.getUserPayload());
-      } catch (InvalidProtocolBufferException e) {
-        throw new TezUncheckedException(e);
-      }
-      long sourceTaskOutputSize = proto.getOutputSize();
-      numVertexManagerEventsReceived++;
-      completedSourceTasksOutputSize += sourceTaskOutputSize;
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Received info of output size: " + sourceTaskOutputSize 
-            + " numInfoReceived: " + numVertexManagerEventsReceived
-            + " total output size: " + completedSourceTasksOutputSize);
-      }
-    }
-    
-  }
-  
-  void updatePendingTasks() {
-    pendingTasks.clear();
-    pendingTasks.addAll(managedVertex.getTasks().keySet());
-    totalTasksToSchedule = pendingTasks.size();
-  }
-  
-  void updateSourceTaskCount() {
-    // track source vertices
-    int numSrcTasks = 0;
-    for(Vertex vertex : bipartiteSources.values()) {
-      numSrcTasks += vertex.getTotalTasks();
-    }
-    numSourceTasks = numSrcTasks;
-  }
-
-  void determineParallelismAndApply() {
-    if(numSourceTasksCompleted == 0) {
-      return;
-    }
-    
-    if(numVertexManagerEventsReceived == 0) {
-      return;
-    }
-    
-    int currentParallelism = pendingTasks.size();
-    long expectedTotalSourceTasksOutputSize = 
-        (numSourceTasks*completedSourceTasksOutputSize)/numVertexManagerEventsReceived;
-    int desiredTaskParallelism = 
-        (int)(
-            (expectedTotalSourceTasksOutputSize+desiredTaskInputDataSize-1)/
-            desiredTaskInputDataSize);
-    if(desiredTaskParallelism < minTaskParallelism) {
-      desiredTaskParallelism = minTaskParallelism;
-    }
-    
-    if(desiredTaskParallelism >= currentParallelism) {
-      return;
-    }
-    
-    // most shufflers will be assigned this range
-    int basePartitionRange = currentParallelism/desiredTaskParallelism;
-    
-    if (basePartitionRange <= 1) {
-      // nothing to do if range is equal 1 partition. shuffler does it by default
-      return;
-    }
-    
-    int numShufflersWithBaseRange = currentParallelism / basePartitionRange;
-    int remainderRangeForLastShuffler = currentParallelism % basePartitionRange; 
-    
-    int finalTaskParallelism = (remainderRangeForLastShuffler > 0) ?
-          (numShufflersWithBaseRange + 1) : (numShufflersWithBaseRange);
-
-    LOG.info("Reduce auto parallelism for vertex: " + managedVertex.getVertexId() 
-        + " to " + finalTaskParallelism + " from " + pendingTasks.size() 
-        + " . Expected output: " + expectedTotalSourceTasksOutputSize 
-        + " based on actual output: " + completedSourceTasksOutputSize
-        + " from " + numVertexManagerEventsReceived + " vertex manager events. "
-        + " desiredTaskInputSize: " + desiredTaskInputDataSize);
-          
-    if(finalTaskParallelism < currentParallelism) {
-      // final parallelism is less than actual parallelism
-      Map<Vertex, EdgeManager> edgeManagers = new HashMap<Vertex, EdgeManager>(
-          bipartiteSources.size());
-      for(Vertex vertex : bipartiteSources.values()) {
-        // use currentParallelism for numSourceTasks to maintain original state
-        // for the source tasks
-        edgeManagers.put(vertex, new CustomShuffleEdgeManager(
-            currentParallelism, finalTaskParallelism, basePartitionRange,
-            ((remainderRangeForLastShuffler > 0) ?
-                remainderRangeForLastShuffler : basePartitionRange)));
-      }
-      
-      managedVertex.setParallelism(finalTaskParallelism, edgeManagers);
-      updatePendingTasks();      
-    }
-  }
-  
-  void schedulePendingTasks(int numTasksToSchedule) {
-    // determine parallelism before scheduling the first time
-    // this is the latest we can wait before determining parallelism.
-    // currently this depends on task completion and so this is the best time
-    // to do this. This is the max time we have until we have to launch tasks 
-    // as specified by the user. If/When we move to some other method of 
-    // calculating parallelism or change parallelism while tasks are already
-    // running then we can create other parameters to trigger this calculation.
-    if(enableAutoParallelism && !parallelismDetermined) {
-      // do this once
-      parallelismDetermined = true;
-      determineParallelismAndApply();
-    }
-    ArrayList<TezTaskID> scheduledTasks = new ArrayList<TezTaskID>(numTasksToSchedule);
-    while(!pendingTasks.isEmpty() && numTasksToSchedule > 0) {
-      numTasksToSchedule--;
-      scheduledTasks.add(pendingTasks.get(0));
-      pendingTasks.remove(0);
-    }
-    managedVertex.scheduleTasks(scheduledTasks);
-  }
-  
-  void schedulePendingTasks() {    
-    int numPendingTasks = pendingTasks.size();
-    if (numPendingTasks == 0) {
-      return;
-    }
-    
-    if (numSourceTasksCompleted == numSourceTasks && numPendingTasks > 0) {
-      LOG.info("All source tasks assigned. " +
-          "Ramping up " + numPendingTasks + 
-          " remaining tasks for vertex: " + managedVertex.getName());
-      schedulePendingTasks(numPendingTasks);
-      return;
-    }
-
-    float completedSourceTaskFraction = 0f;
-    if (numSourceTasks != 0) { // support for 0 source tasks
-      completedSourceTaskFraction = (float)numSourceTasksCompleted/numSourceTasks;
-    } else {
-      completedSourceTaskFraction = 1;
-    }
-    
-    // start scheduling when source tasks completed fraction is more than min.
-    // linearly increase the number of scheduled tasks such that all tasks are 
-    // scheduled when source tasks completed fraction reaches max
-    float tasksFractionToSchedule = 1; 
-    float percentRange = slowStartMaxSrcCompletionFraction - 
-                          slowStartMinSrcCompletionFraction;
-    if (percentRange > 0) {
-      tasksFractionToSchedule = 
-            (completedSourceTaskFraction - slowStartMinSrcCompletionFraction)/
-            percentRange;
-    } else {
-      // min and max are equal. schedule 100% on reaching min
-      if(completedSourceTaskFraction < slowStartMinSrcCompletionFraction) {
-        tasksFractionToSchedule = 0;
-      }
-    }
-    
-    if (tasksFractionToSchedule > 1) {
-      tasksFractionToSchedule = 1;
-    } else if (tasksFractionToSchedule < 0) {
-      tasksFractionToSchedule = 0;
-    }
-    
-    int numTasksToSchedule = 
-        ((int)(tasksFractionToSchedule * totalTasksToSchedule) - 
-         (totalTasksToSchedule - numPendingTasks));
-    
-    if (numTasksToSchedule > 0) {
-      // numTasksToSchedule can be -ve if numSourceTasksCompleted does not 
-      // does not increase monotonically
-      LOG.info("Scheduling " + numTasksToSchedule + " tasks for vertex: " + 
-               managedVertex.getVertexId() + " with totalTasks: " + 
-               totalTasksToSchedule + ". " + numSourceTasksCompleted + 
-               " source tasks completed out of " + numSourceTasks + 
-               ". SourceTaskCompletedFraction: " + completedSourceTaskFraction + 
-               " min: " + slowStartMinSrcCompletionFraction + 
-               " max: " + slowStartMaxSrcCompletionFraction);
-      schedulePendingTasks(numTasksToSchedule);
-    }
-  }
-
-  @Override
-  public void initialize(Configuration conf) {
-    this.slowStartMinSrcCompletionFraction = conf
-        .getFloat(
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION,
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_SRC_FRACTION_DEFAULT);
-    this.slowStartMaxSrcCompletionFraction = conf
-        .getFloat(
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION,
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MAX_SRC_FRACTION_DEFAULT);
-    
-    if(slowStartMinSrcCompletionFraction < 0 || 
-       slowStartMaxSrcCompletionFraction < slowStartMinSrcCompletionFraction) {
-      throw new IllegalArgumentException(
-          "Invalid values for slowStartMinSrcCompletionFraction" + 
-          "/slowStartMaxSrcCompletionFraction. Min cannot be < 0 and " + 
-          "max cannot be < min.");
-    }
-    
-    enableAutoParallelism = conf
-        .getBoolean(
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL,
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_ENABLE_AUTO_PARALLEL_DEFAULT);
-    desiredTaskInputDataSize = conf
-        .getLong(
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE,
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_DESIRED_TASK_INPUT_SIZE_DEFAULT);
-    minTaskParallelism = conf.getInt(
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM,
-            TezConfiguration.TEZ_AM_SHUFFLE_VERTEX_MANAGER_MIN_TASK_PARALLELISM_DEFAULT);
-    LOG.info("Shuffle Vertex Manager: settings" + 
-            " minFrac:" + slowStartMinSrcCompletionFraction +
-            " maxFrac:" + slowStartMaxSrcCompletionFraction +
-            " auto:" + enableAutoParallelism + 
-            " desiredTaskIput:" + desiredTaskInputDataSize +
-            " minTasks:" + minTaskParallelism);
-  }
-
-  @Override
-  public void onRootVertexInitialized(String inputName,
-      InputDescriptor inputDescriptor, List<Event> events) {
-    // Not allowing this for now. Nothing to do.
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java
index 8856f8d..8eb8327 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexImpl.java
@@ -53,6 +53,7 @@ import org.apache.hadoop.yarn.util.Clock;
 import org.apache.tez.common.counters.TezCounters;
 import org.apache.tez.dag.api.DagTypeConverters;
 import org.apache.tez.dag.api.EdgeProperty.DataMovementType;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.dag.api.InputDescriptor;
 import org.apache.tez.dag.api.OutputDescriptor;
 import org.apache.tez.dag.api.ProcessorDescriptor;
@@ -60,6 +61,7 @@ import org.apache.tez.dag.api.TezConfiguration;
 import org.apache.tez.dag.api.TezUncheckedException;
 import org.apache.tez.dag.api.VertexLocationHint;
 import org.apache.tez.dag.api.VertexLocationHint.TaskLocationHint;
+import org.apache.tez.dag.api.VertexManagerPluginDescriptor;
 import org.apache.tez.dag.api.client.ProgressBuilder;
 import org.apache.tez.dag.api.client.StatusGetOpts;
 import org.apache.tez.dag.api.client.VertexStatus;
@@ -72,13 +74,11 @@ import org.apache.tez.dag.app.ContainerContext;
 import org.apache.tez.dag.app.TaskAttemptListener;
 import org.apache.tez.dag.app.TaskHeartbeatHandler;
 import org.apache.tez.dag.app.dag.DAG;
-import org.apache.tez.dag.app.dag.EdgeManager;
 import org.apache.tez.dag.app.dag.RootInputInitializerRunner;
 import org.apache.tez.dag.app.dag.Task;
 import org.apache.tez.dag.app.dag.TaskAttemptStateInternal;
 import org.apache.tez.dag.app.dag.TaskTerminationCause;
 import org.apache.tez.dag.app.dag.Vertex;
-import org.apache.tez.dag.app.dag.VertexManager;
 import org.apache.tez.dag.app.dag.VertexState;
 import org.apache.tez.dag.app.dag.VertexTerminationCause;
 import org.apache.tez.dag.app.dag.event.DAGEvent;
@@ -108,6 +108,7 @@ import org.apache.tez.dag.app.dag.event.VertexEventOneToOneSourceSplit;
 import org.apache.tez.dag.history.DAGHistoryEvent;
 import org.apache.tez.dag.history.events.VertexFinishedEvent;
 import org.apache.tez.dag.history.events.VertexStartedEvent;
+import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager;
 import org.apache.tez.dag.records.TezDAGID;
 import org.apache.tez.dag.records.TezTaskAttemptID;
 import org.apache.tez.dag.records.TezTaskID;
@@ -777,11 +778,16 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
   // TODO Create InputReadyVertexManager that schedules when there is something
   // to read and use that as default instead of ImmediateStart.TEZ-480
   @Override
-  public void scheduleTasks(Collection<TezTaskID> taskIDs) {
+  public void scheduleTasks(List<Integer> taskIDs) {
     readLock.lock();
     try {
-      for (TezTaskID taskID : taskIDs) {
-        eventHandler.handle(new TaskEvent(taskID,
+      for (Integer taskID : taskIDs) {
+        if (tasks.size() <= taskID.intValue()) {
+          throw new TezUncheckedException(
+              "Invalid taskId: " + taskID + " for vertex: " + vertexName);
+        }
+        eventHandler.handle(new TaskEvent(
+            TezTaskID.getInstance(vertexId, taskID.intValue()),
             TaskEventType.T_SCHEDULE));
       }
     } finally {
@@ -790,19 +796,22 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
   }
 
   @Override
-  public void setParallelism(int parallelism,
-      Map<Vertex, EdgeManager> sourceEdgeManagers) {
+  public boolean setParallelism(int parallelism,
+      Map<String, EdgeManager> sourceEdgeManagers) {
     writeLock.lock();
     try {
-      Preconditions.checkState(parallelismSet == false,
-          "Parallelism can only be set dynamically once per vertex");
+      if (parallelismSet == true) {
+        LOG.info("Parallelism can only be set dynamically once per vertex");
+        return false;
+      }
+      
       parallelismSet = true;
 
       // Input initializer expected to set parallelism.
       if (numTasks == -1) {
         Preconditions
             .checkArgument(sourceEdgeManagers == null,
-                "SourceEdge managers cannot be set when determining initial parallelism");
+                "Source edge managers cannot be set when determining initial parallelism");
         this.numTasks = parallelism;
         this.createTasks();
         LOG.info("Vertex " + getVertexId() + 
@@ -818,8 +827,10 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
               "Increasing parallelism is not supported");
         }
         if (parallelism == numTasks) {
-          LOG.info("Ingoring setParallelism to current value: " + parallelism);
-          return;
+          LOG.info("setParallelism same as current value: " + parallelism);
+          Preconditions
+          .checkArgument(sourceEdgeManagers != null,
+              "Source edge managers must be set when not changing parallelism");
         }
   
         // start buffering incoming events so that we can re-route existing events
@@ -860,12 +871,12 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
   
         // set new edge managers
         if(sourceEdgeManagers != null) {
-          for(Map.Entry<Vertex, EdgeManager> entry : sourceEdgeManagers.entrySet()) {
-            Vertex sourceVertex = entry.getKey();
+          for(Map.Entry<String, EdgeManager> entry : sourceEdgeManagers.entrySet()) {
+            LOG.info("Replacing edge manager for source:"
+                + entry.getKey() + " destination: " + getVertexId());
+            Vertex sourceVertex = appContext.getCurrentDAG().getVertex(entry.getKey());
             EdgeManager edgeManager = entry.getValue();
             Edge edge = sourceVertices.get(sourceVertex);
-            LOG.info("Replacing edge manager for source:"
-                + sourceVertex.getVertexId() + " destination: " + getVertexId());
             edge.setEdgeManager(edgeManager);
           }
         }
@@ -909,7 +920,8 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
     } finally {
       writeLock.unlock();
     }
-
+    
+    return true;
   }
 
   public void setVertexLocationHint(VertexLocationHint vertexLocationHint) {
@@ -1315,7 +1327,6 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
         }
       }
 
-      // TODO get this from API
       boolean hasBipartite = false;
       if (vertex.sourceVertices != null) {
         for (Edge edge : vertex.sourceVertices.values()) {
@@ -1325,28 +1336,45 @@ public class VertexImpl implements org.apache.tez.dag.app.dag.Vertex,
           }
         }
       }
-
+      
       if (hasBipartite && vertex.inputsWithInitializers != null) {
         LOG.fatal("A vertex with an Initial Input and a Shuffle Input are not supported at the moment");
         return vertex.finished(VertexState.FAILED);
       }
-
-      if (hasBipartite) {
-        // setup vertex manager
-        // TODO this needs to consider data size and perhaps API.
-        // Currently implicitly BIPARTITE is the only edge type
-        LOG.info("Setting vertexManager to ShuffleVertexManager for " + vertex.logIdentifier);
-        vertex.vertexManager = new ShuffleVertexManager(vertex);
-      } else if (vertex.inputsWithInitializers != null) {
-        LOG.info("Setting vertexManager to RootInputVertexManager for " + vertex.logIdentifier);
-        vertex.vertexManager = new RootInputVertexManager(vertex,
-            vertex.eventHandler);
+      
+      boolean hasUserVertexManager = vertex.vertexPlan.hasVertexManagerPlugin();
+      
+      if (hasUserVertexManager) {
+        VertexManagerPluginDescriptor pluginDesc = DagTypeConverters
+            .convertVertexManagerPluginDescriptorFromDAGPlan(vertex.vertexPlan
+                .getVertexManagerPlugin());
+        LOG.info("Setting user vertex manager plugin: "
+            + pluginDesc.getClassName() + " on vertex: " + vertex.getName());
+        vertex.vertexManager = new VertexManager(pluginDesc, vertex, vertex.appContext);
       } else {
-        // schedule all tasks upon vertex start
-        LOG.info("Setting vertexManager to ImmediateStartVertexManager for " + vertex.logIdentifier);
-        vertex.vertexManager = new ImmediateStartVertexManager(vertex);
+        if (hasBipartite) {
+          // setup vertex manager
+          // TODO this needs to consider data size and perhaps API.
+          // Currently implicitly BIPARTITE is the only edge type
+          LOG.info("Setting vertexManager to ShuffleVertexManager for "
+              + vertex.logIdentifier);
+          vertex.vertexManager = new VertexManager(new ShuffleVertexManager(),
+              vertex, vertex.appContext);
+        } else if (vertex.inputsWithInitializers != null) {
+          LOG.info("Setting vertexManager to RootInputVertexManager for "
+              + vertex.logIdentifier);
+          vertex.vertexManager = new VertexManager(new RootInputVertexManager(
+              vertex, vertex.eventHandler), vertex, vertex.appContext);
+        } else {
+          // schedule all tasks upon vertex start. Default behavior.
+          LOG.info("Setting vertexManager to ImmediateStartVertexManager for "
+              + vertex.logIdentifier);
+          vertex.vertexManager = new VertexManager(
+              new ImmediateStartVertexManager(), vertex, vertex.appContext);
+        }
       }
-      vertex.vertexManager.initialize(vertex.conf);
+      
+      vertex.vertexManager.initialize();
 
       // Setup tasks early if possible. If the VertexManager is not being used
       // to set parallelism, sending events to Tasks is safe (and less confusing

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexManager.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexManager.java b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexManager.java
new file mode 100644
index 0000000..d91c768
--- /dev/null
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/VertexManager.java
@@ -0,0 +1,174 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.tez.dag.app.dag.impl;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tez.common.TezUtils;
+import org.apache.tez.dag.api.EdgeManager;
+import org.apache.tez.dag.api.EdgeProperty;
+import org.apache.tez.dag.api.InputDescriptor;
+import org.apache.tez.dag.api.TezUncheckedException;
+import org.apache.tez.dag.api.VertexLocationHint;
+import org.apache.tez.dag.api.VertexManagerPlugin;
+import org.apache.tez.dag.api.VertexManagerPluginContext;
+import org.apache.tez.dag.api.VertexManagerPluginDescriptor;
+import org.apache.tez.dag.app.AppContext;
+import org.apache.tez.dag.app.dag.Vertex;
+import org.apache.tez.dag.records.TezTaskAttemptID;
+import org.apache.tez.dag.records.TezTaskID;
+import org.apache.tez.runtime.RuntimeUtils;
+import org.apache.tez.runtime.api.Event;
+import org.apache.tez.runtime.api.events.VertexManagerEvent;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class VertexManager {
+  VertexManagerPluginDescriptor pluginDesc;
+  VertexManagerPlugin plugin;
+  Vertex managedVertex;
+  VertexManagerPluginContextImpl pluginContext;
+  AppContext appContext;
+  
+  class VertexManagerPluginContextImpl implements VertexManagerPluginContext {
+    
+    @Override
+    public Map<String, EdgeProperty> getInputVertexEdgeProperties() {
+      Map<Vertex, Edge> inputs = managedVertex.getInputVertices();
+      Map<String, EdgeProperty> vertexEdgeMap = 
+                          Maps.newHashMapWithExpectedSize(inputs.size());
+      for (Map.Entry<Vertex, Edge> entry : inputs.entrySet()) {
+        vertexEdgeMap.put(entry.getKey().getName(), entry.getValue().getEdgeProperty());
+      }
+      return vertexEdgeMap;
+    }
+
+    @Override
+    public String getVertexName() {
+      return managedVertex.getName();
+    }
+
+    @Override
+    public int getVertexNumTasks(String vertexName) {
+      return managedVertex.getTotalTasks();
+    }
+
+    @Override
+    public boolean setVertexParallelism(int parallelism,
+        Map<String, EdgeManager> sourceEdgeManagers) {
+      return managedVertex.setParallelism(parallelism, sourceEdgeManagers);
+    }
+
+    @Override
+    public void scheduleVertexTasks(List<Integer> taskIDs) {
+      managedVertex.scheduleTasks(taskIDs);
+    }
+
+    @Override
+    public Set<String> getVertexInputNames() {
+      Set<String> inputNames = null;
+      Map<String, RootInputLeafOutputDescriptor<InputDescriptor>> inputs = 
+          managedVertex.getAdditionalInputs();
+      if (inputs != null) {
+        inputNames = inputs.keySet();
+      }
+      return inputNames;
+    }
+
+    @Override
+    public void setVertexLocationHint(VertexLocationHint locationHint) {
+      managedVertex.setVertexLocationHint(locationHint);
+    }
+
+  }
+  
+  public VertexManager(VertexManagerPlugin plugin, 
+      Vertex managedVertex, AppContext appContext) {
+    this.plugin = plugin;
+    this.managedVertex = managedVertex;
+    this.appContext = appContext;
+  }
+  
+  public VertexManager(VertexManagerPluginDescriptor pluginDesc, 
+      Vertex managedVertex, AppContext appContext) {
+    this.pluginDesc = pluginDesc;
+    this.managedVertex = managedVertex;
+    this.appContext = appContext;
+  }
+  
+  public VertexManagerPlugin getPlugin() {
+    return plugin;
+  }
+  
+  public void initialize() {
+    pluginContext = new VertexManagerPluginContextImpl();
+    byte[] payload = null;
+    if (pluginDesc != null) {
+      plugin = RuntimeUtils.createClazzInstance(pluginDesc.getClassName());
+      payload = pluginDesc.getUserPayload();
+    }
+    if (payload == null) {
+      // Ease of use. If no payload present then give the common configuration
+      try {
+        payload = TezUtils.createUserPayloadFromConf(appContext.getAMConf());
+      } catch (IOException e) {
+        throw new TezUncheckedException(e);
+      }
+    }
+    plugin.initialize(payload, pluginContext);
+  }
+
+  public void onVertexStarted(List<TezTaskAttemptID> completions) {
+    Map<String, List<Integer>> pluginCompletionsMap = Maps.newHashMap();
+    for (TezTaskAttemptID attemptId : completions) {
+      TezTaskID tezTaskId = attemptId.getTaskID();
+      Integer taskId = new Integer(tezTaskId.getId());
+      String vertexName = 
+          appContext.getCurrentDAG().getVertex(tezTaskId.getVertexID()).getName();
+      List<Integer> taskIdList = pluginCompletionsMap.get(vertexName);
+      if (taskIdList == null) {
+        taskIdList = Lists.newArrayList();
+        pluginCompletionsMap.put(vertexName, taskIdList);
+      }
+      taskIdList.add(taskId);
+    }
+    plugin.onVertexStarted(pluginCompletionsMap);
+  }
+
+  public void onSourceTaskCompleted(TezTaskAttemptID attemptId) {
+    TezTaskID tezTaskId = attemptId.getTaskID();
+    Integer taskId = new Integer(tezTaskId.getId());
+    String vertexName = 
+        appContext.getCurrentDAG().getVertex(tezTaskId.getVertexID()).getName();
+    plugin.onSourceTaskCompleted(vertexName, taskId);
+  }
+
+  public void onVertexManagerEventReceived(VertexManagerEvent vmEvent) {
+    plugin.onVertexManagerEventReceived(vmEvent);
+  }
+
+  public void onRootVertexInitialized(String inputName, 
+      InputDescriptor inputDescriptor, List<Event> events) {
+    plugin.onRootVertexInitialized(inputName, inputDescriptor, events);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fb9488cd/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexImpl.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexImpl.java b/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexImpl.java
index d9b472d..ba4099b 100644
--- a/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexImpl.java
+++ b/tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestVertexImpl.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.yarn.event.EventHandler;
 import org.apache.hadoop.yarn.util.Clock;
 import org.apache.hadoop.yarn.util.SystemClock;
 import org.apache.tez.dag.api.DagTypeConverters;
+import org.apache.tez.dag.api.EdgeManager;
 import org.apache.tez.dag.api.EdgeProperty;
 import org.apache.tez.dag.api.InputDescriptor;
 import org.apache.tez.dag.api.TezConfiguration;
@@ -74,7 +75,6 @@ import org.apache.tez.dag.app.AppContext;
 import org.apache.tez.dag.app.TaskAttemptListener;
 import org.apache.tez.dag.app.TaskHeartbeatHandler;
 import org.apache.tez.dag.app.dag.DAG;
-import org.apache.tez.dag.app.dag.EdgeManager;
 import org.apache.tez.dag.app.dag.RootInputInitializerRunner;
 import org.apache.tez.dag.app.dag.Task;
 import org.apache.tez.dag.app.dag.TaskAttemptStateInternal;
@@ -98,6 +98,7 @@ import org.apache.tez.dag.app.dag.event.VertexEventType;
 import org.apache.tez.dag.app.rm.TaskSchedulerEventHandler;
 import org.apache.tez.dag.history.DAGHistoryEvent;
 import org.apache.tez.dag.history.avro.HistoryEventType;
+import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager;
 import org.apache.tez.dag.records.TezDAGID;
 import org.apache.tez.dag.records.TezTaskAttemptID;
 import org.apache.tez.dag.records.TezTaskID;
@@ -1096,6 +1097,17 @@ public class TestVertexImpl {
         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>();
@@ -1259,8 +1271,8 @@ public class TestVertexImpl {
 
     Vertex v1 = vertices.get("vertex1");
     EdgeManager mockEdgeManager = mock(EdgeManager.class);
-    Map<Vertex, EdgeManager> edgeManager = Collections.singletonMap(
-       v1, mockEdgeManager);
+    Map<String, EdgeManager> edgeManager = Collections.singletonMap(
+       v1.getName(), mockEdgeManager);
     v3.setParallelism(1, edgeManager);
     Assert.assertEquals(1, v3.getTotalTasks());
     Assert.assertEquals(1, tasks.size());
@@ -1392,7 +1404,7 @@ public class TestVertexImpl {
   }
 
   @SuppressWarnings("unchecked")
-  @Test
+  @Test(timeout = 5000)
   public void testVertexKill() {
     initAllVertices(VertexState.INITED);
 
@@ -1451,11 +1463,11 @@ public class TestVertexImpl {
   public void testVertexManagerInit() {
     initAllVertices(VertexState.INITED);
     VertexImpl v2 = vertices.get("vertex2");
-    Assert.assertTrue(v2.getVertexManager()
+    Assert.assertTrue(v2.getVertexManager().getPlugin()
         instanceof ImmediateStartVertexManager);
 
     VertexImpl v6 = vertices.get("vertex6");
-    Assert.assertTrue(v6.getVertexManager()
+    Assert.assertTrue(v6.getVertexManager().getPlugin()
         instanceof ShuffleVertexManager);
   }
 
@@ -1833,7 +1845,7 @@ public class TestVertexImpl {
   }
 
 
-  @Test//(timeout = 5000)
+  @Test(timeout = 5000)
   public void testVertexWithOneToOneSplit() {
     // create a diamond shaped dag with 1-1 edges. 
     // split the source and remaining vertices should split equally
@@ -1855,7 +1867,7 @@ public class TestVertexImpl {
     Assert.assertEquals(VertexState.INITED, v1.getState());
     Assert.assertEquals(numTasks, v1.getTotalTasks());
     Assert.assertEquals(RootInputVertexManager.class.getName(), v1
-        .getVertexManager().getClass().getName());
+        .getVertexManager().getPlugin().getClass().getName());
     Assert.assertEquals(v1Hints, v1.getVertexLocationHint().getTaskLocationHints());
     Assert.assertEquals(true, runner1.hasShutDown);
     
@@ -1909,7 +1921,7 @@ public class TestVertexImpl {
 
     Assert.assertEquals(VertexState.FAILED, v1.getState());
     Assert.assertEquals(RootInputVertexManager.class.getName(), v1
-        .getVertexManager().getClass().getName());
+        .getVertexManager().getPlugin().getClass().getName());
     Assert.assertEquals(true, runner1.hasShutDown);
     
     VertexImplWithCustomInitializer v2 = (VertexImplWithCustomInitializer) vertices.get("vertex2");
@@ -1919,7 +1931,7 @@ public class TestVertexImpl {
     
     Assert.assertEquals(VertexState.FAILED, v2.getState());
     Assert.assertEquals(RootInputVertexManager.class.getName(), v2
-        .getVertexManager().getClass().getName());
+        .getVertexManager().getPlugin().getClass().getName());
     Assert.assertEquals(true, runner2.hasShutDown);
   }
   
@@ -1944,7 +1956,7 @@ public class TestVertexImpl {
     Assert.assertEquals(VertexState.INITED, v1.getState());
     Assert.assertEquals(5, v1.getTotalTasks());
     Assert.assertEquals(RootInputVertexManager.class.getName(), v1
-        .getVertexManager().getClass().getName());
+        .getVertexManager().getPlugin().getClass().getName());
     Assert.assertEquals(v1Hints, v1.getVertexLocationHint().getTaskLocationHints());
     Assert.assertEquals(true, runner1.hasShutDown);
     
@@ -1957,7 +1969,7 @@ public class TestVertexImpl {
     Assert.assertEquals(VertexState.INITED, v2.getState());
     Assert.assertEquals(10, v2.getTotalTasks());
     Assert.assertEquals(RootInputVertexManager.class.getName(), v2
-        .getVertexManager().getClass().getName());
+        .getVertexManager().getPlugin().getClass().getName());
     Assert.assertEquals(v2Hints, v2.getVertexLocationHint().getTaskLocationHints());
     Assert.assertEquals(true, runner2.hasShutDown);
   }
@@ -1973,7 +1985,7 @@ public class TestVertexImpl {
     return locationHints;
   }
 
-  @Test
+  @Test(timeout = 5000)
   public void testVertexWithNoTasks() {
     TezVertexID vId = null;
     try {