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 Set<ReservationAllocation> getReservationsAtTime(long tick) { return getReservations(null, new ReservationInterval(tick, tick), ""); }
public static Map<ReservationInterval, Resource> toAllocations( List<ResourceAllocationRequestProto> allocationRequestsList) { Map<ReservationInterval, Resource> allocations = new HashMap<>(); for (ResourceAllocationRequestProto proto : allocationRequestsList) { allocations.put( new ReservationInterval(proto.getStartTime(), proto.getEndTime()), convertFromProtoFormat(proto.getResource())); } return allocations; }
private Map<ReservationInterval, ReservationRequest> generateAllocation( int startTime, int[] alloc) { Map<ReservationInterval, ReservationRequest> req = new TreeMap<ReservationInterval, ReservationRequest>(); for (int i = 0; i < alloc.length; i++) { req.put(new ReservationInterval(startTime + i, startTime + i + 1), ReservationRequest.newInstance(Resource.newInstance(1024, 1), alloc[i])); } return req; }
public static Map<ReservationInterval, ReservationRequest> generateAllocation( long startTime, long step, int[] alloc) { Map<ReservationInterval, ReservationRequest> req = new TreeMap<ReservationInterval, ReservationRequest>(); for (int i = 0; i < alloc.length; i++) { req.put(new ReservationInterval(startTime + i * step, startTime + (i + 1) * step), ReservationRequest.newInstance( Resource.newInstance(1024, 1), alloc[i])); } return req; }
public static Map<ReservationInterval, Resource> toAllocation( RLESparseResourceAllocation rle, long start, long end) { Map<ReservationInterval, Resource> resAlloc = new TreeMap<>(); for (Map.Entry<Long, Resource> e : rle.getCumulative().entrySet()) { Long nextKey = rle.getCumulative().higherKey(e.getKey()); if (nextKey == null) { break; } else { if (e.getKey() >= start && e.getKey() <= end && nextKey >= start && nextKey <= end) { resAlloc.put(new ReservationInterval(e.getKey(), nextKey), e.getValue()); } } } return resAlloc; }
private Map<ReservationInterval, ReservationRequest> generateAllocation( int startTime, int[] alloc, boolean isStep) { Map<ReservationInterval, ReservationRequest> req = new HashMap<ReservationInterval, ReservationRequest>(); int numContainers = 0; for (int i = 0; i < alloc.length; i++) { if (isStep) { numContainers = alloc[i] + i; } else { numContainers = alloc[i]; } ReservationRequest rr = ReservationRequest .newInstance(Resource.newInstance(1024, 1), (numContainers)); req.put(new ReservationInterval(startTime + i, startTime + i + 1), rr); } return req; }
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); }
private Map<ReservationInterval, ReservationRequest> generateAllocation( int startTime, int[] alloc, boolean isStep) { Map<ReservationInterval, ReservationRequest> req = new HashMap<ReservationInterval, ReservationRequest>(); int numContainers = 0; for (int i = 0; i < alloc.length; i++) { if (isStep) { numContainers = alloc[i] + i; } else { numContainers = alloc[i]; } req.put(new ReservationInterval(startTime + i, startTime + i + 1), ReservationRequest.newInstance(Resource.newInstance(1024, 1), (numContainers))); } return req; }
private Map<ReservationInterval, Resource> generateAllocation( int startTime, int[] alloc) { Map<ReservationInterval, Resource> req = new TreeMap<ReservationInterval, Resource>(); for (int i = 0; i < alloc.length; i++) { req.put(new ReservationInterval(startTime + i, startTime + i + 1), ReservationSystemUtil.toResource( ReservationRequest.newInstance(Resource.newInstance(1024, 1), alloc[i]))); } return req; }
private Map<ReservationInterval, ReservationRequest> generateAllocation( int startTime, int[] alloc, boolean isStep) { Map<ReservationInterval, ReservationRequest> req = new HashMap<ReservationInterval, ReservationRequest>(); int numContainers = 0; for (int i = 0; i < alloc.length; i++) { if (isStep) { numContainers = alloc[i] + i; } else { numContainers = alloc[i]; } ReservationRequest rr = ReservationRequest.newInstance(Resource.newInstance(1024, 1), (numContainers)); req.put(new ReservationInterval(startTime + i, startTime + i + 1), rr); } return req; }
public ReservationInfo(ReservationAllocationState allocation, boolean includeResourceAllocations) throws Exception { acceptanceTime = allocation.getAcceptanceTime(); user = allocation.getUser(); if (includeResourceAllocations) { List<ResourceAllocationRequest> requests = allocation .getResourceAllocationRequests(); for (ResourceAllocationRequest request : requests) { resourceAllocations.add(new ResourceAllocationInfo(new ReservationInterval(request.getStartTime(), request .getEndTime()), request.getCapability())); } } reservationId = allocation.getReservationId().toString(); reservationDefinition = new ReservationDefinitionInfo( allocation.getReservationDefinition()); }
private Map<ReservationInterval, Resource> generateAllocation(int startTime, int[] alloc, boolean isStep) { Map<ReservationInterval, Resource> req = new HashMap<ReservationInterval, Resource>(); int numContainers = 0; for (int i = 0; i < alloc.length; i++) { if (isStep) { numContainers = alloc[i] + i; } else { numContainers = alloc[i]; } req.put(new ReservationInterval(startTime + i, startTime + i + 1), ReservationSystemUtil.toResource(ReservationRequest .newInstance(Resource.newInstance(1024, 1), (numContainers)))); } return req; }
@Test public void testGetReservationsWithNoReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); // Verify that get reservation returns no entries if no queries are made. ReservationInterval interval = new ReservationInterval(0, Long.MAX_VALUE); Set<ReservationAllocation> rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0); }
@Test public void testGetMinimumCapacityInInterval() { long[] timeSteps = { 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L }; int[] alloc = { 2, 5, 7, 10, 3, 4, 0, 8 }; RLESparseResourceAllocation rleSparseVector = ReservationSystemTestUtil .generateRLESparseResourceAllocation(alloc, timeSteps); LOG.info(rleSparseVector.toString()); Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 3L)), Resource.newInstance(5, 5)); Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(2L, 5L)), Resource.newInstance(3, 3)); Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 7L)), Resource.newInstance(0, 0)); }
@Test(expected = PlanningQuotaException.class) public void testFailAvg() throws IOException, PlanningException { // generate an allocation which violates the 25% average single-shot Map<ReservationInterval, ReservationRequest> req = new TreeMap<ReservationInterval, ReservationRequest>(); long win = timeWindow / 2 + 100; int cont = (int) Math.ceil(0.5 * totCont); req.put(new ReservationInterval(initTime, initTime + win), ReservationRequest.newInstance(Resource.newInstance(1024, 1), cont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + win, req, res, minAlloc))); }
private void testPositiveGetRecurringReservationsHelper(long reservationStart, long reservationEnd, long searchStart, long searchEnd, long cycles, long period, int periodMultiplier) { maxPeriodicity = period * periodMultiplier; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); ReservationId reservationID = submitReservation(plan, reservationStart, reservationEnd, period); for (int i = 0; i < cycles; i++) { long searchStepIncrease = i * period; Set<ReservationAllocation> alloc = plan.getReservations(null, new ReservationInterval(searchStart + searchStepIncrease, searchEnd + searchStepIncrease)); assertEquals(1, alloc.size()); assertEquals(reservationID, alloc.iterator().next().getReservationId()); } }
private void testNegativeGetRecurringReservationsHelper(long reservationStart, long reservationEnd, long searchStart, long searchEnd, long cycles, long period, int periodMultiplier) { maxPeriodicity = period * periodMultiplier; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); submitReservation(plan, reservationStart, reservationEnd, period); for (int i = 0; i < cycles; i++) { long searchStepIncrease = i * period; Set<ReservationAllocation> alloc = plan.getReservations(null, new ReservationInterval(searchStart + searchStepIncrease, searchEnd + searchStepIncrease)); assertEquals(0, alloc.size()); } }
@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 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()); }