ReservationInputValidator { public Plan validateReservationSubmissionRequest( ReservationSystem reservationSystem, ReservationSubmissionRequest request, ReservationId reservationId) throws YarnException { String message; if (reservationId == null) { message = "Reservation id cannot be null. Please try again specifying " + " a valid reservation id by creating a new reservation id."; throw RPCUtil.getRemoteException(message); } String queue = request.getQueue(); Plan plan = getPlanFromQueue(reservationSystem, queue, AuditConstants.SUBMIT_RESERVATION_REQUEST); validateReservationDefinition(reservationId, request.getReservationDefinition(), plan, AuditConstants.SUBMIT_RESERVATION_REQUEST); return plan; } ReservationInputValidator(Clock clock); Plan validateReservationSubmissionRequest(
      ReservationSystem reservationSystem, ReservationSubmissionRequest request,
      ReservationId reservationId); Plan validateReservationUpdateRequest(
      ReservationSystem reservationSystem, ReservationUpdateRequest request); Plan validateReservationListRequest(
      ReservationSystem reservationSystem, ReservationListRequest request); Plan validateReservationDeleteRequest(
      ReservationSystem reservationSystem, ReservationDeleteRequest request);  }
@Test public void testSubmitReservationNormal() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testSubmitReservationDoesNotExist() { ReservationSubmissionRequest request = new ReservationSubmissionRequestPBImpl(); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertEquals("The queue is not specified. Please try again with a " + "valid reservable queue.", message); LOG.info(message); } }
@Test public void testSubmitReservationInvalidPlan() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3); when(rSystem.getPlan(PLAN_NAME)).thenReturn(null); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .endsWith(" is not managed by reservation system. Please try again with a valid reservable queue.")); LOG.info(message); } }
@Test public void testSubmitReservationNoDefinition() { ReservationSubmissionRequest request = new ReservationSubmissionRequestPBImpl(); request.setQueue(PLAN_NAME); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertEquals("Missing reservation definition. Please try again by " + "specifying a reservation definition.", message); LOG.info(message); } }
@Test public void testSubmitReservationInvalidDeadline() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 0, 3); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("The specified deadline: 0 is the past")); LOG.info(message); } }
@Test public void testSubmitReservationInvalidRR() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(0, 0, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } }
@Test public void testSubmitReservationEmptyRR() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 0, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } }
@Test public void testSubmitReservationInvalidDuration() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 3, 4); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message.startsWith("The time difference")); Assert .assertTrue(message .contains("must be greater or equal to the minimum resource duration")); LOG.info(message); } }
@Test public void testSubmitReservationExceedsGangSize() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 4); Resource resource = Resource.newInstance(512, 1); when(plan.getTotalCapacity()).thenReturn(resource); Plan plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message.startsWith( "The size of the largest gang in the reservation definition")); Assert.assertTrue(message.contains( "exceed the capacity available ")); LOG.info(message); } }
@Test public void testSubmitReservationValidRecurrenceExpression() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, "600000"); plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testSubmitReservationNegativeRecurrenceExpression() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, "-1234"); plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } }
@Test public void testSubmitReservationMaxPeriodIndivisibleByRecurrenceExp() { long indivisibleRecurrence = YarnConfiguration.DEFAULT_RM_RESERVATION_SYSTEM_MAX_PERIODICITY / 2 + 1; String recurrenceExp = Long.toString(indivisibleRecurrence); ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, recurrenceExp); plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message.startsWith("The maximum periodicity:")); LOG.info(message); } }
@Test public void testSubmitReservationInvalidRecurrenceExpression() { ReservationSubmissionRequest request = createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, "123abc"); plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } request = createSimpleReservationSubmissionRequest(1, 1, 1, 50, 3, "10"); plan = null; try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } }