hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r1294033 - in /incubator/hama/trunk: bin/ examples/src/main/java/org/apache/hama/examples/ graph/src/main/java/org/apache/hama/graph/
Date Mon, 27 Feb 2012 05:06:03 GMT
Author: edwardyoon
Date: Mon Feb 27 05:06:03 2012
New Revision: 1294033

URL: http://svn.apache.org/viewvc?rev=1294033&view=rev
Log:
Fix GraphJobRunner

Modified:
    incubator/hama/trunk/bin/hama
    incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java
    incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java
    incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/SSSP.java
    incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJob.java
    incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java

Modified: incubator/hama/trunk/bin/hama
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/bin/hama?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/bin/hama (original)
+++ incubator/hama/trunk/bin/hama Mon Feb 27 05:06:03 2012
@@ -107,6 +107,14 @@ if [ -d "$HAMA_HOME/core/target/test-cla
   CLASSPATH=${CLASSPATH}:$HAMA_HOME/core/target/test-classes
 fi
 
+# for developers, add Graph classes to CLASSPATH
+if [ -d "$HAMA_HOME/graph/target/classes" ]; then
+  CLASSPATH=${CLASSPATH}:$HAMA_HOME/graph/target/classes
+fi
+if [ -d "$HAMA_HOME/graph/target/test-classes/classes" ]; then
+  CLASSPATH=${CLASSPATH}:$HAMA_HOME/graph/target/test-classes
+fi
+
 # so that filenames w/ spaces are handled correctly in loops below
 IFS=
 

Modified: incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java
(original)
+++ incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/InlinkCount.java
Mon Feb 27 05:06:03 2012
@@ -50,7 +50,7 @@ public class InlinkCount extends Vertex<
       InterruptedException, ClassNotFoundException {
     // Graph job configuration
     HamaConfiguration conf = new HamaConfiguration();
-    GraphJob inlinkJob = new GraphJob(conf);
+    GraphJob inlinkJob = new GraphJob(conf, InlinkCount.class);
     // Set the job name
     inlinkJob.setJobName("Inlink Count");
 

Modified: incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java (original)
+++ incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java Mon
Feb 27 05:06:03 2012
@@ -71,7 +71,7 @@ public class PageRank {
       printUsage();
 
     HamaConfiguration conf = new HamaConfiguration(new Configuration());
-    GraphJob pageJob = new GraphJob(conf);
+    GraphJob pageJob = new GraphJob(conf, PageRank.class);
     pageJob.setJobName("Pagerank");
 
     pageJob.setVertexClass(PageRankVertex.class);

Modified: incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/SSSP.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/SSSP.java?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/SSSP.java (original)
+++ incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/SSSP.java Mon Feb
27 05:06:03 2012
@@ -79,7 +79,7 @@ public class SSSP {
 
     // Graph job configuration
     HamaConfiguration conf = new HamaConfiguration();
-    GraphJob ssspJob = new GraphJob(conf);
+    GraphJob ssspJob = new GraphJob(conf, SSSP.class);
     // Set the job name
     ssspJob.setJobName("Single Source Shortest Path");
 

Modified: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJob.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJob.java?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJob.java (original)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJob.java Mon Feb 27
05:06:03 2012
@@ -26,9 +26,10 @@ import org.apache.hama.bsp.BSPJob;
 public class GraphJob extends BSPJob {
   public final static String VERTEX_CLASS_ATTR = "hama.graph.vertex.class";
 
-  public GraphJob(HamaConfiguration conf) throws IOException {
+  public GraphJob(HamaConfiguration conf, Class<?> exampleClass) throws IOException
{
     super(conf);
     this.setBspClass(GraphJobRunner.class);
+    this.setJarByClass(exampleClass);
   }
 
   /**
@@ -39,7 +40,6 @@ public class GraphJob extends BSPJob {
    */
   public void setVertexClass(Class<? extends Vertex<? extends Writable>> cls)
       throws IllegalStateException {
-    ensureState(JobState.DEFINE);
     conf.setClass(VERTEX_CLASS_ATTR, cls, Vertex.class);
   }
 

Modified: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java?rev=1294033&r1=1294032&r2=1294033&view=diff
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java (original)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java Mon
Feb 27 05:06:03 2012
@@ -25,6 +25,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.MapWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
@@ -36,6 +39,7 @@ import org.apache.hama.util.KeyValuePair
 
 @SuppressWarnings("rawtypes")
 public class GraphJobRunner extends BSP {
+  public static final Log LOG = LogFactory.getLog(GraphJobRunner.class);
   private Map<String, Vertex> vertices = new HashMap<String, Vertex>();
 
   @SuppressWarnings("unchecked")
@@ -85,11 +89,15 @@ public class GraphJobRunner extends BSP 
   @SuppressWarnings("unchecked")
   public void setup(BSPPeer peer) throws IOException, SyncException,
       InterruptedException {
+    Configuration conf = peer.getConfiguration();
+    LOG.debug("vertex class: " + conf.get("hama.graph.vertex.class"));
+
     KeyValuePair<? extends VertexWritable, ? extends VertexArrayWritable> next = null;
     while ((next = peer.readNext()) != null) {
-      Vertex vertex = (Vertex) ReflectionUtils.newInstance(
-          peer.getConfiguration().getClass("hama.graph.vertex.class",
-              Vertex.class), peer.getConfiguration());
+      Vertex<? extends Writable> vertex = (Vertex<? extends Writable>) ReflectionUtils
+          .newInstance(
+              peer.getConfiguration().getClass("hama.graph.vertex.class",
+                  Vertex.class), peer.getConfiguration());
       vertex.setVertexID(next.getKey().getName());
       vertex.peer = peer;
 
@@ -106,10 +114,15 @@ public class GraphJobRunner extends BSP 
     }
 
     long numberVertices = vertices.size() * peer.getNumPeers();
-
     for (Map.Entry<String, Vertex> e : vertices.entrySet()) {
       e.getValue().setNumVertices(numberVertices);
+    }
 
+    startVertexCompute();
+  }
+
+  private void startVertexCompute() throws IOException {
+    for (Map.Entry<String, Vertex> e : vertices.entrySet()) {
       LinkedList<Writable> msgIterator = new LinkedList<Writable>();
       msgIterator.add(e.getValue().getValue());
       e.getValue().compute(msgIterator.iterator());
@@ -118,10 +131,9 @@ public class GraphJobRunner extends BSP 
 
   public void cleanup(BSPPeer peer) {
     // FIXME provide write solution to Vertex
-    System.out.println("for debug\n==================");
+    LOG.debug("for debug\n==================");
     for (Map.Entry<String, Vertex> e : vertices.entrySet()) {
-      System.out.println(e.getValue().getVertexID() + ", "
-          + e.getValue().getValue());
+      LOG.debug(e.getValue().getVertexID() + ", " + e.getValue().getValue());
     }
   }
 }



Mime
View raw message