private ReservationSubmissionRequest createSimpleReservationSubmissionRequest( int numRequests, int numContainers, long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationSubmissionRequest request = new ReservationSubmissionRequestPBImpl(); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); rDef.setArrival(arrival); rDef.setDeadline(deadline); if (numRequests > 0) { ReservationRequests reqs = new ReservationRequestsPBImpl(); rDef.setReservationRequests(reqs); if (numContainers > 0) { ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), numContainers, 1, duration); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); } } request.setQueue(PLAN_NAME); request.setReservationDefinition(rDef); return request; }
private ReservationUpdateRequest createSimpleReservationUpdateRequest( int numRequests, int numContainers, long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl(); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); rDef.setArrival(arrival); rDef.setDeadline(deadline); if (numRequests > 0) { ReservationRequests reqs = new ReservationRequestsPBImpl(); rDef.setReservationRequests(reqs); if (numContainers > 0) { ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), numContainers, 1, duration); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); } } request.setReservationDefinition(rDef); request.setReservationId(ReservationSystemTestUtil.getNewReservationId()); return request; }
private ReservationSubmissionRequest createSimpleReservationSubmissionRequest( int numRequests, int numContainers, long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationSubmissionRequest request = new ReservationSubmissionRequestPBImpl(); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); rDef.setArrival(arrival); rDef.setDeadline(deadline); if (numRequests > 0) { ReservationRequests reqs = new ReservationRequestsPBImpl(); rDef.setReservationRequests(reqs); if (numContainers > 0) { ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), numContainers, 1, duration); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); } } request.setQueue(PLAN_NAME); request.setReservationDefinition(rDef); return request; }
private ReservationUpdateRequest createSimpleReservationUpdateRequest( int numRequests, int numContainers, long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl(); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); rDef.setArrival(arrival); rDef.setDeadline(deadline); if (numRequests > 0) { ReservationRequests reqs = new ReservationRequestsPBImpl(); rDef.setReservationRequests(reqs); if (numContainers > 0) { ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), numContainers, 1, duration); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); } } request.setReservationDefinition(rDef); request.setReservationId(ReservationSystemTestUtil.getNewReservationId()); return request; }
private ReservationDefinition createSimpleReservationDefinition(long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), 1, 1, duration); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); rDef.setReservationRequests(reqs); rDef.setArrival(arrival); rDef.setDeadline(deadline); return rDef; }
@SuppressWarnings("javadoc") @Test public void testSimple() throws PlanningException { prepareBasicPlan(); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(5 * step); rr.setDeadline(20 * step); ReservationRequest r = ReservationRequest.newInstance( Resource.newInstance(2048, 2, 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, 2 * 10))); } }
@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, 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()); }
public static ReservationDefinition generateRandomRR(Random rand, long i) { rand.setSeed(i); long now = System.currentTimeMillis(); // start time at random in the next 12 hours long arrival = rand.nextInt(12 * 3600 * 1000); // deadline at random in the next day long deadline = arrival + rand.nextInt(24 * 3600 * 1000); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(now + arrival); rr.setDeadline(now + deadline); int gang = 1 + rand.nextInt(9); int par = (rand.nextInt(1000) + 1) * gang; long dur = rand.nextInt(2 * 3600 * 1000); // random duration within 2h ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), par, gang, dur); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rand.nextInt(3); ReservationRequestInterpreter[] type = ReservationRequestInterpreter.values(); reqs.setInterpreter(type[rand.nextInt(type.length)]); rr.setReservationRequests(reqs); return rr; }
public static ReservationDefinition generateBigRR(Random rand, long i) { rand.setSeed(i); long now = System.currentTimeMillis(); // start time at random in the next 2 hours long arrival = rand.nextInt(2 * 3600 * 1000); // deadline at random in the next day long deadline = rand.nextInt(24 * 3600 * 1000); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(now + arrival); rr.setDeadline(now + deadline); int gang = 1; int par = 100000; // 100k tasks long dur = rand.nextInt(60 * 1000); // 1min tasks ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), par, gang, dur); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rand.nextInt(3); ReservationRequestInterpreter[] type = ReservationRequestInterpreter.values(); reqs.setInterpreter(type[rand.nextInt(type.length)]); rr.setReservationRequests(reqs); return rr; }
private ReservationDefinition createSimpleReservationDefinition(long arrival, long deadline, long duration, Collection<ReservationRequest> resources) { // create a request with a single atomic ask ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(new ArrayList<ReservationRequest>(resources)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); rDef.setReservationRequests(reqs); rDef.setArrival(arrival); rDef.setDeadline(deadline); return rDef; }
public static ReservationDefinition createSimpleReservationDefinition( long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 1, 1, duration); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); rDef.setReservationRequests(reqs); rDef.setArrival(arrival); rDef.setDeadline(deadline); return rDef; }
public static ReservationDefinition generateRandomRR(Random rand, long i) { rand.setSeed(i); long now = System.currentTimeMillis(); // start time at random in the next 12 hours long arrival = rand.nextInt(12 * 3600 * 1000); // deadline at random in the next day long deadline = arrival + rand.nextInt(24 * 3600 * 1000); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(now + arrival); rr.setDeadline(now + deadline); int gang = 1 + rand.nextInt(9); int par = (rand.nextInt(1000) + 1) * gang; long dur = rand.nextInt(2 * 3600 * 1000); // random duration within 2h ReservationRequest r = ReservationRequest .newInstance(Resource.newInstance(1024, 1), par, gang, dur); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rand.nextInt(3); ReservationRequestInterpreter[] type = ReservationRequestInterpreter.values(); reqs.setInterpreter(type[rand.nextInt(type.length)]); rr.setReservationRequests(reqs); return rr; }
@SuppressWarnings("javadoc") @Test public void testSimple() throws PlanningException { prepareBasicPlan(); // create a request with a single atomic ask 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))); } }
@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()); }
private ReservationDefinition createSimpleReservationDefinition(long arrival, long deadline, long duration) { // create a request with a single atomic ask ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 1, 1, duration); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); rDef.setReservationRequests(reqs); rDef.setArrival(arrival); rDef.setDeadline(deadline); return rDef; }
public static ReservationDefinition generateRandomRR(Random rand, long i) { rand.setSeed(i); long now = System.currentTimeMillis(); // start time at random in the next 12 hours long arrival = rand.nextInt(12 * 3600 * 1000); // deadline at random in the next day long deadline = arrival + rand.nextInt(24 * 3600 * 1000); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(now + arrival); rr.setDeadline(now + deadline); int gang = 1 + rand.nextInt(9); int par = (rand.nextInt(1000) + 1) * gang; long dur = rand.nextInt(2 * 3600 * 1000); // random duration within 2h ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), par, gang, dur); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rand.nextInt(3); ReservationRequestInterpreter[] type = ReservationRequestInterpreter.values(); reqs.setInterpreter(type[rand.nextInt(type.length)]); rr.setReservationRequests(reqs); return rr; }
public static ReservationDefinition generateBigRR(Random rand, long i) { rand.setSeed(i); long now = System.currentTimeMillis(); // start time at random in the next 2 hours long arrival = rand.nextInt(2 * 3600 * 1000); // deadline at random in the next day long deadline = rand.nextInt(24 * 3600 * 1000); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.setArrival(now + arrival); rr.setDeadline(now + deadline); int gang = 1; int par = 100000; // 100k tasks long dur = rand.nextInt(60 * 1000); // 1min tasks ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), par, gang, dur); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); rand.nextInt(3); ReservationRequestInterpreter[] type = ReservationRequestInterpreter.values(); reqs.setInterpreter(type[rand.nextInt(type.length)]); rr.setReservationRequests(reqs); return rr; }
public static ReservationDefinition createSimpleReservationDefinition( long arrival, long deadline, long duration, int parallelism) { // create a request with a single atomic ask ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), parallelism, parallelism, duration); ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.setReservationResources(Collections.singletonList(r)); reqs.setInterpreter(ReservationRequestInterpreter.R_ALL); rDef.setReservationRequests(reqs); rDef.setArrival(arrival); rDef.setDeadline(deadline); return rDef; }
@Test public void testOrder() throws PlanningException { prepareBasicPlan(); // create a completely utilized segment around time 30 int[] f = { 100, 100 }; assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), res, minAlloc))); // create a chain of 4 RR, mixing gang and non-gang 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, 2), 10, 1, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1, 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); // submit to agent ReservationId reservationID = ReservationSystemTestUtil .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); // validate 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(); // create a completely utilized segment at time 30 int[] f = { 100, 100 }; assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), res, minAlloc))); // create a chain of 4 RR, mixing gang and non-gang 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, 2), 10, 1, 10); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1, 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 { // submit to agent result = agent.createReservation(reservationID, "u1", plan, rr); fail(); } catch (PlanningException p) { // expected } // validate 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(); // create a chain of 4 RR, mixing gang and non-gang 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, 2), 10, 1, 10 * step); ReservationRequest r2 = ReservationRequest.newInstance( Resource.newInstance(1024, 1, 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); // submit to agent 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()); // validate 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)); }