hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r570879 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/mapred/JobClient.java
Date Wed, 29 Aug 2007 17:54:32 GMT
Author: cutting
Date: Wed Aug 29 10:54:31 2007
New Revision: 570879

URL: http://svn.apache.org/viewvc?rev=570879&view=rev
Log:
HADOOP-1767.  Add 'bin/hadoop job -list' sub-command.  Contributed by Christophe Taton.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/JobClient.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=570879&r1=570878&r2=570879&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Wed Aug 29 10:54:31 2007
@@ -31,6 +31,8 @@
     HADOOP-1708.  Make files appear in namespace as soon as they are
     created.  (Dhruba Borthakur via dhruba)
 
+    HADOOP-1767.  Add "hadoop job -list" command. (taton via cutting)
+
   OPTIMIZATIONS
 
     HADOOP-1565.  Reduce memory usage of NameNode by replacing 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/JobClient.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/JobClient.java?rev=570879&r1=570878&r2=570879&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/JobClient.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/JobClient.java Wed Aug 29 10:54:31
2007
@@ -757,39 +757,59 @@
   public TaskStatusFilter getTaskOutputFilter(){
     return this.taskOutputFilter; 
   }
+
+  /**
+   * Display usage of the command-line tool and terminate execution
+   */
+  private void displayUsage() {
+    System.out.printf("JobClient <command> <args>\n");
+    System.out.printf("\t-submit\t<job-file>\n");
+    System.out.printf("\t-status\t<job-id>\n");
+    System.out.printf("\t-kill\t<job-id>\n");
+    System.out.printf("\t-events\t<job-id> <from-event-#> <#-of-events>\n");
+    System.out.printf("\t-list\n\n");
+    throw new RuntimeException("JobClient: bad command-line arguments");
+  }
     
   public int run(String[] argv) throws Exception {
-    if (argv.length < 2) {
-      String cmd = "JobClient -submit <job> | -status <id> |" + 
-                   " -events <id> |" +
-                   " -kill <id> [-jt <jobtracker:port>|<config>]";
-      System.out.println(cmd);
-      throw new RuntimeException("JobClient:" + cmd);
-    }
-
-    // Process args
+    // process arguments
     String submitJobFile = null;
     String jobid = null;
+    int fromEvent = 0;
+    int nEvents = 0;
     boolean getStatus = false;
     boolean killJob = false;
+    boolean listEvents = false;
+    boolean listJobs = false;
 
-    for (int i = 0; i < argv.length; i++) {
-      if ("-submit".equals(argv[i])) {
-        submitJobFile = argv[i+1];
-        i++;
-      } else if ("-status".equals(argv[i])) {
-        jobid = argv[i+1];
-        getStatus = true;
-        i++;
-      } else if ("-kill".equals(argv[i])) {
-        jobid = argv[i+1];
-        killJob = true;
-        i++;
-      } else if ("-events".equals(argv[i])) {
-        listEvents(argv[i+1], Integer.parseInt(argv[i+2]), 
-                   Integer.parseInt(argv[i+3]));
-        i += 3;
-      }
+    if (argv.length < 1)
+      displayUsage();
+
+    if ("-submit".equals(argv[0])) {
+      if (argv.length != 2)
+        displayUsage();
+      submitJobFile = argv[1];
+    } else if ("-status".equals(argv[0])) {
+      if (argv.length != 2)
+        displayUsage();
+      jobid = argv[1];
+      getStatus = true;
+    } else if ("-kill".equals(argv[0])) {
+      if (argv.length != 2)
+        displayUsage();
+      jobid = argv[1];
+      killJob = true;
+    } else if ("-events".equals(argv[0])) {
+      if (argv.length != 4)
+        displayUsage();
+      jobid = argv[1];
+      fromEvent = Integer.parseInt(argv[2]);
+      nEvents = Integer.parseInt(argv[3]);
+      listEvents = true;
+    } else if ("-list".equals(argv[0])) {
+      listJobs = true;
+    } else {
+      displayUsage();
     }
 
     // initialize JobClient
@@ -807,6 +827,7 @@
       if (submitJobFile != null) {
         RunningJob job = submitJob(conf);
         System.out.println("Created job " + job.getJobID());
+        exitCode = 0;
       } else if (getStatus) {
         RunningJob job = getJob(jobid);
         if (job == null) {
@@ -825,13 +846,19 @@
           System.out.println("Killed job " + jobid);
           exitCode = 0;
         }
+      } else if (listEvents) {
+        listEvents(jobid, fromEvent, nEvents);
+        exitCode = 0;
+      } else if (listJobs) {
+        listJobs();
+        exitCode = 0;
       }
     } finally {
       close();
     }
     return exitCode;
   }
-    
+
   /**
    * List the events for the given job
    * @param jobId the job id for the job's events to list
@@ -847,6 +874,23 @@
     for(TaskCompletionEvent event: events) {
       System.out.println(event.getTaskStatus() + " " + event.getTaskId() + 
                          " " + event.getTaskTrackerHttp());
+    }
+  }
+
+  /**
+   * Dump a list of currently running jobs
+   * @throws IOException
+   */
+  private void listJobs() throws IOException {
+    JobStatus[] jobs = jobsToComplete();
+    if (jobs == null)
+      jobs = new JobStatus[0];
+
+    System.out.printf("%d jobs currently running\n", jobs.length);
+    System.out.printf("JobId\tState\tStartTime\tUserName\n");
+    for (JobStatus job : jobs) {
+      System.out.printf("%s\t%d\t%d\t%s\n", job.getJobId(), job.getRunState(),
+          job.getStartTime(), job.getUsername());
     }
   }
     



Mime
View raw message