YARN-10424. Adapt existing AppName and UserGroupMapping unittests to ensure backwards compatibility. Contributed by Benjamin Teke.

This commit is contained in:
Peter Bacsko 2020-09-09 09:41:11 +02:00
parent 0d855159f0
commit aba4a506d6
2 changed files with 214 additions and 129 deletions

View File

@ -20,19 +20,24 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.security.GroupMappingServiceProvider; import org.apache.hadoop.security.GroupMappingServiceProvider;
import org.apache.hadoop.security.Groups;
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import java.util.Arrays; import java.io.IOException;
import java.util.Collections;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -55,24 +60,37 @@ public class TestAppNameMappingPlacementRule {
SimpleGroupsMapping.class, GroupMappingServiceProvider.class); SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
} }
private void createQueueHierarchy(
CapacitySchedulerQueueManager queueManager) {
MockQueueHierarchyBuilder.create()
.withQueueManager(queueManager)
.withQueue(ROOT_QUEUE + DOT + Q1_QUEUE)
.withQueue(ROOT_QUEUE + DOT + Q2_QUEUE)
.withQueue(ROOT_QUEUE + DOT + DEFAULT_QUEUE)
.withQueue(ROOT_QUEUE + DOT + AMBIGUOUS_QUEUE)
.withQueue(ROOT_QUEUE + DOT + USER_NAME + DOT + AMBIGUOUS_QUEUE)
.build();
when(queueManager.getQueue(isNull())).thenReturn(null);
}
private void verifyQueueMapping(QueueMapping queueMapping, private void verifyQueueMapping(QueueMapping queueMapping,
String user, String expectedQueue) throws YarnException { String user, String expectedQueue)
throws IOException, YarnException {
verifyQueueMapping(queueMapping, user, verifyQueueMapping(queueMapping, user,
queueMapping.getQueue(), expectedQueue, false); queueMapping.getQueue(), expectedQueue, false);
} }
private void verifyQueueMapping(QueueMapping queueMapping, private void verifyQueueMapping(QueueMapping queueMapping,
String user, String inputQueue, String expectedQueue, String user, String inputQueue,
boolean overwrite) throws YarnException { String expectedQueue, boolean overwrite)
AppNameMappingPlacementRule rule = new AppNameMappingPlacementRule( throws IOException, YarnException {
overwrite, Arrays.asList(queueMapping)); MappingRule rule = MappingRule.createLegacyRule(
queueMapping.getType().toString(),
queueMapping.getSource(),
queueMapping.getFullPath());
CapacitySchedulerQueueManager qm = CSMappingPlacementRule engine = setupEngine(rule, overwrite);
mock(CapacitySchedulerQueueManager.class);
when(qm.isAmbiguous(Mockito.isA(String.class))).thenReturn(false);
when(qm.isAmbiguous(AMBIGUOUS_QUEUE)).thenReturn(true);
rule.queueManager = qm;
ApplicationSubmissionContext asc = Records.newRecord( ApplicationSubmissionContext asc = Records.newRecord(
ApplicationSubmissionContext.class); ApplicationSubmissionContext.class);
@ -87,18 +105,45 @@ public class TestAppNameMappingPlacementRule {
appName = APP_NAME; appName = APP_NAME;
} }
asc.setApplicationName(appName); asc.setApplicationName(appName);
ApplicationPlacementContext ctx = rule.getPlacementForApp(asc, ApplicationPlacementContext ctx = engine.getPlacementForApp(asc,
user); user);
Assert.assertEquals(expectedQueue, Assert.assertEquals(expectedQueue,
ctx != null ? ctx.getQueue() : inputQueue); ctx != null ? ctx.getQueue() : inputQueue);
} }
CSMappingPlacementRule setupEngine(MappingRule rule, boolean override)
throws IOException {
CapacitySchedulerConfiguration csConf =
mock(CapacitySchedulerConfiguration.class);
when(csConf.getMappingRules()).thenReturn(Collections.singletonList(rule));
when(csConf.getOverrideWithQueueMappings())
.thenReturn(override);
CapacitySchedulerQueueManager queueManager =
mock(CapacitySchedulerQueueManager.class);
createQueueHierarchy(queueManager);
CSMappingPlacementRule engine = new CSMappingPlacementRule();
Groups groups = new Groups(conf);
CapacityScheduler cs = mock(CapacityScheduler.class);
when(cs.getConfiguration()).thenReturn(csConf);
when(cs.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
engine.setGroups(groups);
engine.setFailOnConfigError(false);
engine.initialize(cs);
return engine;
}
public QueueMapping getQueueMapping(String source, String queue) { public QueueMapping getQueueMapping(String source, String queue) {
return getQueueMapping(source, null, queue); return getQueueMapping(source, null, queue);
} }
public QueueMapping getQueueMapping(String source, String parent, public QueueMapping getQueueMapping(String source, String parent,
String queue) { String queue) {
return QueueMapping.QueueMappingBuilder.create() return QueueMapping.QueueMappingBuilder.create()
.type(QueueMapping.MappingType.APPLICATION) .type(QueueMapping.MappingType.APPLICATION)
.source(source) .source(source)
@ -108,70 +153,73 @@ public class TestAppNameMappingPlacementRule {
} }
@Test @Test
public void testSpecificAppNameMappedToDefinedQueue() throws YarnException { public void testSpecificAppNameMappedToDefinedQueue()
throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, Q1_QUEUE), verifyQueueMapping(getQueueMapping(APP_NAME, Q1_QUEUE),
USER_NAME, Q1_QUEUE); USER_NAME, Q1_QUEUE);
} }
@Test @Test
public void testPlaceholderAppSourceMappedToQueue() throws YarnException { public void testPlaceholderAppSourceMappedToQueue()
throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APPLICATION_PLACEHOLDER, Q2_QUEUE), verifyQueueMapping(getQueueMapping(APPLICATION_PLACEHOLDER, Q2_QUEUE),
USER_NAME, Q2_QUEUE); USER_NAME, Q2_QUEUE);
} }
@Test @Test
public void testPlaceHolderAppSourceAndQueueMappedToAppNameQueue() public void testPlaceHolderAppSourceAndQueueMappedToAppNameQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APPLICATION_PLACEHOLDER, verifyQueueMapping(getQueueMapping(APPLICATION_PLACEHOLDER,
APPLICATION_PLACEHOLDER), USER_NAME, APP_NAME); APPLICATION_PLACEHOLDER), USER_NAME, APP_NAME);
} }
@Test @Test
public void testQueueInMappingOverridesSpecifiedQueue() public void testQueueInMappingOverridesSpecifiedQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, verifyQueueMapping(getQueueMapping(APP_NAME,
Q1_QUEUE), USER_NAME, Q2_QUEUE, Q1_QUEUE, true); Q1_QUEUE), USER_NAME, Q2_QUEUE, Q1_QUEUE, true);
} }
@Test @Test
public void testQueueInMappingDoesNotOverrideSpecifiedQueue() public void testQueueInMappingDoesNotOverrideSpecifiedQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, verifyQueueMapping(getQueueMapping(APP_NAME,
Q1_QUEUE), USER_NAME, Q2_QUEUE, Q2_QUEUE, false); Q1_QUEUE), USER_NAME, Q2_QUEUE, Q2_QUEUE, false);
} }
@Test @Test
public void testDefaultQueueInMappingIsNotUsedWithoutOverride() public void testDefaultQueueInMappingIsNotUsedWithoutOverride()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, verifyQueueMapping(getQueueMapping(APP_NAME,
DEFAULT_QUEUE), USER_NAME, Q2_QUEUE, Q2_QUEUE, false); DEFAULT_QUEUE), USER_NAME, Q2_QUEUE, Q2_QUEUE, false);
} }
@Test @Test
public void testDefaultQueueInMappingEqualsToInputQueue() public void testDefaultQueueInMappingEqualsToInputQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, verifyQueueMapping(getQueueMapping(APP_NAME,
DEFAULT_QUEUE), USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false); DEFAULT_QUEUE), USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false);
} }
@Test @Test
public void testMappingSourceDiffersFromInputQueue() throws YarnException { public void testMappingSourceDiffersFromInputQueue()
throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(MAPREDUCE_APP_NAME, verifyQueueMapping(getQueueMapping(MAPREDUCE_APP_NAME,
Q1_QUEUE), USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false); Q1_QUEUE), USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false);
} }
@Test(expected = YarnException.class) @Test
public void testMappingContainsAmbiguousLeafQueueWithoutParent() public void testMappingContainsAmbiguousLeafQueueWithoutParent()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, AMBIGUOUS_QUEUE), verifyQueueMapping(getQueueMapping(APP_NAME, AMBIGUOUS_QUEUE),
USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false); USER_NAME, DEFAULT_QUEUE, DEFAULT_QUEUE, false);
} }
@Test @Test
public void testMappingContainsAmbiguousLeafQueueWithParent() public void testMappingContainsAmbiguousLeafQueueWithParent()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping(getQueueMapping(APP_NAME, ROOT_QUEUE, AMBIGUOUS_QUEUE), verifyQueueMapping(getQueueMapping(APP_NAME, ROOT_QUEUE, AMBIGUOUS_QUEUE),
USER_NAME, DEFAULT_QUEUE, AMBIGUOUS_QUEUE, false); USER_NAME, DEFAULT_QUEUE, AMBIGUOUS_QUEUE, false);
} }
} }

