Java Code Examples for org.codehaus.jettison.json.JSONObject#optInt()
The following examples show how to use
org.codehaus.jettison.json.JSONObject#optInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DAGClientTimelineImpl.java From tez with Apache License 2.0 | 5 votes |
private VertexStatusProto.Builder parseVertexStatus(JSONObject jsonRoot, Set<StatusGetOpts> statusOptions) throws JSONException { final JSONObject otherInfoNode = jsonRoot.getJSONObject(ATSConstants.OTHER_INFO); final VertexStatusProto.Builder vertexStatusBuilder = VertexStatusProto.newBuilder(); final String status = otherInfoNode.optString(ATSConstants.STATUS); final String diagnostics = otherInfoNode.optString(ATSConstants.DIAGNOSTICS); if (status.equals("")) { return null; } vertexStatusBuilder.setState(vertexStateProtoMap.get(status)) .addAllDiagnostics(Collections.singleton(diagnostics)); int numRunningTasks = otherInfoNode.optInt(ATSConstants.NUM_TASKS) - otherInfoNode.optInt(ATSConstants.NUM_COMPLETED_TASKS); ProgressProto.Builder progressBuilder = ProgressProto.newBuilder(); progressBuilder.setTotalTaskCount(otherInfoNode.optInt(ATSConstants.NUM_TASKS)); progressBuilder.setRunningTaskCount(numRunningTasks); progressBuilder.setSucceededTaskCount(otherInfoNode.optInt(ATSConstants.NUM_SUCCEEDED_TASKS)); progressBuilder.setKilledTaskCount(otherInfoNode.optInt(ATSConstants.NUM_KILLED_TASKS)); progressBuilder.setFailedTaskCount(otherInfoNode.optInt(ATSConstants.NUM_FAILED_TASKS)); vertexStatusBuilder.setProgress(progressBuilder); if (statusOptions != null && statusOptions.contains(StatusGetOpts.GET_COUNTERS)) { final TezCountersProto.Builder tezCounterBuilder; final JSONObject countersNode = otherInfoNode.optJSONObject(ATSConstants.COUNTERS); tezCounterBuilder = parseDagCounters(countersNode); if (tezCounterBuilder != null) { vertexStatusBuilder.setVertexCounters(tezCounterBuilder); } } return vertexStatusBuilder; }
Example 2
Source File: DAGClientTimelineImpl.java From tez with Apache License 2.0 | 5 votes |
@VisibleForTesting protected Map<String, VertexTaskStats> parseTaskStatsForVertexes() throws TezException, JSONException { if (vertexTaskStatsCache == null) { final String url = String.format("%s/%s?primaryFilter=%s:%s&fields=%s", baseUri, ATSConstants.TEZ_VERTEX_ID, ATSConstants.TEZ_DAG_ID, dagId, FILTER_BY_FIELDS); final JSONObject jsonRoot = getJsonRootEntity(url); final JSONArray vertexNodes = jsonRoot.optJSONArray(ATSConstants.ENTITIES); if (vertexNodes != null) { final int numVertexNodes = vertexNodes.length(); Map<String, VertexTaskStats> vertexTaskStatsMap = new HashMap<String, VertexTaskStats>(numVertexNodes); for (int i = 0; i < numVertexNodes; i++) { final JSONObject vertexNode = vertexNodes.getJSONObject(i); final JSONObject otherInfoNode = vertexNode.getJSONObject(ATSConstants.OTHER_INFO); final String vertexName = otherInfoNode.getString(ATSConstants.VERTEX_NAME); final VertexTaskStats vertexTaskStats = new VertexTaskStats(otherInfoNode.optInt(ATSConstants.NUM_TASKS), otherInfoNode.optInt(ATSConstants.NUM_COMPLETED_TASKS), otherInfoNode.optInt(ATSConstants.NUM_SUCCEEDED_TASKS), otherInfoNode.optInt(ATSConstants.NUM_KILLED_TASKS), otherInfoNode.optInt(ATSConstants.NUM_FAILED_TASKS)); vertexTaskStatsMap.put(vertexName, vertexTaskStats); } vertexTaskStatsCache = vertexTaskStatsMap; } } return vertexTaskStatsCache; }
Example 3
Source File: DagInfo.java From tez with Apache License 2.0 | 5 votes |
private void parseDAGPlan(JSONObject dagPlan) throws JSONException { int version = dagPlan.optInt(Constants.VERSION, 1); parseEdges(dagPlan.optJSONArray(Constants.EDGES)); JSONArray verticesInfo = dagPlan.optJSONArray(Constants.VERTICES); parseBasicVertexInfo(verticesInfo); if (version > 1) { parseDAGContext(dagPlan.optJSONObject(Constants.DAG_CONTEXT)); } }
Example 4
Source File: DagInfo.java From tez with Apache License 2.0 | 5 votes |
/** * Parse edge details in the DAG * * @param edgesArray * * @throws JSONException */ private void parseEdges(JSONArray edgesArray) throws JSONException { if (edgesArray == null) { return; } for (int i = 0; i < edgesArray.length(); i++) { JSONObject edge = edgesArray.getJSONObject(i); Integer edgeId = edge.optInt(Constants.EDGE_ID); String inputVertexName = edge.optString(Constants.INPUT_VERTEX_NAME); String outputVertexName = edge.optString(Constants.OUTPUT_VERTEX_NAME); String dataMovementType = edge.optString(Constants.DATA_MOVEMENT_TYPE); String edgeSourceClass = edge.optString(Constants.EDGE_SOURCE_CLASS); String edgeDestinationClass = edge.optString(Constants.EDGE_DESTINATION_CLASS); String inputUserPayloadAsText = edge.optString(Constants.INPUT_PAYLOAD_TEXT); String outputUserPayloadAsText = edge.optString(Constants.OUTPUT_PAYLOAD_TEXT); EdgeInfo edgeInfo = new EdgeInfo(inputVertexName, outputVertexName, dataMovementType, edgeSourceClass, edgeDestinationClass, inputUserPayloadAsText, outputUserPayloadAsText); edgeInfoMap.put(edgeId, edgeInfo); } }
Example 5
Source File: DagInfo.java From tez with Apache License 2.0 | 4 votes |
DagInfo(JSONObject jsonObject) throws JSONException { super(jsonObject); vertexNameMap = Maps.newHashMap(); vertexNameIDMapping = new DualHashBidiMap<>(); edgeInfoMap = Maps.newHashMap(); basicVertexInfoMap = Maps.newHashMap(); containerMapping = LinkedHashMultimap.create(); Preconditions.checkArgument(jsonObject.getString(Constants.ENTITY_TYPE).equalsIgnoreCase (Constants.TEZ_DAG_ID)); dagId = StringInterner.weakIntern(jsonObject.getString(Constants.ENTITY)); //Parse additional Info JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO); long sTime = otherInfoNode.optLong(Constants.START_TIME); long eTime= otherInfoNode.optLong(Constants.FINISH_TIME); userName = otherInfoNode.optString(Constants.USER); if (eTime < sTime) { LOG.warn("DAG has got wrong start/end values. " + "startTime=" + sTime + ", endTime=" + eTime + ". Will check " + "timestamps in DAG started/finished events"); // Check if events DAG_STARTED, DAG_FINISHED can be made use of for(Event event : eventList) { switch (HistoryEventType.valueOf(event.getType())) { case DAG_STARTED: sTime = event.getAbsoluteTime(); break; case DAG_FINISHED: eTime = event.getAbsoluteTime(); break; default: break; } } if (eTime < sTime) { LOG.warn("DAG has got wrong start/end values in events as well. " + "startTime=" + sTime + ", endTime=" + eTime); } } startTime = sTime; endTime = eTime; //TODO: Not getting populated correctly for lots of jobs. Verify submitTime = otherInfoNode.optLong(Constants.START_REQUESTED_TIME); diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS); failedTasks = otherInfoNode.optInt(Constants.NUM_FAILED_TASKS); JSONObject dagPlan = otherInfoNode.optJSONObject(Constants.DAG_PLAN); name = StringInterner.weakIntern((dagPlan != null) ? (dagPlan.optString(Constants.DAG_NAME)) : null); if (dagPlan != null) { JSONArray vertices = dagPlan.optJSONArray(Constants.VERTICES); if (vertices != null) { numVertices = vertices.length(); } else { numVertices = 0; } parseDAGPlan(dagPlan); } else { numVertices = 0; } status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS)); //parse name id mapping JSONObject vertexIDMappingJson = otherInfoNode.optJSONObject(Constants.VERTEX_NAME_ID_MAPPING); if (vertexIDMappingJson != null) { //get vertex name for (Map.Entry<String, BasicVertexInfo> entry : basicVertexInfoMap.entrySet()) { String vertexId = vertexIDMappingJson.optString(entry.getKey()); //vertexName --> vertexId vertexNameIDMapping.put(entry.getKey(), vertexId); } } }
Example 6
Source File: VertexInfo.java From tez with Apache License 2.0 | 4 votes |
VertexInfo(JSONObject jsonObject) throws JSONException { super(jsonObject); Preconditions.checkArgument( jsonObject.getString(Constants.ENTITY_TYPE).equalsIgnoreCase (Constants.TEZ_VERTEX_ID)); vertexId = StringInterner.weakIntern(jsonObject.optString(Constants.ENTITY)); taskInfoMap = Maps.newHashMap(); inEdgeList = Lists.newLinkedList(); outEdgeList = Lists.newLinkedList(); additionalInputInfoList = Lists.newLinkedList(); additionalOutputInfoList = Lists.newLinkedList(); //Parse additional Info JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO); initRequestedTime = otherInfoNode.optLong(Constants.INIT_REQUESTED_TIME); startRequestedTime = otherInfoNode.optLong(Constants.START_REQUESTED_TIME); long sTime = otherInfoNode.optLong(Constants.START_TIME); long iTime = otherInfoNode.optLong(Constants.INIT_TIME); long eTime = otherInfoNode.optLong(Constants.FINISH_TIME); if (eTime < sTime) { LOG.warn("Vertex has got wrong start/end values. " + "startTime=" + sTime + ", endTime=" + eTime + ". Will check " + "timestamps in DAG started/finished events"); // Check if events VERTEX_STARTED, VERTEX_FINISHED can be made use of for(Event event : eventList) { switch (HistoryEventType.valueOf(event.getType())) { case VERTEX_INITIALIZED: iTime = event.getAbsoluteTime(); break; case VERTEX_STARTED: sTime = event.getAbsoluteTime(); break; case VERTEX_FINISHED: eTime = event.getAbsoluteTime(); break; default: break; } } if (eTime < sTime) { LOG.warn("Vertex has got wrong start/end values in events as well. " + "startTime=" + sTime + ", endTime=" + eTime); } } startTime = sTime; finishTime = eTime; initTime = iTime; diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS); numTasks = otherInfoNode.optInt(Constants.NUM_TASKS); failedTasks = otherInfoNode.optInt(Constants.NUM_FAILED_TASKS); succeededTasks = otherInfoNode.optInt(Constants.NUM_SUCCEEDED_TASKS); completedTasks = otherInfoNode.optInt(Constants.NUM_COMPLETED_TASKS); killedTasks = otherInfoNode.optInt(Constants.NUM_KILLED_TASKS); numFailedTaskAttempts = otherInfoNode.optInt(Constants.NUM_FAILED_TASKS_ATTEMPTS); vertexName = StringInterner.weakIntern(otherInfoNode.optString(Constants.VERTEX_NAME)); processorClass = StringInterner.weakIntern(otherInfoNode.optString(Constants.PROCESSOR_CLASS_NAME)); status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS)); }