Пример #1
0
  /**
   * get service parameters of this particular service and convert them into JSON object
   *
   * @param service
   * @return
   */
  public static JSONObject serviceParametersAsJson(PsService service) {
    JSONObject serviceParameters = new JSONObject();

    Iterator iter = service.getParameters().keySet().iterator();
    while (iter.hasNext()) {
      String key = (String) iter.next();

      Object value = service.getParameters().get(key);

      // check if parameter name indicates that it is an object id
      if (thisIsObjectId(key)) {
        serviceParameters.put(key, value + "");
      } else {
        serviceParameters.put(key, value);
      }
    }
    return serviceParameters;
  }
Пример #2
0
  /**
   * Convert perfsonar service to Json object according to specified detail level
   *
   * @param service
   * @return
   */
  public static JSONObject toJson(PsService service, String detailLevel) {

    JSONObject json = new JSONObject();

    if (service != null) {

      json.put(PsService.ID, int2String(service.getId()));
      json.put(PsService.NAME, service.getName());

      if (!PsApi.DETAIL_LEVEL_LOW.equals(detailLevel)) {

        json.put(PsService.TYPE, service.getType());
        json.put(PsService.DESCRIPTION, service.getDescription());

        // add service parameters

        if (service.getParameters() != null) {
          JSONObject serviceParameters = serviceParametersAsJson(service);
          json.put(PsService.PARAMETERS, serviceParameters);
        }

        json.put(PsService.CHECK_INTERVAL, new Integer(service.getCheckInterval()));
        json.put(PsService.RUNNING, service.isRunning());
        json.put(
            PsService.PREV_CHECK_TIME, IsoDateConverter.dateToString(service.getPrevCheckTime()));
        json.put(
            PsService.NEXT_CHECK_TIME, IsoDateConverter.dateToString(service.getNextCheckTime()));
        json.put(PsService.RUNNING_SINCE, IsoDateConverter.dateToString(service.getRunningSince()));
        json.put(PsService.TIMEOUT, service.getTimeout());

        // add result
        PsRecentServiceResult result = service.getResult();
        JSONObject jsonResult = toJson(result);
        json.put(PsService.RESULT, jsonResult);
      }
    }

    return json;
  }