private ReservationAllocation createReservationAllocation(long startTime, long deadline, long step, int[] alloc, ReservationId id, Resource minAlloc) { Map<ReservationInterval, Resource> allocations = ReservationSystemTestUtil .generateAllocation(startTime, step, alloc); ResourceCalculator rs = mock(ResourceCalculator.class); ReservationDefinition definition = ReservationSystemTestUtil .createSimpleReservationDefinition(startTime, deadline, step); return new InMemoryReservationAllocation(id, definition, "user", ReservationSystemTestUtil.reservationQ, startTime, startTime + step, allocations, rs, minAlloc, false); }
@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 String toString() { StringBuilder sBuf = new StringBuilder(); sBuf.append(getReservationId()).append(" user:").append(getUser()) .append(" startTime: ").append(getStartTime()).append(" endTime: ") .append(getEndTime()).append(" Periodiciy: ").append(periodicity) .append(" alloc:\n[").append(resourcesOverTime.toString()).append("] "); return sBuf.toString(); }
&& !reservation.getUser().equals(user)) { continue; long period = reservation.getPeriodicity(); if (period > 0) { long shift = reservation.getStartTime() % period; (reservation.getEndTime() -shift) % period; long periodicSearchStart = (startTime - shift) % period; long periodicSearchEnd = (endTime - shift) % period; if (reservation.getEndTime() > startTime) { flattenedReservations.add(reservation);
@Override public Set<ReservationAllocation> getReservationsAtTime(long tick) { ReservationInterval searchInterval = new ReservationInterval(tick, Long.MAX_VALUE); readLock.lock(); try { SortedMap<ReservationInterval, Set<InMemoryReservationAllocation>> reservations = currentReservations.headMap(searchInterval, true); if (!reservations.isEmpty()) { Set<ReservationAllocation> flattenedReservations = new HashSet<ReservationAllocation>(); for (Set<InMemoryReservationAllocation> reservationEntries : reservations .values()) { for (InMemoryReservationAllocation reservation : reservationEntries) { if (reservation.getEndTime() > tick) { flattenedReservations.add(reservation); } } } return Collections.unmodifiableSet(flattenedReservations); } else { return Collections.emptySet(); } } finally { readLock.unlock(); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InMemoryReservationAllocation other = (InMemoryReservationAllocation) obj; return this.reservationID.equals(other.getReservationId()); }
@Override public int compareTo(ReservationAllocation other) { // reverse order of acceptance if (this.getAcceptanceTime() > other.getAcceptanceTime()) { return -1; } if (this.getAcceptanceTime() < other.getAcceptanceTime()) { return 1; } return 0; }
@Override public Set<ReservationAllocation> getReservationsAtTime(long tick) { ReservationInterval searchInterval = new ReservationInterval(tick, Long.MAX_VALUE); readLock.lock(); try { SortedMap<ReservationInterval, Set<InMemoryReservationAllocation>> reservations = currentReservations.headMap(searchInterval, true); if (!reservations.isEmpty()) { Set<ReservationAllocation> flattenedReservations = new HashSet<ReservationAllocation>(); for (Set<InMemoryReservationAllocation> reservationEntries : reservations .values()) { for (InMemoryReservationAllocation reservation : reservationEntries) { if (reservation.getEndTime() > tick) { flattenedReservations.add(reservation); } } } return Collections.unmodifiableSet(flattenedReservations); } else { return Collections.emptySet(); } } finally { readLock.unlock(); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InMemoryReservationAllocation other = (InMemoryReservationAllocation) obj; return this.reservationID.equals(other.getReservationId()); }
@Override public int compareTo(ReservationAllocation other) { // reverse order of acceptance if (this.getAcceptanceTime() > other.getAcceptanceTime()) { return -1; } if (this.getAcceptanceTime() < other.getAcceptanceTime()) { return 1; } return 0; }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, long startTime, long endTime, String period) { ReservationInterval interval = new ReservationInterval(startTime, endTime); List<ReservationRequest> request = new ArrayList<>(); request.add(ReservationRequest.newInstance(minAlloc, 1, 1, endTime - startTime)); ReservationDefinition rDef = createSimpleReservationDefinition(startTime, endTime, endTime - startTime, request, period); Map<ReservationInterval, Resource> allocations = new HashMap<>(); allocations.put(interval, minAlloc); return new InMemoryReservationAllocation(reservationID, rDef, user, planName, startTime, endTime, allocations, resCalc, minAlloc); }
@Override public String toString() { StringBuilder sBuf = new StringBuilder(); sBuf.append(getReservationId()).append(" user:").append(getUser()) .append(" startTime: ").append(getStartTime()).append(" endTime: ") .append(getEndTime()).append(" alloc:[") .append(resourcesOverTime.toString()).append("] "); return sBuf.toString(); }
.values()) { for (InMemoryReservationAllocation reservation : reservationEntries) { if (reservation.getEndTime() <= archivalTime) { expiredReservations.add(reservation);
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InMemoryReservationAllocation other = (InMemoryReservationAllocation) obj; return this.reservationID.equals(other.getReservationId()); }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, boolean isStep, String recurrenceExp) { Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, isStep); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values(), recurrenceExp); Map<ReservationInterval, Resource> allocs = ReservationSystemUtil.toResources(allocations); return new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocs, resCalc, minAlloc); }
@Override public String toString() { StringBuilder sBuf = new StringBuilder(); sBuf.append(getReservationId()).append(" user:").append(getUser()) .append(" startTime: ").append(getStartTime()).append(" endTime: ") .append(getEndTime()).append(" alloc:[") .append(resourcesOverTime.toString()).append("] "); return sBuf.toString(); }
.values()) { for (InMemoryReservationAllocation reservation : reservationEntries) { if (reservation.getEndTime() <= archivalTime) { expiredReservations.add(reservation);
@Test(expected = MismatchedUserException.class) public void testUserMismatch() throws IOException, PlanningException { // generate allocation from single tenant that exceed capacity int[] f = generateData(3600, (int) (0.5 * totCont)); ReservationId rid = ReservationSystemTestUtil.getNewReservationId(); plan.addReservation(new InMemoryReservationAllocation(rid, null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); // trying to update a reservation with a mismatching user plan.updateReservation(new InMemoryReservationAllocation(rid, null, "u2", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); }
if (inMemReservation.getUser() == null) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " is not mapped to any user"; LOG.error(errMsg); if (reservationTable.containsKey(inMemReservation.getReservationId())) { String errMsg = "The specified Reservation with ID " + inMemReservation.getReservationId() + " already exists"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); new ReservationInterval(inMemReservation.getStartTime(), inMemReservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); inMemReservation.getReservationId()); return false; reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Sucessfully added reservation: {} to plan.", inMemReservation.getReservationId()); return true; } finally {
.values()) { for (InMemoryReservationAllocation reservation : reservationEntries) { if (reservation.getEndTime() <= archivalTime) { expiredReservations.add(reservation);