9uapaw commented on a change in pull request #3551: URL: https://github.com/apache/hadoop/pull/3551#discussion_r730729218
########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueNodeLabelsSettings.java ########## @@ -0,0 +1,142 @@ +/* + * 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.commons.lang3.StringUtils; +import org.apache.hadoop.util.Sets; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT; +import java.io.IOException; +import java.util.Set; + +public class QueueNodeLabelsSettings { + private final CSQueue parent; + private final String queuePath; + private final CapacitySchedulerContext csContext; + private Set<String> accessibleLabels; + private Set<String> configuredNodeLabels; + private String defaultLabelExpression; + + public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration, + CSQueue parent, + String queuePath, Review comment: See the comment below (let us incorporate the new QueuePath class). ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueNodeLabelsSettings.java ########## @@ -0,0 +1,142 @@ +/* + * 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.commons.lang3.StringUtils; +import org.apache.hadoop.util.Sets; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT; +import java.io.IOException; +import java.util.Set; + +public class QueueNodeLabelsSettings { Review comment: Can you describe briefly what this class is used for? ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/BasicQueueProperties.java ########## @@ -0,0 +1,45 @@ +/* + * 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; + +public class BasicQueueProperties { + private final String queueName; + private final String queuePath; + private CSQueue parent; + + public BasicQueueProperties(CSQueue parent, String queueName) { + this.parent = parent; + this.queueName = queueName; + this.queuePath = ((parent == null) ? "" : (parent.getQueuePath() + ".")) + this.queueName; Review comment: This line is already handled in the new QueuePath class. ########## File path: 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 ########## @@ -265,31 +242,31 @@ public CSQueueMetrics getMetrics() { @Override public String getQueueShortName() { - return queueName; + return basicQueueProperties.getQueueName(); } @Override public String getQueueName() { - return queueName; + return basicQueueProperties.getQueueName(); } @Override - public PrivilegedEntity getPrivilegedEntity() { - return queueEntity; + public CSQueue getParent() { Review comment: See my comment below. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueNodeLabelsSettings.java ########## @@ -0,0 +1,142 @@ +/* + * 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.commons.lang3.StringUtils; +import org.apache.hadoop.util.Sets; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT; +import java.io.IOException; +import java.util.Set; + +public class QueueNodeLabelsSettings { + private final CSQueue parent; + private final String queuePath; + private final CapacitySchedulerContext csContext; + private Set<String> accessibleLabels; + private Set<String> configuredNodeLabels; + private String defaultLabelExpression; + + public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration, + CSQueue parent, + String queuePath, + CapacitySchedulerContext csContext) throws IOException { + this.parent = parent; + this.queuePath = queuePath; + this.csContext = csContext; + initializeNodeLabels(configuration); + } + + private void initializeNodeLabels(CapacitySchedulerConfiguration configuration) + throws IOException { + initializeAccessibleLabels(configuration); + initializeDefaultLabelExpression(configuration); + initializeConfiguredNodeLabels(); + validateNodeLabels(); + } + + private void initializeAccessibleLabels(CapacitySchedulerConfiguration configuration) { + this.accessibleLabels = configuration.getAccessibleNodeLabels(queuePath); + // Inherit labels from parent if not set + if (this.accessibleLabels == null && parent != null) { + this.accessibleLabels = parent.getAccessibleNodeLabels(); + } + } + + private void initializeDefaultLabelExpression(CapacitySchedulerConfiguration configuration) { + this.defaultLabelExpression = configuration.getDefaultNodeLabelExpression(queuePath); + // If the accessible labels is not null and the queue has a parent with a + // similar set of labels copy the defaultNodeLabelExpression from the parent + if (this.accessibleLabels != null && parent != null + && this.defaultLabelExpression == null && + this.accessibleLabels.containsAll(parent.getAccessibleNodeLabels())) { + this.defaultLabelExpression = parent.getDefaultNodeLabelExpression(); + } + } + + private void initializeConfiguredNodeLabels() { + if (csContext.getCapacitySchedulerQueueManager() != null + && csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() != null) { + if (queuePath.equals(ROOT)) { Review comment: See comment below (let us use the new QueuePath class). ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAppLifetimeAndLimitSettings.java ########## @@ -0,0 +1,127 @@ +/* + * 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.exceptions.YarnRuntimeException; + +public class QueueAppLifetimeAndLimitSettings { + // -1 indicates lifetime is disabled + private volatile long maxApplicationLifetime = -1; + private volatile long defaultApplicationLifetime = -1; + + // Indicates if this queue's default lifetime was set by a config property, + // either at this level or anywhere in the queue's hierarchy. + private volatile boolean defaultAppLifetimeWasSpecifiedInConfig = false; + + private int maxParallelApps; + + public QueueAppLifetimeAndLimitSettings(CapacitySchedulerConfiguration configuration, + AbstractCSQueue q, String queuePath) { + // Store max parallel apps property + this.maxParallelApps = configuration.getMaxParallelAppsForQueue(queuePath); + this.maxApplicationLifetime = getInheritedMaxAppLifetime(q, configuration); + this.defaultApplicationLifetime = getInheritedDefaultAppLifetime(q, queuePath, configuration, + maxApplicationLifetime); + } + + private long getInheritedMaxAppLifetime(CSQueue q, CapacitySchedulerConfiguration conf) { + CSQueue parentQ = q.getParent(); + long maxAppLifetime = conf.getMaximumLifetimePerQueue(q.getQueuePath()); + + // If q is the root queue, then get max app lifetime from conf. + if (parentQ == null) { + return maxAppLifetime; + } + + // If this is not the root queue, get this queue's max app lifetime + // from the conf. The parent's max app lifetime will be used if it's + // not set for this queue. + // A value of 0 will override the parent's value and means no max lifetime. + // A negative value means that the parent's max should be used. + long parentsMaxAppLifetime = parentQ.getMaximumApplicationLifetime(); + return (maxAppLifetime >= 0) ? maxAppLifetime : parentsMaxAppLifetime; + } + + private long getInheritedDefaultAppLifetime(CSQueue q, + String queuePath, CapacitySchedulerConfiguration conf, long myMaxAppLifetime) { + CSQueue parentQ = q.getParent(); + long defaultAppLifetime = conf.getDefaultLifetimePerQueue(queuePath); + defaultAppLifetimeWasSpecifiedInConfig = Review comment: If this calculation is moved after the parentQ == null check, the parentQ != null check is redundant here and it could be simplified to defaultAppLifetime >= 0 || parentQ.getDefaultAppLifetimeWasSpecifiedInConfig. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAppLifetimeAndLimitSettings.java ########## @@ -0,0 +1,127 @@ +/* + * 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.exceptions.YarnRuntimeException; + +public class QueueAppLifetimeAndLimitSettings { Review comment: Could you briefly document what this class is used for? ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueNodeLabelsSettings.java ########## @@ -0,0 +1,142 @@ +/* + * 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.commons.lang3.StringUtils; +import org.apache.hadoop.util.Sets; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT; +import java.io.IOException; +import java.util.Set; + +public class QueueNodeLabelsSettings { + private final CSQueue parent; + private final String queuePath; + private final CapacitySchedulerContext csContext; + private Set<String> accessibleLabels; + private Set<String> configuredNodeLabels; + private String defaultLabelExpression; + + public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration, + CSQueue parent, + String queuePath, + CapacitySchedulerContext csContext) throws IOException { + this.parent = parent; + this.queuePath = queuePath; + this.csContext = csContext; + initializeNodeLabels(configuration); + } + + private void initializeNodeLabels(CapacitySchedulerConfiguration configuration) + throws IOException { + initializeAccessibleLabels(configuration); + initializeDefaultLabelExpression(configuration); + initializeConfiguredNodeLabels(); + validateNodeLabels(); + } + + private void initializeAccessibleLabels(CapacitySchedulerConfiguration configuration) { + this.accessibleLabels = configuration.getAccessibleNodeLabels(queuePath); + // Inherit labels from parent if not set + if (this.accessibleLabels == null && parent != null) { + this.accessibleLabels = parent.getAccessibleNodeLabels(); + } + } + + private void initializeDefaultLabelExpression(CapacitySchedulerConfiguration configuration) { + this.defaultLabelExpression = configuration.getDefaultNodeLabelExpression(queuePath); + // If the accessible labels is not null and the queue has a parent with a + // similar set of labels copy the defaultNodeLabelExpression from the parent + if (this.accessibleLabels != null && parent != null + && this.defaultLabelExpression == null && + this.accessibleLabels.containsAll(parent.getAccessibleNodeLabels())) { + this.defaultLabelExpression = parent.getDefaultNodeLabelExpression(); + } + } + + private void initializeConfiguredNodeLabels() { + if (csContext.getCapacitySchedulerQueueManager() != null + && csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() != null) { + if (queuePath.equals(ROOT)) { + this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() + .getConfiguredNodeLabels().getAllConfiguredLabels(); + } else { + this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() + .getConfiguredNodeLabels().getLabelsByQueue(queuePath); + } + } else { + // Fallback to suboptimal but correct logic + this.configuredNodeLabels = csContext.getConfiguration().getConfiguredNodeLabels(queuePath); + } + } + + private void validateNodeLabels() throws IOException { + // Check if labels of this queue is a subset of parent queue, only do this + // when the queue in question is not root + if (isNotRoot()) { + if (parent.getAccessibleNodeLabels() != null && !parent + .getAccessibleNodeLabels().contains(RMNodeLabelsManager.ANY)) { + // If parent isn't "*", child shouldn't be "*" too + if (this.getAccessibleNodeLabels().contains(RMNodeLabelsManager.ANY)) { + throw new IOException("Parent's accessible queue is not ANY(*), " + + "but child's accessible queue is " + RMNodeLabelsManager.ANY); + } else { + Set<String> diff = Sets.difference(this.getAccessibleNodeLabels(), + parent.getAccessibleNodeLabels()); + if (!diff.isEmpty()) { + throw new IOException(String.format( + "Some labels of child queue is not a subset of parent queue, these labels=[%s]", + StringUtils.join(diff, ","))); + } + } + } + } + } + + private boolean isNotRoot() { + return parent != null && parent.getParent() != null; Review comment: I think it would be better to incorporate the usage of the new QueuePath object. You could define the isRoot method on QueuePath instead. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAllocationSettings.java ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceInformation; +import org.apache.hadoop.yarn.util.resource.ResourceUtils; +import org.apache.hadoop.yarn.util.resource.Resources; + +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.UNDEFINED; + +public class QueueAllocationSettings { + private final Resource minimumAllocation; + private volatile Resource maximumAllocation; + + public QueueAllocationSettings(CapacitySchedulerContext csContext) { + this.minimumAllocation = csContext.getMinimumResourceCapability(); + } + + void setupMaximumAllocation(CapacitySchedulerConfiguration csConf, String queuePath, + CSQueue parent, CapacitySchedulerContext csContext) { + /* YARN-10869: When using AutoCreatedLeafQueues, the passed configuration Review comment: I think this comment will need to be removed if the YARN-10929 gets merged before this change. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/BasicQueueProperties.java ########## @@ -0,0 +1,45 @@ +/* + * 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; + +public class BasicQueueProperties { + private final String queueName; + private final String queuePath; Review comment: Let us use the new QueuePath class here as well. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueNodeLabelsSettings.java ########## @@ -0,0 +1,142 @@ +/* + * 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.commons.lang3.StringUtils; +import org.apache.hadoop.util.Sets; +import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT; +import java.io.IOException; +import java.util.Set; + +public class QueueNodeLabelsSettings { + private final CSQueue parent; + private final String queuePath; + private final CapacitySchedulerContext csContext; + private Set<String> accessibleLabels; + private Set<String> configuredNodeLabels; + private String defaultLabelExpression; + + public QueueNodeLabelsSettings(CapacitySchedulerConfiguration configuration, + CSQueue parent, + String queuePath, + CapacitySchedulerContext csContext) throws IOException { + this.parent = parent; + this.queuePath = queuePath; + this.csContext = csContext; + initializeNodeLabels(configuration); + } + + private void initializeNodeLabels(CapacitySchedulerConfiguration configuration) + throws IOException { + initializeAccessibleLabels(configuration); + initializeDefaultLabelExpression(configuration); + initializeConfiguredNodeLabels(); + validateNodeLabels(); + } + + private void initializeAccessibleLabels(CapacitySchedulerConfiguration configuration) { + this.accessibleLabels = configuration.getAccessibleNodeLabels(queuePath); + // Inherit labels from parent if not set + if (this.accessibleLabels == null && parent != null) { + this.accessibleLabels = parent.getAccessibleNodeLabels(); + } + } + + private void initializeDefaultLabelExpression(CapacitySchedulerConfiguration configuration) { + this.defaultLabelExpression = configuration.getDefaultNodeLabelExpression(queuePath); + // If the accessible labels is not null and the queue has a parent with a + // similar set of labels copy the defaultNodeLabelExpression from the parent + if (this.accessibleLabels != null && parent != null + && this.defaultLabelExpression == null && + this.accessibleLabels.containsAll(parent.getAccessibleNodeLabels())) { + this.defaultLabelExpression = parent.getDefaultNodeLabelExpression(); + } + } + + private void initializeConfiguredNodeLabels() { + if (csContext.getCapacitySchedulerQueueManager() != null + && csContext.getCapacitySchedulerQueueManager().getConfiguredNodeLabels() != null) { + if (queuePath.equals(ROOT)) { + this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() + .getConfiguredNodeLabels().getAllConfiguredLabels(); + } else { + this.configuredNodeLabels = csContext.getCapacitySchedulerQueueManager() + .getConfiguredNodeLabels().getLabelsByQueue(queuePath); + } + } else { + // Fallback to suboptimal but correct logic + this.configuredNodeLabels = csContext.getConfiguration().getConfiguredNodeLabels(queuePath); + } + } + + private void validateNodeLabels() throws IOException { + // Check if labels of this queue is a subset of parent queue, only do this + // when the queue in question is not root + if (isNotRoot()) { + if (parent.getAccessibleNodeLabels() != null && !parent + .getAccessibleNodeLabels().contains(RMNodeLabelsManager.ANY)) { + // If parent isn't "*", child shouldn't be "*" too + if (this.getAccessibleNodeLabels().contains(RMNodeLabelsManager.ANY)) { + throw new IOException("Parent's accessible queue is not ANY(*), " + + "but child's accessible queue is " + RMNodeLabelsManager.ANY); + } else { + Set<String> diff = Sets.difference(this.getAccessibleNodeLabels(), + parent.getAccessibleNodeLabels()); + if (!diff.isEmpty()) { + throw new IOException(String.format( + "Some labels of child queue is not a subset of parent queue, these labels=[%s]", + StringUtils.join(diff, ","))); + } + } + } + } + } + + private boolean isNotRoot() { + return parent != null && parent.getParent() != null; + } + + public boolean accessibleToPartition(String nodePartition) { Review comment: I think the nomenclature would be more clear with isAccessibleToPartition. ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAllocationSettings.java ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; + +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceInformation; +import org.apache.hadoop.yarn.util.resource.ResourceUtils; +import org.apache.hadoop.yarn.util.resource.Resources; + +import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.UNDEFINED; + +public class QueueAllocationSettings { Review comment: Could you briefly document what this class is used for? ########## File path: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/BasicQueueProperties.java ########## @@ -0,0 +1,45 @@ +/* + * 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; + +public class BasicQueueProperties { Review comment: I am not sure if it is a good idea to introduce this class. If you use the new QueuePath class, there will only be 2 fields here. My objections are: 1. It will be a really simple storage class, without any logic at all and only 2 fields 2. Changing every access to parent to a double indirection and a method call is going to cost us some cpu cycle. I have checked and JVM does not inline getters (the JIT does, but only after a while and we should not depend on this). -- 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]
