Java Code Examples for org.codehaus.jettison.json.JSONObject

The following are top voted examples for showing how to use org.codehaus.jettison.json.JSONObject. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: smaph   File: SmaphDebugger.java   Source Code and License 8 votes vote down vote up
private JSONArray getAnnotatedSnippetS3(String query, WikipediaInterface wikiApi) throws JSONException, IOException {
	JSONArray res = new JSONArray();
	if (this.annotatedSnippetsAndBoldsS3.containsKey(query))
		for (Triple<String, HashSet<Annotation>, HashSet<Mention>> p : this.annotatedSnippetsAndBoldsS3.get(query)) {
			JSONObject pairJs = new JSONObject();
			res.put(pairJs);
			pairJs.put("snippet", p.getLeft());
			JSONArray annotationsJs = new JSONArray();
			pairJs.put("parts", annotationsJs);
			int lastIdx = 0;
			for (Annotation a : SmaphUtils.sorted(p.getMiddle())) {
				annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, a.getPosition(), p.getRight()));

				JSONObject annotationJs = getTextPartJson(p.getLeft(), a.getPosition(), a.getPosition() + a.getLength(),
						p.getRight());
				annotationsJs.put(annotationJs);
				annotationJs.put("title", wikiApi.getTitlebyId(a.getConcept()));
				annotationJs.put("wid", a.getConcept());
				annotationJs.put("url", widToUrl(a.getConcept(), wikiApi));
				lastIdx = a.getPosition() + a.getLength();
			}
			annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, p.getLeft().length(), p.getRight()));
		}
	return res;
}
 
Example 2
Project: hadoop   File: TestRMWebServices.java   Source Code and License 7 votes vote down vote up
public void verifyClusterMetricsJSON(JSONObject json) throws JSONException,
    Exception {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject clusterinfo = json.getJSONObject("clusterMetrics");
  assertEquals("incorrect number of elements", 27, clusterinfo.length());
  verifyClusterMetrics(
      clusterinfo.getInt("appsSubmitted"), clusterinfo.getInt("appsCompleted"),
      clusterinfo.getInt("reservedMB"), clusterinfo.getInt("availableMB"),
      clusterinfo.getInt("allocatedMB"),
      clusterinfo.getInt("reservedVirtualCores"), clusterinfo.getInt("availableVirtualCores"),
      clusterinfo.getInt("allocatedVirtualCores"), clusterinfo.getInt("totalVirtualCores"),
      clusterinfo.getInt("reservedGpuCores"), clusterinfo.getInt("availableGpuCores"),
      clusterinfo.getInt("allocatedGpuCores"), clusterinfo.getInt("totalGpuCores"),
      clusterinfo.getInt("containersAllocated"),
      clusterinfo.getInt("totalMB"), clusterinfo.getInt("totalNodes"),
      clusterinfo.getInt("lostNodes"), clusterinfo.getInt("unhealthyNodes"),
      clusterinfo.getInt("decommissionedNodes"),
      clusterinfo.getInt("rebootedNodes"),clusterinfo.getInt("activeNodes"));
}
 
Example 3
Project: hadoop   File: TestNMWebServicesApps.java   Source Code and License 6 votes vote down vote up
@Test
public void testNodeAppsUserNone() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  ClientResponse response = r.path("ws").path("v1").path("node").path("apps")
      .queryParam("user", "george").accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
}
 
Example 4
Project: hadoop   File: TestHsWebServicesAttempts.java   Source Code and License 6 votes vote down vote up
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);
    }
  }
}
 
Example 5
Project: smaph   File: SmaphDebugger.java   Source Code and License 6 votes vote down vote up
private JSONArray getEntityFeaturesJson(
		HashMap<String, List<Triple<Integer, HashMap<String, Double>, Boolean>>> source,
		String query, WikipediaInterface wikiApi) throws JSONException,
		IOException {
	JSONArray res = new JSONArray();
	if (source.containsKey(query))
		for (Triple<Integer, HashMap<String, Double>, Boolean> p : source
				.get(query)) {
			JSONObject pairJs = new JSONObject();
			res.put(pairJs);
			pairJs.put("wid", p.getLeft());
			pairJs.put("title", wikiApi.getTitlebyId(p.getLeft()));
			pairJs.put("url", widToUrl(p.getLeft(), wikiApi));
			JSONObject features = new JSONObject();
			pairJs.put("features", features);
			for (String ftrName : SmaphUtils.sorted(p.getMiddle().keySet()))
				features.put(ftrName, p.getMiddle().get(ftrName));
			pairJs.put("accepted", p.getRight());
		}
	return res;
}
 
