private ReservationInterval computeReservationInterval( long stageEarliestStart, long stageDeadline, long dur) { ReservationInterval reservationInt; if (allocateLeft) { reservationInt = new ReservationInterval(stageEarliestStart, stageEarliestStart + dur); } else { reservationInt = new ReservationInterval(stageDeadline - dur, stageDeadline); } return reservationInt; }
@Override public int compareTo(ReservationInterval anotherInterval) { long diff = 0; if (startTime == anotherInterval.getStartTime()) { diff = endTime - anotherInterval.getEndTime(); } else { diff = startTime - anotherInterval.getStartTime(); } if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return 0; } }
/** * Add resource for the specified interval. This function will be used by * {@link InMemoryPlan} while placing reservations between 0 and timePeriod. * The interval may include 0, but the end time must be strictly less than * timePeriod. * * @param interval {@link ReservationInterval} to which the specified resource * is to be added. * @param resource {@link Resource} to be added to the interval specified. * @return true if addition is successful, false otherwise */ public boolean addInterval(ReservationInterval interval, Resource resource) { long startTime = interval.getStartTime(); long endTime = interval.getEndTime(); if (startTime >= 0 && endTime > startTime && endTime <= timePeriod) { return super.addInterval(interval, resource); } else { LOG.info("Cannot set capacity beyond end time: " + timePeriod + " was (" + interval.toString() + ")"); return false; } }
/** * Removes a resource for the specified interval. * * @param interval the {@link ReservationInterval} for which the resource is * to be removed. * @param resource the {@link Resource} to be removed. * @return true if removal is successful, false otherwise */ public boolean removeInterval(ReservationInterval interval, Resource resource) { long startTime = interval.getStartTime(); long endTime = interval.getEndTime(); // If the resource to be subtracted is less than the minimum resource in // the range, abort removal to avoid negative capacity. // TODO revesit decrementing endTime if (!Resources.fitsIn(resource, getMinimumCapacityInInterval( new ReservationInterval(startTime, endTime - 1)))) { LOG.info("Request to remove more resources than what is available"); return false; } if (startTime >= 0 && endTime > startTime && endTime <= timePeriod) { return super.removeInterval(interval, resource); } else { LOG.info("Interval extends beyond the end time " + timePeriod); return false; } }
private long findLatestTime(Set<ReservationInterval> resInt) { long ret = Long.MIN_VALUE; for (ReservationInterval s : resInt) { if (s.getEndTime() > ret) { ret = s.getEndTime(); } } return ret; }
private long findEarliestTime(Set<ReservationInterval> resInt) { long ret = Long.MAX_VALUE; for (ReservationInterval s : resInt) { if (s.getStartTime() < ret) { ret = s.getStartTime(); } } return ret; }
long startTime = interval == null ? 0 : interval.getStartTime(); long endTime = interval == null ? Long.MAX_VALUE : interval.getEndTime(); new ReservationInterval(endTime, Long.MAX_VALUE); readLock.lock(); try {
private long findLatestTime(Set<ReservationInterval> resInt) { long ret = Long.MIN_VALUE; for (ReservationInterval s : resInt) { if (s.getEndTime() > ret) { ret = s.getEndTime(); } } return ret; }
private long findEarliestTime(Set<ReservationInterval> resInt) { long ret = Long.MAX_VALUE; for (ReservationInterval s : resInt) { if (s.getStartTime() < ret) { ret = s.getStartTime(); } } return ret; }
@Override public Set<ReservationAllocation> getReservationsAtTime(long tick) { return getReservations(null, new ReservationInterval(tick, tick), ""); }
@Override public int compareTo(ReservationInterval anotherInterval) { long diff = 0; if (startTime == anotherInterval.getStartTime()) { diff = endTime - anotherInterval.getEndTime(); } else { diff = startTime - anotherInterval.getStartTime(); } if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return 0; } }
for (int i = 0; i < periodicRle.getTimePeriod() / period; i++) { long rStart = r.getKey().getStartTime() + i * period; long rEnd = r.getKey().getEndTime() + i * period; long diff = rEnd - periodicRle.getTimePeriod(); rEnd = periodicRle.getTimePeriod(); ReservationInterval newInterval = new ReservationInterval(0, diff); periodicRle.removeInterval(newInterval, r.getValue()); resAlloc.removeInterval(newInterval, r.getValue()); new ReservationInterval(rStart, rEnd); periodicRle.removeInterval(newInterval, r.getValue()); resAlloc.removeInterval(newInterval, r.getValue()); if (Resources.greaterThan(resCalc, totalCapacity, r.getValue(), ZERO_RESOURCE)) { earliestActive = Math.min(earliestActive, r.getKey().getStartTime()); latestActive = Math.max(latestActive, r.getKey().getEndTime()); new ReservationInterval(earliestActive, latestActive), Resource.newInstance(1, 1)); if (resCount.isEmpty()) {
protected static long findLatestTime(Map<ReservationInterval, Resource> sesInt) { long ret = Long.MIN_VALUE; for (Entry<ReservationInterval, Resource> s : sesInt.entrySet()) { if (s.getKey().getEndTime() > ret && s.getValue() != null) { ret = s.getKey().getEndTime(); } } return ret; }
protected static long findEarliestTime( Map<ReservationInterval, Resource> sesInt) { long ret = Long.MAX_VALUE; for (Entry<ReservationInterval, Resource> s : sesInt.entrySet()) { if (s.getKey().getStartTime() < ret && s.getValue() != null) { ret = s.getKey().getStartTime(); } } return ret; }
new ReservationInterval(lastEntry.getKey(), entry.getKey()); Resource resource = lastEntry.getValue();
@Override public int compareTo(ReservationInterval anotherInterval) { long diff = 0; if (startTime == anotherInterval.getStartTime()) { diff = endTime - anotherInterval.getEndTime(); } else { diff = startTime - anotherInterval.getStartTime(); } if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return 0; } }
for (int i = 0; i < periodicRle.getTimePeriod() / period; i++) { long rStart = r.getKey().getStartTime() + i * period; long rEnd = r.getKey().getEndTime() + i * period; long diff = rEnd - periodicRle.getTimePeriod(); rEnd = periodicRle.getTimePeriod(); ReservationInterval newInterval = new ReservationInterval(0, diff); periodicRle.addInterval(newInterval, r.getValue()); resAlloc.addInterval(newInterval, r.getValue()); new ReservationInterval(rStart, rEnd); periodicRle.addInterval(newInterval, r.getValue()); resAlloc.addInterval(newInterval, r.getValue()); if (Resources.greaterThan(resCalc, totalCapacity, r.getValue(), ZERO_RESOURCE)) { earliestActive = Math.min(earliestActive, r.getKey().getStartTime()); latestActive = Math.max(latestActive, r.getKey().getEndTime()); latestActive = Long.MAX_VALUE; resCount.addInterval(new ReservationInterval(earliestActive, latestActive), Resource.newInstance(1, 1));
@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(); } }
public ResourceAllocationInfo(ReservationInterval interval, Resource res) { this.resource = new ResourceInfo(res); this.startTime = interval.getStartTime(); this.endTime = interval.getEndTime(); }
long maxIntervalArrival = maxInterval.getStartTime(); long maxIntervalDeadline = maxInterval.getEndTime(); long window = maxIntervalDeadline - maxIntervalArrival; long windowRemainder = window - totalDuration; return new ReservationInterval(maxIntervalArrival, latestEnd); } else { long earlyStart = return new ReservationInterval(earlyStart, maxIntervalDeadline);