Java Code Examples for org.codehaus.jettison.json.JSONArray#put()

The following examples show how to use org.codehaus.jettison.json.JSONArray#put() . 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: ConvertSprintBacklog.java    From ezScrum with GNU General Public License v2.0 7 votes vote down vote up
public static String getSprintJSONString(SprintObject sprint) throws JSONException {
	JSONObject sprintJson = new JSONObject();
	sprintJson.put(SprintPlanUtil.TAG_ID, sprint.getId());
	sprintJson.put(SprintPlanUtil.TAG_SPRINT_GOAL, sprint.getGoal());
	sprintJson.put(SprintPlanUtil.TAG_START_DATE, sprint.getStartDateString());
	sprintJson.put(SprintPlanUtil.TAG_DEMO_DATE, sprint.getDemoDateString());
	sprintJson.put(SprintPlanUtil.TAG_DUE_DATE, sprint.getDueDateString());
	sprintJson.put(SprintPlanUtil.TAG_INTERVAL, sprint.getInterval());
	sprintJson.put(SprintPlanUtil.TAG_MEMBERS, sprint.getTeamSize());
	sprintJson.put(SprintPlanUtil.TAG_HOURS_CAN_COMMIT, sprint.getAvailableHours());
	sprintJson.put(SprintPlanUtil.TAG_DAILY_MEETING, sprint.getDailyInfo());
	sprintJson.put(SprintPlanUtil.TAG_DEMO_PLACE, sprint.getDemoPlace());
	
	JSONArray storiesJsonArray = new JSONArray();
	for(StoryObject story : sprint.getStories()){
		storiesJsonArray.put(story.toJSON());
	}
	
	sprintJson.put("stories", storiesJsonArray);
	return sprintJson.toString();
}
 
Example 2
Source File: HistoryEventProtoJsonConversion.java    From tez with Apache License 2.0 6 votes vote down vote up
private static JSONObject convertDAGRecoveredEvent(HistoryEventProto event) throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getDagId());
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_DAG_ID.name());

  // Related Entities not needed as should have been done in
  // dag submission event

  JSONArray events = new JSONArray();
  JSONObject recoverEvent = new JSONObject();
  recoverEvent.put(ATSConstants.TIMESTAMP, event.getEventTime());
  recoverEvent.put(ATSConstants.EVENT_TYPE, HistoryEventType.DAG_RECOVERED.name());

  JSONObject recoverEventInfo = new JSONObject();
  recoverEventInfo.put(ATSConstants.APPLICATION_ATTEMPT_ID, event.getAppAttemptId().toString());
  recoverEventInfo.put(ATSConstants.DAG_STATE, getDataValueByKey(event, ATSConstants.DAG_STATE));
  recoverEventInfo.put(ATSConstants.RECOVERY_FAILURE_REASON,
      getDataValueByKey(event, ATSConstants.RECOVERY_FAILURE_REASON));

  recoverEvent.put(ATSConstants.EVENT_INFO, recoverEventInfo);
  events.put(recoverEvent);

  jsonObject.put(ATSConstants.EVENTS, events);

  return jsonObject;
}
 
Example 3
Source File: ConvertSprint.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
public static String convertSprintsToJsonString(
		ArrayList<SprintObject> sprints) throws JSONException {
	JSONArray jsonSprints = new JSONArray();
	for (SprintObject sprint : sprints) {
		JSONObject jsonSprint = new JSONObject();
		jsonSprint.put(SprintUtil.TAG_ID, sprint.getId())
				.put(SprintUtil.TAG_PROJECT_ID, sprint.getProjectId())
				.put(SprintUtil.TAG_START_DATE, sprint.getStartDateString())
				.put(SprintUtil.TAG_INTERVAL, sprint.getInterval())
				.put(SprintUtil.TAG_TEAM_SIZE, sprint.getTeamSize())
				.put(SprintUtil.TAG_SERIAL_ID, sprint.getSerialId())
				.put(SprintUtil.TAG_SPRINT_GOAL, sprint.getGoal())
				.put(SprintUtil.TAG_HOURS_CAN_COMMIT, sprint.getAvailableHours())
				.put(SprintUtil.TAG_FOCUS_FACTOR, sprint.getFocusFactor())
				.put(SprintUtil.TAG_DEMO_DATE, sprint.getDemoDateString())
				.put(SprintUtil.TAG_DEMO_PLACE, sprint.getDemoPlace())
				.put(SprintUtil.TAG_DAILY_MEETING, sprint.getDailyInfo());
		jsonSprints.put(jsonSprint);
	}
	return jsonSprints.toString();
}
 
Example 4
Source File: JsonHelper.java    From OSTMap with Apache License 2.0 6 votes vote down vote up
public static String generateCoordinates(String json) {
    try {
        JSONObject obj = new JSONObject(json);
        Double[] longLat = Extractor.extractLocation(obj);

        if (obj.has(KEY_COORDINATES) && obj.isNull(KEY_COORDINATES)) {
            //coordinates is empty
            JSONArray longLatArr = new JSONArray();
            if (longLat != null && longLat[0] != null && longLat[1] != null) {
                longLatArr.put(longLat[0]);
                longLatArr.put(longLat[1]);
                JSONObject coordinates1 = new JSONObject().put(KEY_COORDINATES, longLatArr);
                obj.put(KEY_COORDINATES, coordinates1);
            }
        }
        if (obj.has(KEY_PLACE)) {
            //ccordinates is set, remove place
            obj.remove(KEY_PLACE);
        }
        return obj.toString();
    } catch (JSONException e) {
        log.error("no correct JSON string:" + json);

        return null;
    }
}
 
Example 5
Source File: DataResultSnapshotSerializer.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
private String serializeHelper(Message result, ResultFormatter resultFormatter) throws Exception
{
  DataResultSnapshot gResult = (DataResultSnapshot)result;

  JSONObject jo = new JSONObject();
  jo.put(Result.FIELD_ID, gResult.getId());
  jo.put(Result.FIELD_TYPE, gResult.getType());

  JSONArray ja = new JSONArray();

  for (GPOMutable value : gResult.getValues()) {
    JSONObject dataValue = GPOUtils.serializeJSONObject(value, ((DataQuerySnapshot)gResult.getQuery()).getFields(),
        resultFormatter);
    ja.put(dataValue);
  }

  jo.put(DataResultSnapshot.FIELD_DATA, ja);

  if (!gResult.isOneTime()) {
    jo.put(Result.FIELD_COUNTDOWN, gResult.getCountdown());
  }

  return jo.toString();
}
 
Example 6
Source File: HistoryEventProtoJsonConversion.java    From tez with Apache License 2.0 6 votes vote down vote up
private static JSONObject convertDAGInitializedEvent(HistoryEventProto event)
    throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getDagId());
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_DAG_ID.name());

  // Related Entities not needed as should have been done in
  // dag submission event

  JSONArray events = new JSONArray();
  JSONObject initEvent = new JSONObject();
  initEvent.put(ATSConstants.TIMESTAMP, event.getEventTime());
  initEvent.put(ATSConstants.EVENT_TYPE, HistoryEventType.DAG_INITIALIZED.name());
  events.put(initEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  JSONObject otherInfo = new JSONObject();
  otherInfo.put(ATSConstants.VERTEX_NAME_ID_MAPPING,
      getJSONDataValueByKey(event, ATSConstants.VERTEX_NAME_ID_MAPPING));
  jsonObject.put(ATSConstants.OTHER_INFO, otherInfo);

  return jsonObject;
}
 
Example 7
Source File: ApexCli.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  JSONObject result = new JSONObject();
  JSONArray appArray = new JSONArray();
  List<ApplicationReport> apps = StramClientUtils.cleanAppDirectories(yarnClient, conf, fs,
      System.currentTimeMillis() - Long.valueOf(args[1]));
  for (ApplicationReport app : apps) {
    appArray.put(app.getApplicationId().toString());
  }
  result.put("applications", appArray);
  printJson(result);
}
 
Example 8
Source File: ConvertSprintBacklog.java    From ezScrum with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 轉換 task id list 的 json string
 * 
 * @param storyId
 * @param tasks
 * @return
 * @throws JSONException
 */
