Java Code Examples for org.codehaus.jettison.json.JSONObject#optLong()

The following examples show how to use org.codehaus.jettison.json.JSONObject#optLong() . 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: StramWebServices.java    From Bats with Apache License 2.0 6 votes vote down vote up
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, String content) throws JSONException
{
  init();
  LOG.debug("Start recording on {} requested", opId);
  JSONObject response = new JSONObject();
  long numWindows = 0;
  if (StringUtils.isNotBlank(content)) {
    JSONObject r = new JSONObject(content);
    numWindows = r.optLong("numWindows", 0);
  }
  String id = getTupleRecordingId();
  dagManager.startRecording(id, opId, null, numWindows);
  response.put("id", id);
  return response;
}
 
Example 2
Source File: StramWebServices.java    From Bats with Apache License 2.0 6 votes vote down vote up
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/ports/{portName}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, @PathParam("portName") String portName, String content) throws JSONException
{
  init();
  LOG.debug("Start recording on {}.{} requested", opId, portName);
  JSONObject response = new JSONObject();
  long numWindows = 0;
  if (StringUtils.isNotBlank(content)) {
    JSONObject r = new JSONObject(content);
    numWindows = r.optLong("numWindows", 0);
  }
  String id = getTupleRecordingId();
  dagManager.startRecording(id, opId, portName, numWindows);
  response.put("id", id);
  return response;
}
 
Example 3
Source File: StramWebServices.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, String content) throws JSONException
{
  init();
  LOG.debug("Start recording on {} requested", opId);
  JSONObject response = new JSONObject();
  long numWindows = 0;
  if (StringUtils.isNotBlank(content)) {
    JSONObject r = new JSONObject(content);
    numWindows = r.optLong("numWindows", 0);
  }
  String id = getTupleRecordingId();
  dagManager.startRecording(id, opId, null, numWindows);
  response.put("id", id);
  return response;
}
 
Example 4
Source File: StramWebServices.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/ports/{portName}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, @PathParam("portName") String portName, String content) throws JSONException
{
  init();
  LOG.debug("Start recording on {}.{} requested", opId, portName);
  JSONObject response = new JSONObject();
  long numWindows = 0;
  if (StringUtils.isNotBlank(content)) {
    JSONObject r = new JSONObject(content);
    numWindows = r.optLong("numWindows", 0);
  }
  String id = getTupleRecordingId();
  dagManager.startRecording(id, opId, portName, numWindows);
  response.put("id", id);
  return response;
}
 
Example 5
Source File: Utils.java    From tez with Apache License 2.0 6 votes vote down vote up
/**
 * Parse events from json
 *
 * @param eventNodes
 * @param eventList
 * @throws JSONException
 */
public static void parseEvents(JSONArray eventNodes, List<Event> eventList) throws
    JSONException {
  if (eventNodes == null) {
    return;
  }
  for (int i = 0; i < eventNodes.length(); i++) {
    JSONObject eventNode = eventNodes.optJSONObject(i);
    final String eventInfo = eventNode.optString(Constants.EVENT_INFO);
    final String eventType = eventNode.optString(Constants.EVENT_TYPE);
    final long time = eventNode.optLong(Constants.EVENT_TIME_STAMP);

    Event event = new Event(eventInfo, eventType, time);

    eventList.add(event);

  }
}
 
