Search in sources :

Example 1 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestRMWebServicesReservation method testInvalidEndTimeRequestListReservation.

@Test
public void testInvalidEndTimeRequestListReservation() 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 = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", Long.toString((long) (time + MINIMUM_RESOURCE_DURATION * 1.3))).queryParam("end-time", "-1").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);
    String reservationName = reservations.getJSONObject("reservation-definition").getString("reservation-name");
    assertEquals(reservationName, "res_2");
    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 2 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestRMWebServicesReservation method testTimeIntervalRequestListReservation.

@Test
public void testTimeIntervalRequestListReservation() 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 = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", Long.toString((long) (time * 0.9))).queryParam("end-time", Long.toString(time + (long) (0.9 * MINIMUM_RESOURCE_DURATION))).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);
    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 3 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestRMWebServicesReservation method testRDLHelper.

private void testRDLHelper(JSONObject json) throws JSONException {
    JSONObject requests = json.getJSONObject("reservation-definition").getJSONObject("reservation-requests");
    String type = requests.getString("reservation-request-interpreter");
    assertEquals("0", type);
    assertEquals(60, requests.getJSONArray("reservation-request").getJSONObject(0).getInt("duration"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject)

Example 4 with JSONObject

use of org.codehaus.jettison.json.JSONObject 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 5 with JSONObject

use of org.codehaus.jettison.json.JSONObject 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)

Aggregations

JSONObject (org.codehaus.jettison.json.JSONObject)1464 Test (org.junit.Test)457 JSONException (org.codehaus.jettison.json.JSONException)411 ClientResponse (com.sun.jersey.api.client.ClientResponse)402 JSONArray (org.codehaus.jettison.json.JSONArray)385 WebResource (com.sun.jersey.api.client.WebResource)308 Test (org.testng.annotations.Test)263 BaseTest (org.xdi.oxauth.BaseTest)200 Parameters (org.testng.annotations.Parameters)191 Response (javax.ws.rs.core.Response)185 Builder (javax.ws.rs.client.Invocation.Builder)173 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)173 HashMap (java.util.HashMap)133 IOException (java.io.IOException)94 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)88 ArrayList (java.util.ArrayList)86 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)81 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)73 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)69 Map (java.util.Map)62