本文整理匯總了Java中org.codehaus.jettison.json.JSONArray.getJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.getJSONObject方法的具體用法?Java JSONArray.getJSONObject怎麽用?Java JSONArray.getJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jettison.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.getJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sandbox
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
/**
* 獲取沙箱信息.
*
* @param appName 作業雲配置App的名字
* @return 沙箱信息
* @throws JSONException 解析JSON格式異常
*/
public JsonArray sandbox(final String appName) throws JSONException {
JSONObject state = fetch(stateUrl);
JsonArray result = new JsonArray();
for (JSONObject each : findExecutors(state.getJSONArray("frameworks"), appName)) {
JSONArray slaves = state.getJSONArray("slaves");
String slaveHost = null;
for (int i = 0; i < slaves.length(); i++) {
JSONObject slave = slaves.getJSONObject(i);
if (each.getString("slave_id").equals(slave.getString("id"))) {
slaveHost = slave.getString("pid").split("@")[1];
}
}
Preconditions.checkNotNull(slaveHost);
JSONObject slaveState = fetch(String.format("http://%s/state", slaveHost));
String workDir = slaveState.getJSONObject("flags").getString("work_dir");
Collection<JSONObject> executorsOnSlave = findExecutors(slaveState.getJSONArray("frameworks"), appName);
for (JSONObject executorOnSlave : executorsOnSlave) {
JsonObject r = new JsonObject();
r.addProperty("hostname", slaveState.getString("hostname"));
r.addProperty("path", executorOnSlave.getString("directory").replace(workDir, ""));
result.add(r);
}
}
return result;
}
示例2: findExecutors
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
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("@[email protected]")[0])) {
result.add(executor);
}
}
}
return result;
}
示例3: testJobsDefault
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
@Test
public void testJobsDefault() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("history")
.path("mapreduce").path("jobs").get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
JSONObject jobs = json.getJSONObject("jobs");
JSONArray arr = jobs.getJSONArray("job");
assertEquals("incorrect number of elements", 1, arr.length());
JSONObject info = arr.getJSONObject(0);
Job job = appContext.getPartialJob(MRApps.toJobID(info.getString("id")));
VerifyJobsUtils.verifyHsJobPartial(info, job);
}
示例4: testJobsQueryUser
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
@Test
public void testJobsQueryUser() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("history")
.path("mapreduce").path("jobs").queryParam("user", "mock")
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
System.out.println(json.toString());
assertEquals("incorrect number of elements", 1, json.length());
JSONObject jobs = json.getJSONObject("jobs");
JSONArray arr = jobs.getJSONArray("job");
assertEquals("incorrect number of elements", 3, arr.length());
// just verify one of them.
JSONObject info = arr.getJSONObject(0);
Job job = appContext.getPartialJob(MRApps.toJobID(info.getString("id")));
VerifyJobsUtils.verifyHsJobPartial(info, job);
}
示例5: verifyAMTaskAttempts
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyAMTaskAttempts(JSONObject json, Task task)
throws JSONException {
assertEquals("incorrect number of elements", 1, json.length());
JSONObject attempts = json.getJSONObject("taskAttempts");
assertEquals("incorrect number of elements", 1, json.length());
JSONArray arr = attempts.getJSONArray("taskAttempt");
for (TaskAttempt att : task.getAttempts().values()) {
TaskAttemptId id = att.getID();
String attid = MRApps.toString(id);
Boolean found = false;
for (int i = 0; i < arr.length(); i++) {
JSONObject info = arr.getJSONObject(i);
if (attid.matches(info.getString("id"))) {
found = true;
verifyAMTaskAttempt(info, att, task.getType());
}
}
assertTrue("task attempt with id: " + attid
+ " not in web service output", found);
}
}
示例6: verifyAMTask
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyAMTask(JSONArray arr, Job job, String type)
throws JSONException {
for (Task task : job.getTasks().values()) {
TaskId id = task.getID();
String tid = MRApps.toString(id);
Boolean found = false;
if (type != null && task.getType() == MRApps.taskType(type)) {
for (int i = 0; i < arr.length(); i++) {
JSONObject info = arr.getJSONObject(i);
if (tid.matches(info.getString("id"))) {
found = true;
verifyAMSingleTask(info, task);
}
}
assertTrue("task with id: " + tid + " not in web service output", found);
}
}
}
示例7: verifyAMJobTaskAttemptCounters
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyAMJobTaskAttemptCounters(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);
}
}
}
示例8: verifyHsTaskAttempts
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsTaskAttempts(JSONObject json, Task task)
throws JSONException {
assertEquals("incorrect number of elements", 1, json.length());
JSONObject attempts = json.getJSONObject("taskAttempts");
assertEquals("incorrect number of elements", 1, json.length());
JSONArray arr = attempts.getJSONArray("taskAttempt");
for (TaskAttempt att : task.getAttempts().values()) {
TaskAttemptId id = att.getID();
String attid = MRApps.toString(id);
Boolean found = false;
for (int i = 0; i < arr.length(); i++) {
JSONObject info = arr.getJSONObject(i);
if (attid.matches(info.getString("id"))) {
found = true;
verifyHsTaskAttempt(info, att, task.getType());
}
}
assertTrue("task attempt with id: " + attid
+ " not in web service output", found);
}
}
示例9: prepareCompTypes
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private void prepareCompTypes(Set<String> neededTypes) {
try {
JSONArray buildInfo = new JSONArray(Resources.toString(
Compiler.class.getResource(COMP_BUILD_INFO), Charsets.UTF_8));
Set<String> allSimpleTypes = Sets.newHashSet();
for (int i = 0; i < buildInfo.length(); ++i) {
JSONObject comp = buildInfo.getJSONObject(i);
allSimpleTypes.add(comp.getString("type"));
}
simpleCompTypes = Sets.newHashSet(neededTypes);
simpleCompTypes.retainAll(allSimpleTypes);
extCompTypes = Sets.newHashSet(neededTypes);
extCompTypes.removeAll(allSimpleTypes);
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: verifyHsJobAttempts
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsJobAttempts(JSONObject info, Job job)
throws JSONException {
JSONArray attempts = info.getJSONArray("jobAttempt");
assertEquals("incorrect number of elements", 2, attempts.length());
for (int i = 0; i < attempts.length(); i++) {
JSONObject attempt = attempts.getJSONObject(i);
verifyHsJobAttemptsGeneric(job, attempt.getString("nodeHttpAddress"),
attempt.getString("nodeId"), attempt.getInt("id"),
attempt.getLong("startTime"), attempt.getString("containerId"),
attempt.getString("logsLink"));
}
}
示例11: verifyJobAttempts
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyJobAttempts(JSONObject info, Job job)
throws JSONException {
JSONArray attempts = info.getJSONArray("jobAttempt");
assertEquals("incorrect number of elements", 2, attempts.length());
for (int i = 0; i < attempts.length(); i++) {
JSONObject attempt = attempts.getJSONObject(i);
verifyJobAttemptsGeneric(job, attempt.getString("nodeHttpAddress"),
attempt.getString("nodeId"), attempt.getInt("id"),
attempt.getLong("startTime"), attempt.getString("containerId"),
attempt.getString("logsLink"));
}
}
示例12: getSubQueue
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONObject getSubQueue(JSONObject queue, String subQueue)
throws JSONException {
JSONArray queues = queue.getJSONObject("queues").getJSONArray("queue");
for (int i=0; i<queues.length(); ++i) {
checkResourcesUsed(queues.getJSONObject(i));
if (queues.getJSONObject(i).getString("queueName").equals(subQueue) ) {
return queues.getJSONObject(i);
}
}
return null;
}
示例13: testPerUserResourcesJSON
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
@Test
public void testPerUserResourcesJSON() throws Exception {
//Start RM so that it accepts app submissions
rm.start();
try {
rm.submitApp(10, "app1", "user1", null, "b1");
rm.submitApp(20, "app2", "user2", null, "b1");
//Get JSON
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("scheduler/").accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
JSONObject schedulerInfo = json.getJSONObject("scheduler").getJSONObject(
"schedulerInfo");
JSONObject b1 = getSubQueue(getSubQueue(schedulerInfo, "b"), "b1");
//Check users user1 and user2 exist in b1
JSONArray users = b1.getJSONObject("users").getJSONArray("user");
for (int i=0; i<2; ++i) {
JSONObject user = users.getJSONObject(i);
assertTrue("User isn't user1 or user2",user.getString("username")
.equals("user1") || user.getString("username").equals("user2"));
user.getInt("numActiveApplications");
user.getInt("numPendingApplications");
checkResourcesUsed(user);
}
} finally {
rm.stop();
}
}
示例14: testNodesQueryStateLost
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
@Test
public void testNodesQueryStateLost() throws JSONException, Exception {
WebResource r = resource();
MockNM nm1 = rm.registerNode("h1:1234", 5120);
MockNM nm2 = rm.registerNode("h2:1234", 5120);
rm.sendNodeStarted(nm1);
rm.sendNodeStarted(nm2);
rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
rm.NMwaitForState(nm2.getNodeId(), NodeState.RUNNING);
rm.sendNodeLost(nm1);
rm.sendNodeLost(nm2);
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("nodes").queryParam("states", NodeState.LOST.toString())
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
JSONObject nodes = json.getJSONObject("nodes");
assertEquals("incorrect number of elements", 1, nodes.length());
JSONArray nodeArray = nodes.getJSONArray("node");
assertEquals("incorrect number of elements", 2, nodeArray.length());
for (int i = 0; i < nodeArray.length(); ++i) {
JSONObject info = nodeArray.getJSONObject(i);
String host = info.get("id").toString().split(":")[0];
RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(host);
WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "",
info.getString("nodeHTTPAddress"));
WebServicesTestUtils.checkStringMatch("state", rmNode.getState()
.toString(), info.getString("state"));
}
}
示例15: testNodesHelper
import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void testNodesHelper(String path, String media) throws JSONException,
Exception {
WebResource r = resource();
MockNM nm1 = rm.registerNode("h1:1234", 5120);
MockNM nm2 = rm.registerNode("h2:1235", 5121);
rm.sendNodeStarted(nm1);
rm.sendNodeStarted(nm2);
rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
rm.NMwaitForState(nm2.getNodeId(), NodeState.RUNNING);
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path(path).accept(media).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
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", 2, nodeArray.length());
JSONObject info = nodeArray.getJSONObject(0);
String id = info.get("id").toString();
if (id.matches("h1:1234")) {
verifyNodeInfo(info, nm1);
verifyNodeInfo(nodeArray.getJSONObject(1), nm2);
} else {
verifyNodeInfo(info, nm2);
verifyNodeInfo(nodeArray.getJSONObject(1), nm1);
}
}