Search in sources :

Example 6 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class TestRMWebServicesReservation method testFailedSubmitReservation.

@Test
public void testFailedSubmitReservation() throws Exception {
    rm.start();
    // setup a cluster too small to accept the reservation
    setupCluster(1);
    ReservationId rid = getReservationIdTestHelper(1);
    ClientResponse response = reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, rid);
    assertTrue(!isHttpSuccessResponse(response));
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) Test(org.junit.Test)

Example 7 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class TestRMWebServicesReservation method testEmptyStartTimeRequestListReservation.

@Test
public void testEmptyStartTimeRequestListReservation() throws Exception {
    rm.start();
    setupCluster(100);
    ReservationId id1 = getReservationIdTestHelper(1);
    ReservationId id2 = getReservationIdTestHelper(2);
    long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time, "res_1", id1);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION, "res_2", id2);
    WebResource resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("end-time", new Long((long) (time + MINIMUM_RESOURCE_DURATION * 0.9)).toString()).queryParam("include-resource-allocations", "true").queryParam("queue", DEFAULT_QUEUE);
    JSONObject json = testListReservationHelper(resource);
    if (!this.isAuthenticationEnabled() && json == null) {
        return;
    }
    JSONObject reservations = json.getJSONObject("reservations");
    testRDLHelper(reservations);
    // only res_1 should fall into the time interval given in the request json.
    String reservationName = reservations.getJSONObject("reservation-definition").getString("reservation-name");
    assertEquals(reservationName, "res_1");
    rm.stop();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 8 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class TestRMWebServicesReservation method getReservationIdTestHelper.

/**
   * This method is used when a ReservationId is required. Attempt to use REST
   * API. If authentication is not enabled, ensure that the response status is
   * unauthorized and generate a ReservationId because downstream components
   * require a ReservationId for testing.
   * @param fallbackReservationId the ReservationId to use if authentication
   *                              is not enabled, causing the getNewReservation
   *                              API to fail.
   * @return the object representing the reservation ID.
   */
private ReservationId getReservationIdTestHelper(int fallbackReservationId) throws Exception {
    Thread.sleep(1000);
    ClientResponse response = constructWebResource(GET_NEW_RESERVATION_PATH).type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class);
    if (!this.isAuthenticationEnabled()) {
        assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
        return ReservationId.newInstance(clock.getTime(), fallbackReservationId);
    }
    System.out.println("RESPONSE:" + response);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    ReservationId rid = null;
    try {
        rid = ReservationId.parseReservationId(json.getString("reservation-id"));
    } catch (JSONException j) {
    // failure is possible and is checked outside
    }
    return rid;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) JSONException(org.codehaus.jettison.json.JSONException)

Example 9 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class TestRMWebServicesReservation method testInvalidTimeIntervalRequestListReservation.

@Test
public void testInvalidTimeIntervalRequestListReservation() throws Exception {
    rm.start();
    setupCluster(100);
    long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
    ReservationId id1 = getReservationIdTestHelper(1);
    ReservationId id2 = getReservationIdTestHelper(2);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time, "res_1", id1);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION, "res_2", id2);
    WebResource resource;
    resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", "-100").queryParam("end-time", "-100").queryParam("include-resource-allocations", "true").queryParam("queue", DEFAULT_QUEUE);
    JSONObject json = testListReservationHelper(resource);
    if (!this.isAuthenticationEnabled() && json == null) {
        return;
    }
    JSONArray reservations = json.getJSONArray("reservations");
    assertEquals(2, reservations.length());
    testRDLHelper(reservations.getJSONObject(0));
    testRDLHelper(reservations.getJSONObject(1));
    rm.stop();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 10 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class TestInMemoryPlan method testDeleteNonExistingReservation.

@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));
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Aggregations

ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)120 Test (org.junit.Test)85 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)40 PlanningException (org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException)27 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)19 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)17 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)16 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)16 WebResource (com.sun.jersey.api.client.WebResource)14 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)14 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)13 JSONObject (org.codehaus.jettison.json.JSONObject)13 ArrayList (java.util.ArrayList)11 ReservationSubmissionResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse)11 IOException (java.io.IOException)10 Resource (org.apache.hadoop.yarn.api.records.Resource)10 ReservationDefinitionPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl)10 ReservationRequestsPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl)10 ReservationListResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse)9 ReservationAllocationStateProto (org.apache.hadoop.yarn.proto.YarnProtos.ReservationAllocationStateProto)9