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;
}
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()));
}
}
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());
}
}
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);
}
}
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;
}
}
Aggregations