Search in sources :

Example 11 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class AbstractExpression method loadSortListFromJSONArray.

/**
     * Load two lists from a JSONObject.
     * One list is for sort expressions and the other is for sort directions.
     * The lists are cleared before they are filled in.
     * This is the inverse of toJSONArrayFromSortList.
     *
     * The JSONObject should be in object state, not array state.
     * It should have a member named SORT_COLUMNS,
     * which is an array with the <expression, direction> pairs.
     * Sometimes the sort directions are not needed.
     * For example, when deserializing
     *
     * @param sortExpressions The container for the sort expressions.
     * @param sortDirections The container for the sort directions.  This may
     *                       be null if we don't care about directions.  If there
     *                       are no directions in the list this will be empty.
     * @param jarray
     * @throws JSONException
     */
public static void loadSortListFromJSONArray(List<AbstractExpression> sortExpressions, List<SortDirectionType> sortDirections, JSONObject jobj) throws JSONException {
    if (jobj.has(SortMembers.SORT_COLUMNS)) {
        sortExpressions.clear();
        if (sortDirections != null) {
            sortDirections.clear();
        }
        JSONArray jarray = jobj.getJSONArray(SortMembers.SORT_COLUMNS);
        int size = jarray.length();
        for (int ii = 0; ii < size; ++ii) {
            JSONObject tempObj = jarray.getJSONObject(ii);
            sortExpressions.add(fromJSONChild(tempObj, SortMembers.SORT_EXPRESSION));
            if (sortDirections == null || !tempObj.has(SortMembers.SORT_DIRECTION)) {
                continue;
            }
            String sdAsString = tempObj.getString(SortMembers.SORT_DIRECTION);
            sortDirections.add(SortDirectionType.get(sdAsString));
        }
    }
    assert (sortDirections == null || sortExpressions.size() == sortDirections.size());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) JSONString(org.json_voltpatches.JSONString)

Example 12 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class AbstractExpression method loadFromJSONArray.

