Search in sources :

Example 51 with JSONArray

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

the class TestRMWebServicesApps method testAppsQueryStartBeginEnd.

@Test
public void testAppsQueryStartBeginEnd() throws JSONException, Exception {
    rm.start();
    rm.registerNode("127.0.0.1:1234", 2048);
    long start = System.currentTimeMillis();
    Thread.sleep(1);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    long end = System.currentTimeMillis();
    Thread.sleep(1);
    rm.submitApp(CONTAINER_MB);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("startedTimeBegin", String.valueOf(start)).queryParam("startedTimeEnd", String.valueOf(end)).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());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 52 with JSONArray

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

the class TestRMWebServicesApps method testAppsHelper.

public void testAppsHelper(String path, RMApp app, String media) throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path(path).accept(media).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());
    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), app);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource)

Example 53 with JSONArray

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

the class TestRMWebServicesApps method testAppsQueryFinishBeginEnd.

@Test
public void testAppsQueryFinishBeginEnd() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    long start = System.currentTimeMillis();
    Thread.sleep(1);
    RMApp app1 = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    // finish App
    MockAM am = rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
    am.registerAppAttempt();
    am.unregisterAppAttempt();
    amNodeManager.nodeHeartbeat(app1.getCurrentAppAttempt().getAppAttemptId(), 1, ContainerState.COMPLETE);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    long end = System.currentTimeMillis();
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("finishedTimeBegin", String.valueOf(start)).queryParam("finishedTimeEnd", String.valueOf(end)).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());
    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());
    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) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 54 with JSONArray

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

the class TestRMWebServicesForCSWithPartitions method verifyAccesibleNodeLabels.

private void verifyAccesibleNodeLabels(JSONObject queueJson, Set<String> accesibleNodeLabels) throws JSONException {
    JSONArray nodeLabels = queueJson.getJSONArray("nodeLabels");
    assertEquals("number of accessible Node Labels not matching", accesibleNodeLabels.size(), nodeLabels.length());
    for (int i = 0; i < nodeLabels.length(); i++) {
        assertTrue("Invalid accessible node label : " + nodeLabels.getString(i), accesibleNodeLabels.contains(nodeLabels.getString(i)));
    }
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray)

Example 55 with JSONArray

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

Aggregations

JSONArray (org.codehaus.jettison.json.JSONArray)338 JSONObject (org.codehaus.jettison.json.JSONObject)280 Test (org.junit.Test)123 WebResource (com.sun.jersey.api.client.WebResource)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)64 JSONException (org.codehaus.jettison.json.JSONException)64 ArrayList (java.util.ArrayList)38 Test (org.testng.annotations.Test)30 Map (java.util.Map)23 HashMap (java.util.HashMap)22 Vertex (com.tinkerpop.blueprints.Vertex)20 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)20 Produces (javax.ws.rs.Produces)17 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)14 GET (javax.ws.rs.GET)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 IOException (java.io.IOException)12 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)12 HashSet (java.util.HashSet)10 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)9