LOG.info("placing the following ReservationRequest: " + contract); Resource totalCapacity = plan.getTotalCapacity(); long step = plan.getStep(); if (earliestStart % step != 0) { earliestStart = earliestStart + (step - (earliestStart % step)); contract.getDeadline() - contract.getDeadline() % plan.getStep(); new HashMap<ReservationInterval, ReservationRequest>(); RLESparseResourceAllocation tempAssigned = new RLESparseResourceAllocation(plan.getResourceCalculator(), plan.getMinimumAllocation()); && oldDeadline > 0) { if (oldDeadline - findLatestTime(curAlloc.keySet()) > plan .getStep()) { throw new PlanningException("The GreedyAgent" + " couldn't find a valid allocation for your request"); plan.getQueueName(), firstStartTime, findLatestTime(allocations.keySet()), allocations, plan.getResourceCalculator(), plan.getMinimumAllocation()); if (oldReservation != null) { return plan.updateReservation(capReservation); } else { return plan.addReservation(capReservation);
ResourceCalculator resCalc = plan.getResourceCalculator(); Resource totCap = plan.getTotalCapacity(); long now = clock.getTime(); for (long t = now; (t < plan.getLastEndTime() && t < (now + lengthOfCheckZone)); t += plan.getStep()) { Resource excessCap = Resources.subtract(plan.getTotalCommittedResources(t), totCap); new TreeSet<ReservationAllocation>(plan.getReservationsAtTime(t)); for (Iterator<ReservationAllocation> resIter = curReservations.iterator(); resIter.hasNext() && Resources.greaterThan(resCalc, totCap, excessCap, ZERO_RESOURCE);) { ReservationAllocation reservation = resIter.next(); plan.deleteReservation(reservation.getReservationId()); excessCap = Resources.subtract(excessCap, reservation.getResourcesAtTime(t)); LOG.info("Removing reservation " + reservation.getReservationId() + " to repair physical-resource constraints in the plan: " + plan.getQueueName());
private void doAssertions(Plan plan, ReservationAllocation rAllocation) { ReservationId reservationID = rAllocation.getReservationId(); Assert.assertNotNull(plan.getReservationById(reservationID)); Assert.assertEquals(rAllocation, plan.getReservationById(reservationID)); Assert.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); Assert.assertEquals(rAllocation.getEndTime(), plan.getLastEndTime()); Assert.assertEquals(totalCapacity, plan.getTotalCapacity()); Assert.assertEquals(minAlloc, plan.getMinimumAllocation()); Assert.assertEquals(maxAlloc, plan.getMaximumAllocation()); Assert.assertEquals(resCalc, plan.getResourceCalculator()); Assert.assertEquals(planName, plan.getQueueName()); Assert.assertTrue(plan.getMoveOnExpiry()); }
Resource planTotalCapacity = plan.getTotalCapacity(); Resource maxInsRes = Resources.multiply(planTotalCapacity, maxInst); NavigableMap<Long, Resource> instQuota = new TreeMap<Long, Resource>(); plan.getResourceCalculator()); plan.getConsumptionForUserOverTime(user, start, end); ReservationAllocation old = plan.getReservationById(oldId); if (old != null) { used = RLESparseResourceAllocation.merge(plan.getResourceCalculator(), Resources.clone(plan.getTotalCapacity()), used, old.getResourcesOverTime(start, end), RLEOperator.subtract, start, end); .merge(plan.getResourceCalculator(), planTotalCapacity, instRLEQuota, used, RLEOperator.subtract, start, end); .merge(plan.getResourceCalculator(), planTotalCapacity, available, instRLEQuota, RLEOperator.min, start, end);
protected void initialize(Plan plan, ReservationId reservationId, ReservationDefinition reservation) throws PlanningException { // Get plan step & capacity capacity = plan.getTotalCapacity(); step = plan.getStep(); // Get job parameters (type, arrival time & deadline) jobType = reservation.getReservationRequests().getInterpreter(); jobArrival = stepRoundUp(reservation.getArrival(), step); jobDeadline = stepRoundDown(reservation.getDeadline(), step); // Initialize the plan modifications planModifications = new RLESparseResourceAllocation(plan.getResourceCalculator()); // Dirty read of plan load // planLoads are not used by other StageAllocators... and don't deal // well with huge reservation ranges planLoads = plan.getCumulativeLoadOverTime(jobArrival, jobDeadline); ReservationAllocation oldRes = plan.getReservationById(reservationId); if (oldRes != null) { planLoads = RLESparseResourceAllocation.merge( plan.getResourceCalculator(), plan.getTotalCapacity(), planLoads, oldRes.getResourcesOverTime(jobArrival, jobDeadline), RLEOperator.subtract, jobArrival, jobDeadline); } }
plan.getReservationById(reservation.getReservationId()); long step = plan.getStep(); Resource currExistingAllocTot = plan.getTotalCommittedResources(t); Resource currNewAlloc = reservation.getResourcesAtTime(t); Resource currOldAlloc = Resource.newInstance(0, 0); if (Resources.greaterThan(plan.getResourceCalculator(), plan .getTotalCapacity(), Resources.subtract( Resources.add(currExistingAllocTot, currNewAlloc), currOldAlloc), plan.getTotalCapacity())) { throw new ResourceOverCommitException("Resources at time " + t + " would be overcommitted by " + "accepting reservation: "
@Override public synchronized void synchronizePlan(Plan plan, boolean shouldReplan) { String planQueueName = plan.getQueueName(); if (LOG.isDebugEnabled()) { LOG.debug("Running plan follower edit policy for plan: " + planQueueName); long step = plan.getStep(); long now = clock.getTime(); if (now % step != 0) { getPlanResources(plan, planQueue, clusterResources); Set<ReservationAllocation> currentReservations = plan.getReservationsAtTime(now); Set<String> curReservationNames = new HashSet<String>(); Resource reservedResources = Resource.newInstance(0, 0); if (arePlanResourcesLessThanReservations(plan.getResourceCalculator(), clusterResources, planResources, reservedResources)) { if (shouldReplan) { try { plan.getReplanner().plan(plan, null); } catch (PlanningException e) { LOG.warn("Exception while trying to replan: {}", planQueueName, e); cleanupExpiredQueues(planQueueName, plan.getMoveOnExpiry(), expired, defReservationQueue); if (shouldResize) { capToAssign = calculateReservationToPlanProportion( plan.getResourceCalculator(), planResources, reservedResources,
new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocations, resCalc, minAlloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); Assert.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), plan.getTotalCommittedResources(start + i)); Assert.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), plan.getConsumptionForUser(user, start + i)); plan.deleteReservation(reservationID); } catch (PlanningException e) { Assert.fail(e.getMessage()); Assert.assertNull(plan.getReservationById(reservationID)); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(0, 0), plan.getTotalCommittedResources(start + i)); Assert.assertEquals(Resource.newInstance(0, 0), plan.getConsumptionForUser(user, start + i));
public static void validateReservationQueue( AbstractReservationSystem reservationSystem, String planQName) { Plan plan = reservationSystem.getPlan(planQName); Assert.assertNotNull(plan); Assert.assertTrue(plan instanceof InMemoryPlan); Assert.assertEquals(planQName, plan.getQueueName()); Assert.assertEquals(8192, plan.getTotalCapacity().getMemorySize()); Assert.assertTrue( plan.getReservationAgent() instanceof AlignedPlannerWithGreedy); Assert .assertTrue(plan.getSharingPolicy() instanceof CapacityOverTimePolicy); }
ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc, true); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); plan.getConsumptionForUserOverTime(user, start, start + alloc.length); plan.getTotalCommittedResources(start + i)); assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), plan.deleteReservation(reservationID); } catch (PlanningException e) { Assert.fail(e.getMessage()); Assert.assertNull(plan.getReservationById(reservationID)); userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc.length); for (int i = 0; i < alloc.length; i++) { assertEquals(Resource.newInstance(0, 0), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(0, 0), userCons.getCapacityAtTime(start + i));
ReservationAllocation rAllocation = createReservationAllocation(reservationID1, start, alloc1); Assert.assertNull(plan.getReservationById(reservationID1)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); rAllocation = createReservationAllocation(reservationID2, start, alloc2, true); Assert.assertNull(plan.getReservationById(reservationID2)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); Assert.assertNotNull(plan.getReservationById(reservationID2)); plan.getConsumptionForUserOverTime(user, start, start + alloc2.length); Resource.newInstance(1024 * (alloc1[i] + alloc2[i] + i), alloc1[i] + alloc2[i] + i), plan.getTotalCommittedResources(start + i)); assertEquals( Resource.newInstance(1024 * (alloc1[i] + alloc2[i] + i), plan.archiveCompletedReservations(clock.getTime()); } catch (PlanningException e) { Assert.fail(e.getMessage());
ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); plan.getConsumptionForUserOverTime(user, start, start + alloc.length); for (int i = 0; i < alloc.length; i++) { assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), userCons.getCapacityAtTime(start + i)); createReservationAllocation(reservationID, start, updatedAlloc, true); try { plan.updateReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); userCons = plan.getConsumptionForUserOverTime(user, start, start + updatedAlloc.length); updatedAlloc[i] + i), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(1024 * (updatedAlloc[i] + i), updatedAlloc[i] + i), userCons.getCapacityAtTime(start + i));
@Test public void testGetReservationsByInvalidId() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } // If reservationId is null, then nothing is returned. ReservationId invalidReservationID = ReservationSystemTestUtil.getNewReservationId(); Set<ReservationAllocation> rAllocations = plan.getReservations(invalidReservationID, null, ""); Assert.assertTrue(rAllocations.size() == 0); }
private ReservationId submitReservation(Plan plan, long reservationStartTime, long reservationEndTime, long period) { ReservationId reservation = ReservationSystemTestUtil.getNewReservationId(); ReservationAllocation rAllocation = createReservationAllocation( reservation, reservationStartTime, reservationEndTime, String.valueOf(period)); rAllocation.setPeriodicity(period); Assert.assertNull(plan.getReservationById(reservation)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } return reservation; }
private void validateInput(Plan plan, ReservationRequest rr, Resource totalCapacity) throws ContractValidationException { if (rr.getConcurrency() < 1) { throw new ContractValidationException("Gang Size should be >= 1"); } if (rr.getNumContainers() <= 0) { throw new ContractValidationException("Num containers should be >= 0"); } // check that gangSize and numContainers are compatible if (rr.getNumContainers() % rr.getConcurrency() != 0) { throw new ContractValidationException( "Parallelism must be an exact multiple of gang size"); } // check that the largest container request does not exceed // the cluster-wide limit for container sizes if (Resources.greaterThan(plan.getResourceCalculator(), totalCapacity, rr.getCapability(), plan.getMaximumAllocation())) { throw new ContractValidationException("Individual" + " capability requests should not exceed cluster's maxAlloc"); } }
.setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); plan.deleteReservation(reservationID); } catch (PlanningException e) { Assert.fail(e.getMessage()); Assert.assertNull(plan.getReservationById(reservationID)); System.out.print(plan); checkAllocation(plan, new int[] { 0, 0 }, start, period);
.setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); rAllocation.setPeriodicity(period); try { plan.updateReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage());
@Test public void testGetReservationsAtTime() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Set<ReservationAllocation> rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime()); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
@Override public boolean updateReservation(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract) throws PlanningException { // Get the old allocation ReservationAllocation oldAlloc = plan.getReservationById(reservationId); // Allocate (ignores the old allocation) return allocateUser(reservationId, user, plan, contract, oldAlloc); }
@Test public void testDeleteNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to delete a reservation without adding Assert.assertNull(plan.getReservationById(reservationID)); try { plan.deleteReservation(reservationID); Assert.fail("Delete should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }