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
019package org.apache.hadoop.yarn.api.records;
020
021import org.apache.hadoop.classification.InterfaceAudience.Private;
022import org.apache.hadoop.classification.InterfaceAudience.Public;
023import org.apache.hadoop.classification.InterfaceStability.Stable;
024import org.apache.hadoop.classification.InterfaceStability.Unstable;
025import org.apache.hadoop.yarn.util.Records;
026
027/**
028 * Contains various scheduling metrics to be reported by UI and CLI.
029 */
030@Public
031@Stable
032public abstract class ApplicationResourceUsageReport {
033
034  @Private
035  @Unstable
036  public static ApplicationResourceUsageReport newInstance(
037      int numUsedContainers, int numReservedContainers, Resource usedResources,
038      Resource reservedResources, Resource neededResources, long memorySeconds,
039      long vcoreSeconds, float queueUsagePerc, float clusterUsagePerc) {
040    ApplicationResourceUsageReport report =
041        Records.newRecord(ApplicationResourceUsageReport.class);
042    report.setNumUsedContainers(numUsedContainers);
043    report.setNumReservedContainers(numReservedContainers);
044    report.setUsedResources(usedResources);
045    report.setReservedResources(reservedResources);
046    report.setNeededResources(neededResources);
047    report.setMemorySeconds(memorySeconds);
048    report.setVcoreSeconds(vcoreSeconds);
049    report.setQueueUsagePercentage(queueUsagePerc);
050    report.setClusterUsagePercentage(clusterUsagePerc);
051    return report;
052  }
053
054  /**
055   * Get the number of used containers.  -1 for invalid/inaccessible reports.
056   * @return the number of used containers
057   */
058  @Public
059  @Stable
060  public abstract int getNumUsedContainers();
061
062  /**
063   * Set the number of used containers
064   * @param num_containers the number of used containers
065   */
066  @Private
067  @Unstable
068  public abstract void setNumUsedContainers(int num_containers);
069
070  /**
071   * Get the number of reserved containers.  -1 for invalid/inaccessible reports.
072   * @return the number of reserved containers
073   */
074  @Private
075  @Unstable
076  public abstract int getNumReservedContainers();
077
078  /**
079   * Set the number of reserved containers
080   * @param num_reserved_containers the number of reserved containers
081   */
082  @Private
083  @Unstable
084  public abstract void setNumReservedContainers(int num_reserved_containers);
085
086  /**
087   * Get the used <code>Resource</code>.  -1 for invalid/inaccessible reports.
088   * @return the used <code>Resource</code>
089   */
090  @Public
091  @Stable
092  public abstract Resource getUsedResources();
093
094  @Private
095  @Unstable
096  public abstract void setUsedResources(Resource resources);
097
098  /**
099   * Get the reserved <code>Resource</code>.  -1 for invalid/inaccessible reports.
100   * @return the reserved <code>Resource</code>
101   */
102  @Public
103  @Stable
104  public abstract Resource getReservedResources();
105
106  @Private
107  @Unstable
108  public abstract void setReservedResources(Resource reserved_resources);
109
110  /**
111   * Get the needed <code>Resource</code>.  -1 for invalid/inaccessible reports.
112   * @return the needed <code>Resource</code>
113   */
114  @Public
115  @Stable
116  public abstract Resource getNeededResources();
117
118  @Private
119  @Unstable
120  public abstract void setNeededResources(Resource needed_resources);
121
122  /**
123   * Set the aggregated amount of memory (in megabytes) the application has
124   * allocated times the number of seconds the application has been running.
125   * @param memory_seconds the aggregated amount of memory seconds
126   */
127  @Private
128  @Unstable
129  public abstract void setMemorySeconds(long memory_seconds);
130
131  /**
132   * Get the aggregated amount of memory (in megabytes) the application has
133   * allocated times the number of seconds the application has been running.
134   * @return the aggregated amount of memory seconds
135   */
136  @Public
137  @Unstable
138  public abstract long getMemorySeconds();
139
140  /**
141   * Set the aggregated number of vcores that the application has allocated
142   * times the number of seconds the application has been running.
143   * @param vcore_seconds the aggregated number of vcore seconds
144   */
145  @Private
146  @Unstable
147  public abstract void setVcoreSeconds(long vcore_seconds);
148
149  /**
150   * Get the aggregated number of vcores that the application has allocated
151   * times the number of seconds the application has been running.
152   * @return the aggregated number of vcore seconds
153   */
154  @Public
155  @Unstable
156  public abstract long getVcoreSeconds();
157
158  /**
159   * Get the percentage of resources of the queue that the app is using.
160   * @return the percentage of resources of the queue that the app is using.
161   */
162  @Public
163  @Stable
164  public abstract float getQueueUsagePercentage();
165
166  /**
167   * Set the percentage of resources of the queue that the app is using.
168   * @param queueUsagePerc the percentage of resources of the queue that
169   *                       the app is using.
170   */
171  @Private
172  @Unstable
173  public abstract void setQueueUsagePercentage(float queueUsagePerc);
174
175  /**
176   * Get the percentage of resources of the cluster that the app is using.
177   * @return the percentage of resources of the cluster that the app is using.
178   */
179  @Public
180  @Stable
181  public abstract float getClusterUsagePercentage();
182
183  /**
184   * Set the percentage of resources of the cluster that the app is using.
185   * @param clusterUsagePerc the percentage of resources of the cluster that
186   *                         the app is using.
187   */
188  @Private
189  @Unstable
190  public abstract void setClusterUsagePercentage(float clusterUsagePerc);
191}