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);
}
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);
}
}
}
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);
}
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);
}
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();
}
Aggregations