Example 6
Project: hadoop   File: TestHsWebServicesJobsQuery.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobsQueryStartTimeEnd() throws JSONException, Exception {
  WebResource r = resource();
  // the mockJobs start time is the current time - some random amount
  Long now = System.currentTimeMillis();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeEnd", String.valueOf(now))
      .accept(MediaType.APPLICATION_JSON).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", 3, arr.length());
}
 
Example 7
Project: smaph   File: SmaphDebugger.java   Source Code and License 6 votes vote down vote up
private JSONArray getResultsJson(String query, WikipediaInterface wikiApi)
		throws JSONException, IOException {
	JSONArray res = new JSONArray();
	if (result.containsKey(query))
		for (ScoredAnnotation a: result.get(query)) {
			JSONObject triple = new JSONObject();
			res.put(triple);
			triple.put("begin", a.getPosition());
			triple.put("end", a.getPosition() + a.getLength());
			triple.put("score", a.getScore());
			triple.put("wid", a.getConcept());
			triple.put("title", wikiApi.getTitlebyId(a.getConcept()));
			triple.put("url", widToUrl(a.getConcept(), wikiApi));
		}
	return res;
}
 
Example 8
Project: hadoop   File: TestHsWebServicesTasks.java   Source Code and License 6 votes vote down vote up
public void verifyHsTask(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;
          verifyHsSingleTask(info, task);
        }
      }
      assertTrue("task with id: " + tid + " not in web service output", found);
    }
  }
}
 
Example 9
Project: hadoop   File: TestHsWebServicesAttempts.java   Source Code and License 6 votes vote down vote up
@Test
public void testTaskAttemptsSlash() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    for (Task task : jobsMap.get(id).getTasks().values()) {

      String tid = MRApps.toString(task.getID());
      ClientResponse response = r.path("ws").path("v1").path("history")
          .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid)
          .path("attempts/").accept(MediaType.APPLICATION_JSON)
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyHsTaskAttempts(json, task);
    }
  }
}
 
Example 10
Project: hadoop   File: TestHsWebServicesJobConf.java   Source Code and License 6 votes vote down vote up
public void verifyHsJobConf(JSONObject info, Job job) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
        info.getString("path"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray properties = info.getJSONArray("property");
    for (int i = 0; i < properties.length(); i++) {
      JSONObject prop = properties.getJSONObject(i);
      String name = prop.getString("name");
      String value = prop.getString("value");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      assertTrue("value not set", (value != null && !value.isEmpty()));
    }
  }
 
Example 11
Project: convertigo-eclipse   File: DesignDocumentTreeObject.java   Source Code and License 6 votes vote down vote up
public DesignDocumentTreeObject(Viewer viewer, DatabaseObject object, boolean inherited) {
	super(viewer, object, inherited);
	fFilters = new FolderTreeObject(viewer, "Filters");
	fUpdates = new FolderTreeObject(viewer, "Updates");
	fViews = new FolderTreeObject(viewer, "Views");
	loadFilters();
	loadUpdates();
	loadViews();
	
	if (object.bNew) {
		JSONObject json = getObject().getJSONObject();
		CouchKey._id.put(json, CouchKey._design.key() + getObject().getName());
		CouchKey._rev.remove(json);
	}
	
	syncDocument();
}
 
Example 12
Project: convertigo-eclipse   File: DesignDocumentTreeObject.java   Source Code and License 6 votes vote down vote up
private void loadFilters() {
	JSONObject jsonDocument = getObject().getJSONObject();
	JSONObject filters = CouchKey.filters.JSONObject(jsonDocument);
	
	if (filters != null) {
		if (filters.length() > 0) {
			addChild(fFilters);
		}
		
		for (Iterator<String> i = GenericUtils.cast(filters.keys()); i.hasNext(); ) {
			String key = i.next();
			
			try {
				FilterObject filter = new FilterObject(key, filters.getString(key));
				fFilters.addChild(new DesignDocumentFilterTreeObject(viewer, filter));
			} catch (Exception e) {
				Engine.logBeans.warn("[DesignDocument] filter named '" + key + "' is null; skipping...");
			}
		}
	}
}
 
Example 13
Project: hadoop   File: TestAMWebServicesAttempts.java   Source Code and License 6 votes vote down vote up
@Test
public void testTaskAttemptsDefault() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    for (Task task : jobsMap.get(id).getTasks().values()) {

      String tid = MRApps.toString(task.getID());
      ClientResponse response = r.path("ws").path("v1").path("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts")
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
Example 14
Project: hadoop   File: TestNMWebServicesApps.java   Source Code and License 6 votes vote down vote up
@Test
public void testNodeAppsUser() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  HashMap<String, String> hash = addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  ClientResponse response = r.path("ws").path("v1").path("node").path("apps")
      .queryParam("user", "mockUser").accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);

  JSONObject info = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, info.length());
  JSONArray appInfo = info.getJSONArray("app");
  assertEquals("incorrect number of elements", 1, appInfo.length());
  verifyNodeAppInfo(appInfo.getJSONObject(0), app, hash);
}
 
