@Override public boolean updateReservation(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract) throws PlanningException { return computeAllocation(reservationId, user, plan, contract, plan.getReservationById(reservationId)); }
@Override public boolean updateReservation(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract) throws PlanningException { // Get the old allocation ReservationAllocation oldAlloc = plan.getReservationById(reservationId); // Allocate (ignores the old allocation) return allocateUser(reservationId, user, plan, contract, oldAlloc); }
@Override public boolean updateReservation(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract) throws PlanningException { return computeAllocation(reservationId, user, plan, contract, plan.getReservationById(reservationId)); }
@Test public void testDeleteReservationNormal() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); request.setReservationId(reservationID); ReservationAllocation reservation = mock(ReservationAllocation.class); when(plan.getReservationById(reservationID)).thenReturn(reservation); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testDeleteReservationNormal() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); request.setReservationId(reservationID); ReservationAllocation reservation = mock(ReservationAllocation.class); when(plan.getReservationById(reservationID)).thenReturn(reservation); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testDeleteNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to delete a reservation without adding Assert.assertNull(plan.getReservationById(reservationID)); try { plan.deleteReservation(reservationID); Assert.fail("Delete should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }
@Test public void testDeleteNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to delete a reservation without adding Assert.assertNull(plan.getReservationById(reservationID)); try { plan.deleteReservation(reservationID); Assert.fail("Delete should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }
private void validateReservation(Plan plan, ReservationId resId, ReservationDefinition rDef) { ReservationAllocation reservation = plan.getReservationById(resId); Assert.assertNotNull(reservation); Assert.assertEquals(rDef.getDeadline(), reservation.getReservationDefinition().getDeadline()); }
@Test public void testUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to update a reservation without adding int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.updateReservation(rAllocation); Assert.fail("Update should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }
private ReservationId submitReservation(Plan plan, long reservationStartTime, long reservationEndTime, long period) { ReservationId reservation = ReservationSystemTestUtil.getNewReservationId(); ReservationAllocation rAllocation = createReservationAllocation( reservation, reservationStartTime, reservationEndTime, String.valueOf(period)); rAllocation.setPeriodicity(period); Assert.assertNull(plan.getReservationById(reservation)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } return reservation; }
@Test public void testUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to update a reservation without adding int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocations, resCalc, minAlloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.updateReservation(rAllocation); Assert.fail("Update should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }
@Test public void testAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = {}; int start = 100; Map<ReservationInterval, ReservationRequest> allocations = new HashMap<ReservationInterval, ReservationRequest>(); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocations, resCalc, minAlloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); } }
private void doAssertions(Plan plan, ReservationAllocation rAllocation) { ReservationId reservationID = rAllocation.getReservationId(); Assert.assertNotNull(plan.getReservationById(reservationID)); Assert.assertEquals(rAllocation, plan.getReservationById(reservationID)); Assert.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); Assert.assertEquals(rAllocation.getEndTime(), plan.getLastEndTime()); Assert.assertEquals(totalCapacity, plan.getTotalCapacity()); Assert.assertEquals(minAlloc, plan.getMinimumAllocation()); Assert.assertEquals(maxAlloc, plan.getMaximumAllocation()); Assert.assertEquals(resCalc, plan.getResourceCalculator()); Assert.assertEquals(planName, plan.getQueueName()); Assert.assertTrue(plan.getMoveOnExpiry()); }
@Test public void testGetReservationsWithNoInput() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } // Verify that getReservations defaults to getting all reservations if no // reservationID, time interval, and user is provided, Set<ReservationAllocation> rAllocations = plan.getReservations(null, null, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
private void doAssertions(Plan plan, ReservationAllocation rAllocation) { ReservationId reservationID = rAllocation.getReservationId(); Assert.assertNotNull(plan.getReservationById(reservationID)); assertEquals(rAllocation, plan.getReservationById(reservationID)); Assert.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); if (rAllocation.getPeriodicity() <= 0) { assertEquals(rAllocation.getEndTime(), plan.getLastEndTime()); } assertEquals(totalCapacity, plan.getTotalCapacity()); assertEquals(minAlloc, plan.getMinimumAllocation()); assertEquals(maxAlloc, plan.getMaximumAllocation()); assertEquals(resCalc, plan.getResourceCalculator()); assertEquals(planName, plan.getQueueName()); Assert.assertTrue(plan.getMoveOnExpiry()); }
protected void initialize(Plan plan, ReservationId reservationId, ReservationDefinition reservation) throws PlanningException { // Get plan step & capacity capacity = plan.getTotalCapacity(); step = plan.getStep(); // Get job parameters (type, arrival time & deadline) jobType = reservation.getReservationRequests().getInterpreter(); jobArrival = stepRoundUp(reservation.getArrival(), step); jobDeadline = stepRoundDown(reservation.getDeadline(), step); // Initialize the plan modifications planModifications = new RLESparseResourceAllocation(plan.getResourceCalculator()); // Dirty read of plan load // planLoads are not used by other StageAllocators... and don't deal // well with huge reservation ranges planLoads = plan.getCumulativeLoadOverTime(jobArrival, jobDeadline); ReservationAllocation oldRes = plan.getReservationById(reservationId); if (oldRes != null) { planLoads = RLESparseResourceAllocation.merge( plan.getResourceCalculator(), plan.getTotalCapacity(), planLoads, oldRes.getResourcesOverTime(jobArrival, jobDeadline), RLEOperator.subtract, jobArrival, jobDeadline); } }
@Test public void testGetReservationsAtTime() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Set<ReservationAllocation> rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime()); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
@Test public void testAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = {}; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } }
@Test public void testGetReservationsByInvalidId() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } // If reservationId is null, then nothing is returned. ReservationId invalidReservationID = ReservationSystemTestUtil.getNewReservationId(); Set<ReservationAllocation> rAllocations = plan.getReservations(invalidReservationID, null, ""); Assert.assertTrue(rAllocations.size() == 0); }
@Test public void testAddReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, 0); }