Hean-Chhinling commented on code in PR #8897:
URL: https://github.com/apache/hadoop/pull/8897#discussion_r4465352666


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerResolvedConstruction.java:
##########
@@ -0,0 +1,214 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.security.AccessType;
+import org.apache.hadoop.yarn.security.YarnAuthorizationProvider;
+import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
+import org.apache.hadoop.yarn.server.resourcemanager.NodeAttributeTestUtils;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperties;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.resolver.QueueProperty.Kind;
+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.ValueSource;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Queues are set up from the resolved configuration that the queue context
+ * resolves once per (re)initialization, and queues created at runtime are
+ * resolved against it.
+ */
+public class TestCapacitySchedulerResolvedConstruction {
+
+  private MockRM rm;
+
+  @AfterEach
+  public void tearDown() {
+    if (rm != null) {
+      rm.stop();
+      rm = null;
+    }
+    YarnAuthorizationProvider.destroy();
+  }
+
+  private static CapacitySchedulerConfiguration configuration() {
+    CapacitySchedulerConfiguration csConf =
+        new CapacitySchedulerConfiguration();
+    csConf.set(PREFIX + "root.queues", "a,m,plan");
+    csConf.set(PREFIX + "root.a.capacity", "40");
+    csConf.set(PREFIX + "root.m.capacity", "40");
+    csConf.set(PREFIX + "root.plan.capacity", "20");
+    csConf.set(PREFIX + "root.a.queues", "a1");
+    csConf.set(PREFIX + "root.a.a1.capacity", "100");
+    csConf.set(PREFIX + "root.a.a1.maximum-application-lifetime", "50");
+    csConf.set(PREFIX + "root.a.maximum-application-lifetime", "100");
+    csConf.set(PREFIX + "root.a.accessible-node-labels", "*");
+    // v2 auto queue creation below root.a, which only works with weights
+    csConf.setBoolean(PREFIX + "root.a.auto-queue-creation-v2.enabled", true);
+    csConf.set(PREFIX + "root.a.auto-queue-creation-v2.template.priority",
+        "3");
+    csConf.set(PREFIX + "root.a.auto-queue-creation-v2.leaf-template"
+        + ".user-limit-factor", "2");
+    // A v1 managed parent
+    csConf.setBoolean(PREFIX + "root.m.auto-create-child-queue.enabled", true);
+    csConf.set(PREFIX + "root.m.leaf-queue-template.capacity", "10");
+    csConf.set(PREFIX + "root.m.leaf-queue-template.acl_submit_applications",
+        "alice");
+    // A plan queue
+    csConf.setBoolean(PREFIX + "root.plan.reservable", true);
+    csConf.set(PREFIX + "root.plan.user-limit-factor", "3");
+    csConf.set(PREFIX + "root.plan.minimum-user-limit-percent", "50");
+    return csConf;
+  }
+
+  private CapacityScheduler start(CapacitySchedulerConfiguration csConf)
+      throws Exception {
+    YarnConfiguration conf = NodeAttributeTestUtils.getRandomDirConf(csConf);
+    conf.set(YarnConfiguration.RM_SCHEDULER,
+        CapacityScheduler.class.getName());
+    rm = new MockRM(conf);
+    rm.start();
+    return (CapacityScheduler) rm.getResourceScheduler();
+  }
+
+  @Test
+  public void testResolvedOncePerRefresh() throws Exception {
+    CapacityScheduler cs = start(configuration());
+    CapacitySchedulerQueueContext queueContext = cs.getQueueContext();
+    ResolvedQueueTree tree = queueContext.getResolvedQueueTree();
+    assertNotNull(tree);
+    assertEquals(Kind.ROOT, tree.getRoot().getKind());
+    assertEquals(Kind.PLAN, tree.get(new QueuePath("root.plan")).getKind());
+
+    // The settings take the inherited values from the resolved tree
+    AbstractCSQueue a1 = (AbstractCSQueue) cs.getQueue("root.a.a1");
+    ResolvedQueueConfig resolved = tree.get(a1.getQueuePathObject());
+    assertEquals(ValueSource.PARENT,
+        resolved.get(QueueProperties.ACCESSIBLE_NODE_LABELS).getSource());
+    assertEquals(resolved.get(QueueProperties.ACCESSIBLE_NODE_LABELS)
+        .getValue(), a1.getAccessibleNodeLabels());
+    assertEquals(50L, a1.getMaximumApplicationLifetime());
+    assertEquals(50L, a1.getDefaultApplicationLifetime());
+
+    cs.reinitialize(cs.getConfiguration(), rm.getRMContext());
+    ResolvedQueueTree refreshed = queueContext.getResolvedQueueTree();
+    assertNotSame(tree, refreshed);
+    assertSame(cs.getQueue("root.a.a1"), a1);
+    assertEquals(refreshed.get(a1.getQueuePathObject())
+        .get(QueueProperties.ACCESSIBLE_NODE_LABELS).getValue(),
+        a1.getAccessibleNodeLabels());
+  }
+
+  @Test
+  public void testDynamicQueuesResolvedAgainstInstalledTree()
+      throws Exception {
+    CapacitySchedulerConfiguration csConf = configuration();
+    csConf.setLegacyQueueModeEnabled(false);
+    CapacityScheduler cs = start(csConf);
+    CapacitySchedulerQueueContext queueContext = cs.getQueueContext();
+    ResolvedQueueTree tree = queueContext.getResolvedQueueTree();
+    QueuePath parentPath = new QueuePath("root.a.p");
+    QueuePath leafPath = new QueuePath("root.a.p.l");
+    assertEquals(null, tree.get(parentPath));

Review Comment:
   Nit: maybe we could use assertNull() here



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/AbstractCSQueue.java:
##########
@@ -365,27 +402,36 @@ protected void setupQueueConfigs(Resource 
clusterResource) throws
 
       // Setup queue's maximumAllocation respecting the global
       // and the queue settings
-      this.queueAllocationSettings.setupMaximumAllocation(configuration, 
getQueuePathObject(),
-          parent);
+      this.queueAllocationSettings.setupMaximumAllocation(configuration, 
resolved,
+          getQueuePathObject());
 
       // Initialize the queue state based on previous state, configured state
       // and its parent state
       QueueStateHelper.setQueueState(this);
 
       authorizer = YarnAuthorizationProvider.getInstance(configuration);
 
-      this.userWeights = getUserWeightsFromHierarchy();
+      // The resolved weights are the union of the queue's and its ancestors'
+      this.userWeights = UserWeights.createFrom(
+          resolved.get(QueueProperties.USER_WEIGHTS).getValue());
 
       this.reservationsContinueLooking =
           configuration.getReservationContinueLook();
 
-      this.configuredCapacityVectors = configuration
-          .parseConfiguredResourceVector(queuePath,
-              this.queueNodeLabelsSettings.getConfiguredNodeLabels());
-      this.configuredMaxCapacityVectors = configuration
-          .parseConfiguredMaximumCapacityVector(queuePath,
-              this.queueNodeLabelsSettings.getConfiguredNodeLabels(),
-              QueueCapacityVector.newInstance());
+      this.configuredCapacityVectors = new HashMap<>();
+      this.configuredMaxCapacityVectors = new HashMap<>();
+      for (final String label : 
queueNodeLabelsSettings.getConfiguredNodeLabels()) {
+        configuredCapacityVectors.put(label, 
CSQueueUtils.getResolvedValue(resolved,
+            QueueProperties.CAPACITY_VECTOR, label,
+            () -> configuration.parseConfiguredResourceVector(queuePath,
+                Collections.singleton(label)).get(label)));
+      }
+      for (final String label : 
queueNodeLabelsSettings.getConfiguredNodeLabels()) {
+        configuredMaxCapacityVectors.put(label, 
CSQueueUtils.getResolvedValue(resolved,
+            QueueProperties.MAXIMUM_CAPACITY_VECTOR, label,
+            () -> configuration.parseConfiguredMaximumCapacityVector(queuePath,
+                Collections.singleton(label), 
QueueCapacityVector.newInstance()).get(label)));
+      }

Review Comment:
   Nits: These two loops look like they loop on the same thing. Maybe we could 
combine them into one for loop?



##########
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:
##########


Review Comment:
   This is from YARN-12015 but there is an syntax error here that `labels` does 
not exists.  Would be nice if you could fix it here too



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to