public static String getTasksIdJsonStringInStory(long storyId, ArrayList<TaskObject> tasks) throws JSONException {
	JSONObject story = new JSONObject();
	JSONObject storyProperties = new JSONObject();
	JSONArray tasksId = new JSONArray();
	for (TaskObject task : tasks) {
		tasksId.put(task.getId());
	}
	storyProperties.put(SprintBacklogUtil.TAG_ID, storyId);
	storyProperties.put(SprintBacklogUtil.TAG_TASKSIDL, tasksId);

	story.put(SprintBacklogUtil.TAG_STORY, storyProperties);
	return story.toString();
}
 
Example 9
Source File: ConvertSprintBacklog.java    From ezScrum with GNU General Public License v2.0 5 votes vote down vote up
public static String getStoriesIdJsonStringInSprint(ArrayList<StoryObject> stories) throws JSONException {
	JSONObject storiesIdJsonString = new JSONObject();
	JSONArray storyArray = new JSONArray();
	for (StoryObject story : stories) {
		JSONObject stroyJson = new JSONObject();
		stroyJson.put("id", story.getId());
		stroyJson.put("point", story.getEstimate());
		stroyJson.put("status", story.getStatusString());
		storyArray.put(stroyJson);
	}
	storiesIdJsonString.put(SprintPlanUtil.TAG_STORIES, storyArray);
	return storiesIdJsonString.toString();
}
 
Example 10
Source File: AtlasHook.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected void notifyEntities(String user, Collection<Referenceable> entities) {
    JSONArray entitiesArray = new JSONArray();

    for (Referenceable entity : entities) {
        LOG.info("Adding entity for type: {}", entity.getTypeName());
        final String entityJson = InstanceSerialization.toJson(entity, true);
        entitiesArray.put(entityJson);
    }

    List<HookNotification.HookNotificationMessage> hookNotificationMessages = new ArrayList<>();
    hookNotificationMessages.add(new HookNotification.EntityCreateRequest(user, entitiesArray));
    notifyEntities(hookNotificationMessages);
}
 
Example 11
Source File: HistoryEventJsonConversion.java    From tez with Apache License 2.0 5 votes vote down vote up
private static JSONObject convertDAGRecoveredEvent(DAGRecoveredEvent event)
    throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY,
      event.getDagID().toString());
  jsonObject.put(ATSConstants.ENTITY_TYPE,
      EntityTypes.TEZ_DAG_ID.name());

  // Related Entities not needed as should have been done in
  // dag submission event

  JSONArray events = new JSONArray();
  JSONObject recoverEvent = new JSONObject();
  recoverEvent.put(ATSConstants.TIMESTAMP, event.getRecoveredTime());
  recoverEvent.put(ATSConstants.EVENT_TYPE,
      HistoryEventType.DAG_RECOVERED.name());

  JSONObject recoverEventInfo = new JSONObject();
  recoverEventInfo.put(ATSConstants.APPLICATION_ATTEMPT_ID,
      event.getApplicationAttemptId().toString());
  if (event.getRecoveredDagState() != null) {
    recoverEventInfo.put(ATSConstants.DAG_STATE, event.getRecoveredDagState().name());
  }
  if (event.getRecoveryFailureReason() != null) {
    recoverEventInfo.put(ATSConstants.RECOVERY_FAILURE_REASON,
        event.getRecoveryFailureReason());
  }

  recoverEvent.put(ATSConstants.EVENT_INFO, recoverEventInfo);
  events.put(recoverEvent);

  jsonObject.put(ATSConstants.EVENTS, events);

  return jsonObject;
}
 
