public Set<String> getSubmittedYarnApps() throws Exception { String rmHost = PhoenixMRJobUtil.getActiveResourceManagerHost(conf, zkQuorum); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(YarnApplication.APP_STATES_ELEMENT, YarnApplication.state.NEW.toString() + "," + YarnApplication.state.ACCEPTED + "," + YarnApplication.state.SUBMITTED + "," + YarnApplication.state.RUNNING); int rmPort = PhoenixMRJobUtil.getRMPort(conf); String response = PhoenixMRJobUtil.getJobsInformationFromRM(rmHost, rmPort, urlParams); LOG.debug("Already Submitted/Running Apps = " + response); JSONObject jobsJson = new JSONObject(response); JSONObject appsJson = jobsJson.optJSONObject(YarnApplication.APPS_ELEMENT); Set<String> yarnApplicationSet = new HashSet<String>(); if (appsJson == null) { return yarnApplicationSet; } JSONArray appJson = appsJson.optJSONArray(YarnApplication.APP_ELEMENT); if (appJson == null) { return yarnApplicationSet; } for (int i = 0; i < appJson.length(); i++) { Gson gson = new GsonBuilder().create(); YarnApplication yarnApplication = gson.fromJson(appJson.getJSONObject(i).toString(), new TypeToken<YarnApplication>() { }.getType()); yarnApplicationSet.add(yarnApplication.getName()); } return yarnApplicationSet; }
public void writeNamespace(String prefix, String ns) throws XMLStreamException { ((Node) getNodes().peek()).setNamespace(prefix, ns); try { JSONObject nsObj = getCurrentNode().optJSONObject("@xmlns"); if (nsObj == null) { nsObj = new JSONObject(); getCurrentNode().put("@xmlns", nsObj); } if (prefix.equals("")) { prefix = "$"; } nsObj.put(prefix, ns); } catch (JSONException e) { throw new XMLStreamException(e); } }
/** * Given a request object, return the fragment of JSON that deals with Rexster-reserved parameters. * <p/> * These parameters are the returnKeys, showTypes, and offset. * * @param requestObject the request object * @return the JSON */ public static JSONObject getRexsterRequest(final JSONObject requestObject) { return requestObject != null ? requestObject.optJSONObject(Tokens.REXSTER) : null; }
@SuppressWarnings("unused") @Nullable public static JSONObject getOptionalJsonObject(final JSONObject jsonObject, final String attributeName) { final JSONObject res = jsonObject.optJSONObject(attributeName); if (res == JSONObject.NULL || res == null) { return null; } return res; }
@SuppressWarnings("unused") @Nullable public static JSONObject getOptionalJsonObject(JSONObject jsonObject, String attributeName) { final JSONObject res = jsonObject.optJSONObject(attributeName); if (res == JSONObject.NULL || res == null) { return null; } return res; }
@Nullable public static JSONObject getNestedOptionalObject(JSONObject json, final String... path) throws JSONException { for (int i = 0; i < path.length - 1; i++) { String s = path[i]; json = json.getJSONObject(s); } return json.optJSONObject(path[path.length - 1]); }
@Nullable public static <T> T getOptionalJsonObject(final JSONObject jsonObject, final String attributeName, final JsonObjectParser<T> jsonParser) throws JSONException { final JSONObject res = jsonObject.optJSONObject(attributeName); if (res == JSONObject.NULL || res == null) { return null; } return jsonParser.parse(res); }
@Nullable public static JSONObject getNestedOptionalObject(JSONObject json, String... path) throws JSONException { for (int i = 0; i < path.length - 1; i++) { String s = path[i]; json = json.getJSONObject(s); } return json.optJSONObject(path[path.length - 1]); }
@Nullable public static JSONObject getNestedOptionalObject(JSONObject json, String... path) throws JSONException { for (int i = 0; i < path.length - 1; i++) { String s = path[i]; json = json.getJSONObject(s); } return json.optJSONObject(path[path.length - 1]); }
public static JSONArray getNestedOptionalArray(JSONObject json, String... path) throws JSONException { for (int i = 0; json != null && i < path.length - 1; i++) { String s = path[i]; json = json.optJSONObject(s); } return json == null ? null : json.optJSONArray(path[path.length - 1]); }
@Nullable public static JSONObject getNestedOptionalObject(JSONObject json, final String... path) throws JSONException { for (int i = 0; i < path.length - 1; i++) { String s = path[i]; json = json.getJSONObject(s); } return json.optJSONObject(path[path.length - 1]); }
public static JSONArray getNestedOptionalArray(JSONObject json, String... path) throws JSONException { for (int i = 0; json != null && i < path.length - 1; i++) { String s = path[i]; json = json.optJSONObject(s); } return json == null ? null : json.optJSONArray(path[path.length - 1]); }
@Override public T parse(JSONObject json) throws JSONException { final JSONObject valueObject = json.optJSONObject(VALUE_ATTRIBUTE); if (valueObject == null) { throw new JSONException("Expected JSONObject with [" + VALUE_ATTRIBUTE + "] attribute present."); } return jsonParser.parse(valueObject); } }
@Override public T parse(JSONObject json) throws JSONException { final JSONObject valueObject = json.optJSONObject(VALUE_ATTRIBUTE); if (valueObject == null) { throw new JSONException("Expected JSONObject with [" + VALUE_ATTRIBUTE + "] attribute present."); } return jsonParser.parse(valueObject); } }
BaseInfo(JSONObject jsonObject) throws JSONException { final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO); //parse tez counters tezCounters = Utils.parseTezCountersFromJSON( otherInfoNode.optJSONObject(Constants.COUNTERS)); //parse events eventList = Lists.newArrayList(); Utils.parseEvents(jsonObject.optJSONArray(Constants.EVENTS), eventList); }
@Override public Comment parse(JSONObject json) throws JSONException { final URI selfUri = JsonParseUtil.getSelfUri(json); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String body = json.getString("body"); final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author")); final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor")); final Visibility visibility = visibilityJsonParser.parseVisibility(json); return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")), JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id); } }
@Override public Comment parse(JSONObject json) throws JSONException { final URI selfUri = JsonParseUtil.getSelfUri(json); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String body = json.getString("body"); final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author")); final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor")); final Visibility visibility = visibilityJsonParser.parseVisibility(json); return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")), JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id); } }
@Override public Comment parse(JSONObject json) throws JSONException { final URI selfUri = JsonParseUtil.getSelfUri(json); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String body = json.getString("body"); final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author")); final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor")); final Visibility visibility = visibilityJsonParser.parseVisibility(json); return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")), JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id); } }
@Override public CimIssueType parse(final JSONObject json) throws JSONException { final IssueType issueType = issueTypeJsonParser.parse(json); final JSONObject jsonFieldsMap = json.optJSONObject("fields"); final Map<String, CimFieldInfo> fields = (jsonFieldsMap == null) ? Collections.<String, CimFieldInfo>emptyMap() : fieldsParser.parse(jsonFieldsMap); return new CimIssueType(issueType.getSelf(), issueType.getId(), issueType.getName(), issueType.isSubtask(), issueType.getDescription(), issueType.getIconUri(), fields); } }
@Override public CimIssueType parse(final JSONObject json) throws JSONException { final IssueType issueType = issueTypeJsonParser.parse(json); final JSONObject jsonFieldsMap = json.optJSONObject("fields"); final Map<String, CimFieldInfo> fields = (jsonFieldsMap == null) ? Collections.<String, CimFieldInfo>emptyMap() : fieldsParser.parse(jsonFieldsMap); return new CimIssueType(issueType.getSelf(), issueType.getId(), issueType.getName(), issueType.isSubtask(), issueType.getDescription(), issueType.getIconUri(), fields); } }