Search in sources :

Example 36 with JSONObject

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

the class AdhocDDLTestBase method verifySinglePartitionProcedure.

protected boolean verifySinglePartitionProcedure(String proc) throws Exception {
    VoltTable procedures = m_client.callProcedure("@SystemCatalog", "PROCEDURES").getResults()[0];
    boolean found = VoltTableTestHelpers.moveToMatchingRow(procedures, "PROCEDURE_NAME", proc);
    boolean verified = false;
    if (found) {
        String remarks = procedures.getString("REMARKS");
        System.out.println("REMARKS: " + remarks);
        JSONObject jsObj = new JSONObject(remarks);
        verified = (jsObj.getBoolean(Constants.JSON_SINGLE_PARTITION));
    }
    return verified;
}
Also used : JSONObject(org.json_voltpatches.JSONObject)

Example 37 with JSONObject

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

the class TestTheHashinator method checkConfigJSON.

private void checkConfigJSON(ImmutableSortedMap<Integer, Integer> tokens, String JSON) throws JSONException {
    final JSONObject jsonData = new JSONObject(JSON);
    assertEquals(tokens.size(), jsonData.length());
    for (Map.Entry<Integer, Integer> entry : tokens.entrySet()) {
        assertEquals(entry.getValue().intValue(), jsonData.getInt(entry.getKey().toString()));
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) HashMap(java.util.HashMap) ImmutableSortedMap(com.google_voltpatches.common.collect.ImmutableSortedMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 38 with JSONObject

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

the class MapCache method processParentEvent.

/**
     * Rebuild the point-in-time snapshot of the children objects
     * and set watches on new children.
     *
     * @Param event may be null on the first initialization.
     */
private void processParentEvent(WatchedEvent event) throws Exception {
    // get current children snapshot and reset this watch.
    Set<String> children = new TreeSet<String>(m_zk.getChildren(m_rootNode, m_parentWatch));
    // intersect to get newChildren and update m_lastChildren to the current set.
    Set<String> newChildren = new HashSet<String>(children);
    newChildren.removeAll(m_lastChildren);
    m_lastChildren = children;
    List<ByteArrayCallback> callbacks = new ArrayList<ByteArrayCallback>();
    for (String child : children) {
        ByteArrayCallback cb = new ByteArrayCallback();
        // set watches on new children.
        if (newChildren.contains(child)) {
            m_zk.getData(ZKUtil.joinZKPath(m_rootNode, child), m_childWatch, cb, null);
        } else {
            m_zk.getData(ZKUtil.joinZKPath(m_rootNode, child), false, cb, null);
        }
        callbacks.add(cb);
    }
    HashMap<String, JSONObject> cache = new HashMap<String, JSONObject>();
    for (ByteArrayCallback callback : callbacks) {
        try {
            byte[] payload = callback.getData();
            JSONObject jsObj = new JSONObject(new String(payload, "UTF-8"));
            cache.put(callback.getPath(), jsObj);
        } catch (KeeperException.NoNodeException e) {
        // child may have been deleted between the parent trigger and getData.
        }
    }
    m_publicCache.set(ImmutableMap.copyOf(cache));
    if (m_cb != null) {
        m_cb.run(m_publicCache.get());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteArrayCallback(org.voltcore.zk.ZKUtil.ByteArrayCallback) JSONObject(org.json_voltpatches.JSONObject) TreeSet(java.util.TreeSet) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) HashSet(java.util.HashSet)

Example 39 with JSONObject

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

the class ClientInterface method handlePartitionFailOver.

private void handlePartitionFailOver(BinaryPayloadMessage message) {
    try {
        JSONObject jsObj = new JSONObject(new String(message.m_payload, "UTF-8"));
        final int partitionId = jsObj.getInt(Cartographer.JSON_PARTITION_ID);
        final long initiatorHSId = jsObj.getLong(Cartographer.JSON_INITIATOR_HSID);
        for (final ClientInterfaceHandleManager cihm : m_cihm.values()) {
            try {
                cihm.connection.queueTask(new Runnable() {

                    @Override
                    public void run() {
                        failOverConnection(partitionId, initiatorHSId, cihm.connection);
                    }
                });
            } catch (UnsupportedOperationException ignore) {
                // In case some internal connections don't implement queueTask()
                failOverConnection(partitionId, initiatorHSId, cihm.connection);
            }
        }
        // Create adapters here so that it works for elastic add.
        if (!m_internalConnectionHandler.hasAdapter(partitionId)) {
            m_internalConnectionHandler.addAdapter(partitionId, createInternalAdapter(partitionId));
        }
    } catch (Exception e) {
        hostLog.warn("Error handling partition fail over at ClientInterface, continuing anyways", e);
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 40 with JSONObject

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

the class SnapshotDaemon method processUserSnapshotRequestEvent.

/*
     * Process the event generated when the node for a user snapshot request
     * is created.
     */
private void processUserSnapshotRequestEvent(final WatchedEvent event) throws Exception {
    if (event.getType() == EventType.NodeCreated) {
        byte[] data = m_zk.getData(event.getPath(), false, null);
        String jsonString = new String(data, "UTF-8");
        final JSONObject jsObj = new JSONObject(jsonString);
        final String requestId = jsObj.getString("requestId");
        final boolean blocking = jsObj.getBoolean(SnapshotUtil.JSON_BLOCK);
        /*
             * Going to reuse the request object, remove the requestId
             * field now that it is consumed
             */
        jsObj.remove("requestId");
        jsObj.put("perPartitionTxnIds", retrievePerPartitionTransactionIds());
        final long handle = m_nextCallbackHandle++;
        m_procedureCallbacks.put(handle, new ProcedureCallback() {

            @Override
            public void clientCallback(ClientResponse clientResponse) {
                m_lastInitiationTs = null;
                try {
                    /*
                         * If there is an error then we are done.
                         */
                    if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                        ClientResponseImpl rimpl = (ClientResponseImpl) clientResponse;
                        saveResponseToZKAndReset(requestId, rimpl);
                        return;
                    }
                    /*
                         * Now analyze the response. If a snapshot was in progress
                         * we have to reattempt it later, and send a response to the client
                         * saying it was queued. Otherwise, forward the response
                         * failure/success to the client.
                         */
                    if (isSnapshotInProgressResponse(clientResponse)) {
                        scheduleSnapshotForLater(jsObj.toString(4), requestId, true);
                    } else {
                        ClientResponseImpl rimpl = (ClientResponseImpl) clientResponse;
                        saveResponseToZKAndReset(requestId, rimpl);
                        return;
                    }
                } catch (Exception e) {
                    SNAP_LOG.error("Error processing user snapshot request", e);
                    try {
                        userSnapshotRequestExistenceCheck(true);
                    } catch (Exception e2) {
                        VoltDB.crashLocalVoltDB("Error resetting watch for user snapshots", true, e2);
                    }
                }
            }
        });
        initiateSnapshotSave(handle, new Object[] { jsObj.toString(4) }, blocking);
        return;
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException) NodeExistsException(org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) ExecutionException(java.util.concurrent.ExecutionException)

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