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 long preemptedMemorySeconds, long preemptedVcoresSeconds) { 041 ApplicationResourceUsageReport report = 042 Records.newRecord(ApplicationResourceUsageReport.class); 043 report.setNumUsedContainers(numUsedContainers); 044 report.setNumReservedContainers(numReservedContainers); 045 report.setUsedResources(usedResources); 046 report.setReservedResources(reservedResources); 047 report.setNeededResources(neededResources); 048 report.setMemorySeconds(memorySeconds); 049 report.setVcoreSeconds(vcoreSeconds); 050 report.setQueueUsagePercentage(queueUsagePerc); 051 report.setClusterUsagePercentage(clusterUsagePerc); 052 report.setPreemptedMemorySeconds(preemptedMemorySeconds); 053 report.setPreemptedVcoreSeconds(preemptedVcoresSeconds); 054 return report; 055 } 056 057 /** 058 * Get the number of used containers. -1 for invalid/inaccessible reports. 059 * @return the number of used containers 060 */ 061 @Public 062 @Stable 063 public abstract int getNumUsedContainers(); 064 065 /** 066 * Set the number of used containers 067 * @param num_containers the number of used containers 068 */ 069 @Private 070 @Unstable 071 public abstract void setNumUsedContainers(int num_containers); 072 073 /** 074 * Get the number of reserved containers. -1 for invalid/inaccessible reports. 075 * @return the number of reserved containers 076 */ 077 @Private 078 @Unstable 079 public abstract int getNumReservedContainers(); 080 081 /** 082 * Set the number of reserved containers 083 * @param num_reserved_containers the number of reserved containers 084 */ 085 @Private 086 @Unstable 087 public abstract void setNumReservedContainers(int num_reserved_containers); 088 089 /** 090 * Get the used <code>Resource</code>. -1 for invalid/inaccessible reports. 091 * @return the used <code>Resource</code> 092 */ 093 @Public 094 @Stable 095 public abstract Resource getUsedResources(); 096 097 @Private 098 @Unstable 099 public abstract void setUsedResources(Resource resources); 100 101 /** 102 * Get the reserved <code>Resource</code>. -1 for invalid/inaccessible reports. 103 * @return the reserved <code>Resource</code> 104 */ 105 @Public 106 @Stable 107 public abstract Resource getReservedResources(); 108 109 @Private 110 @Unstable 111 public abstract void setReservedResources(Resource reserved_resources); 112 113 /** 114 * Get the needed <code>Resource</code>. -1 for invalid/inaccessible reports. 115 * @return the needed <code>Resource</code> 116 */ 117 @Public 118 @Stable 119 public abstract Resource getNeededResources(); 120 121 @Private 122 @Unstable 123 public abstract void setNeededResources(Resource needed_resources); 124 125 /** 126 * Set the aggregated amount of memory (in megabytes) the application has 127 * allocated times the number of seconds the application has been running. 128 * @param memory_seconds the aggregated amount of memory seconds 129 */ 130 @Private 131 @Unstable 132 public abstract void setMemorySeconds(long memory_seconds); 133 134 /** 135 * Get the aggregated amount of memory (in megabytes) the application has 136 * allocated times the number of seconds the application has been running. 137 * @return the aggregated amount of memory seconds 138 */ 139 @Public 140 @Unstable 141 public abstract long getMemorySeconds(); 142 143 /** 144 * Set the aggregated number of vcores that the application has allocated 145 * times the number of seconds the application has been running. 146 * @param vcore_seconds the aggregated number of vcore seconds 147 */ 148 @Private 149 @Unstable 150 public abstract void setVcoreSeconds(long vcore_seconds); 151 152 /** 153 * Get the aggregated number of vcores that the application has allocated 154 * times the number of seconds the application has been running. 155 * @return the aggregated number of vcore seconds 156 */ 157 @Public 158 @Unstable 159 public abstract long getVcoreSeconds(); 160 161 /** 162 * Get the percentage of resources of the queue that the app is using. 163 * @return the percentage of resources of the queue that the app is using. 164 */ 165 @Public 166 @Stable 167 public abstract float getQueueUsagePercentage(); 168 169 /** 170 * Set the percentage of resources of the queue that the app is using. 171 * @param queueUsagePerc the percentage of resources of the queue that 172 * the app is using. 173 */ 174 @Private 175 @Unstable 176 public abstract void setQueueUsagePercentage(float queueUsagePerc); 177 178 /** 179 * Get the percentage of resources of the cluster that the app is using. 180 * @return the percentage of resources of the cluster that the app is using. 181 */ 182 @Public 183 @Stable 184 public abstract float getClusterUsagePercentage(); 185 186 /** 187 * Set the percentage of resources of the cluster that the app is using. 188 * @param clusterUsagePerc the percentage of resources of the cluster that 189 * the app is using. 190 */ 191 @Private 192 @Unstable 193 public abstract void setClusterUsagePercentage(float clusterUsagePerc); 194 195 /** 196 * Set the aggregated amount of memory preempted (in megabytes) 197 * the application has allocated times the number of seconds 198 * the application has been running. 199 * @param memorySeconds the aggregated amount of memory seconds 200 */ 201 @Private 202 @Unstable 203 public abstract void setPreemptedMemorySeconds(long memorySeconds); 204 205 /** 206 * Get the aggregated amount of memory preempted(in megabytes) 207 * the application has allocated times the number of 208 * seconds the application has been running. 209 * @return the aggregated amount of memory seconds 210 */ 211 @Public 212 @Unstable 213 public abstract long getPreemptedMemorySeconds(); 214 215 /** 216 * Set the aggregated number of vcores preempted that the application has 217 * allocated times the number of seconds the application has been running. 218 * @param vcoreSeconds the aggregated number of vcore seconds 219 */ 220 @Private 221 @Unstable 222 public abstract void setPreemptedVcoreSeconds(long vcoreSeconds); 223 224 /** 225 * Get the aggregated number of vcores preempted that the application has 226 * allocated times the number of seconds the application has been running. 227 * @return the aggregated number of vcore seconds 228 */ 229 @Public 230 @Unstable 231 public abstract long getPreemptedVcoreSeconds(); 232}