Search in sources :

Example 41 with JSONArray

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

the class AbstractPlanNode method helpLoadFromJSONObject.

protected final void helpLoadFromJSONObject(JSONObject jobj, Database db) throws JSONException {
    assert (jobj != null);
    m_id = jobj.getInt(Members.ID.name());
    JSONArray jarray = null;
    //load inline nodes
    if (!jobj.isNull(Members.INLINE_NODES.name())) {
        jarray = jobj.getJSONArray(Members.INLINE_NODES.name());
        PlanNodeTree pnt = new PlanNodeTree();
        pnt.loadPlanNodesFromJSONArrays(jarray, db);
        List<AbstractPlanNode> list = pnt.getNodeList();
        for (AbstractPlanNode pn : list) {
            m_inlineNodes.put(pn.getPlanNodeType(), pn);
        }
    }
    // load the output schema if it was marked significant.
    if (!jobj.isNull(Members.OUTPUT_SCHEMA.name())) {
        m_hasSignificantOutputSchema = true;
        m_outputSchema = loadSchemaFromJSONObject(jobj, Members.OUTPUT_SCHEMA.name());
    }
}
Also used : JSONArray(org.json_voltpatches.JSONArray)

Example 42 with JSONArray

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

the class AbstractPlanNode method loadBooleanArrayFromJSONObject.

protected static void loadBooleanArrayFromJSONObject(JSONObject jobj, String key, List<Boolean> target) throws JSONException {
    if (!jobj.isNull(key)) {
        JSONArray jarray = jobj.getJSONArray(key);
        int numCols = jarray.length();
        for (int ii = 0; ii < numCols; ++ii) {
            target.add(jarray.getBoolean(ii));
        }
    }
}
Also used : JSONArray(org.json_voltpatches.JSONArray)

Example 43 with JSONArray

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

the class TestCollector method createLogFiles.