Example 12
Source File: HistoryEventProtoJsonConversion.java    From tez with Apache License 2.0 5 votes vote down vote up
private static JSONObject convertContainerLaunchedEvent(HistoryEventProto event)
    throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY,
      "tez_" + getDataValueByKey(event, ATSConstants.CONTAINER_ID));
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_CONTAINER_ID.name());

  JSONArray relatedEntities = new JSONArray();
  JSONObject appAttemptEntity = new JSONObject();
  appAttemptEntity.put(ATSConstants.ENTITY, event.getAppAttemptId().toString());
  appAttemptEntity.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_APPLICATION_ATTEMPT.name());

  JSONObject containerEntity = new JSONObject();
  containerEntity.put(ATSConstants.ENTITY, getDataValueByKey(event, ATSConstants.CONTAINER_ID));
  containerEntity.put(ATSConstants.ENTITY_TYPE, ATSConstants.CONTAINER_ID);

  relatedEntities.put(appAttemptEntity);
  relatedEntities.put(containerEntity);
  jsonObject.put(ATSConstants.RELATED_ENTITIES, relatedEntities);

  // TODO decide whether this goes into different events,
  // event info or other info.
  JSONArray events = new JSONArray();
  JSONObject launchEvent = new JSONObject();
  launchEvent.put(ATSConstants.TIMESTAMP, event.getEventTime());
  launchEvent.put(ATSConstants.EVENT_TYPE, HistoryEventType.CONTAINER_LAUNCHED.name());
  events.put(launchEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  // TODO add other container info here? or assume AHS will have this?
  // TODO container logs?

  return jsonObject;
}
 
Example 13
Source File: TypeDiscoverer.java    From Bats with Apache License 2.0 5 votes vote down vote up
private JSONArray getTypes(Type[] types)
{
  JSONArray jsontypes = new JSONArray();
  for (Type upperBound : types) {
    String s = upperBound.toString();
    Type type = this.typeArguments.get(s);
    if (type == null) {
      type = upperBound;
    }
    jsontypes.put(type.toString());
  }
  return jsontypes;
}
 
Example 14
Source File: HistoryEventJsonConversion.java    From tez with Apache License 2.0 5 votes vote down vote up
private static JSONObject convertVertexReconfigureDoneEvent(VertexConfigurationDoneEvent event) throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getVertexID().toString());
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_VERTEX_ID.name());

  // Events
  JSONArray events = new JSONArray();
  JSONObject updateEvent = new JSONObject();
  updateEvent.put(ATSConstants.TIMESTAMP, event.getReconfigureDoneTime());
  updateEvent.put(ATSConstants.EVENT_TYPE,
      HistoryEventType.VERTEX_CONFIGURE_DONE.name());

  JSONObject eventInfo = new JSONObject();
  eventInfo.put(ATSConstants.NUM_TASKS, event.getNumTasks());
  if (event.getSourceEdgeProperties() != null && !event.getSourceEdgeProperties().isEmpty()) {
    JSONObject updatedEdgeManagers = new JSONObject();
    for (Entry<String, EdgeProperty> entry :
        event.getSourceEdgeProperties().entrySet()) {
      updatedEdgeManagers.put(entry.getKey(),
          new JSONObject(DAGUtils.convertEdgeProperty(entry.getValue())));
    }
    eventInfo.put(ATSConstants.UPDATED_EDGE_MANAGERS, updatedEdgeManagers);
  }
  updateEvent.put(ATSConstants.EVENT_INFO, eventInfo);
  events.put(updateEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  // Other info
  JSONObject otherInfo = new JSONObject();
  jsonObject.put(ATSConstants.OTHER_INFO, otherInfo);

  // TODO add more on all other updated information
  return jsonObject;
}
 
