private long findEarliestTime(Set<ReservationInterval> resInt) { long ret = Long.MAX_VALUE; for (ReservationInterval s : resInt) { if (s.getStartTime() < ret) { ret = s.getStartTime(); } } 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; }
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; }
@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; } }
@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; } }
@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; } }
public ResourceAllocationInfo(ReservationInterval interval, Resource res) { this.resource = new ResourceInfo(res); this.startTime = interval.getStartTime(); this.endTime = interval.getEndTime(); }
Long left = interval.getStartTime(); Long right = interval.getEndTime();
/** * Add a resource for the specified interval. * * @param reservationInterval the interval for which the resource is to be * added * @param totCap the resource to be added * @return true if addition is successful, false otherwise */ public boolean addInterval(ReservationInterval reservationInterval, Resource totCap) { if (totCap.equals(ZERO_RESOURCE)) { return true; } writeLock.lock(); try { NavigableMap<Long, Resource> addInt = new TreeMap<Long, Resource>(); addInt.put(reservationInterval.getStartTime(), totCap); addInt.put(reservationInterval.getEndTime(), ZERO_RESOURCE); try { cumulativeCapacity = merge(resourceCalculator, totCap, cumulativeCapacity, addInt, Long.MIN_VALUE, Long.MAX_VALUE, RLEOperator.add); } catch (PlanningException e) { // never happens for add } return true; } finally { writeLock.unlock(); } }
/** * Removes a resource for the specified interval. * * @param reservationInterval the interval for which the resource is to be * removed * @param totCap the resource to be removed * @return true if removal is successful, false otherwise */ public boolean removeInterval(ReservationInterval reservationInterval, Resource totCap) { if (totCap.equals(ZERO_RESOURCE)) { return true; } writeLock.lock(); try { NavigableMap<Long, Resource> removeInt = new TreeMap<Long, Resource>(); removeInt.put(reservationInterval.getStartTime(), totCap); removeInt.put(reservationInterval.getEndTime(), ZERO_RESOURCE); try { cumulativeCapacity = merge(resourceCalculator, totCap, cumulativeCapacity, removeInt, Long.MIN_VALUE, Long.MAX_VALUE, RLEOperator.subtract); } catch (PlanningException e) { // never happens for subtract } return true; } finally { writeLock.unlock(); } }
/** * 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; } }
/** * Get the minimum capacity in the specified time range. * * @param interval the {@link ReservationInterval} to be searched * @return minimum resource allocation */ public Resource getMinimumCapacityInInterval(ReservationInterval interval) { Resource minCapacity = Resource.newInstance(Integer.MAX_VALUE, Integer.MAX_VALUE); long start = interval.getStartTime(); long end = interval.getEndTime(); NavigableMap<Long, Resource> capacityRange = getRangeOverlapping(start, end).getCumulative(); if (!capacityRange.isEmpty()) { for (Map.Entry<Long, Resource> entry : capacityRange.entrySet()) { if (entry.getValue() != null) { minCapacity = Resources.componentwiseMin(minCapacity, entry.getValue()); } } } return minCapacity; }
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; } }
/** * 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; } }
long startKey = reservationInterval.getStartTime(); long endKey = reservationInterval.getEndTime();
for (int i = 0; i < periodicRle.getTimePeriod() / period; i++) { long rStart = r.getKey().getStartTime() + i * period; long rEnd = r.getKey().getEndTime() + i * period; if (Resources.greaterThan(resCalc, totalCapacity, r.getValue(), ZERO_RESOURCE)) { earliestActive = Math.min(earliestActive, r.getKey().getStartTime()); latestActive = Math.max(latestActive, r.getKey().getEndTime());
for (int i = 0; i < periodicRle.getTimePeriod() / period; i++) { long rStart = r.getKey().getStartTime() + i * period; long rEnd = r.getKey().getEndTime() + i * period; if (Resources.greaterThan(resCalc, totalCapacity, r.getValue(), ZERO_RESOURCE)) { earliestActive = Math.min(earliestActive, r.getKey().getStartTime()); latestActive = Math.max(latestActive, r.getKey().getEndTime());
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; }
setStageExecutionInterval(plan, reservation, currentReservationStage, allocations); Long stageArrival = stageInterval.getStartTime(); Long stageDeadline = stageInterval.getEndTime();
ReservationInterval interval = entry.getKey(); Resource resource = entry.getValue(); if (interval.getStartTime() == 101L) { Assert.assertTrue(interval.getEndTime() == 102L); Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 102L) { Assert.assertTrue(interval.getEndTime() == 104L); Assert.assertEquals(resource, Resource.newInstance(10 * 1024, 10)); } else if (interval.getStartTime() == 104L) { Assert.assertTrue(interval.getEndTime() == 105L); Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 105L) { Assert.assertTrue(interval.getEndTime() == 106L); Assert.assertEquals(resource, Resource.newInstance(0 * 1024, 0)); } else if (interval.getStartTime() == 106L) { Assert.assertTrue(interval.getEndTime() == 107L); Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5));