use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class SnapshotScanAgent method getSnapshotDigestScanResults.
private VoltTable getSnapshotDigestScanResults(String path) {
VoltTable results = constructDigestResultsTable();
List<File> relevantFiles = retrieveRelevantFiles(path);
if (relevantFiles == null) {
results.addRow(m_messenger.getHostId(), "", "", "", "FAILURE", m_errorString);
} else {
for (final File f : relevantFiles) {
if (f.getName().endsWith(".vpt")) {
continue;
}
if (f.canRead()) {
try {
Set<String> tableNames = new HashSet<String>();
JSONObject digest = SnapshotUtil.CRCCheck(f, SNAP_LOG);
if (digest == null)
continue;
JSONArray tables = digest.getJSONArray("tables");
for (int ii = 0; ii < tables.length(); ii++) {
tableNames.add(tables.getString(ii));
}
final StringWriter sw = new StringWriter();
int ii = 0;
for (String name : tableNames) {
sw.append(name);
if (ii != tableNames.size() - 1) {
sw.append(',');
}
ii++;
}
results.addRow(m_messenger.getHostId(), path, f.getName(), sw.toString(), "SUCCESS", "");
} catch (Exception e) {
SNAP_LOG.warn(e);
}
}
}
}
return results;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class RealVoltDB method collectLocalNetworkMetadata.
void collectLocalNetworkMetadata() {
boolean threw = false;
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
stringer.key("interfaces").array();
if (m_config.m_externalInterface.equals("")) {
LinkedList<NetworkInterface> interfaces = new LinkedList<>();
try {
Enumeration<NetworkInterface> intfEnum = NetworkInterface.getNetworkInterfaces();
while (intfEnum.hasMoreElements()) {
NetworkInterface intf = intfEnum.nextElement();
if (intf.isLoopback() || !intf.isUp()) {
continue;
}
interfaces.offer(intf);
}
} catch (SocketException e) {
throw new RuntimeException(e);
}
if (interfaces.isEmpty()) {
stringer.value("localhost");
} else {
boolean addedIp = false;
while (!interfaces.isEmpty()) {
NetworkInterface intf = interfaces.poll();
Enumeration<InetAddress> inetAddrs = intf.getInetAddresses();
Inet6Address inet6addr = null;
Inet4Address inet4addr = null;
while (inetAddrs.hasMoreElements()) {
InetAddress addr = inetAddrs.nextElement();
if (addr instanceof Inet6Address) {
inet6addr = (Inet6Address) addr;
if (inet6addr.isLinkLocalAddress()) {
inet6addr = null;
}
} else if (addr instanceof Inet4Address) {
inet4addr = (Inet4Address) addr;
}
}
if (inet4addr != null) {
stringer.value(inet4addr.getHostAddress());
addedIp = true;
}
if (inet6addr != null) {
stringer.value(inet6addr.getHostAddress());
addedIp = true;
}
}
if (!addedIp) {
stringer.value("localhost");
}
}
} else {
stringer.value(m_config.m_externalInterface);
}
} catch (Exception e) {
threw = true;
hostLog.warn("Error while collecting data about local network interfaces", e);
}
try {
if (threw) {
stringer = new JSONStringer();
stringer.object();
stringer.key("interfaces").array();
stringer.value("localhost");
stringer.endArray();
} else {
stringer.endArray();
}
stringer.keySymbolValuePair("clientPort", m_config.m_port);
stringer.keySymbolValuePair("clientInterface", m_config.m_clientInterface);
stringer.keySymbolValuePair("adminPort", m_config.m_adminPort);
stringer.keySymbolValuePair("adminInterface", m_config.m_adminInterface);
stringer.keySymbolValuePair("httpPort", m_config.m_httpPort);
stringer.keySymbolValuePair("httpInterface", m_config.m_httpPortInterface);
stringer.keySymbolValuePair("internalPort", m_config.m_internalPort);
stringer.keySymbolValuePair("internalInterface", m_config.m_internalInterface);
String[] zkInterface = m_config.m_zkInterface.split(":");
stringer.keySymbolValuePair("zkPort", zkInterface[1]);
stringer.keySymbolValuePair("zkInterface", zkInterface[0]);
stringer.keySymbolValuePair("drPort", VoltDB.getReplicationPort(m_catalogContext.cluster.getDrproducerport()));
stringer.keySymbolValuePair("drInterface", VoltDB.getDefaultReplicationInterface());
stringer.keySymbolValuePair("publicInterface", m_config.m_publicInterface);
stringer.endObject();
JSONObject obj = new JSONObject(stringer.toString());
// possibly atomic swap from null to realz
m_localMetadata = obj.toString(4);
hostLog.debug("System Metadata is: " + m_localMetadata);
} catch (Exception e) {
hostLog.warn("Failed to collect data about lcoal network interfaces", e);
}
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class Distributer method updateProcedurePartitioning.
private void updateProcedurePartitioning(VoltTable vt) {
Map<String, Procedure> procs = Maps.newHashMap();
while (vt.advanceRow()) {
try {
//Data embedded in JSON object in remarks column
String jsString = vt.getString(6);
String procedureName = vt.getString(2);
JSONObject jsObj = new JSONObject(jsString);
boolean readOnly = jsObj.getBoolean(Constants.JSON_READ_ONLY);
if (jsObj.getBoolean(Constants.JSON_SINGLE_PARTITION)) {
int partitionParameter = jsObj.getInt(Constants.JSON_PARTITION_PARAMETER);
int partitionParameterType = jsObj.getInt(Constants.JSON_PARTITION_PARAMETER_TYPE);
procs.put(procedureName, new Procedure(false, readOnly, partitionParameter, partitionParameterType));
} else {
// Multi Part procedure JSON descriptors omit the partitionParameter
procs.put(procedureName, new Procedure(true, readOnly, Procedure.PARAMETER_NONE, Procedure.PARAMETER_NONE));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
ImmutableSortedMap<String, Procedure> oldProcs = m_procedureInfo.get();
m_procedureInfo.compareAndSet(oldProcs, ImmutableSortedMap.copyOf(procs));
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class LeaderAppointer method assignLeader.
private long assignLeader(int partitionId, List<Long> children) {
// We used masterHostId = -1 as a way to force the leader choice to be
// the first replica in the list, if we don't have some other mechanism
// which has successfully overridden it.
int masterHostId = -1;
if (m_state.get() == AppointerState.CLUSTER_START) {
try {
// find master in topo
JSONArray parts = m_topo.getJSONArray(AbstractTopology.TOPO_PARTITIONS);
for (int p = 0; p < parts.length(); p++) {
JSONObject aPartition = parts.getJSONObject(p);
int pid = aPartition.getInt(AbstractTopology.TOPO_PARTITION_ID);
if (pid == partitionId) {
masterHostId = aPartition.getInt(AbstractTopology.TOPO_MASTER);
break;
}
}
} catch (JSONException jse) {
tmLog.error("Failed to find master for partition " + partitionId + ", defaulting to 0");
jse.printStackTrace();
// stupid default
masterHostId = -1;
}
} else {
// For now, if we're appointing a new leader as a result of a
// failure, just pick the first replica in the children list.
// Could eventually do something more complex here to try to keep a
// semi-balance, but it's unclear that this has much utility until
// we add rebalancing on rejoin as well.
masterHostId = -1;
}
long masterHSId = children.get(0);
for (Long child : children) {
if (CoreUtils.getHostIdFromHSId(child) == masterHostId) {
masterHSId = child;
break;
}
}
tmLog.info("Appointing HSId " + CoreUtils.hsIdToString(masterHSId) + " as leader for partition " + partitionId);
try {
m_iv2appointees.put(partitionId, masterHSId);
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Unable to appoint new master for partition " + partitionId, true, e);
}
return masterHSId;
}
use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.
the class BalancePartitionsRequest method parseRanges.
private List<PartitionPair> parseRanges(JSONObject jsObj) throws JSONException {
ImmutableList.Builder<PartitionPair> builder = ImmutableList.builder();
JSONArray pairsArray = jsObj.getJSONArray("partitionPairs");
for (int i = 0; i < pairsArray.length(); i++) {
JSONObject pairObj = pairsArray.getJSONObject(i);
builder.add(new PartitionPair(pairObj.getInt("srcPartition"), pairObj.getInt("destPartition"), pairObj.getInt("rangeStart"), pairObj.getInt("rangeEnd")));
}
return builder.build();
}
Aggregations