Example 15
Source File: HistoryEventProtoJsonConversion.java    From tez with Apache License 2.0 5 votes vote down vote up
private static JSONObject convertVertexFinishedEvent(HistoryEventProto event)
    throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getVertexId());
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_VERTEX_ID.name());

  // Events
  JSONArray events = new JSONArray();
  JSONObject finishEvent = new JSONObject();
  finishEvent.put(ATSConstants.TIMESTAMP, event.getEventTime());
  finishEvent.put(ATSConstants.EVENT_TYPE, HistoryEventType.VERTEX_FINISHED.name());
  events.put(finishEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  long startTime = getLongDataValueByKey(event, ATSConstants.START_TIME);

  JSONObject otherInfo = new JSONObject();
  otherInfo.put(ATSConstants.FINISH_TIME, event.getEventTime());
  otherInfo.put(ATSConstants.TIME_TAKEN, (event.getEventTime() - startTime));
  otherInfo.put(ATSConstants.STATUS, getDataValueByKey(event, ATSConstants.STATUS));
  otherInfo.put(ATSConstants.DIAGNOSTICS, getDataValueByKey(event, ATSConstants.DIAGNOSTICS));
  otherInfo.put(ATSConstants.COUNTERS, getJSONDataValueByKey(event, ATSConstants.COUNTERS));

  otherInfo.put(ATSConstants.STATS, getJSONDataValueByKey(event, ATSConstants.STATS));

  // added all info to otherInfo in order to cover
  // all key/value pairs added from event.getVertexTaskStats()
  Iterator<KVPair> it = event.getEventDataList().iterator();
  while (it.hasNext()) {
    KVPair pair = it.next();
    otherInfo.put(pair.getKey(), pair.getValue());
  }

  otherInfo.put(ATSConstants.SERVICE_PLUGIN,
      getJSONDataValueByKey(event, ATSConstants.SERVICE_PLUGIN));

  jsonObject.put(ATSConstants.OTHER_INFO, otherInfo);

  return jsonObject;
}
 
Example 16
Source File: HistoryEventJsonConversion.java    From tez with Apache License 2.0 4 votes vote down vote up
private static JSONObject convertTaskAttemptFinishedEvent(TaskAttemptFinishedEvent event) throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getTaskAttemptID().toString());
  jsonObject.put(ATSConstants.ENTITY_TYPE,
      EntityTypes.TEZ_TASK_ATTEMPT_ID.name());

  // Events
  JSONArray events = new JSONArray();
  JSONObject finishEvent = new JSONObject();
  finishEvent.put(ATSConstants.TIMESTAMP, event.getFinishTime());
  finishEvent.put(ATSConstants.EVENT_TYPE,
      HistoryEventType.TASK_ATTEMPT_FINISHED.name());
  events.put(finishEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  JSONObject otherInfo = new JSONObject();
  otherInfo.put(ATSConstants.CREATION_TIME, event.getCreationTime());
  otherInfo.put(ATSConstants.ALLOCATION_TIME, event.getAllocationTime());
  otherInfo.put(ATSConstants.START_TIME, event.getStartTime());
  otherInfo.put(ATSConstants.FINISH_TIME, event.getFinishTime());
  otherInfo.put(ATSConstants.TIME_TAKEN, (event.getFinishTime() - event.getStartTime()));
  if (event.getCreationCausalTA() != null) {
    otherInfo.put(ATSConstants.CREATION_CAUSAL_ATTEMPT, event.getCreationCausalTA().toString());
  }
  otherInfo.put(ATSConstants.STATUS, event.getState().name());
  if (event.getTaskAttemptError() != null) {
    otherInfo.put(ATSConstants.TASK_ATTEMPT_ERROR_ENUM, event.getTaskAttemptError().name());
  }
  if (event.getTaskFailureType() != null) {
    otherInfo.put(ATSConstants.TASK_FAILURE_TYPE, event.getTaskFailureType().name());
  }
  otherInfo.put(ATSConstants.DIAGNOSTICS, event.getDiagnostics());
  otherInfo.put(ATSConstants.COUNTERS,
      DAGUtils.convertCountersToJSON(event.getCounters()));
  if (event.getDataEvents() != null && !event.getDataEvents().isEmpty()) {
    otherInfo.put(ATSConstants.LAST_DATA_EVENTS, 
        DAGUtils.convertDataEventDependencyInfoToJSON(event.getDataEvents()));
  }
  if (event.getNodeId() != null) {
    otherInfo.put(ATSConstants.NODE_ID, event.getNodeId().toString());
  }
  if (event.getContainerId() != null) {
    otherInfo.put(ATSConstants.CONTAINER_ID, event.getContainerId().toString());
  }
  if (event.getInProgressLogsUrl() != null) {
    otherInfo.put(ATSConstants.IN_PROGRESS_LOGS_URL, event.getInProgressLogsUrl());
  }
  if (event.getCompletedLogsUrl() != null) {
    otherInfo.put(ATSConstants.COMPLETED_LOGS_URL, event.getCompletedLogsUrl());
  }
  if (event.getNodeHttpAddress() != null) {
    otherInfo.put(ATSConstants.NODE_HTTP_ADDRESS, event.getNodeHttpAddress());
  }

  jsonObject.put(ATSConstants.OTHER_INFO, otherInfo);

  return jsonObject;
}
 
