use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.
the class TestNMWebServices method testNode.
@Test
public void testNode() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("node").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
verifyNodeInfo(json);
}
use of org.codehaus.jettison.json.JSONObject 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.JSONObject in project hadoop by apache.
the class JSONHistoryViewerPrinter method printTaskSummary.
private void printTaskSummary() throws JSONException {
HistoryViewer.SummarizedJob ts = new HistoryViewer.SummarizedJob(job);
JSONObject jSums = new JSONObject();
JSONObject jSumSetup = new JSONObject();
jSumSetup.put("total", ts.totalSetups);
jSumSetup.put("successful", ts.numFinishedSetups);
jSumSetup.put("failed", ts.numFailedSetups);
jSumSetup.put("killed", ts.numKilledSetups);
jSumSetup.put("startTime", ts.setupStarted);
jSumSetup.put("finishTime", ts.setupFinished);
jSums.put("setup", jSumSetup);
JSONObject jSumMap = new JSONObject();
jSumMap.put("total", ts.totalMaps);
jSumMap.put("successful", job.getFinishedMaps());
jSumMap.put("failed", ts.numFailedMaps);
jSumMap.put("killed", ts.numKilledMaps);
jSumMap.put("startTime", ts.mapStarted);
jSumMap.put("finishTime", ts.mapFinished);
jSums.put("map", jSumMap);
JSONObject jSumReduce = new JSONObject();
jSumReduce.put("total", ts.totalReduces);
jSumReduce.put("successful", job.getFinishedReduces());
jSumReduce.put("failed", ts.numFailedReduces);
jSumReduce.put("killed", ts.numKilledReduces);
jSumReduce.put("startTime", ts.reduceStarted);
jSumReduce.put("finishTime", ts.reduceFinished);
jSums.put("reduce", jSumReduce);
JSONObject jSumCleanup = new JSONObject();
jSumCleanup.put("total", ts.totalCleanups);
jSumCleanup.put("successful", ts.numFinishedCleanups);
jSumCleanup.put("failed", ts.numFailedCleanups);
jSumCleanup.put("killed", ts.numKilledCleanups);
jSumCleanup.put("startTime", ts.cleanupStarted);
jSumCleanup.put("finishTime", ts.cleanupFinished);
jSums.put("cleanup", jSumCleanup);
json.put("taskSummary", jSums);
}
use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.
the class TestLogsCLI method testInvalidAMContainerId.
@Test(timeout = 5000L)
public void testInvalidAMContainerId() throws Exception {
Configuration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED, true);
YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED, UserGroupInformation.getCurrentUser().getShortUserName());
LogsCLI cli = spy(new LogsCLIForTest(mockYarnClient));
List<JSONObject> list = Arrays.asList(new JSONObject());
doReturn(list).when(cli).getAMContainerInfoForRMWebService(any(Configuration.class), any(String.class));
cli.setConf(conf);
int exitCode = cli.run(new String[] { "-applicationId", "application_1465862913885_0027", "-am", "1000" });
assertTrue(exitCode == -1);
assertTrue(sysErrStream.toString().contains("exceeds the number of AM containers"));
}
use of org.codehaus.jettison.json.JSONObject 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();
}
Aggregations