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; }
@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 boolean removeReservation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); ReservationInterval searchInterval = new ReservationInterval( reservation.getStartTime(), reservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval);
earliestActive = reservation.getStartTime(); latestActive = Long.MAX_VALUE;
earliestActive = reservation.getStartTime(); latestActive = Long.MAX_VALUE;
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 checkStart = reservation.getStartTime() - validWindow; 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, ""); interval = new ReservationInterval(0, rAllocation.getStartTime()); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 1); interval = new ReservationInterval(0, rAllocation.getStartTime() / 2); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0);
@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); }
long startTime = reservation.getStartTime(); long endTime = reservation.getEndTime(); long step = plan.getStep();
long startTime = reservation.getStartTime(); 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()); }
long startTime = reservation.getStartTime(); long endTime = reservation.getEndTime(); long step = plan.getStep();
long startTime = reservation.getStartTime(); 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())); } }