use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.
the class LogsCLI method getAMContainerInfoForRMWebService.
protected List<JSONObject> getAMContainerInfoForRMWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException {
Client webServiceClient = Client.create();
String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf);
WebResource webResource = webServiceClient.resource(webAppAddress);
ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts");
JSONArray requests = json.getJSONArray("appAttempt");
List<JSONObject> amContainersList = new ArrayList<JSONObject>();
for (int i = 0; i < requests.length(); i++) {
amContainersList.add(requests.getJSONObject(i));
}
return amContainersList;
}
use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.
the class LogsCLI method getContainerLogFiles.
private List<Pair<PerContainerLogFileInfo, String>> getContainerLogFiles(Configuration conf, String containerIdStr, String nodeHttpAddress) throws IOException {
List<Pair<PerContainerLogFileInfo, String>> logFileInfos = new ArrayList<>();
Client webServiceClient = Client.create();
try {
WebResource webResource = webServiceClient.resource(WebAppUtils.getHttpSchemePrefix(conf) + nodeHttpAddress);
ClientResponse response = webResource.path("ws").path("v1").path("node").path("containers").path(containerIdStr).path("logs").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
if (response.getStatusInfo().getStatusCode() == ClientResponse.Status.OK.getStatusCode()) {
try {
JSONArray array = new JSONArray();
JSONObject json = response.getEntity(JSONObject.class);
Object logsInfoObj = json.get("containerLogsInfo");
if (logsInfoObj instanceof JSONObject) {
array.put((JSONObject) logsInfoObj);
} else if (logsInfoObj instanceof JSONArray) {
JSONArray logsArray = (JSONArray) logsInfoObj;
for (int i = 0; i < logsArray.length(); i++) {
array.put(logsArray.getJSONObject(i));
}
}
for (int i = 0; i < array.length(); i++) {
JSONObject log = array.getJSONObject(i);
String aggregateType = log.has("logAggregationType") ? log.getString("logAggregationType") : "N/A";
Object ob = log.get("containerLogInfo");
if (ob instanceof JSONArray) {
JSONArray obArray = (JSONArray) ob;
for (int j = 0; j < obArray.length(); j++) {
logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON(obArray.getJSONObject(j)), aggregateType));
}
} else if (ob instanceof JSONObject) {
logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON((JSONObject) ob), aggregateType));
}
}
} catch (Exception e) {
System.err.println("Unable to parse json from webservice. Error:");
System.err.println(e.getMessage());
throw new IOException(e);
}
}
} catch (ClientHandlerException | UniformInterfaceException ex) {
System.err.println("Unable to fetch log files list");
throw new IOException(ex);
}
return logFileInfos;
}
use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.
the class JSONHistoryViewerPrinter method printJobCounters.
private void printJobCounters(Counters totalCounters, Counters mapCounters, Counters reduceCounters) throws JSONException {
// Killed jobs might not have counters
if (totalCounters != null) {
JSONObject jGroups = new JSONObject();
for (String groupName : totalCounters.getGroupNames()) {
CounterGroup totalGroup = totalCounters.getGroup(groupName);
CounterGroup mapGroup = mapCounters.getGroup(groupName);
CounterGroup reduceGroup = reduceCounters.getGroup(groupName);
Iterator<Counter> ctrItr = totalGroup.iterator();
JSONArray jGroup = new JSONArray();
while (ctrItr.hasNext()) {
JSONObject jCounter = new JSONObject();
org.apache.hadoop.mapreduce.Counter counter = ctrItr.next();
String name = counter.getName();
long mapValue = mapGroup.findCounter(name).getValue();
long reduceValue = reduceGroup.findCounter(name).getValue();
long totalValue = counter.getValue();
jCounter.put("counterName", name);
jCounter.put("mapValue", mapValue);
jCounter.put("reduceValue", reduceValue);
jCounter.put("totalValue", totalValue);
jGroup.put(jCounter);
}
jGroups.put(fixGroupNameForShuffleErrors(totalGroup.getName()), jGroup);
}
json.put("counters", jGroups);
}
}
use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.
the class TestRMWebServiceAppsNodelabel method testAppsRunning.
@Test
public void testAppsRunning() throws JSONException, Exception {
rm.start();
MockNM nm1 = rm.registerNode("h1:1234", 2048);
MockNM nm2 = rm.registerNode("h2:1235", 2048);
nodeLabelManager.addLabelsToNode(ImmutableMap.of(NodeId.newInstance("h2", 1235), toSet("X")));
RMApp app1 = rm.submitApp(AM_CONTAINER_MB, "app", "user", null, "default");
MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);
nm1.nodeHeartbeat(true);
// AM request for resource in partition X
am1.allocate("*", 1024, 1, new ArrayList<ContainerId>(), "X");
nm2.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
JSONObject json = response.getEntity(JSONObject.class);
// Verify apps resource
JSONObject apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
JSONObject jsonObject = apps.getJSONArray("app").getJSONObject(0).getJSONObject("resourceInfo");
JSONArray jsonArray = jsonObject.getJSONArray("resourceUsagesByPartition");
assertEquals("Partition expected is 2", 2, jsonArray.length());
// Default partition resource
JSONObject defaultPartition = jsonArray.getJSONObject(0);
verifyResource(defaultPartition, "", getResource(1024, 1), getResource(1024, 1), getResource(0, 0));
// verify resource used for parition x
JSONObject paritionX = jsonArray.getJSONObject(1);
verifyResource(paritionX, "X", getResource(0, 0), getResource(1024, 1), getResource(0, 0));
rm.stop();
}
use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.
the class TestRMWebServicesNodes method testNodesResourceUtilization.
@Test
public void testNodesResourceUtilization() throws JSONException, Exception {
WebResource r = resource();
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
NodeId nodeId1 = rmnode1.getNodeID();
RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes().get(nodeId1);
NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(true, "test health report", System.currentTimeMillis());
ResourceUtilization nodeResource = ResourceUtilization.newInstance(4096, 0, (float) 10.5);
ResourceUtilization containerResource = ResourceUtilization.newInstance(2048, 0, (float) 5.05);
NodeStatus nodeStatus = NodeStatus.newInstance(nodeId1, 0, new ArrayList<ContainerStatus>(), null, nodeHealth, containerResource, nodeResource, null);
node.handle(new RMNodeStatusEvent(nodeId1, nodeStatus, null));
rm.waitForState(nodeId1, NodeState.RUNNING);
ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes").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 nodes = json.getJSONObject("nodes");
assertEquals("incorrect number of elements", 1, nodes.length());
JSONArray nodeArray = nodes.getJSONArray("node");
assertEquals("incorrect number of elements", 1, nodeArray.length());
JSONObject info = nodeArray.getJSONObject(0);
// verify the resource utilization
verifyNodeInfo(info, rmnode1);
}
Aggregations