@Test public void testUpdateReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); 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.addReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i]), (alloc[i])), plan.getTotalCommittedResources(start + i)); Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i]), (alloc[i])), plan.getConsumptionForUser(user, start + i)); } start = 110; int[] updatedAlloc = { 0, 5, 10, 10, 5, 0 }; allocations = generateAllocation(start, updatedAlloc, true); rDef = createSimpleReservationDefinition(start, start + updatedAlloc.length, updatedAlloc.length, allocations.values()); rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + updatedAlloc.length, allocations, resCalc, minAlloc); try { plan.updateReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); for (int i = 0; i < updatedAlloc.length; i++) { Assert.assertEquals( Resource.newInstance(1024 * (updatedAlloc[i] + i), updatedAlloc[i] + i, updatedAlloc[i] + i), plan.getTotalCommittedResources(start + i)); Assert.assertEquals( Resource.newInstance(1024 * (updatedAlloc[i] + i), updatedAlloc[i] + i, updatedAlloc[i] + i), plan.getConsumptionForUser(user, start + i)); } }
@Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Sucessfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } }
InMemoryPlan implements Plan { @Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Sucessfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } } }
InMemoryPlan implements Plan { @Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Sucessfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } } InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry);   InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry, Clock clock); }
InMemoryPlan implements Plan { @Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Sucessfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } } InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry);   InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry, Clock clock); @Override QueueMetrics getQueueMetrics(); Set<ReservationAllocation> getAllReservations(); @Override boolean addReservation(ReservationAllocation reservation); @Override boolean updateReservation(ReservationAllocation reservation); @Override boolean deleteReservation(ReservationId reservationID); @Override void archiveCompletedReservations(long tick); @Override Set<ReservationAllocation> getReservationsAtTime(long tick); @Override long getStep(); @Override SharingPolicy getSharingPolicy(); @Override ReservationAgent getReservationAgent(); @Override Resource getConsumptionForUser(String user, long t); @Override Resource getTotalCommittedResources(long t); @Override ReservationAllocation getReservationById(ReservationId reservationID); @Override Resource getTotalCapacity(); @Override Resource getMinimumAllocation(); @Override void setTotalCapacity(Resource cap); long getEarliestStartTime(); @Override long getLastEndTime(); @Override ResourceCalculator getResourceCalculator(); @Override String getQueueName(); @Override Resource getMaximumAllocation(); String toCumulativeString(); @Override Planner getReplanner(); @Override boolean getMoveOnExpiry(); @Override String toString(); }
InMemoryPlan implements Plan { @Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Sucessfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } } InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry);   InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry, Clock clock); @Override QueueMetrics getQueueMetrics(); Set<ReservationAllocation> getAllReservations(); @Override boolean addReservation(ReservationAllocation reservation); @Override boolean updateReservation(ReservationAllocation reservation); @Override boolean deleteReservation(ReservationId reservationID); @Override void archiveCompletedReservations(long tick); @Override Set<ReservationAllocation> getReservationsAtTime(long tick); @Override long getStep(); @Override SharingPolicy getSharingPolicy(); @Override ReservationAgent getReservationAgent(); @Override Resource getConsumptionForUser(String user, long t); @Override Resource getTotalCommittedResources(long t); @Override ReservationAllocation getReservationById(ReservationId reservationID); @Override Resource getTotalCapacity(); @Override Resource getMinimumAllocation(); @Override void setTotalCapacity(Resource cap); long getEarliestStartTime(); @Override long getLastEndTime(); @Override ResourceCalculator getResourceCalculator(); @Override String getQueueName(); @Override Resource getMaximumAllocation(); String toCumulativeString(); @Override Planner getReplanner(); @Override boolean getMoveOnExpiry(); @Override String toString();  }