You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by cu...@apache.org on 2005/07/01 23:23:39 UTC

svn commit: r208797 - /lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java

Author: cutting
Date: Fri Jul  1 14:23:39 2005
New Revision: 208797

URL: http://svn.apache.org/viewcvs?rev=208797&view=rev
Log:
Get infoPort from config.

Modified:
    lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java

Modified: lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java?rev=208797&r1=208796&r2=208797&view=diff
==============================================================================
--- lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java (original)
+++ lucene/nutch/branches/mapred/src/java/org/apache/nutch/mapred/JobTracker.java Fri Jul  1 14:23:39 2005
@@ -32,35 +32,22 @@
  * @author Mike Cafarella
  *******************************************************/
 public class JobTracker implements MRConstants, InterTrackerProtocol, JobSubmissionProtocol {
-    static final int TRACKERINFO_PORT = 7845;
     static final int MAX_TASK_FAILURES = 4;
 
     public static final Logger LOG = LogFormatter.getLogger("org.apache.nutch.mapred.JobTracker");
-    public static JobTracker tracker = null;
-    public static void createTracker(NutchConf conf) throws IOException {
-      createTracker(getAddress(conf));
-    }
-    public static void createTracker(InetSocketAddress addr) throws IOException {
-      tracker = new JobTracker(addr);
+
+    private static JobTracker tracker = null;
+    public static void startTracker(NutchConf conf) throws IOException {
+      if (tracker != null)
+        throw new IOException("JobTracker already running.");
+      tracker = new JobTracker(conf);
+      tracker.offerService();
+
     }
     public static JobTracker getTracker() {
         return tracker;
     }
 
-    public static InetSocketAddress getAddress(NutchConf conf) {
-      String jobTrackerStr =
-        conf.get("mapred.job.tracker", "localhost:8012");
-      int colon = jobTrackerStr.indexOf(":");
-      if (colon < 0) {
-        throw new RuntimeException("Bad mapred.job.tracker: "+jobTrackerStr);
-      }
-      String jobTrackerName = jobTrackerStr.substring(0, colon);
-      int jobTrackerPort = Integer.parseInt(jobTrackerStr.substring(colon+1));
-      return new InetSocketAddress(jobTrackerName, jobTrackerPort);
-    }
-
-
-
     ///////////////////////////////////////////////////////
     // Used to expire TaskTrackers that have gone down
     ///////////////////////////////////////////////////////
@@ -202,6 +189,8 @@
 
     // Used to provide an HTML view on Job, Task, and TaskTracker structures
     JobTrackerInfoServer infoServer;
+    int infoPort;
+
     Server interTrackerServer;
 
     // Some jobs are stored in a local system directory.  We can delete
@@ -213,7 +202,7 @@
     /**
      * Start the JobTracker process, listen on the indicated port
      */
-    JobTracker(InetSocketAddress addr) throws IOException {
+    JobTracker(NutchConf conf) throws IOException {
         // This is a directory of temporary submission files.  We delete it
         // on startup, and can delete any files that we're done with
         this.systemDir = JobConf.getSystemDir();
@@ -227,6 +216,7 @@
         this.localDir.mkdirs();
 
         // Set ports, start RPC servers, etc.
+        InetSocketAddress addr = getAddress(conf);
         this.localMachine = addr.getHostName();
         this.port = addr.getPort();
         this.interTrackerServer = RPC.getServer(this, addr.getPort());
@@ -237,7 +227,9 @@
 	    String val = (String) p.getProperty(key);
 	    LOG.info("Property '" + key + "' is " + val);
 	}
-        this.infoServer = new JobTrackerInfoServer(this, TRACKERINFO_PORT);
+
+        this.infoPort = conf.getInt("mapred.job.tracker.info.port", 7845);
+        this.infoServer = new JobTrackerInfoServer(this, infoPort);
         this.infoServer.start();
 
         this.startTime = System.currentTimeMillis();
@@ -245,6 +237,19 @@
         new Thread(this.expireTrackers).start();
     }
 
+    private static InetSocketAddress getAddress(NutchConf conf) {
+      String jobTrackerStr =
+        conf.get("mapred.job.tracker", "localhost:8012");
+      int colon = jobTrackerStr.indexOf(":");
+      if (colon < 0) {
+        throw new RuntimeException("Bad mapred.job.tracker: "+jobTrackerStr);
+      }
+      String jobTrackerName = jobTrackerStr.substring(0, colon);
+      int jobTrackerPort = Integer.parseInt(jobTrackerStr.substring(colon+1));
+      return new InetSocketAddress(jobTrackerName, jobTrackerPort);
+    }
+
+
     /**
      * Run forever
      */
@@ -551,7 +556,7 @@
          */
         public JobInProgress(String jobFile) throws IOException {
             String jobid = createJobId();
-            String url = "http://" + localMachine + ":" + TRACKERINFO_PORT + "/jobdetails.jsp?jobid=" + jobid;
+            String url = "http://" + localMachine + ":" + infoPort + "/jobdetails.jsp?jobid=" + jobid;
             this.profile = new JobProfile(jobid, jobFile, url);
             this.status = new JobStatus(jobid, 0.0f, 0.0f, JobStatus.RUNNING);
 
@@ -1001,8 +1006,6 @@
           System.exit(-1);
         }
 
-        JobTracker.createTracker(NutchConf.get());
-        JobTracker jt = JobTracker.getTracker();
-        jt.offerService();
+        startTracker(NutchConf.get());
     }
 }