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