GreedyReservationAgent implements ReservationAgent { @Override public boolean createReservation(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract) throws PlanningException { LOG.info("placing the following ReservationRequest: " + contract); try { boolean res = planner.createReservation(reservationId, user, plan, contract); if (res) { LOG.info("OUTCOME: SUCCESS, Reservation ID: " + reservationId.toString() + ", Contract: " + contract.toString()); } else { LOG.info("OUTCOME: FAILURE, Reservation ID: " + reservationId.toString() + ", Contract: " + contract.toString()); } return res; } catch (PlanningException e) { LOG.info("OUTCOME: FAILURE, Reservation ID: " + reservationId.toString() + ", Contract: " + contract.toString()); throw e; } }  @Override boolean createReservation(ReservationId reservationId, String user,
      Plan plan, ReservationDefinition contract); @Override boolean updateReservation(ReservationId reservationId, String user,
      Plan plan, ReservationDefinition contract); @Override boolean deleteReservation(ReservationId reservationId, String user,
      Plan plan);  }
@SuppressWarnings("javadoc") @Test public void testSimple() throws PlanningException { prepareBasicPlan(); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(5 * step); rr.setDeadline(20 * step); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 5, 10 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); assertTrue("Agent-based allocation failed", reservationID != null); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 3); ReservationAllocation cs = plan.getReservationById(reservationID); System.out.println("--------AFTER SIMPLE ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); for (long i = 10 * step; i < 20 * step; i++) { assertTrue( "Agent-based allocation unexpected", Resources.equals(cs.getResourcesAtTime(i), Resource.newInstance(2048 * 10, 2 * 10))); } }
@SuppressWarnings("javadoc") @Test public void testSharingPolicyFeedback() throws PlanningException { prepareBasicPlan(); float instConstraint = 40; float avgConstraint = 40; ReservationSchedulerConfiguration conf = ReservationSystemTestUtil.createConf(plan.getQueueName(), 100000, instConstraint, avgConstraint); plan.getSharingPolicy().init(plan.getQueueName(), conf); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(5 * step); rr.setDeadline(100 * step); ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(2048, 2), 20, 20, 10 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); agent.createReservation(reservationID, "u3", plan, rr); ReservationId reservationID2 = ReservationSystemTestUtil.getNewReservationId(); agent.createReservation(reservationID2, "u3", plan, rr); ReservationDefinition rr3 = new ReservationDefinitionPBImpl(); rr3.setArrival(5 * step); rr3.setDeadline(100 * step); ReservationRequest r3 = ReservationRequest.newInstance(Resource.newInstance(2048, 2), 45, 45, 10 * step); ReservationRequests reqs3 = new ReservationRequestsPBImpl(); reqs3.setReservationResources(Collections.singletonList(r3)); rr3.setReservationRequests(reqs3); ReservationId reservationID3 = ReservationSystemTestUtil.getNewReservationId(); try { agent.createReservation(reservationID3, "u3", plan, rr3); fail(); } catch (PlanningException pe) { } assertTrue("Agent-based allocation failed", reservationID != null); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 4); ReservationAllocation cs = plan.getReservationById(reservationID); ReservationAllocation cs2 = plan.getReservationById(reservationID2); ReservationAllocation cs3 = plan.getReservationById(reservationID3); assertNotNull(cs); assertNotNull(cs2); assertNull(cs3); System.out.println("--------AFTER SIMPLE ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); for (long i = 90 * step; i < 100 * step; i++) { assertTrue( "Agent-based allocation unexpected", Resources.equals(cs.getResourcesAtTime(i), Resource.newInstance(2048 * 20, 2 * 20))); } for (long i = 80 * step; i < 90 * step; i++) { assertTrue( "Agent-based allocation unexpected", Resources.equals(cs2.getResourcesAtTime(i), Resource.newInstance(2048 * 20, 2 * 20))); } }
@Test public void testOrder() throws PlanningException { prepareBasicPlan(); int[] f = { 100, 100 }; ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 30 * step, 30 * step + f.length * step, f.length * step); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), res, minAlloc), false)); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(0 * step); rr.setDeadline(70 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ORDER); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 1, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 10, 10, 20 * step); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); list.add(r); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); assertTrue("Agent-based allocation failed", reservationID != null); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 4); ReservationAllocation cs = plan.getReservationById(reservationID); assertTrue(cs.toString(), check(cs, 0 * step, 10 * step, 20, 1024, 1)); assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1)); assertTrue(cs.toString(), check(cs, 40 * step, 50 * step, 20, 1024, 1)); assertTrue(cs.toString(), check(cs, 50 * step, 70 * step, 10, 1024, 1)); System.out.println("--------AFTER ORDER ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testOrderNoGapImpossible() throws PlanningException { prepareBasicPlan(); int[] f = { 100, 100 }; ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 30, 30 * step + f.length * step, f.length * step); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), res, minAlloc), false)); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(0L); rr.setDeadline(70L); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ORDER_NO_GAP); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 1, 10); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 10, 10, 20); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); list.add(r); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); boolean result = false; try { result = agent.createReservation(reservationID, "u1", plan, rr); fail(); } catch (PlanningException p) { } assertFalse("Agent-based allocation should have failed", result); assertTrue("Agent-based allocation should have failed", plan .getAllReservations().size() == 3); System.out .println("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testOrderNoGap() throws PlanningException { prepareBasicPlan(); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(0 * step); rr.setDeadline(60 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ORDER_NO_GAP); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 1, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 10, 10, 20 * step); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); list.add(r); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); System.out.println("--------AFTER ORDER ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); 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, 0 * step, 10 * step, 20, 1024, 1)); assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1)); assertTrue(cs.toString(), check(cs, 30 * step, 40 * step, 20, 1024, 1)); assertTrue(cs.toString(), check(cs, 40 * step, 60 * step, 10, 1024, 1)); }
@Test public void testSingleSliding() throws PlanningException { prepareBasicPlan(); 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); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); 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()); }
@Test public void testAny() throws PlanningException { prepareBasicPlan(); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(100 * step); rr.setDeadline(120 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ANY); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 5, 5, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 5, 10 * step); ReservationRequest r3 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 110, 110, 10 * step); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); list.add(r3); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); boolean res = agent.createReservation(reservationID, "u1", plan, rr); assertTrue("Agent-based allocation failed", res); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 3); ReservationAllocation cs = plan.getReservationById(reservationID); assertTrue(cs.toString(), check(cs, 110 * step, 120 * step, 20, 1024, 1)); System.out.println("--------AFTER ANY ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testAnyImpossible() throws PlanningException { prepareBasicPlan(); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(100L); rr.setDeadline(120L); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ANY); ReservationRequest r1 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 35, 5, 30); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 110, 110, 10); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r1); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); boolean result = false; try { result = agent.createReservation(reservationID, "u1", plan, rr); fail(); } catch (PlanningException p) { } assertFalse("Agent-based allocation should have failed", result); assertTrue("Agent-based allocation should have failed", plan .getAllReservations().size() == 2); System.out.println("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testAll() throws PlanningException { prepareBasicPlan(); 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), 5, 5, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 10, 10, 20 * step); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); 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, 110 * step, 20, 1024, 1)); assertTrue(cs.toString(), check(cs, 110 * step, 120 * step, 25, 1024, 1)); System.out.println("--------AFTER ALL ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testAllImpossible() throws PlanningException { prepareBasicPlan(); ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(100L); rr.setDeadline(120L); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(1024, 1), 55, 5, 10); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(2048, 2), 55, 5, 20); List<ReservationRequest> list = new ArrayList<ReservationRequest>(); list.add(r); list.add(r2); reqs.setReservationResources(list); rr.setReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); boolean result = false; try { result = agent.createReservation(reservationID, "u1", plan, rr); fail(); } catch (PlanningException p) { } assertFalse("Agent-based allocation failed", result); assertTrue("Agent-based allocation failed", plan.getAllReservations() .size() == 2); System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }