private void addFixedAllocation(long start, long step, int[] f) throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( start, start + f.length * step, f.length * step); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "user_fixed", "dedicated", start, start + f.length * step, ReservationSystemTestUtil.generateAllocation(start, step, f), res, minAlloc), false)); }
@Override public String toString() { readLock.lock(); try { StringBuffer planStr = new StringBuffer("In-memory Plan: "); planStr.append("Parent Queue: ").append(queueName) .append("Total Capacity: ").append(totalCapacity).append("Step: ") .append(step); for (ReservationAllocation reservation : getAllReservations()) { planStr.append(reservation); } return planStr.toString(); } finally { readLock.unlock(); } }
try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); result = addReservation(reservation); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", } else { addReservation(currReservation); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId());
@Override public boolean deleteReservation(ReservationId reservationID) { writeLock.lock(); try { ReservationAllocation reservation = getReservationById(reservationID); if (reservation == null) { String errMsg = "The specified Reservation with ID " + reservationID + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } return removeReservation(reservation); } finally { writeLock.unlock(); } }
if (reservations != null) { if (rmStateStore != null) { rmStateStore.removeReservation(getQueueName(), reservation.getReservationId().toString()); decrementAllocation(reservation); LOG.info("Sucessfully deleted reservation: {} in plan.", reservation.getReservationId());
@Test public void testSingleSliding() throws PlanningException { prepareBasicPlan(); // create a single request for which we need subsequent (tight) packing. ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(100 * step); rr.setDeadline(120 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 200, 10, 10 * step); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); reqs.setReservationResources(list); rr.setReservationRequests(reqs); // submit to agent ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); // validate results, we expect the second one to be accepted assertTrue("Agent-based allocation failed", reservationID != null); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 3); ReservationAllocation cs = plan.getReservationById(reservationID); assertTrue(cs.toString(), check(cs, 100 * step, 120 * step, 100, 1024, 1)); System.out.println("--------AFTER packed ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
new InMemoryPlan(queueMetrics, policy, agent, clusterCapacity, step, res, minAlloc, maxAlloc, "dedicated", enf, true, clock); ReservationId r1 = ReservationId.newInstance(ts, 1); int[] f5 = { 20, 20, 20, 20, 20 }; assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r1, null, "u3", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc))); when(clock.getTime()).thenReturn(1L); ReservationId r2 = ReservationId.newInstance(ts, 2); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r2, null, "u4", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc))); when(clock.getTime()).thenReturn(2L); ReservationId r3 = ReservationId.newInstance(ts, 3); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r3, null, "u5", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc))); when(clock.getTime()).thenReturn(3L); ReservationId r4 = ReservationId.newInstance(ts, 4); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r4, null, "u6", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc))); when(clock.getTime()).thenReturn(4L); ReservationId r5 = ReservationId.newInstance(ts, 5);
@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); }
assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == numJobsInScenario + 1); ReservationAllocation alloc1 = plan.getReservationById(reservationID);
ReservationSystemTestUtil.createConf(plan.getQueueName(), 100000, instConstraint, avgConstraint); plan.getSharingPolicy().init(plan.getQueueName(), conf); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 4); ReservationAllocation cs = plan.getReservationById(reservationID); ReservationAllocation cs2 = plan.getReservationById(reservationID2); ReservationAllocation cs3 = plan.getReservationById(reservationID3); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString());
assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == numJobsInScenario + 1); ReservationAllocation alloc1 = plan.getReservationById(reservationID); System.out.println(plan.toString());
private void prepareBasicPlan() throws PlanningException { // insert in the reservation a couple of controlled reservations, to create // conditions for assignment that are non-empty int[] f = { 10, 10, 20, 20, 20, 10, 10 }; assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil .generateAllocation(0, step, f), res, minAlloc))); int[] f2 = { 5, 5, 5, 5, 5, 5, 5 }; Map<ReservationInterval, ReservationRequest> alloc = ReservationSystemTestUtil.generateAllocation(5000, step, f2); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc))); System.out.println("--------BEFORE AGENT----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 2); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString());
ReservationInterval interval, String user) { if (reservationID != null) { ReservationAllocation allocation = getReservationById(reservationID); if (allocation == null) { return Collections.emptySet();
@Test(expected = MismatchedUserException.class) public void testUserMismatch() throws IOException, PlanningException { // generate allocation from single tenant that exceed capacity int[] f = generateData(3600, (int) (0.5 * totCont)); ReservationId rid = ReservationSystemTestUtil.getNewReservationId(); plan.addReservation(new InMemoryReservationAllocation(rid, null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); // trying to update a reservation with a mismatching user plan.updateReservation(new InMemoryReservationAllocation(rid, null, "u2", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); }
rmStateStore.storeNewReservation( ReservationSystemUtil.buildStateProto(inMemReservation), getQueueName(), inMemReservation.getReservationId().toString()); reservationTable.put(inMemReservation.getReservationId(), inMemReservation); incrementAllocation(inMemReservation); LOG.info("Successfully added reservation: {} to plan.", inMemReservation.getReservationId());
@Test(expected = ResourceOverCommitException.class) public void testSingleFail() throws IOException, PlanningException { // generate allocation from single tenant that exceed capacity int[] f = generateData(3600, (int) (1.1 * totCont)); plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); }
try { for (InMemoryReservationAllocation expiredReservation : expiredReservations) { removeReservation(expiredReservation);
netAvailable = getSharingPolicy().availableResources(netAvailable, this, user, oldId, start, end); return netAvailable; getAvailableResourceOverTime(user, oldId, start, end, 0); for (int i = 1; i < numInstInLCM; i++) { getAvailableResourceOverTime(user, oldId, rStart, rEnd, 0); RLESparseResourceAllocation.merge(resCalc, getTotalCapacity(), minOverLCM, snapShot, RLEOperator.min, start, end);
private boolean removeReservation(ReservationAllocation reservation) { assert (readWriteLock.isWriteLockedByCurrentThread()); ReservationInterval searchInterval = new ReservationInterval(reservation.getStartTime(), reservation.getEndTime()); Set<InMemoryReservationAllocation> reservations = currentReservations.get(searchInterval); if (reservations != null) { if (!reservations.remove(reservation)) { LOG.error("Unable to remove reservation: {} from plan.", reservation.getReservationId()); return false; } if (reservations.isEmpty()) { currentReservations.remove(searchInterval); } } else { String errMsg = "The specified Reservation with ID " + reservation.getReservationId() + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } reservationTable.remove(reservation.getReservationId()); decrementAllocation(reservation); LOG.info("Sucessfully deleted reservation: {} in plan.", reservation.getReservationId()); return true; }