Example 17
Source File: HistoryEventProtoJsonConversion.java    From tez with Apache License 2.0 4 votes vote down vote up
private static JSONObject convertTaskAttemptStartedEvent(HistoryEventProto event)
    throws JSONException {
  JSONObject jsonObject = new JSONObject();
  jsonObject.put(ATSConstants.ENTITY, event.getTaskAttemptId());
  jsonObject.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_TASK_ATTEMPT_ID.name());

  // Related entities
  JSONArray relatedEntities = new JSONArray();
  JSONObject nodeEntity = new JSONObject();
  nodeEntity.put(ATSConstants.ENTITY, getDataValueByKey(event, ATSConstants.NODE_ID));
  nodeEntity.put(ATSConstants.ENTITY_TYPE, ATSConstants.NODE_ID);

  JSONObject containerEntity = new JSONObject();
  containerEntity.put(ATSConstants.ENTITY, getDataValueByKey(event, ATSConstants.CONTAINER_ID));
  containerEntity.put(ATSConstants.ENTITY_TYPE, ATSConstants.CONTAINER_ID);

  JSONObject taskEntity = new JSONObject();
  taskEntity.put(ATSConstants.ENTITY, event.getTaskAttemptId());
  taskEntity.put(ATSConstants.ENTITY_TYPE, EntityTypes.TEZ_TASK_ID.name());

  relatedEntities.put(nodeEntity);
  relatedEntities.put(containerEntity);
  relatedEntities.put(taskEntity);
  jsonObject.put(ATSConstants.RELATED_ENTITIES, relatedEntities);

  // Events
  JSONArray events = new JSONArray();
  JSONObject startEvent = new JSONObject();
  startEvent.put(ATSConstants.TIMESTAMP, event.getEventTime());
  startEvent.put(ATSConstants.EVENT_TYPE, HistoryEventType.TASK_ATTEMPT_STARTED.name());
  events.put(startEvent);
  jsonObject.put(ATSConstants.EVENTS, events);

  // Other info
  JSONObject otherInfo = new JSONObject();
  otherInfo.put(ATSConstants.IN_PROGRESS_LOGS_URL,
      getDataValueByKey(event, ATSConstants.IN_PROGRESS_LOGS_URL));
  otherInfo.put(ATSConstants.COMPLETED_LOGS_URL,
      getDataValueByKey(event, ATSConstants.COMPLETED_LOGS_URL));
  jsonObject.put(ATSConstants.OTHER_INFO, otherInfo);

  return jsonObject;
}
 
Example 18
Source File: StramUtils.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public static JSONObject getStackTrace()
{
  Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();

  JSONObject jsonObject = new JSONObject();
  JSONArray jsonArray = new JSONArray();

  for (Map.Entry<Thread, StackTraceElement[]> elements : stackTraces.entrySet()) {

    JSONObject jsonThread = new JSONObject();

    Thread thread = elements.getKey();

    try {

      jsonThread.put("name", thread.getName());
      jsonThread.put("state", thread.getState());
      jsonThread.put("id", thread.getId());

      JSONArray stackTraceElements = new JSONArray();

      for (StackTraceElement stackTraceElement : elements.getValue()) {

        stackTraceElements.put(stackTraceElement.toString());
      }

      jsonThread.put("stackTraceElements", stackTraceElements);

      jsonArray.put(jsonThread);
    } catch (Exception ex) {
      LOG.warn("Getting stack trace for the thread " + thread.getName() + " failed.");
      continue;
    }
  }

  try {
    jsonObject.put("threads", jsonArray);
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }

  return jsonObject;
}
 
