ReservationInputValidator { public Plan validateReservationUpdateRequest( ReservationSystem reservationSystem, ReservationUpdateRequest request) throws YarnException { ReservationId reservationId = request.getReservationId(); Plan plan = validateReservation(reservationSystem, reservationId, AuditConstants.UPDATE_RESERVATION_REQUEST); validateReservationDefinition(reservationId, request.getReservationDefinition(), plan, AuditConstants.UPDATE_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 testUpdateReservationNormal() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testUpdateReservationNoID() { ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl(); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); } }
@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); } }
@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); } }
@Test public void testUpdateReservationNoDefinition() { ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl(); request.setReservationId(ReservationSystemTestUtil.getNewReservationId()); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .startsWith("Missing reservation definition. Please try again by specifying a reservation definition.")); LOG.info(message); } }
@Test public void testUpdateReservationInvalidDeadline() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 0, 3); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); 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 testUpdateReservationInvalidRR() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(0, 0, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); 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 testUpdateReservationEmptyRR() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 0, 1, 5, 3); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); 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 testUpdateReservationInvalidDuration() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 3, 4); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .contains("must be greater or equal to the minimum resource duration")); LOG.info(message); } }
@Test public void testUpdateReservationExceedsGangSize() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 4); Resource resource = Resource.newInstance(512, 1); when(plan.getTotalCapacity()).thenReturn(resource); Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); 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 testUpdateReservationValidRecurrenceExpression() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "600000"); plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testUpdateReservationNegativeRecurrenceExpression() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "-1234"); plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } }
@Test public void testUpdateReservationInvalidRecurrenceExpression() { ReservationUpdateRequest request = createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "123abc"); plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } request = createSimpleReservationUpdateRequest(1, 1, 1, 50, 3, "10"); plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert.assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } }