use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class SystemInformationAgent method collectStatsImpl.
@Override
protected void collectStatsImpl(Connection c, long clientHandle, OpsSelector selector, ParameterSet params) throws Exception {
JSONObject obj = new JSONObject();
obj.put("selector", "SYSTEMINFORMATION");
String err = null;
if (selector == OpsSelector.SYSTEMINFORMATION) {
err = parseParamsForSystemInformation(params, obj);
} else {
err = "SystemInformationAgent received non-SYSTEMINFORMATION selector: " + selector.name();
}
if (err != null) {
sendErrorResponse(c, ClientResponse.GRACEFUL_FAILURE, err, clientHandle);
return;
}
String subselector = obj.getString("subselector");
PendingOpsRequest psr = new PendingOpsRequest(selector, subselector, c, clientHandle, System.currentTimeMillis(), obj);
// Intercept them and respond before doing the distributed stuff.
if (subselector.equalsIgnoreCase("DEPLOYMENT")) {
collectSystemInformationDeployment(psr);
return;
}
distributeOpsWork(psr, obj);
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class SystemInformationAgent method parseParamsForSystemInformation.
// Parse the provided parameter set object and fill in subselector and interval into
// the provided JSONObject. If there's an error, return that in the String, otherwise
// return null. Yes, ugly. Bang it out, then refactor later.
private String parseParamsForSystemInformation(ParameterSet params, JSONObject obj) throws Exception {
// Default with no args is OVERVIEW
String subselector = "OVERVIEW";
if (params.toArray().length > 1) {
return "Incorrect number of arguments to @SystemInformation (expects 1, received " + params.toArray().length + ")";
}
if (params.toArray().length == 1) {
Object first = params.toArray()[0];
if (!(first instanceof String)) {
return "First argument to @SystemInformation must be a valid STRING selector, instead was " + first;
}
subselector = (String) first;
if (!(subselector.equalsIgnoreCase("OVERVIEW") || subselector.equalsIgnoreCase("DEPLOYMENT"))) {
return "Invalid @SystemInformation selector " + subselector;
}
}
// Would be nice to have subselector validation here, maybe. Maybe later.
obj.put("subselector", subselector);
obj.put("interval", false);
return null;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class VoltZK method parseMailboxContents.
/**
* Helper method for parsing mailbox node contents into Java objects.
* @throws JSONException
*/
public static List<MailboxNodeContent> parseMailboxContents(List<String> jsons) throws JSONException {
ArrayList<MailboxNodeContent> objects = new ArrayList<MailboxNodeContent>(jsons.size());
for (String json : jsons) {
MailboxNodeContent content = null;
JSONObject jsObj = new JSONObject(json);
long HSId = jsObj.getLong("HSId");
Integer partitionId = null;
if (jsObj.has("partitionId")) {
partitionId = jsObj.getInt("partitionId");
}
content = new MailboxNodeContent(HSId, partitionId);
objects.add(content);
}
return objects;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class StatsAgent method parseParamsForStatistics.
// Parse the provided parameter set object and fill in subselector and interval into
// the provided JSONObject. If there's an error, return that in the String, otherwise
// return null. Yes, ugly. Bang it out, then refactor later.
private String parseParamsForStatistics(ParameterSet params, JSONObject obj) throws Exception {
if ((params.toArray().length < 1) || (params.toArray().length > 2)) {
return "Incorrect number of arguments to @Statistics (expects 2, received " + params.toArray().length + ")";
}
Object first = params.toArray()[0];
if (!(first instanceof String)) {
return "First argument to @Statistics must be a valid STRING selector, instead was " + first;
}
String subselector = (String) first;
try {
StatsSelector s = StatsSelector.valueOf(subselector.toUpperCase());
subselector = s.name();
} catch (Exception e) {
return "First argument to @Statistics must be a valid STRING selector, instead was " + first;
}
boolean interval = false;
if (params.toArray().length == 2) {
interval = ((Number) (params.toArray()[1])).longValue() == 1L;
}
obj.put("subselector", subselector);
obj.put("interval", interval);
return null;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class StatsAgent method collectStatsImpl.
@Override
protected void collectStatsImpl(Connection c, long clientHandle, OpsSelector selector, ParameterSet params) throws Exception {
JSONObject obj = new JSONObject();
obj.put("selector", "STATISTICS");
// parseParamsForStatistics has a clumsy contract, see definition
String err = null;
if (selector == OpsSelector.STATISTICS) {
err = parseParamsForStatistics(params, obj);
} else {
err = "StatsAgent received non-STATISTICS selector: " + selector.name();
}
if (err != null) {
sendErrorResponse(c, ClientResponse.GRACEFUL_FAILURE, err, clientHandle);
return;
}
String subselector = obj.getString("subselector");
// Intercept them and respond before doing the distributed stuff.
if (subselector.equalsIgnoreCase("TOPO")) {
PendingOpsRequest psr = new PendingOpsRequest(selector, subselector, c, clientHandle, System.currentTimeMillis(), obj);
// hacky way to support two format of hashconfig using interval value
// return true if interval == true (delta-flag == 1), indicate sent compressed json
// otherwise return false, indicate sent original binary format
boolean jsonConfig = obj.getBoolean("interval");
collectTopoStats(psr, jsonConfig);
return;
} else if (subselector.equalsIgnoreCase("PARTITIONCOUNT")) {
PendingOpsRequest psr = new PendingOpsRequest(selector, subselector, c, clientHandle, System.currentTimeMillis(), obj);
collectPartitionCount(psr);
return;
}
PendingOpsRequest psr = new PendingOpsRequest(selector, subselector, c, clientHandle, System.currentTimeMillis(), obj);
distributeOpsWork(psr, obj);
}
Aggregations