private static List<AbstractExpression> loadFromJSONArray(List<AbstractExpression> starter, JSONArray jarray, StmtTableScan tableScan) throws JSONException {
    if (starter == null) {
        starter = new ArrayList<>();
    }
    int size = jarray.length();
    for (int i = 0; i < size; ++i) {
        JSONObject tempjobj = jarray.getJSONObject(i);
        starter.add(fromJSONObject(tempjobj, tableScan));
    }
    return starter;
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Example 13 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class MpScheduler method getBalancePartitions.

/**
     * Extract the two involved partitions from the @BalancePartitions request.
     */
private Set<Integer> getBalancePartitions(Iv2InitiateTaskMessage msg) {
    try {
        JSONObject jsObj = new JSONObject((String) msg.getParameters()[0]);
        BalancePartitionsRequest request = new BalancePartitionsRequest(jsObj);
        return Sets.newHashSet(request.partitionPairs.get(0).srcPartition, request.partitionPairs.get(0).destPartition);
    } catch (JSONException e) {
        hostLog.warn("Unable to determine partitions for @BalancePartitions", e);
        return null;
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException) BalancePartitionsRequest(org.voltdb.sysprocs.BalancePartitionsRequest)

Example 14 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class SystemInformation method populateOverviewTable.

/**
     * Accumulate per-host information and return as a table.
     * This function does the real work. Everything else is
     * boilerplate sysproc stuff.
     */
public static VoltTable populateOverviewTable() {
    VoltTable vt = constructOverviewTable();
    int hostId = VoltDB.instance().getHostMessenger().getHostId();
    // try to get the external interface first, if none was set, use local addresses
    InetAddress addr = null;
    String clientInterface = null;
    int clientPort = VoltDB.DEFAULT_PORT;
    String adminInterface = null;
    int adminPort = VoltDB.DEFAULT_ADMIN_PORT;
    String httpInterface = null;
    int httpPort = VoltDB.DEFAULT_HTTP_PORT;
    String internalInterface = null;
    int internalPort = Constants.DEFAULT_INTERNAL_PORT;
    String zkInterface = null;
    int zkPort = Constants.DEFAULT_ZK_PORT;
    String drInterface = null;
    int drPort = VoltDB.DEFAULT_DR_PORT;
    String publicInterface = null;
    try {
        String localMetadata = VoltDB.instance().getLocalMetadata();
        JSONObject jsObj = new JSONObject(localMetadata);
        JSONArray interfaces = jsObj.getJSONArray("interfaces");
        String iface = interfaces.getString(0);
        addr = InetAddress.getByName(iface);
        clientPort = jsObj.getInt("clientPort");
        clientInterface = jsObj.getString("clientInterface");
        adminPort = jsObj.getInt("adminPort");
        adminInterface = jsObj.getString("adminInterface");
        httpPort = jsObj.getInt("httpPort");
        httpInterface = jsObj.getString("httpInterface");
        internalPort = jsObj.getInt("internalPort");
        internalInterface = jsObj.getString("internalInterface");
        zkPort = jsObj.getInt("zkPort");
        zkInterface = jsObj.getString("zkInterface");
        drPort = jsObj.getInt("drPort");
        drInterface = jsObj.getString("drInterface");
        publicInterface = jsObj.getString("publicInterface");
    } catch (JSONException e) {
        hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
    } catch (UnknownHostException e) {
        hostLog.info("Failed to determine hostname, falling back to first resolvable IP address.");
    }
    // host name and IP address.
    if (addr == null) {
        addr = org.voltcore.utils.CoreUtils.getLocalAddress();
    }
    vt.addRow(hostId, "IPADDRESS", addr.getHostAddress());
    vt.addRow(hostId, "HOSTNAME", CoreUtils.getHostnameOrAddress());
    vt.addRow(hostId, "CLIENTINTERFACE", clientInterface);
    vt.addRow(hostId, "CLIENTPORT", Integer.toString(clientPort));
    vt.addRow(hostId, "ADMININTERFACE", adminInterface);
    vt.addRow(hostId, "ADMINPORT", Integer.toString(adminPort));
    vt.addRow(hostId, "HTTPINTERFACE", httpInterface);
    vt.addRow(hostId, "HTTPPORT", Integer.toString(httpPort));
    vt.addRow(hostId, "INTERNALINTERFACE", internalInterface);
    vt.addRow(hostId, "INTERNALPORT", Integer.toString(internalPort));
    vt.addRow(hostId, "ZKINTERFACE", zkInterface);
    vt.addRow(hostId, "ZKPORT", Integer.toString(zkPort));
    vt.addRow(hostId, "DRINTERFACE", drInterface);
    vt.addRow(hostId, "DRPORT", Integer.toString(drPort));
    vt.addRow(hostId, "PUBLICINTERFACE", publicInterface);
    // build string
    vt.addRow(hostId, "BUILDSTRING", VoltDB.instance().getBuildString());
    // version
    vt.addRow(hostId, "VERSION", VoltDB.instance().getVersionString());
    // catalog path
    String path = VoltDB.instance().getConfig().m_pathToCatalog;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "CATALOG", path);
    // deployment path
    path = VoltDB.instance().getConfig().m_pathToDeployment;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "DEPLOYMENT", path);
    String cluster_state = VoltDB.instance().getMode().toString();
    vt.addRow(hostId, "CLUSTERSTATE", cluster_state);
    // INITIALIZED, used by VEM to determine the spinny icon state.
    org.voltdb.OperationMode mode = VoltDB.instance().getMode();
    String areInitialized = Boolean.toString(!VoltDB.instance().rejoining() && (mode == org.voltdb.OperationMode.RUNNING || mode == org.voltdb.OperationMode.PAUSED));
    vt.addRow(hostId, "INITIALIZED", areInitialized);
    String replication_role = VoltDB.instance().getReplicationRole().toString();
    vt.addRow(hostId, "REPLICATIONROLE", replication_role);
    vt.addRow(hostId, "LASTCATALOGUPDATETXNID", Long.toString(VoltDB.instance().getCatalogContext().m_transactionId));
    vt.addRow(hostId, "CATALOGCRC", Long.toString(VoltDB.instance().getCatalogContext().getCatalogCRC()));
    vt.addRow(hostId, "IV2ENABLED", "true");
    long startTimeMs = VoltDB.instance().getHostMessenger().getInstanceId().getTimestamp();
    vt.addRow(hostId, "STARTTIME", Long.toString(startTimeMs));
    vt.addRow(hostId, "UPTIME", MiscUtils.formatUptime(VoltDB.instance().getClusterUptime()));
    SocketHubAppender hubAppender = (SocketHubAppender) Logger.getRootLogger().getAppender("hub");
    int port = 0;
    if (hubAppender != null)
        port = hubAppender.getPort();
    vt.addRow(hostId, "LOG4JPORT", Integer.toString(port));
    //Add license information
    if (MiscUtils.isPro()) {
        vt.addRow(hostId, "LICENSE", VoltDB.instance().getLicenseInformation());
    }
    populatePartitionGroups(hostId, vt);
    // root path
    vt.addRow(hostId, "VOLTDBROOT", VoltDB.instance().getVoltDBRootPath());
    vt.addRow(hostId, "FULLCLUSTERSIZE", Integer.toString(VoltDB.instance().getCatalogContext().getClusterSettings().hostcount()));
    vt.addRow(hostId, "CLUSTERID", Integer.toString(VoltDB.instance().getCatalogContext().getCluster().getDrclusterid()));
    return vt;
}
Also used : UnknownHostException(java.net.UnknownHostException) SocketHubAppender(org.apache.log4j.net.SocketHubAppender) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) VoltTable(org.voltdb.VoltTable) JSONObject(org.json_voltpatches.JSONObject) InetAddress(java.net.InetAddress) File(java.io.File)

Example 15 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class HTTPUtils method responseFromJSON.

public static Response responseFromJSON(String jsonStr) throws JSONException, IOException {
    Response response = new Response();
    JSONObject jsonObj = new JSONObject(jsonStr);
    JSONArray resultsJson = jsonObj.getJSONArray("results");
    response.results = new VoltTable[resultsJson.length()];
    for (int i = 0; i < response.results.length; i++) {
        JSONObject tableJson = resultsJson.getJSONObject(i);
        response.results[i] = VoltTable.fromJSONObject(tableJson);
    //System.out.println(response.results[i].toString());
    }
    if (jsonObj.isNull("status") == false) {
        response.status = (byte) jsonObj.getInt("status");
    }
    if (jsonObj.isNull("appstatus") == false) {
        response.appStatus = (byte) jsonObj.getInt("appstatus");
    }
    if (jsonObj.isNull("statusstring") == false) {
        response.statusString = jsonObj.getString("statusstring");
    }
    if (jsonObj.isNull("appstatusstring") == false) {
        response.appStatusString = jsonObj.getString("appstatusstring");
    }
    if (jsonObj.isNull("exception") == false) {
        response.exception = jsonObj.getString("exception");
    }
    return response;
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

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