Search in sources :

Example 21 with JSONObject

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);
}
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 22 with JSONObject

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);
    }
}
Also used : Counter(org.apache.hadoop.mapreduce.Counter) JSONObject(org.codehaus.jettison.json.JSONObject) CounterGroup(org.apache.hadoop.mapreduce.CounterGroup) Counter(org.apache.hadoop.mapreduce.Counter) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 23 with JSONObject

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject)

Example 24 with JSONObject

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"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) JSONObject(org.codehaus.jettison.json.JSONObject) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Matchers.anyString(org.mockito.Matchers.anyString) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 25 with JSONObject

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();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) JSONObject(org.codehaus.jettison.json.JSONObject) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) 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)

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