@VisibleForTesting ApplicationPlacementContext placeApplication( PlacementManager placementManager, ApplicationSubmissionContext context, String user, boolean isRecovery) throws YarnException { ApplicationPlacementContext placementContext = null; if (placementManager != null) { try { placementContext = placementManager.placeApplication(context, user); } catch (YarnException e) { // Placement could also fail if the user doesn't exist in system // skip if the user is not found during recovery. if (isRecovery) { LOG.warn("PlaceApplication failed,skipping on recovery of rm"); return placementContext; } throw e; } } if (placementContext == null && (context.getQueue() == null) || context .getQueue().isEmpty()) { String msg = "Failed to place application " + context.getApplicationId() + " to queue and specified " + "queue is invalid : " + context .getQueue(); LOG.error(msg); throw new YarnException(msg); } return placementContext; }
@Test public void testRMAppSubmitWithQueueChanged() throws Exception { // 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("newQueue"); } }).when(placementMgr).placeApplication( any(ApplicationSubmissionContext.class), any(String.class)); rmContext.setQueuePlacementManager(placementMgr); asContext.setQueue("oldQueue"); appMonitor.submitApplication(asContext, "test"); RMApp app = rmContext.getRMApps().get(appId); RMAppEvent event = new RMAppEvent(appId, RMAppEventType.START); rmContext.getRMApps().get(appId).handle(event); event = new RMAppEvent(appId, RMAppEventType.APP_NEW_SAVED); rmContext.getRMApps().get(appId).handle(event); Assert.assertNotNull("app is null", app); Assert.assertEquals("newQueue", asContext.getQueue()); // wait for event to be processed int timeoutSecs = 0; while ((getAppEventType() == RMAppEventType.KILL) && timeoutSecs++ < 20) { Thread.sleep(1000); } Assert.assertEquals("app event type sent is wrong", RMAppEventType.START, getAppEventType()); }
pm.placeApplication(asc, USER2)); QueueMappingEntity queueMappingEntity = new QueueMappingEntity(APP_NAME, USER1, PARENT_QUEUE); pm.updateRules(queuePlacementRules); try { ApplicationPlacementContext pc = pm.placeApplication(asc, USER2); Assert.assertNotNull(pc); } catch (Exception e) {
PlacementManager placementMgr = mock(PlacementManager.class); doThrow(new YarnException("No groups for user")).when(placementMgr) .placeApplication(any(ApplicationSubmissionContext.class), any(String.class)); MockRM rm2 = new MockRM(conf, memStore) {
}).when(placementMgr).placeApplication( any(ApplicationSubmissionContext.class), matches("test1")); doAnswer(new Answer<ApplicationPlacementContext>() { }).when(placementMgr).placeApplication( any(ApplicationSubmissionContext.class), matches("test2"));
}).when(placementMgr).placeApplication( any(ApplicationSubmissionContext.class), matches("test"));
}).when(placementMgr).placeApplication( any(ApplicationSubmissionContext.class), matches("user1|user2"));