YARN-10944. AbstractCSQueue: Eliminate code duplication in overloaded versions of setMaxCapacity. Contributed by Andras Gyori

This commit is contained in:
Szilard Nemeth 2022-02-22 11:55:34 +01:00
parent 1f157f802d
commit 0463498adc

View File

@ -74,6 +74,7 @@
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL;
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
public abstract class AbstractCSQueue implements CSQueue {
@ -279,33 +280,23 @@ public boolean hasAccess(QueueACL acl, UserGroupInformation user) {
}
/**
* Set maximum capacity - used only for testing.
* Set maximum capacity for empty node label.
* @param maximumCapacity new max capacity
*/
@VisibleForTesting
void setMaxCapacity(float maximumCapacity) {
writeLock.lock();
try {
// Sanity check
CSQueueUtils.checkMaxCapacity(this.queuePath,
queueCapacities.getCapacity(), maximumCapacity);
float absMaxCapacity = CSQueueUtils.computeAbsoluteMaximumCapacity(
maximumCapacity, parent);
CSQueueUtils.checkAbsoluteCapacity(this.queuePath,
queueCapacities.getAbsoluteCapacity(), absMaxCapacity);
queueCapacities.setMaximumCapacity(maximumCapacity);
queueCapacities.setAbsoluteMaximumCapacity(absMaxCapacity);
} finally {
writeLock.unlock();
}
internalSetMaximumCapacity(maximumCapacity, NO_LABEL);
}
/**
* Set maximum capacity
* Set maximum capacity.
* @param maximumCapacity new max capacity
*/
void setMaxCapacity(String nodeLabel, float maximumCapacity) {
internalSetMaximumCapacity(maximumCapacity, nodeLabel);
}
private void internalSetMaximumCapacity(float maximumCapacity, String nodeLabel) {
writeLock.lock();
try {
// Sanity check
@ -323,7 +314,6 @@ void setMaxCapacity(String nodeLabel, float maximumCapacity) {
}
}
@Override
public String getDefaultNodeLabelExpression() {
return this.queueNodeLabelsSettings.getDefaultLabelExpression();
@ -917,7 +907,7 @@ boolean canAssignToThisQueue(Resource clusterResource,
}
private static String ensurePartition(String partition) {
return Optional.ofNullable(partition).orElse(RMNodeLabelsManager.NO_LABEL);
return Optional.ofNullable(partition).orElse(NO_LABEL);
}
@FunctionalInterface
@ -1016,8 +1006,8 @@ public Set<String> getNodeLabelsForQueue() {
// Add NO_LABEL also to this list as NO_LABEL also can be granted with
// resource in many general cases.
if (!nodeLabels.contains(RMNodeLabelsManager.NO_LABEL)) {
nodeLabels.add(RMNodeLabelsManager.NO_LABEL);
if (!nodeLabels.contains(NO_LABEL)) {
nodeLabels.add(NO_LABEL);
}
return nodeLabels;
}