Ejemplo n.º 1
0
 private ReservationSubmissionRequest createSimpleReservationRequest(
     int numContainers, long arrival, long deadline, long duration) {
   // create a request with a single atomic ask
   ReservationRequest r =
       ReservationRequest.newInstance(Resource.newInstance(1024, 1), numContainers, 1, duration);
   ReservationRequests reqs =
       ReservationRequests.newInstance(
           Collections.singletonList(r), ReservationRequestInterpreter.R_ALL);
   ReservationDefinition rDef =
       ReservationDefinition.newInstance(arrival, deadline, reqs, "testYarnClient#reservation");
   ReservationSubmissionRequest request =
       ReservationSubmissionRequest.newInstance(rDef, ReservationSystemTestUtil.reservationQ);
   return request;
 }
Ejemplo n.º 2
0
  @Test
  public void testReservationAPIs() {
    // initialize
    CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
    ReservationSystemTestUtil.setupQueueConfiguration(conf);
    conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class);
    conf.setBoolean(YarnConfiguration.RM_RESERVATION_SYSTEM_ENABLE, true);
    MiniYARNCluster cluster = new MiniYARNCluster("testReservationAPIs", 2, 1, 1);
    YarnClient client = null;
    try {
      cluster.init(conf);
      cluster.start();
      final Configuration yarnConf = cluster.getConfig();
      client = YarnClient.createYarnClient();
      client.init(yarnConf);
      client.start();

      // create a reservation
      Clock clock = new UTCClock();
      long arrival = clock.getTime();
      long duration = 60000;
      long deadline = (long) (arrival + 1.05 * duration);
      ReservationSubmissionRequest sRequest =
          createSimpleReservationRequest(4, arrival, deadline, duration);
      ReservationSubmissionResponse sResponse = null;
      try {
        sResponse = client.submitReservation(sRequest);
      } catch (Exception e) {
        Assert.fail(e.getMessage());
      }
      Assert.assertNotNull(sResponse);
      ReservationId reservationID = sResponse.getReservationId();
      Assert.assertNotNull(reservationID);
      System.out.println("Submit reservation response: " + reservationID);

      // Update the reservation
      ReservationDefinition rDef = sRequest.getReservationDefinition();
      ReservationRequest rr = rDef.getReservationRequests().getReservationResources().get(0);
      rr.setNumContainers(5);
      arrival = clock.getTime();
      duration = 30000;
      deadline = (long) (arrival + 1.05 * duration);
      rr.setDuration(duration);
      rDef.setArrival(arrival);
      rDef.setDeadline(deadline);
      ReservationUpdateRequest uRequest = ReservationUpdateRequest.newInstance(rDef, reservationID);
      ReservationUpdateResponse uResponse = null;
      try {
        uResponse = client.updateReservation(uRequest);
      } catch (Exception e) {
        Assert.fail(e.getMessage());
      }
      Assert.assertNotNull(sResponse);
      System.out.println("Update reservation response: " + uResponse);

      // Delete the reservation
      ReservationDeleteRequest dRequest = ReservationDeleteRequest.newInstance(reservationID);
      ReservationDeleteResponse dResponse = null;
      try {
        dResponse = client.deleteReservation(dRequest);
      } catch (Exception e) {
        Assert.fail(e.getMessage());
      }
      Assert.assertNotNull(sResponse);
      System.out.println("Delete reservation response: " + dResponse);
    } finally {
      // clean-up
      if (client != null) {
        client.stop();
      }
      cluster.stop();
    }
  }