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.mapreduce;
019    
020    import java.io.DataInput;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    
024    import org.apache.hadoop.classification.InterfaceAudience;
025    import org.apache.hadoop.classification.InterfaceStability;
026    import org.apache.hadoop.io.Writable;
027    
028    /**
029     * Status information on the current state of the Map-Reduce cluster.
030     * 
031     * <p><code>ClusterMetrics</code> provides clients with information such as:
032     * <ol>
033     *   <li>
034     *   Size of the cluster.  
035     *   </li>
036     *   <li>
037     *   Number of blacklisted and decommissioned trackers.  
038     *   </li>
039     *   <li>
040     *   Slot capacity of the cluster. 
041     *   </li>
042     *   <li>
043     *   The number of currently occupied/reserved map & reduce slots.
044     *   </li>
045     *   <li>
046     *   The number of currently running map & reduce tasks.
047     *   </li>
048     *   <li>
049     *   The number of job submissions.
050     *   </li>
051     * </ol></p>
052     * 
053     * <p>Clients can query for the latest <code>ClusterMetrics</code>, via 
054     * {@link Cluster#getClusterStatus()}.</p>
055     * 
056     * @see Cluster
057     */
058    @InterfaceAudience.Public
059    @InterfaceStability.Evolving
060    public class ClusterMetrics implements Writable {
061      private int runningMaps;
062      private int runningReduces;
063      private int occupiedMapSlots;
064      private int occupiedReduceSlots;
065      private int reservedMapSlots;
066      private int reservedReduceSlots;
067      private int totalMapSlots;
068      private int totalReduceSlots;
069      private int totalJobSubmissions;
070      private int numTrackers;
071      private int numBlacklistedTrackers;
072      private int numGraylistedTrackers;
073      private int numDecommissionedTrackers;
074    
075      public ClusterMetrics() {
076      }
077      
078      public ClusterMetrics(int runningMaps, int runningReduces,
079          int occupiedMapSlots, int occupiedReduceSlots, int reservedMapSlots,
080          int reservedReduceSlots, int mapSlots, int reduceSlots,
081          int totalJobSubmissions, int numTrackers, int numBlacklistedTrackers,
082          int numDecommissionedNodes) {
083        this(runningMaps, runningReduces, occupiedMapSlots, occupiedReduceSlots,
084          reservedMapSlots, reservedReduceSlots, mapSlots, reduceSlots,
085          totalJobSubmissions, numTrackers, numBlacklistedTrackers, 0,
086          numDecommissionedNodes);
087      }
088    
089      public ClusterMetrics(int runningMaps, int runningReduces,
090          int occupiedMapSlots, int occupiedReduceSlots, int reservedMapSlots,
091          int reservedReduceSlots, int mapSlots, int reduceSlots,
092          int totalJobSubmissions, int numTrackers, int numBlacklistedTrackers,
093          int numGraylistedTrackers, int numDecommissionedNodes) {
094        this.runningMaps = runningMaps;
095        this.runningReduces = runningReduces;
096        this.occupiedMapSlots = occupiedMapSlots;
097        this.occupiedReduceSlots = occupiedReduceSlots;
098        this.reservedMapSlots = reservedMapSlots;
099        this.reservedReduceSlots = reservedReduceSlots;
100        this.totalMapSlots = mapSlots;
101        this.totalReduceSlots = reduceSlots;
102        this.totalJobSubmissions = totalJobSubmissions;
103        this.numTrackers = numTrackers;
104        this.numBlacklistedTrackers = numBlacklistedTrackers;
105        this.numGraylistedTrackers = numGraylistedTrackers;
106        this.numDecommissionedTrackers = numDecommissionedNodes;
107      }
108    
109      /**
110       * Get the number of running map tasks in the cluster.
111       * 
112       * @return running maps
113       */
114      public int getRunningMaps() {
115        return runningMaps;
116      }
117      
118      /**
119       * Get the number of running reduce tasks in the cluster.
120       * 
121       * @return running reduces
122       */
123      public int getRunningReduces() {
124        return runningReduces;
125      }
126      
127      /**
128       * Get number of occupied map slots in the cluster.
129       * 
130       * @return occupied map slot count
131       */
132      public int getOccupiedMapSlots() { 
133        return occupiedMapSlots;
134      }
135      
136      /**
137       * Get the number of occupied reduce slots in the cluster.
138       * 
139       * @return occupied reduce slot count
140       */
141      public int getOccupiedReduceSlots() { 
142        return occupiedReduceSlots; 
143      }
144    
145      /**
146       * Get number of reserved map slots in the cluster.
147       * 
148       * @return reserved map slot count
149       */
150      public int getReservedMapSlots() { 
151        return reservedMapSlots;
152      }
153      
154      /**
155       * Get the number of reserved reduce slots in the cluster.
156       * 
157       * @return reserved reduce slot count
158       */
159      public int getReservedReduceSlots() { 
160        return reservedReduceSlots; 
161      }
162    
163      /**
164       * Get the total number of map slots in the cluster.
165       * 
166       * @return map slot capacity
167       */
168      public int getMapSlotCapacity() {
169        return totalMapSlots;
170      }
171      
172      /**
173       * Get the total number of reduce slots in the cluster.
174       * 
175       * @return reduce slot capacity
176       */
177      public int getReduceSlotCapacity() {
178        return totalReduceSlots;
179      }
180      
181      /**
182       * Get the total number of job submissions in the cluster.
183       * 
184       * @return total number of job submissions
185       */
186      public int getTotalJobSubmissions() {
187        return totalJobSubmissions;
188      }
189      
190      /**
191       * Get the number of active trackers in the cluster.
192       * 
193       * @return active tracker count.
194       */
195      public int getTaskTrackerCount() {
196        return numTrackers;
197      }
198      
199      /**
200       * Get the number of blacklisted trackers in the cluster.
201       * 
202       * @return blacklisted tracker count
203       */
204      public int getBlackListedTaskTrackerCount() {
205        return numBlacklistedTrackers;
206      }
207      
208      /**
209       * Get the number of graylisted trackers in the cluster.
210       * 
211       * @return graylisted tracker count
212       */
213      public int getGrayListedTaskTrackerCount() {
214        return numGraylistedTrackers;
215      }
216      
217      /**
218       * Get the number of decommissioned trackers in the cluster.
219       * 
220       * @return decommissioned tracker count
221       */
222      public int getDecommissionedTaskTrackerCount() {
223        return numDecommissionedTrackers;
224      }
225    
226      @Override
227      public void readFields(DataInput in) throws IOException {
228        runningMaps = in.readInt();
229        runningReduces = in.readInt();
230        occupiedMapSlots = in.readInt();
231        occupiedReduceSlots = in.readInt();
232        reservedMapSlots = in.readInt();
233        reservedReduceSlots = in.readInt();
234        totalMapSlots = in.readInt();
235        totalReduceSlots = in.readInt();
236        totalJobSubmissions = in.readInt();
237        numTrackers = in.readInt();
238        numBlacklistedTrackers = in.readInt();
239        numGraylistedTrackers = in.readInt();
240        numDecommissionedTrackers = in.readInt();
241      }
242    
243      @Override
244      public void write(DataOutput out) throws IOException {
245        out.writeInt(runningMaps);
246        out.writeInt(runningReduces);
247        out.writeInt(occupiedMapSlots);
248        out.writeInt(occupiedReduceSlots);
249        out.writeInt(reservedMapSlots);
250        out.writeInt(reservedReduceSlots);
251        out.writeInt(totalMapSlots);
252        out.writeInt(totalReduceSlots);
253        out.writeInt(totalJobSubmissions);
254        out.writeInt(numTrackers);
255        out.writeInt(numBlacklistedTrackers);
256        out.writeInt(numGraylistedTrackers);
257        out.writeInt(numDecommissionedTrackers);
258      }
259    
260    }