Example 15
Project: hadoop   File: TestAMWebServicesTasks.java   Source Code and License 6 votes vote down vote up
@Test
public void testTasks() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId).path("tasks")
        .accept(MediaType.APPLICATION_JSON).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 tasks = json.getJSONObject("tasks");
    JSONArray arr = tasks.getJSONArray("task");
    assertEquals("incorrect number of elements", 2, arr.length());

    verifyAMTask(arr, jobsMap.get(id), null);
  }
}
 
Example 16
Project: convertigo-engine   File: AbstractCouchDbTransaction.java   Source Code and License 6 votes vote down vote up
protected void makeDocument(Object result) throws Exception {
		if (result == null) return;
		Engine.logBeans.debug("(CouchDBTransaction) making document...");
		Document doc = context.outputDocument;
		Element root = doc.getDocumentElement();
		
		if (result instanceof JSONObject) {
			JSONObject jsonResult = (JSONObject) result;
//			Element couchdb_output = doc.createElement("couchdb_output");
			XMLUtils.jsonToXml(jsonResult, "couchdb_output", root, getConnector().isJsonUseType(), false, "item");
//			XMLUtils.JsonToXml(jsonResult, couchdb_output);
//			root.appendChild(couchdb_output);
		}
		
		Engine.logBeans.debug("(CouchDBTransaction) Document generated!");
	}
 
Example 17
Project: hadoop   File: TestAHSWebServices.java   Source Code and License 6 votes vote down vote up
@Test
public void testAppsQuery() throws Exception {
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .queryParam("state", YarnApplicationState.FINISHED.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).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 apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 5, array.length());
}
 
Example 18
Project: hadoop   File: TestAMWebServicesJobs.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobAttemptsDefault() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1")
        .path("mapreduce").path("jobs").path(jobId).path("jobattempts")
        .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 info = json.getJSONObject("jobAttempts");
    verifyJobAttempts(info, jobsMap.get(id));
  }
}
 
Example 19
Project: convertigo-engine   File: IonBean.java   Source Code and License 6 votes vote down vote up
public Map<String, IonEvent> getEvents() {
	Map<String, IonEvent> events = new HashMap<String, IonEvent>();
	try {
		JSONObject jsonEvents = jsonBean.getJSONObject(Key.events.name());
		@SuppressWarnings("unchecked")
		Iterator<String> it = jsonEvents.keys();
		while (it.hasNext()) {
			String pkey = it.next();
			if (!pkey.isEmpty()) {
				Object ob = jsonEvents.get(pkey);
				if (ob instanceof JSONObject) {
					IonEvent event = new IonEvent((JSONObject)ob);
					event.setName(pkey);
					events.put(event.getName(), event);
				}
			}
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return events;
}
 
Example 20
Project: hadoop   File: TestAMWebServicesJobs.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobIdSlash() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId + "/").accept(MediaType.APPLICATION_JSON)
        .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 info = json.getJSONObject("job");
    verifyAMJob(info, jobsMap.get(id));
  }
}
 
Example 21
Project: hadoop   File: TestRMWebServicesApps.java   Source Code and License 6 votes vote down vote up
@Test
public void testAppsQueryFinalStatus() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  RMApp app1 = rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps").queryParam("finalStatus", FinalApplicationStatus.UNDEFINED.toString())
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  System.out.println(json.toString());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 1, array.length());
  verifyAppInfo(array.getJSONObject(0), app1);
  rm.stop();
}
 
Example 22
Project: hadoop   File: TestAMWebServicesAttempts.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 23
Project: hadoop   File: TestRMHA.java   Source Code and License 6 votes vote down vote up
private void checkActiveRMWebServices() throws JSONException {

    // Validate web-service
    Client webServiceClient = Client.create(new DefaultClientConfig());
    InetSocketAddress rmWebappAddr =
        NetUtils.getConnectAddress(rm.getWebapp().getListenerAddress());
    String webappURL =
        "http://" + rmWebappAddr.getHostName() + ":" + rmWebappAddr.getPort();
    WebResource webResource = webServiceClient.resource(webappURL);
    String path = app.getApplicationId().toString();

    ClientResponse response =
        webResource.path("ws").path("v1").path("cluster").path("apps")
          .path(path).accept(MediaType.APPLICATION_JSON)
          .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 appJson = json.getJSONObject("app");
    assertEquals("ACCEPTED", appJson.getString("state"));
    // Other stuff is verified in the regular web-services related tests
  }
 
