Search in sources :

Example 66 with JSONArray

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

the class TestAHSWebServices method testMultipleAttempts.

@Test
public void testMultipleAttempts() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps").path(appId.toString()).path("appattempts").queryParam("user.name", USERS[round]).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    if (round == 1) {
        assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
        return;
    }
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject appAttempts = json.getJSONObject("appAttempts");
    assertEquals("incorrect number of elements", 1, appAttempts.length());
    JSONArray array = appAttempts.getJSONArray("appAttempt");
    assertEquals("incorrect number of elements", 5, array.length());
}
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) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 67 with JSONArray

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

the class TestHsWebServicesAttempts method verifyHsJobTaskAttemptCounters.

public void verifyHsJobTaskAttemptCounters(JSONObject info, TaskAttempt att) throws JSONException {
    assertEquals("incorrect number of elements", 2, info.length());
    WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()), info.getString("id"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray counterGroups = info.getJSONArray("taskAttemptCounterGroup");
    for (int i = 0; i < counterGroups.length(); i++) {
        JSONObject counterGroup = counterGroups.getJSONObject(i);
        String name = counterGroup.getString("counterGroupName");
        assertTrue("name not set", (name != null && !name.isEmpty()));
        JSONArray counters = counterGroup.getJSONArray("counter");
        for (int j = 0; j < counters.length(); j++) {
            JSONObject counter = counters.getJSONObject(j);
            String counterName = counter.getString("name");
            assertTrue("name not set", (counterName != null && !counterName.isEmpty()));
            long value = counter.getLong("value");
            assertTrue("value  >= 0", value >= 0);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 68 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project jersey by jersey.

the class EntityTypesTest method testJSONArrayRepresentation.

@Test
public void testJSONArrayRepresentation() throws Exception {
    final JSONArray array = new JSONArray();
    array.put("One").put("Two").put("Three").put(1).put(2.0);
    _test(array, JSONOArrayResource.class, MediaType.APPLICATION_JSON_TYPE);
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 69 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project elastic-job by dangdangdotcom.

the class MesosStateService method findExecutors.

private Collection<JSONObject> findExecutors(final JSONArray frameworks, final String appName) throws JSONException {
    List<JSONObject> result = Lists.newArrayList();
    Optional<String> frameworkIDOptional = frameworkIDService.fetch();
    String frameworkID;
    if (frameworkIDOptional.isPresent()) {
        frameworkID = frameworkIDOptional.get();
    } else {
        return result;
    }
    for (int i = 0; i < frameworks.length(); i++) {
        JSONObject framework = frameworks.getJSONObject(i);
        if (!framework.getString("id").equals(frameworkID)) {
            continue;
        }
        JSONArray executors = framework.getJSONArray("executors");
        for (int j = 0; j < executors.length(); j++) {
            JSONObject executor = executors.getJSONObject(j);
            if (null == appName || appName.equals(getExecutorId(executor).split("@-@")[0])) {
                result.add(executor);
            }
        }
    }
    return result;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 70 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project mirrorgate-jira-stories-collector by BBVA.

the class JiraIssueUtils method getPriorSprint.

public SprintDTO getPriorSprint(Object o) {
    if (o == null) {
        return null;
    }
    List<String> sprints = null;
    if (o instanceof JSONArray) {
        JSONArray array = (JSONArray) o;
        sprints = new ArrayList<>(array.length());
        for (int i = 0; i < array.length(); i++) {
            try {
                sprints.add((String) array.get(i));
            } catch (JSONException e) {
                LOGGER.error("Error parsing sprint field", e);
            }
        }
    } else if (o instanceof List) {
        sprints = (List<String>) o;
    }
    return getPriorSprint(sprints);
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException)

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