private void incrementAllocation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); Map<ReservationInterval, ReservationRequest> allocationRequests = reservation.getAllocationRequests(); // check if we have encountered the user earlier and if not add an entry String user = reservation.getUser(); RLESparseResourceAllocation resAlloc = userResourceAlloc.get(user); if (resAlloc == null) { resAlloc = new RLESparseResourceAllocation(resCalc, minAlloc); userResourceAlloc.put(user, resAlloc); } for (Map.Entry<ReservationInterval, ReservationRequest> r : allocationRequests .entrySet()) { resAlloc.addInterval(r.getKey(), r.getValue()); rleSparseVector.addInterval(r.getKey(), r.getValue()); } }
private void incrementAllocation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); Map<ReservationInterval, ReservationRequest> allocationRequests = reservation.getAllocationRequests(); // check if we have encountered the user earlier and if not add an entry String user = reservation.getUser(); RLESparseResourceAllocation resAlloc = userResourceAlloc.get(user); if (resAlloc == null) { resAlloc = new RLESparseResourceAllocation(resCalc, minAlloc); userResourceAlloc.put(user, resAlloc); } for (Map.Entry<ReservationInterval, ReservationRequest> r : allocationRequests .entrySet()) { resAlloc.addInterval(r.getKey(), r.getValue()); rleSparseVector.addInterval(r.getKey(), r.getValue()); } }
InMemoryReservationAllocation(ReservationId reservationID, ReservationDefinition contract, String user, String planName, long startTime, long endTime, Map<ReservationInterval, ReservationRequest> allocationRequests, ResourceCalculator calculator, Resource minAlloc) { this.contract = contract; this.startTime = startTime; this.endTime = endTime; this.reservationID = reservationID; this.user = user; this.allocationRequests = allocationRequests; this.planName = planName; resourcesOverTime = new RLESparseResourceAllocation(calculator, minAlloc); for (Map.Entry<ReservationInterval, ReservationRequest> r : allocationRequests .entrySet()) { resourcesOverTime.addInterval(r.getKey(), r.getValue()); if (r.getValue().getConcurrency() > 1) { hasGang = true; } } }
InMemoryReservationAllocation(ReservationId reservationID, ReservationDefinition contract, String user, String planName, long startTime, long endTime, Map<ReservationInterval, ReservationRequest> allocationRequests, ResourceCalculator calculator, Resource minAlloc) { this.contract = contract; this.startTime = startTime; this.endTime = endTime; this.reservationID = reservationID; this.user = user; this.allocationRequests = allocationRequests; this.planName = planName; resourcesOverTime = new RLESparseResourceAllocation(calculator, minAlloc); for (Map.Entry<ReservationInterval, ReservationRequest> r : allocationRequests .entrySet()) { resourcesOverTime.addInterval(r.getKey(), r.getValue()); if (r.getValue().getConcurrency() > 1) { hasGang = true; } } }
public InMemoryReservationAllocation(ReservationId reservationID, ReservationDefinition contract, String user, String planName, long startTime, long endTime, Map<ReservationInterval, Resource> allocations, ResourceCalculator calculator, Resource minAlloc, boolean hasGang) { this.contract = contract; this.startTime = startTime; this.endTime = endTime; this.reservationID = reservationID; this.user = user; this.allocationRequests = allocations; this.planName = planName; this.hasGang = hasGang; if (contract != null && contract.getRecurrenceExpression() != null) { this.periodicity = Long.parseLong(contract.getRecurrenceExpression()); } if (periodicity > 0) { resourcesOverTime = new PeriodicRLESparseResourceAllocation(calculator, periodicity); } else { resourcesOverTime = new RLESparseResourceAllocation(calculator); } for (Map.Entry<ReservationInterval, Resource> r : allocations.entrySet()) { resourcesOverTime.addInterval(r.getKey(), r.getValue()); } }
/** * 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; } }
allocation.addInterval(new ReservationInterval(0L, period), zeroResource); allocation.addInterval(new ReservationInterval(0, jobArrival), zeroResource); allocation.addInterval(new ReservationInterval(jobDeadline, period), zeroResource); } else { allocation.addInterval(new ReservationInterval(jobDeadline, jobArrival), zeroResource); allocation.addInterval( new ReservationInterval(jobArrival, earliestStart), zeroResource); allocation.addInterval(new ReservationInterval(latestEnd, jobDeadline), zeroResource);
private int trackProgress(RLESparseResourceAllocation planModifications, ReservationRequest rr, long stageEarliestStart, long stageDeadline, Map<ReservationInterval, Resource> allocationRequests, long dur, int gangsToPlace, int maxGang) { // if we were able to place any gang, record this, and decrement // gangsToPlace if (maxGang > 0) { gangsToPlace -= maxGang; ReservationInterval reservationInt = computeReservationInterval(stageEarliestStart, stageDeadline, dur); Resource reservationRes = Resources.multiply(rr.getCapability(), rr.getConcurrency() * maxGang); // remember occupied space (plan is read-only till we find a plausible // allocation for the entire request). This is needed since we might be // placing other ReservationRequest within the same // ReservationDefinition, // and we must avoid double-counting the available resources planModifications.addInterval(reservationInt, reservationRes); allocationRequests.put(reservationInt, reservationRes); } return gangsToPlace; }
private RLESparseResourceAllocation generateRLEAlloc(long period) { RLESparseResourceAllocation rle = new RLESparseResourceAllocation(new DefaultResourceCalculator()); Resource alloc = Resources.multiply(minAlloc, height * totCont); // loop in case the periodicity of the reservation is smaller than LCM long rStart = initTime % period; long rEnd = initTime % period + duration; // handle wrap-around if (period > 1 && rEnd > period) { long diff = rEnd - period; rEnd = period; // handle multiple wrap-arounds (e.g., 5h duration on a 2h periodicity) if(duration > period) { rle.addInterval(new ReservationInterval(0, period), Resources.multiply(alloc, duration / period - 1)); rle.addInterval(new ReservationInterval(0, diff % period), alloc); } else { rle.addInterval(new ReservationInterval(0, diff), alloc); } } if(rStart > rEnd){ rle.addInterval(new ReservationInterval(rStart, period), alloc); rle.addInterval(new ReservationInterval(0, rEnd), alloc); } else { rle.addInterval(new ReservationInterval(rStart, rEnd), alloc); } return rle; }
/** * Add multiple resources for the specified interval * * @param reservationInterval the interval for which the resource is to be * added * @param ReservationRequests the resources to be added * @param clusterResource the total resources in the cluster * @return true if addition is successful, false otherwise */ public boolean addCompositeInterval(ReservationInterval reservationInterval, List<ReservationRequest> ReservationRequests, Resource clusterResource) { ReservationRequest aggregateReservationRequest = Records.newRecord(ReservationRequest.class); Resource capacity = Resource.newInstance(0, 0); for (ReservationRequest ReservationRequest : ReservationRequests) { Resources.addTo(capacity, Resources.multiply( ReservationRequest.getCapability(), ReservationRequest.getNumContainers())); } aggregateReservationRequest.setNumContainers((int) Math.ceil(Resources .divide(resourceCalculator, clusterResource, capacity, minAlloc))); aggregateReservationRequest.setCapability(minAlloc); return addInterval(reservationInterval, aggregateReservationRequest); }
/** * Add multiple resources for the specified interval * * @param reservationInterval the interval for which the resource is to be * added * @param ReservationRequests the resources to be added * @param clusterResource the total resources in the cluster * @return true if addition is successful, false otherwise */ public boolean addCompositeInterval(ReservationInterval reservationInterval, List<ReservationRequest> ReservationRequests, Resource clusterResource) { ReservationRequest aggregateReservationRequest = Records.newRecord(ReservationRequest.class); Resource capacity = Resource.newInstance(0, 0); for (ReservationRequest ReservationRequest : ReservationRequests) { Resources.addTo(capacity, Resources.multiply( ReservationRequest.getCapability(), ReservationRequest.getNumContainers())); } aggregateReservationRequest.setNumContainers((int) Math.ceil(Resources .divide(resourceCalculator, clusterResource, capacity, minAlloc))); aggregateReservationRequest.setCapability(minAlloc); return addInterval(reservationInterval, aggregateReservationRequest); }
@Test public void testZeroAllocation() { ResourceCalculator resCalc = new DefaultResourceCalculator(); RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc); rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), Resource.newInstance(0, 0)); LOG.info(rleSparseVector.toString()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); Assert.assertTrue(rleSparseVector.isEmpty()); }
@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); }
@Test public void testZeroAlloaction() { ResourceCalculator resCalc = new DefaultResourceCalculator(); Resource minAlloc = Resource.newInstance(1, 1); RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc, minAlloc); rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), ReservationRequest.newInstance(Resource.newInstance(0, 0), (0))); LOG.info(rleSparseVector.toString()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); Assert.assertTrue(rleSparseVector.isEmpty()); }
generateAllocation(start, alloc, true).entrySet(); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());
generateAllocation(start, alloc, true).entrySet(); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());
generateAllocation(start, alloc, false).entrySet(); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());
generateAllocation(start, alloc, false).entrySet(); for (Entry<ReservationInterval, ReservationRequest> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());
generateAllocation(start, alloc, true).entrySet(); for (Entry<ReservationInterval, ReservationRequest> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());
generateAllocation(start, alloc, true).entrySet(); for (Entry<ReservationInterval, ReservationRequest> ip : inputs) { rleSparseVector.addInterval(ip.getKey(), ip.getValue());