Example 24
Project: hadoop   File: TestAMWebServicesJobConf.java   Source Code and License 6 votes vote down vote up
public void verifyAMJobConf(JSONObject info, Job job) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
        info.getString("path"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray properties = info.getJSONArray("property");
    for (int i = 0; i < properties.length(); i++) {
      JSONObject prop = properties.getJSONObject(i);
      String name = prop.getString("name");
      String value = prop.getString("value");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      assertTrue("value not set", (value != null && !value.isEmpty()));
    }
  }
 
Example 25
Project: hadoop   File: TestRMWebServicesApps.java   Source Code and License 6 votes vote down vote up
public void verifyAppInfo(JSONObject info, RMApp app) throws JSONException,
    Exception {

  assertEquals("incorrect number of elements", 30, info.length());

  verifyAppInfoGeneric(app, info.getString("id"), info.getString("user"),
      info.getString("name"), info.getString("applicationType"),
      info.getString("queue"), info.getString("state"),
      info.getString("finalStatus"), (float) info.getDouble("progress"),
      info.getString("trackingUI"), info.getString("diagnostics"),
      info.getLong("clusterId"), info.getLong("startedTime"),
      info.getLong("finishedTime"), info.getLong("elapsedTime"),
      info.getString("amHostHttpAddress"), info.getString("amContainerLogs"),
      info.getInt("allocatedMB"), info.getInt("allocatedVCores"), info.getInt("allocatedGCores"),
      info.getInt("runningContainers"), 
      info.getInt("preemptedResourceMB"),
      info.getInt("preemptedResourceVCores"), info.getInt("preemptedResourceGCores"),
      info.getInt("numNonAMContainerPreempted"),
      info.getInt("numAMContainerPreempted"));
}
 
Example 26
Project: hadoop   File: TestRMWebServicesApps.java   Source Code and License 6 votes vote down vote up
@Test
public void testAppsQueryStateNone() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps")
      .queryParam("state", YarnApplicationState.RUNNING.toString())
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
  rm.stop();
}
 
Example 27
Project: convertigo-engine   File: IonConfig.java   Source Code and License 6 votes vote down vote up
protected Map<String, String> getCfgPlugins(Key key, String keyId) {
	try {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray ar = jsonConfig.getJSONArray(key.name());
		for (int i=0; i<ar.length(); i++) {
			Object ob = ar.get(i);
			if (ob instanceof JSONObject) {
				JSONObject jsonImport = (JSONObject)ob;
				String plugin = jsonImport.getString(keyId);
				if (!plugin.isEmpty() && !jsonImport.toString().isEmpty()) {
					map.put(plugin, jsonImport.toString());
				}
			}
		}
		return map;
	} catch (JSONException e) {
		return new HashMap<String, String>();
	}
}
 
Example 28
Project: hadoop   File: TestHsWebServicesJobConf.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobConf() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("history")
        .path("mapreduce")
        .path("jobs").path(jobId).path("conf")
        .accept(MediaType.APPLICATION_JSON).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 info = json.getJSONObject("conf");
    verifyHsJobConf(info, jobsMap.get(id));
  }
}
 
Example 29
Project: hadoop   File: TestRMWebServicesNodes.java   Source Code and License 6 votes vote down vote up
@Test
public void testNodesQueryNew() throws JSONException, Exception {
  WebResource r = resource();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  MockNM nm2 = rm.registerNode("h2:1235", 5121);
  rm.sendNodeStarted(nm1);
  rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
  rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW);

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("nodes").queryParam("states", NodeState.NEW.toString())
      .accept(MediaType.APPLICATION_JSON).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", 1, nodeArray.length());
  JSONObject info = nodeArray.getJSONObject(0);

  verifyNodeInfo(info, nm2);
}
 
