Search in sources :

Example 1 with QueueMapping

use of org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping in project hadoop by apache.

the class TestUserGroupMappingPlacementRule method testMapping.

@Test
public void testMapping() throws YarnException {
    // simple base case for mapping user to queue
    verifyQueueMapping(new QueueMapping(MappingType.USER, "a", "q1"), "a", "q1");
    verifyQueueMapping(new QueueMapping(MappingType.GROUP, "agroup", "q1"), "a", "q1");
    verifyQueueMapping(new QueueMapping(MappingType.USER, "%user", "q2"), "a", "q2");
    verifyQueueMapping(new QueueMapping(MappingType.USER, "%user", "%user"), "a", "a");
    verifyQueueMapping(new QueueMapping(MappingType.USER, "%user", "%primary_group"), "a", "agroup");
    verifyQueueMapping(new QueueMapping(MappingType.GROUP, "asubgroup1", "q1"), "a", "q1");
    // specify overwritten, and see if user specified a queue, and it will be
    // overridden
    verifyQueueMapping(new QueueMapping(MappingType.USER, "user", "q1"), "user", "q2", "q1", true);
    // if overwritten not specified, it should be which user specified
    verifyQueueMapping(new QueueMapping(MappingType.USER, "user", "q1"), "user", "q2", "q2", false);
}
Also used : QueueMapping(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping) Test(org.junit.Test)

Example 2 with QueueMapping

use of org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping in project hadoop by apache.

the class TestQueueMappings method testQueueMappingTrimSpaces.

@Test
public void testQueueMappingTrimSpaces() throws IOException {
    // space trimming
    conf.set(CapacitySchedulerConfiguration.QUEUE_MAPPING, "    u : a : " + Q1);
    cs.reinitialize(conf, null);
    checkQMapping(new QueueMapping(MappingType.USER, "a", Q1));
}
Also used : QueueMapping(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping) Test(org.junit.Test)

Example 3 with QueueMapping

use of org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping in project hadoop by apache.

the class TestQueueMappings method checkQMapping.

private void checkQMapping(QueueMapping expected) throws IOException {
    UserGroupMappingPlacementRule rule = (UserGroupMappingPlacementRule) cs.getRMContext().getQueuePlacementManager().getPlacementRules().get(0);
    QueueMapping queueMapping = rule.getQueueMappings().get(0);
    Assert.assertEquals(queueMapping, expected);
}
Also used : UserGroupMappingPlacementRule(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule) QueueMapping(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping)

Example 4 with QueueMapping

use of org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping in project hadoop by apache.

the class CapacityScheduler method getUserGroupMappingPlacementRule.

@VisibleForTesting
public UserGroupMappingPlacementRule getUserGroupMappingPlacementRule() throws IOException {
    try {
        readLock.lock();
        boolean overrideWithQueueMappings = conf.getOverrideWithQueueMappings();
        LOG.info("Initialized queue mappings, override: " + overrideWithQueueMappings);
        // Get new user/group mappings
        List<QueueMapping> newMappings = conf.getQueueMappings();
        // check if mappings refer to valid queues
        for (QueueMapping mapping : newMappings) {
            String mappingQueue = mapping.getQueue();
            if (!mappingQueue.equals(UserGroupMappingPlacementRule.CURRENT_USER_MAPPING) && !mappingQueue.equals(UserGroupMappingPlacementRule.PRIMARY_GROUP_MAPPING)) {
                CSQueue queue = getQueue(mappingQueue);
                if (queue == null || !(queue instanceof LeafQueue)) {
                    throw new IOException("mapping contains invalid or non-leaf queue " + mappingQueue);
                }
            }
        }
        // initialize groups if mappings are present
        if (newMappings.size() > 0) {
            Groups groups = new Groups(conf);
            return new UserGroupMappingPlacementRule(overrideWithQueueMappings, newMappings, groups);
        }
        return null;
    } finally {
        readLock.unlock();
    }
}
Also used : Groups(org.apache.hadoop.security.Groups) UserGroupMappingPlacementRule(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule) QueueMapping(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with QueueMapping

use of org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping in project hadoop by apache.

the class CapacitySchedulerConfiguration method getQueueMappings.

/**
   * Get user/group mappings to queues.
   *
   * @return user/groups mappings or null on illegal configs
   */
public List<QueueMapping> getQueueMappings() {
    List<QueueMapping> mappings = new ArrayList<QueueMapping>();
    Collection<String> mappingsString = getTrimmedStringCollection(QUEUE_MAPPING);
    for (String mappingValue : mappingsString) {
        String[] mapping = getTrimmedStringCollection(mappingValue, ":").toArray(new String[] {});
        if (mapping.length != 3 || mapping[1].length() == 0 || mapping[2].length() == 0) {
            throw new IllegalArgumentException("Illegal queue mapping " + mappingValue);
        }
        QueueMapping m;
        try {
            QueueMapping.MappingType mappingType;
            if (mapping[0].equals("u")) {
                mappingType = QueueMapping.MappingType.USER;
            } else if (mapping[0].equals("g")) {
                mappingType = QueueMapping.MappingType.GROUP;
            } else {
                throw new IllegalArgumentException("unknown mapping prefix " + mapping[0]);
            }
            m = new QueueMapping(mappingType, mapping[1], mapping[2]);
        } catch (Throwable t) {
            throw new IllegalArgumentException("Illegal queue mapping " + mappingValue);
        }
        if (m != null) {
            mappings.add(m);
        }
    }
    return mappings;
}
Also used : ArrayList(java.util.ArrayList) QueueMapping(org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping)

Aggregations

QueueMapping (org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping)5 UserGroupMappingPlacementRule (org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Groups (org.apache.hadoop.security.Groups)1