Example 19
Source File: JMXResource.java    From karyon with Apache License 2.0 4 votes vote down vote up
/**
 * Return all the attributes and operations for a single mbean
 *
 * @param key
 *            Exact object name of MBean in String form
 * @param jsonp
 */
@GET
@Path("{key}")
public Response getMBean(@PathParam("key") String key,
                         @QueryParam("jsonp") @DefaultValue("") String jsonp)
        throws Exception {
    LOG.info("key: " + key);

    JSONObject json = new JSONObject();

    ObjectName name = new ObjectName(key);
    json.put("domain", name.getDomain());
    json.put("property", name.getKeyPropertyList());

    if (key.contains("*")) {
        JSONObject keys = new JSONObject();
        for (Entry<String, Map<String, String>> attrs : jmx
                .getMBeanAttributesByRegex(key).entrySet()) {
            keys.put(attrs.getKey(), attrs.getValue());
        }
        json.put("attributes", keys);
        json.put("multikey", true);
    } else {
        json.put("attributes", jmx.getMBeanAttributes(key));
        json.put("multikey", false);

        MBeanOperationInfo[] operations = jmx.getMBeanOperations(key);
        JSONArray ar = new JSONArray();
        for (MBeanOperationInfo operation : operations) {
            JSONObject obj = new JSONObject();
            obj.put("name", operation.getName());
            obj.put("description", operation.getDescription());
            obj.put("returnType", operation.getReturnType());
            obj.put("impact", operation.getImpact());

            JSONArray params = new JSONArray();
            for (MBeanParameterInfo param : operation.getSignature()) {
                JSONObject p = new JSONObject();
                p.put("name", param.getName());
                p.put("type", param.getType());
                params.put(p);
            }
            obj.put("params", params);
            ar.put(obj);
        }
        json.put("operations", ar);
    }

    StringWriter out = new StringWriter();
    if (jsonp.isEmpty()) {
        json.write(out);
    } else {
        out.append(jsonp).append("(");
        json.write(out);
        out.append(");");
    }
    return Response.ok(out.toString()).type(MediaType.APPLICATION_JSON)
            .build();
}
 
Example 20
Source File: ProductBacklogHelperTest.java    From ezScrum with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testGetRemoveStoryTagResponseText() throws JSONException {
	// create 1 story
	mCPB = new CreateProductBacklog(1, mCP);
	mCPB.exe();
	// Test Tag Name
	String TEST_TAG_NAME = "TEST_TAG_NAME";
	// Create Tag
	TagObject newTag = new TagObject(TEST_TAG_NAME, mCP.getAllProjects()
			.get(0).getId());
	newTag.save();
	// Get Story
	StoryObject story = mCPB.getStories().get(0);

	// assemble test json data
	JSONObject expectResponse = new JSONObject();
	expectResponse.put("success", true);
	expectResponse.put("Total", 1);

	JSONArray jsonStroies = new JSONArray();

	JSONObject jsonStory = new JSONObject();
	jsonStory.put("Id", story.getId());
	jsonStory.put("Type", "Story");
	jsonStory.put("Name", story.getName());
	jsonStory.put("Value", story.getValue());
	jsonStory.put("Estimate", story.getEstimate());
	jsonStory.put("Importance", story.getImportance());
	jsonStory.put("Tag", "");
	jsonStory.put("Status", story.getStatusString());
	jsonStory.put("Notes", story.getNotes());
	jsonStory.put("HowToDemo", story.getHowToDemo());
	jsonStory.put("Link", "");
	jsonStory.put("Release", "");
	jsonStory.put("Sprint", story.getSprintId() == StoryObject.NO_PARENT ? "None" : story.getSprintId());
	jsonStory.put("FilterType", "DETAIL");
	jsonStory.put("Attach", false);

	JSONArray jsonFiles = new JSONArray();
	jsonStory.put("AttachFileList", jsonFiles);
	jsonStroies.put(jsonStory);

	expectResponse.put("Stories", jsonStroies);

	// getAddStoryTagResponseText
	StringBuilder actualResponse = mProductBacklogHelper1.getRemoveStoryTagResponseText(story.getId(), newTag.getId());
	// assert
	assertEquals(expectResponse.toString(), actualResponse.toString());
}