@Test public void testAddReservation() { 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)); } }
@Override public boolean addReservation(ReservationAllocation reservation) throws PlanningException { InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation) reservation; if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } writeLock.lock(); try { if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, inMemReservation); reservation.setAcceptanceTimestamp(clock.getTime()); ReservationInterval searchInterval = new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations == null) { reservations = new HashSet<InMemoryReservationAllocation>(); } if (!reservations.add(inMemReservation)) { LOG.error("Unable to add reservation: {} to plan.", inMemReservation.getReservationId()); return false; } currentReservations.put(searchInterval, reservations); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } finally { writeLock.unlock(); } }
InMemoryPlan implements Plan { @Override public boolean addReservation(ReservationAllocation reservation) throws PlanningException { InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation) reservation; if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } writeLock.lock(); try { if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, inMemReservation); reservation.setAcceptanceTimestamp(clock.getTime()); ReservationInterval searchInterval = new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations == null) { reservations = new HashSet<InMemoryReservationAllocation>(); } if (!reservations.add(inMemReservation)) { LOG.error("Unable to add reservation: {} to plan.", inMemReservation.getReservationId()); return false; } currentReservations.put(searchInterval, reservations); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } finally { writeLock.unlock(); } } }
InMemoryPlan implements Plan { @Override public boolean addReservation(ReservationAllocation reservation) throws PlanningException { InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation) reservation; if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } writeLock.lock(); try { if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, inMemReservation); reservation.setAcceptanceTimestamp(clock.getTime()); ReservationInterval searchInterval = new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations == null) { reservations = new HashSet<InMemoryReservationAllocation>(); } if (!reservations.add(inMemReservation)) { LOG.error("Unable to add reservation: {} to plan.", inMemReservation.getReservationId()); return false; } currentReservations.put(searchInterval, reservations); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } 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 addReservation(ReservationAllocation reservation) throws PlanningException { InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation) reservation; if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } writeLock.lock(); try { if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, inMemReservation); reservation.setAcceptanceTimestamp(clock.getTime()); ReservationInterval searchInterval = new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations == null) { reservations = new HashSet<InMemoryReservationAllocation>(); } if (!reservations.add(inMemReservation)) { LOG.error("Unable to add reservation: {} to plan.", inMemReservation.getReservationId()); return false; } currentReservations.put(searchInterval, reservations); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } 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 addReservation(ReservationAllocation reservation) throws PlanningException { InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation) reservation; if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } writeLock.lock(); try { if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, inMemReservation); reservation.setAcceptanceTimestamp(clock.getTime()); ReservationInterval searchInterval = new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations == null) { reservations = new HashSet<InMemoryReservationAllocation>(); } if (!reservations.add(inMemReservation)) { LOG.error("Unable to add reservation: {} to plan.", inMemReservation.getReservationId()); return false; } currentReservations.put(searchInterval, reservations); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } 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();  }