Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Adding the Json Parser Object as the Class Member Variable (#503)
Browse files Browse the repository at this point in the history
Adding the Json Parser Object as the Class Member Variable
  • Loading branch information
adityaj1107 committed Nov 15, 2020
1 parent 4442171 commit d217727
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public static class SQL_SCHEMA_CONSTANTS {

}

public JsonElement toJson() {
public JsonElement toJson(JsonParser jsonParser) {
JsonObject summaryObj = new JsonObject();
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.NODE_IPS_NAME, this.nodeIps);
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.MUTED_NAME, this.muted);
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.ACTION_COL_NAME, this.actionName);
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.TIMESTAMP_COL_NAME, this.timestamp);
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.NODE_IDS_NAME, this.nodeIds);
summaryObj.add(SQL_SCHEMA_CONSTANTS.SUMMARY_NAME, new JsonParser().parse(this.summary));
summaryObj.add(SQL_SCHEMA_CONSTANTS.SUMMARY_NAME, jsonParser.parse(this.summary));
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.ACTIONABLE_NAME, this.actionable);
summaryObj.addProperty(SQL_SCHEMA_CONSTANTS.COOLOFFPERIOD_NAME, this.coolOffPeriod);
return summaryObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

/**
* Request Handler that supports querying the latest action set
*TODO: Update with actual Action Values here and in the README.
*
* <p>To get the response for the latest action set suggested via DM Framework
* curl --url "localhost:9600/_opendistro/_performanceanalyzer/actions" -XGET
Expand Down Expand Up @@ -75,9 +74,11 @@ public class QueryActionRequestHandler extends MetricsHandler implements HttpHan
private static final Logger LOG = LogManager.getLogger(QueryActionRequestHandler.class);
private Persistable persistable;
private AppContext appContext;
JsonParser jsonParser;

public QueryActionRequestHandler(final AppContext appContext) {
this.appContext = appContext;
jsonParser = new JsonParser();
}

@Override
Expand Down Expand Up @@ -147,15 +148,15 @@ private JsonElement getActionData(Persistable persistable) {
JsonArray response = new JsonArray();
if (actionSet != null) {
for (PersistedAction action : actionSet) {
response.add(action.toJson());
response.add(action.toJson(this.jsonParser));
}
result.add(ACTION_SET_JSON_NAME, response);
} else {
result.add(ACTION_SET_JSON_NAME, new JsonArray());
}
} catch (Exception e) {
LOG.error("Fail to query DB, message : {}", e.getMessage());
result.add("error", new JsonParser().parse("Fail to query db").getAsJsonObject());
result.add("error", this.jsonParser.parse("Fail to query db").getAsJsonObject());
}
}
return result;
Expand Down

0 comments on commit d217727

Please sign in to comment.