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; }
private boolean removeReservation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); ReservationInterval searchInterval = new ReservationInterval( reservation.getStartTime(), reservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval);
@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); } }
public static ReservationAllocationStateProto buildStateProto( ReservationAllocation allocation) { ReservationAllocationStateProto.Builder builder = ReservationAllocationStateProto.newBuilder(); builder.setAcceptanceTime(allocation.getAcceptanceTime()); builder.setContainsGangs(allocation.containsGangs()); builder.setStartTime(allocation.getStartTime()); builder.setEndTime(allocation.getEndTime()); builder.setUser(allocation.getUser()); ReservationDefinitionProto definitionProto = convertToProtoFormat( allocation.getReservationDefinition()); builder.setReservationDefinition(definitionProto); for (Map.Entry<ReservationInterval, Resource> entry : allocation.getAllocationRequests().entrySet()) { ResourceAllocationRequestProto p = ResourceAllocationRequestProto.newBuilder() .setStartTime(entry.getKey().getStartTime()) .setEndTime(entry.getKey().getEndTime()) .setResource(convertToProtoFormat(entry.getValue())) .build(); builder.addAllocationRequests(p); } ReservationAllocationStateProto allocationProto = builder.build(); return allocationProto; }
long checkEnd = reservation.getEndTime() + validWindow;
rAllocation.getStartTime(), rAllocation.getEndTime()); Set<ReservationAllocation> rAllocations = plan.getReservations(null, interval, ""); long duration = rAllocation.getEndTime() - rAllocation.getStartTime(); interval = new ReservationInterval( rAllocation.getStartTime() + duration * (long) 0.3, rAllocation.getEndTime() - duration * (long) 0.3); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 1); new ReservationInterval(rAllocation.getEndTime(), Long.MAX_VALUE); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0);
long endTime = reservation.getEndTime(); long step = plan.getStep();
long endTime = reservation.getEndTime(); long step = plan.getStep();
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()); }
long endTime = reservation.getEndTime(); long step = plan.getStep();
long endTime = reservation.getEndTime(); long step = plan.getStep();
void assertAllocationStateEqual( ReservationAllocation expected, ReservationAllocationStateProto actual) { Assert.assertEquals( expected.getAcceptanceTime(), actual.getAcceptanceTime()); Assert.assertEquals(expected.getStartTime(), actual.getStartTime()); Assert.assertEquals(expected.getEndTime(), actual.getEndTime()); Assert.assertEquals(expected.containsGangs(), actual.getContainsGangs()); Assert.assertEquals(expected.getUser(), actual.getUser()); assertEquals( expected.getReservationDefinition(), ReservationSystemUtil.convertFromProtoFormat( actual.getReservationDefinition())); assertEquals( expected.getAllocationRequests(), ReservationSystemUtil.toAllocations( actual.getAllocationRequestsList())); } }