YARN-11038. Fix testQueueSubmitWithACL* tests in TestAppManager. Contributed by Tamas Domok

This commit is contained in:
Szilard Nemeth 2021-12-08 16:41:35 +01:00
parent 19430118c6
commit 66a08e933a
1 changed files with 62 additions and 67 deletions

View File

@ -274,10 +274,41 @@ public class TestAppManager extends AppManagerTestBase{
setupDispatcher(rmContext, conf); setupDispatcher(rmContext, conf);
} }
private static PlacementManager createMockPlacementManager(
String userRegex, String placementQueue, String placementParentQueue
) throws YarnException {
PlacementManager placementMgr = mock(PlacementManager.class);
doAnswer(new Answer<ApplicationPlacementContext>() {
@Override
public ApplicationPlacementContext answer(InvocationOnMock invocation)
throws Throwable {
return new ApplicationPlacementContext(placementQueue, placementParentQueue);
}
}).when(placementMgr).placeApplication(
any(ApplicationSubmissionContext.class),
matches(userRegex),
any(Boolean.class));
return placementMgr;
}
private TestRMAppManager createAppManager(RMContext context, Configuration configuration) {
ApplicationMasterService masterService = new ApplicationMasterService(context,
context.getScheduler());
return new TestRMAppManager(context,
new ClientToAMTokenSecretManagerInRM(),
context.getScheduler(), masterService,
new ApplicationACLsManager(configuration), configuration);
}
@Test @Test
public void testQueueSubmitWithACLsEnabledWithQueueMapping() public void testQueueSubmitWithACLsEnabledWithQueueMapping()
throws IOException, YarnException, InterruptedException { throws YarnException {
YarnConfiguration conf = new YarnConfiguration(); YarnConfiguration conf = new YarnConfiguration(new Configuration(false));
conf.set(YarnConfiguration.YARN_ACL_ENABLE, "true");
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
ResourceScheduler.class); ResourceScheduler.class);
@ -285,11 +316,11 @@ public class TestAppManager extends AppManagerTestBase{
CapacitySchedulerConfiguration(conf, false); CapacitySchedulerConfiguration(conf, false);
csConf.set(PREFIX + "root.queues", "default,test"); csConf.set(PREFIX + "root.queues", "default,test");
csConf.setFloat(PREFIX + "root.default.capacity", 50.0f); csConf.setCapacity("root.default", 50.0f);
csConf.setFloat(PREFIX + "root.default.maximum-capacity", 100.0f); csConf.setMaximumCapacity("root.default", 100.0f);
csConf.setFloat(PREFIX + "root.test.capacity", 50.0f); csConf.setCapacity("root.test", 50.0f);
csConf.setFloat(PREFIX + "root.test.maximum-capacity", 100.0f); csConf.setMaximumCapacity("root.test", 100.0f);
csConf.set(PREFIX + "root.acl_submit_applications", " "); csConf.set(PREFIX + "root.acl_submit_applications", " ");
csConf.set(PREFIX + "root.acl_administer_queue", " "); csConf.set(PREFIX + "root.acl_administer_queue", " ");
@ -300,55 +331,30 @@ public class TestAppManager extends AppManagerTestBase{
csConf.set(PREFIX + "root.test.acl_submit_applications", "test"); csConf.set(PREFIX + "root.test.acl_submit_applications", "test");
csConf.set(PREFIX + "root.test.acl_administer_queue", "test"); csConf.set(PREFIX + "root.test.acl_administer_queue", "test");
csConf.set(PREFIX + "root.test.acl_submit_applications", "test"); asContext.setQueue("test");
csConf.set(PREFIX + "root.test.acl_administer_queue", "test");
csConf.set(YarnConfiguration.YARN_ACL_ENABLE, "true"); MockRM newMockRM = new MockRM(csConf);
// Setup a PlacementManager returns a new queue
PlacementManager placementMgr = mock(PlacementManager.class);
doAnswer(new Answer<ApplicationPlacementContext>() {
@Override
public ApplicationPlacementContext answer(InvocationOnMock invocation)
throws Throwable {
return new ApplicationPlacementContext("test");
}
}).when(placementMgr).placeApplication(
any(ApplicationSubmissionContext.class), matches("test"));
asContext.setQueue("oldQueue");
MockRM newMockRM = new MockRM(conf);
RMContext newMockRMContext = newMockRM.getRMContext(); RMContext newMockRMContext = newMockRM.getRMContext();
newMockRMContext.setQueuePlacementManager(placementMgr); newMockRMContext.setQueuePlacementManager(createMockPlacementManager("test", "test", null));
ApplicationMasterService masterService = TestRMAppManager newAppMonitor = createAppManager(newMockRMContext, conf);
new ApplicationMasterService(newMockRMContext,
newMockRMContext.getScheduler());
TestRMAppManager newAppMonitor = new TestRMAppManager(newMockRMContext,
new ClientToAMTokenSecretManagerInRM(),
newMockRMContext.getScheduler(), masterService,
new ApplicationACLsManager(conf), conf);
//only user test has permission to submit to 'test' queue
newAppMonitor.submitApplication(asContext, "test"); newAppMonitor.submitApplication(asContext, "test");
RMApp app = newMockRMContext.getRMApps().get(appId);
Assert.assertNotNull("app should not be null", app);
Assert.assertEquals("the queue should be placed on 'test' queue", "test", app.getQueue());
try { try {
//should fail since user does not have permission to submit to queue
// 'test'
asContext.setApplicationId(appId = MockApps.newAppID(2)); asContext.setApplicationId(appId = MockApps.newAppID(2));
newAppMonitor.submitApplication(asContext, "test1"); newAppMonitor.submitApplication(asContext, "test1");
Assert.fail("should fail since test1 does not have permission to submit to queue");
} catch(YarnException e) { } catch(YarnException e) {
assertTrue(e.getCause() instanceof AccessControlException); assertTrue(e.getCause() instanceof AccessControlException);
} }
} }
@Test @Test
public void public void testQueueSubmitWithACLsEnabledWithQueueMappingForAutoCreatedQueue()
testQueueSubmitWithACLsEnabledWithQueueMappingForAutoCreatedQueue() throws IOException, YarnException {
throws IOException, YarnException, InterruptedException {
YarnConfiguration conf = new YarnConfiguration(); YarnConfiguration conf = new YarnConfiguration();
conf.set(YarnConfiguration.YARN_ACL_ENABLE, "true"); conf.set(YarnConfiguration.YARN_ACL_ENABLE, "true");
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
@ -358,8 +364,11 @@ public class TestAppManager extends AppManagerTestBase{
conf, false); conf, false);
csConf.set(PREFIX + "root.queues", "default,managedparent"); csConf.set(PREFIX + "root.queues", "default,managedparent");
csConf.setFloat(PREFIX + "root.default.capacity", 50.0f); csConf.setCapacity("root.default", 50.0f);
csConf.setFloat(PREFIX + "root.default.maximum-capacity", 100.0f); csConf.setMaximumCapacity("root.default", 100.0f);
csConf.setCapacity("root.managedparent", 50.0f);
csConf.setMaximumCapacity("root.managedparent", 100.0f);
csConf.set(PREFIX + "root.acl_submit_applications", " "); csConf.set(PREFIX + "root.acl_submit_applications", " ");
csConf.set(PREFIX + "root.acl_administer_queue", " "); csConf.set(PREFIX + "root.acl_administer_queue", " ");
@ -374,22 +383,9 @@ public class TestAppManager extends AppManagerTestBase{
csConf.setAutoCreatedLeafQueueConfigCapacity("root.managedparent", 30f); csConf.setAutoCreatedLeafQueueConfigCapacity("root.managedparent", 30f);
csConf.setAutoCreatedLeafQueueConfigMaxCapacity("root.managedparent", 100f); csConf.setAutoCreatedLeafQueueConfigMaxCapacity("root.managedparent", 100f);
// Setup a PlacementManager returns a new queue
PlacementManager placementMgr = mock(PlacementManager.class);
doAnswer(new Answer<ApplicationPlacementContext>() {
@Override
public ApplicationPlacementContext answer(InvocationOnMock invocation)
throws Throwable {
return new ApplicationPlacementContext("user1", "managedparent");
}
}).when(placementMgr).placeApplication(
any(ApplicationSubmissionContext.class), matches("user1|user2"));
asContext.setQueue("oldQueue"); asContext.setQueue("oldQueue");
MockRM newMockRM = new MockRM(conf); MockRM newMockRM = new MockRM(csConf);
CapacityScheduler cs = CapacityScheduler cs =
((CapacityScheduler) newMockRM.getResourceScheduler()); ((CapacityScheduler) newMockRM.getResourceScheduler());
ManagedParentQueue managedParentQueue = new ManagedParentQueue(cs, ManagedParentQueue managedParentQueue = new ManagedParentQueue(cs,
@ -398,22 +394,21 @@ public class TestAppManager extends AppManagerTestBase{
managedParentQueue); managedParentQueue);
RMContext newMockRMContext = newMockRM.getRMContext(); RMContext newMockRMContext = newMockRM.getRMContext();
newMockRMContext.setQueuePlacementManager(placementMgr); newMockRMContext.setQueuePlacementManager(createMockPlacementManager(
ApplicationMasterService masterService = new ApplicationMasterService( "user1|user2", "user1", "managedparent"));
newMockRMContext, newMockRMContext.getScheduler()); TestRMAppManager newAppMonitor = createAppManager(newMockRMContext, conf);
TestRMAppManager newAppMonitor = new TestRMAppManager(newMockRMContext,
new ClientToAMTokenSecretManagerInRM(), newMockRMContext.getScheduler(),
masterService, new ApplicationACLsManager(conf), conf);
//only user test has permission to submit to 'user1' queue
newAppMonitor.submitApplication(asContext, "user1"); newAppMonitor.submitApplication(asContext, "user1");
RMApp app = newMockRMContext.getRMApps().get(appId);
Assert.assertNotNull("app should not be null", app);
Assert.assertEquals("the queue should be placed on 'managedparent.user1' queue",
"managedparent.user1",
app.getQueue());
try { try {
//should fail since user does not have permission to submit to queue
// 'managedparent'
asContext.setApplicationId(appId = MockApps.newAppID(2)); asContext.setApplicationId(appId = MockApps.newAppID(2));
newAppMonitor.submitApplication(asContext, "user2"); newAppMonitor.submitApplication(asContext, "user2");
Assert.fail("should fail since user2 does not have permission to submit to queue");
} catch (YarnException e) { } catch (YarnException e) {
assertTrue(e.getCause() instanceof AccessControlException); assertTrue(e.getCause() instanceof AccessControlException);
} }