Search in sources :

Example 6 with JSONArray

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

the class TestCollector method getLogPaths.

private List<String> getLogPaths(String voltDbRootPath) throws Exception {
    File configLogDir = new File(voltDbRootPath, Constants.CONFIG_DIR);
    File configInfo = new File(configLogDir, "config.json");
    JSONObject jsonObject = Collector.parseJSONFile(configInfo.getCanonicalPath());
    List<String> logPaths = new ArrayList<String>();
    JSONArray jsonArray = jsonObject.getJSONArray("log4jDst");
    for (int i = 0; i < jsonArray.length(); i++) {
        String path = jsonArray.getJSONObject(i).getString("path");
        logPaths.add(path);
    }
    return logPaths;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json_voltpatches.JSONArray) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 7 with JSONArray

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

the class SocketJoiner method connectToPrimary.

/*
     * If this node failed to bind to the leader address
     * it must connect to the leader which will generate a host id and
     * advertise the rest of the cluster so that connectToPrimary can connect to it
     */
private void connectToPrimary(InetSocketAddress coordIp, ConnectStrategy mode) throws Exception {
    // collect clock skews from all nodes
    List<Long> skews = new ArrayList<Long>();
    // collect the set of active voltdb version strings in the cluster
    // this is used to limit simulatanious versions to two
    Set<String> activeVersions = new TreeSet<String>();
    try {
        LOG.debug("Non-Primary Starting & Connecting to Primary");
        SocketChannel socket = createLeaderSocket(coordIp, mode);
        // in probe mode
        if (socket == null)
            return;
        if (!coordIp.equals(m_coordIp)) {
            m_coordIp = coordIp;
        }
        socket.socket().setTcpNoDelay(true);
        socket.socket().setPerformancePreferences(0, 2, 1);
        // blocking call, send a request to the leader node and get a host id assigned by the leader
        RequestHostIdResponse response = requestHostId(socket, skews, activeVersions);
        // check if the membership request is accepted
        JSONObject responseBody = response.getResponseBody();
        if (!responseBody.optBoolean(ACCEPTED, true)) {
            socket.close();
            if (!responseBody.optBoolean(MAY_RETRY, false)) {
                org.voltdb.VoltDB.crashLocalVoltDB("Request to join cluster is rejected: " + responseBody.optString(REASON, "rejection reason is not available"));
            }
            throw new CoreUtils.RetryException(responseBody.optString(REASON, "rejection reason is not available"));
        }
        /*
             * Get the generated host id, and the interface we connected on
             * that was echoed back
             */
        m_localHostId = responseBody.getInt(NEW_HOST_ID);
        m_reportedInternalInterface = responseBody.getString(REPORTED_ADDRESS);
        ImmutableMap.Builder<Integer, JSONObject> cmbld = ImmutableMap.builder();
        cmbld.put(m_localHostId, m_acceptor.decorate(responseBody, Optional.<Boolean>empty()));
        /*
             * Loop over all the hosts and create a connection (except for the first entry, that is the leader)
             * and publish the host id that was generated. This finishes creating the mesh
             */
        JSONArray otherHosts = responseBody.getJSONArray(HOSTS);
        int[] hostIds = new int[otherHosts.length()];
        SocketChannel[] hostSockets = new SocketChannel[hostIds.length];
        InetSocketAddress[] listeningAddresses = new InetSocketAddress[hostIds.length];
        for (int ii = 0; ii < otherHosts.length(); ii++) {
            JSONObject host = otherHosts.getJSONObject(ii);
            String address = host.getString(ADDRESS);
            int port = host.getInt(PORT);
            final int hostId = host.getInt(HOST_ID);
            LOG.info("Leader provided address " + address + ":" + port);
            InetSocketAddress hostAddr = new InetSocketAddress(address, port);
            if (ii == 0) {
                //Leader already has a socket
                hostIds[ii] = hostId;
                listeningAddresses[ii] = hostAddr;
                hostSockets[ii] = socket;
                cmbld.put(ii, response.getLeaderInfo());
                continue;
            }
            // connect to all the peer hosts (except leader) and advertise our existence
            SocketChannel hostSocket = connectToHost(hostAddr);
            JSONObject hostInfo = publishHostId(hostAddr, hostSocket, skews, activeVersions);
            hostIds[ii] = hostId;
            hostSockets[ii] = hostSocket;
            listeningAddresses[ii] = hostAddr;
            cmbld.put(ii, hostInfo);
        }
        /*
             * The max difference of clock skew cannot exceed MAX_CLOCKSKEW, and the number of
             * active versions in the cluster cannot be more than 2.
             */
        checkClockSkew(skews);
        checkActiveVersions(activeVersions, m_acceptor.getVersionChecker().getVersionString());
        /*
             * Notify the leader that we connected to the entire cluster, it will then go
             * and queue a txn for our agreement site to join the cluster
             */
        ByteBuffer joinCompleteBuffer = ByteBuffer.allocate(1);
        while (joinCompleteBuffer.hasRemaining()) {
            hostSockets[0].write(joinCompleteBuffer);
        }
        /*
             * Let host messenger know about the connections.
             * It will init the agreement site and then we are done.
             */
        m_joinHandler.notifyOfHosts(m_localHostId, hostIds, hostSockets, listeningAddresses, cmbld.build());
    } catch (ClosedByInterruptException e) {
    //This is how shutdown is done
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) JSONArray(org.json_voltpatches.JSONArray) ByteBuffer(java.nio.ByteBuffer) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) JSONObject(org.json_voltpatches.JSONObject) TreeSet(java.util.TreeSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 8 with JSONArray

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

the class ChannelDistributer method asChannelSet.

/**
     * Reads the JSON document contained in the byte array data, and
     * converts it to a {@link NavigableSet<ChannelSpec> set of channel specs}
     *
     * @param data zookeeper node data content
     * @return a {@link NavigableSet<ChannelSpec> set of channel specs}
     * @throws JSONException on JSON parse failures
     * @throws IllegalArgumentException on encoded channel spec parse failures
     */
static NavigableSet<ChannelSpec> asChannelSet(byte[] data) throws JSONException, IllegalArgumentException {
    ImmutableSortedSet.Builder<ChannelSpec> sbld = ImmutableSortedSet.naturalOrder();
    JSONArray ja = new JSONArray(new String(data, StandardCharsets.UTF_8));
    for (int i = 0; i < ja.length(); ++i) {
        sbld.add(new ChannelSpec(ja.getString(i)));
    }
    return sbld.build();
}
Also used : ImmutableSortedSet(com.google_voltpatches.common.collect.ImmutableSortedSet) JSONArray(org.json_voltpatches.JSONArray)

Example 9 with JSONArray

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

the class AggregatePlanNode method loadFromJSONObject.

@Override
public void loadFromJSONObject(JSONObject jobj, Database db) throws JSONException {
    helpLoadFromJSONObject(jobj, db);
    JSONArray jarray = jobj.getJSONArray(Members.AGGREGATE_COLUMNS.name());
    int size = jarray.length();
    for (int i = 0; i < size; i++) {
        JSONObject tempObj = jarray.getJSONObject(i);
        m_aggregateTypes.add(ExpressionType.get(tempObj.getString(Members.AGGREGATE_TYPE.name())));
        m_aggregateDistinct.add(tempObj.getInt(Members.AGGREGATE_DISTINCT.name()));
        m_aggregateOutputColumns.add(tempObj.getInt(Members.AGGREGATE_OUTPUT_COLUMN.name()));
        if (tempObj.isNull(Members.AGGREGATE_EXPRESSION.name())) {
            m_aggregateExpressions.add(null);
        } else {
            m_aggregateExpressions.add(AbstractExpression.fromJSONChild(tempObj, Members.AGGREGATE_EXPRESSION.name()));
        }
    }
    AbstractExpression.loadFromJSONArrayChild(m_groupByExpressions, jobj, Members.GROUPBY_EXPRESSIONS.name(), null);
    if (!jobj.isNull(Members.PARTIAL_GROUPBY_COLUMNS.name())) {
        JSONArray jarray2 = jobj.getJSONArray(Members.PARTIAL_GROUPBY_COLUMNS.name());
        int numCols = jarray2.length();
        m_partialGroupByColumns = new ArrayList<>(numCols);
        for (int ii = 0; ii < numCols; ++ii) {
            m_partialGroupByColumns.add(jarray2.getInt(ii));
        }
    }
    m_prePredicate = AbstractExpression.fromJSONChild(jobj, Members.PRE_PREDICATE.name());
    m_postPredicate = AbstractExpression.fromJSONChild(jobj, Members.POST_PREDICATE.name());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray)

Example 10 with JSONArray

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

the class TupleScanPlanNode method loadFromJSONObject.

@Override
public void loadFromJSONObject(JSONObject jobj, Database db) throws JSONException {
    super.loadFromJSONObject(jobj, db);
    if (jobj.has(Members.PARAM_IDX.name())) {
        JSONArray paramIdxArray = jobj.getJSONArray(Members.PARAM_IDX.name());
        int paramSize = paramIdxArray.length();
        assert (m_outputSchema != null && paramSize == m_outputSchema.size());
        for (int i = 0; i < paramSize; ++i) {
            int paramIdx = paramIdxArray.getInt(i);
            ParameterValueExpression pve = new ParameterValueExpression();
            pve.setParameterIndex(paramIdx);
            AbstractExpression expr = m_outputSchema.getColumns().get(i).getExpression();
            pve.setValueSize(expr.getValueSize());
            pve.setValueType(expr.getValueType());
            m_columnList.add(pve);
        }
    }
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) JSONArray(org.json_voltpatches.JSONArray) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression)

Aggregations

JSONArray (org.json_voltpatches.JSONArray)44 JSONObject (org.json_voltpatches.JSONObject)29 JSONException (org.json_voltpatches.JSONException)13 File (java.io.File)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 JSONString (org.json_voltpatches.JSONString)4 ByteBuffer (java.nio.ByteBuffer)3 HashSet (java.util.HashSet)3 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)2 InetSocketAddress (java.net.InetSocketAddress)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ExecutionException (java.util.concurrent.ExecutionException)2 ZipFile (java.util.zip.ZipFile)2 HttpResponse (org.apache.http.HttpResponse)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 InstanceId (org.voltcore.utils.InstanceId)2 Configuration (org.voltdb.VoltDB.Configuration)2 ClientResponse (org.voltdb.client.ClientResponse)2