View File

@ -23,7 +23,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.isNull;
import java.util.Arrays; import java.io.IOException;
import java.util.Collections;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.security.GroupMappingServiceProvider; import org.apache.hadoop.security.GroupMappingServiceProvider;
@ -35,6 +36,8 @@ import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping.MappingType; import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping.MappingType;
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping.QueueMappingBuilder; import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping.QueueMappingBuilder;
import org.apache.hadoop.yarn.server.resourcemanager.placement.TestUserGroupMappingPlacementRule.QueueMappingTestData.QueueMappingTestDataBuilder; import org.apache.hadoop.yarn.server.resourcemanager.placement.TestUserGroupMappingPlacementRule.QueueMappingTestData.QueueMappingTestDataBuilder;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.PrimaryGroupMapping; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.PrimaryGroupMapping;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
@ -42,14 +45,9 @@ import org.apache.hadoop.yarn.util.Records;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestUserGroupMappingPlacementRule { public class TestUserGroupMappingPlacementRule {
private static final Logger LOG = private final YarnConfiguration conf = new YarnConfiguration();
LoggerFactory.getLogger(TestUserGroupMappingPlacementRule.class);
YarnConfiguration conf = new YarnConfiguration();
@Before @Before
public void setup() { public void setup() {
@ -57,9 +55,27 @@ public class TestUserGroupMappingPlacementRule {
SimpleGroupsMapping.class, GroupMappingServiceProvider.class); SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
} }
private void verifyQueueMapping(QueueMappingTestData queueMappingTestData) private void createQueueHierarchy(
throws YarnException { CapacitySchedulerQueueManager queueManager) {
MockQueueHierarchyBuilder.create()
.withQueueManager(queueManager)
.withQueue("root.default")
.withQueue("root.agroup.a")
.withQueue("root.bgroup")
.withQueue("root.usergroup.c")
.withQueue("root.asubgroup2")
.withQueue("root.bsubgroup2.b")
.withQueue("root.users.primarygrouponly")
.withQueue("root.devs.primarygrouponly")
.withQueue("root.admins.primarygrouponly")
.withManagedParentQueue("root.managedParent")
.build();
when(queueManager.getQueue(isNull())).thenReturn(null);
}
private void verifyQueueMapping(QueueMappingTestData queueMappingTestData)
throws IOException, YarnException {
QueueMapping queueMapping = queueMappingTestData.queueMapping; QueueMapping queueMapping = queueMappingTestData.queueMapping;
String inputUser = queueMappingTestData.inputUser; String inputUser = queueMappingTestData.inputUser;
String inputQueue = queueMappingTestData.inputQueue; String inputQueue = queueMappingTestData.inputQueue;
@ -67,87 +83,100 @@ public class TestUserGroupMappingPlacementRule {
boolean overwrite = queueMappingTestData.overwrite; boolean overwrite = queueMappingTestData.overwrite;
String expectedParentQueue = queueMappingTestData.expectedParentQueue; String expectedParentQueue = queueMappingTestData.expectedParentQueue;
Groups groups = new Groups(conf); MappingRule rule = MappingRule.createLegacyRule(
UserGroupMappingPlacementRule rule = new UserGroupMappingPlacementRule( queueMapping.getType().toString(),
overwrite, Arrays.asList(queueMapping), groups); queueMapping.getSource(),
CapacitySchedulerQueueManager queueManager = queueMapping.getFullPath());
mock(CapacitySchedulerQueueManager.class);
MockQueueHierarchyBuilder.create() CSMappingPlacementRule engine = setupEngine(rule, overwrite);
.withQueueManager(queueManager)
.withQueue("root.agroup.a")
.withQueue("root.asubgroup2")
.withQueue("root.bsubgroup2.b")
.withQueue("root.users.primarygrouponly")
.withQueue("root.admins.primarygrouponly")
.withManagedParentQueue("root.managedParent")
.build();
when(queueManager.getQueue(isNull())).thenReturn(null);
rule.setQueueManager(queueManager);
ApplicationSubmissionContext asc = Records.newRecord( ApplicationSubmissionContext asc = Records.newRecord(
ApplicationSubmissionContext.class); ApplicationSubmissionContext.class);
asc.setQueue(inputQueue); asc.setQueue(inputQueue);
ApplicationPlacementContext ctx = rule.getPlacementForApp(asc, inputUser); ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, inputUser);
Assert.assertEquals("Queue", expectedQueue, Assert.assertEquals("Queue", expectedQueue,
ctx != null ? ctx.getQueue() : inputQueue); ctx != null ? ctx.getQueue() : inputQueue);
if (expectedParentQueue != null) { if (ctx != null && expectedParentQueue != null) {
Assert.assertEquals("Parent Queue", expectedParentQueue, Assert.assertEquals("Parent Queue", expectedParentQueue,
ctx.getParentQueue()); ctx.getParentQueue());
} }
} }
CSMappingPlacementRule setupEngine(MappingRule rule,
boolean override)
throws IOException {
CapacitySchedulerConfiguration csConf =
mock(CapacitySchedulerConfiguration.class);
when(csConf.getMappingRules()).thenReturn(Collections.singletonList(rule));
when(csConf.getOverrideWithQueueMappings())
.thenReturn(override);
CapacitySchedulerQueueManager queueManager =
mock(CapacitySchedulerQueueManager.class);
createQueueHierarchy(queueManager);
CSMappingPlacementRule engine = new CSMappingPlacementRule();
Groups groups = new Groups(conf);
CapacityScheduler cs = mock(CapacityScheduler.class);
when(cs.getConfiguration()).thenReturn(csConf);
when(cs.getCapacitySchedulerQueueManager()).thenReturn(queueManager);
engine.setGroups(groups);
engine.setFailOnConfigError(false);
engine.initialize(cs);
return engine;
}
@Test @Test
public void testSecondaryGroupMapping() throws YarnException { public void testSecondaryGroupMapping() throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
.type(MappingType.USER) .type(MappingType.USER)
.source("%user") .source("%user")
.queue("%secondary_group").build()) .queue("%secondary_group").build())
.inputUser("a") .inputUser("a")
.expectedQueue("asubgroup2") .expectedQueue("asubgroup2")
.expectedParentQueue("root") .expectedParentQueue("root")
.build()); .build());
// PrimaryGroupMapping.class returns only primary group, no secondary groups // PrimaryGroupMapping.class returns only primary group, no secondary groups
conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
PrimaryGroupMapping.class, GroupMappingServiceProvider.class); PrimaryGroupMapping.class, GroupMappingServiceProvider.class);
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
.type(MappingType.USER) .type(MappingType.USER)
.source("%user") .source("%user")
.queue("%secondary_group") .queue("%secondary_group")
.build()) .build())
.inputUser("a") .inputUser("a")
.expectedQueue("default") .expectedQueue("default")
.build()); .build());
} }
@Test @Test(expected = YarnException.class)
public void testNullGroupMapping() { public void testNullGroupMapping() throws IOException, YarnException {
conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
NullGroupsMapping.class, GroupMappingServiceProvider.class); NullGroupsMapping.class, GroupMappingServiceProvider.class);
try { verifyQueueMapping(
verifyQueueMapping( QueueMappingTestDataBuilder.create()
QueueMappingTestDataBuilder.create() .queueMapping(QueueMappingBuilder.create()
.queueMapping(QueueMappingBuilder.create() .type(MappingType.USER)
.type(MappingType.USER) .source("%user")
.source("%user") .queue("%secondary_group")
.queue("%secondary_group") .build())
.build()) .inputUser("a")
.inputUser("a") .expectedQueue("default")
.expectedQueue("default") .build());
.build()); fail("No Groups for user 'a'");
fail("No Groups for user 'a'");
} catch (YarnException e) {
// Exception is expected as there are no groups for given user
}
} }
@Test @Test
public void testSimpleUserMappingToSpecificQueue() throws YarnException { public void testSimpleUserMappingToSpecificQueue()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -161,7 +190,8 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testSimpleGroupMappingToSpecificQueue() throws YarnException { public void testSimpleGroupMappingToSpecificQueue()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -175,7 +205,8 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testUserMappingToSpecificQueueForEachUser() throws YarnException { public void testUserMappingToSpecificQueueForEachUser()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -189,7 +220,8 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testUserMappingToQueueNamedAsUsername() throws YarnException { public void testUserMappingToQueueNamedAsUsername()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -203,7 +235,8 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testUserMappingToQueueNamedGroupOfTheUser() throws YarnException { public void testUserMappingToQueueNamedGroupOfTheUser()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -211,15 +244,15 @@ public class TestUserGroupMappingPlacementRule {
.source("%user") .source("%user")
.queue("%primary_group") .queue("%primary_group")
.build()) .build())
.inputUser("a") .inputUser("b")
.expectedQueue("agroup") .expectedQueue("bgroup")
.expectedParentQueue("root") .expectedParentQueue("root")
.build()); .build());
} }
@Test @Test
public void testUserMappingToQueueNamedAsUsernameWithPrimaryGroupAsParentQueue() public void testUserMappingToQueueNamedAsUsernameWithPrimaryGroupAsParentQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -236,7 +269,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToPrimaryGroupInvalidNestedPlaceholder() public void testUserMappingToPrimaryGroupInvalidNestedPlaceholder()
throws YarnException { throws IOException, YarnException {
// u:%user:%primary_group.%random, no matching queue // u:%user:%primary_group.%random, no matching queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -253,7 +286,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToSecondaryGroupInvalidNestedPlaceholder() public void testUserMappingToSecondaryGroupInvalidNestedPlaceholder()
throws YarnException { throws IOException, YarnException {
// u:%user:%secondary_group.%random, no matching queue // u:%user:%secondary_group.%random, no matching queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -270,7 +303,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingDiffersFromSubmitterQueueDoesNotExist() public void testUserMappingDiffersFromSubmitterQueueDoesNotExist()
throws YarnException { throws IOException, YarnException {
// u:a:%random, submitter: xyz, no matching queue // u:a:%random, submitter: xyz, no matching queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -285,23 +318,24 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testSpecificUserMappingToPrimaryGroup() throws YarnException { public void testSpecificUserMappingToPrimaryGroup()
throws IOException, YarnException {
// u:a:%primary_group // u:a:%primary_group
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
.type(MappingType.USER) .type(MappingType.USER)
.source("a") .source("b")
.queue("%primary_group") .queue("%primary_group")
.build()) .build())
.inputUser("a") .inputUser("b")
.expectedQueue("agroup") .expectedQueue("bgroup")
.build()); .build());
} }
@Test @Test
public void testSpecificUserMappingToSecondaryGroup() public void testSpecificUserMappingToSecondaryGroup()
throws YarnException { throws IOException, YarnException {
// u:a:%secondary_group // u:a:%secondary_group
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -317,7 +351,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testSpecificUserMappingWithNoSecondaryGroup() public void testSpecificUserMappingWithNoSecondaryGroup()
throws YarnException { throws IOException, YarnException {
// u:nosecondarygroupuser:%secondary_group, no matching queue // u:nosecondarygroupuser:%secondary_group, no matching queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -333,7 +367,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testGenericUserMappingWithNoSecondaryGroup() public void testGenericUserMappingWithNoSecondaryGroup()
throws YarnException { throws IOException, YarnException {
// u:%user:%user, no matching queue // u:%user:%user, no matching queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -350,7 +384,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToNestedUserPrimaryGroupWithAmbiguousQueues() public void testUserMappingToNestedUserPrimaryGroupWithAmbiguousQueues()
throws YarnException { throws IOException, YarnException {
// u:%user:%user, submitter nosecondarygroupuser, queue is ambiguous // u:%user:%user, submitter nosecondarygroupuser, queue is ambiguous
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -365,9 +399,9 @@ public class TestUserGroupMappingPlacementRule {
.build()); .build());
} }
@Test(expected = YarnException.class) @Test
public void testResolvedQueueIsNotManaged() public void testResolvedQueueIsNotManaged()
throws YarnException { throws IOException, YarnException {
// u:%user:%primary_group.%user, "admins" group will be "root", // u:%user:%primary_group.%user, "admins" group will be "root",
// resulting parent queue will be "root" which is not managed // resulting parent queue will be "root" which is not managed
verifyQueueMapping( verifyQueueMapping(
@ -379,12 +413,13 @@ public class TestUserGroupMappingPlacementRule {
.parentQueue("%primary_group") .parentQueue("%primary_group")
.build()) .build())
.inputUser("admins") .inputUser("admins")
.expectedQueue("default")
.build()); .build());
} }
@Test(expected = YarnException.class) @Test
public void testUserMappingToPrimaryGroupWithAmbiguousQueues() public void testUserMappingToPrimaryGroupWithAmbiguousQueues()
throws YarnException { throws IOException, YarnException {
// u:%user:%primary_group, submitter nosecondarygroupuser, // u:%user:%primary_group, submitter nosecondarygroupuser,
// queue is ambiguous // queue is ambiguous
verifyQueueMapping( verifyQueueMapping(
@ -401,7 +436,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToQueueNamedAsUsernameWithSecondaryGroupAsParentQueue() public void testUserMappingToQueueNamedAsUsernameWithSecondaryGroupAsParentQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -417,7 +452,8 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testGroupMappingToStaticQueue() throws YarnException { public void testGroupMappingToStaticQueue()
throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -432,7 +468,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToQueueNamedAsGroupNameWithRootAsParentQueue() public void testUserMappingToQueueNamedAsGroupNameWithRootAsParentQueue()
throws YarnException { throws IOException, YarnException {
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -441,15 +477,15 @@ public class TestUserGroupMappingPlacementRule {
.queue("%primary_group") .queue("%primary_group")
.parentQueue("root") .parentQueue("root")
.build()) .build())
.inputUser("a") .inputUser("b")
.expectedQueue("agroup") .expectedQueue("bgroup")
.expectedParentQueue("root") .expectedParentQueue("root")
.build()); .build());
} }
@Test @Test
public void testUserMappingToPrimaryGroupQueueDoesNotExistUnmanagedParent() public void testUserMappingToPrimaryGroupQueueDoesNotExistUnmanagedParent()
throws YarnException { throws IOException, YarnException {
// "abcgroup" queue doesn't exist, %primary_group queue, not managed parent // "abcgroup" queue doesn't exist, %primary_group queue, not managed parent
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -466,7 +502,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToPrimaryGroupQueueDoesNotExistManagedParent() public void testUserMappingToPrimaryGroupQueueDoesNotExistManagedParent()
throws YarnException { throws IOException, YarnException {
// "abcgroup" queue doesn't exist, %primary_group queue, managed parent // "abcgroup" queue doesn't exist, %primary_group queue, managed parent
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -484,7 +520,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToSecondaryGroupQueueDoesNotExist() public void testUserMappingToSecondaryGroupQueueDoesNotExist()
throws YarnException { throws IOException, YarnException {
// "abcgroup" queue doesn't exist, %secondary_group queue // "abcgroup" queue doesn't exist, %secondary_group queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -501,7 +537,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToSecondaryGroupQueueUnderParent() public void testUserMappingToSecondaryGroupQueueUnderParent()
throws YarnException { throws IOException, YarnException {
// "asubgroup2" queue exists, %secondary_group queue // "asubgroup2" queue exists, %secondary_group queue
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -519,7 +555,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testUserMappingToSpecifiedQueueOverwritesInputQueueFromMapping() public void testUserMappingToSpecifiedQueueOverwritesInputQueueFromMapping()
throws YarnException { throws IOException, YarnException {
// specify overwritten, and see if user specified a queue, and it will be // specify overwritten, and see if user specified a queue, and it will be
// overridden // overridden
verifyQueueMapping( verifyQueueMapping(
@ -537,8 +573,9 @@ public class TestUserGroupMappingPlacementRule {
} }
@Test @Test
public void testUserMappingToExplicitlySpecifiedQueue() throws YarnException { public void testUserMappingToExplicitlySpecifiedQueue()
// if overwritten not specified, it should be which user specified throws IOException, YarnException {
// if overwritten not specified, it should be which user specified
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
.queueMapping(QueueMappingBuilder.create() .queueMapping(QueueMappingBuilder.create()
@ -554,7 +591,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testGroupMappingToExplicitlySpecifiedQueue() public void testGroupMappingToExplicitlySpecifiedQueue()
throws YarnException { throws IOException, YarnException {
// if overwritten not specified, it should be which user specified // if overwritten not specified, it should be which user specified
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -565,14 +602,14 @@ public class TestUserGroupMappingPlacementRule {
.parentQueue("usergroup") .parentQueue("usergroup")
.build()) .build())
.inputUser("user") .inputUser("user")
.inputQueue("a") .inputQueue("c")
.expectedQueue("a") .expectedQueue("c")
.build()); .build());
} }
@Test @Test
public void testGroupMappingToSpecifiedQueueOverwritesInputQueueFromMapping() public void testGroupMappingToSpecifiedQueueOverwritesInputQueueFromMapping()
throws YarnException { throws IOException, YarnException {
// if overwritten not specified, it should be which user specified // if overwritten not specified, it should be which user specified
verifyQueueMapping( verifyQueueMapping(
QueueMappingTestDataBuilder.create() QueueMappingTestDataBuilder.create()
@ -591,7 +628,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testGroupMappingToSpecifiedQueueUnderAGivenParentQueue() public void testGroupMappingToSpecifiedQueueUnderAGivenParentQueue()
throws YarnException { throws IOException, YarnException {
// If user specific queue is enabled for a specified group under a given // If user specific queue is enabled for a specified group under a given
// parent queue // parent queue
verifyQueueMapping( verifyQueueMapping(
@ -609,7 +646,7 @@ public class TestUserGroupMappingPlacementRule {
@Test @Test
public void testGroupMappingToSpecifiedQueueWithoutParentQueue() public void testGroupMappingToSpecifiedQueueWithoutParentQueue()
throws YarnException { throws IOException, YarnException {
// If user specific queue is enabled for a specified group without parent // If user specific queue is enabled for a specified group without parent
// queue // queue
verifyQueueMapping( verifyQueueMapping(