@Override public RLESparseResourceAllocation getResourcesOverTime(long start, long end) { return resourcesOverTime.getRangeOverlapping(start, end); }
@Override public RLESparseResourceAllocation getReservationCountForUserOverTime( String user, long start, long end) { readLock.lock(); try { RLESparseResourceAllocation userResAlloc = userActiveReservationCount.get(user); if (userResAlloc != null) { return userResAlloc.getRangeOverlapping(start, end); } else { return new RLESparseResourceAllocation(resCalc); } } finally { readLock.unlock(); } }
@Override public RLESparseResourceAllocation getCumulativeLoadOverTime(long start, long end) throws PlanningException { readLock.lock(); try { RLESparseResourceAllocation ret = rleSparseVector.getRangeOverlapping(start, end); ret = RLESparseResourceAllocation.merge(resCalc, totalCapacity, ret, periodicRle.getRangeOverlapping(start, end), RLEOperator.add, start, end); return ret; } finally { readLock.unlock(); } } }
@Override public RLESparseResourceAllocation getConsumptionForUserOverTime(String user, long start, long end) { readLock.lock(); try { // merge periodic and non-periodic allocations RLESparseResourceAllocation userResAlloc = userResourceAlloc.get(user); RLESparseResourceAllocation userPeriodicResAlloc = userPeriodicResourceAlloc.get(user); if (userResAlloc != null && userPeriodicResAlloc != null) { return RLESparseResourceAllocation.merge(resCalc, totalCapacity, userResAlloc, userPeriodicResAlloc, RLEOperator.add, start, end); } if (userResAlloc != null) { return userResAlloc.getRangeOverlapping(start, end); } if (userPeriodicResAlloc != null) { return userPeriodicResAlloc.getRangeOverlapping(start, end); } } catch (PlanningException e) { LOG.warn("Exception while trying to merge periodic" + " and non-periodic user allocations: {}", e.getMessage(), e); } finally { readLock.unlock(); } return new RLESparseResourceAllocation(resCalc); }
/** * Merges the range start to end of two {@code RLESparseResourceAllocation} * using a given {@code RLEOperator}. * * @param resCalc the resource calculator * @param clusterResource the total cluster resources (for DRF) * @param a the left operand * @param b the right operand * @param operator the operator to be applied during merge * @param start the start-time of the range to be considered * @param end the end-time of the range to be considered * @return the a merged RLESparseResourceAllocation, produced by applying * "operator" to "a" and "b" * @throws PlanningException in case the operator is subtractTestPositive and * the result would contain a negative value */ public static RLESparseResourceAllocation merge(ResourceCalculator resCalc, Resource clusterResource, RLESparseResourceAllocation a, RLESparseResourceAllocation b, RLEOperator operator, long start, long end) throws PlanningException { NavigableMap<Long, Resource> cumA = a.getRangeOverlapping(start, end).getCumulative(); NavigableMap<Long, Resource> cumB = b.getRangeOverlapping(start, end).getCumulative(); NavigableMap<Long, Resource> out = merge(resCalc, clusterResource, cumA, cumB, start, end, operator); return new RLESparseResourceAllocation(out, resCalc); }
/** * 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; }
@Test public void testRangeOverlapping() { ResourceCalculator resCalc = new DefaultResourceCalculator(); RLESparseResourceAllocation r = new RLESparseResourceAllocation(resCalc); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; Set<Entry<ReservationInterval, Resource>> inputs = generateAllocation(start, alloc, false).entrySet(); for (Entry<ReservationInterval, Resource> ip : inputs) { r.addInterval(ip.getKey(), ip.getValue()); } long s = r.getEarliestStartTime(); long d = r.getLatestNonNullTime(); // tries to trigger "out-of-range" bug r = r.getRangeOverlapping(s, d); r = r.getRangeOverlapping(s - 1, d - 1); r = r.getRangeOverlapping(s + 1, d + 1); }
netRLERes.getRangeOverlapping(stageEarliestStart, stageDeadline) .getCumulative();