source: proiecte/HadoopJUnit/hadoop-0.20.1/src/mapred/org/apache/hadoop/mapred/JobQueueClient.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.apache.hadoop.mapred;
19
20import java.io.IOException;
21
22import org.apache.hadoop.conf.Configured;
23import org.apache.hadoop.util.Tool;
24import org.apache.hadoop.util.ToolRunner;
25/**
26 * <code>JobQueueClient</code> is interface provided to the user in order
27 * to get JobQueue related information from the {@link JobTracker}
28 *
29 * It provides the facility to list the JobQueues present and ability to
30 * view the list of jobs within a specific JobQueue
31 *
32**/
33
34class JobQueueClient extends Configured implements  Tool {
35 
36  JobClient jc;
37
38 
39  public JobQueueClient() {
40  }
41 
42  public JobQueueClient(JobConf conf) throws IOException {
43    setConf(conf);
44  }
45 
46  private void init(JobConf conf) throws IOException {
47    setConf(conf);
48    jc = new JobClient(conf);
49  }
50 
51  @Override
52  public int run(String[] argv) throws Exception {
53    int exitcode = -1;
54   
55    if(argv.length < 1){
56      displayUsage("");
57      return exitcode;
58    }
59    String cmd = argv[0];
60    boolean displayQueueList = false;
61    boolean displayQueueInfoWithJobs = false;
62    boolean displayQueueInfoWithoutJobs = false;
63   
64    if("-list".equals(cmd)){
65      displayQueueList = true;
66    }else if("-info".equals(cmd)){
67      if(argv.length == 2 && !(argv[1].equals("-showJobs"))) {
68        displayQueueInfoWithoutJobs = true;
69      } else if(argv.length == 3){
70        if(argv[2].equals("-showJobs")){
71          displayQueueInfoWithJobs = true;
72        }else {
73          displayUsage(cmd);
74          return exitcode;
75        }
76      }else {
77        displayUsage(cmd);
78        return exitcode;
79      }     
80    } else {
81      displayUsage(cmd);
82      return exitcode;
83    }
84    JobConf conf = new JobConf(getConf());
85    init(conf);
86    if (displayQueueList) {
87      displayQueueList();
88      exitcode = 0;
89    } else if (displayQueueInfoWithoutJobs){
90      displayQueueInfo(argv[1],false);
91      exitcode = 0;
92    } else if (displayQueueInfoWithJobs) {
93      displayQueueInfo(argv[1],true);
94      exitcode = 0;
95    }
96   
97    return exitcode;
98  }
99 
100  /**
101   * Method used to display information pertaining to a Single JobQueue
102   * registered with the {@link QueueManager}. Display of the Jobs is
103   * determine by the boolean
104   *
105   * @throws IOException
106   */
107
108  private void displayQueueInfo(String queue, boolean showJobs) throws IOException {
109    JobQueueInfo schedInfo = jc.getQueueInfo(queue);
110    if (schedInfo == null) {
111      System.out.printf("Queue Name : %s has no scheduling information \n", queue);
112    } else {
113      System.out.printf("Queue Name : %s \n", schedInfo.getQueueName());
114      System.out.printf("Scheduling Info : %s \n",schedInfo.getSchedulingInfo());
115    }
116    if (showJobs) {
117      System.out.printf("Job List\n");
118      JobStatus[] jobs = jc.getJobsFromQueue(queue);
119      if (jobs == null)
120        jobs = new JobStatus[0];
121      jc.displayJobList(jobs);
122    }
123  }
124
125  /**
126   * Method used to display the list of the JobQueues registered
127   * with the {@link QueueManager}
128   *
129   * @throws IOException
130   */
131  private void displayQueueList() throws IOException {
132    JobQueueInfo[] queues = jc.getQueues();
133    for (JobQueueInfo queue : queues) {
134      String schedInfo = queue.getSchedulingInfo();
135      if(schedInfo.trim().equals("")){
136        schedInfo = "N/A";
137      }
138      System.out.printf("Queue Name : %s \n", queue.getQueueName());
139      System.out.printf("Scheduling Info : %s \n",queue.getSchedulingInfo());
140    }
141  }
142
143  private void displayUsage(String cmd) {
144    String prefix = "Usage: JobQueueClient ";
145    if ("-queueinfo".equals(cmd)){
146      System.err.println(prefix + "[" + cmd + "<job-queue-name> [-showJobs]]");
147    }else {
148      System.err.printf(prefix + "<command> <args>\n");
149      System.err.printf("\t[-list]\n");
150      System.err.printf("\t[-info <job-queue-name> [-showJobs]]\n\n");
151      ToolRunner.printGenericCommandUsage(System.out);
152    }
153  }
154
155  public static void main(String[] argv) throws Exception {
156    int res = ToolRunner.run(new JobQueueClient(), argv);
157    System.exit(res);
158  }
159 
160}
Note: See TracBrowser for help on using the repository browser.