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     */
018    package org.apache.hadoop.mapred;
019    
020    import java.util.Map;
021    
022    import org.apache.hadoop.classification.InterfaceAudience;
023    import org.apache.hadoop.classification.InterfaceStability;
024    import org.apache.hadoop.mapreduce.JobACL;
025    import 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     *@deprecated Use {@link org.apache.hadoop.mapreduce.JobStatus} instead
033     **/
034    @Deprecated
035    @InterfaceAudience.Public
036    @InterfaceStability.Stable
037    public class JobStatus extends org.apache.hadoop.mapreduce.JobStatus {
038    
039      public static final int RUNNING = 
040        org.apache.hadoop.mapreduce.JobStatus.State.RUNNING.getValue();
041      public static final int SUCCEEDED = 
042        org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED.getValue();
043      public static final int FAILED = 
044        org.apache.hadoop.mapreduce.JobStatus.State.FAILED.getValue();
045      public static final int PREP = 
046        org.apache.hadoop.mapreduce.JobStatus.State.PREP.getValue();
047      public static final int KILLED = 
048        org.apache.hadoop.mapreduce.JobStatus.State.KILLED.getValue();
049    
050      private static final String UNKNOWN = "UNKNOWN";
051      
052      private static final String[] runStates =
053        {UNKNOWN, "RUNNING", "SUCCEEDED", "FAILED", "PREP", "KILLED"};
054    
055      /**
056       * Helper method to get human-readable state of the job.
057       * @param state job state
058       * @return human-readable state of the job
059       */
060      public static String getJobRunState(int state) {
061        if (state < 1 || state >= runStates.length) {
062          return UNKNOWN;
063        }
064        return runStates[state];
065      }
066      
067      static org.apache.hadoop.mapreduce.JobStatus.State getEnum(int state) {
068        switch (state) {
069          case 1: return org.apache.hadoop.mapreduce.JobStatus.State.RUNNING;
070          case 2: return org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED;
071          case 3: return org.apache.hadoop.mapreduce.JobStatus.State.FAILED;
072          case 4: return org.apache.hadoop.mapreduce.JobStatus.State.PREP;
073          case 5: return org.apache.hadoop.mapreduce.JobStatus.State.KILLED;
074        }
075        return null;
076      }
077      
078      /**
079       */
080      public JobStatus() {
081      }
082    
083      /**
084       * Create a job status object for a given jobid.
085       * @param jobid The jobid of the job
086       * @param mapProgress The progress made on the maps
087       * @param reduceProgress The progress made on the reduces
088       * @param cleanupProgress The progress made on cleanup
089       * @param runState The current state of the job
090       * @param user userid of the person who submitted the job.
091       * @param jobName user-specified job name.
092       * @param jobFile job configuration file. 
093       * @param trackingUrl link to the web-ui for details of the job.
094       */
095      public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
096                       float cleanupProgress, int runState, 
097                       String user, String jobName, 
098                       String jobFile, String trackingUrl) {
099        this(jobid, mapProgress, reduceProgress, cleanupProgress, runState,
100                      JobPriority.NORMAL, user, jobName, jobFile, trackingUrl);
101      }
102    
103      /**
104       * Create a job status object for a given jobid.
105       * @param jobid The jobid of the job
106       * @param mapProgress The progress made on the maps
107       * @param reduceProgress The progress made on the reduces
108       * @param runState The current state of the job
109       * @param user userid of the person who submitted the job.
110       * @param jobName user-specified job name.
111       * @param jobFile job configuration file. 
112       * @param trackingUrl link to the web-ui for details of the job.
113       */
114      public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
115                       int runState, String user, String jobName, 
116                       String jobFile, String trackingUrl) {
117        this(jobid, mapProgress, reduceProgress, 0.0f, runState, user, jobName, 
118            jobFile, trackingUrl);
119      }
120    
121      /**
122       * Create a job status object for a given jobid.
123       * @param jobid The jobid of the job
124       * @param mapProgress The progress made on the maps
125       * @param reduceProgress The progress made on the reduces
126       * @param runState The current state of the job
127       * @param jp Priority of the job.
128       * @param user userid of the person who submitted the job.
129       * @param jobName user-specified job name.
130       * @param jobFile job configuration file. 
131       * @param trackingUrl link to the web-ui for details of the job.
132       */
133       public JobStatus(JobID jobid, float mapProgress, float reduceProgress,
134                          float cleanupProgress, int runState, JobPriority jp, 
135                          String user, String jobName, String jobFile, 
136                          String trackingUrl) {
137         this(jobid, 0.0f, mapProgress, reduceProgress, 
138              cleanupProgress, runState, jp, user, jobName, jobFile, trackingUrl);
139       }
140       
141      /**
142       * Create a job status object for a given jobid.
143       * @param jobid The jobid of the job
144       * @param setupProgress The progress made on the setup
145       * @param mapProgress The progress made on the maps
146       * @param reduceProgress The progress made on the reduces
147       * @param cleanupProgress The progress made on the cleanup
148       * @param runState The current state of the job
149       * @param jp Priority of the job.
150       * @param user userid of the person who submitted the job.
151       * @param jobName user-specified job name.
152       * @param jobFile job configuration file. 
153       * @param trackingUrl link to the web-ui for details of the job.
154       */
155       public JobStatus(JobID jobid, float setupProgress, float mapProgress,
156                        float reduceProgress, float cleanupProgress, 
157                        int runState, JobPriority jp, String user, String jobName, 
158                        String jobFile, String trackingUrl) {
159         this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
160             runState, jp,
161             user, jobName, "default", jobFile, trackingUrl);
162       }
163       
164       /**
165        * Create a job status object for a given jobid.
166        * @param jobid The jobid of the job
167        * @param setupProgress The progress made on the setup
168        * @param mapProgress The progress made on the maps
169        * @param reduceProgress The progress made on the reduces
170        * @param cleanupProgress The progress made on the cleanup
171        * @param runState The current state of the job
172        * @param jp Priority of the job.
173        * @param user userid of the person who submitted the job.
174        * @param jobName user-specified job name.
175        * @param queue job queue name.
176        * @param jobFile job configuration file. 
177        * @param trackingUrl link to the web-ui for details of the job.
178        */
179       public JobStatus(JobID jobid, float setupProgress, float mapProgress,
180           float reduceProgress, float cleanupProgress, 
181           int runState, JobPriority jp, 
182           String user, String jobName, String queue, 
183           String jobFile, String trackingUrl) {
184         super(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress,
185             getEnum(runState), org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()),
186             user, jobName, queue, jobFile, trackingUrl);
187       }
188    
189    
190      public static JobStatus downgrade(org.apache.hadoop.mapreduce.JobStatus stat){
191        JobStatus old = new JobStatus(JobID.downgrade(stat.getJobID()),
192          stat.getSetupProgress(), stat.getMapProgress(), stat.getReduceProgress(),
193          stat.getCleanupProgress(), stat.getState().getValue(), 
194          JobPriority.valueOf(stat.getPriority().name()),
195          stat.getUsername(), stat.getJobName(), stat.getJobFile(),
196          stat.getTrackingUrl());
197        old.setStartTime(stat.getStartTime());
198        old.setFinishTime(stat.getFinishTime());
199        old.setSchedulingInfo(stat.getSchedulingInfo());
200        old.setHistoryFile(stat.getHistoryFile());
201        return old;
202      }
203      /**
204       * @deprecated use getJobID instead
205       */
206      @Deprecated
207      public String getJobId() { return getJobID().toString(); }
208      
209      /**
210       * @return The jobid of the Job
211       */
212      public JobID getJobID() { return JobID.downgrade(super.getJobID()); }
213      
214      /**
215       * Return the priority of the job
216       * @return job priority
217       */
218       public synchronized JobPriority getJobPriority() { 
219         return JobPriority.valueOf(super.getPriority().name());
220       }
221    
222       /**
223        * Sets the map progress of this job
224        * @param p The value of map progress to set to
225        */
226       protected synchronized void setMapProgress(float p) { 
227         super.setMapProgress(p); 
228       }
229    
230       /**
231        * Sets the cleanup progress of this job
232        * @param p The value of cleanup progress to set to
233        */
234       protected synchronized void setCleanupProgress(float p) { 
235         super.setCleanupProgress(p); 
236       }
237    
238       /**
239        * Sets the setup progress of this job
240        * @param p The value of setup progress to set to
241        */
242       protected synchronized void setSetupProgress(float p) { 
243         super.setSetupProgress(p); 
244       }
245    
246       /**
247        * Sets the reduce progress of this Job
248        * @param p The value of reduce progress to set to
249        */
250       protected synchronized void setReduceProgress(float p) { 
251         super.setReduceProgress(p); 
252       }
253         
254       /** 
255        * Set the finish time of the job
256        * @param finishTime The finishTime of the job
257        */
258       protected synchronized void setFinishTime(long finishTime) {
259         super.setFinishTime(finishTime);
260       }
261    
262       /**
263        * Set the job history file url for a completed job
264        */
265       protected synchronized void setHistoryFile(String historyFile) {
266         super.setHistoryFile(historyFile);
267       }
268    
269       /**
270        * Set the link to the web-ui for details of the job.
271        */
272       protected synchronized void setTrackingUrl(String trackingUrl) {
273         super.setTrackingUrl(trackingUrl);
274       }
275    
276       /**
277        * Set the job retire flag to true.
278        */
279       protected synchronized void setRetired() {
280         super.setRetired();
281       }
282    
283       /**
284        * Change the current run state of the job.
285        */
286       protected synchronized void setRunState(int state) {
287         super.setState(getEnum(state));
288       }
289    
290       /**
291        * @return running state of the job
292        */
293       public synchronized int getRunState() { return super.getState().getValue(); }
294         
295    
296       /** 
297        * Set the start time of the job
298        * @param startTime The startTime of the job
299        */
300       protected synchronized void setStartTime(long startTime) { 
301         super.setStartTime(startTime);
302       }
303         
304       /**
305        * @param userName The username of the job
306        */
307       protected synchronized void setUsername(String userName) { 
308         super.setUsername(userName);
309       }
310    
311       /**
312        * Used to set the scheduling information associated to a particular Job.
313        * 
314        * @param schedulingInfo Scheduling information of the job
315        */
316       protected synchronized void setSchedulingInfo(String schedulingInfo) {
317         super.setSchedulingInfo(schedulingInfo);
318       }
319    
320       protected synchronized void setJobACLs(Map<JobACL, AccessControlList> acls) {
321         super.setJobACLs(acls);
322       }
323    
324       public synchronized void setFailureInfo(String failureInfo) {
325         super.setFailureInfo(failureInfo);
326       }
327       
328      /**
329       * Set the priority of the job, defaulting to NORMAL.
330       * @param jp new job priority
331       */
332       public synchronized void setJobPriority(JobPriority jp) {
333         super.setPriority(
334           org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()));
335       }
336      
337       /**
338        * @return Percentage of progress in maps 
339        */
340       public synchronized float mapProgress() { return super.getMapProgress(); }
341         
342       /**
343        * @return Percentage of progress in cleanup 
344        */
345       public synchronized float cleanupProgress() { 
346         return super.getCleanupProgress(); 
347       }
348         
349       /**
350        * @return Percentage of progress in setup 
351        */
352       public synchronized float setupProgress() { 
353         return super.getSetupProgress(); 
354       }
355         
356       /**
357        * @return Percentage of progress in reduce 
358        */
359       public synchronized float reduceProgress() { 
360         return super.getReduceProgress(); 
361       }
362    
363       // A utility to convert new job runstates to the old ones.
364       static int getOldNewJobRunState(
365         org.apache.hadoop.mapreduce.JobStatus.State state) {
366         return state.getValue();
367       }
368    }