Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 41628 invoked from network); 29 Aug 2007 17:54:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Aug 2007 17:54:55 -0000 Received: (qmail 40419 invoked by uid 500); 29 Aug 2007 17:54:50 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 40385 invoked by uid 500); 29 Aug 2007 17:54:50 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 40376 invoked by uid 99); 29 Aug 2007 17:54:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2007 10:54:50 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2007 17:54:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C6EDF1A9832; Wed, 29 Aug 2007 10:54:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: hadoop-commits@lucene.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070829175432.C6EDF1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 \n"); + System.out.printf("\t-submit\t\n"); + System.out.printf("\t-status\t\n"); + System.out.printf("\t-kill\t\n"); + System.out.printf("\t-events\t <#-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 | -status |" + - " -events |" + - " -kill [-jt |]"; - 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()); } }