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.ArrayList;
021    import java.util.List;
022    import java.util.Properties;
023    
024    import org.apache.hadoop.classification.InterfaceAudience;
025    import org.apache.hadoop.classification.InterfaceStability;
026    import org.apache.hadoop.mapreduce.QueueInfo;
027    import org.apache.hadoop.mapreduce.QueueState;
028    
029    /**
030     * Class that contains the information regarding the Job Queues which are 
031     * maintained by the Hadoop Map/Reduce framework.
032     */
033    @InterfaceAudience.Public
034    @InterfaceStability.Stable
035    public class JobQueueInfo extends QueueInfo {
036    
037      /**
038       * Default constructor for Job Queue Info.
039       * 
040       */
041      public JobQueueInfo() {
042        super();  
043      }
044    
045      /**
046       * Construct a new JobQueueInfo object using the queue name and the
047       * scheduling information passed.
048       * 
049       * @param queueName Name of the job queue
050       * @param schedulingInfo Scheduling Information associated with the job
051       * queue
052       */
053      public JobQueueInfo(String queueName, String schedulingInfo) {
054        super(queueName, schedulingInfo);
055      }
056      
057      JobQueueInfo(QueueInfo queue) {
058        this(queue.getQueueName(), queue.getSchedulingInfo());
059        setQueueState(queue.getState().getStateName());
060        setQueueChildren(queue.getQueueChildren());
061        setProperties(queue.getProperties());
062        setJobStatuses(queue.getJobStatuses());
063      }
064      
065      /**
066       * Set the queue name of the JobQueueInfo
067       * 
068       * @param queueName Name of the job queue.
069       */
070      protected void setQueueName(String queueName) {
071        super.setQueueName(queueName);
072      }
073    
074      /**
075       * Set the scheduling information associated to particular job queue
076       * 
077       * @param schedulingInfo
078       */
079      protected void setSchedulingInfo(String schedulingInfo) {
080        super.setSchedulingInfo(schedulingInfo);
081      }
082    
083      /**
084       * Set the state of the queue
085       * @param state state of the queue.
086       */
087      protected void setQueueState(String state) {
088        super.setState(QueueState.getState(state));
089      }
090      
091      String getQueueState() {
092        return super.getState().toString();
093      }
094      
095      protected void setChildren(List<JobQueueInfo> children) {
096        List<QueueInfo> list = new ArrayList<QueueInfo>();
097        for (JobQueueInfo q : children) {
098          list.add(q);
099        }
100        super.setQueueChildren(list);
101      }
102    
103      public List<JobQueueInfo> getChildren() {
104        List<JobQueueInfo> list = new ArrayList<JobQueueInfo>();
105        for (QueueInfo q : super.getQueueChildren()) {
106          list.add((JobQueueInfo)q);
107        }
108        return list;
109      }
110    
111      protected void setProperties(Properties props) {
112        super.setProperties(props);
113      }
114    
115      /**
116       * Add a child {@link JobQueueInfo} to this {@link JobQueueInfo}. Modify the
117       * fully-qualified name of the child {@link JobQueueInfo} to reflect the
118       * hierarchy.
119       * 
120       * Only for testing.
121       * 
122       * @param child
123       */
124      void addChild(JobQueueInfo child) {
125        List<JobQueueInfo> children = getChildren();
126        children.add(child);
127        setChildren(children);
128      }
129    
130      /**
131       * Remove the child from this {@link JobQueueInfo}. This also resets the
132       * queue-name of the child from a fully-qualified name to a simple queue name.
133       * 
134       * Only for testing.
135       * 
136       * @param child
137       */
138      void removeChild(JobQueueInfo child) {
139        List<JobQueueInfo> children = getChildren();
140        children.remove(child);
141        setChildren(children);
142      }
143    
144      protected void setJobStatuses(org.apache.hadoop.mapreduce.JobStatus[] stats) {
145        super.setJobStatuses(stats);
146      }
147    
148    }