Example 6
Source File: TaskAttemptInfo.java    From tez with Apache License 2.0 4 votes vote down vote up
TaskAttemptInfo(JSONObject jsonObject) throws JSONException {
  super(jsonObject);

  Preconditions.checkArgument(
      jsonObject.getString(Constants.ENTITY_TYPE).equalsIgnoreCase
          (Constants.TEZ_TASK_ATTEMPT_ID));

  taskAttemptId = StringInterner.weakIntern(jsonObject.optString(Constants.ENTITY));

  //Parse additional Info
  final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO);

  long sTime = otherInfoNode.optLong(Constants.START_TIME);
  long eTime = otherInfoNode.optLong(Constants.FINISH_TIME);
  if (eTime < sTime) {
    LOG.warn("TaskAttemptInfo has got wrong start/end values. "
        + "startTime=" + sTime + ", endTime=" + eTime + ". Will check "
        + "timestamps in DAG started/finished events");

    // Check if events TASK_STARTED, TASK_FINISHED can be made use of
    for(Event event : eventList) {
      switch (HistoryEventType.valueOf(event.getType())) {
      case TASK_ATTEMPT_STARTED:
        sTime = event.getAbsoluteTime();
        break;
      case TASK_ATTEMPT_FINISHED:
        eTime = event.getAbsoluteTime();
        break;
      default:
        break;
      }
    }

    if (eTime < sTime) {
      LOG.warn("TaskAttemptInfo has got wrong start/end values in events as well. "
          + "startTime=" + sTime + ", endTime=" + eTime);
    }
  }
  startTime = sTime;
  endTime = eTime;

  diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS);
  creationTime = otherInfoNode.optLong(Constants.CREATION_TIME);
  creationCausalTA = StringInterner.weakIntern(
      otherInfoNode.optString(Constants.CREATION_CAUSAL_ATTEMPT));
  allocationTime = otherInfoNode.optLong(Constants.ALLOCATION_TIME);
  containerId = StringInterner.weakIntern(otherInfoNode.optString(Constants.CONTAINER_ID));
  String id = otherInfoNode.optString(Constants.NODE_ID);
  nodeId = StringInterner.weakIntern((id != null) ? (id.split(":")[0]) : "");
  logUrl = otherInfoNode.optString(Constants.COMPLETED_LOGS_URL);

  status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS));
  container = new Container(containerId, nodeId);
  if (otherInfoNode.has(Constants.LAST_DATA_EVENTS)) {
    List<DataDependencyEvent> eventInfo = Utils.parseDataEventDependencyFromJSON(
        otherInfoNode.optJSONObject(Constants.LAST_DATA_EVENTS));
    long lastTime = 0;
    for (DataDependencyEvent item : eventInfo) {
      // check these are in time order
      Preconditions.checkState(lastTime < item.getTimestamp());
      lastTime = item.getTimestamp();
      lastDataEvents.add(item);
    }
  }
  terminationCause = StringInterner
      .weakIntern(otherInfoNode.optString(ATSConstants.TASK_ATTEMPT_ERROR_ENUM));
  executionTimeInterval = (endTime > startTime) ? (endTime - startTime) : 0;
}
 
Example 7
Source File: DagInfo.java    From tez with Apache License 2.0 4 votes vote down vote up
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 8
Source File: TaskInfo.java    From tez with Apache License 2.0 4 votes vote down vote up
TaskInfo(JSONObject jsonObject) throws JSONException {
  super(jsonObject);

  Preconditions.checkArgument(
      jsonObject.getString(Constants.ENTITY_TYPE).equalsIgnoreCase
          (Constants.TEZ_TASK_ID));

  taskId = StringInterner.weakIntern(jsonObject.optString(Constants.ENTITY));

  //Parse additional Info
  final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO);

  long sTime = otherInfoNode.optLong(Constants.START_TIME);
  long eTime = otherInfoNode.optLong(Constants.FINISH_TIME);
  if (eTime < sTime) {
    LOG.warn("Task has got wrong start/end values. "
        + "startTime=" + sTime + ", endTime=" + eTime + ". Will check "
        + "timestamps in DAG started/finished events");

    // Check if events TASK_STARTED, TASK_FINISHED can be made use of
    for(Event event : eventList) {
      switch (HistoryEventType.valueOf(event.getType())) {
      case TASK_STARTED:
        sTime = event.getAbsoluteTime();
        break;
      case TASK_FINISHED:
        eTime = event.getAbsoluteTime();
        break;
      default:
        break;
      }
    }

    if (eTime < sTime) {
      LOG.warn("Task has got wrong start/end values in events as well. "
          + "startTime=" + sTime + ", endTime=" + eTime);
    }
  }
  startTime = sTime;
  endTime = eTime;

  diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS);
  successfulAttemptId = StringInterner.weakIntern(
      otherInfoNode.optString(Constants.SUCCESSFUL_ATTEMPT_ID));
  scheduledTime = otherInfoNode.optLong(Constants.SCHEDULED_TIME);
  status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS));
}
 
Example 9
Source File: VertexInfo.java    From tez with Apache License 2.0 4 votes vote down vote up
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));
}