tez-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bi...@apache.org
Subject git commit: TEZ-525. Expose DAG api to get vertex by name (bikas)
Date Fri, 04 Oct 2013 00:50:53 GMT
Updated Branches:
  refs/heads/master 08b3ca8d2 -> fbcf33f75


TEZ-525. Expose DAG api to get vertex by name (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/fbcf33f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tez/tree/fbcf33f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tez/diff/fbcf33f7

Branch: refs/heads/master
Commit: fbcf33f75f0da7d6d21faf3a14a1cd97a6419933
Parents: 08b3ca8
Author: Bikas Saha <bikas@apache.org>
Authored: Thu Oct 3 17:41:41 2013 -0700
Committer: Bikas Saha <bikas@apache.org>
Committed: Thu Oct 3 17:41:41 2013 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/tez/dag/api/DAG.java   | 33 ++++++++++++--------
 .../java/org/apache/tez/dag/api/Vertex.java     |  9 +++---
 .../org/apache/tez/dag/api/TestDAGVerify.java   |  8 ++---
 3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fbcf33f7/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 8b78324..5a51891 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
@@ -46,39 +46,46 @@ import org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint;
 import org.apache.tez.dag.api.records.DAGProtos.PlanVertexType;
 import org.apache.tez.dag.api.records.DAGProtos.VertexPlan;
 
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+
 
 public class DAG { // FIXME rename to Topology
-  final List<Vertex> vertices;
+  final BiMap<String, Vertex> vertices;
   final List<Edge> edges;
   final String name;
 
   public DAG(String name) {
-    this.vertices = new ArrayList<Vertex>();
+    this.vertices = HashBiMap.<String, Vertex>create();
     this.edges = new ArrayList<Edge>();
     this.name = name;
   }
 
   public synchronized DAG addVertex(Vertex vertex) {
-    if (vertices.contains(vertex)) {
-      throw new IllegalArgumentException(
-          "Vertex " + vertex + " already defined!");
+    if (vertices.containsKey(vertex.getVertexName())) {
+      throw new IllegalStateException(
+          "Vertex " + vertex.getVertexName() + " already defined!");
     }
-    vertices.add(vertex);
+    vertices.put(vertex.getVertexName(), vertex);
     return this;
   }
+  
+  public synchronized Vertex getVertex(String vertexName) {
+    return vertices.get(vertexName);
+  }
 
   @Private
-  public synchronized List<Vertex> getVertices() {
-    return Collections.unmodifiableList(this.vertices);
+  public synchronized Set<Vertex> getVertices() {
+    return Collections.unmodifiableSet(this.vertices.values());
   }
 
   public synchronized DAG addEdge(Edge edge) {
     // Sanity checks
-    if (!vertices.contains(edge.getInputVertex())) {
+    if (!vertices.containsValue(edge.getInputVertex())) {
       throw new IllegalArgumentException(
           "Input vertex " + edge.getInputVertex() + " doesn't exist!");
     }
-    if (!vertices.contains(edge.getOutputVertex())) {
+    if (!vertices.containsValue(edge.getOutputVertex())) {
       throw new IllegalArgumentException(
           "Output vertex " + edge.getOutputVertex() + " doesn't exist!");
     }
@@ -159,7 +166,7 @@ public class DAG { // FIXME rename to Topology
     // check for valid vertices, duplicate vertex names,
     // and prepare for cycle detection
     Map<String, AnnotatedVertex> vertexMap = new HashMap<String, AnnotatedVertex>();
-    for(Vertex v : vertices){
+    for(Vertex v : vertices.values()){
       if(vertexMap.containsKey(v.getVertexName())){
          throw new IllegalStateException("DAG contains multiple vertices"
              + " with name: " + v.getVertexName());
@@ -169,7 +176,7 @@ public class DAG { // FIXME rename to Topology
 
     // Verify Input/Output names don't collide amongs themselves as well as with vertexNames
     Set<String> namedIOs = new HashSet<String>();
-    for (Vertex v : vertices) {
+    for (Vertex v : vertices.values()) {
       for (NamedDescriptor<InputDescriptor> in : v.getInputs()) {
         if (vertexMap.containsKey(in.getName())) {
           throw new IllegalStateException(
@@ -294,7 +301,7 @@ public class DAG { // FIXME rename to Topology
 
     dagBuilder.setName(this.name);
 
-    for(Vertex vertex : vertices){
+    for(Vertex vertex : vertices.values()){
       VertexPlan.Builder vertexBuilder = VertexPlan.newBuilder();
       vertexBuilder.setName(vertex.getVertexName());
       vertexBuilder.setType(PlanVertexType.NORMAL); // vertex type is implicitly NORMAL until
 TEZ-46.

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fbcf33f7/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 5c98354..9506af1 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
@@ -19,6 +19,7 @@
 package org.apache.tez.dag.api;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -184,12 +185,12 @@ public class Vertex { // FIXME rename to Task
     outputEdgeIds.add(edgeId);
   }
 
-  List<Vertex> getInputVertices() {
-    return inputVertices;
+  public List<Vertex> getInputVertices() {
+    return Collections.unmodifiableList(inputVertices);
   }
 
-  List<Vertex> getOutputVertices() {
-    return outputVertices;
+  public List<Vertex> getOutputVertices() {
+    return Collections.unmodifiableList(outputVertices);
   }
 
   List<String> getInputEdgeIds() {

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/fbcf33f7/tez-api/src/test/java/org/apache/tez/dag/api/TestDAGVerify.java
----------------------------------------------------------------------
diff --git a/tez-api/src/test/java/org/apache/tez/dag/api/TestDAGVerify.java b/tez-api/src/test/java/org/apache/tez/dag/api/TestDAGVerify.java
index 41b3182..459194f 100644
--- a/tez-api/src/test/java/org/apache/tez/dag/api/TestDAGVerify.java
+++ b/tez-api/src/test/java/org/apache/tez/dag/api/TestDAGVerify.java
@@ -265,10 +265,10 @@ public class TestDAGVerify {
     Vertex v1repeat = new Vertex("v1",
         new ProcessorDescriptor("MapProcessor"),
         dummyTaskCount, dummyTaskResource);
-    DAG dag = new DAG("testDag");
-    dag.addVertex(v1);
-    dag.addVertex(v1repeat);
     try {
+      DAG dag = new DAG("testDag");
+      dag.addVertex(v1);
+      dag.addVertex(v1repeat);
       dag.verify();
     }
     catch (IllegalStateException e){
@@ -276,7 +276,7 @@ public class TestDAGVerify {
     }
     Assert.assertNotNull(ex);
     System.out.println(ex.getMessage());
-    Assert.assertTrue(ex.getMessage().startsWith("DAG contains multiple vertices with name"));
+    Assert.assertTrue(ex.getMessage().startsWith("Vertex v1 already defined"));
   }
 
   @Test (expected = IllegalStateException.class)


Mime
View raw message