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.mapreduce;
019
020import java.io.DataInput;
021import java.io.DataOutput;
022import java.io.IOException;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026import 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
060public 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 numDecommissionedTrackers;
073
074  public ClusterMetrics() {
075  }
076  
077  public ClusterMetrics(int runningMaps, int runningReduces,
078      int occupiedMapSlots, int occupiedReduceSlots,
079      int reservedMapSlots, int reservedReduceSlots,
080      int mapSlots, int reduceSlots, 
081      int totalJobSubmissions,
082      int numTrackers, int numBlacklistedTrackers,
083      int numDecommissionedNodes) {
084    this.runningMaps = runningMaps;
085    this.runningReduces = runningReduces;
086    this.occupiedMapSlots = occupiedMapSlots;
087    this.occupiedReduceSlots = occupiedReduceSlots;
088    this.reservedMapSlots = reservedMapSlots;
089    this.reservedReduceSlots = reservedReduceSlots;
090    this.totalMapSlots = mapSlots;
091    this.totalReduceSlots = reduceSlots;
092    this.totalJobSubmissions = totalJobSubmissions;
093    this.numTrackers = numTrackers;
094    this.numBlacklistedTrackers = numBlacklistedTrackers;
095    this.numDecommissionedTrackers = numDecommissionedNodes;
096  }
097
098  /**
099   * Get the number of running map tasks in the cluster.
100   * 
101   * @return running maps
102   */
103  public int getRunningMaps() {
104    return runningMaps;
105  }
106  
107  /**
108   * Get the number of running reduce tasks in the cluster.
109   * 
110   * @return running reduces
111   */
112  public int getRunningReduces() {
113    return runningReduces;
114  }
115  
116  /**
117   * Get number of occupied map slots in the cluster.
118   * 
119   * @return occupied map slot count
120   */
121  public int getOccupiedMapSlots() { 
122    return occupiedMapSlots;
123  }
124  
125  /**
126   * Get the number of occupied reduce slots in the cluster.
127   * 
128   * @return occupied reduce slot count
129   */
130  public int getOccupiedReduceSlots() { 
131    return occupiedReduceSlots; 
132  }
133
134  /**
135   * Get number of reserved map slots in the cluster.
136   * 
137   * @return reserved map slot count
138   */
139  public int getReservedMapSlots() { 
140    return reservedMapSlots;
141  }
142  
143  /**
144   * Get the number of reserved reduce slots in the cluster.
145   * 
146   * @return reserved reduce slot count
147   */
148  public int getReservedReduceSlots() { 
149    return reservedReduceSlots; 
150  }
151
152  /**
153   * Get the total number of map slots in the cluster.
154   * 
155   * @return map slot capacity
156   */
157  public int getMapSlotCapacity() {
158    return totalMapSlots;
159  }
160  
161  /**
162   * Get the total number of reduce slots in the cluster.
163   * 
164   * @return reduce slot capacity
165   */
166  public int getReduceSlotCapacity() {
167    return totalReduceSlots;
168  }
169  
170  /**
171   * Get the total number of job submissions in the cluster.
172   * 
173   * @return total number of job submissions
174   */
175  public int getTotalJobSubmissions() {
176    return totalJobSubmissions;
177  }
178  
179  /**
180   * Get the number of active trackers in the cluster.
181   * 
182   * @return active tracker count.
183   */
184  public int getTaskTrackerCount() {
185    return numTrackers;
186  }
187  
188  /**
189   * Get the number of blacklisted trackers in the cluster.
190   * 
191   * @return blacklisted tracker count
192   */
193  public int getBlackListedTaskTrackerCount() {
194    return numBlacklistedTrackers;
195  }
196  
197  /**
198   * Get the number of decommissioned trackers in the cluster.
199   * 
200   * @return decommissioned tracker count
201   */
202  public int getDecommissionedTaskTrackerCount() {
203    return numDecommissionedTrackers;
204  }
205
206  @Override
207  public void readFields(DataInput in) throws IOException {
208    runningMaps = in.readInt();
209    runningReduces = in.readInt();
210    occupiedMapSlots = in.readInt();
211    occupiedReduceSlots = in.readInt();
212    reservedMapSlots = in.readInt();
213    reservedReduceSlots = in.readInt();
214    totalMapSlots = in.readInt();
215    totalReduceSlots = in.readInt();
216    totalJobSubmissions = in.readInt();
217    numTrackers = in.readInt();
218    numBlacklistedTrackers = in.readInt();
219    numDecommissionedTrackers = in.readInt();
220  }
221
222  @Override
223  public void write(DataOutput out) throws IOException {
224    out.writeInt(runningMaps);
225    out.writeInt(runningReduces);
226    out.writeInt(occupiedMapSlots);
227    out.writeInt(occupiedReduceSlots);
228    out.writeInt(reservedMapSlots);
229    out.writeInt(reservedReduceSlots);
230    out.writeInt(totalMapSlots);
231    out.writeInt(totalReduceSlots);
232    out.writeInt(totalJobSubmissions);
233    out.writeInt(numTrackers);
234    out.writeInt(numBlacklistedTrackers);
235    out.writeInt(numDecommissionedTrackers);
236  }
237
238}