Search in sources :

Example 6 with JSONObject

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);
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Example 7 with JSONObject

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Example 8 with JSONObject

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ArrayList(java.util.ArrayList)

Example 9 with JSONObject

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;
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Example 10 with JSONObject

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);
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Aggregations

JSONObject (org.json_voltpatches.JSONObject)123 JSONException (org.json_voltpatches.JSONException)45 JSONArray (org.json_voltpatches.JSONArray)30 IOException (java.io.IOException)20 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)18 HashMap (java.util.HashMap)17 File (java.io.File)14 Map (java.util.Map)14 ByteBuffer (java.nio.ByteBuffer)13 ExecutionException (java.util.concurrent.ExecutionException)12 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 TreeSet (java.util.TreeSet)6 JSONStringer (org.json_voltpatches.JSONStringer)6 HashSet (java.util.HashSet)5 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)5 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)4 InetAddress (java.net.InetAddress)4