Example 30
Project: convertigo-engine   File: ComponentManager.java   Source Code and License 6 votes vote down vote up
private void readPropertyModels(JSONObject root) {
	try {
		JSONObject props = root.getJSONObject("Props");
		@SuppressWarnings("unchecked")
		Iterator<String> it = props.keys();
		while (it.hasNext()) {
			String key = it.next();
			if (!key.isEmpty()) {
				IonProperty property = new IonProperty(props.getJSONObject(key));
				property.setName(key);
				pCache.put(key, property);
			}
		}
	} catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 31
Project: hadoop   File: TestHsWebServicesJobsQuery.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobsQueryFinishTimeEndInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("finishedTimeEnd", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
Example 32
Project: hadoop   File: TestHsWebServicesJobsQuery.java   Source Code and License 6 votes vote down vote up
@Test
public void testJobsQueryFinishTimeInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("finishedTimeBegin", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
Example 33
Project: hadoop   File: TestAMWebServicesTasks.java   Source Code and License 5 votes vote down vote up
public void verifyAMSingleTask(JSONObject info, Task task)
    throws JSONException {
  assertEquals("incorrect number of elements", 9, info.length());

  verifyTaskGeneric(task, info.getString("id"), info.getString("state"),
      info.getString("type"), info.getString("successfulAttempt"),
      info.getLong("startTime"), info.getLong("finishTime"),
      info.getLong("elapsedTime"), (float) info.getDouble("progress"),
      info.getString("status"));
}
 
Example 34
Project: hadoop   File: TestNMWebServicesApps.java   Source Code and License 5 votes vote down vote up
@Test
public void testNodeSingleAppsInvalid() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp(2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps").path("app_foo_0000")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    WebServicesTestUtils.checkStringMatch("exception message",
        "For input string: \"foo\"", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NumberFormatException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.NumberFormatException", classname);
  }
}
 
Example 35
Project: hadoop   File: TestRMWebServices.java   Source Code and License 5 votes vote down vote up
@Test
public void testCluster() throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  verifyClusterInfo(json);
}
 
Example 36
Project: smaph   File: WATRelatednessComputer.java   Source Code and License 5 votes vote down vote up
private double queryJsonRel(int wid1, int wid2, String urlTemplate) {
	String url = String.format(urlTemplate, baseUri, gcubeToken, wid1, wid2);
	LOG.info(url);
	JSONObject obj = SmaphUtils.httpQueryJson(url);
	try {
		increaseFlushCounter();
		double rel = obj.getJSONArray("pairs").getJSONObject(0).getDouble("relatedness");
		LOG.debug(" -> " + rel);
		return rel;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 37
Project: hadoop   File: TestRMWebServicesApps.java   Source Code and License 5 votes vote down vote up
@Test
public void testAppsQueryFinalStatusInvalid() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .queryParam("finalStatus", "INVALID_test")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid state query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    WebServicesTestUtils
        .checkStringContains(
            "exception message",
            "org.apache.hadoop.yarn.api.records.FinalApplicationStatus.INVALID_test",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "IllegalArgumentException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.IllegalArgumentException", classname);

  } finally {
    rm.stop();
  }
}
 
Example 38
Project: hadoop   File: TestAMWebServicesAttempts.java   Source Code and License 5 votes vote down vote up
@Test
public void testTaskAttemptId() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();

  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    for (Task task : jobsMap.get(id).getTasks().values()) {
      String tid = MRApps.toString(task.getID());

      for (TaskAttempt att : task.getAttempts().values()) {
        TaskAttemptId attemptid = att.getID();
        String attid = MRApps.toString(attemptid);

        ClientResponse response = r.path("ws").path("v1").path("mapreduce")
            .path("jobs").path(jobId).path("tasks").path(tid)
            .path("attempts").path(attid).accept(MediaType.APPLICATION_JSON)
            .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 info = json.getJSONObject("taskAttempt");
        verifyAMTaskAttempt(info, att, task.getType());
      }
    }
  }
}
 
Example 39
Project: hadoop   File: TestRMWebServicesNodes.java   Source Code and License 5 votes vote down vote up
public void testSingleNodeHelper(String nodeid, MockNM nm, String media)
    throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("nodes").path(nodeid).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 info = json.getJSONObject("node");
  verifyNodeInfo(info, nm);
}
 
Example 40
Project: convertigo-eclipse   File: MobilePickerContentProvider.java   Source Code and License 5 votes vote down vote up
private void addSequences(Map<String, Set<String>> map, TVObject tvs, Object object, boolean isReferenced) {
	if (object != null) {
		if (object instanceof Project) {
			Project project = (Project)object;
			for (Sequence s : project.getSequencesList()) {
				String label = isReferenced ? s.getQName():s.getName();

				tvs.add(new TVObject(label, s));
				
				Set<String> infos = map.get(s.getQName());
				if (infos != null) {
					for (String info: infos) {
						try {
							JSONObject jsonInfo = new JSONObject(info);
							if (jsonInfo.has("marker")) {
								String marker = jsonInfo.getString("marker");
								if (!marker.isEmpty()) {
									tvs.add(new TVObject(label + "#" + marker, s, jsonInfo));
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}
	}
}