diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java index 3a519ecf5f1..43e2b2d14ce 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java @@ -27,12 +27,9 @@ import org.apache.hadoop.security.authorize.AccessControlList; import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.StringUtils; -import org.apache.hadoop.yarn.api.records.Priority; -import org.apache.hadoop.yarn.api.records.QueueACL; -import org.apache.hadoop.yarn.api.records.QueueState; -import org.apache.hadoop.yarn.api.records.ReservationACL; -import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.*; import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; import org.apache.hadoop.yarn.security.AccessType; @@ -133,11 +130,14 @@ public static final boolean DEFAULT_RESERVE_CONT_LOOK_ALL_NODES = true; @Private - public static final String MAXIMUM_ALLOCATION_MB = "maximum-allocation-mb"; + public static final String MAXIMUM_ALLOCATION="maximum-allocation"; + + @Private + public static final String MAXIMUM_ALLOCATION_MB = MAXIMUM_ALLOCATION+"-mb"; @Private public static final String MAXIMUM_ALLOCATION_VCORES = - "maximum-allocation-vcores"; + MAXIMUM_ALLOCATION+"-vcores"; /** * Ordering policy of queues @@ -806,34 +806,43 @@ public void setQueuePriority(String queue, int priority) { */ public Resource getMaximumAllocationPerQueue(String queue) { String queuePrefix = getQueuePrefix(queue); - long maxAllocationMbPerQueue = getInt(queuePrefix + MAXIMUM_ALLOCATION_MB, - (int)UNDEFINED); - int maxAllocationVcoresPerQueue = getInt( - queuePrefix + MAXIMUM_ALLOCATION_VCORES, (int)UNDEFINED); - if (LOG.isDebugEnabled()) { - LOG.debug("max alloc mb per queue for " + queue + " is " - + maxAllocationMbPerQueue); - LOG.debug("max alloc vcores per queue for " + queue + " is " - + maxAllocationVcoresPerQueue); - } Resource clusterMax = getMaximumAllocation(); - if (maxAllocationMbPerQueue == (int)UNDEFINED) { - LOG.info("max alloc mb per queue for " + queue + " is undefined"); - maxAllocationMbPerQueue = clusterMax.getMemorySize(); - } - if (maxAllocationVcoresPerQueue == (int)UNDEFINED) { - LOG.info("max alloc vcore per queue for " + queue + " is undefined"); - maxAllocationVcoresPerQueue = clusterMax.getVirtualCores(); + + Resource result = Resources.clone(clusterMax); + boolean queMaxLargerThanClusterMax = false; + for (ResourceInformation resourceIter : clusterMax.getResources()) { + String resourceName = resourceIter.getName(); + String resourceMaxString = MAXIMUM_ALLOCATION + "-" + resourceName; + + //to ensure backward compatibility + if (resourceName + .equalsIgnoreCase(ResourceInformation.MEMORY_MB.getName())) { + resourceMaxString = MAXIMUM_ALLOCATION_MB; + } + long tempMaxAllocationResourcePerQueue = + getInt(queuePrefix + resourceMaxString, (int) UNDEFINED); + + if (LOG.isDebugEnabled()) { + LOG.debug( + "max alloc " + resourceName + " per queue for " + queue + " is " + + tempMaxAllocationResourcePerQueue); + } + if (tempMaxAllocationResourcePerQueue != (int) UNDEFINED) { + result.getResourceInformation(resourceName) + .setValue(tempMaxAllocationResourcePerQueue); + } else { + LOG.info("max alloc " + resourceIter + " per queue for " + queue + + " is undefined"); + } + if (tempMaxAllocationResourcePerQueue > clusterMax + .getResourceInformation(resourceName).getValue()) + queMaxLargerThanClusterMax = true; } - Resource result = Resources.createResource(maxAllocationMbPerQueue, - maxAllocationVcoresPerQueue); - if (maxAllocationMbPerQueue > clusterMax.getMemorySize() - || maxAllocationVcoresPerQueue > clusterMax.getVirtualCores()) { + if (queMaxLargerThanClusterMax) { throw new IllegalArgumentException( "Queue maximum allocation cannot be larger than the cluster setting" - + " for queue " + queue - + " max allocation per queue: " + result - + " cluster setting: " + clusterMax); + + " for queue " + queue + " max allocation per queue: " + result + + " cluster setting: " + clusterMax); } return result; }