You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "brumi1024 (via GitHub)" <gi...@apache.org> on 2026/10/19 20:25:10 UTC
[PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
brumi1024 opened a new pull request, #8845:
URL: https://github.com/apache/hadoop/pull/8845
<!--
Thanks for sending a pull request!
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute
2. Make sure your PR title starts with JIRA issue id, e.g., 'HADOOP-17799. Your PR title ...'.
-->
### Description of PR
Every per-queue property is declared once as a QueueProperty in QueueProperties: key suffix, parser, applicable queue kinds, resolution steps (queue key, v2 and v1 templates, parent, global key, default) and derivations such as absolute capacity and maximum applications. QueueConfigResolver walks the hierarchy once and produces an immutable ResolvedQueueConfig per queue in which every value records its source; parse failures are kept and rethrown unchanged when the value is read.
CapacitySchedulerConfiguration getters keep their signatures and delegate to the same descriptors against the live configuration, so each default and inheritance rule has one definition. Parity tests compare every getter with the resolver over a set of configurations, including dynamic v1 and v2 queues and reservation queues, and check that configurations trunk rejects keep the same failure.
Leaf queues, plan queues and the derived maximum applications of the resolver share the application limit arithmetic in QueueApplicationLimits, so the derived values cannot drift from the live ones.
### How was this patch tested?
Config loading tests, newly added test cases in YARN-12011, sanity check in a small cluster.
### For code changes:
- [x] Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
- [ ] Object storage: Have the integration tests been executed and the endpoint
declared according to the connector-specific documentation? *Note: Automated CI
testing doesn't cover all cases so manual testing with cloud storage is still
required.*
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`, `NOTICE-binary` files?
### AI Tooling
If an AI tool was used:
- [x] The PR includes the phrase "Contains content generated by <tool>"
where <tool> is the name of the AI tool used.
- [x] My use of AI contributions follows the ASF legal policy
https://www.apache.org/legal/generative-tooling.html
Contains code generated by Claude Code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4388570395
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueConfigResolverParity.java:
##########
@@ -0,0 +1,1268 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.authorize.AccessControlList;
+import org.apache.hadoop.yarn.api.records.QueueACL;
+import org.apache.hadoop.yarn.api.records.ReservationACL;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.security.AccessType;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ConfigSnapshot;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueConfigResolver;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.Resolved;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolvedQueueConfig;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolvedQueueTree;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.TestQueueConfigResolver;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ValueSource;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.policy.FifoOrderingPolicy;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Parity between the resolver and trunk behavior.
+ * <ul>
+ * <li>Every {@code CapacitySchedulerConfiguration} per-queue getter returns
+ * the resolved value, or throws the resolved failure, for every queue of a
+ * set of configurations.</li>
+ * <li>Inherited and derived values equal the values of the queues a MockRM
+ * builds from the same configuration.</li>
+ * <li>For dynamic v1 and v2 queues created in a MockRM, the getters of the
+ * queue context configuration, which holds the template writes, return the
+ * values {@link QueueConfigResolver#resolveDynamicQueue} resolves.</li>
+ * </ul>
+ * For configurations trunk rejects at startup, the resolver must hold a
+ * failed value with the exception type and message that failed queue
+ * initialization.
+ */
+public class TestQueueConfigResolverParity {
+ /**
+ * Configurations that trunk rejects with a check (mixed capacity
+ * modes of siblings) rather than a parse failure, so the resolver has no
+ * failed value for them.
+ */
+ private static final Set<String> CHECK_REJECTIONS = new HashSet<>(
+ Arrays.asList("absolute with weight units", "absolute before percentage"));
+ private static final String P = CapacitySchedulerConfiguration.PREFIX;
+ private static final int GB = 1024;
+
+ /** Reads the value a getter returns for a queue and label. */
+ private interface Getter {
+ Object get(CapacitySchedulerConfiguration conf, QueuePath queue,
+ String label, ResolutionInputs inputs);
+ }
+
+ /** Properties a queue may inherit from its parent queue. */
+ private static final Set<QueueProperty<?>> INHERITED =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(USER_LIMIT,
+ USER_LIMIT_FACTOR, USER_WEIGHTS, STATE, ACCESSIBLE_NODE_LABELS,
+ DEFAULT_NODE_LABEL_EXPRESSION, QUEUE_ORDERING_POLICY,
+ MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME));
+ /** Properties templates do not write for dynamic queues. */
+ private static final Set<QueueProperty<?>> NOT_TEMPLATED =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(QUEUES, USER_WEIGHTS,
+ ACL_SUBMIT_RESERVATIONS, ACL_LIST_RESERVATIONS,
+ ACL_ADMINISTER_RESERVATIONS, ALLOW_ZERO_CAPACITY_SUM,
+ AUTO_CREATE_CHILD_QUEUE_ENABLED, AUTO_CREATE_CHILD_QUEUE_MAX_QUEUES,
+ AUTO_CREATE_CHILD_QUEUE_FAIL_ON_EXCEEDING_CAPACITY,
+ AUTO_CREATED_QUEUE_MANAGEMENT_POLICY_NAME, LEAF_QUEUE_TEMPLATE,
+ AUTO_QUEUE_CREATION_V2_ENABLED, AUTO_QUEUE_CREATION_V2_MAX_DEPTH,
+ AQC_V2_TEMPLATE, AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE,
+ RESERVABLE, RESERVATION_WINDOW_MS, AVERAGE_CAPACITY_PERCENT,
+ INSTANTANEOUS_MAX_CAPACITY_PERCENT, RESERVATION_ADMISSION_POLICY_NAME,
+ RESERVATION_AGENT, RESERVATION_PLANNER,
+ RESERVATION_MOVE_ON_EXPIRY_ENABLED, RESERVATION_ENFORCEMENT_WINDOW_MS,
+ SHOW_RESERVATIONS_AS_QUEUES));
+
+ private static final Map<QueueProperty<?>, Getter> GETTERS =
+ new LinkedHashMap<>();
+
+ static {
+ GETTERS.put(QUEUES, (c, q, l, i) -> c.getQueues(q));
+ GETTERS.put(CAPACITY, (c, q, l, i) -> c.getNonLabeledQueueCapacity(q));
+ GETTERS.put(CAPACITY_WEIGHT, (c, q, l, i) -> l.equals(NO_LABEL)
+ ? c.getNonLabeledQueueWeight(q) : c.getLabeledQueueWeight(q, l));
+ GETTERS.put(CAPACITY_IS_ABSOLUTE_RESOURCE, (c, q, l, i) ->
+ c.checkConfigTypeIsAbsoluteResource(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(MINIMUM_RESOURCE, (c, q, l, i) ->
+ c.getMinimumResourceRequirement(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(CAPACITY_VECTOR, (c, q, l, i) -> c
+ .parseConfiguredResourceVector(q, Collections.singleton(l)).get(l));
+ GETTERS.put(MAXIMUM_CAPACITY,
+ (c, q, l, i) -> c.getNonLabeledQueueMaximumCapacity(q));
+ GETTERS.put(MAXIMUM_RESOURCE, (c, q, l, i) ->
+ c.getMaximumResourceRequirement(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(MAXIMUM_CAPACITY_VECTOR, (c, q, l, i) -> c
+ .parseConfiguredMaximumCapacityVector(q, Collections.singleton(l),
+ QueueCapacityVector.newInstance()).get(l));
+ GETTERS.put(LABELED_CAPACITY,
+ (c, q, l, i) -> c.getLabeledQueueCapacity(q, l));
+ GETTERS.put(LABELED_MAXIMUM_CAPACITY,
+ (c, q, l, i) -> c.getLabeledQueueMaximumCapacity(q, l));
+ GETTERS.put(MAXIMUM_AM_RESOURCE_PERCENT, (c, q, l, i) ->
+ c.getMaximumApplicationMasterResourcePerQueuePercent(q));
+ GETTERS.put(LABELED_MAXIMUM_AM_RESOURCE_PERCENT,
+ (c, q, l, i) -> c.getMaximumAMResourcePercentPerPartition(q, l));
+ GETTERS.put(MAXIMUM_APPLICATIONS,
+ (c, q, l, i) -> c.getMaximumApplicationsPerQueue(q));
+ GETTERS.put(USER_LIMIT, (c, q, l, i) -> c.getUserLimit(q));
+ GETTERS.put(USER_LIMIT_FACTOR, (c, q, l, i) -> c.getUserLimitFactor(q));
+ GETTERS.put(STATE, (c, q, l, i) -> c.getConfiguredState(q));
+ GETTERS.put(ACCESSIBLE_NODE_LABELS,
+ (c, q, l, i) -> c.getAccessibleNodeLabels(q));
+ GETTERS.put(DEFAULT_NODE_LABEL_EXPRESSION,
+ (c, q, l, i) -> c.getDefaultNodeLabelExpression(q));
+ GETTERS.put(ACL_SUBMIT_APPLICATIONS,
+ (c, q, l, i) -> c.getAcl(q, QueueACL.SUBMIT_APPLICATIONS));
+ GETTERS.put(ACL_ADMINISTER_QUEUE,
+ (c, q, l, i) -> c.getAcl(q, QueueACL.ADMINISTER_QUEUE));
+ GETTERS.put(ACL_APPLICATION_MAX_PRIORITY, (c, q, l, i) ->
+ c.getPriorityAcls(q, i.getClusterMaximumApplicationPriority()));
+ GETTERS.put(ACL_SUBMIT_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.SUBMIT_RESERVATIONS));
+ GETTERS.put(ACL_LIST_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.LIST_RESERVATIONS));
+ GETTERS.put(ACL_ADMINISTER_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.ADMINISTER_RESERVATIONS));
+ GETTERS.put(QUEUE_ORDERING_POLICY, (c, q, l, i) ->
+ c.getQueueOrderingPolicy(q, null).getConfigName());
+ GETTERS.put(PRIORITY, (c, q, l, i) -> c.getQueuePriority(q).getPriority());
+ GETTERS.put(DEFAULT_APPLICATION_PRIORITY,
+ (c, q, l, i) -> c.getDefaultApplicationPriorityConfPerQueue(q));
+ GETTERS.put(MAXIMUM_ALLOCATION_MB,
+ (c, q, l, i) -> c.getQueueMaximumAllocationMb(q));
+ GETTERS.put(MAXIMUM_ALLOCATION_VCORES,
+ (c, q, l, i) -> c.getQueueMaximumAllocationVcores(q));
+ GETTERS.put(PREEMPTION_DISABLED,
+ (c, q, l, i) -> c.getPreemptionDisabled(q, false));
+ GETTERS.put(INTRA_QUEUE_PREEMPTION_DISABLED,
+ (c, q, l, i) -> c.getIntraQueuePreemptionDisabled(q, false));
+ GETTERS.put(MAXIMUM_APPLICATION_LIFETIME,
+ (c, q, l, i) -> c.getMaximumLifetimePerQueue(q));
+ GETTERS.put(DEFAULT_APPLICATION_LIFETIME,
+ (c, q, l, i) -> c.getDefaultLifetimePerQueue(q));
+ GETTERS.put(MAX_PARALLEL_APPS,
+ (c, q, l, i) -> c.getMaxParallelAppsForQueue(q));
+ GETTERS.put(MULTI_NODE_SORTING_POLICY,
+ (c, q, l, i) -> c.getMultiNodesSortingAlgorithmPolicy(q));
+ GETTERS.put(ALLOW_ZERO_CAPACITY_SUM,
+ (c, q, l, i) -> c.getAllowZeroCapacitySum(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_ENABLED,
+ (c, q, l, i) -> c.isAutoCreateChildQueueEnabled(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_MAX_QUEUES,
+ (c, q, l, i) -> c.getAutoCreatedQueuesMaxChildQueuesLimit(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_FAIL_ON_EXCEEDING_CAPACITY,
+ (c, q, l, i) ->
+ c.getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded(q));
+ GETTERS.put(AUTO_CREATED_QUEUE_MANAGEMENT_POLICY_NAME,
+ (c, q, l, i) -> c.getAutoCreatedQueueManagementPolicy(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_ENABLED,
+ (c, q, l, i) -> c.isAutoQueueCreationV2Enabled(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_MAX_QUEUES,
+ (c, q, l, i) -> c.getAutoCreatedQueuesV2MaxChildQueuesLimit(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_MAX_DEPTH,
+ (c, q, l, i) -> c.getMaximumAutoCreatedQueueDepth(q));
+ GETTERS.put(AUTO_QUEUE_AUTO_REMOVAL_ENABLED,
+ (c, q, l, i) -> c.isAutoExpiredDeletionEnabled(q));
+ GETTERS.put(AQC_V2_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getTemplateProperties());
+ GETTERS.put(AQC_V2_LEAF_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getLeafOnlyProperties());
+ GETTERS.put(AQC_V2_PARENT_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getParentOnlyProperties());
+ GETTERS.put(RESERVABLE, (c, q, l, i) -> c.isReservable(q));
+ GETTERS.put(RESERVATION_WINDOW_MS,
+ (c, q, l, i) -> c.getReservationWindow(q));
+ GETTERS.put(AVERAGE_CAPACITY_PERCENT,
+ (c, q, l, i) -> c.getAverageCapacity(q));
+ GETTERS.put(INSTANTANEOUS_MAX_CAPACITY_PERCENT,
+ (c, q, l, i) -> c.getInstantaneousMaxCapacity(q));
+ GETTERS.put(RESERVATION_ADMISSION_POLICY_NAME,
+ (c, q, l, i) -> c.getReservationAdmissionPolicy(q));
+ GETTERS.put(RESERVATION_AGENT, (c, q, l, i) -> c.getReservationAgent(q));
+ GETTERS.put(RESERVATION_PLANNER, (c, q, l, i) -> c.getReplanner(q));
+ GETTERS.put(RESERVATION_MOVE_ON_EXPIRY_ENABLED,
+ (c, q, l, i) -> c.getMoveOnExpiry(q));
+ GETTERS.put(RESERVATION_ENFORCEMENT_WINDOW_MS,
+ (c, q, l, i) -> c.getEnforcementWindow(q));
+ GETTERS.put(SHOW_RESERVATIONS_AS_QUEUES,
+ (c, q, l, i) -> c.getShowReservationAsQueues(q));
+ }
+
+ /**
+ * Properties without a plain getter, and why: user weights, the maximum
+ * allocation, the ordering policy parameters and the v1 template are
+ * compared against live queues or their template writes instead; the
+ * application ordering policy getter builds the policy object.
+ */
+ private static final Set<QueueProperty<?>> WITHOUT_GETTER =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(USER_WEIGHTS,
+ MAXIMUM_ALLOCATION, ORDERING_POLICY_PARAMETERS, LEAF_QUEUE_TEMPLATE,
+ APP_ORDERING_POLICY));
+
+ @Test
+ public void testEveryPropertyIsCompared() {
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ assertTrue(GETTERS.containsKey(property)
+ || WITHOUT_GETTER.contains(property), property.toString());
+ }
+ }
+
+ @Test
+ public void testGettersMatchResolvedValues() throws Exception {
+ int compared = 0;
+ for (Map.Entry<String, Configuration> entry : corpus().entrySet()) {
+ CapacitySchedulerConfiguration conf =
+ new CapacitySchedulerConfiguration(entry.getValue(), false);
+ ResolutionInputs inputs = TestQueueConfigResolver.inputs(conf,
+ Collections.<DynamicQueue>emptyList());
+ ResolvedQueueTree tree =
+ QueueConfigResolver.resolve(conf.getConfigSnapshot(), inputs);
+ ConfiguredNodeLabels labels = new ConfiguredNodeLabels(conf);
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ if (queue.isDynamic()) {
+ // Without a scheduler nothing writes the template entries
+ continue;
+ }
+ compared += assertGetterParity(entry.getKey(), conf, inputs, queue);
+ Set<String> expectedLabels = queue.getQueuePath().isRoot()
+ ? labels.getAllConfiguredLabels()
+ : labels.getLabelsByQueue(queue.getQueuePath().getFullPath());
+ assertEquals(expectedLabels,
+ queue.get(CONFIGURED_NODE_LABELS).getValue(), entry.getKey());
+ }
+ }
+ assertTrue(compared > 1000, "compared " + compared + " values");
+ }
+
+ @Test
+ public void testRejectedConfigurationsHoldFailedValues() throws Exception {
+ for (Map.Entry<String, Configuration> entry : rejections().entrySet()) {
+ String name = entry.getKey();
+ CapacitySchedulerConfiguration conf =
+ new CapacitySchedulerConfiguration(entry.getValue(), false);
+ ResolutionInputs inputs = TestQueueConfigResolver.inputs(conf,
+ Collections.<DynamicQueue>emptyList());
+ ResolvedQueueTree tree =
+ QueueConfigResolver.resolve(conf.getConfigSnapshot(), inputs);
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ assertGetterParity(name, conf, inputs, queue);
+ }
+ Throwable rootCause = null;
+ MockRM rm = null;
+ try {
+ // Queues are parsed when the RM is initialized
+ rm = startRM(entry.getValue());
+ } catch (Exception e) {
+ rootCause = e;
+ while (rootCause.getCause() != null) {
+ rootCause = rootCause.getCause();
+ }
+ } finally {
+ if (rm != null) {
+ rm.stop();
+ }
+ }
+ assertNotNull(rootCause, name + " was accepted");
+ assertRejectionResolved(name, tree, rootCause);
+ }
+ }
+
+ /** The existing dynamic queues of a live hierarchy. */
+ private static List<DynamicQueue> dynamicQueues(CSQueue queue,
+ List<DynamicQueue> dynamic) {
+ if (queue instanceof AutoCreatedLeafQueue) {
+ dynamic.add(new DynamicQueue(queue.getQueuePathObject(), true, true));
+ } else if (!(queue instanceof ReservationQueue)
+ && ((AbstractCSQueue) queue).isDynamicQueue()) {
+ dynamic.add(new DynamicQueue(queue.getQueuePathObject(), false,
+ queue instanceof AbstractLeafQueue));
+ }
+ if (queue.getChildQueues() != null) {
+ for (CSQueue child : queue.getChildQueues()) {
+ dynamicQueues(child, dynamic);
+ }
+ }
+ return dynamic;
+ }
+
+ /**
+ * The exception that failed queue initialization must be a resolved
+ * failure, with the same type and message.
+ */
+ private static void assertRejectionResolved(String name,
+ ResolvedQueueTree tree, Throwable rootCause) {
+ List<String> failures = new ArrayList<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ for (Resolved<?> value : queue.explain().values()) {
+ if (value.isFailed()) {
+ try {
+ value.getValue();
+ } catch (RuntimeException e) {
+ failures.add(e.getClass().getName() + ": " + e.getMessage());
+ }
+ }
+ }
+ }
+ String expected = rootCause.getClass().getName() + ": "
+ + rootCause.getMessage();
+ if (CHECK_REJECTIONS.contains(name)) {
+ assertTrue(!failures.contains(expected), name);
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "Hean-Chhinling (via GitHub)" <gi...@apache.org>.
Hean-Chhinling commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4414204976
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
Review Comment:
Nit: Here as well, would be nice to not use the wildcard import instead import each one if possible
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(QueueConfigResolver.class);
+
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
Review Comment:
Nit: I see a lot of this inline import in `QueueConfigResolver` and `QueueProperties`.
Would it be better to `import java.util.Arrays` at the top of each of this file?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueProperties.java:
##########
@@ -0,0 +1,950 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLGroup;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.QueueCapacityConfigParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.util.UnitsConversionUtil;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.*;
Review Comment:
Nit: Would be nice to not use the wildcard imports if possible
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java:
##########
Review Comment:
Nit: We can remove this field now as `getPriorityAcls` at line 1133 is using `QueueProperties`.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(QueueConfigResolver.class);
+
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.computeIfAbsent(queuePath, k -> {
+ Set<String> newLabels = new HashSet<>();
+ newLabels.add(RMNodeLabelsManager.NO_LABEL);
+ return newLabels;
+ });
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ LOG.trace("Failed to read the queue kind of {}", path, e);
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Map<String, Set<String>> configuredLabels =
+ tree.getConfiguredNodeLabels();
+ labels = labels(path.isRoot() ? allLabels(configuredLabels)
+ : labelsOf(configuredLabels, path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue. Like
+ // AbstractCSQueue and AutoCreatedLeafQueue, a template whose only label
+ // is the empty label does not count.
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ LOG.trace("Failed to read {} for {}", key, queue.getQueuePath(), e);
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
Review Comment:
Nit: Seems like the javadoc here is not up to date with the method. We only have `siblingWeights` and not `extraSibling`
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueProperties.java:
##########
@@ -0,0 +1,950 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLGroup;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.QueueCapacityConfigParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.util.UnitsConversionUtil;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.*;
+
+/**
+ * One {@link QueueProperty} per per-queue configuration key of the Capacity
+ * Scheduler, and the parse rules they share with the
+ * {@code CapacitySchedulerConfiguration} getters.
+ * <p>
+ * A property that takes an argument documents it; {@code null} selects the
+ * default the queues use. Readers mirror the getters exactly, including
+ * which fallback keys are read before the queue key, so that the getters can
+ * delegate to them without changing values, exception types or messages.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueProperties {
+ /**
+ * The readers log under the loggers of the code they replace, so log
+ * output and log based tests stay the same.
+ */
+ private static final Logger LOG =
+ LoggerFactory.getLogger(CapacitySchedulerConfiguration.class);
+ private static final Logger CONF_LOG =
+ LoggerFactory.getLogger(Configuration.class);
+
+ private static final String WEIGHT_SUFFIX = "w";
+ private static final QueueCapacityConfigParser CAPACITY_PARSER =
+ CapacitySchedulerConfiguration.getQueueCapacityConfigParser();
+ private static final AppPriorityACLConfigurationParser PRIORITY_ACL_PARSER =
+ new AppPriorityACLConfigurationParser();
+ /** The resource types the queues pass to the absolute resource parser. */
+ public static final Set<String> QUEUE_RESOURCE_TYPES =
+ ImmutableSet.of("memory", "vcores");
+ /** Key of the scheduler-wide maximum-queue-depth fallback. */
+ public static final String GLOBAL_MAXIMUM_QUEUE_DEPTH =
+ PREFIX + MAXIMUM_QUEUE_DEPTH;
+ /** Key of the scheduler-wide multi-node sorting policy fallback. */
+ public static final String GLOBAL_MULTI_NODE_SORTING_POLICY =
+ MULTI_NODE_SORTING_POLICY_NAME;
+
+ /** The kinds of configured queues. */
+ private static final Set<Kind> ALL =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.LEAF, Kind.PLAN);
+ /**
+ * Every kind, ReservationQueue included; a ReservationQueue sets up every
+ * value except its capacities, which come from its entitlement.
+ */
+ private static final Set<Kind> SET_UP = EnumSet.allOf(Kind.class);
+ private static final Set<Kind> PARENTS = EnumSet.of(Kind.ROOT, Kind.PARENT);
+ /** Queues set up as parent queue objects, PlanQueue included. */
+ private static final Set<Kind> PARENT_OBJECTS =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.PLAN);
+ private static final Set<Kind> LEAVES =
+ EnumSet.of(Kind.LEAF, Kind.PLAN, Kind.RESERVATION);
+ /** Queues set up as leaf queue objects. */
+ private static final Set<Kind> LEAF =
+ EnumSet.of(Kind.LEAF, Kind.RESERVATION);
+ private static final Set<Kind> PLANS = EnumSet.of(Kind.PLAN);
+
+ private QueueProperties() {
+ }
+
+ // P01
Review Comment:
If you don't mind me asking, could you help explain what is this P01, P02 means?
I am not sure if this reference to some point in the design docs or maybe something else
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "K0K0V0K (via GitHub)" <gi...@apache.org>.
K0K0V0K commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4352101901
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
Review Comment:
Nit: Maybe a trace level log can be useful here?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
Review Comment:
Nit: Maybe this is a bit hard to read
```
Resolved<Set> labels;
if (labelFailure != null) {
labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
} else {
Set configuredLabels = tree.getConfiguredNodeLabels();
labels = labels(path.isRoot()
? allLabels(configuredLabels)
: labelsOf(configuredLabels, path.getFullPath()));
}
```
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
Review Comment:
Nit: Maybe use `!templateLabels.isEmpty()` instead of `templateLabels.size() > 1`
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
Review Comment:
Nit: Maybe a trace level log would be nice.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
Review Comment:
Nit, maybe this would be better:
```
Set<String> labels = labelsByQueue.computeIfAbsent(queuePath, k -> {
Set<String> newLabels = new HashSet<>();
newLabels.add(RMNodeLabelsManager.NO_LABEL);
return newLabels;
});
labels.add(labelName);
```
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
+ return CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE;
+ }
+ }
+
+ private static Resolved<Float> deriveAbsoluteCapacity(
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Map<String, Float>> siblingWeights, String label,
+ boolean legacyMode, boolean maximum) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> configured = maximum
+ ? queue.get(noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label)
+ : queue.get(noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ if (configured.isFailed()) {
+ return configured;
+ }
+ float parentValue = 1f;
+ if (parent != null) {
+ Resolved<Float> parentAbsolute = parent.get(
+ maximum ? ABSOLUTE_MAXIMUM_CAPACITY : ABSOLUTE_CAPACITY, label);
+ if (parentAbsolute == null) {
+ parentValue = 0f;
+ } else if (parentAbsolute.isFailed()) {
+ return parentAbsolute;
+ } else {
+ parentValue = parentAbsolute.getValue();
+ }
+ }
+ float capacity = configured.getValue() / 100;
+ String formula = (maximum ? "maximum-capacity" : "capacity")
+ + " x parent absolute";
+ if (maximum) {
+ // A non-positive maximum keeps the cleared value
+ return Resolved.of(capacity > 0f ? capacity * parentValue : 0f,
+ ValueSource.DERIVED, formula);
+ }
+ if (!legacyMode) {
+ return Resolved.of(capacity * parentValue, ValueSource.DERIVED, formula);
+ }
+ // Legacy weight normalization (AbstractParentQueue)
+ Resolved<Float> weight = queue.get(CAPACITY_WEIGHT, label);
+ if (weight.isFailed()) {
+ return weight;
+ }
+ float normalizedWeight;
+ if (parent == null) {
+ normalizedWeight = weight.getValue() > 0 ? 1f : 0f;
+ } else if (siblingWeights.isFailed()) {
+ return Resolved.failed(failureOf(siblingWeights),
+ siblingWeights.getSource(), siblingWeights.getSourceDetail());
+ } else {
+ Float sum = siblingWeights.getValue() == null ? null
+ : siblingWeights.getValue().get(label);
+ normalizedWeight = sum == null || Math.abs(sum) <= 1e-6 ? 0f
+ : weightOf(queue, weight.getValue()) / sum;
+ }
+ float effective = Math.max(capacity, normalizedWeight);
+ return Resolved.of(effective > 0f ? effective * parentValue : 0f,
+ ValueSource.DERIVED, "max(capacity, normalized weight)"
+ + " x parent absolute");
+ }
+
+ /**
+ * Sums the weights of siblings per label.
+ * @return label to the sum, a {@code null} map when no sibling uses
+ * weights, or the first weight failure
+ */
+ private static Resolved<Map<String, Float>> weightSums(
+ List<ResolvedQueueConfig> siblings) {
+ boolean weightMode = false;
+ Map<String, Float> sums = new HashMap<>();
+ for (ResolvedQueueConfig sibling : siblings) {
+ for (String label : sibling.getConfiguredNodeLabels()) {
+ Resolved<Float> weight = sibling.get(CAPACITY_WEIGHT, label);
+ if (weight == null) {
+ continue;
+ }
+ if (weight.isFailed()) {
+ return Resolved.failed(failureOf(weight), weight.getSource(),
+ weight.getSourceDetail());
+ }
+ float value = weightOf(sibling, weight.getValue());
+ weightMode |= value >= 0;
+ Float sum = sums.get(label);
+ sums.put(label, (sum == null ? 0f : sum) + Math.max(0, value));
+ }
+ }
+ return Resolved.of(weightMode ? sums : null, ValueSource.DERIVED, null);
+ }
+
+ /** Dynamic queues without a weight count as weight 1. */
+ private static float weightOf(ResolvedQueueConfig queue, float weight) {
+ return queue.isDynamic() && weight == -1f ? 1f : weight;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplications(
+ Function<String, String> conf, ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ Resolved<Integer> explicit = queue.get(MAXIMUM_APPLICATIONS);
+ if (explicit.isFailed() || explicit.getValue() >= 0) {
+ return explicit;
+ }
+ try {
+ if (queue.getKind() == Kind.PLAN) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ return Resolved.of(QueueApplicationLimits.scaleByAbsoluteCapacity(
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS,
+ absolute.getValue()), ValueSource.DERIVED,
+ "10000 x absolute capacity");
+ }
+ int globalPerQueue = readInt(conf,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION,
+ (int) CapacitySchedulerConfiguration.UNDEFINED);
+ int system = readInt(conf,
+ CapacitySchedulerConfiguration.MAXIMUM_SYSTEM_APPLICATIONS,
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS);
+ int base =
+ QueueApplicationLimits.baseMaximumApplications(globalPerQueue, system);
+ if (QueueApplicationLimits.usesBaseMaximumApplications(globalPerQueue,
+ isAbsoluteResourceType(queue, legacyMode))) {
+ return Resolved.of(base, ValueSource.GLOBAL,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION);
+ }
+ int maxApps = -1;
+ for (String label : queue.getConfiguredNodeLabels()) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY, label);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ maxApps = Math.max(maxApps, QueueApplicationLimits
+ .scaleByAbsoluteCapacity(base, absolute.getValue()));
+ }
+ return Resolved.of(maxApps, ValueSource.DERIVED,
+ "maximum applications x absolute capacity");
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, null);
+ }
+ }
+
+ private static boolean isAbsoluteResourceType(ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (legacyMode) {
+ Resolved<Boolean> absolute = queue.get(CAPACITY_IS_ABSOLUTE_RESOURCE);
+ return absolute != null && !absolute.isFailed() && absolute.getValue();
+ }
+ Resolved<QueueCapacityVector> vector = queue.get(CAPACITY_VECTOR, none);
+ if (vector == null || vector.isFailed()) {
+ return false;
+ }
+ return QueueCapacityChecks.capacityConfigTypeOf(vector.getValue())
+ == CapacityConfigType.ABSOLUTE_RESOURCE;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplicationsPerUser(
+ ResolvedQueueConfig queue, Resolved<Integer> maxApps) {
+ Resolved<Float> userLimit = queue.get(USER_LIMIT);
+ Resolved<Float> userLimitFactor = queue.get(USER_LIMIT_FACTOR);
+ for (Resolved<?> input : java.util.Arrays.<Resolved<?>>asList(maxApps,
+ userLimit, userLimitFactor)) {
+ if (input.isFailed()) {
+ return failedInteger(input);
+ }
+ }
+ // A PlanQueue does not cap the per-user value at the queue value
+ int perUser = QueueApplicationLimits.maximumApplicationsPerUser(
+ maxApps.getValue(), userLimit.getValue(), userLimitFactor.getValue(),
+ queue.getKind() != Kind.PLAN);
+ return Resolved.of(perUser, ValueSource.DERIVED,
+ userLimitFactor.getValue() == -1 ? "maximum applications"
+ : "maximum applications x user limit x user limit factor");
+ }
+
+ private static <T> void readInto(ResolvedQueueConfig queue, Lookup lookup,
+ QueueProperty<T> property, String label, Object argument) {
+ queue.put(property, label,
+ read(lookup, property, queue.getQueuePath(), label, argument));
+ }
+
+ private static <T> Resolved<T> read(Lookup lookup, QueueProperty<T> property,
+ QueuePath path, String label, Object argument) {
+ lookup.reset();
+ try {
+ T value = property.read(lookup, lookup.queuePrefix, path, label,
+ argument);
+ return Resolved.of(value, lookup.source(), lookup.sourceDetail());
+ } catch (RuntimeException e) {
Review Comment:
Nit: Maybe a trace level log would be nice.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
+ return CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE;
+ }
+ }
+
+ private static Resolved<Float> deriveAbsoluteCapacity(
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Map<String, Float>> siblingWeights, String label,
+ boolean legacyMode, boolean maximum) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> configured = maximum
+ ? queue.get(noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label)
+ : queue.get(noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ if (configured.isFailed()) {
+ return configured;
+ }
+ float parentValue = 1f;
+ if (parent != null) {
+ Resolved<Float> parentAbsolute = parent.get(
+ maximum ? ABSOLUTE_MAXIMUM_CAPACITY : ABSOLUTE_CAPACITY, label);
+ if (parentAbsolute == null) {
+ parentValue = 0f;
+ } else if (parentAbsolute.isFailed()) {
+ return parentAbsolute;
+ } else {
+ parentValue = parentAbsolute.getValue();
+ }
+ }
+ float capacity = configured.getValue() / 100;
+ String formula = (maximum ? "maximum-capacity" : "capacity")
+ + " x parent absolute";
+ if (maximum) {
+ // A non-positive maximum keeps the cleared value
+ return Resolved.of(capacity > 0f ? capacity * parentValue : 0f,
+ ValueSource.DERIVED, formula);
+ }
+ if (!legacyMode) {
+ return Resolved.of(capacity * parentValue, ValueSource.DERIVED, formula);
+ }
+ // Legacy weight normalization (AbstractParentQueue)
+ Resolved<Float> weight = queue.get(CAPACITY_WEIGHT, label);
+ if (weight.isFailed()) {
+ return weight;
+ }
+ float normalizedWeight;
+ if (parent == null) {
+ normalizedWeight = weight.getValue() > 0 ? 1f : 0f;
+ } else if (siblingWeights.isFailed()) {
+ return Resolved.failed(failureOf(siblingWeights),
+ siblingWeights.getSource(), siblingWeights.getSourceDetail());
+ } else {
+ Float sum = siblingWeights.getValue() == null ? null
+ : siblingWeights.getValue().get(label);
+ normalizedWeight = sum == null || Math.abs(sum) <= 1e-6 ? 0f
+ : weightOf(queue, weight.getValue()) / sum;
+ }
+ float effective = Math.max(capacity, normalizedWeight);
+ return Resolved.of(effective > 0f ? effective * parentValue : 0f,
+ ValueSource.DERIVED, "max(capacity, normalized weight)"
+ + " x parent absolute");
+ }
+
+ /**
+ * Sums the weights of siblings per label.
+ * @return label to the sum, a {@code null} map when no sibling uses
+ * weights, or the first weight failure
+ */
+ private static Resolved<Map<String, Float>> weightSums(
+ List<ResolvedQueueConfig> siblings) {
+ boolean weightMode = false;
+ Map<String, Float> sums = new HashMap<>();
+ for (ResolvedQueueConfig sibling : siblings) {
+ for (String label : sibling.getConfiguredNodeLabels()) {
+ Resolved<Float> weight = sibling.get(CAPACITY_WEIGHT, label);
+ if (weight == null) {
+ continue;
+ }
+ if (weight.isFailed()) {
+ return Resolved.failed(failureOf(weight), weight.getSource(),
+ weight.getSourceDetail());
+ }
+ float value = weightOf(sibling, weight.getValue());
+ weightMode |= value >= 0;
+ Float sum = sums.get(label);
+ sums.put(label, (sum == null ? 0f : sum) + Math.max(0, value));
+ }
+ }
+ return Resolved.of(weightMode ? sums : null, ValueSource.DERIVED, null);
+ }
+
+ /** Dynamic queues without a weight count as weight 1. */
+ private static float weightOf(ResolvedQueueConfig queue, float weight) {
+ return queue.isDynamic() && weight == -1f ? 1f : weight;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplications(
+ Function<String, String> conf, ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ Resolved<Integer> explicit = queue.get(MAXIMUM_APPLICATIONS);
+ if (explicit.isFailed() || explicit.getValue() >= 0) {
+ return explicit;
+ }
+ try {
+ if (queue.getKind() == Kind.PLAN) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ return Resolved.of(QueueApplicationLimits.scaleByAbsoluteCapacity(
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS,
+ absolute.getValue()), ValueSource.DERIVED,
+ "10000 x absolute capacity");
+ }
+ int globalPerQueue = readInt(conf,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION,
+ (int) CapacitySchedulerConfiguration.UNDEFINED);
+ int system = readInt(conf,
+ CapacitySchedulerConfiguration.MAXIMUM_SYSTEM_APPLICATIONS,
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS);
+ int base =
+ QueueApplicationLimits.baseMaximumApplications(globalPerQueue, system);
+ if (QueueApplicationLimits.usesBaseMaximumApplications(globalPerQueue,
+ isAbsoluteResourceType(queue, legacyMode))) {
+ return Resolved.of(base, ValueSource.GLOBAL,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION);
+ }
+ int maxApps = -1;
+ for (String label : queue.getConfiguredNodeLabels()) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY, label);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ maxApps = Math.max(maxApps, QueueApplicationLimits
+ .scaleByAbsoluteCapacity(base, absolute.getValue()));
+ }
+ return Resolved.of(maxApps, ValueSource.DERIVED,
+ "maximum applications x absolute capacity");
+ } catch (RuntimeException e) {
Review Comment:
Nit: Maybe a trace level log would be nice
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueConfigResolverParity.java:
##########
@@ -0,0 +1,1268 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.authorize.AccessControlList;
+import org.apache.hadoop.yarn.api.records.QueueACL;
+import org.apache.hadoop.yarn.api.records.ReservationACL;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.security.AccessType;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ConfigSnapshot;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueConfigResolver;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.Resolved;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolvedQueueConfig;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolvedQueueTree;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.TestQueueConfigResolver;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ValueSource;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.policy.FifoOrderingPolicy;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Parity between the resolver and trunk behavior.
+ * <ul>
+ * <li>Every {@code CapacitySchedulerConfiguration} per-queue getter returns
+ * the resolved value, or throws the resolved failure, for every queue of a
+ * set of configurations.</li>
+ * <li>Inherited and derived values equal the values of the queues a MockRM
+ * builds from the same configuration.</li>
+ * <li>For dynamic v1 and v2 queues created in a MockRM, the getters of the
+ * queue context configuration, which holds the template writes, return the
+ * values {@link QueueConfigResolver#resolveDynamicQueue} resolves.</li>
+ * </ul>
+ * For configurations trunk rejects at startup, the resolver must hold a
+ * failed value with the exception type and message that failed queue
+ * initialization.
+ */
+public class TestQueueConfigResolverParity {
+ /**
+ * Configurations that trunk rejects with a check (mixed capacity
+ * modes of siblings) rather than a parse failure, so the resolver has no
+ * failed value for them.
+ */
+ private static final Set<String> CHECK_REJECTIONS = new HashSet<>(
+ Arrays.asList("absolute with weight units", "absolute before percentage"));
+ private static final String P = CapacitySchedulerConfiguration.PREFIX;
+ private static final int GB = 1024;
+
+ /** Reads the value a getter returns for a queue and label. */
+ private interface Getter {
+ Object get(CapacitySchedulerConfiguration conf, QueuePath queue,
+ String label, ResolutionInputs inputs);
+ }
+
+ /** Properties a queue may inherit from its parent queue. */
+ private static final Set<QueueProperty<?>> INHERITED =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(USER_LIMIT,
+ USER_LIMIT_FACTOR, USER_WEIGHTS, STATE, ACCESSIBLE_NODE_LABELS,
+ DEFAULT_NODE_LABEL_EXPRESSION, QUEUE_ORDERING_POLICY,
+ MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME));
+ /** Properties templates do not write for dynamic queues. */
+ private static final Set<QueueProperty<?>> NOT_TEMPLATED =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(QUEUES, USER_WEIGHTS,
+ ACL_SUBMIT_RESERVATIONS, ACL_LIST_RESERVATIONS,
+ ACL_ADMINISTER_RESERVATIONS, ALLOW_ZERO_CAPACITY_SUM,
+ AUTO_CREATE_CHILD_QUEUE_ENABLED, AUTO_CREATE_CHILD_QUEUE_MAX_QUEUES,
+ AUTO_CREATE_CHILD_QUEUE_FAIL_ON_EXCEEDING_CAPACITY,
+ AUTO_CREATED_QUEUE_MANAGEMENT_POLICY_NAME, LEAF_QUEUE_TEMPLATE,
+ AUTO_QUEUE_CREATION_V2_ENABLED, AUTO_QUEUE_CREATION_V2_MAX_DEPTH,
+ AQC_V2_TEMPLATE, AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE,
+ RESERVABLE, RESERVATION_WINDOW_MS, AVERAGE_CAPACITY_PERCENT,
+ INSTANTANEOUS_MAX_CAPACITY_PERCENT, RESERVATION_ADMISSION_POLICY_NAME,
+ RESERVATION_AGENT, RESERVATION_PLANNER,
+ RESERVATION_MOVE_ON_EXPIRY_ENABLED, RESERVATION_ENFORCEMENT_WINDOW_MS,
+ SHOW_RESERVATIONS_AS_QUEUES));
+
+ private static final Map<QueueProperty<?>, Getter> GETTERS =
+ new LinkedHashMap<>();
+
+ static {
+ GETTERS.put(QUEUES, (c, q, l, i) -> c.getQueues(q));
+ GETTERS.put(CAPACITY, (c, q, l, i) -> c.getNonLabeledQueueCapacity(q));
+ GETTERS.put(CAPACITY_WEIGHT, (c, q, l, i) -> l.equals(NO_LABEL)
+ ? c.getNonLabeledQueueWeight(q) : c.getLabeledQueueWeight(q, l));
+ GETTERS.put(CAPACITY_IS_ABSOLUTE_RESOURCE, (c, q, l, i) ->
+ c.checkConfigTypeIsAbsoluteResource(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(MINIMUM_RESOURCE, (c, q, l, i) ->
+ c.getMinimumResourceRequirement(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(CAPACITY_VECTOR, (c, q, l, i) -> c
+ .parseConfiguredResourceVector(q, Collections.singleton(l)).get(l));
+ GETTERS.put(MAXIMUM_CAPACITY,
+ (c, q, l, i) -> c.getNonLabeledQueueMaximumCapacity(q));
+ GETTERS.put(MAXIMUM_RESOURCE, (c, q, l, i) ->
+ c.getMaximumResourceRequirement(l, q, QUEUE_RESOURCE_TYPES));
+ GETTERS.put(MAXIMUM_CAPACITY_VECTOR, (c, q, l, i) -> c
+ .parseConfiguredMaximumCapacityVector(q, Collections.singleton(l),
+ QueueCapacityVector.newInstance()).get(l));
+ GETTERS.put(LABELED_CAPACITY,
+ (c, q, l, i) -> c.getLabeledQueueCapacity(q, l));
+ GETTERS.put(LABELED_MAXIMUM_CAPACITY,
+ (c, q, l, i) -> c.getLabeledQueueMaximumCapacity(q, l));
+ GETTERS.put(MAXIMUM_AM_RESOURCE_PERCENT, (c, q, l, i) ->
+ c.getMaximumApplicationMasterResourcePerQueuePercent(q));
+ GETTERS.put(LABELED_MAXIMUM_AM_RESOURCE_PERCENT,
+ (c, q, l, i) -> c.getMaximumAMResourcePercentPerPartition(q, l));
+ GETTERS.put(MAXIMUM_APPLICATIONS,
+ (c, q, l, i) -> c.getMaximumApplicationsPerQueue(q));
+ GETTERS.put(USER_LIMIT, (c, q, l, i) -> c.getUserLimit(q));
+ GETTERS.put(USER_LIMIT_FACTOR, (c, q, l, i) -> c.getUserLimitFactor(q));
+ GETTERS.put(STATE, (c, q, l, i) -> c.getConfiguredState(q));
+ GETTERS.put(ACCESSIBLE_NODE_LABELS,
+ (c, q, l, i) -> c.getAccessibleNodeLabels(q));
+ GETTERS.put(DEFAULT_NODE_LABEL_EXPRESSION,
+ (c, q, l, i) -> c.getDefaultNodeLabelExpression(q));
+ GETTERS.put(ACL_SUBMIT_APPLICATIONS,
+ (c, q, l, i) -> c.getAcl(q, QueueACL.SUBMIT_APPLICATIONS));
+ GETTERS.put(ACL_ADMINISTER_QUEUE,
+ (c, q, l, i) -> c.getAcl(q, QueueACL.ADMINISTER_QUEUE));
+ GETTERS.put(ACL_APPLICATION_MAX_PRIORITY, (c, q, l, i) ->
+ c.getPriorityAcls(q, i.getClusterMaximumApplicationPriority()));
+ GETTERS.put(ACL_SUBMIT_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.SUBMIT_RESERVATIONS));
+ GETTERS.put(ACL_LIST_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.LIST_RESERVATIONS));
+ GETTERS.put(ACL_ADMINISTER_RESERVATIONS, (c, q, l, i) ->
+ c.getReservationAcls(q).get(ReservationACL.ADMINISTER_RESERVATIONS));
+ GETTERS.put(QUEUE_ORDERING_POLICY, (c, q, l, i) ->
+ c.getQueueOrderingPolicy(q, null).getConfigName());
+ GETTERS.put(PRIORITY, (c, q, l, i) -> c.getQueuePriority(q).getPriority());
+ GETTERS.put(DEFAULT_APPLICATION_PRIORITY,
+ (c, q, l, i) -> c.getDefaultApplicationPriorityConfPerQueue(q));
+ GETTERS.put(MAXIMUM_ALLOCATION_MB,
+ (c, q, l, i) -> c.getQueueMaximumAllocationMb(q));
+ GETTERS.put(MAXIMUM_ALLOCATION_VCORES,
+ (c, q, l, i) -> c.getQueueMaximumAllocationVcores(q));
+ GETTERS.put(PREEMPTION_DISABLED,
+ (c, q, l, i) -> c.getPreemptionDisabled(q, false));
+ GETTERS.put(INTRA_QUEUE_PREEMPTION_DISABLED,
+ (c, q, l, i) -> c.getIntraQueuePreemptionDisabled(q, false));
+ GETTERS.put(MAXIMUM_APPLICATION_LIFETIME,
+ (c, q, l, i) -> c.getMaximumLifetimePerQueue(q));
+ GETTERS.put(DEFAULT_APPLICATION_LIFETIME,
+ (c, q, l, i) -> c.getDefaultLifetimePerQueue(q));
+ GETTERS.put(MAX_PARALLEL_APPS,
+ (c, q, l, i) -> c.getMaxParallelAppsForQueue(q));
+ GETTERS.put(MULTI_NODE_SORTING_POLICY,
+ (c, q, l, i) -> c.getMultiNodesSortingAlgorithmPolicy(q));
+ GETTERS.put(ALLOW_ZERO_CAPACITY_SUM,
+ (c, q, l, i) -> c.getAllowZeroCapacitySum(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_ENABLED,
+ (c, q, l, i) -> c.isAutoCreateChildQueueEnabled(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_MAX_QUEUES,
+ (c, q, l, i) -> c.getAutoCreatedQueuesMaxChildQueuesLimit(q));
+ GETTERS.put(AUTO_CREATE_CHILD_QUEUE_FAIL_ON_EXCEEDING_CAPACITY,
+ (c, q, l, i) ->
+ c.getShouldFailAutoQueueCreationWhenGuaranteedCapacityExceeded(q));
+ GETTERS.put(AUTO_CREATED_QUEUE_MANAGEMENT_POLICY_NAME,
+ (c, q, l, i) -> c.getAutoCreatedQueueManagementPolicy(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_ENABLED,
+ (c, q, l, i) -> c.isAutoQueueCreationV2Enabled(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_MAX_QUEUES,
+ (c, q, l, i) -> c.getAutoCreatedQueuesV2MaxChildQueuesLimit(q));
+ GETTERS.put(AUTO_QUEUE_CREATION_V2_MAX_DEPTH,
+ (c, q, l, i) -> c.getMaximumAutoCreatedQueueDepth(q));
+ GETTERS.put(AUTO_QUEUE_AUTO_REMOVAL_ENABLED,
+ (c, q, l, i) -> c.isAutoExpiredDeletionEnabled(q));
+ GETTERS.put(AQC_V2_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getTemplateProperties());
+ GETTERS.put(AQC_V2_LEAF_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getLeafOnlyProperties());
+ GETTERS.put(AQC_V2_PARENT_TEMPLATE, (c, q, l, i) ->
+ new AutoCreatedQueueTemplate(c, q).getParentOnlyProperties());
+ GETTERS.put(RESERVABLE, (c, q, l, i) -> c.isReservable(q));
+ GETTERS.put(RESERVATION_WINDOW_MS,
+ (c, q, l, i) -> c.getReservationWindow(q));
+ GETTERS.put(AVERAGE_CAPACITY_PERCENT,
+ (c, q, l, i) -> c.getAverageCapacity(q));
+ GETTERS.put(INSTANTANEOUS_MAX_CAPACITY_PERCENT,
+ (c, q, l, i) -> c.getInstantaneousMaxCapacity(q));
+ GETTERS.put(RESERVATION_ADMISSION_POLICY_NAME,
+ (c, q, l, i) -> c.getReservationAdmissionPolicy(q));
+ GETTERS.put(RESERVATION_AGENT, (c, q, l, i) -> c.getReservationAgent(q));
+ GETTERS.put(RESERVATION_PLANNER, (c, q, l, i) -> c.getReplanner(q));
+ GETTERS.put(RESERVATION_MOVE_ON_EXPIRY_ENABLED,
+ (c, q, l, i) -> c.getMoveOnExpiry(q));
+ GETTERS.put(RESERVATION_ENFORCEMENT_WINDOW_MS,
+ (c, q, l, i) -> c.getEnforcementWindow(q));
+ GETTERS.put(SHOW_RESERVATIONS_AS_QUEUES,
+ (c, q, l, i) -> c.getShowReservationAsQueues(q));
+ }
+
+ /**
+ * Properties without a plain getter, and why: user weights, the maximum
+ * allocation, the ordering policy parameters and the v1 template are
+ * compared against live queues or their template writes instead; the
+ * application ordering policy getter builds the policy object.
+ */
+ private static final Set<QueueProperty<?>> WITHOUT_GETTER =
+ new HashSet<>(Arrays.<QueueProperty<?>>asList(USER_WEIGHTS,
+ MAXIMUM_ALLOCATION, ORDERING_POLICY_PARAMETERS, LEAF_QUEUE_TEMPLATE,
+ APP_ORDERING_POLICY));
+
+ @Test
+ public void testEveryPropertyIsCompared() {
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ assertTrue(GETTERS.containsKey(property)
+ || WITHOUT_GETTER.contains(property), property.toString());
+ }
+ }
+
+ @Test
+ public void testGettersMatchResolvedValues() throws Exception {
+ int compared = 0;
+ for (Map.Entry<String, Configuration> entry : corpus().entrySet()) {
+ CapacitySchedulerConfiguration conf =
+ new CapacitySchedulerConfiguration(entry.getValue(), false);
+ ResolutionInputs inputs = TestQueueConfigResolver.inputs(conf,
+ Collections.<DynamicQueue>emptyList());
+ ResolvedQueueTree tree =
+ QueueConfigResolver.resolve(conf.getConfigSnapshot(), inputs);
+ ConfiguredNodeLabels labels = new ConfiguredNodeLabels(conf);
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ if (queue.isDynamic()) {
+ // Without a scheduler nothing writes the template entries
+ continue;
+ }
+ compared += assertGetterParity(entry.getKey(), conf, inputs, queue);
+ Set<String> expectedLabels = queue.getQueuePath().isRoot()
+ ? labels.getAllConfiguredLabels()
+ : labels.getLabelsByQueue(queue.getQueuePath().getFullPath());
+ assertEquals(expectedLabels,
+ queue.get(CONFIGURED_NODE_LABELS).getValue(), entry.getKey());
+ }
+ }
+ assertTrue(compared > 1000, "compared " + compared + " values");
+ }
+
+ @Test
+ public void testRejectedConfigurationsHoldFailedValues() throws Exception {
+ for (Map.Entry<String, Configuration> entry : rejections().entrySet()) {
+ String name = entry.getKey();
+ CapacitySchedulerConfiguration conf =
+ new CapacitySchedulerConfiguration(entry.getValue(), false);
+ ResolutionInputs inputs = TestQueueConfigResolver.inputs(conf,
+ Collections.<DynamicQueue>emptyList());
+ ResolvedQueueTree tree =
+ QueueConfigResolver.resolve(conf.getConfigSnapshot(), inputs);
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ assertGetterParity(name, conf, inputs, queue);
+ }
+ Throwable rootCause = null;
+ MockRM rm = null;
+ try {
+ // Queues are parsed when the RM is initialized
+ rm = startRM(entry.getValue());
+ } catch (Exception e) {
+ rootCause = e;
+ while (rootCause.getCause() != null) {
+ rootCause = rootCause.getCause();
+ }
+ } finally {
+ if (rm != null) {
+ rm.stop();
+ }
+ }
+ assertNotNull(rootCause, name + " was accepted");
+ assertRejectionResolved(name, tree, rootCause);
+ }
+ }
+
+ /** The existing dynamic queues of a live hierarchy. */
+ private static List<DynamicQueue> dynamicQueues(CSQueue queue,
+ List<DynamicQueue> dynamic) {
+ if (queue instanceof AutoCreatedLeafQueue) {
+ dynamic.add(new DynamicQueue(queue.getQueuePathObject(), true, true));
+ } else if (!(queue instanceof ReservationQueue)
+ && ((AbstractCSQueue) queue).isDynamicQueue()) {
+ dynamic.add(new DynamicQueue(queue.getQueuePathObject(), false,
+ queue instanceof AbstractLeafQueue));
+ }
+ if (queue.getChildQueues() != null) {
+ for (CSQueue child : queue.getChildQueues()) {
+ dynamicQueues(child, dynamic);
+ }
+ }
+ return dynamic;
+ }
+
+ /**
+ * The exception that failed queue initialization must be a resolved
+ * failure, with the same type and message.
+ */
+ private static void assertRejectionResolved(String name,
+ ResolvedQueueTree tree, Throwable rootCause) {
+ List<String> failures = new ArrayList<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ for (Resolved<?> value : queue.explain().values()) {
+ if (value.isFailed()) {
+ try {
+ value.getValue();
+ } catch (RuntimeException e) {
+ failures.add(e.getClass().getName() + ": " + e.getMessage());
+ }
+ }
+ }
+ }
+ String expected = rootCause.getClass().getName() + ": "
+ + rootCause.getMessage();
+ if (CHECK_REJECTIONS.contains(name)) {
+ assertTrue(!failures.contains(expected), name);
Review Comment:
Nit: Maybe this can be assertFalse?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
Review Comment:
Nit: Maybe a trace level log would be nice
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
Review Comment:
Nit: Maybe a bit hard to read
```
Resolved<Float> capacity;
if (plan == null) {
capacity = Resolved.of(0f, ValueSource.DERIVED, null);
} else if (plan.isFailed()) {
capacity = plan;
} else {
capacity = Resolved.of(plan.getValue(), ValueSource.DERIVED, "plan absolute capacity x entitlement 1.0");
}
queue.put(ABSOLUTE_CAPACITY, label, capacity);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6525542482
Thanks @K0K0V0K @Hean-Chhinling @p-szucs for the reviews, merging to trunk.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6445560231
:confetti_ball: **+1 overall**
| Vote | Subsystem | Runtime | Logfile | Comment |
|:----:|----------:|--------:|:--------:|:-------:|
| +0 :ok: | reexec | 6m 56s | | Docker mode activated. |
|||| _ Prechecks _ |
| +1 :green_heart: | dupname | 0m 0s | | No case conflicting files found. |
| +0 :ok: | codespell | 0m 0s | | codespell was not available. |
| +0 :ok: | detsecrets | 0m 0s | | detect-secrets was not available. |
| +1 :green_heart: | @author | 0m 0s | | The patch does not contain any @author tags. |
| +1 :green_heart: | test4tests | 0m 0s | | The patch appears to include 3 new or modified test files. |
|||| _ trunk Compile Tests _ |
| +1 :green_heart: | mvninstall | 28m 19s | | trunk passed |
| +1 :green_heart: | compile | 0m 53s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | compile | 0m 54s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | checkstyle | 0m 54s | | trunk passed |
| +1 :green_heart: | mvnsite | 0m 55s | | trunk passed |
| +1 :green_heart: | javadoc | 0m 51s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 50s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 36s | | trunk passed |
| +1 :green_heart: | shadedclient | 16m 49s | | branch has no errors when building and testing our client artifacts. |
|||| _ Patch Compile Tests _ |
| +1 :green_heart: | mvninstall | 0m 34s | | the patch passed |
| +1 :green_heart: | compile | 0m 35s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javac | 0m 34s | | the patch passed |
| +1 :green_heart: | compile | 0m 36s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | javac | 0m 36s | | the patch passed |
| +1 :green_heart: | blanks | 0m 0s | | The patch has no blanks issues. |
| +1 :green_heart: | checkstyle | 0m 31s | | hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager: The patch generated 0 new + 39 unchanged - 2 fixed = 39 total (was 41) |
| +1 :green_heart: | mvnsite | 0m 36s | | the patch passed |
| +1 :green_heart: | javadoc | 0m 31s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 30s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 22s | | the patch passed |
| +1 :green_heart: | shadedclient | 16m 38s | | patch has no errors when building and testing our client artifacts. |
|||| _ Other Tests _ |
| +1 :green_heart: | unit | 92m 31s | | hadoop-yarn-server-resourcemanager in the patch passed. |
| +1 :green_heart: | asflicense | 0m 27s | | The patch does not generate ASF License warnings. |
| | | 174m 8s | | |
| Subsystem | Report/Notes |
|----------:|:-------------|
| Docker | ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/2/artifact/out/Dockerfile |
| GITHUB PR | https://github.com/apache/hadoop/pull/8845 |
| Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets |
| uname | Linux 657e51826ab8 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
| Build tool | maven |
| Personality | dev-support/bin/hadoop.sh |
| git revision | trunk / a2cd983b2fa53611e12a3c54f67f9f052471a385 |
| Default Java | Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/2/testReport/ |
| Max. process+thread count | 951 (vs. ulimit of 10000) |
| modules | C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager |
| Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/2/console |
| versions | git=2.43.0 maven=3.9.15 spotbugs=4.9.7 |
| Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
This message was automatically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4388582821
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
Review Comment:
The current check matches trunk on purpose. AbstractCSQueue and AutoCreatedLeafQueue both use parentNodeLabels.size() > 1, where a set of size 1 means “only the empty label”, so the template defines no real labels.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6502136090
Thanks @Hean-Chhinling for the check, updated based on the review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6506260977
:confetti_ball: **+1 overall**
| Vote | Subsystem | Runtime | Logfile | Comment |
|:----:|----------:|--------:|:--------:|:-------:|
| +0 :ok: | reexec | 7m 59s | | Docker mode activated. |
|||| _ Prechecks _ |
| +1 :green_heart: | dupname | 0m 0s | | No case conflicting files found. |
| +0 :ok: | codespell | 0m 0s | | codespell was not available. |
| +0 :ok: | detsecrets | 0m 0s | | detect-secrets was not available. |
| +1 :green_heart: | @author | 0m 0s | | The patch does not contain any @author tags. |
| +1 :green_heart: | test4tests | 0m 0s | | The patch appears to include 3 new or modified test files. |
|||| _ trunk Compile Tests _ |
| +1 :green_heart: | mvninstall | 32m 53s | | trunk passed |
| +1 :green_heart: | compile | 0m 58s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | compile | 0m 48s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | checkstyle | 0m 50s | | trunk passed |
| +1 :green_heart: | mvnsite | 0m 54s | | trunk passed |
| +1 :green_heart: | javadoc | 0m 57s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 47s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 36s | | trunk passed |
| +1 :green_heart: | shadedclient | 19m 26s | | branch has no errors when building and testing our client artifacts. |
|||| _ Patch Compile Tests _ |
| +1 :green_heart: | mvninstall | 0m 38s | | the patch passed |
| +1 :green_heart: | compile | 0m 37s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javac | 0m 37s | | the patch passed |
| +1 :green_heart: | compile | 0m 36s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | javac | 0m 36s | | the patch passed |
| +1 :green_heart: | blanks | 0m 1s | | The patch has no blanks issues. |
| +1 :green_heart: | checkstyle | 0m 37s | | hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager: The patch generated 0 new + 38 unchanged - 3 fixed = 38 total (was 41) |
| +1 :green_heart: | mvnsite | 0m 46s | | the patch passed |
| +1 :green_heart: | javadoc | 0m 34s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 30s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 27s | | the patch passed |
| +1 :green_heart: | shadedclient | 19m 43s | | patch has no errors when building and testing our client artifacts. |
|||| _ Other Tests _ |
| +1 :green_heart: | unit | 94m 5s | | hadoop-yarn-server-resourcemanager in the patch passed. |
| +1 :green_heart: | asflicense | 0m 26s | | The patch does not generate ASF License warnings. |
| | | 187m 16s | | |
| Subsystem | Report/Notes |
|----------:|:-------------|
| Docker | ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/3/artifact/out/Dockerfile |
| GITHUB PR | https://github.com/apache/hadoop/pull/8845 |
| Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets |
| uname | Linux d19129e512f9 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
| Build tool | maven |
| Personality | dev-support/bin/hadoop.sh |
| git revision | trunk / a170ea88945e72282f7b9d3ea3523b827ad72172 |
| Default Java | Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/3/testReport/ |
| Max. process+thread count | 903 (vs. ulimit of 10000) |
| modules | C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager |
| Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/3/console |
| versions | git=2.43.0 maven=3.9.15 spotbugs=4.9.7 |
| Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
This message was automatically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4388575077
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
+ return CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE;
+ }
+ }
+
+ private static Resolved<Float> deriveAbsoluteCapacity(
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Map<String, Float>> siblingWeights, String label,
+ boolean legacyMode, boolean maximum) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> configured = maximum
+ ? queue.get(noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label)
+ : queue.get(noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ if (configured.isFailed()) {
+ return configured;
+ }
+ float parentValue = 1f;
+ if (parent != null) {
+ Resolved<Float> parentAbsolute = parent.get(
+ maximum ? ABSOLUTE_MAXIMUM_CAPACITY : ABSOLUTE_CAPACITY, label);
+ if (parentAbsolute == null) {
+ parentValue = 0f;
+ } else if (parentAbsolute.isFailed()) {
+ return parentAbsolute;
+ } else {
+ parentValue = parentAbsolute.getValue();
+ }
+ }
+ float capacity = configured.getValue() / 100;
+ String formula = (maximum ? "maximum-capacity" : "capacity")
+ + " x parent absolute";
+ if (maximum) {
+ // A non-positive maximum keeps the cleared value
+ return Resolved.of(capacity > 0f ? capacity * parentValue : 0f,
+ ValueSource.DERIVED, formula);
+ }
+ if (!legacyMode) {
+ return Resolved.of(capacity * parentValue, ValueSource.DERIVED, formula);
+ }
+ // Legacy weight normalization (AbstractParentQueue)
+ Resolved<Float> weight = queue.get(CAPACITY_WEIGHT, label);
+ if (weight.isFailed()) {
+ return weight;
+ }
+ float normalizedWeight;
+ if (parent == null) {
+ normalizedWeight = weight.getValue() > 0 ? 1f : 0f;
+ } else if (siblingWeights.isFailed()) {
+ return Resolved.failed(failureOf(siblingWeights),
+ siblingWeights.getSource(), siblingWeights.getSourceDetail());
+ } else {
+ Float sum = siblingWeights.getValue() == null ? null
+ : siblingWeights.getValue().get(label);
+ normalizedWeight = sum == null || Math.abs(sum) <= 1e-6 ? 0f
+ : weightOf(queue, weight.getValue()) / sum;
+ }
+ float effective = Math.max(capacity, normalizedWeight);
+ return Resolved.of(effective > 0f ? effective * parentValue : 0f,
+ ValueSource.DERIVED, "max(capacity, normalized weight)"
+ + " x parent absolute");
+ }
+
+ /**
+ * Sums the weights of siblings per label.
+ * @return label to the sum, a {@code null} map when no sibling uses
+ * weights, or the first weight failure
+ */
+ private static Resolved<Map<String, Float>> weightSums(
+ List<ResolvedQueueConfig> siblings) {
+ boolean weightMode = false;
+ Map<String, Float> sums = new HashMap<>();
+ for (ResolvedQueueConfig sibling : siblings) {
+ for (String label : sibling.getConfiguredNodeLabels()) {
+ Resolved<Float> weight = sibling.get(CAPACITY_WEIGHT, label);
+ if (weight == null) {
+ continue;
+ }
+ if (weight.isFailed()) {
+ return Resolved.failed(failureOf(weight), weight.getSource(),
+ weight.getSourceDetail());
+ }
+ float value = weightOf(sibling, weight.getValue());
+ weightMode |= value >= 0;
+ Float sum = sums.get(label);
+ sums.put(label, (sum == null ? 0f : sum) + Math.max(0, value));
+ }
+ }
+ return Resolved.of(weightMode ? sums : null, ValueSource.DERIVED, null);
+ }
+
+ /** Dynamic queues without a weight count as weight 1. */
+ private static float weightOf(ResolvedQueueConfig queue, float weight) {
+ return queue.isDynamic() && weight == -1f ? 1f : weight;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplications(
+ Function<String, String> conf, ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ Resolved<Integer> explicit = queue.get(MAXIMUM_APPLICATIONS);
+ if (explicit.isFailed() || explicit.getValue() >= 0) {
+ return explicit;
+ }
+ try {
+ if (queue.getKind() == Kind.PLAN) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ return Resolved.of(QueueApplicationLimits.scaleByAbsoluteCapacity(
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS,
+ absolute.getValue()), ValueSource.DERIVED,
+ "10000 x absolute capacity");
+ }
+ int globalPerQueue = readInt(conf,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION,
+ (int) CapacitySchedulerConfiguration.UNDEFINED);
+ int system = readInt(conf,
+ CapacitySchedulerConfiguration.MAXIMUM_SYSTEM_APPLICATIONS,
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS);
+ int base =
+ QueueApplicationLimits.baseMaximumApplications(globalPerQueue, system);
+ if (QueueApplicationLimits.usesBaseMaximumApplications(globalPerQueue,
+ isAbsoluteResourceType(queue, legacyMode))) {
+ return Resolved.of(base, ValueSource.GLOBAL,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION);
+ }
+ int maxApps = -1;
+ for (String label : queue.getConfiguredNodeLabels()) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY, label);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ maxApps = Math.max(maxApps, QueueApplicationLimits
+ .scaleByAbsoluteCapacity(base, absolute.getValue()));
+ }
+ return Resolved.of(maxApps, ValueSource.DERIVED,
+ "maximum applications x absolute capacity");
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, null);
+ }
+ }
+
+ private static boolean isAbsoluteResourceType(ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (legacyMode) {
+ Resolved<Boolean> absolute = queue.get(CAPACITY_IS_ABSOLUTE_RESOURCE);
+ return absolute != null && !absolute.isFailed() && absolute.getValue();
+ }
+ Resolved<QueueCapacityVector> vector = queue.get(CAPACITY_VECTOR, none);
+ if (vector == null || vector.isFailed()) {
+ return false;
+ }
+ return QueueCapacityChecks.capacityConfigTypeOf(vector.getValue())
+ == CapacityConfigType.ABSOLUTE_RESOURCE;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplicationsPerUser(
+ ResolvedQueueConfig queue, Resolved<Integer> maxApps) {
+ Resolved<Float> userLimit = queue.get(USER_LIMIT);
+ Resolved<Float> userLimitFactor = queue.get(USER_LIMIT_FACTOR);
+ for (Resolved<?> input : java.util.Arrays.<Resolved<?>>asList(maxApps,
+ userLimit, userLimitFactor)) {
+ if (input.isFailed()) {
+ return failedInteger(input);
+ }
+ }
+ // A PlanQueue does not cap the per-user value at the queue value
+ int perUser = QueueApplicationLimits.maximumApplicationsPerUser(
+ maxApps.getValue(), userLimit.getValue(), userLimitFactor.getValue(),
+ queue.getKind() != Kind.PLAN);
+ return Resolved.of(perUser, ValueSource.DERIVED,
+ userLimitFactor.getValue() == -1 ? "maximum applications"
+ : "maximum applications x user limit x user limit factor");
+ }
+
+ private static <T> void readInto(ResolvedQueueConfig queue, Lookup lookup,
+ QueueProperty<T> property, String label, Object argument) {
+ queue.put(property, label,
+ read(lookup, property, queue.getQueuePath(), label, argument));
+ }
+
+ private static <T> Resolved<T> read(Lookup lookup, QueueProperty<T> property,
+ QueuePath path, String label, Object argument) {
+ lookup.reset();
+ try {
+ T value = property.read(lookup, lookup.queuePrefix, path, label,
+ argument);
+ return Resolved.of(value, lookup.source(), lookup.sourceDetail());
+ } catch (RuntimeException e) {
Review Comment:
Done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
+ return CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE;
+ }
+ }
+
+ private static Resolved<Float> deriveAbsoluteCapacity(
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Map<String, Float>> siblingWeights, String label,
+ boolean legacyMode, boolean maximum) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> configured = maximum
+ ? queue.get(noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label)
+ : queue.get(noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ if (configured.isFailed()) {
+ return configured;
+ }
+ float parentValue = 1f;
+ if (parent != null) {
+ Resolved<Float> parentAbsolute = parent.get(
+ maximum ? ABSOLUTE_MAXIMUM_CAPACITY : ABSOLUTE_CAPACITY, label);
+ if (parentAbsolute == null) {
+ parentValue = 0f;
+ } else if (parentAbsolute.isFailed()) {
+ return parentAbsolute;
+ } else {
+ parentValue = parentAbsolute.getValue();
+ }
+ }
+ float capacity = configured.getValue() / 100;
+ String formula = (maximum ? "maximum-capacity" : "capacity")
+ + " x parent absolute";
+ if (maximum) {
+ // A non-positive maximum keeps the cleared value
+ return Resolved.of(capacity > 0f ? capacity * parentValue : 0f,
+ ValueSource.DERIVED, formula);
+ }
+ if (!legacyMode) {
+ return Resolved.of(capacity * parentValue, ValueSource.DERIVED, formula);
+ }
+ // Legacy weight normalization (AbstractParentQueue)
+ Resolved<Float> weight = queue.get(CAPACITY_WEIGHT, label);
+ if (weight.isFailed()) {
+ return weight;
+ }
+ float normalizedWeight;
+ if (parent == null) {
+ normalizedWeight = weight.getValue() > 0 ? 1f : 0f;
+ } else if (siblingWeights.isFailed()) {
+ return Resolved.failed(failureOf(siblingWeights),
+ siblingWeights.getSource(), siblingWeights.getSourceDetail());
+ } else {
+ Float sum = siblingWeights.getValue() == null ? null
+ : siblingWeights.getValue().get(label);
+ normalizedWeight = sum == null || Math.abs(sum) <= 1e-6 ? 0f
+ : weightOf(queue, weight.getValue()) / sum;
+ }
+ float effective = Math.max(capacity, normalizedWeight);
+ return Resolved.of(effective > 0f ? effective * parentValue : 0f,
+ ValueSource.DERIVED, "max(capacity, normalized weight)"
+ + " x parent absolute");
+ }
+
+ /**
+ * Sums the weights of siblings per label.
+ * @return label to the sum, a {@code null} map when no sibling uses
+ * weights, or the first weight failure
+ */
+ private static Resolved<Map<String, Float>> weightSums(
+ List<ResolvedQueueConfig> siblings) {
+ boolean weightMode = false;
+ Map<String, Float> sums = new HashMap<>();
+ for (ResolvedQueueConfig sibling : siblings) {
+ for (String label : sibling.getConfiguredNodeLabels()) {
+ Resolved<Float> weight = sibling.get(CAPACITY_WEIGHT, label);
+ if (weight == null) {
+ continue;
+ }
+ if (weight.isFailed()) {
+ return Resolved.failed(failureOf(weight), weight.getSource(),
+ weight.getSourceDetail());
+ }
+ float value = weightOf(sibling, weight.getValue());
+ weightMode |= value >= 0;
+ Float sum = sums.get(label);
+ sums.put(label, (sum == null ? 0f : sum) + Math.max(0, value));
+ }
+ }
+ return Resolved.of(weightMode ? sums : null, ValueSource.DERIVED, null);
+ }
+
+ /** Dynamic queues without a weight count as weight 1. */
+ private static float weightOf(ResolvedQueueConfig queue, float weight) {
+ return queue.isDynamic() && weight == -1f ? 1f : weight;
+ }
+
+ private static Resolved<Integer> deriveMaximumApplications(
+ Function<String, String> conf, ResolvedQueueConfig queue,
+ boolean legacyMode) {
+ Resolved<Integer> explicit = queue.get(MAXIMUM_APPLICATIONS);
+ if (explicit.isFailed() || explicit.getValue() >= 0) {
+ return explicit;
+ }
+ try {
+ if (queue.getKind() == Kind.PLAN) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ return Resolved.of(QueueApplicationLimits.scaleByAbsoluteCapacity(
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS,
+ absolute.getValue()), ValueSource.DERIVED,
+ "10000 x absolute capacity");
+ }
+ int globalPerQueue = readInt(conf,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION,
+ (int) CapacitySchedulerConfiguration.UNDEFINED);
+ int system = readInt(conf,
+ CapacitySchedulerConfiguration.MAXIMUM_SYSTEM_APPLICATIONS,
+ CapacitySchedulerConfiguration.DEFAULT_MAXIMUM_SYSTEM_APPLICATIIONS);
+ int base =
+ QueueApplicationLimits.baseMaximumApplications(globalPerQueue, system);
+ if (QueueApplicationLimits.usesBaseMaximumApplications(globalPerQueue,
+ isAbsoluteResourceType(queue, legacyMode))) {
+ return Resolved.of(base, ValueSource.GLOBAL,
+ CapacitySchedulerConfiguration.QUEUE_GLOBAL_MAX_APPLICATION);
+ }
+ int maxApps = -1;
+ for (String label : queue.getConfiguredNodeLabels()) {
+ Resolved<Float> absolute = queue.get(ABSOLUTE_CAPACITY, label);
+ if (absolute.isFailed()) {
+ return failedInteger(absolute);
+ }
+ maxApps = Math.max(maxApps, QueueApplicationLimits
+ .scaleByAbsoluteCapacity(base, absolute.getValue()));
+ }
+ return Resolved.of(maxApps, ValueSource.DERIVED,
+ "maximum applications x absolute capacity");
+ } catch (RuntimeException e) {
Review Comment:
Done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
+ ? (plan == null ? Resolved.of(0f, ValueSource.DERIVED, null) : plan)
+ : Resolved.of(plan.getValue(), ValueSource.DERIVED,
+ "plan absolute capacity x entitlement 1.0"));
+ continue;
+ }
+ queue.put(ABSOLUTE_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, false));
+ queue.put(ABSOLUTE_MAXIMUM_CAPACITY, label, deriveAbsoluteCapacity(queue,
+ parent, siblingWeights, label, legacyMode, true));
+ }
+ if (EFFECTIVE_MAXIMUM_APPLICATIONS.getAppliesTo().contains(
+ queue.getKind())) {
+ Resolved<Integer> maxApps = deriveMaximumApplications(
+ snapshotLookup(tree.getSnapshot()), queue, legacyMode);
+ queue.put(EFFECTIVE_MAXIMUM_APPLICATIONS,
+ CommonNodeLabelsManager.NO_LABEL, maxApps);
+ queue.put(MAXIMUM_APPLICATIONS_PER_USER,
+ CommonNodeLabelsManager.NO_LABEL,
+ deriveMaximumApplicationsPerUser(queue, maxApps));
+ }
+ }
+
+ /** Queues read the legacy queue mode flag from their configuration. */
+ private static boolean isLegacyQueueMode(ConfigSnapshot snapshot) {
+ try {
+ return readBoolean(snapshotLookup(snapshot),
+ PREFIX + "legacy-queue-mode.enabled",
+ CapacitySchedulerConfiguration.DEFAULT_LEGACY_QUEUE_MODE);
+ } catch (RuntimeException e) {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4414896697
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueProperties.java:
##########
@@ -0,0 +1,950 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLGroup;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.QueueCapacityConfigParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.util.UnitsConversionUtil;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.*;
Review Comment:
done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(QueueConfigResolver.class);
+
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
Review Comment:
done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(QueueConfigResolver.class);
+
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.computeIfAbsent(queuePath, k -> {
+ Set<String> newLabels = new HashSet<>();
+ newLabels.add(RMNodeLabelsManager.NO_LABEL);
+ return newLabels;
+ });
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ LOG.trace("Failed to read the queue kind of {}", path, e);
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Map<String, Set<String>> configuredLabels =
+ tree.getConfiguredNodeLabels();
+ labels = labels(path.isRoot() ? allLabels(configuredLabels)
+ : labelsOf(configuredLabels, path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue. Like
+ // AbstractCSQueue and AutoCreatedLeafQueue, a template whose only label
+ // is the empty label does not count.
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ LOG.trace("Failed to read {} for {}", key, queue.getQueuePath(), e);
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
Review Comment:
done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java:
##########
Review Comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4388579688
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
+ value = Resolved.failed(e, ValueSource.TEMPLATE_V1, key);
+ }
+ } else {
+ // v2 uses the raw template text, type specific entries first
+ QueueProperty<Map<String, String>> typeSpecific =
+ queue.getKind() == Kind.LEAF ? AQC_V2_LEAF_TEMPLATE
+ : AQC_V2_PARENT_TEMPLATE;
+ for (QueueProperty<Map<String, String>> template
+ : java.util.Arrays.asList(typeSpecific, AQC_V2_TEMPLATE)) {
+ String raw = templateEntries(parent, template).get(acl.getName());
+ if (value == null && raw != null) {
+ value = Resolved.of(raw, ValueSource.TEMPLATE_V2,
+ template.getKey(parent.getQueuePath(), null) + acl.getName());
+ }
+ }
+ }
+ queue.put(acl, CommonNodeLabelsManager.NO_LABEL, value != null ? value
+ : Resolved.of(CapacitySchedulerConfiguration.NONE_ACL,
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+
+ /** v2 dynamic queues without a capacity vector get 1w and 100%. */
+ private static void resolveDynamicCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ Resolved<QueueCapacityVector> min = queue.get(CAPACITY_VECTOR, label);
+ if (!min.isFailed() && min.getValue().isEmpty()) {
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(1, ResourceUnitCapacityType.WEIGHT),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DEFAULT, DYNAMIC_QUEUE_DEFAULT));
+ }
+ }
+ }
+
+ /** PlanQueue vectors are replaced by the percentage capacities. */
+ private static void resolvePlanCapacityVectors(ResolvedQueueConfig queue,
+ Set<String> labels) {
+ for (String label : labels) {
+ boolean noLabel = label.equals(CommonNodeLabelsManager.NO_LABEL);
+ Resolved<Float> capacity = queue.get(
+ noLabel ? CAPACITY : LABELED_CAPACITY, label);
+ Resolved<Float> maximum = queue.get(
+ noLabel ? MAXIMUM_CAPACITY : LABELED_MAXIMUM_CAPACITY, label);
+ if (capacity.isFailed() || maximum.isFailed()) {
+ continue;
+ }
+ queue.put(CAPACITY_VECTOR, label, Resolved.of(QueueCapacityVector.of(
+ capacity.getValue() / 100 * 100, ResourceUnitCapacityType.PERCENTAGE),
+ ValueSource.DERIVED, CAPACITY.getKey(queue.getQueuePath(), label)));
+ queue.put(MAXIMUM_CAPACITY_VECTOR, label, Resolved.of(
+ QueueCapacityVector.of(maximum.getValue() / 100 * 100,
+ ResourceUnitCapacityType.PERCENTAGE), ValueSource.DERIVED,
+ MAXIMUM_CAPACITY.getKey(queue.getQueuePath(), label)));
+ }
+ }
+
+ /**
+ * Derived values: configured absolute capacities, the effective maximum
+ * applications and maximum applications per user, for a cluster that has
+ * resources. Effective resources and the values computed from them at
+ * runtime are not derived.
+ * @param extraSibling a queue that is not in the tree but is a sibling of
+ * the others, or {@code null}
+ */
+ private static void derive(ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ boolean legacyMode, Resolved<Map<String, Float>> siblingWeights) {
+ QueuePath path = queue.getQueuePath();
+ ResolvedQueueConfig parent =
+ path.isRoot() ? null : tree.get(path.getParentObject());
+ for (String label : queue.getConfiguredNodeLabels()) {
+ if (queue.getKind() == Kind.RESERVATION) {
+ // The default reservation queue's entitlement is the whole plan
+ Resolved<Float> plan = parent.get(ABSOLUTE_CAPACITY, label);
+ queue.put(ABSOLUTE_CAPACITY, label, plan == null || plan.isFailed()
Review Comment:
Done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
+ ? Resolved.<Set<String>>failed(labelFailure, ValueSource.DERIVED, null)
+ : labels(path.isRoot() ? allLabels(tree.getConfiguredNodeLabels())
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, false, labels, null);
+ tree.add(queue);
+ for (String child : children) {
+ resolveConfigured(tree, queue,
+ QueuePath.createFromQueues(path.getFullPath(), child),
+ dynamicParents, labelFailure);
+ }
+ }
+
+ /**
+ * Resolves a queue that receives template entries: a v1 auto-created leaf
+ * ({@code legacy}), a v2 dynamic leaf or parent, or a ReservationQueue,
+ * which takes the v2 path of its PlanQueue parent.
+ */
+ private static ResolvedQueueConfig resolveDynamic(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean legacy,
+ RuntimeException labelFailure) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ boolean leaf = kind != Kind.PARENT;
+ String childPrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, OverlayEntry> overlay = new LinkedHashMap<>();
+ if (legacy) {
+ Resolved<Map<String, String>> template = parent.get(LEAF_QUEUE_TEMPLATE);
+ if (template != null && !template.isFailed()) {
+ for (Map.Entry<String, String> entry
+ : template.getValue().entrySet()) {
+ String name = entry.getKey().replaceFirst(
+ AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, path.getLeafName());
+ overlay.put(name, new OverlayEntry(entry.getKey(),
+ entry.getValue(), ValueSource.TEMPLATE_V1));
+ }
+ }
+ } else {
+ if (leaf) {
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .USER_LIMIT_FACTOR, new OverlayEntry("-1.0"));
+ overlay.put(childPrefix + CapacitySchedulerConfiguration
+ .MAXIMUM_AM_RESOURCE_SUFFIX, new OverlayEntry("1.0"));
+ }
+ Map<String, String> typeSpecific = templateEntries(parent,
+ leaf ? AQC_V2_LEAF_TEMPLATE : AQC_V2_PARENT_TEMPLATE);
+ Map<String, String> common = templateEntries(parent, AQC_V2_TEMPLATE);
+ for (Map.Entry<String, String> entry : typeSpecific.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ leaf ? AutoCreatedQueueTemplate.AUTO_QUEUE_LEAF_TEMPLATE_PREFIX
+ : AutoCreatedQueueTemplate.AUTO_QUEUE_PARENT_TEMPLATE_PREFIX,
+ entry));
+ }
+ }
+ for (Map.Entry<String, String> entry : common.entrySet()) {
+ if (snapshot.getRaw(childPrefix + entry.getKey()) == null
+ && !typeSpecific.containsKey(entry.getKey())) {
+ overlay.put(childPrefix + entry.getKey(), v2Entry(snapshot, parent,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX, entry));
+ }
+ }
+ }
+ expandOverlay(snapshot, overlay);
+
+ // Labels are registered only from the exact template pseudo-queue
+ Resolved<Set<String>> labels;
+ if (labelFailure != null) {
+ labels = Resolved.failed(labelFailure, ValueSource.DERIVED, null);
+ } else {
+ Set<String> templateLabels = tree.getConfiguredNodeLabels().get(
+ parent.getQueuePath().getFullPath() + (legacy
+ ? LEAF_TEMPLATE_PSEUDO_QUEUE : V2_TEMPLATE_PSEUDO_QUEUE));
+ labels = labels(templateLabels != null && templateLabels.size() > 1
+ ? Collections.unmodifiableSet(new HashSet<>(templateLabels))
+ : labelsOf(tree.getConfiguredNodeLabels(), path.getFullPath()));
+ }
+ ResolvedQueueConfig queue =
+ resolveQueue(tree, parent, path, kind, true, labels, overlay);
+ // A PlanQueue is a managed parent, so its ReservationQueue takes the
+ // ACLs of its leaf-queue-template
+ resolveDynamicAcls(queue, parent, snapshot,
+ legacy || kind == Kind.RESERVATION);
+ if (kind == Kind.RESERVATION) {
+ // The plan's user limits replace the reservation queue's own
+ queue.put(USER_LIMIT, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT), parent));
+ queue.put(USER_LIMIT_FACTOR, CommonNodeLabelsManager.NO_LABEL,
+ inherit(parent.get(USER_LIMIT_FACTOR), parent));
+ } else if (!legacy) {
+ // v1 auto-created leaves are not dynamic queue objects, so they keep
+ // the vectors read from their path; their entitlement replaces them
+ resolveDynamicCapacityVectors(queue, queue.getConfiguredNodeLabels());
+ }
+ return queue;
+ }
+
+ /**
+ * @param labels the configured node labels of the queue; a failure to
+ * index them leaves only the empty label
+ */
+ private static ResolvedQueueConfig resolveQueue(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Kind kind, boolean dynamic,
+ Resolved<Set<String>> labeled, Map<String, OverlayEntry> overlay) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ Set<String> labels = labeled.isFailed() ? noLabel() : labeled.getValue();
+ ResolvedQueueConfig queue =
+ new ResolvedQueueConfig(path, kind, dynamic, labels);
+ queue.put(CONFIGURED_NODE_LABELS, CommonNodeLabelsManager.NO_LABEL,
+ labeled);
+ Lookup lookup = new Lookup(snapshot, overlay, path);
+
+ for (QueueProperty<?> property : ALL_PROPERTIES) {
+ if (SPECIAL.contains(property)
+ || !property.getAppliesTo().contains(kind)) {
+ continue;
+ }
+ if (property.isLabeled()) {
+ for (String label : labels) {
+ readInto(queue, lookup, property, label, null);
+ }
+ } else {
+ readInto(queue, lookup, property, CommonNodeLabelsManager.NO_LABEL,
+ null);
+ }
+ }
+ for (String label : labels) {
+ if (!label.equals(CommonNodeLabelsManager.NO_LABEL)) {
+ readInto(queue, lookup, LABELED_CAPACITY, label, null);
+ readInto(queue, lookup, LABELED_MAXIMUM_CAPACITY, label, null);
+ }
+ }
+ if (ACL_APPLICATION_MAX_PRIORITY.getAppliesTo().contains(kind)) {
+ readInto(queue, lookup, ACL_APPLICATION_MAX_PRIORITY,
+ CommonNodeLabelsManager.NO_LABEL,
+ tree.getInputs().getClusterMaximumApplicationPriority());
+ // Ordering policy parameters are iterated from the live configuration,
+ // which holds raw values and the template entries. The prefix query
+ // also returns the ordering-policy key itself, which is not a parameter.
+ String parameterPrefix = ORDERING_POLICY_PARAMETERS.getKey(path, null);
+ Map<String, String> parameters = new HashMap<>();
+ for (Map.Entry<String, String> entry : snapshot
+ .getRawPropertiesWithPrefix(parameterPrefix, true).entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue());
+ }
+ }
+ if (overlay != null) {
+ for (Map.Entry<String, OverlayEntry> entry : overlay.entrySet()) {
+ if (entry.getKey().startsWith(parameterPrefix)) {
+ parameters.put(entry.getKey().substring(parameterPrefix.length()),
+ entry.getValue().raw);
+ }
+ }
+ }
+ readMap(queue, lookup, ORDERING_POLICY_PARAMETERS, parameters,
+ Function.<String>identity());
+ }
+ if (AQC_V2_TEMPLATE.getAppliesTo().contains(kind)) {
+ resolveTemplates(queue, snapshot, path);
+ }
+ if (kind == Kind.PLAN) {
+ resolvePlanCapacityVectors(queue, labels);
+ }
+ resolveInherited(tree, queue, parent, lookup);
+ return queue;
+ }
+
+ /** PARENT steps, in the order queue setup evaluates them. */
+ private static void resolveInherited(ResolvedQueueTree tree,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent, Lookup lookup) {
+ ConfigSnapshot snapshot = tree.getSnapshot();
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+
+ // Node labels (QueueNodeLabelsSettings)
+ Resolved<Set<String>> accessible =
+ read(lookup, ACCESSIBLE_NODE_LABELS, path, none, null);
+ if (!accessible.isFailed() && accessible.getValue() == null
+ && parent != null) {
+ accessible = inherit(parent.get(ACCESSIBLE_NODE_LABELS), parent);
+ }
+ queue.put(ACCESSIBLE_NODE_LABELS, none, accessible);
+ Resolved<String> expression =
+ read(lookup, DEFAULT_NODE_LABEL_EXPRESSION, path, none, null);
+ Resolved<Set<String>> parentAccessible =
+ parent == null ? null : parent.get(ACCESSIBLE_NODE_LABELS);
+ if (!expression.isFailed() && expression.getValue() == null
+ && parent != null && !accessible.isFailed()
+ && accessible.getValue() != null && !parentAccessible.isFailed()
+ && accessible.getValue().containsAll(parentAccessible.getValue())) {
+ expression = inherit(parent.get(DEFAULT_NODE_LABEL_EXPRESSION), parent);
+ }
+ queue.put(DEFAULT_NODE_LABEL_EXPRESSION, none, expression);
+
+ // Maximum allocation (QueueAllocationSettings)
+ queue.put(MAXIMUM_ALLOCATION, none,
+ resolveMaximumAllocation(tree, queue, parent, lookup));
+
+ // Initial state (QueueStateHelper), DRAINING is inherited as STOPPED
+ Resolved<QueueState> state = read(lookup, STATE, path, none, null);
+ if (!state.isFailed() && state.getValue() == null) {
+ if (parent == null) {
+ state = Resolved.of(QueueState.RUNNING, ValueSource.DEFAULT, null);
+ } else {
+ Resolved<QueueState> parentState = parent.get(STATE);
+ state = parentState.isFailed() ? parentState : Resolved.of(
+ parentState.getValue() == QueueState.DRAINING
+ ? QueueState.STOPPED : parentState.getValue(),
+ ValueSource.PARENT, parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(STATE, none, state);
+
+ // User weights, unioned with the parent's; read from the snapshot only,
+ // since template entries are invisible to the user weight lookup. The
+ // entries map to their full keys, so that only the weight keys the
+ // reader picks are substituted, as UserWeights does
+ String weightPrefix = USER_WEIGHTS.getKey(path, null);
+ Map<String, String> weightKeys = new HashMap<>();
+ for (String key : snapshot.getRawPropertiesWithPrefix(weightPrefix, false)
+ .keySet()) {
+ weightKeys.put(key, weightPrefix + key);
+ }
+ Resolved<Map<String, Float>> weights = readMap(null, lookup, USER_WEIGHTS,
+ weightKeys, snapshotLookup(snapshot));
+ if (!weights.isFailed() && parent != null) {
+ Resolved<Map<String, Float>> parentWeights = parent.get(USER_WEIGHTS);
+ if (parentWeights.isFailed()) {
+ weights = parentWeights;
+ } else if (!parentWeights.getValue().isEmpty()) {
+ Map<String, Float> union = new HashMap<>(parentWeights.getValue());
+ union.putAll(weights.getValue());
+ weights = Resolved.of(Collections.unmodifiableMap(union),
+ weights.getValue().isEmpty() ? ValueSource.PARENT
+ : ValueSource.QUEUE,
+ weights.getValue().isEmpty()
+ ? parent.getQueuePath().getFullPath() : weightPrefix);
+ }
+ }
+ queue.put(USER_WEIGHTS, none, weights);
+
+ // Preemption (CSQueuePreemptionSettings)
+ queue.put(PREEMPTION_DISABLED, none, resolveDisabledFlag(snapshot, lookup,
+ queue, parent, PREEMPTION_DISABLED,
+ YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS));
+ queue.put(INTRA_QUEUE_PREEMPTION_DISABLED, none, resolveDisabledFlag(
+ snapshot, lookup, queue, parent, INTRA_QUEUE_PREEMPTION_DISABLED,
+ CapacitySchedulerConfiguration.INTRAQUEUE_PREEMPTION_ENABLED,
+ CapacitySchedulerConfiguration.DEFAULT_INTRAQUEUE_PREEMPTION_ENABLED));
+
+ // Lifetimes (QueueAppLifetimeAndLimitSettings)
+ Resolved<Long> maxLifetime =
+ read(lookup, MAXIMUM_APPLICATION_LIFETIME, path, none, null);
+ if (!maxLifetime.isFailed() && parent != null
+ && maxLifetime.getValue() < 0) {
+ maxLifetime = inherit(parent.get(MAXIMUM_APPLICATION_LIFETIME), parent);
+ }
+ queue.put(MAXIMUM_APPLICATION_LIFETIME, none, maxLifetime);
+ queue.put(DEFAULT_APPLICATION_LIFETIME, none,
+ resolveDefaultLifetime(lookup, queue, parent, maxLifetime));
+
+ // Queue ordering policy, the parent's policy is the default
+ if (QUEUE_ORDERING_POLICY.getAppliesTo().contains(queue.getKind())) {
+ Resolved<String> parentPolicy =
+ parent == null ? null : parent.get(QUEUE_ORDERING_POLICY);
+ Resolved<String> policy;
+ if (parentPolicy != null && parentPolicy.isFailed()) {
+ policy = parentPolicy;
+ } else {
+ policy = read(lookup, QUEUE_ORDERING_POLICY, path, none,
+ parentPolicy == null ? null : parentPolicy.getValue());
+ if (parentPolicy != null && policy.getSource() == ValueSource.DEFAULT) {
+ policy = Resolved.of(policy.getValue(), ValueSource.PARENT,
+ parent.getQueuePath().getFullPath());
+ }
+ }
+ queue.put(QUEUE_ORDERING_POLICY, none, policy);
+ }
+ }
+
+ private static Resolved<Resource> resolveMaximumAllocation(
+ ResolvedQueueTree tree, ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, Lookup lookup) {
+ QueuePath path = queue.getQueuePath();
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ Resolved<Resource> base = parent == null
+ ? Resolved.of(tree.getInputs().getClusterMaximumAllocation(),
+ ValueSource.GLOBAL, "cluster maximum allocation")
+ : inherit(parent.get(MAXIMUM_ALLOCATION), parent);
+ if (base.isFailed()) {
+ return base;
+ }
+ Resolved<Resource> queueMax =
+ read(lookup, MAXIMUM_ALLOCATION, path, none, null);
+ if (queueMax.isFailed()) {
+ return queueMax;
+ }
+ Resource maximumAllocation = Resources.clone(base.getValue());
+ if (queueMax.getValue() != Resources.none()) {
+ for (ResourceInformation ri : queueMax.getValue().getResources()) {
+ maximumAllocation.setResourceInformation(ri.getName(), ri);
+ }
+ return Resolved.of(maximumAllocation, queueMax.getSource(),
+ queueMax.getSourceDetail());
+ }
+ // Backward compatible per-resource keys, only when maximum-allocation
+ // is not set
+ Resolved<Long> memory = read(lookup, MAXIMUM_ALLOCATION_MB, path, none,
+ null);
+ if (memory.isFailed()) {
+ return Resolved.failed(failureOf(memory), memory.getSource(),
+ memory.getSourceDetail());
+ }
+ Resolved<Integer> vcores = read(lookup, MAXIMUM_ALLOCATION_VCORES, path,
+ none, null);
+ if (vcores.isFailed()) {
+ return Resolved.failed(failureOf(vcores), vcores.getSource(),
+ vcores.getSourceDetail());
+ }
+ Resolved<?> source = base;
+ if (memory.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setMemorySize(memory.getValue());
+ source = memory;
+ }
+ if (vcores.getValue() != CapacitySchedulerConfiguration.UNDEFINED) {
+ maximumAllocation.setVirtualCores(vcores.getValue());
+ source = vcores;
+ }
+ return Resolved.of(maximumAllocation, source.getSource(),
+ source.getSourceDetail());
+ }
+
+ private static Resolved<Boolean> resolveDisabledFlag(ConfigSnapshot snapshot,
+ Lookup lookup, ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ QueueProperty<Boolean> property, String gateKey, boolean gateDefault) {
+ try {
+ if (!readBoolean(snapshotLookup(snapshot), gateKey, gateDefault)) {
+ return Resolved.of(true, ValueSource.GLOBAL, gateKey);
+ }
+ } catch (RuntimeException e) {
+ return Resolved.failed(e, ValueSource.GLOBAL, gateKey);
+ }
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ if (parent == null) {
+ return read(lookup, property, queue.getQueuePath(), none, false);
+ }
+ Resolved<Boolean> inherited = parent.get(property);
+ if (inherited.isFailed()) {
+ return inherited;
+ }
+ Resolved<Boolean> own = read(lookup, property, queue.getQueuePath(), none,
+ inherited.getValue());
+ return own.getSource() == ValueSource.DEFAULT
+ ? inherit(inherited, parent) : own;
+ }
+
+ private static Resolved<Long> resolveDefaultLifetime(Lookup lookup,
+ ResolvedQueueConfig queue, ResolvedQueueConfig parent,
+ Resolved<Long> maxLifetime) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Long> own = read(lookup, DEFAULT_APPLICATION_LIFETIME, path,
+ CommonNodeLabelsManager.NO_LABEL, null);
+ if (own.isFailed()) {
+ return own;
+ }
+ long defaultLifetime = own.getValue();
+ boolean specified = defaultLifetime >= 0
+ || (parent != null && parent.isDefaultLifetimeSpecified());
+ queue.setDefaultLifetimeSpecified(specified);
+ if (parent == null) {
+ return own;
+ }
+ if (maxLifetime.isFailed()) {
+ // Queue setup reads the maximum first and fails on it
+ return Resolved.failed(failureOf(maxLifetime), ValueSource.DEFAULT,
+ maxLifetime.getSourceDetail());
+ }
+ Resolved<Long> parentDefault = parent.get(DEFAULT_APPLICATION_LIFETIME);
+ if (parentDefault.isFailed()) {
+ return parentDefault;
+ }
+ long myMax = maxLifetime.getValue();
+ boolean inherited = false;
+ if (defaultLifetime < 0) {
+ if (specified) {
+ defaultLifetime = Math.min(parentDefault.getValue(), myMax);
+ inherited = true;
+ } else {
+ defaultLifetime = myMax;
+ }
+ }
+ // The check of the default against the maximum is not a resolution step
+ if (defaultLifetime <= 0) {
+ defaultLifetime = myMax;
+ inherited = false;
+ }
+ if (defaultLifetime == own.getValue()) {
+ return own;
+ }
+ return inherited
+ ? Resolved.of(defaultLifetime, ValueSource.PARENT,
+ parent.getQueuePath().getFullPath())
+ : Resolved.of(defaultLifetime, ValueSource.DEFAULT,
+ MAXIMUM_APPLICATION_LIFETIME.getKey(path, null));
+ }
+
+ private static void resolveTemplates(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, QueuePath path) {
+ String none = CommonNodeLabelsManager.NO_LABEL;
+ String queuePrefix = QueuePrefixes.getQueuePrefix(path);
+ Map<String, String> leafTemplate = snapshot.getRawPropertiesWithPrefix(
+ queuePrefix + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX, true);
+ queue.put(LEAF_QUEUE_TEMPLATE, none, Resolved.of(leafTemplate,
+ leafTemplate.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ LEAF_QUEUE_TEMPLATE.getKey(path, null)));
+
+ Resolved<Integer> depth = queue.get(AUTO_QUEUE_CREATION_V2_MAX_DEPTH);
+ if (depth.isFailed()) {
+ RuntimeException failure = failureOf(depth);
+ queue.put(AQC_V2_TEMPLATE, none, Resolved.<Map<String, String>>failed(
+ failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_LEAF_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ queue.put(AQC_V2_PARENT_TEMPLATE, none, Resolved.<Map<String, String>>
+ failed(failure, depth.getSource(), depth.getSourceDetail()));
+ return;
+ }
+ List<QueuePath> owners = path.isInvalid()
+ ? Collections.<QueuePath>emptyList()
+ : path.getWildcardedQueuePaths(depth.getValue());
+ putTemplate(queue, snapshot, owners, AQC_V2_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_LEAF_TEMPLATE);
+ putTemplate(queue, snapshot, owners, AQC_V2_PARENT_TEMPLATE);
+ }
+
+ private static void putTemplate(ResolvedQueueConfig queue,
+ ConfigSnapshot snapshot, List<QueuePath> owners,
+ QueueProperty<Map<String, String>> property) {
+ // The most specific owner path wins
+ Map<String, String> entries = new HashMap<>();
+ for (QueuePath owner : owners) {
+ Map<String, String> ownerEntries = snapshot.getRawPropertiesWithPrefix(
+ QueuePrefixes.getQueuePrefix(owner) + property.getName(), false);
+ for (Map.Entry<String, String> entry : ownerEntries.entrySet()) {
+ if (!entry.getKey().isEmpty()) {
+ entries.putIfAbsent(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ queue.put(property, CommonNodeLabelsManager.NO_LABEL, Resolved.of(
+ Collections.unmodifiableMap(entries),
+ entries.isEmpty() ? ValueSource.DEFAULT : ValueSource.QUEUE,
+ property.getKey(queue.getQueuePath(), null)));
+ }
+
+ /**
+ * Dynamic queues take their queue ACLs from the parent's templates, with
+ * {@code " "} as the fallback, replacing the ACLs read from their own keys.
+ */
+ private static void resolveDynamicAcls(ResolvedQueueConfig queue,
+ ResolvedQueueConfig parent, ConfigSnapshot snapshot, boolean legacy) {
+ for (QueueProperty<String> acl : java.util.Arrays.asList(
+ ACL_SUBMIT_APPLICATIONS, ACL_ADMINISTER_QUEUE)) {
+ Resolved<String> value = null;
+ if (legacy) {
+ // v1 reads the substituted template value
+ String key = QueuePrefixes.getQueuePrefix(QueuePrefixes
+ .getAutoCreatedQueueObjectTemplateConfPrefix(
+ parent.getQueuePath())) + acl.getName();
+ try {
+ String text = snapshot.get(key);
+ if (text != null) {
+ value = Resolved.of(text, ValueSource.TEMPLATE_V1, key);
+ }
+ } catch (RuntimeException e) {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6279420808
:confetti_ball: **+1 overall**
| Vote | Subsystem | Runtime | Logfile | Comment |
|:----:|----------:|--------:|:--------:|:-------:|
| +0 :ok: | reexec | 0m 27s | | Docker mode activated. |
|||| _ Prechecks _ |
| +1 :green_heart: | dupname | 0m 0s | | No case conflicting files found. |
| +0 :ok: | codespell | 0m 1s | | codespell was not available. |
| +0 :ok: | detsecrets | 0m 1s | | detect-secrets was not available. |
| +1 :green_heart: | @author | 0m 0s | | The patch does not contain any @author tags. |
| +1 :green_heart: | test4tests | 0m 0s | | The patch appears to include 3 new or modified test files. |
|||| _ trunk Compile Tests _ |
| +1 :green_heart: | mvninstall | 28m 55s | | trunk passed |
| +1 :green_heart: | compile | 0m 49s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | compile | 0m 55s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | checkstyle | 0m 54s | | trunk passed |
| +1 :green_heart: | mvnsite | 0m 56s | | trunk passed |
| +1 :green_heart: | javadoc | 0m 51s | | trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 50s | | trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 34s | | trunk passed |
| +1 :green_heart: | shadedclient | 16m 59s | | branch has no errors when building and testing our client artifacts. |
|||| _ Patch Compile Tests _ |
| +1 :green_heart: | mvninstall | 0m 34s | | the patch passed |
| +1 :green_heart: | compile | 0m 31s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javac | 0m 31s | | the patch passed |
| +1 :green_heart: | compile | 0m 35s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | javac | 0m 35s | | the patch passed |
| +1 :green_heart: | blanks | 0m 0s | | The patch has no blanks issues. |
| +1 :green_heart: | checkstyle | 0m 30s | | hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager: The patch generated 0 new + 39 unchanged - 2 fixed = 39 total (was 41) |
| +1 :green_heart: | mvnsite | 0m 38s | | the patch passed |
| +1 :green_heart: | javadoc | 0m 28s | | the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu |
| +1 :green_heart: | javadoc | 0m 30s | | the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| +1 :green_heart: | spotbugs | 1m 20s | | the patch passed |
| +1 :green_heart: | shadedclient | 16m 10s | | patch has no errors when building and testing our client artifacts. |
|||| _ Other Tests _ |
| +1 :green_heart: | unit | 92m 25s | | hadoop-yarn-server-resourcemanager in the patch passed. |
| +1 :green_heart: | asflicense | 0m 25s | | The patch does not generate ASF License warnings. |
| | | 167m 39s | | |
| Subsystem | Report/Notes |
|----------:|:-------------|
| Docker | ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/1/artifact/out/Dockerfile |
| GITHUB PR | https://github.com/apache/hadoop/pull/8845 |
| Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets |
| uname | Linux de6f3f72504a 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
| Build tool | maven |
| Personality | dev-support/bin/hadoop.sh |
| git revision | trunk / 76ccaaf66c47ac1d2b6f1e076754993290b890a8 |
| Default Java | Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu |
| Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/1/testReport/ |
| Max. process+thread count | 952 (vs. ulimit of 10000) |
| modules | C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager |
| Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8845/1/console |
| versions | git=2.43.0 maven=3.9.15 spotbugs=4.9.7 |
| Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
This message was automatically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#issuecomment-6441759619
Thanks @K0K0V0K for the review, improved the PR based on your suggestions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4414894112
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueProperties.java:
##########
@@ -0,0 +1,950 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLGroup;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.QueueCapacityConfigParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.util.UnitsConversionUtil;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.*;
+
+/**
+ * One {@link QueueProperty} per per-queue configuration key of the Capacity
+ * Scheduler, and the parse rules they share with the
+ * {@code CapacitySchedulerConfiguration} getters.
+ * <p>
+ * A property that takes an argument documents it; {@code null} selects the
+ * default the queues use. Readers mirror the getters exactly, including
+ * which fallback keys are read before the queue key, so that the getters can
+ * delegate to them without changing values, exception types or messages.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueProperties {
+ /**
+ * The readers log under the loggers of the code they replace, so log
+ * output and log based tests stay the same.
+ */
+ private static final Logger LOG =
+ LoggerFactory.getLogger(CapacitySchedulerConfiguration.class);
+ private static final Logger CONF_LOG =
+ LoggerFactory.getLogger(Configuration.class);
+
+ private static final String WEIGHT_SUFFIX = "w";
+ private static final QueueCapacityConfigParser CAPACITY_PARSER =
+ CapacitySchedulerConfiguration.getQueueCapacityConfigParser();
+ private static final AppPriorityACLConfigurationParser PRIORITY_ACL_PARSER =
+ new AppPriorityACLConfigurationParser();
+ /** The resource types the queues pass to the absolute resource parser. */
+ public static final Set<String> QUEUE_RESOURCE_TYPES =
+ ImmutableSet.of("memory", "vcores");
+ /** Key of the scheduler-wide maximum-queue-depth fallback. */
+ public static final String GLOBAL_MAXIMUM_QUEUE_DEPTH =
+ PREFIX + MAXIMUM_QUEUE_DEPTH;
+ /** Key of the scheduler-wide multi-node sorting policy fallback. */
+ public static final String GLOBAL_MULTI_NODE_SORTING_POLICY =
+ MULTI_NODE_SORTING_POLICY_NAME;
+
+ /** The kinds of configured queues. */
+ private static final Set<Kind> ALL =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.LEAF, Kind.PLAN);
+ /**
+ * Every kind, ReservationQueue included; a ReservationQueue sets up every
+ * value except its capacities, which come from its entitlement.
+ */
+ private static final Set<Kind> SET_UP = EnumSet.allOf(Kind.class);
+ private static final Set<Kind> PARENTS = EnumSet.of(Kind.ROOT, Kind.PARENT);
+ /** Queues set up as parent queue objects, PlanQueue included. */
+ private static final Set<Kind> PARENT_OBJECTS =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.PLAN);
+ private static final Set<Kind> LEAVES =
+ EnumSet.of(Kind.LEAF, Kind.PLAN, Kind.RESERVATION);
+ /** Queues set up as leaf queue objects. */
+ private static final Set<Kind> LEAF =
+ EnumSet.of(Kind.LEAF, Kind.RESERVATION);
+ private static final Set<Kind> PLANS = EnumSet.of(Kind.PLAN);
+
+ private QueueProperties() {
+ }
+
+ // P01
Review Comment:
They were row IDs from a working list of properties I kept during the redesign, which isn’t part of the repo and forgot to remove them. I removed them and kept the descriptions.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1340 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
Review Comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4388588865
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
+ }
+ Kind kind;
+ if (path.isRoot()) {
+ kind = Kind.ROOT;
+ } else if (children.isEmpty() && !parentLike) {
+ kind = reservable ? Kind.PLAN : Kind.LEAF;
+ } else {
+ kind = Kind.PARENT;
+ }
+
+ Resolved<Set<String>> labels = labelFailure != null
Review Comment:
Done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
+ if (labels == null) {
+ labels = new HashSet<>();
+ labels.add(RMNodeLabelsManager.NO_LABEL);
+ labelsByQueue.put(queuePath, labels);
+ }
+ labels.add(labelName);
+ }
+ }
+ return labelsByQueue;
+ }
+
+ private static void resolveConfigured(ResolvedQueueTree tree,
+ ResolvedQueueConfig parent, QueuePath path, Set<QueuePath> dynamicParents,
+ RuntimeException labelFailure) {
+ Function<String, String> conf = snapshotLookup(tree.getSnapshot());
+ // The queue kind is decided as CapacitySchedulerQueueManager.parseQueue
+ // does; a value that fails to read counts as unset, its failure is kept
+ // in the resolved property
+ List<String> children = Collections.emptyList();
+ boolean parentLike = dynamicParents.contains(path);
+ boolean reservable = false;
+ try {
+ children = QUEUES.read(conf, path);
+ parentLike = parentLike
+ || AUTO_QUEUE_CREATION_V2_ENABLED.read(conf, path)
+ || AUTO_CREATE_CHILD_QUEUE_ENABLED.read(conf, path);
+ reservable = RESERVABLE.read(conf, path);
+ } catch (RuntimeException e) {
+ // Recorded when the queue's properties are read
Review Comment:
Done.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueConfigResolver.java:
##########
@@ -0,0 +1,1315 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationConstants;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AbstractCSQueue.CapacityConfigType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueApplicationLimits;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityChecks;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.ResolutionInputs.DynamicQueue;
+import org.apache.hadoop.yarn.util.resource.Resources;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties.*;
+
+/**
+ * Resolves the configuration of every queue from a {@link ConfigSnapshot},
+ * top-down, the way queue construction reads it today, without building
+ * queues.
+ * <p>
+ * Values are read through the {@link QueueProperty} readers that the
+ * {@code CapacitySchedulerConfiguration} getters use. For dynamic queues the
+ * snapshot is overlaid with the entries trunk writes into the live
+ * configuration before the queue reads it:
+ * <ul>
+ * <li>v2 dynamic leaves first get {@code user-limit-factor=-1} and
+ * {@code maximum-am-resource-percent=1.0}, unconditionally;</li>
+ * <li>v2 templates of the parent then write the type specific template
+ * ({@code leaf-template} or {@code parent-template}) and the generic
+ * {@code template}, skipping keys that are explicitly set for the queue in
+ * the snapshot, so a type specific entry from a wildcard path beats a generic
+ * entry from the exact path;</li>
+ * <li>a v1 auto-created leaf gets every {@code leaf-queue-template} entry of
+ * its managed parent, overwriting explicit keys.</li>
+ * </ul>
+ * Static queues never receive templates. Inheritance from the parent
+ * (PARENT steps) uses the parent's resolved values, and derived values are
+ * computed from resolved values only; effective resources, which depend on
+ * the cluster resource, are not resolved.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueConfigResolver {
+ static final QueuePath ROOT =
+ new QueuePath(CapacitySchedulerConfiguration.ROOT);
+
+ private static final String LABELS_PREFIX =
+ CapacitySchedulerConfiguration.ACCESSIBLE_NODE_LABELS;
+ private static final String DYNAMIC_LEAF_DEFAULT = "dynamic leaf default";
+ private static final String DYNAMIC_QUEUE_DEFAULT = "dynamic queue default";
+ private static final String LEAF_TEMPLATE_PSEUDO_QUEUE =
+ DOT + AUTO_CREATED_LEAF_QUEUE_TEMPLATE_PREFIX;
+ private static final String V2_TEMPLATE_PSEUDO_QUEUE = DOT
+ + AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.substring(0,
+ AutoCreatedQueueTemplate.AUTO_QUEUE_TEMPLATE_PREFIX.length() - 1);
+
+ /** Properties resolved by dedicated code instead of a plain read. */
+ private static final Set<QueueProperty<?>> SPECIAL = new HashSet<>(
+ java.util.Arrays.<QueueProperty<?>>asList(LABELED_CAPACITY,
+ LABELED_MAXIMUM_CAPACITY, USER_WEIGHTS, STATE,
+ ACCESSIBLE_NODE_LABELS, DEFAULT_NODE_LABEL_EXPRESSION,
+ ACL_APPLICATION_MAX_PRIORITY, QUEUE_ORDERING_POLICY,
+ ORDERING_POLICY_PARAMETERS, MAXIMUM_ALLOCATION, PREEMPTION_DISABLED,
+ INTRA_QUEUE_PREEMPTION_DISABLED, MAXIMUM_APPLICATION_LIFETIME,
+ DEFAULT_APPLICATION_LIFETIME, LEAF_QUEUE_TEMPLATE, AQC_V2_TEMPLATE,
+ AQC_V2_LEAF_TEMPLATE, AQC_V2_PARENT_TEMPLATE));
+
+ private QueueConfigResolver() {
+ }
+
+ /**
+ * Resolves every configured queue and every existing dynamic queue.
+ * @param snapshot the configuration
+ * @param inputs what the scheduler holds outside the configuration
+ * @return the resolved tree
+ */
+ public static ResolvedQueueTree resolve(ConfigSnapshot snapshot,
+ ResolutionInputs inputs) {
+ Map<String, Set<String>> labels;
+ RuntimeException labelFailure = null;
+ try {
+ labels = configuredNodeLabelsByQueue(snapshot);
+ } catch (RuntimeException e) {
+ labels = Collections.emptyMap();
+ labelFailure = e;
+ }
+ ResolvedQueueTree tree = new ResolvedQueueTree(snapshot, inputs, labels);
+
+ Set<QueuePath> dynamicParents = new HashSet<>();
+ for (DynamicQueue queue : inputs.getDynamicQueues()) {
+ if (!queue.isLeaf()) {
+ dynamicParents.add(queue.getPath());
+ }
+ }
+ resolveConfigured(tree, null, ROOT, dynamicParents, labelFailure);
+
+ // Existing dynamic queues that are not configured keep their dynamic
+ // nature; configured ones were turned static above
+ List<DynamicQueue> dynamicQueues =
+ new ArrayList<>(inputs.getDynamicQueues());
+ Collections.sort(dynamicQueues, new Comparator<DynamicQueue>() {
+ @Override
+ public int compare(DynamicQueue a, DynamicQueue b) {
+ return Integer.compare(a.getPath().getPathComponents().length,
+ b.getPath().getPathComponents().length);
+ }
+ });
+ for (DynamicQueue queue : dynamicQueues) {
+ QueuePath path = queue.getPath();
+ ResolvedQueueConfig parent = path.isRoot() ? null
+ : tree.get(path.getParentObject());
+ if (tree.get(path) == null && parent != null) {
+ tree.add(resolveDynamic(tree, parent, path,
+ queue.isLeaf() ? Kind.LEAF : Kind.PARENT,
+ queue.isLegacyAutoCreated(), labelFailure));
+ }
+ }
+
+ // The default ReservationQueue of every PlanQueue
+ for (ResolvedQueueConfig queue : new ArrayList<>(tree.getQueues())) {
+ if (queue.getKind() == Kind.PLAN) {
+ QueuePath path = QueuePath.createFromQueues(
+ queue.getQueuePath().getFullPath(), queue.getQueuePath()
+ .getLeafName() + ReservationConstants.DEFAULT_QUEUE_SUFFIX);
+ tree.add(resolveDynamic(tree, queue, path, Kind.RESERVATION, false,
+ labelFailure));
+ }
+ }
+
+ boolean legacyMode = isLegacyQueueMode(snapshot);
+ Map<QueuePath, Resolved<Map<String, Float>>> weightSums = new HashMap<>();
+ for (ResolvedQueueConfig queue : tree.getQueues()) {
+ QueuePath path = queue.getQueuePath();
+ Resolved<Map<String, Float>> sums = null;
+ if (!path.isRoot()) {
+ sums = weightSums.get(path.getParentObject());
+ if (sums == null) {
+ sums = weightSums(tree.getChildren(path.getParentObject()));
+ weightSums.put(path.getParentObject(), sums);
+ }
+ }
+ derive(tree, queue, legacyMode, sums);
+ }
+ return tree;
+ }
+
+ /**
+ * Resolves a dynamic queue that does not exist yet, as it would be set up
+ * if it were created now under its parent in the tree. A leaf under a
+ * managed parent is resolved as a v1 auto-created leaf.
+ * @param tree the resolved tree
+ * @param path the path of the new queue
+ * @param leaf whether the new queue is a leaf
+ * @return the resolved configuration of the queue, not added to the tree
+ * @throws IllegalArgumentException if the parent is not in the tree
+ */
+ public static ResolvedQueueConfig resolveDynamicQueue(ResolvedQueueTree tree,
+ QueuePath path, boolean leaf) {
+ ResolvedQueueConfig parent = tree.get(path.getParentObject());
+ if (parent == null) {
+ throw new IllegalArgumentException("Parent of " + path
+ + " is not in the resolved tree");
+ }
+ boolean legacy = leaf && isManagedParent(parent);
+ Resolved<Set<String>> rootLabels =
+ tree.getRoot().get(CONFIGURED_NODE_LABELS);
+ ResolvedQueueConfig queue = resolveDynamic(tree, parent, path,
+ leaf ? Kind.LEAF : Kind.PARENT, legacy,
+ rootLabels.isFailed() ? failureOf(rootLabels) : null);
+ List<ResolvedQueueConfig> siblings =
+ new ArrayList<>(tree.getChildren(parent.getQueuePath()));
+ siblings.add(queue);
+ derive(tree, queue, isLegacyQueueMode(tree.getSnapshot()),
+ weightSums(siblings));
+ return queue;
+ }
+
+ /**
+ * Indexes the labels of every queue path that has
+ * {@code <path>.accessible-node-labels.<label>.<property>} keys, including
+ * template pseudo-queues; every indexed path also gets the empty label.
+ * @param snapshot the configuration
+ * @return queue path to its configured labels
+ * @throws StringIndexOutOfBoundsException for a key that ends right after
+ * the label
+ */
+ public static Map<String, Set<String>> configuredNodeLabelsByQueue(
+ ConfigSnapshot snapshot) {
+ Map<String, Set<String>> labelsByQueue = new HashMap<>();
+ Map<String, String> schedulerEntries =
+ snapshot.getRawPropertiesWithPrefix(PREFIX, false);
+ for (String key : schedulerEntries.keySet()) {
+ // Consider all keys that have the accessible-node-labels prefix,
+ // excluding <queue-path>.accessible-node-labels itself
+ if (key.contains(LABELS_PREFIX + DOT)) {
+ int labelStartIdx = key.indexOf(LABELS_PREFIX)
+ + LABELS_PREFIX.length() + 1;
+ int labelEndIndx = key.indexOf('.', labelStartIdx);
+ String labelName = key.substring(labelStartIdx, labelEndIndx);
+ String queuePath =
+ key.substring(0, key.indexOf(LABELS_PREFIX) - 1);
+ Set<String> labels = labelsByQueue.get(queuePath);
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "Hean-Chhinling (via GitHub)" <gi...@apache.org>.
Hean-Chhinling commented on code in PR #8845:
URL: https://github.com/apache/hadoop/pull/8845#discussion_r4421896912
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/resolver/QueueProperties.java:
##########
@@ -0,0 +1,950 @@
+/**
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.QueueState;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLConfigurationParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AppPriorityACLGroup;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueTemplate;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.QueueCapacityConfigParser;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+import org.apache.hadoop.yarn.util.UnitsConversionUtil;
+import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.*;
+
+/**
+ * One {@link QueueProperty} per per-queue configuration key of the Capacity
+ * Scheduler, and the parse rules they share with the
+ * {@code CapacitySchedulerConfiguration} getters.
+ * <p>
+ * A property that takes an argument documents it; {@code null} selects the
+ * default the queues use. Readers mirror the getters exactly, including
+ * which fallback keys are read before the queue key, so that the getters can
+ * delegate to them without changing values, exception types or messages.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class QueueProperties {
+ /**
+ * The readers log under the loggers of the code they replace, so log
+ * output and log based tests stay the same.
+ */
+ private static final Logger LOG =
+ LoggerFactory.getLogger(CapacitySchedulerConfiguration.class);
+ private static final Logger CONF_LOG =
+ LoggerFactory.getLogger(Configuration.class);
+
+ private static final String WEIGHT_SUFFIX = "w";
+ private static final QueueCapacityConfigParser CAPACITY_PARSER =
+ CapacitySchedulerConfiguration.getQueueCapacityConfigParser();
+ private static final AppPriorityACLConfigurationParser PRIORITY_ACL_PARSER =
+ new AppPriorityACLConfigurationParser();
+ /** The resource types the queues pass to the absolute resource parser. */
+ public static final Set<String> QUEUE_RESOURCE_TYPES =
+ ImmutableSet.of("memory", "vcores");
+ /** Key of the scheduler-wide maximum-queue-depth fallback. */
+ public static final String GLOBAL_MAXIMUM_QUEUE_DEPTH =
+ PREFIX + MAXIMUM_QUEUE_DEPTH;
+ /** Key of the scheduler-wide multi-node sorting policy fallback. */
+ public static final String GLOBAL_MULTI_NODE_SORTING_POLICY =
+ MULTI_NODE_SORTING_POLICY_NAME;
+
+ /** The kinds of configured queues. */
+ private static final Set<Kind> ALL =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.LEAF, Kind.PLAN);
+ /**
+ * Every kind, ReservationQueue included; a ReservationQueue sets up every
+ * value except its capacities, which come from its entitlement.
+ */
+ private static final Set<Kind> SET_UP = EnumSet.allOf(Kind.class);
+ private static final Set<Kind> PARENTS = EnumSet.of(Kind.ROOT, Kind.PARENT);
+ /** Queues set up as parent queue objects, PlanQueue included. */
+ private static final Set<Kind> PARENT_OBJECTS =
+ EnumSet.of(Kind.ROOT, Kind.PARENT, Kind.PLAN);
+ private static final Set<Kind> LEAVES =
+ EnumSet.of(Kind.LEAF, Kind.PLAN, Kind.RESERVATION);
+ /** Queues set up as leaf queue objects. */
+ private static final Set<Kind> LEAF =
+ EnumSet.of(Kind.LEAF, Kind.RESERVATION);
+ private static final Set<Kind> PLANS = EnumSet.of(Kind.PLAN);
+
+ private QueueProperties() {
+ }
+
+ // P01
Review Comment:
I see..thank you, Beni!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org
Re: [PR] YARN-12015. Add a Capacity Scheduler queue configuration resolver with explicit inheritance and value sources [hadoop]
Posted by "brumi1024 (via GitHub)" <gi...@apache.org>.
brumi1024 merged PR #8845:
URL: https://github.com/apache/hadoop/pull/8845
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org