Search in sources :

Example 61 with JSONObject

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

the class TestRMWebServicesForCSWithPartitions method testSchedulerPartitions.

@Test
public void testSchedulerPartitions() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifySchedulerInfoJson(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 62 with JSONObject

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

the class TestRMWebServicesForCSWithPartitions method verifySchedulerInfoJson.

private void verifySchedulerInfoJson(JSONObject json) throws JSONException, Exception {
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject info = json.getJSONObject("scheduler");
    assertEquals("incorrect number of elements", 1, info.length());
    info = info.getJSONObject("schedulerInfo");
    assertEquals("incorrect number of elements", 8, info.length());
    JSONObject capacitiesJsonObject = info.getJSONObject(CAPACITIES);
    JSONArray partitionsCapsArray = capacitiesJsonObject.getJSONArray(QUEUE_CAPACITIES_BY_PARTITION);
    assertEquals("incorrect number of elements", CLUSTER_LABELS.size(), partitionsCapsArray.length());
    for (int i = 0; i < partitionsCapsArray.length(); i++) {
        JSONObject partitionInfo = partitionsCapsArray.getJSONObject(i);
        String partitionName = partitionInfo.getString("partitionName");
        assertTrue("Unknown partition received", CLUSTER_LABELS.contains(partitionName));
        verifyPartitionCapacityInfoJson(partitionInfo, 100, 0, 100, 100, 0, 100);
    }
    JSONObject jsonQueuesObject = info.getJSONObject("queues");
    JSONArray queuesArray = jsonQueuesObject.getJSONArray("queue");
    for (int i = 0; i < queuesArray.length(); i++) {
        JSONObject queueJson = queuesArray.getJSONObject(i);
        String queue = queueJson.getString("queueName");
        assertEquals("Partition resourceInfo is wrong", 1, queueJson.getJSONObject("resources").getJSONArray(RESOURCE_USAGES_BY_PARTITION).length());
        JSONObject resourcesJsonObject = queueJson.getJSONObject("resources");
        JSONArray partitionsResourcesArray = resourcesJsonObject.getJSONArray("resourceUsagesByPartition");
        assertEquals("incorrect number of elements", 1, partitionsResourcesArray.length());
        capacitiesJsonObject = queueJson.getJSONObject(CAPACITIES);
        partitionsCapsArray = capacitiesJsonObject.getJSONArray(QUEUE_CAPACITIES_BY_PARTITION);
        JSONObject partitionInfo = null;
        String partitionName = null;
        switch(queue) {
            case QUEUE_A:
                assertEquals("incorrect number of partitions", 1, partitionsCapsArray.length());
                partitionInfo = partitionsCapsArray.getJSONObject(0);
                partitionName = partitionInfo.getString("partitionName");
                verifyPartitionCapacityInfoJson(partitionInfo, 30, 0, 50, 30, 0, 50);
                assertEquals("incorrect number of elements", 6, partitionsResourcesArray.getJSONObject(0).length());
                break;
            case QUEUE_B:
                assertEquals("Invalid default Label expression", LABEL_LX, queueJson.getString("defaultNodeLabelExpression"));
                assertEquals("incorrect number of elements", 6, partitionsResourcesArray.getJSONObject(0).length());
                verifyAccesibleNodeLabels(queueJson, ImmutableSet.of(LABEL_LX));
                assertEquals("incorrect number of partitions", 2, partitionsCapsArray.length());
                for (int j = 0; j < partitionsCapsArray.length(); j++) {
                    partitionInfo = partitionsCapsArray.getJSONObject(j);
                    partitionName = partitionInfo.getString("partitionName");
                    switch(partitionName) {
                        case LABEL_LX:
                            verifyPartitionCapacityInfoJson(partitionInfo, 30, 0, 100, 30, 0, 100);
                            break;
                        case DEFAULT_PARTITION:
                            verifyPartitionCapacityInfoJson(partitionInfo, 30, 0, 50, 30, 0, 50);
                            break;
                        default:
                            Assert.fail("Unexpected partition" + partitionName);
                    }
                }
                break;
            case QUEUE_C:
                verifyAccesibleNodeLabels(queueJson, ImmutableSet.of(LABEL_LX, LABEL_LY));
                assertEquals("incorrect number of elements", 4, partitionsResourcesArray.getJSONObject(0).length());
                verifyQcPartitionsCapacityInfoJson(partitionsCapsArray, 70, 100, 70, 100, 100, 100, 100, 100, 40, 50, 40, 50);
                verifySubQueuesOfQc(queueJson);
                break;
            default:
                Assert.fail("Unexpected queue" + queue);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 63 with JSONObject

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

the class TestRMWebServices method testClusterSchedulerFifoDefault.

@Test
public void testClusterSchedulerFifoDefault() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifyClusterSchedulerFifo(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 64 with JSONObject

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

the class TestRMWebServices method testClusterSchedulerFifo.

@Test
public void testClusterSchedulerFifo() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifyClusterSchedulerFifo(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 65 with JSONObject

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

the class TestRMWebServicesApps method testAppsQueryFinalStatus.

@Test
public void testAppsQueryFinalStatus() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    RMApp app1 = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("finalStatus", FinalApplicationStatus.UNDEFINED.toString()).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    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());
    System.out.println(json.toString());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 1, array.length());
    verifyAppInfo(array.getJSONObject(0), app1);
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

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