YARN-10375. CS Mapping rule config parser should return MappingRule objects. Contributed by Gergely Pollak.

This commit is contained in:
Peter Bacsko 2020-09-03 18:54:22 +02:00
parent 288dab7563
commit 5c15815773

View File

@ -21,6 +21,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import org.apache.hadoop.yarn.server.resourcemanager.placement.MappingRule;
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueuePlacementRuleUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -279,6 +280,10 @@ public class CapacitySchedulerConfiguration extends ReservationSchedulerConfigur
@Private
public static final String QUEUE_MAPPING = PREFIX + "queue-mappings";
@Private
public static final String QUEUE_MAPPING_NAME =
YarnConfiguration.QUEUE_PLACEMENT_RULES + ".app-name";
@Private
public static final String ENABLE_QUEUE_MAPPING_OVERRIDE = QUEUE_MAPPING + "-override.enable";
@ -1159,6 +1164,46 @@ public List<QueueMapping> getQueueMappings() {
return mappings;
}
public List<MappingRule> getMappingRules() {
List<MappingRule> mappings = new ArrayList<MappingRule>();
Collection<String> mappingsString =
getTrimmedStringCollection(QUEUE_MAPPING);
for (String mappingValue : mappingsString) {
String[] mapping =
StringUtils.getTrimmedStringCollection(mappingValue, ":")
.toArray(new String[] {});
if (mapping.length != 3 || mapping[1].length() == 0
|| mapping[2].length() == 0) {
throw new IllegalArgumentException(
"Illegal queue mapping " + mappingValue);
}
if (mapping[0].equals("u") || mapping[0].equals("g")) {
mappings.add(MappingRule.createLegacyRule(
mapping[0], mapping[1], mapping[2]));
} else {
throw new IllegalArgumentException(
"unknown mapping prefix " + mapping[0]);
}
}
mappingsString = getTrimmedStringCollection(QUEUE_MAPPING_NAME);
for (String mappingValue : mappingsString) {
String[] mapping =
StringUtils.getTrimmedStringCollection(mappingValue, ":")
.toArray(new String[] {});
if (mapping.length != 2 || mapping[1].length() == 0) {
throw new IllegalArgumentException(
"Illegal queue mapping " + mappingValue);
}
mappings.add(MappingRule.createLegacyRule(mapping[0], mapping[1]));
}
return mappings;
}
@Private
@VisibleForTesting
public void setQueuePlacementRules(Collection<String> queuePlacementRules) {