private Plan getPlanFromQueue(ReservationSystem reservationSystem, String queue, String auditConstant, String nullQueueErrorMessage, String nullPlanErrorMessage) throws YarnException { if (queue == null || queue.isEmpty()) { RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", nullQueueErrorMessage); throw RPCUtil.getRemoteException(nullQueueErrorMessage); } // check if the associated plan is valid Plan plan = reservationSystem.getPlan(queue); if (plan == null) { RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", nullPlanErrorMessage); throw RPCUtil.getRemoteException(nullPlanErrorMessage); } return plan; }
@Before public void setUp() { clock = mock(Clock.class); plan = mock(Plan.class); rSystem = mock(ReservationSystem.class); plans.put(PLAN_NAME, plan); rrValidator = new ReservationInputValidator(clock); when(clock.getTime()).thenReturn(1L); ResourceCalculator rCalc = new DefaultResourceCalculator(); Resource resource = Resource.newInstance(10240, 10); when(plan.getResourceCalculator()).thenReturn(rCalc); when(plan.getTotalCapacity()).thenReturn(resource); when(rSystem.getQueueForReservation(any(ReservationId.class))).thenReturn( PLAN_NAME); when(rSystem.getPlan(PLAN_NAME)).thenReturn(plan); }
private void refreshScheduler(String planName, ReservationDefinition contract, String reservationId) { if ((contract.getArrival() - clock.getTime()) < reservationSystem .getPlanFollowerTimeStep()) { LOG.debug(MessageFormat .format( "Reservation {0} is within threshold so attempting to create synchronously.", reservationId)); reservationSystem.synchronizePlan(planName, true); LOG.info(MessageFormat.format("Created reservation {0} synchronously.", reservationId)); } }
.getReservationsACLsManager(); ReservationACL reservationACL = getReservationACLFromAuditConstant( auditConstant); ReservationAllocation reservation; Plan plan = reservationSystem.getPlan(queueName); if (reservationId != null && plan != null) { reservation = plan.getReservationById(reservationId);
private Plan validateReservation(ReservationSystem reservationSystem, ReservationId reservationId, String auditConstant) throws YarnException { // check if the reservation id is valid if (reservationId == null) { String message = "Missing reservation id." + " Please try again by specifying a reservation id."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } String queue = reservationSystem.getQueueForReservation(reservationId); String nullQueueErrorMessage = "The specified reservation with ID: " + reservationId + " is unknown. Please try again with a valid reservation."; String nullPlanErrorMessage = "The specified reservation: " + reservationId + " is not associated with any valid plan." + " Please try again with a valid reservation."; return getPlanFromQueue(reservationSystem, queue, auditConstant, nullQueueErrorMessage, nullPlanErrorMessage); }
private void addNodeCapacityToPlan(MockRM rm, int memory, int vCores) { try { rm.registerNode("127.0.0.1:1", memory, vCores); int attempts = 10; do { rm1.drainEvents(); rm.getRMContext().getReservationSystem() .synchronizePlan(ReservationSystemTestUtil.reservationQ, false); if (rm.getRMContext().getReservationSystem() .getPlan(ReservationSystemTestUtil.reservationQ).getTotalCapacity() .getMemorySize() > 0) { break; } LOG.info("Waiting for node capacity to be added to plan"); Thread.sleep(100); } while (attempts-- > 0); if (attempts <= 0) { Assert.fail("Exhausted attempts in checking if node capacity was " + "added to the plan"); } } catch (Exception e) { Assert.fail(e.getMessage()); } }
recordFactory.newRecordInstance(ReservationSubmissionResponse.class); ReservationId reservationId = reservationSystem.getNewReservationId(); reservationSystem.setQueueForReservation(reservationId, queueName);
private void waitForReservationActivation(MockRM rm, ReservationId reservationId, String planName) { try { int attempts = 20; do { rm.getRMContext().getReservationSystem().synchronizePlan(planName, false); if (rm.getResourceScheduler() .getQueueInfo(reservationId.toString(), false, false) .getCapacity() > 0f) { break; } LOG.info("Waiting for reservation to be active"); Thread.sleep(100); } while (attempts-- > 0); if (attempts <= 0) { Assert .fail("Exceeded attempts in waiting for reservation to be active"); } } catch (Exception e) { Assert.fail(e.getMessage()); } }
private void refreshQueues() throws IOException, YarnException { rmContext.getScheduler().reinitialize(getConfig(), this.rmContext); // refresh the reservation system ReservationSystem rSystem = rmContext.getReservationSystem(); if (rSystem != null) { rSystem.reinitialize(getConfig(), rmContext); } }
reservationSystem = createReservationSystem(); if (reservationSystem != null) { reservationSystem.setRMContext(rmContext); addIfService(reservationSystem); rmContext.setReservationSystem(reservationSystem);
@Override public GetNewReservationResponse getNewReservation( GetNewReservationRequest request) throws YarnException, IOException { checkReservationSystem(); GetNewReservationResponse response = recordFactory.newRecordInstance(GetNewReservationResponse.class); ReservationId reservationId = reservationSystem.getNewReservationId(); response.setReservationId(reservationId); // Create a new Reservation Id return response; }
reservationSystem.setQueueForReservation(reservationId, queueName);
@Override public void editSchedule() { Collection<Plan> plans = getContext().getReservationSystem().getAllPlans().values(); try { for (Plan plan : plans) { long currReservations = plan.getReservationsAtTime(clock.getTime()).size(); long numberReservationQueues = getContext().getScheduler() .getQueueInfo(plan.getQueueName(), true, false).getChildQueues() .size(); if (currReservations != numberReservationQueues - 1) { logOrThrow("Number of reservations (" + currReservations + ") does NOT match the number of reservationQueues (" + (numberReservationQueues - 1) + "), while it should."); } } } catch (IOException io) { throw new InvariantViolationException("Issue during invariant check: ", io); } }
@Test public void testUpdateReservationDoesnotExist() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 4); ReservationId rId = request.getReservationId(); when(rSystem.getQueueForReservation(rId)).thenReturn(null); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message.equals(MessageFormat .format( "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", rId))); LOG.info(message); } }
recordFactory.newRecordInstance(ReservationSubmissionResponse.class); ReservationId reservationId = reservationSystem.getNewReservationId(); reservationSystem.setQueueForReservation(reservationId, queueName);
.synchronizePlan(ReservationSystemTestUtil.reservationQ, true); RMApp app1 = rm1.submitApp(200, "dynamicQApp", UserGroupInformation.getCurrentUser().getShortUserName(), null,
@Override public RefreshQueuesResponse refreshQueues(RefreshQueuesRequest request) throws YarnException, StandbyException { String argName = "refreshQueues"; final String msg = "refresh queues."; UserGroupInformation user = checkAcls(argName); checkRMStatus(user.getShortUserName(), argName, msg); RefreshQueuesResponse response = recordFactory.newRecordInstance(RefreshQueuesResponse.class); try { rmContext.getScheduler().reinitialize(getConfig(), this.rmContext); // refresh the reservation system ReservationSystem rSystem = rmContext.getReservationSystem(); if (rSystem != null) { rSystem.reinitialize(getConfig(), rmContext); } RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return response; } catch (IOException ioe) { throw logAndWrapException(ioe, user.getShortUserName(), argName, msg); } }
reservationSystem = createReservationSystem(); if (reservationSystem != null) { reservationSystem.setRMContext(rmContext); addIfService(reservationSystem); rmContext.setReservationSystem(reservationSystem);
private void registerNode(String host, int memory, int vCores) throws Exception { try { resourceManager.registerNode(host, memory, vCores); int attempts = 10; Collection<Plan> plans; do { resourceManager.drainEvents(); LOG.info("Waiting for node capacity to be added to plan"); plans = resourceManager.getRMContext().getReservationSystem() .getAllPlans().values(); if (checkCapacity(plans)) { break; } Thread.sleep(100); } while (attempts-- > 0); if (attempts <= 0) { Assert.fail("Exhausted attempts in checking if node capacity was " + "added to the plan"); } } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testUpdateReservationInvalidPlan() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 4); when(rSystem.getPlan(PLAN_NAME)).thenReturn(null); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); LOG.info(message); } }