示例#1
0
  /**
   * Create the JVM information
   *
   * @return
   */
  private JsonValue getJVMInformation() {
    JsonObject report = JsonValueBuilder.jsonValue();

    // Arguments
    List<String> arguments = runtimeMxBean.getInputArguments();
    JsonArray argumentsJson = report.array(JVM_ARGUMENTS_LABEL);
    for (String argument : arguments) {
      argumentsJson.add(argument);
    }

    // some useful jvm properties
    JsonObject propertiesJson = JsonValueBuilder.jsonValue();

    propertiesJson.put("java.vm.info", System.getProperty("java.vm.info"));
    propertiesJson.put("java.vm.name", System.getProperty("java.vm.info"));
    propertiesJson.put(
        "java.vm.specification.name", System.getProperty("java.vm.specification.name"));
    propertiesJson.put(
        "java.vm.specification.vendor", System.getProperty("java.vm.specification.vendor"));
    propertiesJson.put(
        "java.vm.specification.version", System.getProperty("java.vm.specification.version"));
    propertiesJson.put("java.vm.vendor", System.getProperty("java.vm.vendor"));
    propertiesJson.put("java.vm.version", System.getProperty("java.vm.version"));

    report.put(JVM_PROPERTIES_LABEL, propertiesJson.build().asMap());

    report.put(JVM_JAVA_VERSION_LABEL, System.getProperty("java.version"));

    // Memory
    JsonObject memoryJson = JsonValueBuilder.jsonValue();
    memoryJson.put(JVM_UNIT_MEMORY_LABEL, FileSizeUnit.MB);

    // Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    // Print used memory
    memoryJson.put(
        JVM_USED_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory() - runtime.freeMemory()));

    // Print free memory
    memoryJson.put(JVM_FREE_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.freeMemory()));

    // Print total available memory
    memoryJson.put(JVM_TOTAL_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory()));

    // Print Maximum available memory
    memoryJson.put(JVM_MAX_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.maxMemory()));

    // GNU systems don't support the "sun.arch.data.model" property, so we print both
    memoryJson.put(JVM_BIT_SIZE_GNU_LABEL, System.getProperty("sun.arch.data.model"));
    memoryJson.put(JVM_BIT_SIZE_LABEL, System.getProperty("os.arch"));

    report.put(JVM_MEMORY_LABEL, memoryJson.build().asMap());

    return report.build();
  }
示例#2
0
 /**
  * Get the system properties
  *
  * @return
  */
 private JsonValue getSystemProperties() {
   JsonObject report = JsonValueBuilder.jsonValue();
   Properties sysProps = System.getProperties();
   for (String propertyName : sysProps.stringPropertyNames()) {
     report.put(propertyName, sysProps.getProperty(propertyName));
   }
   return report.build();
 }
 private JsonValue readJsonFile(String path) throws AuditException {
   try {
     InputStream is = AuditServiceProviderImpl.class.getResourceAsStream(path);
     String contents = IOUtils.readStream(is);
     return JsonValueBuilder.toJsonValue(contents.replaceAll("\\s", ""));
   } catch (IOException e) {
     debug.error("Unable to read configuration file {}", path, e);
     throw new AuditException("Unable to read configuration file " + path, e);
   }
 }
示例#4
0
  /**
   * Create the infoReport
   *
   * @param record
   * @return
   */
  public JsonValue infoReport(Record record) {
    JsonObject report = JsonValueBuilder.jsonValue();

    report.put(GLOBAL_INFO_LABEL, globalInformationReport(record).asMap());
    report.put(RECORD_LABEL, RecordProperties.toJson(record.getRecordProperties()).asMap());
    report.put(JVM_LABEL, getJVMInformation().asMap());
    report.put(SYSTEM_PROPERTIES_LABEL, getSystemProperties().asMap());

    return report.build();
  }
示例#5
0
  /** Create the global information report * @return */
  private JsonValue globalInformationReport(Record record) {

    JsonObject report = JsonValueBuilder.jsonValue();
    synchronized (dateFormat) {
      report.put(DATE_LABEL, dateFormat.format(new Date()));
    }
    report.put(OPENAM_VERSION_LABEL, SystemPropertiesManager.get(Constants.AM_VERSION));

    // OpenAM properties contain a part of the OpenAM configuration, we need to have the config
    // export enable
    if (record.getRecordProperties().isConfigExportEnabled()) {
      JsonObject openAMPropertiesJson = JsonValueBuilder.jsonValue();
      Properties sysProps = SystemProperties.getProperties();
      for (String propertyName : sysProps.stringPropertyNames()) {
        report.put(propertyName, sysProps.getProperty(propertyName));
      }
      report.put(OPENAM_PROPERTIES_LABEL, openAMPropertiesJson.build().asMap());
    }

    return report.build();
  }
  /**
   * Creates a JSON field for a callback.
   *
   * @param name The name of the field.
   * @param values The array value of the field.
   * @return The JSON field object.
   */
  final JsonValue createJsonField(String name, Object[] values) {
    JsonArray jsonArray =
        JsonValueBuilder.jsonValue().put("name", name == null ? "" : name).array("value");

    if (values != null) {
      for (Object value : values) {
        jsonArray.add(value);
      }
    }
    JsonObject jsonObject = jsonArray.build();

    return jsonObject.build();
  }
  private Map<String, Object> toMap(JsonRepresentation entity) throws BadRequestException {
    if (entity == null) {
      return Collections.emptyMap();
    }

    try {
      final String jsonString = entity.getJsonObject().toString();
      if (StringUtils.isNotEmpty(jsonString)) {
        JsonValue jsonContent = JsonValueBuilder.toJsonValue(jsonString);
        return jsonContent.asMap(Object.class);
      }

      return Collections.emptyMap();
    } catch (JSONException e) {
      throw new BadRequestException(e.getMessage());
    }
  }
  /** {@inheritDoc} */
  public JsonValue convertToJson(ConfirmationCallback callback, int index) {

    String prompt = callback.getPrompt();
    int messageType = callback.getMessageType();
    String[] options = callback.getOptions();
    int optionType = callback.getOptionType();
    int defaultOption = callback.getDefaultOption();
    int selectedIndex = callback.getSelectedIndex();

    JsonValue jsonValue =
        JsonValueBuilder.jsonValue()
            .put("type", CALLBACK_NAME)
            .array("output")
            .add(createOutputField("prompt", prompt))
            .add(createOutputField("messageType", messageType))
            .add(createOutputField("options", options))
            .add(createOutputField("optionType", optionType))
            .addLast(createOutputField("defaultOption", defaultOption))
            .array("input")
            .addLast(createInputField(index, selectedIndex))
            .build();

    return jsonValue;
  }
 /**
  * Creates a JSON field for a callback.
  *
  * @param name The name of the field.
  * @param value The value of the field.
  * @return The JSON field object.
  */
 final JsonValue createJsonField(String name, Object value) {
   return JsonValueBuilder.jsonValue()
       .put("name", name == null ? "" : name)
       .put("value", value == null ? "" : value)
       .build();
 }