001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.mapred;
019
020import java.util.Map;
021
022import org.apache.hadoop.classification.InterfaceAudience;
023import org.apache.hadoop.classification.InterfaceStability;
024import org.apache.hadoop.mapreduce.JobACL;
025import org.apache.hadoop.security.authorize.AccessControlList;
026
027/**************************************************
028 * Describes the current status of a job.  This is
029 * not intended to be a comprehensive piece of data.
030 * For that, look at JobProfile.
031 *************************************************
032 **/
033@InterfaceAudience.Public
034@InterfaceStability.Stable
035public class JobStatus extends org.apache.hadoop.mapreduce.JobStatus {
036
037  public static final int RUNNING = 
038    org.apache.hadoop.mapreduce.JobStatus.State.RUNNING.getValue();
039  public static final int SUCCEEDED = 
040    org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED.getValue();
041  public static final int FAILED = 
042    org.apache.hadoop.mapreduce.JobStatus.State.FAILED.getValue();
043  public static final int PREP = 
044    org.apache.hadoop.mapreduce.JobStatus.State.PREP.getValue();
045  public static final int KILLED = 
046    org.apache.hadoop.mapreduce.JobStatus.State.KILLED.getValue();
047
048  private static final String UNKNOWN = "UNKNOWN";
049  
050  private static final String[] runStates =
051    {UNKNOWN, "RUNNING", "SUCCEEDED", "FAILED", "PREP", "KILLED"};
052
053  /**
054   * Helper method to get human-readable state of the job.
055   * @param state job state
056   * @return human-readable state of the job
057   */
058  public static String getJobRunState(int state) {
059    if (state < 1 || state >= runStates.length) {
060      return UNKNOWN;
061    }
062    return runStates[state];
063  }
064  
065  static org.apache.hadoop.mapreduce.JobStatus.State getEnum(int state) {
066    switch (state) {
067      case 1: return org.apache.hadoop.mapreduce.JobStatus.State.RUNNING;
068      case 2: return org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED;
069      case 3: return org.apache.hadoop.mapreduce.JobStatus.State.FAILED;
070      case 4: return org.apache.hadoop.mapreduce.JobStatus.State.PREP;
071      case 5: return org.apache.hadoop.mapreduce.JobStatus.State.KILLED;
072    }
073    return null;
074  }
075  
076  /**
077   */
078  public JobStatus() {
079  }
080  
081  @Deprecated
082  public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
083      float cleanupProgress, int runState) {
084    this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, null,
085        null, null, null);
086  }
087
088  /**
089   * Create a job status object for a given jobid.
090   * @param jobid The jobid of the job
091   * @param mapProgress The progress made on the maps
092   * @param reduceProgress The progress made on the reduces
093   * @param runState The current state of the job
094   */
095  @Deprecated
096  public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
097      int runState) {
098    this (jobid, mapProgress, reduceProgress, runState, null, null, null, null);
099  }
100
101  /**
102   * Create a job status object for a given jobid.
103   * @param jobid The jobid of the job
104   * @param mapProgress The progress made on the maps
105   * @param reduceProgress The progress made on the reduces
106   * @param runState The current state of the job
107   * @param jp Priority of the job.
108   */
109  @Deprecated
110  public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
111      float cleanupProgress, int runState, JobPriority jp) {
112    this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, jp,
113        null, null, null, null);
114  }
115
116  /**
117   * Create a job status object for a given jobid.
118   * @param jobid The jobid of the job
119   * @param setupProgress The progress made on the setup
120   * @param mapProgress The progress made on the maps
121   * @param reduceProgress The progress made on the reduces
122   * @param cleanupProgress The progress made on the cleanup
123   * @param runState The current state of the job
124   * @param jp Priority of the job.
125   */
126  @Deprecated
127  public JobStatus(JobID jobid, float setupProgress, float mapProgress,
128      float reduceProgress, float cleanupProgress, 
129      int runState, JobPriority jp) {
130    this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
131        runState, jp, null, null, null, null);
132  }
133
134  /**
135   * Create a job status object for a given jobid.
136   * @param jobid The jobid of the job
137   * @param mapProgress The progress made on the maps
138   * @param reduceProgress The progress made on the reduces
139   * @param cleanupProgress The progress made on cleanup
140   * @param runState The current state of the job
141   * @param user userid of the person who submitted the job.
142   * @param jobName user-specified job name.
143   * @param jobFile job configuration file. 
144   * @param trackingUrl link to the web-ui for details of the job.
145   */
146  public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
147                   float cleanupProgress, int runState, 
148                   String user, String jobName, 
149                   String jobFile, String trackingUrl) {
150    this(jobid, mapProgress, reduceProgress, cleanupProgress, runState,
151        JobPriority.DEFAULT, user, jobName, jobFile, trackingUrl);
152  }
153
154  /**
155   * Create a job status object for a given jobid.
156   * @param jobid The jobid of the job
157   * @param mapProgress The progress made on the maps
158   * @param reduceProgress The progress made on the reduces
159   * @param runState The current state of the job
160   * @param user userid of the person who submitted the job.
161   * @param jobName user-specified job name.
162   * @param jobFile job configuration file. 
163   * @param trackingUrl link to the web-ui for details of the job.
164   */
165  public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
166                   int runState, String user, String jobName, 
167                   String jobFile, String trackingUrl) {
168    this(jobid, mapProgress, reduceProgress, 0.0f, runState, user, jobName, 
169        jobFile, trackingUrl);
170  }
171
172  /**
173   * Create a job status object for a given jobid.
174   * @param jobid The jobid of the job
175   * @param mapProgress The progress made on the maps
176   * @param reduceProgress The progress made on the reduces
177   * @param runState The current state of the job
178   * @param jp Priority of the job.
179   * @param user userid of the person who submitted the job.
180   * @param jobName user-specified job name.
181   * @param jobFile job configuration file. 
182   * @param trackingUrl link to the web-ui for details of the job.
183   */
184   public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
185                      float cleanupProgress, int runState, JobPriority jp, 
186                      String user, String jobName, String jobFile, 
187                      String trackingUrl) {
188     this(jobid, 0.0f, mapProgress, reduceProgress, 
189          cleanupProgress, runState, jp, user, jobName, jobFile,
190          trackingUrl);
191   }
192   
193  /**
194   * Create a job status object for a given jobid.
195   * @param jobid The jobid of the job
196   * @param setupProgress The progress made on the setup
197   * @param mapProgress The progress made on the maps
198   * @param reduceProgress The progress made on the reduces
199   * @param cleanupProgress The progress made on the cleanup
200   * @param runState The current state of the job
201   * @param jp Priority of the job.
202   * @param user userid of the person who submitted the job.
203   * @param jobName user-specified job name.
204   * @param jobFile job configuration file.
205   * @param trackingUrl link to the web-ui for details of the job.
206   */
207   public JobStatus(JobID jobid, float setupProgress, float mapProgress,
208                    float reduceProgress, float cleanupProgress,
209                    int runState, JobPriority jp, String user, String jobName,
210                    String jobFile, String trackingUrl) {
211     this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
212         runState, jp, user, jobName, "default", jobFile, trackingUrl);
213   }
214
215   /**
216    * Create a job status object for a given jobid.
217    * @param jobid The jobid of the job
218    * @param setupProgress The progress made on the setup
219    * @param mapProgress The progress made on the maps
220    * @param reduceProgress The progress made on the reduces
221    * @param cleanupProgress The progress made on the cleanup
222    * @param runState The current state of the job
223    * @param jp Priority of the job.
224    * @param user userid of the person who submitted the job.
225    * @param jobName user-specified job name.
226    * @param jobFile job configuration file.
227    * @param trackingUrl link to the web-ui for details of the job.
228    * @param isUber Whether job running in uber mode
229    */
230    public JobStatus(JobID jobid, float setupProgress, float mapProgress,
231                     float reduceProgress, float cleanupProgress,
232                     int runState, JobPriority jp, String user, String jobName,
233                     String jobFile, String trackingUrl, boolean isUber) {
234      this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
235          runState, jp, user, jobName, "default", jobFile, trackingUrl, isUber);
236  }
237
238   /**
239    * Create a job status object for a given jobid.
240    * @param jobid The jobid of the job
241    * @param setupProgress The progress made on the setup
242    * @param mapProgress The progress made on the maps
243    * @param reduceProgress The progress made on the reduces
244    * @param cleanupProgress The progress made on the cleanup
245    * @param runState The current state of the job
246    * @param jp Priority of the job.
247    * @param user userid of the person who submitted the job.
248    * @param jobName user-specified job name.
249    * @param jobFile job configuration file.
250    * @param trackingUrl link to the web-ui for details of the job.
251    * @param isUber Whether job running in uber mode
252    * @param historyFile history file
253    */
254  public JobStatus(JobID jobid, float setupProgress, float mapProgress,
255                   float reduceProgress, float cleanupProgress,
256                   int runState, JobPriority jp, String user, String jobName,
257                   String jobFile, String trackingUrl, boolean isUber,
258                   String historyFile) {
259      this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
260          runState, jp, user, jobName, "default", jobFile, trackingUrl, isUber,
261          historyFile);
262  }
263   
264   /**
265    * Create a job status object for a given jobid.
266    * @param jobid The jobid of the job
267    * @param setupProgress The progress made on the setup
268    * @param mapProgress The progress made on the maps
269    * @param reduceProgress The progress made on the reduces
270    * @param cleanupProgress The progress made on the cleanup
271    * @param runState The current state of the job
272    * @param jp Priority of the job.
273    * @param user userid of the person who submitted the job.
274    * @param jobName user-specified job name.
275    * @param queue job queue name.
276    * @param jobFile job configuration file.
277    * @param trackingUrl link to the web-ui for details of the job.
278    */
279   public JobStatus(JobID jobid, float setupProgress, float mapProgress,
280       float reduceProgress, float cleanupProgress,
281       int runState, JobPriority jp,
282       String user, String jobName, String queue,
283       String jobFile, String trackingUrl) {
284     this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
285         runState, jp,
286         user, jobName, queue, jobFile, trackingUrl, false);
287   }
288
289   /**
290    * Create a job status object for a given jobid.
291    * @param jobid The jobid of the job
292    * @param setupProgress The progress made on the setup
293    * @param mapProgress The progress made on the maps
294    * @param reduceProgress The progress made on the reduces
295    * @param cleanupProgress The progress made on the cleanup
296    * @param runState The current state of the job
297    * @param jp Priority of the job.
298    * @param user userid of the person who submitted the job.
299    * @param jobName user-specified job name.
300    * @param queue job queue name.
301    * @param jobFile job configuration file. 
302    * @param trackingUrl link to the web-ui for details of the job.
303    * @param isUber Whether job running in uber mode
304    */
305   public JobStatus(JobID jobid, float setupProgress, float mapProgress,
306       float reduceProgress, float cleanupProgress, 
307       int runState, JobPriority jp, 
308       String user, String jobName, String queue, 
309       String jobFile, String trackingUrl, boolean isUber) {
310     this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
311         runState, jp, user, jobName, queue, jobFile, trackingUrl, isUber, "");
312   }
313
314  /**
315   * Create a job status object for a given jobid.
316   * @param jobid The jobid of the job
317   * @param setupProgress The progress made on the setup
318   * @param mapProgress The progress made on the maps
319   * @param reduceProgress The progress made on the reduces
320   * @param cleanupProgress The progress made on the cleanup
321   * @param runState The current state of the job
322   * @param jp Priority of the job.
323   * @param user userid of the person who submitted the job.
324   * @param jobName user-specified job name.
325   * @param queue job queue name.
326   * @param jobFile job configuration file.
327   * @param trackingUrl link to the web-ui for details of the job.
328   * @param isUber Whether job running in uber mode
329   * @param historyFile history file
330   */
331  public JobStatus(JobID jobid, float setupProgress, float mapProgress,
332                   float reduceProgress, float cleanupProgress,
333                   int runState, JobPriority jp,
334                   String user, String jobName, String queue,
335                   String jobFile, String trackingUrl, boolean isUber,
336                   String historyFile) {
337    super(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
338        getEnum(runState),
339        org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()),
340        user, jobName, queue, jobFile, trackingUrl, isUber, historyFile);
341  }
342
343  public static JobStatus downgrade(org.apache.hadoop.mapreduce.JobStatus stat){
344    JobStatus old = new JobStatus(JobID.downgrade(stat.getJobID()),
345      stat.getSetupProgress(), stat.getMapProgress(), stat.getReduceProgress(),
346      stat.getCleanupProgress(), stat.getState().getValue(), 
347      JobPriority.valueOf(stat.getPriority().name()),
348      stat.getUsername(), stat.getJobName(), stat.getQueue(), stat.getJobFile(),
349      stat.getTrackingUrl(), stat.isUber());
350    old.setStartTime(stat.getStartTime());
351    old.setFinishTime(stat.getFinishTime());
352    old.setSchedulingInfo(stat.getSchedulingInfo());
353    old.setHistoryFile(stat.getHistoryFile());
354    return old;
355  }
356  /**
357   * @deprecated use getJobID instead
358   */
359  @Deprecated
360  public String getJobId() { return getJobID().toString(); }
361  
362  /**
363   * @return The jobid of the Job
364   */
365  public JobID getJobID() { return JobID.downgrade(super.getJobID()); }
366  
367  /**
368   * Return the priority of the job
369   * @return job priority
370   */
371   public synchronized JobPriority getJobPriority() { 
372     return JobPriority.valueOf(super.getPriority().name());
373   }
374
375   /**
376    * Sets the map progress of this job
377    * @param p The value of map progress to set to
378    */
379   protected synchronized void setMapProgress(float p) { 
380     super.setMapProgress(p); 
381   }
382
383   /**
384    * Sets the cleanup progress of this job
385    * @param p The value of cleanup progress to set to
386    */
387   protected synchronized void setCleanupProgress(float p) { 
388     super.setCleanupProgress(p); 
389   }
390
391   /**
392    * Sets the setup progress of this job
393    * @param p The value of setup progress to set to
394    */
395   protected synchronized void setSetupProgress(float p) { 
396     super.setSetupProgress(p); 
397   }
398
399   /**
400    * Sets the reduce progress of this Job
401    * @param p The value of reduce progress to set to
402    */
403   protected synchronized void setReduceProgress(float p) { 
404     super.setReduceProgress(p); 
405   }
406     
407   /** 
408    * Set the finish time of the job
409    * @param finishTime The finishTime of the job
410    */
411   protected synchronized void setFinishTime(long finishTime) {
412     super.setFinishTime(finishTime);
413   }
414
415   /**
416    * Set the job history file url for a completed job
417    */
418   protected synchronized void setHistoryFile(String historyFile) {
419     super.setHistoryFile(historyFile);
420   }
421
422   /**
423    * Set the link to the web-ui for details of the job.
424    */
425   protected synchronized void setTrackingUrl(String trackingUrl) {
426     super.setTrackingUrl(trackingUrl);
427   }
428
429   /**
430    * Set the job retire flag to true.
431    */
432   protected synchronized void setRetired() {
433     super.setRetired();
434   }
435
436   /**
437    * Change the current run state of the job.
438    *
439    * The setter is public to be compatible with M/R 1.x, however, it should be
440    * used internally.
441    *
442    * @param state the state of the job
443    */
444   @InterfaceAudience.Private
445   public synchronized void setRunState(int state) {
446     super.setState(getEnum(state));
447   }
448
449   /**
450    * @return running state of the job
451    */
452   public synchronized int getRunState() { return super.getState().getValue(); }
453     
454
455   /** 
456    * Set the start time of the job
457    * @param startTime The startTime of the job
458    */
459   protected synchronized void setStartTime(long startTime) { 
460     super.setStartTime(startTime);
461   }
462     
463   /**
464    * @param userName The username of the job
465    */
466   protected synchronized void setUsername(String userName) { 
467     super.setUsername(userName);
468   }
469
470   /**
471    * Used to set the scheduling information associated to a particular Job.
472    *
473    * The setter is public to be compatible with M/R 1.x, however, it should be
474    * used internally.
475    *
476    * @param schedulingInfo Scheduling information of the job
477    */
478   @InterfaceAudience.Private
479   public synchronized void setSchedulingInfo(String schedulingInfo) {
480     super.setSchedulingInfo(schedulingInfo);
481   }
482
483   protected synchronized void setJobACLs(Map<JobACL, AccessControlList> acls) {
484     super.setJobACLs(acls);
485   }
486
487   public synchronized void setFailureInfo(String failureInfo) {
488     super.setFailureInfo(failureInfo);
489   }
490   
491  /**
492   * Set the priority of the job, defaulting to NORMAL.
493   * @param jp new job priority
494   */
495   public synchronized void setJobPriority(JobPriority jp) {
496     super.setPriority(
497       org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()));
498   }
499  
500   /**
501    * @return Percentage of progress in maps 
502    */
503   public synchronized float mapProgress() { return super.getMapProgress(); }
504     
505   /**
506    * @return Percentage of progress in cleanup 
507    */
508   public synchronized float cleanupProgress() { 
509     return super.getCleanupProgress(); 
510   }
511     
512   /**
513    * @return Percentage of progress in setup 
514    */
515   public synchronized float setupProgress() { 
516     return super.getSetupProgress(); 
517   }
518     
519   /**
520    * @return Percentage of progress in reduce 
521    */
522   public synchronized float reduceProgress() { 
523     return super.getReduceProgress(); 
524   }
525
526   // A utility to convert new job runstates to the old ones.
527   static int getOldNewJobRunState(
528     org.apache.hadoop.mapreduce.JobStatus.State state) {
529     return state.getValue();
530   }
531}