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

Adding the Json Parser Object as the Class Member Variable #503

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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