private boolean removeReservation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); ReservationInterval searchInterval = new ReservationInterval(reservation.getStartTime(), reservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations != null) { if (!reservations.remove(reservation)) { LOG.error("Unable to remove reservation: {} from plan.", reservation.getReservationId()); return false; } if (reservations.isEmpty()) { currentReservations.remove(searchInterval); } } else { String errMsg = "The specified Reservation with ID " + reservation.getReservationId() + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } reservationTable.remove(reservation.getReservationId()); decrementAllocation(reservation); LOG.info("Sucessfully deleted reservation: {} in plan.", reservation.getReservationId()); return true; }
private boolean removeReservation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); ReservationInterval searchInterval = new ReservationInterval(reservation.getStartTime(), reservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations != null) { if (!reservations.remove(reservation)) { LOG.error("Unable to remove reservation: {} from plan.", reservation.getReservationId()); return false; } if (reservations.isEmpty()) { currentReservations.remove(searchInterval); } } else { String errMsg = "The specified Reservation with ID " + reservation.getReservationId() + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } reservationTable.remove(reservation.getReservationId()); decrementAllocation(reservation); LOG.info("Sucessfully deleted reservation: {} in plan.", reservation.getReservationId()); return true; }
protected int getReservedResources(long now, Set<ReservationAllocation> currentReservations, Set<String> curReservationNames, Resource reservedResources) { int numRes = 0; if (currentReservations != null) { numRes = currentReservations.size(); for (ReservationAllocation reservation : currentReservations) { curReservationNames.add(reservation.getReservationId().toString()); Resources.addTo(reservedResources, reservation.getResourcesAtTime(now)); } } return numRes; }
protected int getReservedResources(long now, Set<ReservationAllocation> currentReservations, Set<String> curReservationNames, Resource reservedResources) { int numRes = 0; if (currentReservations != null) { numRes = currentReservations.size(); for (ReservationAllocation reservation : currentReservations) { curReservationNames.add(reservation.getReservationId().toString()); Resources.addTo(reservedResources, reservation.getResourcesAtTime(now)); } } return numRes; }
protected int getReservedResources(long now, Set<ReservationAllocation> currentReservations, Set<String> curReservationNames, Resource reservedResources) { int numRes = 0; if (currentReservations != null) { numRes = currentReservations.size(); for (ReservationAllocation reservation : currentReservations) { curReservationNames.add(reservation.getReservationId().toString()); Resources.addTo(reservedResources, reservation.getResourcesAtTime(now)); } } return numRes; }
boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); reservation.getReservationId()); return result; } else { reservation.getReservationId()); return result;
if (rmStateStore != null) { rmStateStore.removeReservation(getQueueName(), reservation.getReservationId().toString()); reservation.getReservationId()); return false; + reservation.getReservationId() + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); reservationTable.remove(reservation.getReservationId()); decrementAllocation(reservation); LOG.info("Sucessfully deleted reservation: {} in plan.", reservation.getReservationId()); return true;
public static List<ReservationAllocationState> convertAllocationsToReservationInfo(Set<ReservationAllocation> res, boolean includeResourceAllocations) { List<ReservationAllocationState> reservationInfo = new ArrayList<>(); Map<ReservationInterval, Resource> requests; for (ReservationAllocation allocation : res) { List<ResourceAllocationRequest> allocations = new ArrayList<>(); if (includeResourceAllocations) { requests = allocation.getAllocationRequests(); for (Map.Entry<ReservationInterval, Resource> request : requests.entrySet()) { ReservationInterval interval = request.getKey(); allocations.add(ResourceAllocationRequest.newInstance( interval.getStartTime(), interval.getEndTime(), request.getValue())); } } reservationInfo.add(ReservationAllocationState.newInstance( allocation.getAcceptanceTime(), allocation.getUser(), allocations, allocation.getReservationId(), allocation.getReservationDefinition())); } return reservationInfo; } }
private Resource getUnallocatedReservedResources( ReservationAllocation reservation) { Resource resResource; Resource reservationResource = planFollower.getReservationQueueResourceIfExists(plan, reservation.getReservationId()); if (reservationResource != null) { resResource = Resources.subtract(reservation.getResourcesAtTime(now), reservationResource); } else { resResource = reservation.getResourcesAtTime(now); } return resResource; }
private Resource getUnallocatedReservedResources( ReservationAllocation reservation) { Resource resResource; Resource reservationResource = planFollower .getReservationQueueResourceIfExists (plan, reservation.getReservationId()); if (reservationResource != null) { resResource = Resources.subtract( reservation.getResourcesAtTime(now), reservationResource); } else { resResource = reservation.getResourcesAtTime(now); } return resResource; }
private Resource getUnallocatedReservedResources( ReservationAllocation reservation) { Resource resResource; Resource reservationResource = planFollower .getReservationQueueResourceIfExists (plan, reservation.getReservationId()); if (reservationResource != null) { resResource = Resources.subtract( reservation.getResourcesAtTime(now), reservationResource); } else { resResource = reservation.getResourcesAtTime(now); } return resResource; }
@Override public int compareTo(ReservationAllocation other) { // reverse order of acceptance if (this.getAcceptanceTime() > other.getAcceptanceTime()) { return -1; } if (this.getAcceptanceTime() < other.getAcceptanceTime()) { return 1; } if (this.getReservationId().getId() > other.getReservationId().getId()) { return -1; } if (this.getReservationId().getId() < other.getReservationId().getId()) { return 1; } return 0; }
@Override public void validate(Plan plan, ReservationAllocation reservation) throws PlanningException { RLESparseResourceAllocation available = plan.getAvailableResourceOverTime( reservation.getUser(), reservation.getReservationId(), reservation.getStartTime(), reservation.getEndTime(), reservation.getPeriodicity()); // test the reservation does not exceed what is available try { RLESparseResourceAllocation ask = reservation.getResourcesOverTime( reservation.getStartTime(), reservation.getEndTime()); RLESparseResourceAllocation .merge(plan.getResourceCalculator(), plan.getTotalCapacity(), available, ask, RLESparseResourceAllocation.RLEOperator.subtractTestNonNegative, reservation.getStartTime(), reservation.getEndTime()); } catch (PlanningException p) { throw new ResourceOverCommitException( "Resources at time " + reservation.getStartTime() + " would be overcommitted by accepting reservation: " + reservation.getReservationId(), p); } }
private void testPositiveGetRecurringReservationsHelper(long reservationStart, long reservationEnd, long searchStart, long searchEnd, long cycles, long period, int periodMultiplier) { maxPeriodicity = period * periodMultiplier; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); ReservationId reservationID = submitReservation(plan, reservationStart, reservationEnd, period); for (int i = 0; i < cycles; i++) { long searchStepIncrease = i * period; Set<ReservationAllocation> alloc = plan.getReservations(null, new ReservationInterval(searchStart + searchStepIncrease, searchEnd + searchStepIncrease)); assertEquals(1, alloc.size()); assertEquals(reservationID, alloc.iterator().next().getReservationId()); } }
plan.getReservationById(reservation.getReservationId()); throw new ResourceOverCommitException("Resources at time " + t + " would be overcommitted by " + "accepting reservation: " + reservation.getReservationId());
plan.getReservationById(reservation.getReservationId()); throw new ResourceOverCommitException("Resources at time " + t + " would be overcommitted by " + "accepting reservation: " + reservation.getReservationId());
private void doAssertions(ReservationAllocation rAllocation, ReservationId reservationID, ReservationDefinition rDef, Map<ReservationInterval, Resource> allocations, int start, int[] alloc) { Assert.assertEquals(reservationID, rAllocation.getReservationId()); Assert.assertEquals(rDef, rAllocation.getReservationDefinition()); Assert.assertEquals(allocations, rAllocation.getAllocationRequests()); Assert.assertEquals(user, rAllocation.getUser()); Assert.assertEquals(planName, rAllocation.getPlanName()); Assert.assertEquals(start, rAllocation.getStartTime()); Assert.assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); }
private void doAssertions(ReservationAllocation rAllocation, ReservationId reservationID, ReservationDefinition rDef, Map<ReservationInterval, ReservationRequest> allocations, int start, int[] alloc) { Assert.assertEquals(reservationID, rAllocation.getReservationId()); Assert.assertEquals(rDef, rAllocation.getReservationDefinition()); Assert.assertEquals(allocations, rAllocation.getAllocationRequests()); Assert.assertEquals(user, rAllocation.getUser()); Assert.assertEquals(planName, rAllocation.getPlanName()); Assert.assertEquals(start, rAllocation.getStartTime()); Assert.assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); }
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()); }
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()); }