private void createLogFiles() throws Exception {
    try {
        String configInfoPath = m_voltDbRootPath + File.separator + Constants.CONFIG_DIR + File.separator + "config.json";
        ;
        JSONObject jsonObject = Collector.parseJSONFile(configInfoPath);
        JSONArray jsonArray = jsonObject.getJSONArray("log4jDst");
        //maintain the file naming format
        String fileNamePrefix = "volt-junit-fulllog.txt.";
        String fileText = "This is a dummy log file.";
        String workingDir = getWorkingDir(m_voltDbRootPath);
        VoltFile logFolder = new VoltFile(workingDir + "/obj/release/testoutput/");
        logFolder.mkdir();
        for (File oldLogFile : logFolder.listFiles()) {
            if (oldLogFile.getName().startsWith(fileNamePrefix)) {
                oldLogFile.delete();
            }
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String[] fileDates = new String[6];
        Calendar cal, cal2;
        cal = Calendar.getInstance();
        cal2 = Calendar.getInstance();
        for (int i = -1; i < 2; i++) {
            cal.add(Calendar.DATE, -i - 1);
            fileDates[i + 1] = formatter.format(cal.getTime());
        }
        cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -1);
        cal2.set(cal.get(Calendar.YEAR), 11, 31);
        fileDates[3] = formatter.format(cal2.getTime());
        cal2.add(Calendar.DATE, -4);
        fileDates[4] = formatter.format(cal2.getTime());
        cal2 = Calendar.getInstance();
        cal2.set(cal2.get(Calendar.YEAR), 0, 02);
        fileDates[5] = formatter.format(cal2.getTime());
        for (String fileDate : fileDates) {
            VoltFile file = new VoltFile(logFolder, fileNamePrefix + fileDate);
            file.createNewFile();
            BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
            writer.write(fileText);
            writer.close();
            formatter.format(file.lastModified());
            file.setLastModified(formatter.parse(fileDate).getTime());
            JSONObject object = new JSONObject();
            object.put("path", file.getCanonicalPath());
            object.put("format", "'.'" + fileDate);
            jsonArray.put(object);
        }
        VoltFile repeatFileFolder = new VoltFile(logFolder, "test");
        repeatFileFolder.mkdir();
        VoltFile file = new VoltFile(repeatFileFolder, fileNamePrefix + fileDates[0]);
        file.createNewFile();
        BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
        writer.write(fileText);
        writer.close();
        JSONObject object = new JSONObject();
        object.put("path", file.getCanonicalPath());
        object.put("format", "'.'" + fileDates[0]);
        jsonArray.put(object);
        FileOutputStream fos = new FileOutputStream(configInfoPath);
        fos.write(jsonObject.toString(4).getBytes(Charsets.UTF_8));
        fos.close();
    } catch (JSONException e) {
        System.err.print(e.getMessage());
    } catch (ParseException e) {
        System.err.print(e.getMessage());
    }
}
Also used : Calendar(java.util.Calendar) FileWriter(java.io.FileWriter) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) BufferedWriter(java.io.BufferedWriter) JSONObject(org.json_voltpatches.JSONObject) FileOutputStream(java.io.FileOutputStream) ParseException(java.text.ParseException) ZipFile(java.util.zip.ZipFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 44 with JSONArray

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

the class HostMessenger method writeRequestJoinResponse.

/*
     * Advertise to a newly connecting node the topology of the cluster so that it can connect to
     * the rest of the nodes
     */
private void writeRequestJoinResponse(int hostId, JoinAcceptor.PleaDecision decision, SocketChannel socket) throws Exception {
    JSONObject jsObj = new JSONObject();
    jsObj.put(SocketJoiner.ACCEPTED, decision.accepted);
    if (decision.accepted) {
        /*
             * Tell the new node what its host id is
             */
        jsObj.put(SocketJoiner.NEW_HOST_ID, hostId);
        /*
             * Echo back the address that the node connected from
             */
        jsObj.put(SocketJoiner.REPORTED_ADDRESS, ((InetSocketAddress) socket.socket().getRemoteSocketAddress()).getAddress().getHostAddress());
        /*
             * Create an array containing an id for every node including this one
             * even though the connection has already been made
             */
        JSONArray jsArray = new JSONArray();
        JSONObject hostObj = new JSONObject();
        hostObj.put(SocketJoiner.HOST_ID, getHostId());
        hostObj.put(SocketJoiner.ADDRESS, m_config.internalInterface.isEmpty() ? socket.socket().getLocalAddress().getHostAddress() : m_config.internalInterface);
        hostObj.put(SocketJoiner.PORT, m_config.internalPort);
        jsArray.put(hostObj);
        for (Entry<Integer, Collection<ForeignHost>> entry : m_foreignHosts.asMap().entrySet()) {
            if (entry.getValue().isEmpty())
                continue;
            int hsId = entry.getKey();
            Iterator<ForeignHost> it = entry.getValue().iterator();
            // all fhs to same host have the same address and port
            ForeignHost fh = it.next();
            hostObj = new JSONObject();
            hostObj.put(SocketJoiner.HOST_ID, hsId);
            hostObj.put(SocketJoiner.ADDRESS, fh.m_listeningAddress.getAddress().getHostAddress());
            hostObj.put(SocketJoiner.PORT, fh.m_listeningAddress.getPort());
            jsArray.put(hostObj);
        }
        jsObj.put(SocketJoiner.HOSTS, jsArray);
    } else {
        jsObj.put(SocketJoiner.REASON, decision.errMsg);
        jsObj.put(SocketJoiner.MAY_RETRY, decision.mayRetry);
    }
    byte[] messageBytes = jsObj.toString(4).getBytes("UTF-8");
    ByteBuffer message = ByteBuffer.allocate(4 + messageBytes.length);
    message.putInt(messageBytes.length);
    message.put(messageBytes).flip();
    while (message.hasRemaining()) {
        socket.write(message);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JSONObject(org.json_voltpatches.JSONObject) InetSocketAddress(java.net.InetSocketAddress) JSONArray(org.json_voltpatches.JSONArray) Collection(java.util.Collection) ImmutableCollection(com.google_voltpatches.common.collect.ImmutableCollection) ByteBuffer(java.nio.ByteBuffer)

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