Search in sources :

Example 1 with JSONJAXBContext

use of com.sun.jersey.api.json.JSONJAXBContext in project hadoop by apache.

the class TestRMWebServicesReservation method updateReservationTestHelper.

private void updateReservationTestHelper(String path, ReservationId reservationId, String media) throws JSONException, Exception {
    String reservationJson = loadJsonFile("update-reservation.json");
    JSONJAXBContext jc = new JSONJAXBContext(JSONConfiguration.mapped().build(), ReservationUpdateRequestInfo.class);
    JSONUnmarshaller unmarshaller = jc.createJSONUnmarshaller();
    ReservationUpdateRequestInfo rsci = unmarshaller.unmarshalFromJSON(new StringReader(reservationJson), ReservationUpdateRequestInfo.class);
    if (this.isAuthenticationEnabled()) {
        // only works when previous submit worked
        if (rsci.getReservationId() == null) {
            throw new IOException("Incorrectly parsed the reservatinId");
        }
        rsci.setReservationId(reservationId.toString());
    }
    Thread.sleep(1000);
    ClientResponse response = constructWebResource(path).entity(rsci, MediaType.APPLICATION_JSON).accept(media).post(ClientResponse.class);
    if (!this.isAuthenticationEnabled()) {
        assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
        return;
    }
    System.out.println("RESPONSE:" + response);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    assertResponseStatusCode(Status.OK, response.getStatusInfo());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) StringReader(java.io.StringReader) IOException(java.io.IOException) ReservationUpdateRequestInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateRequestInfo) JSONUnmarshaller(com.sun.jersey.api.json.JSONUnmarshaller) JSONJAXBContext(com.sun.jersey.api.json.JSONJAXBContext)

Example 2 with JSONJAXBContext

use of com.sun.jersey.api.json.JSONJAXBContext in project hadoop by apache.

the class TestRMWebServicesAppsModification method appTimeoutToJSON.

protected static String appTimeoutToJSON(AppTimeoutInfo timeout) throws Exception {
    StringWriter sw = new StringWriter();
    JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false).build(), AppTimeoutInfo.class);
    JSONMarshaller jm = ctx.createJSONMarshaller();
    jm.marshallToJSON(timeout, sw);
    jm.marshallToJSON(timeout, System.out);
    return sw.toString();
}
Also used : JSONMarshaller(com.sun.jersey.api.json.JSONMarshaller) StringWriter(java.io.StringWriter) JSONJAXBContext(com.sun.jersey.api.json.JSONJAXBContext)

Example 3 with JSONJAXBContext

use of com.sun.jersey.api.json.JSONJAXBContext in project hadoop by apache.

the class TestRMWebServicesNodeLabels method toJson.

@SuppressWarnings("rawtypes")
private String toJson(Object nsli, Class klass) throws Exception {
    StringWriter sw = new StringWriter();
    JSONJAXBContext ctx = new JSONJAXBContext(klass);
    JSONMarshaller jm = ctx.createJSONMarshaller();
    jm.marshallToJSON(nsli, sw);
    return sw.toString();
}
Also used : JSONMarshaller(com.sun.jersey.api.json.JSONMarshaller) StringWriter(java.io.StringWriter) JSONJAXBContext(com.sun.jersey.api.json.JSONJAXBContext)

Example 4 with JSONJAXBContext

use of com.sun.jersey.api.json.JSONJAXBContext in project hadoop by apache.

the class TestRMWebServicesAppsModification method appPriorityToJSON.

protected static String appPriorityToJSON(AppPriority targetPriority) throws Exception {
    StringWriter sw = new StringWriter();
    JSONJAXBContext ctx = new JSONJAXBContext(AppPriority.class);
    JSONMarshaller jm = ctx.createJSONMarshaller();
    jm.marshallToJSON(targetPriority, sw);
    return sw.toString();
}
Also used : JSONMarshaller(com.sun.jersey.api.json.JSONMarshaller) StringWriter(java.io.StringWriter) JSONJAXBContext(com.sun.jersey.api.json.JSONJAXBContext)

Example 5 with JSONJAXBContext

use of com.sun.jersey.api.json.JSONJAXBContext in project hadoop by apache.

the class TestRMWebServicesAppsModification method appQueueToJSON.

protected static String appQueueToJSON(AppQueue targetQueue) throws Exception {
    StringWriter sw = new StringWriter();
    JSONJAXBContext ctx = new JSONJAXBContext(AppQueue.class);
    JSONMarshaller jm = ctx.createJSONMarshaller();
    jm.marshallToJSON(targetQueue, sw);
    return sw.toString();
}
Also used : JSONMarshaller(com.sun.jersey.api.json.JSONMarshaller) StringWriter(java.io.StringWriter) JSONJAXBContext(com.sun.jersey.api.json.JSONJAXBContext)

Aggregations

JSONJAXBContext (com.sun.jersey.api.json.JSONJAXBContext)8 JSONMarshaller (com.sun.jersey.api.json.JSONMarshaller)5 StringWriter (java.io.StringWriter)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 JSONUnmarshaller (com.sun.jersey.api.json.JSONUnmarshaller)3 StringReader (java.io.StringReader)3 IOException (java.io.IOException)2 ReservationDeleteRequestInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteRequestInfo)1 ReservationSubmissionRequestInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationSubmissionRequestInfo)1 ReservationUpdateRequestInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateRequestInfo)1