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    
019    package org.apache.hadoop.mapred.jobcontrol;
020    
021    
022    import java.io.IOException;
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    import org.apache.commons.logging.Log;
027    import org.apache.commons.logging.LogFactory;
028    import org.apache.hadoop.classification.InterfaceAudience;
029    import org.apache.hadoop.classification.InterfaceStability;
030    import org.apache.hadoop.mapred.JobClient;
031    import org.apache.hadoop.mapred.JobConf;
032    import org.apache.hadoop.mapred.JobID;
033    import org.apache.hadoop.mapreduce.lib.jobcontrol.ControlledJob;
034    
035    /** 
036     * @deprecated Use {@link ControlledJob} instead.  
037     */
038    @Deprecated
039    @InterfaceAudience.Public
040    @InterfaceStability.Stable
041    public class Job extends ControlledJob {
042      static final Log LOG = LogFactory.getLog(Job.class);
043    
044      final public static int SUCCESS = 0;
045      final public static int WAITING = 1;
046      final public static int RUNNING = 2;
047      final public static int READY = 3;
048      final public static int FAILED = 4;
049      final public static int DEPENDENT_FAILED = 5;
050    
051      /** 
052       * Construct a job.
053       * @param jobConf a mapred job configuration representing a job to be executed.
054       * @param dependingJobs an array of jobs the current job depends on
055       */
056      @SuppressWarnings("unchecked")
057      public Job(JobConf jobConf, ArrayList<?> dependingJobs) throws IOException {
058        super(new org.apache.hadoop.mapreduce.Job(jobConf), 
059              (List<ControlledJob>) dependingJobs);
060      }
061    
062      public Job(JobConf conf) throws IOException {
063        super(conf);
064      }
065    
066      /**
067       * @return the mapred ID of this job as assigned by the 
068       * mapred framework.
069       */
070      public JobID getAssignedJobID() {
071        org.apache.hadoop.mapreduce.JobID temp = super.getMapredJobID();
072        if(temp == null) {
073          return null;
074        }
075        return JobID.downgrade(temp);
076      }
077    
078      /**
079       * @deprecated setAssignedJobID should not be called.
080       * JOBID is set by the framework.
081       */
082      @Deprecated
083      public void setAssignedJobID(JobID mapredJobID) {
084        // do nothing
085      }
086    
087      /**
088       * @return the mapred job conf of this job
089       */
090      public synchronized JobConf getJobConf() {
091        return new JobConf(super.getJob().getConfiguration());
092      }
093    
094    
095      /**
096       * Set the mapred job conf for this job.
097       * @param jobConf the mapred job conf for this job.
098       */
099      public synchronized void setJobConf(JobConf jobConf) {
100        try {
101          super.setJob(new org.apache.hadoop.mapreduce.Job(jobConf));
102        } catch (IOException ioe) { 
103          LOG.info("Exception" + ioe);
104        }
105      }
106    
107      /**
108       * @return the state of this job
109       */
110      public synchronized int getState() {
111        State state = super.getJobState();
112        if (state == State.SUCCESS) {
113          return SUCCESS;
114        } 
115        if (state == State.WAITING) {
116          return WAITING;
117        }
118        if (state == State.RUNNING) {
119          return RUNNING;
120        }
121        if (state == State.READY) {
122          return READY;
123        }
124        if (state == State.FAILED ) {
125          return FAILED;
126        }
127        if (state == State.DEPENDENT_FAILED ) {
128          return DEPENDENT_FAILED;
129        }
130        return -1;
131      }
132      
133      /**
134       * @return the job client of this job
135       */
136      public JobClient getJobClient() {
137        try {
138          return new JobClient(super.getJob().getConfiguration());
139        } catch (IOException ioe) {
140          return null;
141        }
142      }
143    
144      /**
145       * @return the depending jobs of this job
146       */
147      public ArrayList<Job> getDependingJobs() {
148        return JobControl.castToJobList(super.getDependentJobs());
149      }
150    
151    }