YARN-10907. Minimize usages of AbstractCSQueue#csContext. Contributed by Benjamin Teke

This commit is contained in:
Szilard Nemeth 2021-12-13 21:57:46 +01:00
parent 898055e204
commit a5bcf4c792
38 changed files with 1010 additions and 736 deletions

View File

@ -95,7 +95,7 @@ protected void addReservationQueue(
PlanQueue planQueue = (PlanQueue)queue; PlanQueue planQueue = (PlanQueue)queue;
try { try {
ReservationQueue resQueue = ReservationQueue resQueue =
new ReservationQueue(cs, currResId, planQueue); new ReservationQueue(cs.getQueueContext(), currResId, planQueue);
cs.addQueue(resQueue); cs.addQueue(resQueue);
} catch (SchedulerDynamicEditException e) { } catch (SchedulerDynamicEditException e) {
LOG.warn( LOG.warn(
@ -115,7 +115,7 @@ protected void createDefaultReservationQueue(
if (cs.getQueue(defReservationId) == null) { if (cs.getQueue(defReservationId) == null) {
try { try {
ReservationQueue defQueue = ReservationQueue defQueue =
new ReservationQueue(cs, defReservationId, planQueue); new ReservationQueue(cs.getQueueContext(), defReservationId, planQueue);
cs.addQueue(defQueue); cs.addQueue(defQueue);
} catch (SchedulerDynamicEditException e) { } catch (SchedulerDynamicEditException e) {
LOG.warn( LOG.warn(

View File

@ -35,23 +35,15 @@
* of AbstractManagedParentQueue * of AbstractManagedParentQueue
*/ */
public class AbstractAutoCreatedLeafQueue extends AbstractLeafQueue { public class AbstractAutoCreatedLeafQueue extends AbstractLeafQueue {
protected AbstractManagedParentQueue parent;
public AbstractAutoCreatedLeafQueue(CapacitySchedulerContext cs,
String queueName, AbstractManagedParentQueue parent, CSQueue old)
throws IOException {
super(cs, queueName, parent, old);
this.parent = parent;
}
private static final Logger LOG = LoggerFactory.getLogger( private static final Logger LOG = LoggerFactory.getLogger(
AbstractAutoCreatedLeafQueue.class); AbstractAutoCreatedLeafQueue.class);
public AbstractAutoCreatedLeafQueue(CapacitySchedulerContext cs, protected AbstractManagedParentQueue parent;
CapacitySchedulerConfiguration leafQueueConfigs, String queueName,
AbstractManagedParentQueue parent, CSQueue old) throws IOException { public AbstractAutoCreatedLeafQueue(CapacitySchedulerQueueContext queueContext,
super(cs, leafQueueConfigs, queueName, parent, old); String queueName, AbstractManagedParentQueue parent, CSQueue old)
throws IOException {
super(queueContext, queueName, parent, old);
this.parent = parent; this.parent = parent;
} }
@ -71,7 +63,7 @@ public void setEntitlement(QueueEntitlement entitlement)
@Override @Override
protected Resource getMinimumAbsoluteResource(String queuePath, protected Resource getMinimumAbsoluteResource(String queuePath,
String label) { String label) {
return super.getMinimumAbsoluteResource(csContext.getConfiguration() return super.getMinimumAbsoluteResource(queueContext.getConfiguration()
.getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()),
label); label);
} }
@ -79,7 +71,7 @@ protected Resource getMinimumAbsoluteResource(String queuePath,
@Override @Override
protected Resource getMaximumAbsoluteResource(String queuePath, protected Resource getMaximumAbsoluteResource(String queuePath,
String label) { String label) {
return super.getMaximumAbsoluteResource(csContext.getConfiguration() return super.getMaximumAbsoluteResource(queueContext.getConfiguration()
.getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()),
label); label);
} }
@ -87,7 +79,7 @@ protected Resource getMaximumAbsoluteResource(String queuePath,
@Override @Override
protected boolean checkConfigTypeIsAbsoluteResource(String queuePath, protected boolean checkConfigTypeIsAbsoluteResource(String queuePath,
String label) { String label) {
return super.checkConfigTypeIsAbsoluteResource(csContext.getConfiguration() return super.checkConfigTypeIsAbsoluteResource(queueContext.getConfiguration()
.getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(this.getParent().getQueuePath()),
label); label);
} }
@ -122,7 +114,7 @@ public void setEntitlement(String nodeLabel, QueueEntitlement entitlement)
//update queue used capacity etc //update queue used capacity etc
CSQueueUtils.updateQueueStatistics(resourceCalculator, CSQueueUtils.updateQueueStatistics(resourceCalculator,
csContext.getClusterResource(), queueContext.getClusterResource(),
this, labelManager, nodeLabel); this, labelManager, nodeLabel);
} finally { } finally {
writeLock.unlock(); writeLock.unlock();

View File

@ -117,7 +117,7 @@ public enum CapacityConfigType {
private final RecordFactory recordFactory = private final RecordFactory recordFactory =
RecordFactoryProvider.getRecordFactory(null); RecordFactoryProvider.getRecordFactory(null);
protected CapacitySchedulerContext csContext; protected CapacitySchedulerQueueContext queueContext;
protected YarnAuthorizationProvider authorizer = null; protected YarnAuthorizationProvider authorizer = null;
protected ActivitiesManager activitiesManager; protected ActivitiesManager activitiesManager;
@ -131,33 +131,39 @@ public enum CapacityConfigType {
// is it a dynamic queue? // is it a dynamic queue?
private boolean dynamicQueue = false; private boolean dynamicQueue = false;
public AbstractCSQueue(CapacitySchedulerContext cs, public AbstractCSQueue(CapacitySchedulerQueueContext queueContext, String queueName,
String queueName, CSQueue parent, CSQueue old) throws IOException {
this(cs, cs.getConfiguration(), queueName, parent, old);
}
public AbstractCSQueue(CapacitySchedulerContext cs,
CapacitySchedulerConfiguration configuration, String queueName,
CSQueue parent, CSQueue old) { CSQueue parent, CSQueue old) {
this.labelManager = cs.getRMContext().getNodeLabelManager();
this.parent = parent; this.parent = parent;
this.queuePath = createQueuePath(parent, queueName); this.queuePath = createQueuePath(parent, queueName);
this.resourceCalculator = cs.getResourceCalculator();
this.activitiesManager = cs.getActivitiesManager(); this.queueContext = queueContext;
this.resourceCalculator = queueContext.getResourceCalculator();
this.activitiesManager = queueContext.getActivitiesManager();
this.labelManager = queueContext.getLabelManager();
// must be called after parent and queueName is set // must be called after parent and queueName is set
CSQueueMetrics metrics = old != null ? CSQueueMetrics metrics = old != null ?
(CSQueueMetrics) old.getMetrics() : (CSQueueMetrics) old.getMetrics() :
CSQueueMetrics.forQueue(getQueuePath(), parent, CSQueueMetrics.forQueue(getQueuePath(), parent,
cs.getConfiguration().getEnableUserMetrics(), configuration); queueContext.getConfiguration().getEnableUserMetrics(), queueContext.getConfiguration());
usageTracker = new CSQueueUsageTracker(metrics); this.usageTracker = new CSQueueUsageTracker(metrics);
this.csContext = cs;
this.queueAllocationSettings = new QueueAllocationSettings(csContext); this.queueCapacities = new QueueCapacities(parent == null);
queueEntity = new PrivilegedEntity(EntityType.QUEUE, getQueuePath()); this.queueAllocationSettings = new QueueAllocationSettings(queueContext.getMinimumAllocation());
queueCapacities = new QueueCapacities(parent == null);
this.queueEntity = new PrivilegedEntity(EntityType.QUEUE, getQueuePath());
this.resourceTypes = new HashSet<>();
for (AbsoluteResourceType type : AbsoluteResourceType.values()) {
this.resourceTypes.add(type.toString().toLowerCase());
}
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
readLock = lock.readLock(); this.readLock = lock.readLock();
writeLock = lock.writeLock(); this.writeLock = lock.writeLock();
LOG.debug("Initialized {}: name={}, fullname={}", this.getClass().getSimpleName(),
queueName, getQueuePath());
} }
private static QueuePath createQueuePath(CSQueue parent, String queueName) { private static QueuePath createQueuePath(CSQueue parent, String queueName) {
@ -167,11 +173,6 @@ private static QueuePath createQueuePath(CSQueue parent, String queueName) {
return new QueuePath(parent.getQueuePath(), queueName); return new QueuePath(parent.getQueuePath(), queueName);
} }
@VisibleForTesting
protected void setupConfigurableCapacities() {
setupConfigurableCapacities(csContext.getConfiguration());
}
protected void setupConfigurableCapacities( protected void setupConfigurableCapacities(
CapacitySchedulerConfiguration configuration) { CapacitySchedulerConfiguration configuration) {
CSQueueUtils.loadCapacitiesByLabelsFromConf(queuePath, queueCapacities, CSQueueUtils.loadCapacitiesByLabelsFromConf(queuePath, queueCapacities,
@ -262,6 +263,10 @@ public PrivilegedEntity getPrivilegedEntity() {
return queueEntity; return queueEntity;
} }
public CapacitySchedulerQueueContext getQueueContext() {
return queueContext;
}
public Set<String> getAccessibleNodeLabels() { public Set<String> getAccessibleNodeLabels() {
return queueNodeLabelsSettings.getAccessibleNodeLabels(); return queueNodeLabelsSettings.getAccessibleNodeLabels();
} }
@ -336,26 +341,24 @@ protected void setupQueueConfigs(Resource clusterResource,
// Collect and set the Node label configuration // Collect and set the Node label configuration
this.queueNodeLabelsSettings = new QueueNodeLabelsSettings(configuration, parent, this.queueNodeLabelsSettings = new QueueNodeLabelsSettings(configuration, parent,
getQueuePath(), csContext); getQueuePath(), queueContext.getQueueManager().getConfiguredNodeLabelsForAllQueues());
// Initialize the queue capacities // Initialize the queue capacities
setupConfigurableCapacities(configuration); setupConfigurableCapacities(configuration);
updateAbsoluteCapacities(); updateAbsoluteCapacities();
updateCapacityConfigType(); updateCapacityConfigType();
// Fetch minimum/maximum resource limits for this queue if // Fetch minimum/maximum resource limits for this queue if
// configured // configured
this.resourceTypes = new HashSet<>();
for (AbsoluteResourceType type : AbsoluteResourceType.values()) {
resourceTypes.add(type.toString().toLowerCase());
}
updateConfigurableResourceLimits(clusterResource); updateConfigurableResourceLimits(clusterResource);
// Setup queue's maximumAllocation respecting the global // Setup queue's maximumAllocation respecting the global
// and the queue settings // and the queue settings
this.queueAllocationSettings.setupMaximumAllocation(configuration, getQueuePath(), // TODO remove the getConfiguration() param after the AQC configuration duplication
parent, csContext); // removal is resolved
this.queueAllocationSettings.setupMaximumAllocation(configuration,
queueContext.getConfiguration(), getQueuePath(),
parent);
// Initialize the queue state based on previous state, configured state // Initialize the queue state based on previous state, configured state
// and its parent state // and its parent state
@ -369,7 +372,8 @@ protected void setupQueueConfigs(Resource clusterResource,
this.reservationsContinueLooking = this.reservationsContinueLooking =
configuration.getReservationContinueLook(); configuration.getReservationContinueLook();
this.configuredCapacityVectors = csContext.getConfiguration()
this.configuredCapacityVectors = queueContext.getConfiguration()
.parseConfiguredResourceVector(queuePath.getFullPath(), .parseConfiguredResourceVector(queuePath.getFullPath(),
this.queueNodeLabelsSettings.getConfiguredNodeLabels()); this.queueNodeLabelsSettings.getConfiguredNodeLabels());
@ -378,7 +382,10 @@ protected void setupQueueConfigs(Resource clusterResource,
this, labelManager, null); this, labelManager, null);
// Store preemption settings // Store preemption settings
this.preemptionSettings = new CSQueuePreemptionSettings(this, csContext, configuration); // TODO remove the getConfiguration() param after the AQC configuration duplication
// removal is resolved
this.preemptionSettings = new CSQueuePreemptionSettings(this, configuration,
queueContext.getConfiguration());
this.priority = configuration.getQueuePriority( this.priority = configuration.getQueuePriority(
getQueuePath()); getQueuePath());
@ -409,12 +416,13 @@ protected void setDynamicQueueProperties(
AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX); AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX);
parentTemplate = parentTemplate.substring(0, parentTemplate.lastIndexOf( parentTemplate = parentTemplate.substring(0, parentTemplate.lastIndexOf(
DOT)); DOT));
Set<String> parentNodeLabels = csContext Set<String> parentNodeLabels = queueContext.getQueueManager()
.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() .getConfiguredNodeLabelsForAllQueues()
.getLabelsByQueue(parentTemplate); .getLabelsByQueue(parentTemplate);
if (parentNodeLabels != null && parentNodeLabels.size() > 1) { if (parentNodeLabels != null && parentNodeLabels.size() > 1) {
csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() queueContext.getQueueManager()
.getConfiguredNodeLabelsForAllQueues()
.setLabelsByQueue(getQueuePath(), new HashSet<>(parentNodeLabels)); .setLabelsByQueue(getQueuePath(), new HashSet<>(parentNodeLabels));
} }
} }
@ -436,20 +444,18 @@ private UserWeights getUserWeightsFromHierarchy(
} }
protected Resource getMinimumAbsoluteResource(String queuePath, String label) { protected Resource getMinimumAbsoluteResource(String queuePath, String label) {
Resource minResource = csContext.getConfiguration() return queueContext.getConfiguration()
.getMinimumResourceRequirement(label, queuePath, resourceTypes); .getMinimumResourceRequirement(label, queuePath, resourceTypes);
return minResource;
} }
protected Resource getMaximumAbsoluteResource(String queuePath, String label) { protected Resource getMaximumAbsoluteResource(String queuePath, String label) {
Resource maxResource = csContext.getConfiguration() return queueContext.getConfiguration()
.getMaximumResourceRequirement(label, queuePath, resourceTypes); .getMaximumResourceRequirement(label, queuePath, resourceTypes);
return maxResource;
} }
protected boolean checkConfigTypeIsAbsoluteResource(String queuePath, protected boolean checkConfigTypeIsAbsoluteResource(String queuePath,
String label) { String label) {
return csContext.getConfiguration().checkConfigTypeIsAbsoluteResource(label, return queueContext.getConfiguration().checkConfigTypeIsAbsoluteResource(label,
queuePath, resourceTypes); queuePath, resourceTypes);
} }
@ -743,7 +749,7 @@ protected void releaseResource(Resource clusterResource,
} }
@Private @Private
public boolean getReservationContinueLooking() { public boolean isReservationsContinueLooking() {
return reservationsContinueLooking; return reservationsContinueLooking;
} }
@ -764,7 +770,7 @@ public boolean getPreemptionDisabled() {
@Private @Private
public boolean getIntraQueuePreemptionDisabled() { public boolean getIntraQueuePreemptionDisabled() {
return preemptionSettings.getIntraQueuePreemptionDisabled(); return preemptionSettings.isIntraQueuePreemptionDisabled();
} }
@Private @Private
@ -1026,12 +1032,12 @@ public Set<String> getNodeLabelsForQueue() {
} }
public Resource getTotalKillableResource(String partition) { public Resource getTotalKillableResource(String partition) {
return csContext.getPreemptionManager().getKillableResource(getQueuePath(), return queueContext.getPreemptionManager().getKillableResource(getQueuePath(),
partition); partition);
} }
public Iterator<RMContainer> getKillableContainers(String partition) { public Iterator<RMContainer> getKillableContainers(String partition) {
return csContext.getPreemptionManager().getKillableContainers( return queueContext.getPreemptionManager().getKillableContainers(
getQueuePath(), getQueuePath(),
partition); partition);
} }
@ -1383,7 +1389,7 @@ public boolean isInactiveDynamicQueue() {
long idleDurationSeconds = long idleDurationSeconds =
(Time.monotonicNow() - getLastSubmittedTimestamp())/1000; (Time.monotonicNow() - getLastSubmittedTimestamp())/1000;
return isDynamicQueue() && isEligibleForAutoDeletion() && return isDynamicQueue() && isEligibleForAutoDeletion() &&
(idleDurationSeconds > this.csContext.getConfiguration(). (idleDurationSeconds > queueContext.getConfiguration().
getAutoExpiredDeletionTime()); getAutoExpiredDeletionTime());
} }

View File

@ -44,9 +44,9 @@ public abstract class AbstractManagedParentQueue extends ParentQueue {
protected AutoCreatedLeafQueueConfig leafQueueTemplate; protected AutoCreatedLeafQueueConfig leafQueueTemplate;
protected AutoCreatedQueueManagementPolicy queueManagementPolicy = null; protected AutoCreatedQueueManagementPolicy queueManagementPolicy = null;
public AbstractManagedParentQueue(CapacitySchedulerContext cs, public AbstractManagedParentQueue(CapacitySchedulerQueueContext queueContext,
String queueName, CSQueue parent, CSQueue old) throws IOException { String queueName, CSQueue parent, CSQueue old) throws IOException {
super(cs, queueName, parent, old); super(queueContext, queueName, parent, old);
} }
@Override @Override
@ -55,7 +55,7 @@ public void reinitialize(CSQueue newlyParsedQueue, Resource clusterResource)
writeLock.lock(); writeLock.lock();
try { try {
// Set new configs // Set new configs
setupQueueConfigs(clusterResource, csContext.getConfiguration()); setupQueueConfigs(clusterResource, queueContext.getConfiguration());
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
@ -121,8 +121,7 @@ public CSQueue removeChildQueue(String childQueueName)
CSQueue childQueue; CSQueue childQueue;
writeLock.lock(); writeLock.lock();
try { try {
childQueue = this.csContext.getCapacitySchedulerQueueManager().getQueue( childQueue = queueContext.getQueueManager().getQueue(childQueueName);
childQueueName);
if (childQueue != null) { if (childQueue != null) {
removeChildQueue(childQueue); removeChildQueue(childQueue);
} else { } else {
@ -176,14 +175,14 @@ protected CapacitySchedulerConfiguration initializeLeafQueueConfigs(String
CapacitySchedulerConfiguration leafQueueConfigs = new CapacitySchedulerConfiguration leafQueueConfigs = new
CapacitySchedulerConfiguration(new Configuration(false), false); CapacitySchedulerConfiguration(new Configuration(false), false);
Map<String, String> rtProps = csContext Map<String, String> rtProps = queueContext
.getConfiguration().getConfigurationProperties() .getConfiguration().getConfigurationProperties()
.getPropertiesWithPrefix(YarnConfiguration.RESOURCE_TYPES + ".", true); .getPropertiesWithPrefix(YarnConfiguration.RESOURCE_TYPES + ".", true);
for (Map.Entry<String, String> entry : rtProps.entrySet()) { for (Map.Entry<String, String> entry : rtProps.entrySet()) {
leafQueueConfigs.set(entry.getKey(), entry.getValue()); leafQueueConfigs.set(entry.getKey(), entry.getValue());
} }
Map<String, String> templateConfigs = csContext Map<String, String> templateConfigs = queueContext
.getConfiguration().getConfigurationProperties() .getConfiguration().getConfigurationProperties()
.getPropertiesWithPrefix(configPrefix, true); .getPropertiesWithPrefix(configPrefix, true);

View File

@ -39,16 +39,11 @@ public class AutoCreatedLeafQueue extends AbstractAutoCreatedLeafQueue {
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory
.getLogger(AutoCreatedLeafQueue.class); .getLogger(AutoCreatedLeafQueue.class);
public AutoCreatedLeafQueue(CapacitySchedulerContext cs, String queueName, public AutoCreatedLeafQueue(CapacitySchedulerQueueContext queueContext, String queueName,
ManagedParentQueue parent) throws IOException { ManagedParentQueue parent) throws IOException {
// TODO once YARN-10907 is merged the duplicated collection of super(queueContext, queueName, parent, null);
// leafQueueConfigs won't be necessary super.setupQueueConfigs(queueContext.getClusterResource(), parent.getLeafQueueConfigs(queueName));
super(cs, parent.getLeafQueueConfigs(queueName),
queueName,
parent, null);
super.setupQueueConfigs(cs.getClusterResource(), parent.getLeafQueueConfigs(queueName));
LOG.debug("Initialized AutoCreatedLeafQueue: name={}, fullname={}", queueName, getQueuePath());
updateCapacitiesToZero(); updateCapacitiesToZero();
} }
@ -74,8 +69,7 @@ public void reinitialize(CSQueue newlyParsedQueue, Resource clusterResource)
} }
} }
public void reinitializeFromTemplate(AutoCreatedLeafQueueConfig public void reinitializeFromTemplate(AutoCreatedLeafQueueConfig leafQueueTemplate) {
leafQueueTemplate) throws SchedulerDynamicEditException, IOException {
writeLock.lock(); writeLock.lock();
try { try {
@ -105,7 +99,7 @@ public void mergeCapacities(QueueCapacities capacities) {
.getAbsoluteMaximumCapacity(nodeLabel)); .getAbsoluteMaximumCapacity(nodeLabel));
Resource resourceByLabel = labelManager.getResourceByLabel(nodeLabel, Resource resourceByLabel = labelManager.getResourceByLabel(nodeLabel,
csContext.getClusterResource()); queueContext.getClusterResource());
getQueueResourceQuotas().setEffectiveMinResource(nodeLabel, getQueueResourceQuotas().setEffectiveMinResource(nodeLabel,
Resources.multiply(resourceByLabel, Resources.multiply(resourceByLabel,
queueCapacities.getAbsoluteCapacity(nodeLabel))); queueCapacities.getAbsoluteCapacity(nodeLabel)));
@ -133,12 +127,12 @@ protected void setDynamicQueueProperties(
String parentTemplate = String.format("%s.%s", getParent().getQueuePath(), String parentTemplate = String.format("%s.%s", getParent().getQueuePath(),
CapacitySchedulerConfiguration CapacitySchedulerConfiguration
.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX); .AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX);
Set<String> parentNodeLabels = csContext Set<String> parentNodeLabels = queueContext
.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() .getQueueManager().getConfiguredNodeLabelsForAllQueues()
.getLabelsByQueue(parentTemplate); .getLabelsByQueue(parentTemplate);
if (parentNodeLabels != null && parentNodeLabels.size() > 1) { if (parentNodeLabels != null && parentNodeLabels.size() > 1) {
csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() queueContext.getQueueManager().getConfiguredNodeLabelsForAllQueues()
.setLabelsByQueue(getQueuePath(), .setLabelsByQueue(getQueuePath(),
new HashSet<>(parentNodeLabels)); new HashSet<>(parentNodeLabels));
} }

View File

@ -27,17 +27,15 @@ public interface AutoCreatedQueueManagementPolicy {
/** /**
* Initialize policy * Initialize policy
* @param schedulerContext Capacity Scheduler context * @param parentQueue parent queue
*/ */
void init(CapacitySchedulerContext schedulerContext, ParentQueue void init(ParentQueue parentQueue) throws IOException;
parentQueue) throws IOException;
/** /**
* Reinitialize policy state ( if required ) * Reinitialize policy state ( if required )
* @param schedulerContext Capacity Scheduler context * @param parentQueue parent queue
*/ */
void reinitialize(CapacitySchedulerContext schedulerContext, void reinitialize(ParentQueue parentQueue) throws IOException;
ParentQueue parentQueue) throws IOException;
/** /**
* Get initial template for the specified leaf queue * Get initial template for the specified leaf queue

View File

@ -26,11 +26,13 @@ public class CSQueuePreemptionSettings {
public CSQueuePreemptionSettings( public CSQueuePreemptionSettings(
CSQueue queue, CSQueue queue,
CapacitySchedulerContext csContext, CapacitySchedulerConfiguration configuration,
CapacitySchedulerConfiguration configuration) { CapacitySchedulerConfiguration originalSchedulerConfiguration) {
this.preemptionDisabled = isQueueHierarchyPreemptionDisabled(queue, csContext, configuration); this.preemptionDisabled = isQueueHierarchyPreemptionDisabled(queue, configuration,
originalSchedulerConfiguration);
this.intraQueuePreemptionDisabledInHierarchy = this.intraQueuePreemptionDisabledInHierarchy =
isIntraQueueHierarchyPreemptionDisabled(queue, csContext, configuration); isIntraQueueHierarchyPreemptionDisabled(queue, configuration,
originalSchedulerConfiguration);
} }
/** /**
@ -40,14 +42,14 @@ public CSQueuePreemptionSettings(
* NOTE: Cross-queue preemptability is inherited from a queue's parent. * NOTE: Cross-queue preemptability is inherited from a queue's parent.
* *
* @param q queue to check preemption state * @param q queue to check preemption state
* @param csContext
* @param configuration capacity scheduler config * @param configuration capacity scheduler config
* @return true if queue has cross-queue preemption disabled, false otherwise * @return true if queue has cross-queue preemption disabled, false otherwise
*/ */
private boolean isQueueHierarchyPreemptionDisabled(CSQueue q, private boolean isQueueHierarchyPreemptionDisabled(CSQueue q,
CapacitySchedulerContext csContext, CapacitySchedulerConfiguration configuration) { CapacitySchedulerConfiguration configuration,
CapacitySchedulerConfiguration originalSchedulerConfiguration) {
boolean systemWidePreemption = boolean systemWidePreemption =
csContext.getConfiguration() originalSchedulerConfiguration
.getBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, .getBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS); YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS);
CSQueue parentQ = q.getParent(); CSQueue parentQ = q.getParent();
@ -79,14 +81,14 @@ private boolean isQueueHierarchyPreemptionDisabled(CSQueue q,
* NOTE: Intra-queue preemptability is inherited from a queue's parent. * NOTE: Intra-queue preemptability is inherited from a queue's parent.
* *
* @param q queue to check intra-queue preemption state * @param q queue to check intra-queue preemption state
* @param csContext
* @param configuration capacity scheduler config * @param configuration capacity scheduler config
* @return true if queue has intra-queue preemption disabled, false otherwise * @return true if queue has intra-queue preemption disabled, false otherwise
*/ */
private boolean isIntraQueueHierarchyPreemptionDisabled(CSQueue q, private boolean isIntraQueueHierarchyPreemptionDisabled(CSQueue q,
CapacitySchedulerContext csContext, CapacitySchedulerConfiguration configuration) { CapacitySchedulerConfiguration configuration,
CapacitySchedulerConfiguration originalSchedulerConfiguration) {
boolean systemWideIntraQueuePreemption = boolean systemWideIntraQueuePreemption =
csContext.getConfiguration().getBoolean( originalSchedulerConfiguration.getBoolean(
CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED, CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
CapacitySchedulerConfiguration CapacitySchedulerConfiguration
.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED); .DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED);
@ -109,7 +111,7 @@ private boolean isIntraQueueHierarchyPreemptionDisabled(CSQueue q,
parentQ.getIntraQueuePreemptionDisabledInHierarchy()); parentQ.getIntraQueuePreemptionDisabledInHierarchy());
} }
public boolean getIntraQueuePreemptionDisabled() { public boolean isIntraQueuePreemptionDisabled() {
return intraQueuePreemptionDisabledInHierarchy || preemptionDisabled; return intraQueuePreemptionDisabledInHierarchy || preemptionDisabled;
} }

View File

@ -183,6 +183,8 @@ public class CapacityScheduler extends
private CapacitySchedulerQueueManager queueManager; private CapacitySchedulerQueueManager queueManager;
private CapacitySchedulerQueueContext queueContext;
private WorkflowPriorityMappingsManager workflowPriorityMappingsMgr; private WorkflowPriorityMappingsManager workflowPriorityMappingsMgr;
// timeout to join when we stop this service // timeout to join when we stop this service
@ -267,6 +269,11 @@ public CapacitySchedulerConfiguration getConfiguration() {
return conf; return conf;
} }
@Override
public CapacitySchedulerQueueContext getQueueContext() {
return queueContext;
}
@Override @Override
public RMContainerTokenSecretManager getContainerTokenSecretManager() { public RMContainerTokenSecretManager getContainerTokenSecretManager() {
return this.rmContext.getContainerTokenSecretManager(); return this.rmContext.getContainerTokenSecretManager();
@ -319,6 +326,7 @@ void initScheduler(Configuration configuration) throws
this.workflowPriorityMappingsMgr = new WorkflowPriorityMappingsManager(); this.workflowPriorityMappingsMgr = new WorkflowPriorityMappingsManager();
this.activitiesManager = new ActivitiesManager(rmContext); this.activitiesManager = new ActivitiesManager(rmContext);
activitiesManager.init(conf); activitiesManager.init(conf);
this.queueContext = new CapacitySchedulerQueueContext(this);
initializeQueues(this.conf); initializeQueues(this.conf);
this.isLazyPreemptionEnabled = conf.getLazyPreemptionEnabled(); this.isLazyPreemptionEnabled = conf.getLazyPreemptionEnabled();
this.assignMultipleEnabled = this.conf.getAssignMultipleEnabled(); this.assignMultipleEnabled = this.conf.getAssignMultipleEnabled();
@ -844,6 +852,7 @@ private void initializeQueues(CapacitySchedulerConfiguration conf)
@Lock(CapacityScheduler.class) @Lock(CapacityScheduler.class)
private void reinitializeQueues(CapacitySchedulerConfiguration newConf) private void reinitializeQueues(CapacitySchedulerConfiguration newConf)
throws IOException { throws IOException {
queueContext.reinitialize();
this.queueManager.reinitializeQueues(newConf); this.queueManager.reinitializeQueues(newConf);
updatePlacementRules(); updatePlacementRules();

View File

@ -1658,6 +1658,12 @@ public Map<String, Set<String>> getConfiguredNodeLabelsByQueue() {
return labelsByQueue; return labelsByQueue;
} }
public Priority getClusterLevelApplicationMaxPriority() {
return Priority.newInstance(getInt(
YarnConfiguration.MAX_CLUSTER_LEVEL_APPLICATION_PRIORITY,
YarnConfiguration.DEFAULT_CLUSTER_LEVEL_APPLICATION_PRIORITY));
}
public Integer getDefaultApplicationPriorityConfPerQueue(String queue) { public Integer getDefaultApplicationPriorityConfPerQueue(String queue) {
Integer defaultPriority = getInt(getQueuePrefix(queue) Integer defaultPriority = getInt(getQueuePrefix(queue)
+ DEFAULT_APPLICATION_PRIORITY, + DEFAULT_APPLICATION_PRIORITY,

View File

@ -41,6 +41,8 @@
*/ */
public interface CapacitySchedulerContext { public interface CapacitySchedulerContext {
CapacitySchedulerConfiguration getConfiguration(); CapacitySchedulerConfiguration getConfiguration();
CapacitySchedulerQueueContext getQueueContext();
Resource getMinimumResourceCapability(); Resource getMinimumResourceCapability();

View File

@ -0,0 +1,132 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceUsage;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerHealth;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.activities.ActivitiesManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.preemption.PreemptionManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode;
import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
/**
* Class to store common queue related information, like instances
* to necessary manager classes or the global CapacityScheduler
* configuration.
*/
public class CapacitySchedulerQueueContext {
// Manager classes
private final CapacitySchedulerContext csContext;
private final CapacitySchedulerQueueManager queueManager;
private final RMNodeLabelsManager labelManager;
private final PreemptionManager preemptionManager;
private final ActivitiesManager activitiesManager;
private final ResourceCalculator resourceCalculator;
// CapacityScheduler configuration
private CapacitySchedulerConfiguration configuration;
private Resource minimumAllocation;
public CapacitySchedulerQueueContext(CapacitySchedulerContext csContext) {
this.csContext = csContext;
this.queueManager = csContext.getCapacitySchedulerQueueManager();
this.labelManager = csContext.getRMContext().getNodeLabelManager();
this.preemptionManager = csContext.getPreemptionManager();
this.activitiesManager = csContext.getActivitiesManager();
this.resourceCalculator = csContext.getResourceCalculator();
this.configuration = new CapacitySchedulerConfiguration(csContext.getConfiguration());
this.minimumAllocation = csContext.getMinimumResourceCapability();
}
public void reinitialize() {
// When csConfProvider.loadConfiguration is called, the useLocalConfigurationProvider is
// correctly set to load the config entries from the capacity-scheduler.xml.
// For this reason there is no need to reload from it again.
this.configuration = new CapacitySchedulerConfiguration(csContext.getConfiguration(), false);
this.minimumAllocation = csContext.getMinimumResourceCapability();
}
public CapacitySchedulerQueueManager getQueueManager() {
return queueManager;
}
public RMNodeLabelsManager getLabelManager() {
return labelManager;
}
public PreemptionManager getPreemptionManager() {
return preemptionManager;
}
public ActivitiesManager getActivitiesManager() {
return activitiesManager;
}
public ResourceCalculator getResourceCalculator() {
return resourceCalculator;
}
public CapacitySchedulerConfiguration getConfiguration() {
return configuration;
}
public Resource getMinimumAllocation() {
return minimumAllocation;
}
public Resource getClusterResource() {
return csContext.getClusterResource();
}
public ResourceUsage getClusterResourceUsage() {
return queueManager.getRootQueue().getQueueResourceUsage();
}
public SchedulerHealth getSchedulerHealth() {
return csContext.getSchedulerHealth();
}
public long getLastNodeUpdateTime() {
return csContext.getLastNodeUpdateTime();
}
public FiCaSchedulerNode getNode(NodeId nodeId) {
return csContext.getNode(nodeId);
}
public FiCaSchedulerApp getApplicationAttempt(
ApplicationAttemptId applicationAttemptId) {
return csContext.getApplicationAttempt(applicationAttemptId);
}
// TODO this is used in GuaranteedOrZeroCapacityOverTimePolicy, refactor the comparator there
public RMApp getRMApp(ApplicationId applicationId) {
return csContext.getRMContext().getRMApps().get(applicationId);
}
}

View File

@ -106,6 +106,11 @@ public CSQueue getRootQueue() {
return this.root; return this.root;
} }
@VisibleForTesting
protected void setRootQueue(CSQueue rootQueue) {
this.root = rootQueue;
}
@Override @Override
public Map<String, CSQueue> getQueues() { public Map<String, CSQueue> getQueues() {
return queues.getFullNameQueues(); return queues.getFullNameQueues();
@ -167,7 +172,7 @@ public void setCapacitySchedulerContext(
public void initializeQueues(CapacitySchedulerConfiguration conf) public void initializeQueues(CapacitySchedulerConfiguration conf)
throws IOException { throws IOException {
configuredNodeLabels = new ConfiguredNodeLabels(conf); configuredNodeLabels = new ConfiguredNodeLabels(conf);
root = parseQueue(this.csContext, conf, null, root = parseQueue(this.csContext.getQueueContext(), conf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, NOOP); CapacitySchedulerConfiguration.ROOT, queues, queues, NOOP);
setQueueAcls(authorizer, appPriorityACLManager, queues); setQueueAcls(authorizer, appPriorityACLManager, queues);
labelManager.reinitializeQueueLabels(getQueueToLabels()); labelManager.reinitializeQueueLabels(getQueueToLabels());
@ -183,7 +188,7 @@ public void reinitializeQueues(CapacitySchedulerConfiguration newConf)
// Parse new queues // Parse new queues
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
configuredNodeLabels = new ConfiguredNodeLabels(newConf); configuredNodeLabels = new ConfiguredNodeLabels(newConf);
CSQueue newRoot = parseQueue(this.csContext, newConf, null, CSQueue newRoot = parseQueue(this.csContext.getQueueContext(), newConf, null,
CapacitySchedulerConfiguration.ROOT, newQueues, queues, NOOP); CapacitySchedulerConfiguration.ROOT, newQueues, queues, NOOP);
// When failing over, if using configuration store, don't validate queue // When failing over, if using configuration store, don't validate queue
@ -215,7 +220,7 @@ public void reinitializeQueues(CapacitySchedulerConfiguration newConf)
/** /**
* Parse the queue from the configuration. * Parse the queue from the configuration.
* @param csContext the CapacitySchedulerContext * @param queueContext the CapacitySchedulerQueueContext
* @param conf the CapacitySchedulerConfiguration * @param conf the CapacitySchedulerConfiguration
* @param parent the parent queue * @param parent the parent queue
* @param queueName the queue name * @param queueName the queue name
@ -226,7 +231,7 @@ public void reinitializeQueues(CapacitySchedulerConfiguration newConf)
* @throws IOException * @throws IOException
*/ */
static CSQueue parseQueue( static CSQueue parseQueue(
CapacitySchedulerContext csContext, CapacitySchedulerQueueContext queueContext,
CapacitySchedulerConfiguration conf, CapacitySchedulerConfiguration conf,
CSQueue parent, String queueName, CSQueue parent, String queueName,
CSQueueStore newQueues, CSQueueStore newQueues,
@ -265,7 +270,7 @@ static CSQueue parseQueue(
// Check if the queue will be dynamically managed by the Reservation // Check if the queue will be dynamically managed by the Reservation
// system // system
if (isReservableQueue) { if (isReservableQueue) {
queue = new PlanQueue(csContext, queueName, parent, queue = new PlanQueue(queueContext, queueName, parent,
oldQueues.get(fullQueueName)); oldQueues.get(fullQueueName));
//initializing the "internal" default queue, for SLS compatibility //initializing the "internal" default queue, for SLS compatibility
@ -273,7 +278,7 @@ static CSQueue parseQueue(
queueName + ReservationConstants.DEFAULT_QUEUE_SUFFIX; queueName + ReservationConstants.DEFAULT_QUEUE_SUFFIX;
List<CSQueue> childQueues = new ArrayList<>(); List<CSQueue> childQueues = new ArrayList<>();
ReservationQueue resQueue = new ReservationQueue(csContext, ReservationQueue resQueue = new ReservationQueue(queueContext,
defReservationId, (PlanQueue) queue); defReservationId, (PlanQueue) queue);
try { try {
resQueue.setEntitlement(new QueueEntitlement(1.0f, 1.0f)); resQueue.setEntitlement(new QueueEntitlement(1.0f, 1.0f));
@ -285,11 +290,11 @@ static CSQueue parseQueue(
newQueues.add(resQueue); newQueues.add(resQueue);
} else if (isAutoCreateEnabled) { } else if (isAutoCreateEnabled) {
queue = new ManagedParentQueue(csContext, queueName, parent, queue = new ManagedParentQueue(queueContext, queueName, parent,
oldQueues.get(fullQueueName)); oldQueues.get(fullQueueName));
} else{ } else{
queue = new LeafQueue(csContext, queueName, parent, queue = new LeafQueue(queueContext, queueName, parent,
oldQueues.get(fullQueueName)); oldQueues.get(fullQueueName));
// Used only for unit tests // Used only for unit tests
queue = hook.hook(queue); queue = hook.hook(queue);
@ -302,10 +307,10 @@ static CSQueue parseQueue(
ParentQueue parentQueue; ParentQueue parentQueue;
if (isAutoCreateEnabled) { if (isAutoCreateEnabled) {
parentQueue = new ManagedParentQueue(csContext, queueName, parent, parentQueue = new ManagedParentQueue(queueContext, queueName, parent,
oldQueues.get(fullQueueName)); oldQueues.get(fullQueueName));
} else{ } else{
parentQueue = new ParentQueue(csContext, queueName, parent, parentQueue = new ParentQueue(queueContext, queueName, parent,
oldQueues.get(fullQueueName)); oldQueues.get(fullQueueName));
} }
@ -314,7 +319,7 @@ static CSQueue parseQueue(
List<CSQueue> childQueues = new ArrayList<>(); List<CSQueue> childQueues = new ArrayList<>();
for (String childQueueName : childQueueNames) { for (String childQueueName : childQueueNames) {
CSQueue childQueue = parseQueue(csContext, conf, queue, childQueueName, CSQueue childQueue = parseQueue(queueContext, conf, queue, childQueueName,
newQueues, oldQueues, hook); newQueues, oldQueues, hook);
childQueues.add(childQueue); childQueues.add(childQueue);
} }
@ -633,7 +638,7 @@ public List<String> determineMissingParents(
* for all queues. * for all queues.
* @return configured node labels * @return configured node labels
*/ */
public ConfiguredNodeLabels getConfiguredNodeLabels() { public ConfiguredNodeLabels getConfiguredNodeLabelsForAllQueues() {
return configuredNodeLabels; return configuredNodeLabels;
} }
@ -676,7 +681,7 @@ private AbstractLeafQueue createLegacyAutoQueue(QueuePath queue)
(ManagedParentQueue) parentQueue; (ManagedParentQueue) parentQueue;
AutoCreatedLeafQueue autoCreatedLeafQueue = AutoCreatedLeafQueue autoCreatedLeafQueue =
new AutoCreatedLeafQueue( new AutoCreatedLeafQueue(
csContext, queue.getLeafName(), autoCreateEnabledParentQueue); csContext.getQueueContext(), queue.getLeafName(), autoCreateEnabledParentQueue);
addLegacyDynamicQueue(autoCreatedLeafQueue); addLegacyDynamicQueue(autoCreatedLeafQueue);
return autoCreatedLeafQueue; return autoCreatedLeafQueue;

View File

@ -31,26 +31,16 @@ public class LeafQueue extends AbstractLeafQueue {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(LeafQueue.class); LoggerFactory.getLogger(LeafQueue.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) public LeafQueue(CapacitySchedulerQueueContext queueContext,
public LeafQueue(CapacitySchedulerContext cs,
String queueName, CSQueue parent, CSQueue old) throws IOException { String queueName, CSQueue parent, CSQueue old) throws IOException {
this(cs, cs.getConfiguration(), queueName, parent, old, false); this(queueContext, queueName, parent, old, false);
} }
public LeafQueue(CapacitySchedulerContext cs, public LeafQueue(CapacitySchedulerQueueContext queueContext,
CapacitySchedulerConfiguration configuration,
String queueName, CSQueue parent, CSQueue old) throws IOException {
this(cs, configuration, queueName, parent, old, false);
}
public LeafQueue(CapacitySchedulerContext cs,
CapacitySchedulerConfiguration configuration,
String queueName, CSQueue parent, CSQueue old, boolean isDynamic) throws String queueName, CSQueue parent, CSQueue old, boolean isDynamic) throws
IOException { IOException {
super(cs, configuration, queueName, parent, old, isDynamic); super(queueContext, queueName, parent, old, isDynamic);
setupQueueConfigs(cs.getClusterResource(), configuration); setupQueueConfigs(queueContext.getClusterResource(), queueContext.getConfiguration());
LOG.debug("LeafQueue: name={}, fullname={}", queueName, getQueuePath());
} }
} }

View File

@ -53,23 +53,18 @@ public class ManagedParentQueue extends AbstractManagedParentQueue {
private static final Logger LOG = LoggerFactory.getLogger( private static final Logger LOG = LoggerFactory.getLogger(
ManagedParentQueue.class); ManagedParentQueue.class);
public ManagedParentQueue(final CapacitySchedulerContext cs, public ManagedParentQueue(final CapacitySchedulerQueueContext queueContext,
final String queueName, final CSQueue parent, final CSQueue old) final String queueName, final CSQueue parent, final CSQueue old)
throws IOException { throws IOException {
super(cs, queueName, parent, old); super(queueContext, queueName, parent, old);
shouldFailAutoCreationWhenGuaranteedCapacityExceeded = shouldFailAutoCreationWhenGuaranteedCapacityExceeded =
csContext.getConfiguration() queueContext.getConfiguration()
.getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded( .getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded(
getQueuePath()); getQueuePath());
leafQueueTemplate = initializeLeafQueueConfigs().build(); leafQueueTemplate = initializeLeafQueueConfigs().build();
LOG.info(
"Created Managed Parent Queue: [{}] with capacity: [{}]"
+ " with max capacity: [{}]",
queueName, super.getCapacity(), super.getMaximumCapacity());
initializeQueueManagementPolicy(); initializeQueueManagementPolicy();
} }
@ -82,7 +77,7 @@ public void reinitialize(CSQueue newlyParsedQueue, Resource clusterResource)
validate(newlyParsedQueue); validate(newlyParsedQueue);
shouldFailAutoCreationWhenGuaranteedCapacityExceeded = shouldFailAutoCreationWhenGuaranteedCapacityExceeded =
csContext.getConfiguration() queueContext.getConfiguration()
.getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded( .getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded(
getQueuePath()); getQueuePath());
@ -133,23 +128,23 @@ public void reinitialize(CSQueue newlyParsedQueue, Resource clusterResource)
private void initializeQueueManagementPolicy() throws IOException { private void initializeQueueManagementPolicy() throws IOException {
queueManagementPolicy = queueManagementPolicy =
csContext.getConfiguration().getAutoCreatedQueueManagementPolicyClass( queueContext.getConfiguration().getAutoCreatedQueueManagementPolicyClass(
getQueuePath()); getQueuePath());
queueManagementPolicy.init(csContext, this); queueManagementPolicy.init(this);
} }
private void reinitializeQueueManagementPolicy() throws IOException { private void reinitializeQueueManagementPolicy() throws IOException {
AutoCreatedQueueManagementPolicy managementPolicy = AutoCreatedQueueManagementPolicy managementPolicy =
csContext.getConfiguration().getAutoCreatedQueueManagementPolicyClass( queueContext.getConfiguration().getAutoCreatedQueueManagementPolicyClass(
getQueuePath()); getQueuePath());
if (!(managementPolicy.getClass().equals( if (!(managementPolicy.getClass().equals(
this.queueManagementPolicy.getClass()))) { this.queueManagementPolicy.getClass()))) {
queueManagementPolicy = managementPolicy; queueManagementPolicy = managementPolicy;
queueManagementPolicy.init(csContext, this); queueManagementPolicy.init(this);
} else{ } else{
queueManagementPolicy.reinitialize(csContext, this); queueManagementPolicy.reinitialize(this);
} }
} }
@ -158,21 +153,25 @@ protected AutoCreatedLeafQueueConfig.Builder initializeLeafQueueConfigs() throws
AutoCreatedLeafQueueConfig.Builder builder = AutoCreatedLeafQueueConfig.Builder builder =
new AutoCreatedLeafQueueConfig.Builder(); new AutoCreatedLeafQueueConfig.Builder();
CapacitySchedulerConfiguration configuration =
queueContext.getConfiguration();
// TODO load configs into CapacitySchedulerConfiguration instead of duplicating them
String leafQueueTemplateConfPrefix = getLeafQueueConfigPrefix( String leafQueueTemplateConfPrefix = getLeafQueueConfigPrefix(
csContext.getConfiguration()); configuration);
//Load template configuration //Load template configuration into CapacitySchedulerConfiguration
CapacitySchedulerConfiguration conf = CapacitySchedulerConfiguration autoCreatedTemplateConfig =
super.initializeLeafQueueConfigs(leafQueueTemplateConfPrefix); super.initializeLeafQueueConfigs(leafQueueTemplateConfPrefix);
builder.configuration(conf); builder.configuration(autoCreatedTemplateConfig);
QueuePath templateQueuePath = csContext.getConfiguration() QueuePath templateQueuePath = configuration
.getAutoCreatedQueueObjectTemplateConfPrefix(getQueuePath()); .getAutoCreatedQueueObjectTemplateConfPrefix(getQueuePath());
Set<String> templateConfiguredNodeLabels = csContext Set<String> templateConfiguredNodeLabels = queueContext
.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() .getQueueManager().getConfiguredNodeLabelsForAllQueues()
.getLabelsByQueue(templateQueuePath.getFullPath()); .getLabelsByQueue(templateQueuePath.getFullPath());
for (String nodeLabel : templateConfiguredNodeLabels) { for (String nodeLabel : templateConfiguredNodeLabels) {
Resource templateMinResource = conf.getMinimumResourceRequirement( Resource templateMinResource = autoCreatedTemplateConfig.getMinimumResourceRequirement(
nodeLabel, csContext.getConfiguration() nodeLabel, configuration
.getAutoCreatedQueueTemplateConfPrefix(getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(getQueuePath()),
resourceTypes); resourceTypes);
@ -187,7 +186,7 @@ protected AutoCreatedLeafQueueConfig.Builder initializeLeafQueueConfigs() throws
QueueCapacities queueCapacities = new QueueCapacities(false); QueueCapacities queueCapacities = new QueueCapacities(false);
CSQueueUtils.loadCapacitiesByLabelsFromConf(templateQueuePath, CSQueueUtils.loadCapacitiesByLabelsFromConf(templateQueuePath,
queueCapacities, queueCapacities,
csContext.getConfiguration(), configuration,
templateConfiguredNodeLabels); templateConfiguredNodeLabels);
@ -205,35 +204,38 @@ protected AutoCreatedLeafQueueConfig.Builder initializeLeafQueueConfigs() throws
} }
private void updateQueueCapacities(QueueCapacities queueCapacities) { private void updateQueueCapacities(QueueCapacities queueCapacities) {
CapacitySchedulerConfiguration configuration =
queueContext.getConfiguration();
for (String label : queueCapacities.getExistingNodeLabels()) { for (String label : queueCapacities.getExistingNodeLabels()) {
queueCapacities.setCapacity(label, queueCapacities.setCapacity(label,
this.csContext.getResourceCalculator().divide( resourceCalculator.divide(
this.csContext.getClusterResource(), queueContext.getClusterResource(),
this.csContext.getConfiguration().getMinimumResourceRequirement( configuration.getMinimumResourceRequirement(
label, label,
this.csContext.getConfiguration() configuration
.getAutoCreatedQueueTemplateConfPrefix(getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(getQueuePath()),
resourceTypes), resourceTypes),
getQueueResourceQuotas().getConfiguredMinResource(label))); getQueueResourceQuotas().getConfiguredMinResource(label)));
Resource childMaxResource = this.csContext.getConfiguration() Resource childMaxResource = configuration
.getMaximumResourceRequirement(label, .getMaximumResourceRequirement(label,
this.csContext.getConfiguration() configuration
.getAutoCreatedQueueTemplateConfPrefix(getQueuePath()), .getAutoCreatedQueueTemplateConfPrefix(getQueuePath()),
resourceTypes); resourceTypes);
Resource parentMaxRes = getQueueResourceQuotas() Resource parentMaxRes = getQueueResourceQuotas()
.getConfiguredMaxResource(label); .getConfiguredMaxResource(label);
Resource effMaxResource = Resources.min( Resource effMaxResource = Resources.min(
this.csContext.getResourceCalculator(), resourceCalculator,
this.csContext.getClusterResource(), queueContext.getClusterResource(),
childMaxResource.equals(Resources.none()) ? parentMaxRes childMaxResource.equals(Resources.none()) ? parentMaxRes
: childMaxResource, : childMaxResource,
parentMaxRes); parentMaxRes);
queueCapacities.setMaximumCapacity( queueCapacities.setMaximumCapacity(
label, this.csContext.getResourceCalculator().divide( label, resourceCalculator.divide(
this.csContext.getClusterResource(), queueContext.getClusterResource(),
effMaxResource, effMaxResource,
getQueueResourceQuotas().getConfiguredMaxResource(label))); getQueueResourceQuotas().getConfiguredMaxResource(label)));
@ -268,7 +270,7 @@ public void addChildQueue(CSQueue childQueue)
"Expected child queue to be an instance of AutoCreatedLeafQueue"); "Expected child queue to be an instance of AutoCreatedLeafQueue");
} }
CapacitySchedulerConfiguration conf = csContext.getConfiguration(); CapacitySchedulerConfiguration conf = queueContext.getConfiguration();
ManagedParentQueue parentQueue = ManagedParentQueue parentQueue =
(ManagedParentQueue) childQueue.getParent(); (ManagedParentQueue) childQueue.getParent();
@ -322,8 +324,8 @@ public void addChildQueue(CSQueue childQueue)
// Do one update cluster resource call to make sure all absolute resources // Do one update cluster resource call to make sure all absolute resources
// effective resources are updated. // effective resources are updated.
updateClusterResource(this.csContext.getClusterResource(), updateClusterResource(queueContext.getClusterResource(),
new ResourceLimits(this.csContext.getClusterResource())); new ResourceLimits(queueContext.getClusterResource()));
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
} }
@ -427,12 +429,11 @@ public void validateQueueManagementChanges(
+ " Ignoring update " + queueManagementChanges); + " Ignoring update " + queueManagementChanges);
} }
switch (queueManagementChange.getQueueAction()){ if (queueManagementChange.getQueueAction() ==
case UPDATE_QUEUE: QueueManagementChange.QueueAction.UPDATE_QUEUE) {
AutoCreatedLeafQueueConfig template = AutoCreatedLeafQueueConfig template =
queueManagementChange.getUpdatedQueueTemplate(); queueManagementChange.getUpdatedQueueTemplate();
((AutoCreatedLeafQueue) childQueue).validateConfigurations(template); ((AutoCreatedLeafQueue) childQueue).validateConfigurations(template);
break;
} }
} }
@ -442,14 +443,13 @@ private void applyQueueManagementChanges(
List<QueueManagementChange> queueManagementChanges) List<QueueManagementChange> queueManagementChanges)
throws SchedulerDynamicEditException, IOException { throws SchedulerDynamicEditException, IOException {
for (QueueManagementChange queueManagementChange : queueManagementChanges) { for (QueueManagementChange queueManagementChange : queueManagementChanges) {
switch (queueManagementChange.getQueueAction()){ if (queueManagementChange.getQueueAction() ==
case UPDATE_QUEUE: QueueManagementChange.QueueAction.UPDATE_QUEUE) {
AutoCreatedLeafQueue childQueueToBeUpdated = AutoCreatedLeafQueue childQueueToBeUpdated =
(AutoCreatedLeafQueue) queueManagementChange.getQueue(); (AutoCreatedLeafQueue) queueManagementChange.getQueue();
//acquires write lock on leaf queue //acquires write lock on leaf queue
childQueueToBeUpdated.reinitializeFromTemplate( childQueueToBeUpdated.reinitializeFromTemplate(
queueManagementChange.getUpdatedQueueTemplate()); queueManagementChange.getUpdatedQueueTemplate());
break;
} }
} }
} }
@ -465,7 +465,7 @@ public CapacitySchedulerConfiguration getLeafQueueConfigs(
CapacitySchedulerConfiguration leafQueueConfigTemplate = new CapacitySchedulerConfiguration leafQueueConfigTemplate = new
CapacitySchedulerConfiguration(new Configuration(false), false); CapacitySchedulerConfiguration(new Configuration(false), false);
for (final Iterator<Map.Entry<String, String>> iterator = for (final Iterator<Map.Entry<String, String>> iterator =
templateConfig.iterator(); iterator.hasNext(); ) { templateConfig.iterator(); iterator.hasNext();) {
Map.Entry<String, String> confKeyValuePair = iterator.next(); Map.Entry<String, String> confKeyValuePair = iterator.next();
final String name = confKeyValuePair.getKey().replaceFirst( final String name = confKeyValuePair.getKey().replaceFirst(
CapacitySchedulerConfiguration CapacitySchedulerConfiguration

View File

@ -87,7 +87,6 @@ public class ParentQueue extends AbstractCSQueue {
protected final List<CSQueue> childQueues; protected final List<CSQueue> childQueues;
private final boolean rootQueue; private final boolean rootQueue;
private volatile int numApplications; private volatile int numApplications;
private final CapacitySchedulerContext scheduler;
private final RecordFactory recordFactory = private final RecordFactory recordFactory =
RecordFactoryProvider.getRecordFactory(null); RecordFactoryProvider.getRecordFactory(null);
@ -108,27 +107,20 @@ public class ParentQueue extends AbstractCSQueue {
// after every time recalculation // after every time recalculation
private volatile Map<String, Float> effectiveMinRatioPerResource; private volatile Map<String, Float> effectiveMinRatioPerResource;
public ParentQueue(CapacitySchedulerContext cs, public ParentQueue(CapacitySchedulerQueueContext queueContext,
String queueName, CSQueue parent, CSQueue old) throws IOException { String queueName, CSQueue parent, CSQueue old) throws IOException {
this(cs, cs.getConfiguration(), queueName, parent, old, false); this(queueContext, queueName, parent, old, false);
}
private ParentQueue(CapacitySchedulerContext cs,
CapacitySchedulerConfiguration csConf, String queueName,
CSQueue parent,
CSQueue old) throws IOException {
this(cs, csConf, queueName, parent, old, false);
} }
private ParentQueue(CapacitySchedulerContext cs, private ParentQueue(CapacitySchedulerQueueContext queueContext,
CapacitySchedulerConfiguration csConf, String queueName, CSQueue parent, String queueName, CSQueue parent, CSQueue old, boolean isDynamic)
CSQueue old, boolean isDynamic)
throws IOException { throws IOException {
super(cs, queueName, parent, old); super(queueContext, queueName, parent, old);
setDynamicQueue(isDynamic); setDynamicQueue(isDynamic);
this.scheduler = cs;
this.rootQueue = (parent == null); this.rootQueue = (parent == null);
float rawCapacity = csConf.getNonLabeledQueueCapacity(this.queuePath); float rawCapacity = queueContext.getConfiguration()
.getNonLabeledQueueCapacity(this.queuePath);
if (rootQueue && if (rootQueue &&
(rawCapacity != CapacitySchedulerConfiguration.MAXIMUM_CAPACITY_VALUE)) { (rawCapacity != CapacitySchedulerConfiguration.MAXIMUM_CAPACITY_VALUE)) {
@ -139,13 +131,10 @@ private ParentQueue(CapacitySchedulerContext cs,
this.childQueues = new ArrayList<>(); this.childQueues = new ArrayList<>();
this.allowZeroCapacitySum = this.allowZeroCapacitySum =
cs.getConfiguration().getAllowZeroCapacitySum(getQueuePath()); queueContext.getConfiguration()
.getAllowZeroCapacitySum(getQueuePath());
setupQueueConfigs(cs.getClusterResource(), csConf); setupQueueConfigs(queueContext.getClusterResource(), queueContext.getConfiguration());
LOG.info("Initialized parent-queue " + queueName +
" name=" + queueName +
", fullname=" + getQueuePath());
} }
// returns what is configured queue ordering policy // returns what is configured queue ordering policy
@ -156,41 +145,42 @@ private String getQueueOrderingPolicyConfigName() {
} }
protected void setupQueueConfigs(Resource clusterResource, protected void setupQueueConfigs(Resource clusterResource,
CapacitySchedulerConfiguration csConf) CapacitySchedulerConfiguration configuration)
throws IOException { throws IOException {
writeLock.lock(); writeLock.lock();
try { try {
autoCreatedQueueTemplate = new AutoCreatedQueueTemplate( autoCreatedQueueTemplate = new AutoCreatedQueueTemplate(
csConf, this.queuePath); configuration, this.queuePath);
super.setupQueueConfigs(clusterResource, csConf); super.setupQueueConfigs(clusterResource, configuration);
StringBuilder aclsString = new StringBuilder(); StringBuilder aclsString = new StringBuilder();
for (Map.Entry<AccessType, AccessControlList> e : acls.entrySet()) { for (Map.Entry<AccessType, AccessControlList> e : getACLs().entrySet()) {
aclsString.append(e.getKey() + ":" + e.getValue().getAclString()); aclsString.append(e.getKey()).append(":")
.append(e.getValue().getAclString());
} }
StringBuilder labelStrBuilder = new StringBuilder(); StringBuilder labelStrBuilder = new StringBuilder();
if (queueNodeLabelsSettings.getAccessibleNodeLabels() != null) { if (getAccessibleNodeLabels() != null) {
for (String nodeLabel : queueNodeLabelsSettings.getAccessibleNodeLabels()) { for (String nodeLabel : getAccessibleNodeLabels()) {
labelStrBuilder.append(nodeLabel).append(","); labelStrBuilder.append(nodeLabel).append(",");
} }
} }
// Initialize queue ordering policy // Initialize queue ordering policy
queueOrderingPolicy = csConf.getQueueOrderingPolicy( queueOrderingPolicy = configuration.getQueueOrderingPolicy(
getQueuePath(), parent == null ? getQueuePath(), parent == null ?
null : null :
((ParentQueue) parent).getQueueOrderingPolicyConfigName()); ((ParentQueue) parent).getQueueOrderingPolicyConfigName());
queueOrderingPolicy.setQueues(childQueues); queueOrderingPolicy.setQueues(childQueues);
LOG.info(getQueueName() + ", " + getCapacityOrWeightString() LOG.info(getQueueName() + ", " + getCapacityOrWeightString()
+ ", absoluteCapacity=" + this.queueCapacities.getAbsoluteCapacity() + ", absoluteCapacity=" + getAbsoluteCapacity()
+ ", maxCapacity=" + this.queueCapacities.getMaximumCapacity() + ", maxCapacity=" + getMaximumCapacity()
+ ", absoluteMaxCapacity=" + this.queueCapacities + ", absoluteMaxCapacity=" + getAbsoluteMaximumCapacity()
.getAbsoluteMaximumCapacity() + ", state=" + getState() + ", acls=" + ", state=" + getState() + ", acls="
+ aclsString + ", labels=" + labelStrBuilder.toString() + "\n" + aclsString + ", labels=" + labelStrBuilder + "\n"
+ ", reservationsContinueLooking=" + reservationsContinueLooking + ", reservationsContinueLooking=" + isReservationsContinueLooking()
+ ", orderingPolicy=" + getQueueOrderingPolicyConfigName() + ", orderingPolicy=" + getQueueOrderingPolicyConfigName()
+ ", priority=" + priority + ", priority=" + getPriority()
+ ", allowZeroCapacitySum=" + allowZeroCapacitySum); + ", allowZeroCapacitySum=" + allowZeroCapacitySum);
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
@ -325,7 +315,7 @@ void setChildQueues(Collection<CSQueue> childQueues) throws IOException {
.getConfiguredMinResource(nodeLabel)); .getConfiguredMinResource(nodeLabel));
} }
Resource resourceByLabel = labelManager.getResourceByLabel(nodeLabel, Resource resourceByLabel = labelManager.getResourceByLabel(nodeLabel,
scheduler.getClusterResource()); queueContext.getClusterResource());
Resource parentMinResource = Resource parentMinResource =
usageTracker.getQueueResourceQuotas().getConfiguredMinResource(nodeLabel); usageTracker.getQueueResourceQuotas().getConfiguredMinResource(nodeLabel);
if (!parentMinResource.equals(Resources.none()) && Resources.lessThan( if (!parentMinResource.equals(Resources.none()) && Resources.lessThan(
@ -488,11 +478,10 @@ private CSQueue createNewQueue(String childQueuePath, boolean isLeaf)
childQueuePath.lastIndexOf(".") + 1); childQueuePath.lastIndexOf(".") + 1);
if (isLeaf) { if (isLeaf) {
childQueue = new LeafQueue(csContext, csContext.getConfiguration(), childQueue = new LeafQueue(queueContext,
queueShortName, this, null, true); queueShortName, this, null, true);
} else{ } else{
childQueue = new ParentQueue(csContext, csContext.getConfiguration(), childQueue = new ParentQueue(queueContext, queueShortName, this, null, true);
queueShortName, this, null, true);
} }
childQueue.setDynamicQueue(true); childQueue.setDynamicQueue(true);
// It should be sufficient now, we don't need to set more, because weights // It should be sufficient now, we don't need to set more, because weights
@ -523,7 +512,7 @@ private CSQueue addDynamicChildQueue(String childQueuePath, boolean isLeaf)
// should not happen, since it will be handled before calling this method) // should not happen, since it will be handled before calling this method)
// , but we will move on. // , but we will move on.
CSQueue queue = CSQueue queue =
csContext.getCapacitySchedulerQueueManager().getQueueByFullName( queueContext.getQueueManager().getQueueByFullName(
childQueuePath); childQueuePath);
if (queue != null) { if (queue != null) {
LOG.warn( LOG.warn(
@ -533,7 +522,7 @@ private CSQueue addDynamicChildQueue(String childQueuePath, boolean isLeaf)
} }
// Check if the max queue limit is exceeded. // Check if the max queue limit is exceeded.
int maxQueues = csContext.getConfiguration(). int maxQueues = queueContext.getConfiguration().
getAutoCreatedQueuesV2MaxChildQueuesLimit(getQueuePath()); getAutoCreatedQueuesV2MaxChildQueuesLimit(getQueuePath());
if (childQueues.size() >= maxQueues) { if (childQueues.size() >= maxQueues) {
throw new SchedulerDynamicEditException( throw new SchedulerDynamicEditException(
@ -564,8 +553,8 @@ private CSQueue addDynamicChildQueue(String childQueuePath, boolean isLeaf)
// Call updateClusterResource. // Call updateClusterResource.
// Which will deal with all effectiveMin/MaxResource // Which will deal with all effectiveMin/MaxResource
// Calculation // Calculation
this.updateClusterResource(csContext.getClusterResource(), this.updateClusterResource(queueContext.getClusterResource(),
new ResourceLimits(this.csContext.getClusterResource())); new ResourceLimits(queueContext.getClusterResource()));
return newQueue; return newQueue;
} finally { } finally {
@ -596,14 +585,14 @@ public void removeChildQueue(CSQueue queue)
// Now we can do remove and update // Now we can do remove and update
this.childQueues.remove(queue); this.childQueues.remove(queue);
this.scheduler.getCapacitySchedulerQueueManager() queueContext.getQueueManager()
.removeQueue(queue.getQueuePath()); .removeQueue(queue.getQueuePath());
// Call updateClusterResource, // Call updateClusterResource,
// which will deal with all effectiveMin/MaxResource // which will deal with all effectiveMin/MaxResource
// Calculation // Calculation
this.updateClusterResource(csContext.getClusterResource(), this.updateClusterResource(queueContext.getClusterResource(),
new ResourceLimits(this.csContext.getClusterResource())); new ResourceLimits(queueContext.getClusterResource()));
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
@ -617,7 +606,7 @@ public void removeChildQueue(CSQueue queue)
* false otherwise * false otherwise
*/ */
public boolean isEligibleForAutoQueueCreation() { public boolean isEligibleForAutoQueueCreation() {
return isDynamicQueue() || csContext.getConfiguration(). return isDynamicQueue() || queueContext.getConfiguration().
isAutoQueueCreationV2Enabled(getQueuePath()); isAutoQueueCreationV2Enabled(getQueuePath());
} }
@ -644,7 +633,7 @@ public void reinitialize(CSQueue newlyParsedQueue,
ParentQueue newlyParsedParentQueue = (ParentQueue) newlyParsedQueue; ParentQueue newlyParsedParentQueue = (ParentQueue) newlyParsedQueue;
// Set new configs // Set new configs
setupQueueConfigs(clusterResource, csContext.getConfiguration()); setupQueueConfigs(clusterResource, queueContext.getConfiguration());
// Re-configure existing child queues and add new ones // Re-configure existing child queues and add new ones
// The CS has already checked to ensure all existing child queues are present! // The CS has already checked to ensure all existing child queues are present!
@ -685,7 +674,7 @@ public void reinitialize(CSQueue newlyParsedQueue,
currentChildQueues.put(newChildQueueName, newChildQueue); currentChildQueues.put(newChildQueueName, newChildQueue);
// inform CapacitySchedulerQueueManager // inform CapacitySchedulerQueueManager
CapacitySchedulerQueueManager queueManager = CapacitySchedulerQueueManager queueManager =
this.csContext.getCapacitySchedulerQueueManager(); queueContext.getQueueManager();
queueManager.addQueue(newChildQueueName, newChildQueue); queueManager.addQueue(newChildQueueName, newChildQueue);
continue; continue;
} }
@ -1399,7 +1388,7 @@ public void recoverContainer(Resource clusterResource,
// Careful! Locking order is important! // Careful! Locking order is important!
writeLock.lock(); writeLock.lock();
try { try {
FiCaSchedulerNode node = scheduler.getNode( FiCaSchedulerNode node = queueContext.getNode(
rmContainer.getContainer().getNodeId()); rmContainer.getContainer().getNodeId());
allocateResource(clusterResource, allocateResource(clusterResource,
rmContainer.getContainer().getResource(), node.getPartition()); rmContainer.getContainer().getResource(), node.getPartition());
@ -1437,7 +1426,7 @@ public void attachContainer(Resource clusterResource,
FiCaSchedulerApp application, RMContainer rmContainer) { FiCaSchedulerApp application, RMContainer rmContainer) {
if (application != null) { if (application != null) {
FiCaSchedulerNode node = FiCaSchedulerNode node =
scheduler.getNode(rmContainer.getContainer().getNodeId()); queueContext.getNode(rmContainer.getContainer().getNodeId());
allocateResource(clusterResource, rmContainer.getContainer() allocateResource(clusterResource, rmContainer.getContainer()
.getResource(), node.getPartition()); .getResource(), node.getPartition());
LOG.info("movedContainer" + " queueMoveIn=" + getQueuePath() LOG.info("movedContainer" + " queueMoveIn=" + getQueuePath()
@ -1456,7 +1445,7 @@ public void detachContainer(Resource clusterResource,
FiCaSchedulerApp application, RMContainer rmContainer) { FiCaSchedulerApp application, RMContainer rmContainer) {
if (application != null) { if (application != null) {
FiCaSchedulerNode node = FiCaSchedulerNode node =
scheduler.getNode(rmContainer.getContainer().getNodeId()); queueContext.getNode(rmContainer.getContainer().getNodeId());
super.releaseResource(clusterResource, super.releaseResource(clusterResource,
rmContainer.getContainer().getResource(), rmContainer.getContainer().getResource(),
node.getPartition()); node.getPartition());
@ -1543,9 +1532,9 @@ private void killContainersToEnforceMaxQueueCapacity(String partition,
while (Resources.greaterThan(resourceCalculator, partitionResource, while (Resources.greaterThan(resourceCalculator, partitionResource,
usageTracker.getQueueUsage().getUsed(partition), maxResource)) { usageTracker.getQueueUsage().getUsed(partition), maxResource)) {
RMContainer toKillContainer = killableContainerIter.next(); RMContainer toKillContainer = killableContainerIter.next();
FiCaSchedulerApp attempt = csContext.getApplicationAttempt( FiCaSchedulerApp attempt = queueContext.getApplicationAttempt(
toKillContainer.getContainerId().getApplicationAttemptId()); toKillContainer.getContainerId().getApplicationAttemptId());
FiCaSchedulerNode node = csContext.getNode( FiCaSchedulerNode node = queueContext.getNode(
toKillContainer.getAllocatedNode()); toKillContainer.getAllocatedNode());
if (null != attempt && null != node) { if (null != attempt && null != node) {
AbstractLeafQueue lq = attempt.getCSLeafQueue(); AbstractLeafQueue lq = attempt.getCSLeafQueue();
@ -1656,7 +1645,7 @@ Map<String, Float> getEffectiveMinRatioPerResource() {
@Override @Override
public boolean isEligibleForAutoDeletion() { public boolean isEligibleForAutoDeletion() {
return isDynamicQueue() && getChildQueues().size() == 0 && return isDynamicQueue() && getChildQueues().size() == 0 &&
csContext.getConfiguration(). queueContext.getConfiguration().
isAutoExpiredDeletionEnabled(this.getQueuePath()); isAutoExpiredDeletionEnabled(this.getQueuePath());
} }

View File

@ -40,17 +40,15 @@ public class PlanQueue extends AbstractManagedParentQueue {
private int maxAppsPerUserForReservation; private int maxAppsPerUserForReservation;
private float userLimit; private float userLimit;
private float userLimitFactor; private float userLimitFactor;
protected CapacitySchedulerContext schedulerContext;
private boolean showReservationsAsQueues; private boolean showReservationsAsQueues;
public PlanQueue(CapacitySchedulerContext cs, String queueName, public PlanQueue(CapacitySchedulerQueueContext queueContext, String queueName,
CSQueue parent, CSQueue old) throws IOException { CSQueue parent, CSQueue old) throws IOException {
super(cs, queueName, parent, old); super(queueContext, queueName, parent, old);
updateAbsoluteCapacities(); updateAbsoluteCapacities();
this.schedulerContext = cs;
// Set the reservation queue attributes for the Plan // Set the reservation queue attributes for the Plan
CapacitySchedulerConfiguration conf = cs.getConfiguration(); CapacitySchedulerConfiguration conf = queueContext.getConfiguration();
String queuePath = super.getQueuePath(); String queuePath = super.getQueuePath();
int maxAppsForReservation = conf.getMaximumApplicationsPerQueue(queuePath); int maxAppsForReservation = conf.getMaximumApplicationsPerQueue(queuePath);
showReservationsAsQueues = conf.getShowReservationAsQueues(queuePath); showReservationsAsQueues = conf.getShowReservationAsQueues(queuePath);
@ -106,7 +104,7 @@ public void reinitialize(CSQueue newlyParsedQueue,
} }
// Set new configs // Set new configs
setupQueueConfigs(clusterResource, csContext.getConfiguration()); setupQueueConfigs(clusterResource, queueContext.getConfiguration());
updateQuotas(newlyParsedParentQueue.userLimit, updateQuotas(newlyParsedParentQueue.userLimit,
newlyParsedParentQueue.userLimitFactor, newlyParsedParentQueue.userLimitFactor,

View File

@ -32,12 +32,13 @@ public class QueueAllocationSettings {
private final Resource minimumAllocation; private final Resource minimumAllocation;
private Resource maximumAllocation; private Resource maximumAllocation;
public QueueAllocationSettings(CapacitySchedulerContext csContext) { public QueueAllocationSettings(Resource minimumAllocation) {
this.minimumAllocation = csContext.getMinimumResourceCapability(); this.minimumAllocation = minimumAllocation;
} }
void setupMaximumAllocation(CapacitySchedulerConfiguration csConf, String queuePath, void setupMaximumAllocation(CapacitySchedulerConfiguration configuration,
CSQueue parent, CapacitySchedulerContext csContext) { CapacitySchedulerConfiguration originalSchedulerConfiguration, String queuePath,
CSQueue parent) {
/* YARN-10869: When using AutoCreatedLeafQueues, the passed configuration /* YARN-10869: When using AutoCreatedLeafQueues, the passed configuration
* object is a cloned one containing only the template configs * object is a cloned one containing only the template configs
* (see ManagedParentQueue#getLeafQueueConfigs). To ensure that the actual * (see ManagedParentQueue#getLeafQueueConfigs). To ensure that the actual
@ -45,8 +46,8 @@ void setupMaximumAllocation(CapacitySchedulerConfiguration csConf, String queueP
* be used. * be used.
*/ */
Resource clusterMax = ResourceUtils Resource clusterMax = ResourceUtils
.fetchMaximumAllocationFromConfig(csContext.getConfiguration()); .fetchMaximumAllocationFromConfig(originalSchedulerConfiguration);
Resource queueMax = csConf.getQueueMaximumAllocation(queuePath); Resource queueMax = configuration.getQueueMaximumAllocation(queuePath);
maximumAllocation = Resources.clone( maximumAllocation = Resources.clone(
parent == null ? clusterMax : parent.getMaximumAllocation()); parent == null ? clusterMax : parent.getMaximumAllocation());
@ -59,8 +60,8 @@ void setupMaximumAllocation(CapacitySchedulerConfiguration csConf, String queueP
if (queueMax == Resources.none()) { if (queueMax == Resources.none()) {
// Handle backward compatibility // Handle backward compatibility
long queueMemory = csConf.getQueueMaximumAllocationMb(queuePath); long queueMemory = configuration.getQueueMaximumAllocationMb(queuePath);
int queueVcores = csConf.getQueueMaximumAllocationVcores(queuePath); int queueVcores = configuration.getQueueMaximumAllocationVcores(queuePath);
if (queueMemory != UNDEFINED) { if (queueMemory != UNDEFINED) {
maximumAllocation.setMemorySize(queueMemory); maximumAllocation.setMemorySize(queueMemory);
} }

View File

@ -31,7 +31,6 @@
public class QueueNodeLabelsSettings { public class QueueNodeLabelsSettings {
private final CSQueue parent; private final CSQueue parent;
private final String queuePath; private final String queuePath;
private final CapacitySchedulerContext csContext;
private Set<String> accessibleLabels; private Set<String> accessibleLabels;
private Set<String> configuredNodeLabels; private Set<String> configuredNodeLabels;
private String defaultLabelExpression; private String defaultLabelExpression;
@ -39,18 +38,18 @@ public class QueueNodeLabelsSettings {
public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration, public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration,
CSQueue parent, CSQueue parent,
String queuePath, String queuePath,
CapacitySchedulerContext csContext) throws IOException { ConfiguredNodeLabels configuredNodeLabels) throws IOException {
this.parent = parent; this.parent = parent;
this.queuePath = queuePath; this.queuePath = queuePath;
this.csContext = csContext; initializeNodeLabels(configuration, configuredNodeLabels);
initializeNodeLabels(configuration);
} }
private void initializeNodeLabels(CapacitySchedulerConfiguration configuration) private void initializeNodeLabels(CapacitySchedulerConfiguration configuration,
ConfiguredNodeLabels configuredNodeLabels)
throws IOException { throws IOException {
initializeAccessibleLabels(configuration); initializeAccessibleLabels(configuration);
initializeDefaultLabelExpression(configuration); initializeDefaultLabelExpression(configuration);
initializeConfiguredNodeLabels(); initializeConfiguredNodeLabels(configuration, configuredNodeLabels);
validateNodeLabels(); validateNodeLabels();
} }
@ -73,19 +72,17 @@ private void initializeDefaultLabelExpression(CapacitySchedulerConfiguration con
} }
} }
private void initializeConfiguredNodeLabels() { private void initializeConfiguredNodeLabels(CapacitySchedulerConfiguration configuration,
if (csContext.getCapacitySchedulerQueueManager() != null ConfiguredNodeLabels configuredNodeLabelsParam) {
&& csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() != null) { if (configuredNodeLabelsParam != null) {
if (queuePath.equals(ROOT)) { if (queuePath.equals(ROOT)) {
this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() this.configuredNodeLabels = configuredNodeLabelsParam.getAllConfiguredLabels();
.getConfiguredNodeLabels().getAllConfiguredLabels();
} else { } else {
this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() this.configuredNodeLabels = configuredNodeLabelsParam.getLabelsByQueue(queuePath);
.getConfiguredNodeLabels().getLabelsByQueue(queuePath);
} }
} else { } else {
// Fallback to suboptimal but correct logic // Fallback to suboptimal but correct logic
this.configuredNodeLabels = csContext.getConfiguration().getConfiguredNodeLabels(queuePath); this.configuredNodeLabels = configuration.getConfiguredNodeLabels(queuePath);
} }
} }

View File

@ -31,20 +31,17 @@
* *
*/ */
public class ReservationQueue extends AbstractAutoCreatedLeafQueue { public class ReservationQueue extends AbstractAutoCreatedLeafQueue {
private static final Logger LOG =
private static final Logger LOG = LoggerFactory LoggerFactory.getLogger(ReservationQueue.class);
.getLogger(ReservationQueue.class);
private PlanQueue parent; private PlanQueue parent;
public ReservationQueue(CapacitySchedulerContext cs, String queueName, public ReservationQueue(CapacitySchedulerQueueContext queueContext, String queueName,
PlanQueue parent) throws IOException { PlanQueue parent) throws IOException {
super(cs, queueName, parent, null); super(queueContext, queueName, parent, null);
super.setupQueueConfigs(cs.getClusterResource(), super.setupQueueConfigs(queueContext.getClusterResource(),
cs.getConfiguration()); queueContext.getConfiguration());
LOG.debug("Initialized ReservationQueue: name={}, fullname={}",
queueName, getQueuePath());
// the following parameters are common to all reservation in the plan // the following parameters are common to all reservation in the plan
updateQuotas(parent.getUserLimitForReservation(), updateQuotas(parent.getUserLimitForReservation(),
parent.getUserLimitFactor(), parent.getUserLimitFactor(),

View File

@ -58,7 +58,6 @@ public class UsersManager implements AbstractUsersManager {
private final AbstractLeafQueue lQueue; private final AbstractLeafQueue lQueue;
private final RMNodeLabelsManager labelManager; private final RMNodeLabelsManager labelManager;
private final ResourceCalculator resourceCalculator; private final ResourceCalculator resourceCalculator;
private final CapacitySchedulerContext scheduler;
private Map<String, User> users = new ConcurrentHashMap<>(); private Map<String, User> users = new ConcurrentHashMap<>();
private ResourceUsage totalResUsageForActiveUsers = new ResourceUsage(); private ResourceUsage totalResUsageForActiveUsers = new ResourceUsage();
@ -296,17 +295,13 @@ public void setWeight(float weight) {
* Leaf Queue Object * Leaf Queue Object
* @param labelManager * @param labelManager
* Label Manager instance * Label Manager instance
* @param scheduler
* Capacity Scheduler Context
* @param resourceCalculator * @param resourceCalculator
* rc * rc
*/ */
public UsersManager(QueueMetrics metrics, AbstractLeafQueue lQueue, public UsersManager(QueueMetrics metrics, AbstractLeafQueue lQueue,
RMNodeLabelsManager labelManager, CapacitySchedulerContext scheduler, RMNodeLabelsManager labelManager, ResourceCalculator resourceCalculator) {
ResourceCalculator resourceCalculator) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
this.lQueue = lQueue; this.lQueue = lQueue;
this.scheduler = scheduler;
this.labelManager = labelManager; this.labelManager = labelManager;
this.resourceCalculator = resourceCalculator; this.resourceCalculator = resourceCalculator;
this.qUsageRatios = new UsageRatios(); this.qUsageRatios = new UsageRatios();
@ -844,10 +839,8 @@ partitionResource, getUsageRatio(nodePartition),
/** /**
* Update new usage ratio. * Update new usage ratio.
* *
* @param partition * @param partition Node partition
* Node partition * @param clusterResource cluster resource
* @param clusterResource
* Cluster Resource
*/ */
public void updateUsageRatio(String partition, Resource clusterResource) { public void updateUsageRatio(String partition, Resource clusterResource) {
writeLock.lock(); writeLock.lock();
@ -1064,6 +1057,8 @@ private ResourceUsage getTotalResourceUsagePerUser(String userName) {
* Name of the user * Name of the user
* @param resource * @param resource
* Resource to increment/decrement * Resource to increment/decrement
* @param clusterResource
* Cluster resource (for testing purposes only)
* @param nodePartition * @param nodePartition
* Node label * Node label
* @param isAllocate * @param isAllocate
@ -1071,6 +1066,7 @@ private ResourceUsage getTotalResourceUsagePerUser(String userName) {
* @return user * @return user
*/ */
public User updateUserResourceUsage(String userName, Resource resource, public User updateUserResourceUsage(String userName, Resource resource,
Resource clusterResource,
String nodePartition, boolean isAllocate) { String nodePartition, boolean isAllocate) {
this.writeLock.lock(); this.writeLock.lock();
try { try {
@ -1086,7 +1082,7 @@ public User updateUserResourceUsage(String userName, Resource resource,
// Update usage ratios // Update usage ratios
Resource resourceByLabel = labelManager.getResourceByLabel(nodePartition, Resource resourceByLabel = labelManager.getResourceByLabel(nodePartition,
scheduler.getClusterResource()); clusterResource);
incQueueUsageRatio(nodePartition, user.updateUsageRatio( incQueueUsageRatio(nodePartition, user.updateUsageRatio(
resourceCalculator, resourceByLabel, nodePartition)); resourceCalculator, resourceByLabel, nodePartition));

View File

@ -80,7 +80,7 @@ private boolean checkHeadroom(ResourceLimits currentResourceLimits,
// require // require
Resource resourceCouldBeUnReserved = Resource resourceCouldBeUnReserved =
application.getAppAttemptResourceUsage().getReserved(nodePartition); application.getAppAttemptResourceUsage().getReserved(nodePartition);
if (!application.getCSLeafQueue().getReservationContinueLooking()) { if (!application.getCSLeafQueue().isReservationsContinueLooking()) {
// If we don't allow reservation continuous looking, // If we don't allow reservation continuous looking,
// we won't allow to unreserve before allocation. // we won't allow to unreserve before allocation.
resourceCouldBeUnReserved = Resources.none(); resourceCouldBeUnReserved = Resources.none();
@ -154,7 +154,7 @@ private ContainerAllocation preCheckForNodeCandidateSet(FiCaSchedulerNode node,
return ContainerAllocation.PRIORITY_SKIPPED; return ContainerAllocation.PRIORITY_SKIPPED;
} }
if (!application.getCSLeafQueue().getReservationContinueLooking()) { if (!application.getCSLeafQueue().isReservationsContinueLooking()) {
if (!shouldAllocOrReserveNewContainer(schedulerKey, required)) { if (!shouldAllocOrReserveNewContainer(schedulerKey, required)) {
LOG.debug("doesn't need containers based on reservation algo!"); LOG.debug("doesn't need containers based on reservation algo!");
ActivitiesLogger.APP.recordSkippedAppActivityWithoutAllocation( ActivitiesLogger.APP.recordSkippedAppActivityWithoutAllocation(
@ -551,7 +551,7 @@ private ContainerAllocation assignContainer(Resource clusterResource,
RMContainer unreservedContainer = null; RMContainer unreservedContainer = null;
boolean reservationsContinueLooking = boolean reservationsContinueLooking =
application.getCSLeafQueue().getReservationContinueLooking(); application.getCSLeafQueue().isReservationsContinueLooking();
// Check if we need to kill some containers to allocate this one // Check if we need to kill some containers to allocate this one
List<RMContainer> toKillContainers = null; List<RMContainer> toKillContainers = null;

View File

@ -70,7 +70,6 @@ public class GuaranteedOrZeroCapacityOverTimePolicy
implements AutoCreatedQueueManagementPolicy { implements AutoCreatedQueueManagementPolicy {
private static final int DEFAULT_QUEUE_PRINT_SIZE_LIMIT = 25; private static final int DEFAULT_QUEUE_PRINT_SIZE_LIMIT = 25;
private CapacitySchedulerContext scheduler;
private ManagedParentQueue managedParentQueue; private ManagedParentQueue managedParentQueue;
private static final Logger LOG = private static final Logger LOG =
@ -263,9 +262,9 @@ private class PendingApplicationComparator
@Override @Override
public int compare(FiCaSchedulerApp app1, FiCaSchedulerApp app2) { public int compare(FiCaSchedulerApp app1, FiCaSchedulerApp app2) {
RMApp rmApp1 = scheduler.getRMContext().getRMApps().get( RMApp rmApp1 = managedParentQueue.getQueueContext().getRMApp(
app1.getApplicationId()); app1.getApplicationId());
RMApp rmApp2 = scheduler.getRMContext().getRMApps().get( RMApp rmApp2 = managedParentQueue.getQueueContext().getRMApp(
app2.getApplicationId()); app2.getApplicationId());
if (rmApp1 != null && rmApp2 != null) { if (rmApp1 != null && rmApp2 != null) {
return Long.compare(rmApp1.getSubmitTime(), rmApp2.getSubmitTime()); return Long.compare(rmApp1.getSubmitTime(), rmApp2.getSubmitTime());
@ -283,10 +282,7 @@ public int compare(FiCaSchedulerApp app1, FiCaSchedulerApp app2) {
new PendingApplicationComparator(); new PendingApplicationComparator();
@Override @Override
public void init(final CapacitySchedulerContext schedulerContext, public void init(final ParentQueue parentQueue) throws IOException {
final ParentQueue parentQueue) throws IOException {
this.scheduler = schedulerContext;
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
readLock = lock.readLock(); readLock = lock.readLock();
writeLock = lock.writeLock(); writeLock = lock.writeLock();
@ -372,7 +368,7 @@ public List<QueueManagementChange> computeQueueManagementChanges()
//Populate new entitlements //Populate new entitlements
return leafQueueEntitlements.mapToQueueManagementChanges((leafQueueName, capacities) -> { return leafQueueEntitlements.mapToQueueManagementChanges((leafQueueName, capacities) -> {
AutoCreatedLeafQueue leafQueue = AutoCreatedLeafQueue leafQueue =
(AutoCreatedLeafQueue) scheduler.getCapacitySchedulerQueueManager() (AutoCreatedLeafQueue) managedParentQueue.getQueueContext().getQueueManager()
.getQueue(leafQueueName); .getQueue(leafQueueName);
AutoCreatedLeafQueueConfig newTemplate = buildTemplate(capacities); AutoCreatedLeafQueueConfig newTemplate = buildTemplate(capacities);
return new QueueManagementChange.UpdateQueue(leafQueue, newTemplate); return new QueueManagementChange.UpdateQueue(leafQueue, newTemplate);
@ -651,7 +647,8 @@ public void commitQueueManagementChanges(
.mergeCapacities(updatedQueueTemplate.getQueueCapacities()); .mergeCapacities(updatedQueueTemplate.getQueueCapacities());
leafQueue.getQueueResourceQuotas() leafQueue.getQueueResourceQuotas()
.setConfiguredMinResource(Resources.multiply( .setConfiguredMinResource(Resources.multiply(
this.scheduler.getClusterResource(), updatedQueueTemplate managedParentQueue.getQueueContext().getClusterResource(),
updatedQueueTemplate
.getQueueCapacities().getCapacity(nodeLabel))); .getQueueCapacities().getCapacity(nodeLabel)));
deactivate(leafQueue, nodeLabel); deactivate(leafQueue, nodeLabel);
} }
@ -693,8 +690,7 @@ public boolean hasPendingApps(final AutoCreatedLeafQueue leafQueue) {
} }
@Override @Override
public void reinitialize(CapacitySchedulerContext schedulerContext, public void reinitialize(final ParentQueue parentQueue) throws IOException {
final ParentQueue parentQueue) throws IOException {
if (!(parentQueue instanceof ManagedParentQueue)) { if (!(parentQueue instanceof ManagedParentQueue)) {
throw new IllegalStateException( throw new IllegalStateException(
"Expected instance of type " + ManagedParentQueue.class + " found " "Expected instance of type " + ManagedParentQueue.class + " found "

View File

@ -388,7 +388,7 @@ public void testQueueSubmitWithACLsEnabledWithQueueMappingForAutoCreatedQueue()
MockRM newMockRM = new MockRM(csConf); MockRM newMockRM = new MockRM(csConf);
CapacityScheduler cs = CapacityScheduler cs =
((CapacityScheduler) newMockRM.getResourceScheduler()); ((CapacityScheduler) newMockRM.getResourceScheduler());
ManagedParentQueue managedParentQueue = new ManagedParentQueue(cs, ManagedParentQueue managedParentQueue = new ManagedParentQueue(cs.getQueueContext(),
"managedparent", cs.getQueue("root"), null); "managedparent", cs.getQueue("root"), null);
cs.getCapacitySchedulerQueueManager().addQueue("managedparent", cs.getCapacitySchedulerQueueManager().addQueue("managedparent",
managedParentQueue); managedParentQueue);

View File

@ -215,7 +215,7 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue()
CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
ManagedParentQueue parentQueue = (ManagedParentQueue) cs.getQueue(QUEUED); ManagedParentQueue parentQueue = (ManagedParentQueue) cs.getQueue(QUEUED);
AutoCreatedLeafQueue d1 = new AutoCreatedLeafQueue(cs, "d1", parentQueue); AutoCreatedLeafQueue d1 = new AutoCreatedLeafQueue(cs.getQueueContext(), "d1", parentQueue);
cs.addQueue(d1); cs.addQueue(d1);
/** /**
@ -240,7 +240,7 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue()
* d1 will occupy all entire resource * d1 will occupy all entire resource
* of Managed Parent queue. * of Managed Parent queue.
*/ */
AutoCreatedLeafQueue d2 = new AutoCreatedLeafQueue(cs, "d2", parentQueue); AutoCreatedLeafQueue d2 = new AutoCreatedLeafQueue(cs.getQueueContext(), "d2", parentQueue);
cs.addQueue(d2); cs.addQueue(d2);
cs.getRootQueue().updateClusterResource(cs.getClusterResource(), cs.getRootQueue().updateClusterResource(cs.getClusterResource(),

View File

@ -107,19 +107,11 @@ public void setUp() throws IOException {
rmContext = TestUtils.getMockRMContext(); rmContext = TestUtils.getMockRMContext();
Resource clusterResource = Resources.createResource(10 * 16 * GB, 10 * 32); Resource clusterResource = Resources.createResource(10 * 16 * GB, 10 * 32);
CapacitySchedulerContext csContext = mock(CapacitySchedulerContext.class); CapacitySchedulerContext csContext = createCSContext(csConf, resourceCalculator,
when(csContext.getConfiguration()).thenReturn(csConf); Resources.createResource(GB, 1), Resources.createResource(16*GB, 32),
when(csContext.getConf()).thenReturn(conf); clusterResource);
when(csContext.getMinimumResourceCapability()).
thenReturn(Resources.createResource(GB, 1));
when(csContext.getMaximumResourceCapability()).
thenReturn(Resources.createResource(16*GB, 32));
when(csContext.getClusterResource()).
thenReturn(clusterResource);
when(csContext.getResourceCalculator()).
thenReturn(resourceCalculator);
when(csContext.getRMContext()).thenReturn(rmContext); when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager()); CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
RMContainerTokenSecretManager containerTokenSecretManager = RMContainerTokenSecretManager containerTokenSecretManager =
new RMContainerTokenSecretManager(conf); new RMContainerTokenSecretManager(conf);
@ -129,13 +121,13 @@ public void setUp() throws IOException {
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
root = CapacitySchedulerQueueManager root = CapacitySchedulerQueueManager
.parseQueue(csContext, csConf, null, "root", .parseQueue(queueContext, csConf, null, "root",
queues, queues, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
root.updateClusterResource(clusterResource, root.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
queue = spy(new LeafQueue(csContext, A, root, null)); queue = spy(new LeafQueue(queueContext, A, root, null));
QueueResourceQuotas queueResourceQuotas = ((LeafQueue) queues.get(A)) QueueResourceQuotas queueResourceQuotas = ((LeafQueue) queues.get(A))
.getQueueResourceQuotas(); .getQueueResourceQuotas();
doReturn(queueResourceQuotas).when(queue).getQueueResourceQuotas(); doReturn(queueResourceQuotas).when(queue).getQueueResourceQuotas();
@ -278,28 +270,21 @@ public void testLimitsComputation() throws Exception {
CapacitySchedulerConfiguration csConf = CapacitySchedulerConfiguration csConf =
new CapacitySchedulerConfiguration(); new CapacitySchedulerConfiguration();
setupQueueConfiguration(csConf); setupQueueConfiguration(csConf);
YarnConfiguration conf = new YarnConfiguration();
CapacitySchedulerContext csContext = mock(CapacitySchedulerContext.class);
when(csContext.getConfiguration()).thenReturn(csConf);
when(csContext.getConf()).thenReturn(conf);
when(csContext.getMinimumResourceCapability()).
thenReturn(Resources.createResource(GB, 1));
when(csContext.getMaximumResourceCapability()).
thenReturn(Resources.createResource(16*GB, 16));
when(csContext.getResourceCalculator()).thenReturn(resourceCalculator);
when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
// Say cluster has 100 nodes of 16G each // Say cluster has 100 nodes of 16G each
Resource clusterResource = Resource clusterResource =
Resources.createResource(100 * 16 * GB, 100 * 16); Resources.createResource(100 * 16 * GB, 100 * 16);
when(csContext.getClusterResource()).thenReturn(clusterResource);
CapacitySchedulerContext csContext = createCSContext(csConf, resourceCalculator, Resources.createResource(GB, 1),
Resources.createResource(16*GB, 16), clusterResource);
CapacitySchedulerQueueManager queueManager = csContext.getCapacitySchedulerQueueManager();
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
"root", queues, queues, TestUtils.spyHook); "root", queues, queues, TestUtils.spyHook);
queueManager.setRootQueue(root);
root.updateClusterResource(clusterResource, root.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
@ -367,12 +352,14 @@ public void testLimitsComputation() throws Exception {
// Change the per-queue max AM resources percentage. // Change the per-queue max AM resources percentage.
csConf.setFloat(PREFIX + queue.getQueuePath() csConf.setFloat(PREFIX + queue.getQueuePath()
+ ".maximum-am-resource-percent", 0.5f); + ".maximum-am-resource-percent", 0.5f);
queueContext.reinitialize();
// Re-create queues to get new configs. // Re-create queues to get new configs.
queues = new CSQueueStore(); queues = new CSQueueStore();
root = CapacitySchedulerQueueManager.parseQueue( root = CapacitySchedulerQueueManager.parseQueue(
csContext, csConf, null, "root", queueContext, csConf, null, "root",
queues, queues, TestUtils.spyHook); queues, queues, TestUtils.spyHook);
clusterResource = Resources.createResource(100 * 16 * GB); clusterResource = Resources.createResource(100 * 16 * GB);
queueManager.setRootQueue(root);
root.updateClusterResource(clusterResource, new ResourceLimits( root.updateClusterResource(clusterResource, new ResourceLimits(
clusterResource)); clusterResource));
@ -391,10 +378,11 @@ public void testLimitsComputation() throws Exception {
// Change the per-queue max applications. // Change the per-queue max applications.
csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications", csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications",
9999); 9999);
queueContext.reinitialize();
// Re-create queues to get new configs. // Re-create queues to get new configs.
queues = new CSQueueStore(); queues = new CSQueueStore();
root = CapacitySchedulerQueueManager.parseQueue( root = CapacitySchedulerQueueManager.parseQueue(
csContext, csConf, null, "root", queueContext, csConf, null, "root",
queues, queues, TestUtils.spyHook); queues, queues, TestUtils.spyHook);
root.updateClusterResource(clusterResource, new ResourceLimits( root.updateClusterResource(clusterResource, new ResourceLimits(
clusterResource)); clusterResource));
@ -587,26 +575,19 @@ public void testHeadroom() throws Exception {
new CapacitySchedulerConfiguration(); new CapacitySchedulerConfiguration();
csConf.setUserLimit(CapacitySchedulerConfiguration.ROOT + "." + A, 25); csConf.setUserLimit(CapacitySchedulerConfiguration.ROOT + "." + A, 25);
setupQueueConfiguration(csConf); setupQueueConfiguration(csConf);
YarnConfiguration conf = new YarnConfiguration();
CapacitySchedulerContext csContext = mock(CapacitySchedulerContext.class);
when(csContext.getConfiguration()).thenReturn(csConf);
when(csContext.getConf()).thenReturn(conf);
when(csContext.getMinimumResourceCapability()).
thenReturn(Resources.createResource(GB));
when(csContext.getMaximumResourceCapability()).
thenReturn(Resources.createResource(16*GB));
when(csContext.getResourceCalculator()).thenReturn(resourceCalculator);
when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
// Say cluster has 100 nodes of 16G each // Say cluster has 100 nodes of 16G each
Resource clusterResource = Resources.createResource(100 * 16 * GB); Resource clusterResource = Resources.createResource(100 * 16 * GB);
when(csContext.getClusterResource()).thenReturn(clusterResource);
CapacitySchedulerContext csContext = createCSContext(csConf, resourceCalculator, Resources.createResource(GB),
Resources.createResource(16*GB), clusterResource);
CapacitySchedulerQueueManager queueManager = csContext.getCapacitySchedulerQueueManager();
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(csContext, CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(queueContext,
csConf, null, "root", queues, queues, TestUtils.spyHook); csConf, null, "root", queues, queues, TestUtils.spyHook);
queueManager.setRootQueue(rootQueue);
rootQueue.updateClusterResource(clusterResource, rootQueue.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
@ -952,27 +933,17 @@ public void testAMResourceLimitWithDRCAndFullParent() throws Exception {
setupQueueConfiguration(csConf); setupQueueConfiguration(csConf);
csConf.setFloat(CapacitySchedulerConfiguration. csConf.setFloat(CapacitySchedulerConfiguration.
MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT, 0.3f); MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT, 0.3f);
YarnConfiguration conf = new YarnConfiguration();
CapacitySchedulerContext csContext = mock(CapacitySchedulerContext.class);
when(csContext.getConfiguration()).thenReturn(csConf);
when(csContext.getConf()).thenReturn(conf);
when(csContext.getMinimumResourceCapability()).
thenReturn(Resources.createResource(GB));
when(csContext.getMaximumResourceCapability()).
thenReturn(Resources.createResource(16*GB));
when(csContext.getResourceCalculator()).
thenReturn(new DominantResourceCalculator());
when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
// Total cluster resources. // Total cluster resources.
Resource clusterResource = Resources.createResource(100 * GB, 1000); Resource clusterResource = Resources.createResource(100 * GB, 1000);
when(csContext.getClusterResource()).thenReturn(clusterResource);
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(
createCSContext(csConf, new DominantResourceCalculator(), Resources.createResource(GB),
Resources.createResource(16*GB), clusterResource));
// Set up queue hierarchy. // Set up queue hierarchy.
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(csContext, CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(queueContext,
csConf, null, "root", queues, queues, TestUtils.spyHook); csConf, null, "root", queues, queues, TestUtils.spyHook);
rootQueue.updateClusterResource(clusterResource, rootQueue.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
@ -1015,4 +986,32 @@ public void testAMResourceLimitWithDRCAndFullParent() throws Exception {
+ amLimit.getVirtualCores(), + amLimit.getVirtualCores(),
amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores()); amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores());
} }
private CapacitySchedulerContext createCSContext(CapacitySchedulerConfiguration csConf,
ResourceCalculator rc, Resource minResource, Resource maxResource, Resource clusterResource) {
YarnConfiguration conf = new YarnConfiguration();
CapacitySchedulerContext csContext = mock(CapacitySchedulerContext.class);
when(csContext.getConfiguration()).thenReturn(csConf);
when(csContext.getConf()).thenReturn(conf);
when(csContext.getMinimumResourceCapability()).
thenReturn(minResource);
when(csContext.getMaximumResourceCapability()).
thenReturn(maxResource);
when(csContext.getResourceCalculator()).
thenReturn(rc);
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(conf,
rmContext.getNodeLabelManager(), null);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
// Total cluster resources.
when(csContext.getClusterResource()).thenReturn(clusterResource);
return csContext;
}
} }

View File

@ -777,6 +777,12 @@ public void testHeadroom() throws Exception {
when(spyRMContext.getNodeLabelManager()).thenReturn(mgr); when(spyRMContext.getNodeLabelManager()).thenReturn(mgr);
when(csContext.getRMContext()).thenReturn(spyRMContext); when(csContext.getRMContext()).thenReturn(spyRMContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager()); when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
CapacitySchedulerQueueManager queueManager =
new CapacitySchedulerQueueManager(csConf, mgr, null);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
// Setup nodelabels
queueManager.reinitConfiguredNodeLabels(csConf);
mgr.activateNode(NodeId.newInstance("h0", 0), mgr.activateNode(NodeId.newInstance("h0", 0),
Resource.newInstance(160 * GB, 16)); // default Label Resource.newInstance(160 * GB, 16)); // default Label
@ -789,16 +795,15 @@ public void testHeadroom() throws Exception {
Resource clusterResource = Resources.createResource(160 * GB); Resource clusterResource = Resources.createResource(160 * GB);
when(csContext.getClusterResource()).thenReturn(clusterResource); when(csContext.getClusterResource()).thenReturn(clusterResource);
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(csContext);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(csContext, CSQueue rootQueue = CapacitySchedulerQueueManager.parseQueue(queueContext,
csConf, null, "root", queues, queues, TestUtils.spyHook); csConf, null, "root", queues, queues, TestUtils.spyHook);
queueManager.setRootQueue(rootQueue);
rootQueue.updateClusterResource(clusterResource, rootQueue.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
ResourceUsage queueResUsage = rootQueue.getQueueResourceUsage();
when(csContext.getClusterResourceUsage())
.thenReturn(queueResUsage);
// Manipulate queue 'a' // Manipulate queue 'a'
LeafQueue queue = TestLeafQueue.stubLeafQueue((LeafQueue) queues.get("b2")); LeafQueue queue = TestLeafQueue.stubLeafQueue((LeafQueue) queues.get("b2"));
queue.updateClusterResource(clusterResource, queue.updateClusterResource(clusterResource,

View File

@ -92,9 +92,13 @@ public void setup() throws IOException {
when(preemptionManager.getKillableResource(any(), anyString())) when(preemptionManager.getKillableResource(any(), anyString()))
.thenReturn(Resource.newInstance(0, 0)); .thenReturn(Resource.newInstance(0, 0));
when(scheduler.getPreemptionManager()).thenReturn(preemptionManager); when(scheduler.getPreemptionManager()).thenReturn(preemptionManager);
when(scheduler.getActivitiesManager()).thenReturn(activitiesManager);
queueManager = new CapacitySchedulerQueueManager(csConfig, labelManager, queueManager = new CapacitySchedulerQueueManager(csConfig, labelManager,
appPriorityACLManager); appPriorityACLManager);
queueManager.setCapacitySchedulerContext(scheduler); queueManager.setCapacitySchedulerContext(scheduler);
when(scheduler.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
CapacitySchedulerQueueContext queueContext = new CapacitySchedulerQueueContext(scheduler);
when(scheduler.getQueueContext()).thenReturn(queueContext);
queueManager.initializeQueues(csConfig); queueManager.initializeQueues(csConfig);
} }

View File

@ -39,6 +39,7 @@ public class TestCSQueueStore {
private CSQueue root; private CSQueue root;
private CapacitySchedulerContext csContext; private CapacitySchedulerContext csContext;
private CapacitySchedulerQueueContext queueContext;
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
@ -62,22 +63,26 @@ public void setUp() throws IOException {
when(csContext.getResourceCalculator()). when(csContext.getResourceCalculator()).
thenReturn(resourceCalculator); thenReturn(resourceCalculator);
when(csContext.getRMContext()).thenReturn(rmContext); when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(
new CapacitySchedulerQueueManager(csConf, null, null));
queueContext = new CapacitySchedulerQueueContext(csContext);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
root = CapacitySchedulerQueueManager root = CapacitySchedulerQueueManager
.parseQueue(csContext, csConf, null, "root", .parseQueue(queueContext, csConf, null, "root",
queues, queues, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
public CSQueue createLeafQueue(String name, CSQueue parent) public CSQueue createLeafQueue(String name, CSQueue parent)
throws IOException { throws IOException {
return new LeafQueue(csContext, name, parent, null); return new LeafQueue(queueContext, name, parent, null);
} }
public CSQueue createParentQueue(String name, CSQueue parent) public CSQueue createParentQueue(String name, CSQueue parent)
throws IOException { throws IOException {
return new ParentQueue(csContext, name, parent, null); return new ParentQueue(queueContext, name, parent, null);
} }
/** /**

View File

@ -680,7 +680,7 @@ public void testAutoCreationFailsWhenParentCapacityExceeded()
// Test add one auto created queue dynamically and manually modify // Test add one auto created queue dynamically and manually modify
// capacity // capacity
ManagedParentQueue parentQueue = (ManagedParentQueue) newCS.getQueue("c"); ManagedParentQueue parentQueue = (ManagedParentQueue) newCS.getQueue("c");
AutoCreatedLeafQueue c1 = new AutoCreatedLeafQueue(newCS, "c1", AutoCreatedLeafQueue c1 = new AutoCreatedLeafQueue(newCS.getQueueContext(), "c1",
parentQueue); parentQueue);
newCS.addQueue(c1); newCS.addQueue(c1);
c1.setCapacity(0.5f); c1.setCapacity(0.5f);
@ -689,13 +689,13 @@ public void testAutoCreationFailsWhenParentCapacityExceeded()
setEntitlement(c1, new QueueEntitlement(0.5f, 1f)); setEntitlement(c1, new QueueEntitlement(0.5f, 1f));
AutoCreatedLeafQueue c2 = new AutoCreatedLeafQueue(newCS, "c2", AutoCreatedLeafQueue c2 = new AutoCreatedLeafQueue(newCS.getQueueContext(), "c2",
parentQueue); parentQueue);
newCS.addQueue(c2); newCS.addQueue(c2);
setEntitlement(c2, new QueueEntitlement(0.5f, 1f)); setEntitlement(c2, new QueueEntitlement(0.5f, 1f));
try { try {
AutoCreatedLeafQueue c3 = new AutoCreatedLeafQueue(newCS, "c3", AutoCreatedLeafQueue c3 = new AutoCreatedLeafQueue(newCS.getQueueContext(), "c3",
parentQueue); parentQueue);
newCS.addQueue(c3); newCS.addQueue(c3);
fail("Expected exception for auto queue creation failure"); fail("Expected exception for auto queue creation failure");

View File

@ -86,14 +86,14 @@ public void testRefreshQueuesWithReservations() throws Exception {
// Test add one reservation dynamically and manually modify capacity // Test add one reservation dynamically and manually modify capacity
ReservationQueue a1 = ReservationQueue a1 =
new ReservationQueue(cs, "a1", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a1", (PlanQueue) cs.getQueue("a"));
cs.addQueue(a1); cs.addQueue(a1);
a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f)); a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f));
// Test add another reservation queue and use setEntitlement to modify // Test add another reservation queue and use setEntitlement to modify
// capacity // capacity
ReservationQueue a2 = ReservationQueue a2 =
new ReservationQueue(cs, "a2", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a2", (PlanQueue) cs.getQueue("a"));
cs.addQueue(a2); cs.addQueue(a2);
cs.setEntitlement("a2", new QueueEntitlement(A2_CAPACITY / 100, 1.0f)); cs.setEntitlement("a2", new QueueEntitlement(A2_CAPACITY / 100, 1.0f));
@ -116,7 +116,7 @@ public void testAddQueueFailCases() throws Exception {
try { try {
// Test invalid addition (adding non-zero size queue) // Test invalid addition (adding non-zero size queue)
ReservationQueue a1 = ReservationQueue a1 =
new ReservationQueue(cs, "a1", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a1", (PlanQueue) cs.getQueue("a"));
a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f)); a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f));
cs.addQueue(a1); cs.addQueue(a1);
fail(); fail();
@ -126,7 +126,7 @@ public void testAddQueueFailCases() throws Exception {
// Test add one reservation dynamically and manually modify capacity // Test add one reservation dynamically and manually modify capacity
ReservationQueue a1 = ReservationQueue a1 =
new ReservationQueue(cs, "a1", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a1", (PlanQueue) cs.getQueue("a"));
cs.addQueue(a1); cs.addQueue(a1);
//set default queue capacity to zero //set default queue capacity to zero
((ReservationQueue) cs ((ReservationQueue) cs
@ -138,7 +138,7 @@ public void testAddQueueFailCases() throws Exception {
// Test add another reservation queue and use setEntitlement to modify // Test add another reservation queue and use setEntitlement to modify
// capacity // capacity
ReservationQueue a2 = ReservationQueue a2 =
new ReservationQueue(cs, "a2", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a2", (PlanQueue) cs.getQueue("a"));
cs.addQueue(a2); cs.addQueue(a2);
@ -165,7 +165,7 @@ public void testRemoveQueue() throws Exception {
// Test add one reservation dynamically and manually modify capacity // Test add one reservation dynamically and manually modify capacity
ReservationQueue a1 = ReservationQueue a1 =
new ReservationQueue(cs, "a1", (PlanQueue) cs.getQueue("a")); new ReservationQueue(cs.getQueueContext(), "a1", (PlanQueue) cs.getQueue("a"));
cs.addQueue(a1); cs.addQueue(a1);
a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f)); a1.setEntitlement(new QueueEntitlement(A1_CAPACITY / 100, 1f));
@ -249,7 +249,7 @@ public void testMoveAppToPlanQueue() throws Exception {
// create the default reservation queue // create the default reservation queue
String defQName = "a" + ReservationConstants.DEFAULT_QUEUE_SUFFIX; String defQName = "a" + ReservationConstants.DEFAULT_QUEUE_SUFFIX;
ReservationQueue defQ = ReservationQueue defQ =
new ReservationQueue(scheduler, defQName, new ReservationQueue(scheduler.getQueueContext(), defQName,
(PlanQueue) scheduler.getQueue("a")); (PlanQueue) scheduler.getQueue("a"));
scheduler.addQueue(defQ); scheduler.addQueue(defQ);
defQ.setEntitlement(new QueueEntitlement(1f, 1f)); defQ.setEntitlement(new QueueEntitlement(1f, 1f));

View File

@ -177,7 +177,7 @@ private void testUserLimitThroughputWithNumberOfResourceTypes(
LeafQueue qb = (LeafQueue)cs.getQueue(queueName); LeafQueue qb = (LeafQueue)cs.getQueue(queueName);
// For now make user limit large so we can activate all applications // For now make user limit large so we can activate all applications
qb.setUserLimitFactor((float)100.0); qb.setUserLimitFactor((float)100.0);
qb.setupConfigurableCapacities(); qb.setupConfigurableCapacities(cs.getConfiguration());
lqs[i] = qb; lqs[i] = qb;
} }

View File

@ -74,6 +74,7 @@ public class TestChildQueueOrder {
YarnConfiguration conf; YarnConfiguration conf;
CapacitySchedulerConfiguration csConf; CapacitySchedulerConfiguration csConf;
CapacitySchedulerContext csContext; CapacitySchedulerContext csContext;
CapacitySchedulerQueueContext queueContext;
final static int GB = 1024; final static int GB = 1024;
final static String DEFAULT_RACK = "/default"; final static String DEFAULT_RACK = "/default";
@ -100,6 +101,10 @@ public void setUp() throws Exception {
thenReturn(resourceComparator); thenReturn(resourceComparator);
when(csContext.getRMContext()).thenReturn(rmContext); when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager()); when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(
new CapacitySchedulerQueueManager(csConf, rmContext.getNodeLabelManager(), null));
queueContext = new CapacitySchedulerQueueContext(csContext);
} }
private FiCaSchedulerApp getMockApplication(int appId, String user) { private FiCaSchedulerApp getMockApplication(int appId, String user) {
@ -219,9 +224,10 @@ private void setupSortedQueues(CapacitySchedulerConfiguration conf) {
public void testSortedQueues() throws Exception { public void testSortedQueues() throws Exception {
// Setup queue configs // Setup queue configs
setupSortedQueues(csConf); setupSortedQueues(csConf);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);

View File

@ -143,6 +143,7 @@ public class TestLeafQueue {
CapacityScheduler cs; CapacityScheduler cs;
CapacitySchedulerConfiguration csConf; CapacitySchedulerConfiguration csConf;
CapacitySchedulerContext csContext; CapacitySchedulerContext csContext;
CapacitySchedulerQueueContext queueContext;
private RMApp rmApp; private RMApp rmApp;
CSQueue root; CSQueue root;
@ -203,6 +204,7 @@ private void setUpInternal(ResourceCalculator rC, boolean withNodeLabels)
csConf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true); csConf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true);
csConf.setBoolean(CapacitySchedulerConfiguration.RESERVE_CONT_LOOK_ALL_NODES, csConf.setBoolean(CapacitySchedulerConfiguration.RESERVE_CONT_LOOK_ALL_NODES,
false); false);
csConf.setResourceComparator(rC.getClass());
final String newRoot = "root" + System.currentTimeMillis(); final String newRoot = "root" + System.currentTimeMillis();
setupQueueConfiguration(csConf, newRoot, withNodeLabels); setupQueueConfiguration(csConf, newRoot, withNodeLabels);
YarnConfiguration conf = new YarnConfiguration(); YarnConfiguration conf = new YarnConfiguration();
@ -228,12 +230,20 @@ private void setUpInternal(ResourceCalculator rC, boolean withNodeLabels)
containerTokenSecretManager.rollMasterKey(); containerTokenSecretManager.rollMasterKey();
when(csContext.getContainerTokenSecretManager()).thenReturn( when(csContext.getContainerTokenSecretManager()).thenReturn(
containerTokenSecretManager); containerTokenSecretManager);
CapacitySchedulerQueueManager queueManager =
new CapacitySchedulerQueueManager(csConf, null, null);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
queueManager.reinitConfiguredNodeLabels(csConf);
queueContext = new CapacitySchedulerQueueContext(csContext);
root = root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
ROOT, ROOT,
queues, queues, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
queueManager.setRootQueue(root);
root.updateClusterResource(Resources.createResource(100 * 16 * GB, 100 * 32), root.updateClusterResource(Resources.createResource(100 * 16 * GB, 100 * 32),
new ResourceLimits(Resources.createResource(100 * 16 * GB, 100 * 32))); new ResourceLimits(Resources.createResource(100 * 16 * GB, 100 * 32)));
@ -242,8 +252,8 @@ private void setUpInternal(ResourceCalculator rC, boolean withNodeLabels)
.thenReturn(queueResUsage); .thenReturn(queueResUsage);
cs.setRMContext(spyRMContext); cs.setRMContext(spyRMContext);
cs.init(csConf);
cs.setResourceCalculator(rC); cs.setResourceCalculator(rC);
cs.init(csConf);
when(spyRMContext.getScheduler()).thenReturn(cs); when(spyRMContext.getScheduler()).thenReturn(cs);
when(spyRMContext.getYarnConfiguration()) when(spyRMContext.getYarnConfiguration())
@ -1087,11 +1097,12 @@ public void testUserLimitCache() throws Exception {
csConf.setCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, 100); csConf.setCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, 100);
csConf.setMaximumCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, csConf.setMaximumCapacity(CapacitySchedulerConfiguration.ROOT + "." + A,
100); 100);
queueContext.reinitialize();
// reinitialize queues // reinitialize queues
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CSQueue newRoot =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, CapacitySchedulerConfiguration.ROOT,
newQueues, queues, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -1305,11 +1316,12 @@ public void testUserLimitCacheActiveUsersChanged() throws Exception {
csConf.setCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, 100); csConf.setCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, 100);
csConf.setMaximumCapacity(CapacitySchedulerConfiguration.ROOT + "." + A, csConf.setMaximumCapacity(CapacitySchedulerConfiguration.ROOT + "." + A,
100); 100);
queueContext.reinitialize();
// reinitialize queues // reinitialize queues
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CSQueue newRoot =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, CapacitySchedulerConfiguration.ROOT,
newQueues, queues, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -1920,6 +1932,7 @@ public void testUserSpecificUserLimits() throws Exception {
+ CapacitySchedulerConfiguration.USER_WEIGHT, + CapacitySchedulerConfiguration.USER_WEIGHT,
0.7f); 0.7f);
csConf.reinitializeConfigurationProperties(); csConf.reinitializeConfigurationProperties();
queueContext.reinitialize();
when(csContext.getClusterResource()) when(csContext.getClusterResource())
.thenReturn(Resources.createResource(16 * GB, 32)); .thenReturn(Resources.createResource(16 * GB, 32));
@ -3216,10 +3229,12 @@ public void testRackLocalityDelayScheduling() throws Exception {
csConf.setInt(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, 2); csConf.setInt(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, 2);
csConf.setInt( csConf.setInt(
CapacitySchedulerConfiguration.RACK_LOCALITY_ADDITIONAL_DELAY, 1); CapacitySchedulerConfiguration.RACK_LOCALITY_ADDITIONAL_DELAY, 1);
queueContext.reinitialize();
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(csContext, CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(queueContext,
csConf, null, ROOT, newQueues, queues, csConf, null, ROOT, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
csContext.getCapacitySchedulerQueueManager().setRootQueue(newRoot);
root.reinitialize(newRoot, cs.getClusterResource()); root.reinitialize(newRoot, cs.getClusterResource());
// Manipulate queue 'b' // Manipulate queue 'b'
@ -3652,9 +3667,10 @@ public void testActivateApplicationAfterQueueRefresh() throws Exception {
CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT, CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT,
CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_APPLICATIONMASTERS_RESOURCE_PERCENT CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_APPLICATIONMASTERS_RESOURCE_PERCENT
* 2); * 2);
queueContext.reinitialize();
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CSQueue newRoot =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
ROOT, ROOT,
newQueues, queues, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -3683,12 +3699,14 @@ public void testLocalityDelaysAfterQueueRefresh() throws Exception {
csConf.setInt(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, 60); csConf.setInt(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, 60);
csConf.setInt( csConf.setInt(
CapacitySchedulerConfiguration.RACK_LOCALITY_ADDITIONAL_DELAY, 600); CapacitySchedulerConfiguration.RACK_LOCALITY_ADDITIONAL_DELAY, 600);
queueContext.reinitialize();
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CSQueue newRoot =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
ROOT, ROOT,
newQueues, queues, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
csContext.getCapacitySchedulerQueueManager().setRootQueue(newRoot);
root.reinitialize(newRoot, cs.getClusterResource()); root.reinitialize(newRoot, cs.getClusterResource());
// after reinitialization // after reinitialization
@ -4043,8 +4061,14 @@ public void testMaxAMResourcePerQueuePercentAfterQueueRefresh()
CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT, CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT,
0.1f); 0.1f);
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(csConf,
rmContext.getNodeLabelManager(), null);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
CapacitySchedulerQueueContext newQueueContext = new CapacitySchedulerQueueContext(csContext);
CSQueue root; CSQueue root;
root = CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, root = CapacitySchedulerQueueManager.parseQueue(newQueueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, TestUtils.spyHook); CapacitySchedulerConfiguration.ROOT, queues, queues, TestUtils.spyHook);
root.updateClusterResource(clusterResource, root.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
@ -4060,9 +4084,10 @@ public void testMaxAMResourcePerQueuePercentAfterQueueRefresh()
csConf.setFloat( csConf.setFloat(
CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT, CapacitySchedulerConfiguration.MAXIMUM_APPLICATION_MASTERS_RESOURCE_PERCENT,
0.2f); 0.2f);
newQueueContext.reinitialize();
clusterResource = Resources.createResource(100 * 20 * GB, 100 * 32); clusterResource = Resources.createResource(100 * 20 * GB, 100 * 32);
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(csContext, CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(newQueueContext,
csConf, null, CapacitySchedulerConfiguration.ROOT, newQueues, queues, csConf, null, CapacitySchedulerConfiguration.ROOT, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
root.reinitialize(newRoot, clusterResource); root.reinitialize(newRoot, clusterResource);
@ -5112,15 +5137,15 @@ public void testSetupQueueConfigsWithSpecifiedConfiguration()
assertEquals(0, conf.size()); assertEquals(0, conf.size());
conf.setNodeLocalityDelay(60); conf.setNodeLocalityDelay(60);
conf.setCapacity(ROOT + DOT + leafQueueName, 10); csConf.setCapacity(ROOT + DOT + leafQueueName, 10);
conf.setMaximumCapacity(ROOT + DOT + leafQueueName, 100); csConf.setMaximumCapacity(ROOT + DOT + leafQueueName, 100);
conf.setUserLimitFactor(ROOT + DOT +leafQueueName, 0.1f); csConf.setUserLimitFactor(ROOT + DOT +leafQueueName, 0.1f);
csConf.setNodeLocalityDelay(30); csConf.setNodeLocalityDelay(30);
csConf.setGlobalMaximumApplicationsPerQueue(20); csConf.setGlobalMaximumApplicationsPerQueue(20);
queueContext.reinitialize();
LeafQueue leafQueue = new LeafQueue(csContext, conf, LeafQueue leafQueue = new LeafQueue(queueContext, leafQueueName, cs.getRootQueue(),
leafQueueName, cs.getRootQueue(),
null); null);
leafQueue.updateClusterResource(Resource.newInstance(0, 0), leafQueue.updateClusterResource(Resource.newInstance(0, 0),
@ -5148,6 +5173,7 @@ public void testSetupQueueConfigsWithSpecifiedConfiguration()
// limit maximum apps by max system apps // limit maximum apps by max system apps
csConf.setMaximumSystemApplications(15); csConf.setMaximumSystemApplications(15);
queueContext.reinitialize();
leafQueue.updateClusterResource(Resource.newInstance(0, 0), leafQueue.updateClusterResource(Resource.newInstance(0, 0),
new ResourceLimits(Resource.newInstance(0, 0))); new ResourceLimits(Resource.newInstance(0, 0)));

View File

@ -79,7 +79,8 @@ public class TestParentQueue {
YarnConfiguration conf; YarnConfiguration conf;
CapacitySchedulerConfiguration csConf; CapacitySchedulerConfiguration csConf;
CapacitySchedulerContext csContext; CapacitySchedulerContext csContext;
CapacitySchedulerQueueContext queueContext;
final static int GB = 1024; final static int GB = 1024;
final static String DEFAULT_RACK = "/default"; final static String DEFAULT_RACK = "/default";
@ -105,6 +106,10 @@ public void setUp() throws Exception {
when(csContext.getResourceCalculator()). when(csContext.getResourceCalculator()).
thenReturn(resourceComparator); thenReturn(resourceComparator);
when(csContext.getRMContext()).thenReturn(rmContext); when(csContext.getRMContext()).thenReturn(rmContext);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(
new CapacitySchedulerQueueManager(csConf, rmContext.getNodeLabelManager(), null));
queueContext = new CapacitySchedulerQueueContext(csContext);
} }
private static final String A = "a"; private static final String A = "a";
@ -121,6 +126,8 @@ private void setupSingleLevelQueues(CapacitySchedulerConfiguration conf) {
conf.setCapacity(Q_A, 30); conf.setCapacity(Q_A, 30);
conf.setCapacity(Q_B, 70); conf.setCapacity(Q_B, 70);
queueContext.reinitialize();
LOG.info("Setup top-level queues a and b"); LOG.info("Setup top-level queues a and b");
} }
@ -137,6 +144,8 @@ private void setupSingleLevelQueuesWithAbsoluteResource(
conf.setMinimumResourceRequirement("", new QueuePath(Q_B), conf.setMinimumResourceRequirement("", new QueuePath(Q_B),
QUEUE_B_RESOURCE); QUEUE_B_RESOURCE);
queueContext.reinitialize();
LOG.info("Setup top-level queues a and b with absolute resource"); LOG.info("Setup top-level queues a and b with absolute resource");
} }
@ -253,7 +262,7 @@ public void testSingleLevelQueues() throws Exception {
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -371,11 +380,12 @@ public void testSingleLevelQueuesPrecision() throws Exception {
setupSingleLevelQueues(csConf); setupSingleLevelQueues(csConf);
csConf.setCapacity(Q_A, 30); csConf.setCapacity(Q_A, 30);
csConf.setCapacity(Q_B, 70.5F); csConf.setCapacity(Q_B, 70.5F);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
boolean exceptionOccurred = false; boolean exceptionOccurred = false;
try { try {
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} catch (IOException ie) { } catch (IOException ie) {
@ -386,10 +396,11 @@ public void testSingleLevelQueuesPrecision() throws Exception {
} }
csConf.setCapacity(Q_A, 30); csConf.setCapacity(Q_A, 30);
csConf.setCapacity(Q_B, 70); csConf.setCapacity(Q_B, 70);
queueContext.reinitialize();
exceptionOccurred = false; exceptionOccurred = false;
queues.clear(); queues.clear();
try { try {
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} catch (IllegalArgumentException ie) { } catch (IllegalArgumentException ie) {
@ -400,10 +411,11 @@ public void testSingleLevelQueuesPrecision() throws Exception {
} }
csConf.setCapacity(Q_A, 30); csConf.setCapacity(Q_A, 30);
csConf.setCapacity(Q_B, 70.005F); csConf.setCapacity(Q_B, 70.005F);
queueContext.reinitialize();
exceptionOccurred = false; exceptionOccurred = false;
queues.clear(); queues.clear();
try { try {
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} catch (IllegalArgumentException ie) { } catch (IllegalArgumentException ie) {
@ -470,6 +482,7 @@ private void setupMultiLevelQueues(CapacitySchedulerConfiguration conf) {
conf.setQueues(Q_C111, new String[] {C1111}); conf.setQueues(Q_C111, new String[] {C1111});
final String Q_C1111= Q_C111 + "." + C1111; final String Q_C1111= Q_C111 + "." + C1111;
conf.setCapacity(Q_C1111, 100); conf.setCapacity(Q_C1111, 100);
queueContext.reinitialize();
} }
@Test @Test
@ -495,7 +508,7 @@ public void testMultiLevelQueues() throws Exception {
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -657,9 +670,10 @@ public void testQueueCapacitySettingChildZero() throws Exception {
csConf.setCapacity(Q_B + "." + B1, 0); csConf.setCapacity(Q_B + "." + B1, 0);
csConf.setCapacity(Q_B + "." + B2, 0); csConf.setCapacity(Q_B + "." + B2, 0);
csConf.setCapacity(Q_B + "." + B3, 0); csConf.setCapacity(Q_B + "." + B3, 0);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
@ -672,9 +686,10 @@ public void testQueueCapacitySettingParentZero() throws Exception {
// set parent capacity to 0 when child not 0 // set parent capacity to 0 when child not 0
csConf.setCapacity(Q_B, 0); csConf.setCapacity(Q_B, 0);
csConf.setCapacity(Q_A, 60); csConf.setCapacity(Q_A, 60);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
@ -690,8 +705,9 @@ public void testQueueCapacitySettingParentZeroChildren100pctZeroSumAllowed()
csConf.setCapacity(Q_B, 0); csConf.setCapacity(Q_B, 0);
csConf.setCapacity(Q_A, 60); csConf.setCapacity(Q_A, 60);
csConf.setAllowZeroCapacitySum(Q_B, true); csConf.setAllowZeroCapacitySum(Q_B, true);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
@ -710,8 +726,9 @@ public void testQueueCapacitySettingParentZeroChildren50pctZeroSumAllowed()
csConf.setCapacity(Q_B + "." + B2, 20); csConf.setCapacity(Q_B + "." + B2, 20);
csConf.setCapacity(Q_B + "." + B3, 20); csConf.setCapacity(Q_B + "." + B3, 20);
csConf.setAllowZeroCapacitySum(Q_B, true); csConf.setAllowZeroCapacitySum(Q_B, true);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
@ -730,8 +747,9 @@ public void testQueueCapacitySettingParentNonZeroChildrenZeroSumAllowed()
csConf.setCapacity(Q_B + "." + B2, 0); csConf.setCapacity(Q_B + "." + B2, 0);
csConf.setCapacity(Q_B + "." + B3, 0); csConf.setCapacity(Q_B + "." + B3, 0);
csConf.setAllowZeroCapacitySum(Q_B, true); csConf.setAllowZeroCapacitySum(Q_B, true);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} }
@ -746,12 +764,12 @@ public void testQueueCapacityZero() throws Exception {
csConf.setCapacity(Q_B + "." + B1, 0); csConf.setCapacity(Q_B + "." + B1, 0);
csConf.setCapacity(Q_B + "." + B2, 0); csConf.setCapacity(Q_B + "." + B2, 0);
csConf.setCapacity(Q_B + "." + B3, 0); csConf.setCapacity(Q_B + "." + B3, 0);
csConf.setCapacity(Q_A, 60); csConf.setCapacity(Q_A, 60);
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
try { try {
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -767,7 +785,7 @@ public void testOffSwitchScheduling() throws Exception {
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -849,7 +867,7 @@ public void testOffSwitchSchedulingMultiLevelQueues() throws Exception {
//B3 //B3
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -948,10 +966,11 @@ public void testQueueAcl() throws Exception {
csConf.setAcl(Q_C, QueueACL.ADMINISTER_QUEUE, "*"); csConf.setAcl(Q_C, QueueACL.ADMINISTER_QUEUE, "*");
final String Q_C11= Q_C + "." + C1 + "." + C11; final String Q_C11= Q_C + "." + C1 + "." + C11;
csConf.setAcl(Q_C11, QueueACL.SUBMIT_APPLICATIONS, "*"); csConf.setAcl(Q_C11, QueueACL.SUBMIT_APPLICATIONS, "*");
queueContext.reinitialize();
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CSQueue root =
CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
CapacitySchedulerConfiguration.ROOT, queues, queues, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
YarnAuthorizationProvider authorizer = YarnAuthorizationProvider authorizer =
@ -1014,7 +1033,7 @@ public void testAbsoluteResourceWithChangeInClusterResource()
setupSingleLevelQueuesWithAbsoluteResource(csConf); setupSingleLevelQueuesWithAbsoluteResource(csConf);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CapacitySchedulerQueueManager.parseQueue(csContext, csConf, CSQueue root = CapacitySchedulerQueueManager.parseQueue(queueContext, csConf,
null, CapacitySchedulerConfiguration.ROOT, queues, queues, null, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -1085,7 +1104,7 @@ public void testDeriveCapacityFromAbsoluteConfigurations() throws Exception {
setupSingleLevelQueuesWithAbsoluteResource(csConf); setupSingleLevelQueuesWithAbsoluteResource(csConf);
CSQueueStore queues = new CSQueueStore(); CSQueueStore queues = new CSQueueStore();
CSQueue root = CapacitySchedulerQueueManager.parseQueue(csContext, csConf, CSQueue root = CapacitySchedulerQueueManager.parseQueue(queueContext, csConf,
null, CapacitySchedulerConfiguration.ROOT, queues, queues, null, CapacitySchedulerConfiguration.ROOT, queues, queues,
TestUtils.spyHook); TestUtils.spyHook);
@ -1138,6 +1157,7 @@ public void testDeriveCapacityFromAbsoluteConfigurations() throws Exception {
// Set GlobalMaximumApplicationsPerQueue in csConf // Set GlobalMaximumApplicationsPerQueue in csConf
csConf.setGlobalMaximumApplicationsPerQueue(8000); csConf.setGlobalMaximumApplicationsPerQueue(8000);
queueContext.reinitialize();
root.updateClusterResource(clusterResource, root.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));
@ -1155,6 +1175,7 @@ public void testDeriveCapacityFromAbsoluteConfigurations() throws Exception {
Integer.toString(queueAMaxApplications)); Integer.toString(queueAMaxApplications));
csConf.set("yarn.scheduler.capacity." + Q_B + ".maximum-applications", csConf.set("yarn.scheduler.capacity." + Q_B + ".maximum-applications",
Integer.toString(queueBMaxApplications)); Integer.toString(queueBMaxApplications));
queueContext.reinitialize();
root.updateClusterResource(clusterResource, root.updateClusterResource(clusterResource,
new ResourceLimits(clusterResource)); new ResourceLimits(clusterResource));

View File

@ -46,6 +46,7 @@ public class TestReservationQueue {
private CapacitySchedulerConfiguration csConf; private CapacitySchedulerConfiguration csConf;
private CapacitySchedulerContext csContext; private CapacitySchedulerContext csContext;
private CapacitySchedulerQueueContext queueContext;
final static int DEF_MAX_APPS = 10000; final static int DEF_MAX_APPS = 10000;
final static int GB = 1024; final static int GB = 1024;
private final ResourceCalculator resourceCalculator = private final ResourceCalculator resourceCalculator =
@ -63,7 +64,7 @@ public void setup() throws IOException, SchedulerDynamicEditException {
CapacitySchedulerQueueManager csQm = mock( CapacitySchedulerQueueManager csQm = mock(
CapacitySchedulerQueueManager.class); CapacitySchedulerQueueManager.class);
ConfiguredNodeLabels labels = new ConfiguredNodeLabels(csConf); ConfiguredNodeLabels labels = new ConfiguredNodeLabels(csConf);
when(csQm.getConfiguredNodeLabels()).thenReturn(labels); when(csQm.getConfiguredNodeLabelsForAllQueues()).thenReturn(labels);
when(csContext.getConfiguration()).thenReturn(csConf); when(csContext.getConfiguration()).thenReturn(csConf);
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(csQm); when(csContext.getCapacitySchedulerQueueManager()).thenReturn(csQm);
when(csContext.getConf()).thenReturn(conf); when(csContext.getConf()).thenReturn(conf);
@ -78,9 +79,11 @@ public void setup() throws IOException, SchedulerDynamicEditException {
RMContext mockRMContext = TestUtils.getMockRMContext(); RMContext mockRMContext = TestUtils.getMockRMContext();
when(csContext.getRMContext()).thenReturn(mockRMContext); when(csContext.getRMContext()).thenReturn(mockRMContext);
queueContext = new CapacitySchedulerQueueContext(csContext);
// create a queue // create a queue
planQueue = new PlanQueue(csContext, "root", null, null); planQueue = new PlanQueue(queueContext, "root", null, null);
autoCreatedLeafQueue = new ReservationQueue(csContext, "a", planQueue); autoCreatedLeafQueue = new ReservationQueue(queueContext, "a", planQueue);
planQueue.addChildQueue(autoCreatedLeafQueue); planQueue.addChildQueue(autoCreatedLeafQueue);
} }

View File

@ -90,6 +90,7 @@ public class TestReservations {
CapacityScheduler cs; CapacityScheduler cs;
// CapacitySchedulerConfiguration csConf; // CapacitySchedulerConfiguration csConf;
CapacitySchedulerContext csContext; CapacitySchedulerContext csContext;
CapacitySchedulerQueueContext queueContext;
private final ResourceCalculator resourceCalculator = private final ResourceCalculator resourceCalculator =
new DefaultResourceCalculator(); new DefaultResourceCalculator();
@ -135,7 +136,10 @@ private void setup(CapacitySchedulerConfiguration csConf,
when(csContext.getClusterResource()).thenReturn( when(csContext.getClusterResource()).thenReturn(
Resources.createResource(100 * 16 * GB, 100 * 12)); Resources.createResource(100 * 16 * GB, 100 * 12));
when(csContext.getResourceCalculator()).thenReturn(resourceCalculator); when(csContext.getResourceCalculator()).thenReturn(resourceCalculator);
CapacitySchedulerQueueManager queueManager = new CapacitySchedulerQueueManager(conf,
rmContext.getNodeLabelManager(), null);
when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager()); when(csContext.getPreemptionManager()).thenReturn(new PreemptionManager());
when(csContext.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
when(csContext.getRMContext()).thenReturn(rmContext); when(csContext.getRMContext()).thenReturn(rmContext);
RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager( RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager(
conf); conf);
@ -143,12 +147,11 @@ private void setup(CapacitySchedulerConfiguration csConf,
when(csContext.getContainerTokenSecretManager()).thenReturn( when(csContext.getContainerTokenSecretManager()).thenReturn(
containerTokenSecretManager); containerTokenSecretManager);
root = CapacitySchedulerQueueManager.parseQueue(csContext, csConf, null, queueContext = new CapacitySchedulerQueueContext(csContext);
CapacitySchedulerConfiguration.ROOT, queues, queues, TestUtils.spyHook);
ResourceUsage queueResUsage = root.getQueueResourceUsage(); root = CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null,
when(csContext.getClusterResourceUsage()) CapacitySchedulerConfiguration.ROOT, queues, queues, TestUtils.spyHook);
.thenReturn(queueResUsage); queueManager.setRootQueue(root);
spyRMContext = spy(rmContext); spyRMContext = spy(rmContext);
when(spyRMContext.getScheduler()).thenReturn(cs); when(spyRMContext.getScheduler()).thenReturn(cs);
@ -1181,23 +1184,24 @@ public void testAssignToQueue() throws Exception {
public void refreshQueuesTurnOffReservationsContLook(LeafQueue a, public void refreshQueuesTurnOffReservationsContLook(LeafQueue a,
CapacitySchedulerConfiguration csConf) throws Exception { CapacitySchedulerConfiguration csConf) throws Exception {
// before reinitialization // before reinitialization
assertEquals(true, a.getReservationContinueLooking()); assertEquals(true, a.isReservationsContinueLooking());
assertEquals(true, assertEquals(true,
((ParentQueue) a.getParent()).getReservationContinueLooking()); ((ParentQueue) a.getParent()).isReservationsContinueLooking());
csConf.setBoolean( csConf.setBoolean(
CapacitySchedulerConfiguration.RESERVE_CONT_LOOK_ALL_NODES, false); CapacitySchedulerConfiguration.RESERVE_CONT_LOOK_ALL_NODES, false);
CSQueueStore newQueues = new CSQueueStore(); CSQueueStore newQueues = new CSQueueStore();
CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(csContext, queueContext.reinitialize();
CSQueue newRoot = CapacitySchedulerQueueManager.parseQueue(queueContext,
csConf, null, CapacitySchedulerConfiguration.ROOT, newQueues, queues, csConf, null, CapacitySchedulerConfiguration.ROOT, newQueues, queues,
TestUtils.spyHook); TestUtils.spyHook);
queues = newQueues; queues = newQueues;
root.reinitialize(newRoot, cs.getClusterResource()); root.reinitialize(newRoot, cs.getClusterResource());
// after reinitialization // after reinitialization
assertEquals(false, a.getReservationContinueLooking()); assertEquals(false, a.isReservationsContinueLooking());
assertEquals(false, assertEquals(false,
((ParentQueue) a.getParent()).getReservationContinueLooking()); ((ParentQueue) a.getParent()).isReservationsContinueLooking());
} }
@Test @Test

View File

@ -58,15 +58,11 @@ public class TestUsersManager {
@Mock @Mock
private QueueMetrics metrics; private QueueMetrics metrics;
@Mock
private CapacitySchedulerContext context;
@Before @Before
public void setup() { public void setup() {
usersManager = new UsersManager(metrics, usersManager = new UsersManager(metrics,
lQueue, lQueue,
labelMgr, labelMgr,
context,
new DefaultResourceCalculator()); new DefaultResourceCalculator());
when(lQueue.getMinimumAllocation()).thenReturn(MINIMUM_ALLOCATION); when(lQueue.getMinimumAllocation()).thenReturn(MINIMUM_ALLOCATION);