ASTERIXDB-1714: Eliminate dependency on org.json
Change-Id: Ie9c5400fd134ae75d43385255af7794e968b1c7e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1392
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-algebra/pom.xml b/asterixdb/asterix-algebra/pom.xml
index f53997e..dc195e2 100644
--- a/asterixdb/asterix-algebra/pom.xml
+++ b/asterixdb/asterix-algebra/pom.xml
@@ -171,10 +171,6 @@
<artifactId>algebricks-rewriter</artifactId>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 79c0c6a..ae93779 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -196,16 +196,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>2.8.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.8.4</version>
- </dependency>
- <dependency>
<groupId>org.apache.hyracks</groupId>
<artifactId>hyracks-control-cc</artifactId>
</dependency>
@@ -326,5 +316,13 @@
<type>jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index f9794e4..754b7f9 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -18,7 +18,6 @@
*/
package org.apache.asterix.api.common;
-
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.RemoteException;
@@ -30,6 +29,7 @@
import java.util.Random;
import java.util.Set;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
import org.apache.asterix.api.common.Job.SubmissionMode;
@@ -90,7 +90,6 @@
import org.apache.hyracks.api.client.NodeControllerInfo;
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.api.job.JobSpecification;
-import org.json.JSONException;
/**
* Provides helper methods for compilation of a query into a JobSpec and submission
@@ -161,9 +160,8 @@
return new Pair<>(q, q.getVarCounter());
}
- public JobSpecification compileQuery(IClusterInfoCollector clusterInfoCollector,
- MetadataProvider metadataProvider, Query rwQ, int varCounter, String outputDatasetName,
- SessionConfig conf, ICompiledDmlStatement statement)
+ public JobSpecification compileQuery(IClusterInfoCollector clusterInfoCollector, MetadataProvider metadataProvider,
+ Query rwQ, int varCounter, String outputDatasetName, SessionConfig conf, ICompiledDmlStatement statement)
throws AlgebricksException, RemoteException, ACIDException {
if (!conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && conf.is(SessionConfig.OOB_REWRITTEN_EXPR_TREE)) {
@@ -178,8 +176,8 @@
org.apache.asterix.common.transactions.JobId asterixJobId = JobIdFactory.generateJobId();
metadataProvider.setJobId(asterixJobId);
- ILangExpressionToPlanTranslator t =
- translatorFactory.createExpressionToPlanTranslator(metadataProvider, varCounter);
+ ILangExpressionToPlanTranslator t = translatorFactory.createExpressionToPlanTranslator(metadataProvider,
+ varCounter);
ILogicalPlan plan;
// statement = null when it's a query
@@ -217,8 +215,8 @@
OptimizationConfUtil.getPhysicalOptimizationConfig().setMaxFramesExternalGroupBy(groupFrameLimit);
OptimizationConfUtil.getPhysicalOptimizationConfig().setMaxFramesForJoin(joinFrameLimit);
- HeuristicCompilerFactoryBuilder builder =
- new HeuristicCompilerFactoryBuilder(OptimizationContextFactory.INSTANCE);
+ HeuristicCompilerFactoryBuilder builder = new HeuristicCompilerFactoryBuilder(
+ OptimizationContextFactory.INSTANCE);
builder.setPhysicalOptimizationConfig(OptimizationConfUtil.getPhysicalOptimizationConfig());
builder.setLogicalRewrites(ruleSetFactory.getLogicalRewrites());
builder.setPhysicalRewrites(ruleSetFactory.getPhysicalRewrites());
@@ -304,16 +302,17 @@
builder.setTypeTraitProvider(format.getTypeTraitProvider());
builder.setNormalizedKeyComputerFactoryProvider(format.getNormalizedKeyComputerFactoryProvider());
- JobEventListenerFactory jobEventListenerFactory =
- new JobEventListenerFactory(asterixJobId, metadataProvider.isWriteTransaction());
+ JobEventListenerFactory jobEventListenerFactory = new JobEventListenerFactory(asterixJobId,
+ metadataProvider.isWriteTransaction());
JobSpecification spec = compiler.createJob(AppContextInfo.INSTANCE, jobEventListenerFactory);
if (conf.is(SessionConfig.OOB_HYRACKS_JOB)) {
printPlanPrefix(conf, "Hyracks job");
if (rwQ != null) {
try {
- conf.out().println(spec.toJSON().toString(1));
- } catch (JSONException e) {
+ conf.out().println(
+ new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(spec.toJSON()));
+ } catch (IOException e) {
throw new AlgebricksException(e);
}
conf.out().println(spec.getUserConstraints());
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterAPIServlet.java
index 02be70b..988b5bb 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterAPIServlet.java
@@ -31,12 +31,17 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.apache.asterix.common.config.AsterixProperties;
+import org.apache.asterix.common.config.ExternalProperties;
+import org.apache.asterix.common.utils.JSONUtil;
import org.apache.asterix.common.config.AbstractProperties;
import org.apache.asterix.common.config.ReplicationProperties;
import org.apache.asterix.runtime.util.ClusterStateManager;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ClusterAPIServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -53,6 +58,7 @@
protected static final String REPLICATION_URI_KEY = "replicationUri";
private static final Pattern PARENT_DIR = Pattern.compile("/[^./]+/\\.\\./");
private static final Pattern REPLICATION_PROPERTY = Pattern.compile("^replication\\.");
+ private final ObjectMapper om = new ObjectMapper();
@Override
public final void doGet(HttpServletRequest request, HttpServletResponse response) {
@@ -67,9 +73,8 @@
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter responseWriter = response.getWriter();
- JSONObject json;
-
try {
+ ObjectNode json;
switch (request.getPathInfo() == null ? "" : request.getPathInfo()) {
case "":
json = getClusterStateJSON(request, "");
@@ -84,7 +89,7 @@
throw new IllegalArgumentException();
}
response.setStatus(HttpServletResponse.SC_OK);
- responseWriter.write(json.toString(4));
+ responseWriter.write(JSONUtil.convertNode(json));
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (Exception e) {
@@ -94,15 +99,15 @@
responseWriter.flush();
}
- protected JSONObject getClusterStateSummaryJSON() throws JSONException {
+ protected ObjectNode getClusterStateSummaryJSON() {
return ClusterStateManager.INSTANCE.getClusterStateSummary();
}
- protected JSONObject getReplicationJSON() throws JSONException {
+ protected ObjectNode getReplicationJSON() {
for (AbstractProperties props : getPropertiesInstances()) {
if (props instanceof ReplicationProperties) {
- JSONObject json = new JSONObject();
- json.put("config", props.getProperties(key -> REPLICATION_PROPERTY.matcher(key).replaceFirst("")));
+ ObjectNode json = om.createObjectNode();
+ json.putPOJO("config", props.getProperties(key -> REPLICATION_PROPERTY.matcher(key).replaceFirst("")));
return json;
}
}
@@ -123,13 +128,12 @@
return AbstractProperties.getImplementations();
}
- protected JSONObject getClusterStateJSON(HttpServletRequest request, String pathToNode) throws JSONException {
- JSONObject json;
- json = ClusterStateManager.INSTANCE.getClusterStateDescription();
+ protected ObjectNode getClusterStateJSON(HttpServletRequest request, String pathToNode) {
+ ObjectNode json = ClusterStateManager.INSTANCE.getClusterStateDescription();
Map<String, Object> allProperties = getAllClusterProperties();
- json.put("config", allProperties);
+ json.putPOJO("config", allProperties);
- JSONArray ncs = json.getJSONArray("ncs");
+ ArrayNode ncs = (ArrayNode) json.get("ncs");
final StringBuilder requestURL = new StringBuilder(request.getRequestURL());
if (requestURL.charAt(requestURL.length() - 1) != '/') {
requestURL.append('/');
@@ -138,18 +142,18 @@
String clusterURL = canonicalize(requestURL);
String adminURL = canonicalize(clusterURL + "../");
String nodeURL = clusterURL + "node/";
- for (int i = 0; i < ncs.length(); i++) {
- JSONObject nc = ncs.getJSONObject(i);
- nc.put(CONFIG_URI_KEY, nodeURL + nc.getString(NODE_ID_KEY) + "/config");
- nc.put(STATS_URI_KEY, nodeURL + nc.getString(NODE_ID_KEY) + "/stats");
- nc.put(THREAD_DUMP_URI_KEY, nodeURL + nc.getString(NODE_ID_KEY) + "/threaddump");
+ for (int i = 0; i < ncs.size(); i++) {
+ ObjectNode nc = (ObjectNode) ncs.get(i);
+ nc.put(CONFIG_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/config");
+ nc.put(STATS_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/stats");
+ nc.put(THREAD_DUMP_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/threaddump");
}
- JSONObject cc;
+ ObjectNode cc;
if (json.has("cc")) {
- cc = json.getJSONObject("cc");
+ cc = (ObjectNode) json.get("cc");
} else {
- cc = new JSONObject();
- json.put("cc", cc);
+ cc = om.createObjectNode();
+ json.set("cc", cc);
}
cc.put(CONFIG_URI_KEY, clusterURL + "cc/config");
cc.put(STATS_URI_KEY, clusterURL + "cc/stats");
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterCCDetailsAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterCCDetailsAPIServlet.java
index 75fba74..569d5a0 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterCCDetailsAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterCCDetailsAPIServlet.java
@@ -29,30 +29,31 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hyracks.api.client.IHyracksClientConnection;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ClusterCCDetailsAPIServlet extends ClusterAPIServlet {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger(ClusterCCDetailsAPIServlet.class.getName());
+ private final ObjectMapper om = new ObjectMapper();
@Override
protected void getUnsafe(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter responseWriter = response.getWriter();
ServletContext context = getServletContext();
IHyracksClientConnection hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
- JSONObject json;
-
try {
+ ObjectNode json;
if (request.getPathInfo() == null) {
- json = getClusterStateJSON(request, "../").getJSONObject("cc");
+ json = (ObjectNode) getClusterStateJSON(request, "../").get("cc");
} else {
json = processNode(request, hcc);
}
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
- responseWriter.write(json.toString(4));
+ responseWriter.write(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json));
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (Exception e) {
@@ -62,8 +63,7 @@
responseWriter.flush();
}
- private JSONObject processNode(HttpServletRequest request, IHyracksClientConnection hcc)
- throws Exception {
+ private ObjectNode processNode(HttpServletRequest request, IHyracksClientConnection hcc) throws Exception {
String pathInfo = request.getPathInfo();
if (pathInfo.endsWith("/")) {
throw new IllegalArgumentException();
@@ -71,13 +71,13 @@
String[] parts = pathInfo.substring(1).split("/");
if (request.getPathInfo() == null) {
- return getClusterStateJSON(request, "../../").getJSONObject("cc");
+ return (ObjectNode) getClusterStateJSON(request, "../../").get("cc");
} else if (parts.length == 1) {
switch (parts[0]) {
case "config":
- return new JSONObject(hcc.getNodeDetailsJSON(null, false, true));
+ return om.readValue(hcc.getNodeDetailsJSON(null, false, true), ObjectNode.class);
case "stats":
- return new JSONObject(hcc.getNodeDetailsJSON(null, true, false));
+ return om.readValue(hcc.getNodeDetailsJSON(null, true, false), ObjectNode.class);
case "threaddump":
return processCCThreadDump(hcc);
@@ -90,12 +90,12 @@
}
}
- private JSONObject processCCThreadDump(IHyracksClientConnection hcc) throws Exception {
+ private ObjectNode processCCThreadDump(IHyracksClientConnection hcc) throws Exception {
String dump = hcc.getThreadDump(null);
if (dump == null) {
throw new IllegalArgumentException();
}
- return new JSONObject(dump);
+ return (ObjectNode) om.readTree(dump);
}
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterNodeDetailsAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterNodeDetailsAPIServlet.java
index 1489e55..590e869 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterNodeDetailsAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ClusterNodeDetailsAPIServlet.java
@@ -29,37 +29,45 @@
import java.util.logging.Logger;
import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.asterix.runtime.util.ClusterStateManager;
import org.apache.hyracks.api.client.IHyracksClientConnection;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ClusterNodeDetailsAPIServlet extends ClusterAPIServlet {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger(ClusterNodeDetailsAPIServlet.class.getName());
+ private final ObjectMapper om = new ObjectMapper();
+
+ @Override
+ public void init() throws ServletException{
+ om.enable(SerializationFeature.INDENT_OUTPUT);
+ }
@Override
protected void getUnsafe(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter responseWriter = response.getWriter();
ServletContext context = getServletContext();
IHyracksClientConnection hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
- JSONObject json;
-
try {
+ ObjectNode json;
if (request.getPathInfo() == null) {
- json = new JSONObject();
- json.put("ncs", getClusterStateJSON(request, "../").getJSONArray("ncs"));
+ json = om.createObjectNode();
+ json.set("ncs", getClusterStateJSON(request, "../").get("ncs"));
} else {
json = processNode(request, hcc);
}
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
- responseWriter.write(json.toString(4));
+ responseWriter.write(om.writerWithDefaultPrettyPrinter().writeValueAsString(json));
} catch (IllegalStateException e) { // NOSONAR - exception not logged or rethrown
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
@@ -71,7 +79,7 @@
responseWriter.flush();
}
- private JSONObject processNode(HttpServletRequest request, IHyracksClientConnection hcc)
+ private ObjectNode processNode(HttpServletRequest request, IHyracksClientConnection hcc)
throws Exception {
String pathInfo = request.getPathInfo();
if (pathInfo.endsWith("/")) {
@@ -81,19 +89,18 @@
final String node = parts[0];
if (parts.length == 1) {
- JSONArray ncs = getClusterStateJSON(request, "../../").getJSONArray("ncs");
- for (int i = 0; i < ncs.length(); i++) {
- JSONObject json = ncs.getJSONObject(i);
- if (node.equals(json.getString("node_id"))) {
- return json;
+ ArrayNode ncs = (ArrayNode) getClusterStateJSON(request, "../../").get("ncs");
+ for (int i = 0; i < ncs.size(); i++) {
+ if (node.equals(ncs.get(i).get("node_id").asText())) {
+ return (ObjectNode) ncs.get(i);
}
}
if ("cc".equals(node)) {
- return new JSONObject();
+ return om.createObjectNode();
}
throw new IllegalArgumentException();
} else if (parts.length == 2) {
- JSONObject json;
+ ObjectNode json;
switch (parts[1]) {
case "config":
@@ -118,78 +125,78 @@
}
}
- protected JSONObject fixupKeys(JSONObject json) throws JSONException {
+ protected ObjectNode fixupKeys(ObjectNode json) {
// TODO (mblow): generate the keys with _ to begin with
List<String> keys = new ArrayList<>();
- for (Iterator iter = json.keys(); iter.hasNext(); ) {
+ for (Iterator iter = json.fieldNames(); iter.hasNext(); ) {
keys.add((String) iter.next());
}
for (String key : keys) {
String newKey = key.replace('-', '_');
if (!newKey.equals(key)) {
- json.put(newKey, json.remove(key));
+ json.set(newKey, json.remove(key));
}
}
return json;
}
- protected JSONObject processNodeStats(IHyracksClientConnection hcc, String node) throws Exception {
+ protected ObjectNode processNodeStats(IHyracksClientConnection hcc, String node) throws Exception {
final String details = hcc.getNodeDetailsJSON(node, true, false);
if (details == null) {
throw new IllegalArgumentException();
}
- JSONObject json = new JSONObject(details);
- int index = json.getInt("rrd-ptr") - 1;
+ ObjectNode json = (ObjectNode) om.readTree(details);
+ int index = json.get("rrd-ptr").asInt() - 1;
json.remove("rrd-ptr");
List<String> keys = new ArrayList<>();
- for (Iterator iter = json.keys(); iter.hasNext(); ) {
+ for (Iterator iter = json.fieldNames(); iter.hasNext(); ) {
keys.add((String) iter.next());
}
- final JSONArray gcNames = json.getJSONArray("gc-names");
- final JSONArray gcCollectionTimes = json.getJSONArray("gc-collection-times");
- final JSONArray gcCollectionCounts = json.getJSONArray("gc-collection-counts");
+ final ArrayNode gcNames = (ArrayNode) json.get("gc-names");
+ final ArrayNode gcCollectionTimes = (ArrayNode) json.get("gc-collection-times");
+ final ArrayNode gcCollectionCounts = (ArrayNode) json.get("gc-collection-counts");
for (String key : keys) {
if (key.startsWith("gc-")) {
json.remove(key);
- } else if (json.get(key) instanceof JSONArray) {
- final JSONArray valueArray = json.getJSONArray(key);
+ } else if (json.get(key) instanceof ArrayNode) {
+ final ArrayNode valueArray = (ArrayNode) json.get(key);
// fixup an index of -1 to the final element in the array (i.e. RRD_SIZE)
if (index == -1) {
- index = valueArray.length() - 1;
+ index = valueArray.size() - 1;
}
final Object value = valueArray.get(index);
json.remove(key);
- json.put(key.replaceAll("s$",""), value);
+ json.putPOJO(key.replaceAll("s$",""), value);
}
}
- List<JSONObject> gcs = new ArrayList<>();
+ List<ObjectNode> gcs = new ArrayList<>();
- for (int i = 0; i < gcNames.length(); i++) {
- JSONObject gc = new JSONObject();
- gc.put("name", gcNames.get(i));
- gc.put("collection-time", ((JSONArray)gcCollectionTimes.get(i)).get(index));
- gc.put("collection-count", ((JSONArray)gcCollectionCounts.get(i)).get(index));
+ for (int i = 0; i < gcNames.size(); i++) {
+ ObjectNode gc = om.createObjectNode();
+ gc.set("name", gcNames.get(i));
+ gc.set("collection-time", ((ArrayNode)gcCollectionTimes.get(i)).get(index));
+ gc.set("collection-count", ((ArrayNode)gcCollectionCounts.get(i)).get(index));
gcs.add(gc);
}
- json.put("gcs", gcs);
+ json.putPOJO("gcs", gcs);
return json;
}
- private JSONObject processNodeConfig(IHyracksClientConnection hcc, String node) throws Exception {
+ private ObjectNode processNodeConfig(IHyracksClientConnection hcc, String node) throws Exception {
String config = hcc.getNodeDetailsJSON(node, false, true);
if (config == null) {
throw new IllegalArgumentException();
}
- return new JSONObject(config);
+ return (ObjectNode) om.readTree(config);
}
- private JSONObject processNodeThreadDump(IHyracksClientConnection hcc, String node) throws Exception {
+ private ObjectNode processNodeThreadDump(IHyracksClientConnection hcc, String node) throws Exception {
if ("cc".equals(node)) {
- return new JSONObject();
+ return om.createObjectNode();
}
String dump = hcc.getThreadDump(node);
if (dump == null) {
@@ -198,7 +205,7 @@
? new IllegalStateException()
: new IllegalArgumentException();
}
- return new JSONObject(dump);
+ return (ObjectNode) om.readTree(dump);
}
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ConnectorAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ConnectorAPIServlet.java
index ac1a5aa..78801b8 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ConnectorAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ConnectorAPIServlet.java
@@ -30,7 +30,7 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.metadata.MetadataManager;
import org.apache.asterix.metadata.MetadataTransactionContext;
import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -40,10 +40,9 @@
import org.apache.asterix.util.FlushDatasetUtils;
import org.apache.hyracks.api.client.IHyracksClientConnection;
import org.apache.hyracks.api.client.NodeControllerInfo;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.hyracks.api.io.FileSplit;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
/***
* The REST API that takes a dataverse name and a dataset name as the input
@@ -62,7 +61,8 @@
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
try {
- JSONObject jsonResponse = new JSONObject();
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode jsonResponse = om.createObjectNode();
String dataverseName = request.getParameter("dataverseName");
String datasetName = request.getParameter("datasetName");
if (dataverseName == null || datasetName == null) {
@@ -94,8 +94,8 @@
return;
}
boolean temp = dataset.getDatasetDetails().isTemp();
- FileSplit[] fileSplits =
- metadataProvider.splitsForDataset(mdTxnCtx, dataverseName, datasetName, datasetName, temp);
+ FileSplit[] fileSplits = metadataProvider.splitsForDataset(mdTxnCtx, dataverseName, datasetName,
+ datasetName, temp);
ARecordType recordType = (ARecordType) metadataProvider.findType(dataset.getItemTypeDataverseName(),
dataset.getItemTypeName());
List<List<String>> primaryKeys = DatasetUtils.getPartitioningKeys(dataset);
@@ -127,24 +127,25 @@
}
}
- private void formResponseObject(JSONObject jsonResponse, FileSplit[] fileSplits, ARecordType recordType,
+ private void formResponseObject(ObjectNode jsonResponse, FileSplit[] fileSplits, ARecordType recordType,
String primaryKeys, boolean temp, Map<String, NodeControllerInfo> nodeMap) throws Exception {
- JSONArray partititons = new JSONArray();
+ ObjectMapper om = new ObjectMapper();
+ ArrayNode partititons = om.createArrayNode();
// Whether the dataset is temp or not
jsonResponse.put("temp", temp);
// Adds a primary key.
jsonResponse.put("keys", primaryKeys);
// Adds record type.
- jsonResponse.put("type", recordType.toJSON());
+ jsonResponse.set("type", recordType.toJSON());
// Generates file partitions.
for (FileSplit split : fileSplits) {
String ipAddress = nodeMap.get(split.getNodeName()).getNetworkAddress().getAddress().toString();
String path = split.getPath();
FilePartition partition = new FilePartition(ipAddress, path);
- partititons.put(partition.toJSONObject());
+ partititons.add(partition.toObjectNode());
}
// Generates the response object which contains the splits.
- jsonResponse.put("splits", partititons);
+ jsonResponse.set("splits", partititons);
}
}
@@ -170,8 +171,9 @@
return ipAddress + ":" + path;
}
- public JSONObject toJSONObject() throws JSONException {
- JSONObject partition = new JSONObject();
+ public ObjectNode toObjectNode() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode partition = om.createObjectNode();
partition.put("ip", ipAddress);
partition.put("path", path);
return partition;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/DiagnosticsAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/DiagnosticsAPIServlet.java
index c709ab5..4416d5c 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/DiagnosticsAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/DiagnosticsAPIServlet.java
@@ -32,14 +32,14 @@
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.asterix.runtime.util.AppContextInfo;
import org.apache.hyracks.api.client.IHyracksClientConnection;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class DiagnosticsAPIServlet extends ClusterNodeDetailsAPIServlet {
private static final long serialVersionUID = 1L;
@@ -50,14 +50,16 @@
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter responseWriter = response.getWriter();
- JSONObject json;
+ ObjectNode json;
+ ObjectMapper om = new ObjectMapper();
+ om.enable(SerializationFeature.INDENT_OUTPUT);
try {
if (request.getPathInfo() != null) {
throw new IllegalArgumentException();
}
json = getClusterDiagnosticsJSON();
response.setStatus(HttpServletResponse.SC_OK);
- responseWriter.write(json.toString(4));
+ responseWriter.write(om.writerWithDefaultPrettyPrinter().writeValueAsString(json));
} catch (IllegalStateException e) { // NOSONAR - exception not logged or rethrown
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
@@ -69,47 +71,46 @@
responseWriter.flush();
}
- private JSONObject getClusterDiagnosticsJSON() throws Exception {
+ private ObjectNode getClusterDiagnosticsJSON() throws Exception {
+ ObjectMapper om = new ObjectMapper();
final ServletContext context = getServletContext();
- IHyracksClientConnection hcc =
- (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
+ IHyracksClientConnection hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
ExecutorService executor = (ExecutorService) context.getAttribute(ServletConstants.EXECUTOR_SERVICE);
- Map<String, Future<JSONObject>> ccFutureData = new HashMap<>();
- ccFutureData.put("threaddump", executor.submit(() -> fixupKeys(new JSONObject(hcc.getThreadDump(null)))));
- ccFutureData.put("config", executor.submit(() ->
- fixupKeys(new JSONObject(hcc.getNodeDetailsJSON(null, false, true)))));
- ccFutureData.put("stats", executor.submit(() ->
- fixupKeys(new JSONObject(hcc.getNodeDetailsJSON(null, true, false)))));
+ Map<String, Future<ObjectNode>> ccFutureData = new HashMap<>();
+ ccFutureData.put("threaddump",
+ executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getThreadDump(null)))));
+ ccFutureData.put("config",
+ executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getNodeDetailsJSON(null, false, true)))));
+ ccFutureData.put("stats",
+ executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getNodeDetailsJSON(null, true, false)))));
- Map<String, Map<String, Future<JSONObject>>> ncDataMap = new HashMap<>();
+ Map<String, Map<String, Future<ObjectNode>>> ncDataMap = new HashMap<>();
for (String nc : AppContextInfo.INSTANCE.getMetadataProperties().getNodeNames()) {
- Map<String, Future<JSONObject>> ncData = new HashMap<>();
- ncData.put("threaddump", executor.submit(() ->
- fixupKeys(new JSONObject(hcc.getThreadDump(nc)))));
- ncData.put("config", executor.submit(() ->
- fixupKeys(new JSONObject(hcc.getNodeDetailsJSON(nc, false, true)))));
- ncData.put("stats", executor.submit(() ->
- fixupKeys(processNodeStats(hcc, nc))));
+ Map<String, Future<ObjectNode>> ncData = new HashMap<>();
+ ncData.put("threaddump", executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getThreadDump(nc)))));
+ ncData.put("config", executor
+ .submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getNodeDetailsJSON(nc, false, true)))));
+ ncData.put("stats", executor.submit(() -> fixupKeys(processNodeStats(hcc, nc))));
ncDataMap.put(nc, ncData);
}
- JSONObject result = new JSONObject();
- result.put("cc", resolveFutures(ccFutureData));
+ ObjectNode result = om.createObjectNode();
+ result.putPOJO("cc", resolveFutures(ccFutureData));
List<Map<String, ?>> ncList = new ArrayList<>();
- for (Map.Entry<String, Map<String, Future<JSONObject>>> entry : ncDataMap.entrySet()) {
+ for (Map.Entry<String, Map<String, Future<ObjectNode>>> entry : ncDataMap.entrySet()) {
final Map<String, Object> ncMap = resolveFutures(entry.getValue());
ncMap.put("node_id", entry.getKey());
ncList.add(ncMap);
}
- result.put("ncs", ncList);
- result.put("date", new Date());
+ result.putPOJO("ncs", ncList);
+ result.putPOJO("date", new Date());
return result;
}
- private Map<String, Object> resolveFutures(Map<String, Future<JSONObject>> futureMap)
+ private Map<String, Object> resolveFutures(Map<String, Future<ObjectNode>> futureMap)
throws ExecutionException, InterruptedException {
Map<String, Object> result = new HashMap<>();
- for (Map.Entry<String, Future<JSONObject>> entry : futureMap.entrySet()) {
+ for (Map.Entry<String, Future<ObjectNode>> entry : futureMap.entrySet()) {
result.put(entry.getKey(), entry.getValue().get());
}
return result;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryResultAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryResultAPIServlet.java
index 9994bc7..b250690 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryResultAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryResultAPIServlet.java
@@ -31,6 +31,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.app.result.ResultReader;
import org.apache.asterix.app.result.ResultUtil;
import org.apache.asterix.common.exceptions.AsterixException;
@@ -42,12 +43,11 @@
import org.apache.hyracks.api.dataset.ResultSetId;
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.client.dataset.HyracksDataset;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class QueryResultAPIServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
-
private static final Logger LOGGER = Logger.getLogger(QueryResultAPIServlet.class.getName());
@Override
@@ -83,10 +83,11 @@
context.setAttribute(HYRACKS_DATASET_ATTR, hds);
}
}
- JSONObject handleObj = new JSONObject(strHandle);
- JSONArray handle = handleObj.getJSONArray("handle");
- JobId jobId = new JobId(handle.getLong(0));
- ResultSetId rsId = new ResultSetId(handle.getLong(1));
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode handleObj = (ObjectNode) om.readTree(strHandle);
+ ArrayNode handle = (ArrayNode) handleObj.get("handle");
+ JobId jobId = new JobId(handle.get(0).asLong());
+ ResultSetId rsId = new ResultSetId(handle.get(1).asLong());
ResultReader resultReader = new ResultReader(hds);
resultReader.open(jobId, rsId);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
index 9da518a..a0454fd 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
@@ -37,6 +37,7 @@
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -293,6 +294,7 @@
private static SessionConfig createSessionConfig(RequestParameters param, PrintWriter resultWriter) {
SessionConfig.ResultDecorator resultPrefix = new SessionConfig.ResultDecorator() {
int resultNo = -1;
+
@Override
public AlgebricksAppendable append(AlgebricksAppendable app) throws AlgebricksException {
app.append("\t\"");
@@ -306,16 +308,24 @@
}
};
+
SessionConfig.ResultDecorator resultPostfix = (AlgebricksAppendable app) -> app.append("\t,\n");
- SessionConfig.ResultDecorator handlePrefix = (AlgebricksAppendable app) -> app.append("\t\"").append
- (ResultFields.HANDLE.str()).append("\": ");
+ SessionConfig.ResultDecorator handlePrefix = new SessionConfig.ResultDecorator() {
+ @Override
+ public AlgebricksAppendable append(AlgebricksAppendable app) throws AlgebricksException {
+ app.append("\t\"");
+ app.append(ResultFields.HANDLE.str());
+ app.append("\": ");
+ return app;
+ }
+ };
SessionConfig.ResultDecorator handlePostfix = (AlgebricksAppendable app) -> app.append(",\n");
SessionConfig.OutputFormat format = getFormat(param.format);
- SessionConfig sessionConfig = new SessionConfig(resultWriter, format, resultPrefix, resultPostfix,
- handlePrefix, handlePostfix);
+ SessionConfig sessionConfig = new SessionConfig(resultWriter, format, resultPrefix, resultPostfix, handlePrefix,
+ handlePostfix);
sessionConfig.set(SessionConfig.FORMAT_WRAPPER_ARRAY, true);
sessionConfig.set(SessionConfig.FORMAT_INDENT_JSON, param.pretty);
sessionConfig.set(SessionConfig.FORMAT_QUOTE_RECORD,
@@ -376,7 +386,7 @@
printField(pw, ResultFields.STATUS.str(), rs.str());
}
- private static void printError(PrintWriter pw, Throwable e) {
+ private static void printError(PrintWriter pw, Throwable e) throws JsonProcessingException {
Throwable rootCause = ResultUtil.getRootCause(e);
if (rootCause == null) {
rootCause = e;
@@ -386,16 +396,10 @@
pw.print(ResultFields.ERRORS.str());
pw.print("\": [{ \n");
printField(pw, ErrorField.CODE.str(), "1");
+
final String msg = rootCause.getMessage();
printField(pw, ErrorField.MSG.str(), JSONUtil.escape(msg != null ? msg : rootCause.getClass().getSimpleName()),
addStack);
- if (addStack) {
- StringWriter sw = new StringWriter();
- PrintWriter stackWriter = new PrintWriter(sw);
- LOGGER.info(stackWriter.toString());
- stackWriter.close();
- printField(pw, ErrorField.STACK.str(), JSONUtil.escape(sw.toString()), false);
- }
pw.print("\t}],\n");
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryStatusAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryStatusAPIServlet.java
index 9555e11..6d1b1b2 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryStatusAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryStatusAPIServlet.java
@@ -29,14 +29,15 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.app.result.ResultReader;
import org.apache.hyracks.api.client.IHyracksClientConnection;
import org.apache.hyracks.api.dataset.IHyracksDataset;
import org.apache.hyracks.api.dataset.ResultSetId;
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.client.dataset.HyracksDataset;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class QueryStatusAPIServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -61,10 +62,11 @@
context.setAttribute(HYRACKS_DATASET_ATTR, hds);
}
}
- JSONObject handleObj = new JSONObject(strHandle);
- JSONArray handle = handleObj.getJSONArray("handle");
- JobId jobId = new JobId(handle.getLong(0));
- ResultSetId rsId = new ResultSetId(handle.getLong(1));
+ ObjectMapper om = new ObjectMapper();
+ JsonNode handleObj = om.readTree(strHandle);
+ JsonNode handle = handleObj.get("handle");
+ JobId jobId = new JobId(handle.get(0).asLong());
+ ResultSetId rsId = new ResultSetId(handle.get(1).asLong());
/* TODO(madhusudancs): We need to find a way to LOSSLESS_JSON serialize default format obtained from
* metadataProvider in the AQLTranslator and store it as part of the result handle.
@@ -72,7 +74,7 @@
ResultReader resultReader = new ResultReader(hds);
resultReader.open(jobId, rsId);
- JSONObject jsonResponse = new JSONObject();
+ ObjectNode jsonResponse = om.createObjectNode();
String status;
switch (resultReader.getStatus()) {
case RUNNING:
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryWebInterfaceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryWebInterfaceServlet.java
index 383d8fd..d3e5556 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryWebInterfaceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryWebInterfaceServlet.java
@@ -30,12 +30,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.config.ExternalProperties;
import org.apache.asterix.runtime.util.AppContextInfo;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codehaus.jettison.json.JSONObject;
public class QueryWebInterfaceServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -110,7 +111,8 @@
response.setCharacterEncoding("utf-8");
response.setContentType("application/json");
ExternalProperties externalProperties = AppContextInfo.INSTANCE.getExternalProperties();
- JSONObject obj = new JSONObject();
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode obj = om.createObjectNode();
try {
PrintWriter out = response.getWriter();
obj.put("api_port", String.valueOf(externalProperties.getAPIServerPort()));
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/RESTAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/RESTAPIServlet.java
index 4a06590..dd030b0 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/RESTAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/RESTAPIServlet.java
@@ -33,6 +33,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.app.result.ResultReader;
import org.apache.asterix.app.result.ResultUtil;
import org.apache.asterix.app.translator.QueryTranslator;
@@ -53,7 +54,7 @@
import org.apache.hyracks.api.client.IHyracksClientConnection;
import org.apache.hyracks.api.dataset.IHyracksDataset;
import org.apache.hyracks.client.dataset.HyracksDataset;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
abstract class RESTAPIServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -211,9 +212,9 @@
} catch (AsterixException | TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError pe) {
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
String errorMessage = ResultUtil.buildParseExceptionMessage(pe, query);
- JSONObject errorResp =
+ ObjectNode errorResp =
ResultUtil.getErrorResponse(2, errorMessage, "", ResultUtil.extractFullStackTrace(pe));
- sessionConfig.out().write(errorResp.toString());
+ sessionConfig.out().write(new ObjectMapper().writeValueAsString(errorResp));
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (Exception e) {
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
index d99b379..d07166e 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
@@ -31,11 +31,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.config.GlobalConfig;
import org.apache.asterix.runtime.util.ClusterStateManager;
import org.apache.hyracks.api.client.IHyracksClientConnection;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ShutdownAPIServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -62,25 +64,25 @@
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.setStatus(HttpServletResponse.SC_ACCEPTED);
- JSONObject jsonObject = new JSONObject();
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode jsonObject = om.createObjectNode();
try {
jsonObject.put("status", "SHUTTING_DOWN");
- jsonObject.put("date", new Date());
- JSONObject clusterState = ClusterStateManager.INSTANCE.getClusterStateDescription();
- JSONArray ncs = clusterState.getJSONArray("ncs");
- for (int i = 0; i < ncs.length(); i++) {
- JSONObject nc = ncs.getJSONObject(i);
- String node = nc.getString(NODE_ID_KEY);
- JSONObject details = new JSONObject(hcc.getNodeDetailsJSON(node, false, true));
- nc.put(PID, details.get(PID));
- if (details.has(INI) && details.getJSONObject(INI).has(NCSERVICE_PID)) {
- nc.put(NCSERVICE_PID, details.getJSONObject(INI).getInt(NCSERVICE_PID));
+ jsonObject.putPOJO("date", new Date());
+ ObjectNode clusterState = ClusterStateManager.INSTANCE.getClusterStateDescription();
+ ArrayNode ncs = (ArrayNode) clusterState.get("ncs");
+ for (int i = 0; i < ncs.size(); i++) {
+ ObjectNode nc = (ObjectNode) ncs.get(i);
+ String node = nc.get(NODE_ID_KEY).asText();
+ ObjectNode details = (ObjectNode) om.readTree(hcc.getNodeDetailsJSON(node, false, true));
+ nc.set(PID, details.get(PID));
+ if (details.has(INI) && details.get(INI).has(NCSERVICE_PID)) {
+ nc.put(NCSERVICE_PID, details.get(INI).get(NCSERVICE_PID).asInt());
}
}
- jsonObject.put("cluster", clusterState);
-
+ jsonObject.set("cluster", clusterState);
final PrintWriter writer = response.getWriter();
- writer.print(jsonObject.toString(4));
+ writer.print(om.writeValueAsString(jsonObject));
writer.close();
} catch (Exception e) {
GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, "Exception writing response", e);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/VersionAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/VersionAPIServlet.java
index c1ce344..398a355 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/VersionAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/VersionAPIServlet.java
@@ -27,8 +27,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.runtime.util.AppContextInfo;
-import org.json.JSONObject;
import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_BUILD_PROP_ATTR;
@@ -40,7 +41,11 @@
ServletContext context = getServletContext();
AppContextInfo props = (AppContextInfo) context.getAttribute(ASTERIX_BUILD_PROP_ATTR);
Map<String, String> buildProperties = props.getBuildProperties().getAllProps();
- JSONObject responseObject = new JSONObject(buildProperties);
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode responseObject = om.createObjectNode();
+ for (Map.Entry<String, String> e : buildProperties.entrySet()) {
+ responseObject.put(e.getKey(), e.getValue());
+ }
response.setCharacterEncoding("utf-8");
PrintWriter responseWriter = response.getWriter();
responseWriter.write(responseObject.toString());
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
index 22034c3..5465fbd 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultPrinter.java
@@ -24,6 +24,9 @@
import java.io.StringWriter;
import java.nio.ByteBuffer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.utils.JSONUtil;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.translator.IStatementExecutor.Stats;
@@ -126,13 +129,20 @@
if (conf.is(SessionConfig.FORMAT_HTML)) {
conf.out().println("</pre>");
}
+ conf.out().flush();
}
- private void printRecord(String result) {
+ private void displayRecord(String result) throws HyracksDataException {
+ ObjectMapper om = new ObjectMapper();
+ om.enable(SerializationFeature.INDENT_OUTPUT);
String record = result;
if (indentJSON) {
// TODO(tillw): this is inefficient - do this during record generation
- record = JSONUtil.indent(record, 2);
+ try {
+ record = om.writerWithDefaultPrettyPrinter().writeValueAsString(om.readValue(result, ObjectNode.class));
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
}
if (conf.fmt() == SessionConfig.OutputFormat.CSV) {
// TODO(tillw): this is inefficient as well
@@ -152,7 +162,7 @@
printPrefix();
// TODO(tillw) evil hack
quoteRecord = true;
- printRecord(record);
+ displayRecord(record);
printPostfix();
}
@@ -179,7 +189,11 @@
conf.out().print(", ");
}
notFirst = true;
- printRecord(result);
+ try {
+ displayRecord(result);
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
}
frameBuffer.clear();
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultUtil.java
index 595c6ab..80b8ffe 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultUtil.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ResultUtil.java
@@ -33,6 +33,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.api.http.servlet.APIServlet;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.translator.IStatementExecutor.Stats;
@@ -42,9 +43,9 @@
import org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendable;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.log4j.Logger;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ResultUtil {
private static final Logger LOGGER = Logger.getLogger(ResultUtil.class.getName());
@@ -94,25 +95,21 @@
}
}
- public static JSONObject getErrorResponse(int errorCode, String errorMessage, String errorSummary,
+ public static ObjectNode getErrorResponse(int errorCode, String errorMessage, String errorSummary,
String errorStackTrace) {
- JSONObject errorResp = new JSONObject();
- JSONArray errorArray = new JSONArray();
- errorArray.put(errorCode);
- errorArray.put(errorMessage);
- try {
- errorResp.put("error-code", errorArray);
- if (!"".equals(errorSummary)) {
- errorResp.put("summary", errorSummary);
- } else {
- //parse exception
- errorResp.put("summary", errorMessage);
- }
- errorResp.put("stacktrace", errorStackTrace);
- } catch (JSONException e) {
- LOGGER.warn("Failed to build the result's JSON object", e);
- // TODO(madhusudancs): Figure out what to do when JSONException occurs while building the results.
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode errorResp = om.createObjectNode();
+ ArrayNode errorArray = om.createArrayNode();
+ errorArray.add(errorCode);
+ errorArray.add(errorMessage);
+ errorResp.set("error-code", errorArray);
+ if (!"".equals(errorSummary)) {
+ errorResp.put("summary", errorSummary);
+ } else {
+ //parse exception
+ errorResp.put("summary", errorMessage);
}
+ errorResp.put("stacktrace", errorStackTrace);
return errorResp;
}
@@ -141,7 +138,7 @@
errorCode = 4;
}
- JSONObject errorResp = ResultUtil.getErrorResponse(errorCode, extractErrorMessage(e), extractErrorSummary(e),
+ ObjectNode errorResp = ResultUtil.getErrorResponse(errorCode, extractErrorMessage(e), extractErrorSummary(e),
extractFullStackTrace(e));
out.write(errorResp.toString());
}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 906525c..593adb2 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -40,6 +40,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.active.ActiveJobNotificationHandler;
import org.apache.asterix.active.ActivityState;
import org.apache.asterix.active.EntityId;
@@ -205,6 +206,9 @@
import org.apache.hyracks.api.job.JobId;
import org.apache.hyracks.api.job.JobSpecification;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
@@ -2589,15 +2593,15 @@
private void handleQueryResult(MetadataProvider metadataProvider, IHyracksClientConnection hcc,
IHyracksDataset hdc, JobSpecification jobSpec, ResultDelivery resultDelivery, Stats stats)
throws Exception {
- if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.FINE)) {
- GlobalConfig.ASTERIX_LOGGER.fine(jobSpec.toJSON().toString(1));
- }
JobId jobId = JobUtils.runJob(hcc, jobSpec, false);
+ ResultHandle hand;
switch (resultDelivery) {
case ASYNC:
- ResultUtil.printResultHandle(new ResultHandle(jobId, metadataProvider.getResultSetId()), sessionConfig);
+ hand = new ResultHandle(jobId,metadataProvider.getResultSetId());
+ ResultUtil.printResultHandle(hand,sessionConfig);
hcc.waitForCompletion(jobId);
+ sessionConfig.out().flush();
break;
case IMMEDIATE:
hcc.waitForCompletion(jobId);
@@ -2607,7 +2611,9 @@
break;
case DEFERRED:
hcc.waitForCompletion(jobId);
- ResultUtil.printResultHandle(new ResultHandle(jobId, metadataProvider.getResultSetId()), sessionConfig);
+ hand = new ResultHandle(jobId,metadataProvider.getResultSetId());
+ ResultUtil.printResultHandle(hand,sessionConfig);
+ sessionConfig.out().flush();
break;
default:
break;
@@ -3237,4 +3243,4 @@
}
return recordNameTypesMap;
}
-}
\ No newline at end of file
+}
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/ConnectorAPIServletTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/ConnectorAPIServletTest.java
index fdcbad5..48d1c1c 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/ConnectorAPIServletTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/ConnectorAPIServletTest.java
@@ -36,6 +36,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.metadata.MetadataManager;
import org.apache.asterix.metadata.MetadataTransactionContext;
import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -48,10 +49,10 @@
import org.apache.hyracks.api.client.IHyracksClientConnection;
import org.apache.hyracks.api.client.NodeControllerInfo;
import org.apache.hyracks.api.comm.NetworkAddress;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.hyracks.api.io.FileSplit;
import org.apache.hyracks.api.io.ManagedFileSplit;
-import org.json.JSONArray;
-import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Assert;
import org.junit.Test;
@@ -97,22 +98,21 @@
servlet.doGet(mockRequest, mockResponse);
// Constructs the actual response.
- JSONTokener tokener = new JSONTokener(
- new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray())));
- JSONObject actualResponse = new JSONObject(tokener);
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toString());
// Checks the temp-or-not, primary key, data type of the dataset.
- boolean temp = actualResponse.getBoolean("temp");
+ boolean temp = actualResponse.get("temp").asBoolean();
Assert.assertFalse(temp);
- String primaryKey = actualResponse.getString("keys");
+ String primaryKey = actualResponse.get("keys").asText();
Assert.assertEquals("DataverseName,DatasetName", primaryKey);
ARecordType recordType = (ARecordType) JSONDeserializerForTypes
- .convertFromJSON((JSONObject) actualResponse.get("type"));
+ .convertFromJSON((ObjectNode) actualResponse.get("type"));
Assert.assertEquals(getMetadataRecordType("Metadata", "Dataset"), recordType);
// Checks the correctness of results.
- JSONArray splits = actualResponse.getJSONArray("splits");
- String path = ((JSONObject) splits.get(0)).getString("path");
+ ArrayNode splits = (ArrayNode) actualResponse.get("splits");
+ String path = (splits.get(0)).get("path").asText();
Assert.assertTrue(path.endsWith("Metadata/Dataset_idx_Dataset"));
// Tears down the asterixdb cluster.
@@ -122,7 +122,8 @@
@Test
public void testFormResponseObject() throws Exception {
ConnectorAPIServlet servlet = new ConnectorAPIServlet();
- JSONObject actualResponse = new JSONObject();
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode actualResponse = om.createObjectNode();
FileSplit[] splits = new FileSplit[2];
splits[0] = new ManagedFileSplit("asterix_nc1", "foo1");
splits[1] = new ManagedFileSplit("asterix_nc2", "foo2");
@@ -142,24 +143,24 @@
// Calls ConnectorAPIServlet.formResponseObject.
nodeMap.put("asterix_nc1", mockInfo1);
nodeMap.put("asterix_nc2", mockInfo2);
- PA.invokeMethod(servlet, "formResponseObject(" + JSONObject.class.getName() + ", " + FileSplit.class.getName()
+ PA.invokeMethod(servlet, "formResponseObject(" + ObjectNode.class.getName() + ", " + FileSplit.class.getName()
+ "[], " + ARecordType.class.getName() + ", " + String.class.getName() + ", boolean, " + Map.class
.getName() + ")", actualResponse, splits, recordType, primaryKey, true, nodeMap);
// Constructs expected response.
- JSONObject expectedResponse = new JSONObject();
+ ObjectNode expectedResponse = om.createObjectNode();
expectedResponse.put("temp", true);
expectedResponse.put("keys", primaryKey);
- expectedResponse.put("type", recordType.toJSON());
- JSONArray splitsArray = new JSONArray();
- JSONObject element1 = new JSONObject();
+ expectedResponse.set("type", recordType.toJSON());
+ ArrayNode splitsArray = om.createArrayNode();
+ ObjectNode element1 = om.createObjectNode();
element1.put("ip", "127.0.0.1");
element1.put("path", splits[0].getPath());
- JSONObject element2 = new JSONObject();
+ ObjectNode element2 = om.createObjectNode();
element2.put("ip", "127.0.0.2");
element2.put("path", splits[1].getPath());
- splitsArray.put(element1);
- splitsArray.put(element2);
- expectedResponse.put("splits", splitsArray);
+ splitsArray.add(element1);
+ splitsArray.add(element2);
+ expectedResponse.set("splits", splitsArray);
// Checks results.
Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionAPIServletTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionAPIServletTest.java
index 2209fc5..da0ec0c 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionAPIServletTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionAPIServletTest.java
@@ -37,12 +37,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.config.BuildProperties;
import org.apache.asterix.runtime.util.AppContextInfo;
import org.apache.asterix.test.runtime.SqlppExecutionTest;
import org.apache.hyracks.api.client.IHyracksClientConnection;
-import org.json.JSONObject;
-import org.json.JSONTokener;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Assert;
import org.junit.Test;
@@ -103,10 +103,13 @@
servlet.doGet(mockRequest, mockResponse);
// Constructs the actual response.
- JSONTokener tokener = new JSONTokener(
- new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray())));
- JSONObject actualResponse = new JSONObject(tokener);
- JSONObject expectedResponse = new JSONObject(propMap);
+
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toByteArray());
+ ObjectNode expectedResponse = om.createObjectNode();
+ for (Map.Entry<String, String> e : propMap.entrySet()) {
+ expectedResponse.put(e.getKey(), e.getValue());
+ }
// Checks the response contains all the expected keys.
Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/any-object/any-object.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/any-object/any-object.2.query.sqlpp
index 91a980e..afaa5b1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/any-object/any-object.2.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/any-object/any-object.2.query.sqlpp
@@ -17,6 +17,4 @@
* under the License.
*/
-select element x
-from Metadata.Datatype as x
-order by x.DataverseName, x.DatatypeName;
+select element x from Metadata.Datatype as x;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1/cluster_state_1.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1/cluster_state_1.1.adm
index 15b1baa..746b75d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1/cluster_state_1.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1/cluster_state_1.1.adm
@@ -1,129 +1,162 @@
{
- "cc": {
- "configUri": "http://127.0.0.1:19002/admin/cluster/cc/config",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/cc/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ "cc" : {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/cc/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/cc/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ },
+ "config" : {
+ "api.port" : 19002,
+ "cluster.partitions" : {
+ "0" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "1" : {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ },
+ "2" : {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "3" : {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ }
},
- "config": {
- "api.port": 19002,
- "cluster.partitions": {
- "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1",
- "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- },
- "compiler.framesize": 32768,
- "compiler.groupmemory": 163840,
- "compiler.joinmemory": 262144,
- "compiler.parallelism": 0,
- "compiler.pregelix.home": "~/pregelix",
- "compiler.sortmemory": 327680,
- "core.dump.paths": {},
- "feed.central.manager.port": 4500,
- "feed.max.threshold.period": 5,
- "feed.memory.available.wait.timeout": 10,
- "feed.memory.global.budget": 67108864,
- "feed.pending.work.threshold": 50,
- "feed.port": 19003,
- "instance.name": null,
- "log.level": "INFO",
- "max.wait.active.cluster": 60,
- "metadata.callback.port": 0,
- "metadata.node": "asterix_nc1",
- "metadata.partition": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "metadata.port": 0,
- "metadata.registration.timeout.secs": 60,
- "node.partitions": {
- "asterix_nc1": [
- "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1"
- ],
- "asterix_nc2": [
- "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- ]
- },
- "node.stores": {
- "asterix_nc1": [
- "iodevice0",
- "iodevice1"
- ],
- "asterix_nc2": [
- "iodevice0",
- "iodevice1"
- ]
- },
- "plot.activate": false,
- "storage.buffercache.maxopenfiles": 2147483647,
- "storage.buffercache.pagesize": 32768,
- "storage.buffercache.size": 50331648,
- "storage.lsm.bloomfilter.falsepositiverate": 0.01,
- "storage.memorycomponent.globalbudget": 536870912,
- "storage.memorycomponent.numcomponents": 2,
- "storage.memorycomponent.numpages": 8,
- "storage.memorycomponent.pagesize": 131072,
- "storage.metadata.memorycomponent.numpages": 256,
- "transaction.log.dirs": {
- "asterix_nc1": "target/txnLogDir/asterix_nc1",
- "asterix_nc2": "target/txnLogDir/asterix_nc2"
- },
- "txn.commitprofiler.reportinterval": 5,
- "txn.job.recovery.memorysize": 67108864,
- "txn.lock.escalationthreshold": 1000,
- "txn.lock.shrinktimer": 5000,
- "txn.lock.timeout.sweepthreshold": 10000,
- "txn.lock.timeout.waitthreshold": 60000,
- "txn.log.buffer.numpages": 8,
- "txn.log.buffer.pagesize": 131072,
- "txn.log.checkpoint.history": 0,
- "txn.log.checkpoint.lsnthreshold": 67108864,
- "txn.log.checkpoint.pollfrequency": 120,
- "txn.log.partitionsize": 268435456,
- "web.port": 19001,
- "web.queryinterface.port": 19006,
- "web.secondary.port": 19005
+ "compiler.framesize" : 32768,
+ "compiler.groupmemory" : 163840,
+ "compiler.joinmemory" : 262144,
+ "compiler.parallelism" : 0,
+ "compiler.pregelix.home" : "~/pregelix",
+ "compiler.sortmemory" : 327680,
+ "core.dump.paths" : { },
+ "feed.central.manager.port" : 4500,
+ "feed.max.threshold.period" : 5,
+ "feed.memory.available.wait.timeout" : 10,
+ "feed.memory.global.budget" : 67108864,
+ "feed.pending.work.threshold" : 50,
+ "feed.port" : 19003,
+ "instance.name" : null,
+ "log.level" : "INFO",
+ "max.wait.active.cluster" : 60,
+ "metadata.callback.port" : 0,
+ "metadata.node" : "asterix_nc1",
+ "metadata.partition" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
},
- "diagnosticsUri": "http://127.0.0.1:19002/admin/diagnostics",
- "fullShutdownUri": "http://127.0.0.1:19002/admin/shutdown?all=true",
- "metadata_node": "asterix_nc1",
- "ncs": [
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
- "node_id": "asterix_nc1",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_0"
- },
- {
- "active": true,
- "partition_id": "partition_1"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
- },
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
- "node_id": "asterix_nc2",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_2"
- },
- {
- "active": true,
- "partition_id": "partition_3"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
- }
- ],
- "replicationUri": "http://127.0.0.1:19002/admin/cluster/replication",
- "shutdownUri": "http://127.0.0.1:19002/admin/shutdown",
- "state": "ACTIVE",
- "versionUri": "http://127.0.0.1:19002/admin/version"
+ "metadata.port" : 0,
+ "metadata.registration.timeout.secs" : 60,
+ "node.partitions" : {
+ "asterix_nc1" : [ {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ],
+ "asterix_nc2" : [ {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ]
+ },
+ "node.stores" : {
+ "asterix_nc1" : [ "iodevice0", "iodevice1" ],
+ "asterix_nc2" : [ "iodevice0", "iodevice1" ]
+ },
+ "plot.activate" : false,
+ "storage.buffercache.maxopenfiles" : 2147483647,
+ "storage.buffercache.pagesize" : 32768,
+ "storage.buffercache.size" : 50331648,
+ "storage.lsm.bloomfilter.falsepositiverate" : 0.01,
+ "storage.memorycomponent.globalbudget" : 536870912,
+ "storage.memorycomponent.numcomponents" : 2,
+ "storage.memorycomponent.numpages" : 8,
+ "storage.memorycomponent.pagesize" : 131072,
+ "storage.metadata.memorycomponent.numpages" : 256,
+ "transaction.log.dirs" : {
+ "asterix_nc1" : "target/txnLogDir/asterix_nc1",
+ "asterix_nc2" : "target/txnLogDir/asterix_nc2"
+ },
+ "txn.commitprofiler.reportinterval" : 5,
+ "txn.job.recovery.memorysize" : 67108864,
+ "txn.lock.escalationthreshold" : 1000,
+ "txn.lock.shrinktimer" : 5000,
+ "txn.lock.timeout.sweepthreshold" : 10000,
+ "txn.lock.timeout.waitthreshold" : 60000,
+ "txn.log.buffer.numpages" : 8,
+ "txn.log.buffer.pagesize" : 131072,
+ "txn.log.checkpoint.history" : 0,
+ "txn.log.checkpoint.lsnthreshold" : 67108864,
+ "txn.log.checkpoint.pollfrequency" : 120,
+ "txn.log.partitionsize" : 268435456,
+ "web.port" : 19001,
+ "web.queryinterface.port" : 19006,
+ "web.secondary.port" : 19005
+ },
+ "diagnosticsUri" : "http://127.0.0.1:19002/admin/diagnostics",
+ "fullShutdownUri" : "http://127.0.0.1:19002/admin/shutdown?all=true",
+ "metadata_node" : "asterix_nc1",
+ "ncs" : [ {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
+ "node_id" : "asterix_nc1",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_0"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_1"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
+ }, {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
+ "node_id" : "asterix_nc2",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_2"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_3"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
+ } ],
+ "replicationUri" : "http://127.0.0.1:19002/admin/cluster/replication",
+ "shutdownUri" : "http://127.0.0.1:19002/admin/shutdown",
+ "state" : "ACTIVE",
+ "versionUri" : "http://127.0.0.1:19002/admin/version"
}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_full/cluster_state_1_full.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_full/cluster_state_1_full.1.adm
index 11e964c..7818a58 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_full/cluster_state_1_full.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_full/cluster_state_1_full.1.adm
@@ -1,129 +1,162 @@
{
- "cc": {
- "configUri": "http://127.0.0.1:19002/admin/cluster/cc/config",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/cc/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ "cc" : {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/cc/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/cc/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ },
+ "config" : {
+ "api.port" : 19002,
+ "cluster.partitions" : {
+ "0" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "1" : {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ },
+ "2" : {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "3" : {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ }
},
- "config": {
- "api.port": 19002,
- "cluster.partitions": {
- "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1",
- "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- },
- "compiler.framesize": 32768,
- "compiler.groupmemory": 163840,
- "compiler.joinmemory": 262144,
- "compiler.parallelism": -1,
- "compiler.pregelix.home": "~/pregelix",
- "compiler.sortmemory": 327680,
- "core.dump.paths": {},
- "feed.central.manager.port": 4500,
- "feed.max.threshold.period": 5,
- "feed.memory.available.wait.timeout": 10,
- "feed.memory.global.budget": 67108864,
- "feed.pending.work.threshold": 50,
- "feed.port": 19003,
- "instance.name": null,
- "log.level": "INFO",
- "max.wait.active.cluster": 60,
- "metadata.callback.port": 0,
- "metadata.node": "asterix_nc1",
- "metadata.partition": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "metadata.port": 0,
- "metadata.registration.timeout.secs": 60,
- "node.partitions": {
- "asterix_nc1": [
- "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1"
- ],
- "asterix_nc2": [
- "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- ]
- },
- "node.stores": {
- "asterix_nc1": [
- "iodevice0",
- "iodevice1"
- ],
- "asterix_nc2": [
- "iodevice0",
- "iodevice1"
- ]
- },
- "plot.activate": false,
- "storage.buffercache.maxopenfiles": 2147483647,
- "storage.buffercache.pagesize": 32768,
- "storage.buffercache.size": 50331648,
- "storage.lsm.bloomfilter.falsepositiverate": 0.01,
- "storage.memorycomponent.globalbudget": 536870912,
- "storage.memorycomponent.numcomponents": 2,
- "storage.memorycomponent.numpages": 8,
- "storage.memorycomponent.pagesize": 131072,
- "storage.metadata.memorycomponent.numpages": 256,
- "transaction.log.dirs": {
- "asterix_nc1": "target/txnLogDir/asterix_nc1",
- "asterix_nc2": "target/txnLogDir/asterix_nc2"
- },
- "txn.commitprofiler.reportinterval": 5,
- "txn.job.recovery.memorysize": 67108864,
- "txn.lock.escalationthreshold": 1000,
- "txn.lock.shrinktimer": 5000,
- "txn.lock.timeout.sweepthreshold": 10000,
- "txn.lock.timeout.waitthreshold": 60000,
- "txn.log.buffer.numpages": 8,
- "txn.log.buffer.pagesize": 131072,
- "txn.log.checkpoint.history": 0,
- "txn.log.checkpoint.lsnthreshold": 67108864,
- "txn.log.checkpoint.pollfrequency": 120,
- "txn.log.partitionsize": 268435456,
- "web.port": 19001,
- "web.queryinterface.port": 19006,
- "web.secondary.port": 19005
+ "compiler.framesize" : 32768,
+ "compiler.groupmemory" : 163840,
+ "compiler.joinmemory" : 262144,
+ "compiler.parallelism" : -1,
+ "compiler.pregelix.home" : "~/pregelix",
+ "compiler.sortmemory" : 327680,
+ "core.dump.paths" : { },
+ "feed.central.manager.port" : 4500,
+ "feed.max.threshold.period" : 5,
+ "feed.memory.available.wait.timeout" : 10,
+ "feed.memory.global.budget" : 67108864,
+ "feed.pending.work.threshold" : 50,
+ "feed.port" : 19003,
+ "instance.name" : null,
+ "log.level" : "INFO",
+ "max.wait.active.cluster" : 60,
+ "metadata.callback.port" : 0,
+ "metadata.node" : "asterix_nc1",
+ "metadata.partition" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
},
- "diagnosticsUri": "http://127.0.0.1:19002/admin/diagnostics",
- "fullShutdownUri": "http://127.0.0.1:19002/admin/shutdown?all=true",
- "metadata_node": "asterix_nc1",
- "ncs": [
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
- "node_id": "asterix_nc1",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_0"
- },
- {
- "active": true,
- "partition_id": "partition_1"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
- },
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
- "node_id": "asterix_nc2",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_2"
- },
- {
- "active": true,
- "partition_id": "partition_3"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
- }
- ],
- "replicationUri": "http://127.0.0.1:19002/admin/cluster/replication",
- "shutdownUri": "http://127.0.0.1:19002/admin/shutdown",
- "state": "ACTIVE",
- "versionUri": "http://127.0.0.1:19002/admin/version"
+ "metadata.port" : 0,
+ "metadata.registration.timeout.secs" : 60,
+ "node.partitions" : {
+ "asterix_nc1" : [ {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ],
+ "asterix_nc2" : [ {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ]
+ },
+ "node.stores" : {
+ "asterix_nc1" : [ "iodevice0", "iodevice1" ],
+ "asterix_nc2" : [ "iodevice0", "iodevice1" ]
+ },
+ "plot.activate" : false,
+ "storage.buffercache.maxopenfiles" : 2147483647,
+ "storage.buffercache.pagesize" : 32768,
+ "storage.buffercache.size" : 50331648,
+ "storage.lsm.bloomfilter.falsepositiverate" : 0.01,
+ "storage.memorycomponent.globalbudget" : 536870912,
+ "storage.memorycomponent.numcomponents" : 2,
+ "storage.memorycomponent.numpages" : 8,
+ "storage.memorycomponent.pagesize" : 131072,
+ "storage.metadata.memorycomponent.numpages" : 256,
+ "transaction.log.dirs" : {
+ "asterix_nc1" : "target/txnLogDir/asterix_nc1",
+ "asterix_nc2" : "target/txnLogDir/asterix_nc2"
+ },
+ "txn.commitprofiler.reportinterval" : 5,
+ "txn.job.recovery.memorysize" : 67108864,
+ "txn.lock.escalationthreshold" : 1000,
+ "txn.lock.shrinktimer" : 5000,
+ "txn.lock.timeout.sweepthreshold" : 10000,
+ "txn.lock.timeout.waitthreshold" : 60000,
+ "txn.log.buffer.numpages" : 8,
+ "txn.log.buffer.pagesize" : 131072,
+ "txn.log.checkpoint.history" : 0,
+ "txn.log.checkpoint.lsnthreshold" : 67108864,
+ "txn.log.checkpoint.pollfrequency" : 120,
+ "txn.log.partitionsize" : 268435456,
+ "web.port" : 19001,
+ "web.queryinterface.port" : 19006,
+ "web.secondary.port" : 19005
+ },
+ "diagnosticsUri" : "http://127.0.0.1:19002/admin/diagnostics",
+ "fullShutdownUri" : "http://127.0.0.1:19002/admin/shutdown?all=true",
+ "metadata_node" : "asterix_nc1",
+ "ncs" : [ {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
+ "node_id" : "asterix_nc1",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_0"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_1"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
+ }, {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
+ "node_id" : "asterix_nc2",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_2"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_3"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
+ } ],
+ "replicationUri" : "http://127.0.0.1:19002/admin/cluster/replication",
+ "shutdownUri" : "http://127.0.0.1:19002/admin/shutdown",
+ "state" : "ACTIVE",
+ "versionUri" : "http://127.0.0.1:19002/admin/version"
}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_less/cluster_state_1_less.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_less/cluster_state_1_less.1.adm
index 83f18f1..71d6f8a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_less/cluster_state_1_less.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_1_less/cluster_state_1_less.1.adm
@@ -1,129 +1,162 @@
{
- "cc": {
- "configUri": "http://127.0.0.1:19002/admin/cluster/cc/config",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/cc/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ "cc" : {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/cc/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/cc/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+ },
+ "config" : {
+ "api.port" : 19002,
+ "cluster.partitions" : {
+ "0" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "1" : {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ },
+ "2" : {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "3" : {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ }
},
- "config": {
- "api.port": 19002,
- "cluster.partitions": {
- "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1",
- "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- },
- "compiler.framesize": 32768,
- "compiler.groupmemory": 163840,
- "compiler.joinmemory": 262144,
- "compiler.parallelism": 3,
- "compiler.pregelix.home": "~/pregelix",
- "compiler.sortmemory": 327680,
- "core.dump.paths": {},
- "feed.central.manager.port": 4500,
- "feed.max.threshold.period": 5,
- "feed.memory.available.wait.timeout": 10,
- "feed.memory.global.budget": 67108864,
- "feed.pending.work.threshold": 50,
- "feed.port": 19003,
- "instance.name": null,
- "log.level": "INFO",
- "max.wait.active.cluster": 60,
- "metadata.callback.port": 0,
- "metadata.node": "asterix_nc1",
- "metadata.partition": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "metadata.port": 0,
- "metadata.registration.timeout.secs": 60,
- "node.partitions": {
- "asterix_nc1": [
- "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1"
- ],
- "asterix_nc2": [
- "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
- ]
- },
- "node.stores": {
- "asterix_nc1": [
- "iodevice0",
- "iodevice1"
- ],
- "asterix_nc2": [
- "iodevice0",
- "iodevice1"
- ]
- },
- "plot.activate": false,
- "storage.buffercache.maxopenfiles": 2147483647,
- "storage.buffercache.pagesize": 32768,
- "storage.buffercache.size": 50331648,
- "storage.lsm.bloomfilter.falsepositiverate": 0.01,
- "storage.memorycomponent.globalbudget": 536870912,
- "storage.memorycomponent.numcomponents": 2,
- "storage.memorycomponent.numpages": 8,
- "storage.memorycomponent.pagesize": 131072,
- "storage.metadata.memorycomponent.numpages": 256,
- "transaction.log.dirs": {
- "asterix_nc1": "target/txnLogDir/asterix_nc1",
- "asterix_nc2": "target/txnLogDir/asterix_nc2"
- },
- "txn.commitprofiler.reportinterval": 5,
- "txn.job.recovery.memorysize": 67108864,
- "txn.lock.escalationthreshold": 1000,
- "txn.lock.shrinktimer": 5000,
- "txn.lock.timeout.sweepthreshold": 10000,
- "txn.lock.timeout.waitthreshold": 60000,
- "txn.log.buffer.numpages": 8,
- "txn.log.buffer.pagesize": 131072,
- "txn.log.checkpoint.history": 0,
- "txn.log.checkpoint.lsnthreshold": 67108864,
- "txn.log.checkpoint.pollfrequency": 120,
- "txn.log.partitionsize": 268435456,
- "web.port": 19001,
- "web.queryinterface.port": 19006,
- "web.secondary.port": 19005
+ "compiler.framesize" : 32768,
+ "compiler.groupmemory" : 163840,
+ "compiler.joinmemory" : 262144,
+ "compiler.parallelism" : 3,
+ "compiler.pregelix.home" : "~/pregelix",
+ "compiler.sortmemory" : 327680,
+ "core.dump.paths" : { },
+ "feed.central.manager.port" : 4500,
+ "feed.max.threshold.period" : 5,
+ "feed.memory.available.wait.timeout" : 10,
+ "feed.memory.global.budget" : 67108864,
+ "feed.pending.work.threshold" : 50,
+ "feed.port" : 19003,
+ "instance.name" : null,
+ "log.level" : "INFO",
+ "max.wait.active.cluster" : 60,
+ "metadata.callback.port" : 0,
+ "metadata.node" : "asterix_nc1",
+ "metadata.partition" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
},
- "diagnosticsUri": "http://127.0.0.1:19002/admin/diagnostics",
- "fullShutdownUri": "http://127.0.0.1:19002/admin/shutdown?all=true",
- "metadata_node": "asterix_nc1",
- "ncs": [
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
- "node_id": "asterix_nc1",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_0"
- },
- {
- "active": true,
- "partition_id": "partition_1"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
- },
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
- "node_id": "asterix_nc2",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_2"
- },
- {
- "active": true,
- "partition_id": "partition_3"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
- }
- ],
- "replicationUri": "http://127.0.0.1:19002/admin/cluster/replication",
- "shutdownUri": "http://127.0.0.1:19002/admin/shutdown",
- "state": "ACTIVE",
- "versionUri": "http://127.0.0.1:19002/admin/version"
+ "metadata.port" : 0,
+ "metadata.registration.timeout.secs" : 60,
+ "node.partitions" : {
+ "asterix_nc1" : [ {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ],
+ "asterix_nc2" : [ {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ }, {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ } ]
+ },
+ "node.stores" : {
+ "asterix_nc1" : [ "iodevice0", "iodevice1" ],
+ "asterix_nc2" : [ "iodevice0", "iodevice1" ]
+ },
+ "plot.activate" : false,
+ "storage.buffercache.maxopenfiles" : 2147483647,
+ "storage.buffercache.pagesize" : 32768,
+ "storage.buffercache.size" : 50331648,
+ "storage.lsm.bloomfilter.falsepositiverate" : 0.01,
+ "storage.memorycomponent.globalbudget" : 536870912,
+ "storage.memorycomponent.numcomponents" : 2,
+ "storage.memorycomponent.numpages" : 8,
+ "storage.memorycomponent.pagesize" : 131072,
+ "storage.metadata.memorycomponent.numpages" : 256,
+ "transaction.log.dirs" : {
+ "asterix_nc1" : "target/txnLogDir/asterix_nc1",
+ "asterix_nc2" : "target/txnLogDir/asterix_nc2"
+ },
+ "txn.commitprofiler.reportinterval" : 5,
+ "txn.job.recovery.memorysize" : 67108864,
+ "txn.lock.escalationthreshold" : 1000,
+ "txn.lock.shrinktimer" : 5000,
+ "txn.lock.timeout.sweepthreshold" : 10000,
+ "txn.lock.timeout.waitthreshold" : 60000,
+ "txn.log.buffer.numpages" : 8,
+ "txn.log.buffer.pagesize" : 131072,
+ "txn.log.checkpoint.history" : 0,
+ "txn.log.checkpoint.lsnthreshold" : 67108864,
+ "txn.log.checkpoint.pollfrequency" : 120,
+ "txn.log.partitionsize" : 268435456,
+ "web.port" : 19001,
+ "web.queryinterface.port" : 19006,
+ "web.secondary.port" : 19005
+ },
+ "diagnosticsUri" : "http://127.0.0.1:19002/admin/diagnostics",
+ "fullShutdownUri" : "http://127.0.0.1:19002/admin/shutdown?all=true",
+ "metadata_node" : "asterix_nc1",
+ "ncs" : [ {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
+ "node_id" : "asterix_nc1",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_0"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_1"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
+ }, {
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
+ "node_id" : "asterix_nc2",
+ "partitions" : [ {
+ "active" : true,
+ "partition_id" : "partition_2"
+ }, {
+ "active" : true,
+ "partition_id" : "partition_3"
+ } ],
+ "state" : "ACTIVE",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
+ } ],
+ "replicationUri" : "http://127.0.0.1:19002/admin/cluster/replication",
+ "shutdownUri" : "http://127.0.0.1:19002/admin/shutdown",
+ "state" : "ACTIVE",
+ "versionUri" : "http://127.0.0.1:19002/admin/version"
}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_3/cluster_state_3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_3/cluster_state_3.1.adm
index b0815ee..14a00d0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_3/cluster_state_3.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_3/cluster_state_3.1.adm
@@ -1,36 +1,29 @@
-{"ncs": [
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
- "node_id": "asterix_nc1",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_0"
- },
- {
- "active": true,
- "partition_id": "partition_1"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
- },
- {
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
- "node_id": "asterix_nc2",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_2"
- },
- {
- "active": true,
- "partition_id": "partition_3"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
- }
-]}
+{
+ "ncs" : [ {
+ "node_id" : "asterix_nc1",
+ "state" : "ACTIVE",
+ "partitions" : [ {
+ "partition_id" : "partition_0",
+ "active" : true
+ }, {
+ "partition_id" : "partition_1",
+ "active" : true
+ } ],
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
+ }, {
+ "node_id" : "asterix_nc2",
+ "state" : "ACTIVE",
+ "partitions" : [ {
+ "partition_id" : "partition_2",
+ "active" : true
+ }, {
+ "partition_id" : "partition_3",
+ "active" : true
+ } ],
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc2/threaddump"
+ } ]
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_4/cluster_state_4.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_4/cluster_state_4.1.adm
index 4635690..5e88f5c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_4/cluster_state_4.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_4/cluster_state_4.1.adm
@@ -1,17 +1,14 @@
{
- "configUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
- "node_id": "asterix_nc1",
- "partitions": [
- {
- "active": true,
- "partition_id": "partition_0"
- },
- {
- "active": true,
- "partition_id": "partition_1"
- }
- ],
- "state": "ACTIVE",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
-}
+ "node_id" : "asterix_nc1",
+ "state" : "ACTIVE",
+ "partitions" : [ {
+ "partition_id" : "partition_0",
+ "active" : true
+ }, {
+ "partition_id" : "partition_1",
+ "active" : true
+ } ],
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/node/asterix_nc1/threaddump"
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_1/cluster_state_cc_1.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_1/cluster_state_cc_1.1.adm
index 5e1e154..879ecbc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_1/cluster_state_cc_1.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_1/cluster_state_cc_1.1.adm
@@ -1,5 +1,5 @@
{
- "configUri": "http://127.0.0.1:19002/admin/cluster/cc/config",
- "statsUri": "http://127.0.0.1:19002/admin/cluster/cc/stats",
- "threadDumpUri": "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
-}
+ "configUri" : "http://127.0.0.1:19002/admin/cluster/cc/config",
+ "statsUri" : "http://127.0.0.1:19002/admin/cluster/cc/stats",
+ "threadDumpUri" : "http://127.0.0.1:19002/admin/cluster/cc/threaddump"
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.regexadm
index 196a12b..01ff72a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.regexadm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.regexadm
@@ -1,27 +1,24 @@
\{
- "date": ".*",
- "gcs": \[
- \{
- "collection-count": .*,
- "collection-time": .*,
- "name": ".*"
- \},
- \{
- "collection-count": .*,
- "collection-time": .*,
- "name": ".*"
- \}
- \],
- "heap_committed_size": [0-9]*,
- "heap_init_size": [0-9]*,
- "heap_max_size": [0-9]*,
- "heap_used_size": [0-9]*,
- "nonheap_committed_size": [0-9]*,
- "nonheap_init_size": [0-9]*,
- "nonheap_max_size": -?[0-9]*,
- "nonheap_used_size": [0-9]*,
- "peak_thread_count": [0-9]*,
- "started_thread_count": [0-9]*,
- "system_load_average": [0-9\.]*,
- "thread_count": [0-9]*
-\}
\ No newline at end of file
+ "gcs" : \[ \{
+ "name" : ".*",
+ "collection-time" : .*,
+ "collection-count" : .*
+ \}, \{
+ "name" : ".*",
+ "collection-time" : .*,
+ "collection-count" : .*
+ \} \],
+ "date" : ".*",
+ "heap_init_size" : [0-9]*,
+ "heap_used_size" : [0-9]*,
+ "heap_committed_size" : [0-9]*,
+ "heap_max_size" : [0-9]*,
+ "nonheap_init_size" : [0-9]*,
+ "nonheap_used_size" : [0-9]*,
+ "nonheap_committed_size" : [0-9]*,
+ "nonheap_max_size" : -?[0-9]*,
+ "thread_count" : [0-9]*,
+ "peak_thread_count" : [0-9]*,
+ "started_thread_count" : [0-9]*,
+ "system_load_average" : [0-9\.]*
+\}*
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_nc_threaddump_1/cluster_state_cc_threaddump_1.1.regex b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_nc_threaddump_1/cluster_state_cc_threaddump_1.1.regex
index 1e5c47b..3f1bfdc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_nc_threaddump_1/cluster_state_cc_threaddump_1.1.regex
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/cluster_state_nc_threaddump_1/cluster_state_cc_threaddump_1.1.regex
@@ -1,10 +1,10 @@
-/"date": ".*"/
-/"threads": \[/
-/"id": [0-9]+/
-/"lock_name": ".*"/
-/"name": ".*"/
-/"stack": \[/
+/"date" : ".*"/
+/"threads" : \[/
+/"id" : [0-9]+/
+/"lock_name" : ".*"/
+/"name" : ".*"/
+/"stack" : \[/
/"java.lang.Thread.run\(Thread.java:[0-9]+\)"/
-/"state": "TIMED_WAITING"/
-/"state": "RUNNABLE"/
-/"state": "WAITING"/
\ No newline at end of file
+/"state" : "TIMED_WAITING"/
+/"state" : "RUNNABLE"/
+/"state" : "WAITING"/
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/diagnostics_1/diagnostics_1.1.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/diagnostics_1/diagnostics_1.1.regexadm
index 29c03bf..b2dafd9 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/diagnostics_1/diagnostics_1.1.regexadm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/diagnostics_1/diagnostics_1.1.regexadm
@@ -1,10 +1,7 @@
-.*"cc": \{
- "config": \{.*
- \},
- "stats": \{.*
- \},
- "threaddump": \{.*
- \}
-.*"ncs".*"node_id": "asterix_nc1",
-.*"threaddump".*"node_id": "asterix_nc2",
-.*"threaddump".*
\ No newline at end of file
+.*"cc" : \{.*
+ "stats" : \{.*
+ \},.*
+ "threaddump" : \{.*
+ \},.*
+ "config" : \{.*
+ \}.*"ncs".*"node_id" : "asterix_nc1".*"threaddump".*"node_id" : "asterix_nc2".*"threaddump".*
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/replication/replication.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/replication/replication.1.adm
index 8adc10c..74e019b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/replication/replication.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/replication/replication.1.adm
@@ -1,9 +1,11 @@
-{"config": {
- "enabled": false,
- "factor": 2,
- "log.batchsize": 4096,
- "log.buffer.numpages": 8,
- "log.buffer.pagesize": 131072,
- "max.remote.recovery.attempts": 5,
- "timeout": 30
-}}
+{
+ "config" : {
+ "enabled" : false,
+ "factor" : 2,
+ "log.batchsize" : 4096,
+ "log.buffer.numpages" : 8,
+ "log.buffer.pagesize" : 131072,
+ "max.remote.recovery.attempts" : 5,
+ "timeout" : 30
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-client-helper/pom.xml b/asterixdb/asterix-client-helper/pom.xml
index 3270fbb..04de18a 100644
--- a/asterixdb/asterix-client-helper/pom.xml
+++ b/asterixdb/asterix-client-helper/pom.xml
@@ -108,8 +108,12 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
</dependency>
</dependencies>
</project>
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/GetClusterStateCommand.java b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/GetClusterStateCommand.java
index 77ed78f..e0fcb06 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/GetClusterStateCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/GetClusterStateCommand.java
@@ -24,10 +24,11 @@
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.clienthelper.Args;
import org.apache.commons.io.IOUtils;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class GetClusterStateCommand extends RemoteCommand {
@@ -49,8 +50,9 @@
conn = openConnection(args.getClusterStatePath(), Method.GET);
if (conn.getResponseCode() == HttpServletResponse.SC_OK) {
String result = IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8.name());
- JSONObject json = new JSONObject(result);
- final String state = json.getString("state");
+ ObjectMapper om = new ObjectMapper();
+ JsonNode json = om.readTree(result);
+ final String state = json.get("state").asText();
logState(state);
switch (state) {
case "ACTIVE":
@@ -66,9 +68,6 @@
} catch (IOException e) { // NOSONAR - log or rethrow exception
logState("DOWN");
return 1;
- } catch (JSONException e) { // NOSONAR - log or rethrow exception
- logState("UNKNOWN (malformed response)");
- return 3;
}
}
}
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
index b0b4c6f..dad9f8c 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
@@ -25,10 +25,11 @@
import javax.servlet.http.HttpServletResponse;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.clienthelper.Args;
import org.apache.commons.io.IOUtils;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class WaitForClusterCommand extends RemoteCommand {
@@ -66,14 +67,15 @@
conn = openConnection(args.getClusterStatePath(), Method.GET);
if (conn.getResponseCode() == HttpServletResponse.SC_OK) {
String result = IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8.name());
- JSONObject json = new JSONObject(result);
- lastState = json.getString("state");
+ ObjectMapper om = new ObjectMapper();
+ JsonNode json = om.readTree(result);
+ lastState = json.get("state").asText();
if ("ACTIVE".equals(lastState)) {
log("Cluster started and is ACTIVE.");
return 0;
}
}
- } catch (JSONException |IOException e) { //NOSONAR - log or rethrow exception
+ } catch (IOException e) { //NOSONAR - log or rethrow exception
// ignore exception, try again
}
}
diff --git a/asterixdb/asterix-common/pom.xml b/asterixdb/asterix-common/pom.xml
index d4a4517..722e1c5 100644
--- a/asterixdb/asterix-common/pom.xml
+++ b/asterixdb/asterix-common/pom.xml
@@ -270,10 +270,6 @@
<version>1.2.17</version>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>test</scope>
@@ -307,6 +303,19 @@
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>18.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/AbstractProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/AbstractProperties.java
index b6a960f..eccbff2 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/AbstractProperties.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/AbstractProperties.java
@@ -49,9 +49,14 @@
Map<String, Object> properties = new HashMap<>();
for (Method m : getClass().getMethods()) {
PropertyKey key = m.getAnnotation(PropertyKey.class);
+ Stringify stringify = m.getAnnotation(Stringify.class);
if (key != null) {
try {
- properties.put(keyTransformer.apply(key.value()), m.invoke(this));
+ if (stringify != null) {
+ properties.put(keyTransformer.apply(key.value()), String.valueOf(m.invoke(this)));
+ } else {
+ properties.put(keyTransformer.apply(key.value()), m.invoke(this));
+ }
} catch (Exception e) {
LOGGER.log(Level.INFO, "Error accessing property: " + key.value(), e);
}
@@ -65,6 +70,10 @@
String value();
}
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Stringify {
+ }
+
public static List<AbstractProperties> getImplementations() {
return Collections.unmodifiableList(IMPLS);
}
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ExternalProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ExternalProperties.java
index dac154c..eb6bda5 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ExternalProperties.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ExternalProperties.java
@@ -22,35 +22,35 @@
public class ExternalProperties extends AbstractProperties {
- private static final String EXTERNAL_WEBPORT_KEY = "web.port";
- private static final int EXTERNAL_WEBPORT_DEFAULT = 19001;
+ public static final String EXTERNAL_WEBPORT_KEY = "web.port";
+ public static final int EXTERNAL_WEBPORT_DEFAULT = 19001;
- private static final String EXTERNAL_SECONDARY_WEBPORT_KEY = "web.secondary.port";
- private static final int EXTERNAL_SECONDARY_WEBPORT_DEFAULT = 19005;
+ public static final String EXTERNAL_SECONDARY_WEBPORT_KEY = "web.secondary.port";
+ public static final int EXTERNAL_SECONDARY_WEBPORT_DEFAULT = 19005;
- private static final String QUERY_WEBPORT_KEY = "web.queryinterface.port";
- private static final int QUERY_WEBPORT_DEFAULT = 19006;
+ public static final String QUERY_WEBPORT_KEY = "web.queryinterface.port";
+ public static final int QUERY_WEBPORT_DEFAULT = 19006;
- private static final String EXTERNAL_LOGLEVEL_KEY = "log.level";
- private static final Level EXTERNAL_LOGLEVEL_DEFAULT = Level.WARNING;
+ public static final String EXTERNAL_LOGLEVEL_KEY = "log.level";
+ public static final Level EXTERNAL_LOGLEVEL_DEFAULT = Level.WARNING;
- private static final String EXTERNAL_APISERVER_KEY = "api.port";
- private static final int EXTERNAL_APISERVER_DEFAULT = 19002;
+ public static final String EXTERNAL_APISERVER_KEY = "api.port";
+ public static final int EXTERNAL_APISERVER_DEFAULT = 19002;
- private static final String EXTERNAL_FEEDSERVER_KEY = "feed.port";
- private static final int EXTERNAL_FEEDSERVER_DEFAULT = 19003;
+ public static final String EXTERNAL_FEEDSERVER_KEY = "feed.port";
+ public static final int EXTERNAL_FEEDSERVER_DEFAULT = 19003;
- private static final String EXTERNAL_CC_JAVA_OPTS_KEY = "cc.java.opts";
- private static final String EXTERNAL_CC_JAVA_OPTS_DEFAULT = "-Xmx1024m";
+ public static final String EXTERNAL_CC_JAVA_OPTS_KEY = "cc.java.opts";
+ public static final String EXTERNAL_CC_JAVA_OPTS_DEFAULT = "-Xmx1024m";
- private static final String EXTERNAL_NC_JAVA_OPTS_KEY = "nc.java.opts";
- private static final String EXTERNAL_NC_JAVA_OPTS_DEFAULT = "-Xmx1024m";
+ public static final String EXTERNAL_NC_JAVA_OPTS_KEY = "nc.java.opts";
+ public static final String EXTERNAL_NC_JAVA_OPTS_DEFAULT = "-Xmx1024m";
- private static final String EXTERNAL_MAX_WAIT_FOR_ACTIVE_CLUSTER = "max.wait.active.cluster";
- private static final int EXTERNAL_MAX_WAIT_FOR_ACTIVE_CLUSTER_DEFAULT = 60;
+ public static final String EXTERNAL_MAX_WAIT_FOR_ACTIVE_CLUSTER = "max.wait.active.cluster";
+ public static final int EXTERNAL_MAX_WAIT_FOR_ACTIVE_CLUSTER_DEFAULT = 60;
- private static final String EXTERNAL_PLOT_ACTIVATE = "plot.activate";
- private static final boolean EXTERNAL_PLOT_ACTIVATE_DEFAULT = false;
+ public static final String EXTERNAL_PLOT_ACTIVATE = "plot.activate";
+ public static final boolean EXTERNAL_PLOT_ACTIVATE_DEFAULT = false;
public ExternalProperties(PropertiesAccessor accessor) {
super(accessor);
@@ -87,6 +87,7 @@
}
@PropertyKey(EXTERNAL_LOGLEVEL_KEY)
+ @Stringify
public Level getLogLevel() {
return accessor.getProperty(EXTERNAL_LOGLEVEL_KEY, EXTERNAL_LOGLEVEL_DEFAULT,
PropertyInterpreters.getLevelPropertyInterpreter());
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
index 0cbf1b9..80df260 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
@@ -18,49 +18,65 @@
*/
package org.apache.asterix.common.utils;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Logger;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
public class JSONUtil {
private static final Logger LOGGER = Logger.getLogger(JSONUtil.class.getName());
private static final String INDENT = "\t";
+ private static final ObjectMapper SORTED_MAPPER = new ObjectMapper();
+
private JSONUtil() {
}
+ static {
+ SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
+ }
+
+ public static String convertNode(final JsonNode node) throws JsonProcessingException {
+ final Object obj = SORTED_MAPPER.treeToValue(node, Object.class);
+ final String json = SORTED_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
+ return json;
+ }
+
public static String indent(String str, int initialIndent) {
+ ObjectMapper om = new ObjectMapper();
try {
- return append(new StringBuilder(), new JSONObject(str), initialIndent).toString();
- } catch (JSONException e) {
+ return appendObj(new StringBuilder(), om.readTree(str), initialIndent).toString();
+ } catch (IOException e) {
+ LOGGER.finest(String.valueOf(e));
LOGGER.finest("Could not indent JSON string, returning the input string: " + str);
return str;
}
}
- private static StringBuilder append(StringBuilder sb, Object o, int indent) throws JSONException {
- if (o instanceof JSONObject) {
- return append(sb, (JSONObject) o, indent);
- } else if (o instanceof JSONArray) {
- return append(sb, (JSONArray) o, indent);
- } else if (o instanceof String) {
- return quoteAndEscape(sb, (String) o);
- } else if (JSONObject.NULL.equals(o) || o instanceof Number || o instanceof Boolean) {
+ private static StringBuilder appendOrd(StringBuilder sb, JsonNode o, int indent) {
+ if (o.isObject()) {
+ return appendObj(sb, o, indent);
+ } else if (o.isArray()) {
+ return appendAry(sb, o, indent);
+ } else if (o.isTextual()) {
+ return quoteAndEscape(sb, o.asText());
+ } else if (o.isNull() || o.isIntegralNumber() || o.isBoolean()) {
return sb.append(String.valueOf(o));
}
throw new UnsupportedOperationException(o.getClass().getSimpleName());
}
- private static StringBuilder append(StringBuilder builder, JSONObject jobj, int indent) throws JSONException {
+ private static StringBuilder appendObj(StringBuilder builder, JsonNode jobj, int indent) {
StringBuilder sb = builder.append("{\n");
boolean first = true;
- for (Iterator it = jobj.keys(); it.hasNext();) {
- final String key = (String) it.next();
+ for (Iterator<JsonNode> it = jobj.iterator(); it.hasNext();) {
+ final String key = it.next().asText();
if (first) {
first = false;
} else {
@@ -69,20 +85,32 @@
sb = indent(sb, indent + 1);
sb = quote(sb, key);
sb = sb.append(": ");
- sb = append(sb, jobj.get(key), indent + 1);
+ if (jobj.get(key).isArray()) {
+ sb = appendAry(sb, jobj.get(key), indent + 1);
+ } else if (jobj.get(key).isObject()) {
+ sb = appendObj(sb, jobj.get(key), indent + 1);
+ } else {
+ sb = appendOrd(sb, jobj.get(key), indent + 1);
+ }
}
sb = sb.append("\n");
return indent(sb, indent).append("}");
}
- private static StringBuilder append(StringBuilder builder, JSONArray jarr, int indent) throws JSONException {
+ private static StringBuilder appendAry(StringBuilder builder, JsonNode jarr, int indent) {
StringBuilder sb = builder.append("[\n");
- for (int i = 0; i < jarr.length(); ++i) {
+ for (int i = 0; i < jarr.size(); ++i) {
if (i > 0) {
sb = sb.append(",\n");
}
sb = indent(sb, indent + 1);
- sb = append(sb, jarr.get(i), indent + 1);
+ if (jarr.get(i).isArray()) {
+ sb = appendAry(sb, jarr.get(i), indent + 1);
+ } else if (jarr.get(i).isObject()) {
+ sb = appendObj(sb, jarr.get(i), indent + 1);
+ } else {
+ sb = appendOrd(sb, jarr.get(i), indent + 1);
+ }
}
sb = sb.append("\n");
return indent(sb, indent).append("]");
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/ResultExtractor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/ResultExtractor.java
index 662888e..8399f7a 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/ResultExtractor.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/ResultExtractor.java
@@ -19,18 +19,24 @@
package org.apache.asterix.test.aql;
import java.io.InputStream;
+import java.io.StringWriter;
import java.nio.charset.Charset;
+import java.util.Iterator;
import java.util.logging.Logger;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.PrettyPrinter;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Iterators;
+import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.commons.io.IOUtils;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
/**
* extracts results from the response of the QueryServiceServlet.
- *
* As the response is not necessarily valid JSON, non-JSON content has to be extracted in some cases.
* The current implementation creates a toomany copies of the data to be usable for larger results.
*/
@@ -39,150 +45,84 @@
private static final Logger LOGGER = Logger.getLogger(ResultExtractor.class.getName());
public static InputStream extract(InputStream resultStream) throws Exception {
- final Charset utf8 = Charset.forName("UTF-8");
- String result = IOUtils.toString(resultStream, utf8);
+ ObjectMapper om = new ObjectMapper();
+ StringWriter sw = new StringWriter();
+ String resultStr = IOUtils.toString(resultStream, Charset.defaultCharset());
+ PrettyPrinter singleLine = new SingleLinePrettyPrinter();
+ ObjectNode result = om.readValue(resultStr, ObjectNode.class);
LOGGER.fine("+++++++\n" + result + "\n+++++++\n");
- JSONTokener tokener = new JSONTokener(result);
- tokener.nextTo('{');
- tokener.next('{');
- String name;
- String type = null;
- String status = null;
+ String type = "";
+ String status = "";
String results = "";
- while ((name = getFieldName(tokener)) != null) {
- if ("requestID".equals(name) || "signature".equals(name)) {
- getStringField(tokener);
- } else if ("status".equals(name)) {
- status = getStringField(tokener);
- } else if ("type".equals(name)) {
- type = getStringField(tokener);
- } else if ("metrics".equals(name)) {
- JSONObject metrics = getObjectField(tokener);
- LOGGER.fine(name + ": " + metrics);
- } else if ("errors".equals(name)) {
- JSONArray errors = getArrayField(tokener);
- LOGGER.fine(name + ": " + errors);
- JSONObject err = errors.getJSONObject(0);
- throw new Exception(err.getString("msg"));
- } else if ("results".equals(name)) {
- results = getResults(tokener, type);
- } else {
- throw tokener.syntaxError(name + ": unanticipated field");
+ String field = "";
+ for (Iterator<String> sIter = result.fieldNames(); sIter.hasNext();) {
+ field = sIter.next();
+ switch (field) {
+ case "requestID":
+ break;
+ case "signature":
+ break;
+ case "status":
+ status = om.writeValueAsString(result.get(field));
+ break;
+ case "type":
+ type = om.writeValueAsString(result.get(field));
+ break;
+ case "metrics":
+ LOGGER.fine(om.writeValueAsString(result.get(field)));
+ break;
+ case "errors":
+ JsonNode errors = result.get(field).get(0).get("msg");
+ throw new AsterixException(errors.asText());
+ case "results":
+ if (result.get(field).size() <= 1) {
+ if (result.get(field).size() == 0) {
+ results = "";
+ } else if (result.get(field).isArray()) {
+ if (result.get(field).get(0).isTextual()) {
+ results = result.get(field).get(0).asText();
+ } else {
+ ObjectMapper omm = new ObjectMapper();
+ omm.setDefaultPrettyPrinter(singleLine);
+ omm.enable(SerializationFeature.INDENT_OUTPUT);
+ results = omm.writer(singleLine).writeValueAsString(result.get(field));
+ }
+ } else {
+ results = om.writeValueAsString(result.get(field));
+ }
+ } else {
+ StringBuilder sb = new StringBuilder();
+ JsonNode[] fields = Iterators.toArray(result.get(field).elements(), JsonNode.class);
+ if (fields.length > 1) {
+ for (JsonNode f : fields) {
+ if (f.isObject()) {
+ sb.append(om.writeValueAsString(f));
+ } else {
+ sb.append(f.asText());
+ }
+ }
+ }
+ results = sb.toString();
+ }
+ break;
+ default:
+ throw new AsterixException(field + "unanticipated field");
}
}
- while (tokener.more() && tokener.skipTo('}') != '}') {
- // skip along
- }
- tokener.next('}');
- if (! "success".equals(status)) {
- throw new Exception("Unexpected status: '" + status + "'");
- }
- return IOUtils.toInputStream(results, utf8);
+
+ return IOUtils.toInputStream(results);
}
public static String extractHandle(InputStream resultStream) throws Exception {
final Charset utf8 = Charset.forName("UTF-8");
+ ObjectMapper om = new ObjectMapper();
String result = IOUtils.toString(resultStream, utf8);
- JSONObject parsed = new JSONObject(result);
- JSONArray handle = parsed.getJSONArray("handle");
- JSONObject res = new JSONObject();
- res.put("handle", handle);
- return res.toString();
- }
-
- private static String getFieldName(JSONTokener tokener) throws JSONException {
- char c = tokener.skipTo('"');
- if (c != '"') {
- return null;
- }
- tokener.next('"');
- return tokener.nextString('"');
- }
-
- private static String getStringField(JSONTokener tokener) throws JSONException {
- tokener.skipTo('"');
- tokener.next('"');
- return tokener.nextString('"');
- }
-
- private static JSONArray getArrayField(JSONTokener tokener) throws JSONException {
- tokener.skipTo(':');
- tokener.next(':');
- Object obj = tokener.nextValue();
- if (obj instanceof JSONArray) {
- return (JSONArray) obj;
- } else {
- throw tokener.syntaxError(String.valueOf(obj) + ": unexpected value");
- }
- }
-
- private static JSONObject getObjectField(JSONTokener tokener) throws JSONException {
- tokener.skipTo(':');
- tokener.next(':');
- Object obj = tokener.nextValue();
- if (obj instanceof JSONObject) {
- return (JSONObject) obj;
- } else {
- throw tokener.syntaxError(String.valueOf(obj) + ": unexpected value");
- }
- }
-
- private static String getResults(JSONTokener tokener, String type) throws JSONException {
- tokener.skipTo(':');
- tokener.next(':');
- StringBuilder result = new StringBuilder();
- if (type != null) {
- // a type was provided in the response and so the result is encoded as an array of escaped strings that
- // need to be concatenated
- Object obj = tokener.nextValue();
- if (!(obj instanceof JSONArray)) {
- throw tokener.syntaxError("array expected");
- }
- JSONArray array = (JSONArray) obj;
- for (int i = 0; i < array.length(); ++i) {
- result.append(array.getString(i));
- }
- return result.toString();
- } else {
- int level = 0;
- boolean inQuote = false;
- while (tokener.more()) {
- char c = tokener.next();
- switch (c) {
- case '{':
- case '[':
- ++level;
- result.append(c);
- break;
- case '}':
- case ']':
- --level;
- result.append(c);
- break;
- case '"':
- if (inQuote) {
- --level;
- } else {
- ++level;
- }
- inQuote = !inQuote;
- result.append(c);
- break;
- case ',':
- if (level == 0) {
- return result.toString().trim();
- } else {
- result.append(c);
- }
- break;
- default:
- result.append(c);
- break;
- }
- }
- }
- return null;
+ ObjectNode resultJson = om.readValue(result, ObjectNode.class);
+ JsonNode handle = resultJson.get("handle");
+ ObjectNode res = om.createObjectNode();
+ res.set("handle", handle);
+ return om.writeValueAsString(res);
}
}
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java
new file mode 100644
index 0000000..52f68a0
--- /dev/null
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java
@@ -0,0 +1,404 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.test.aql;
+
+import java.io.*;
+
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.io.SerializedString;
+import com.fasterxml.jackson.core.util.DefaultIndenter;
+import com.fasterxml.jackson.core.util.Instantiatable;
+
+/**
+ * Default {@link PrettyPrinter} implementation that uses 2-space
+ * indentation with platform-default linefeeds.
+ * Usually this class is not instantiated directly, but instead
+ * method {@link JsonGenerator#useSingleLinePrettyPrinter} is
+ * used, which will use an instance of this class for operation.
+ */
+@SuppressWarnings("serial")
+public class SingleLinePrettyPrinter
+ implements PrettyPrinter, Instantiatable<SingleLinePrettyPrinter>, java.io.Serializable {
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Constant that specifies default "root-level" separator to use between
+ * root values: a single space character.
+ *
+ * @since 2.1
+ */
+ public final static SerializedString DEFAULT_ROOT_VALUE_SEPARATOR = new SerializedString(" ");
+
+ /**
+ * Interface that defines objects that can produce indentation used
+ * to separate object entries and array values. Indentation in this
+ * context just means insertion of white space, independent of whether
+ * linefeeds are output.
+ */
+ public interface Indenter {
+ void writeIndentation(JsonGenerator jg, int level) throws IOException;
+
+ /**
+ * @return True if indenter is considered inline (does not add linefeeds),
+ * false otherwise
+ */
+ boolean isInline();
+ }
+
+ // // // Config, indentation
+
+ /**
+ * By default, let's use only spaces to separate array values.
+ */
+ protected Indenter _arrayIndenter = FixedSpaceIndenter.instance;
+
+ /**
+ * By default, let's use linefeed-adding indenter for separate
+ * object entries. We'll further configure indenter to use
+ * system-specific linefeeds, and 2 spaces per level (as opposed to,
+ * say, single tabs)
+ */
+ protected Indenter _objectIndenter = new FixedSpaceIndenter();
+
+ /**
+ * String printed between root-level values, if any.
+ */
+ protected final SerializableString _rootSeparator;
+
+ // // // Config, other white space configuration
+
+ /**
+ * By default we will add spaces around colons used to
+ * separate object fields and values.
+ * If disabled, will not use spaces around colon.
+ */
+ protected boolean _spacesInObjectEntries = true;
+
+ // // // State:
+
+ /**
+ * Number of open levels of nesting. Used to determine amount of
+ * indentation to use.
+ */
+ protected transient int _nesting;
+
+ /*
+ /**********************************************************
+ /* Life-cycle (construct, configure)
+ /**********************************************************
+ */
+
+ public SingleLinePrettyPrinter() {
+ this(DEFAULT_ROOT_VALUE_SEPARATOR);
+ }
+
+ /**
+ * Constructor that specifies separator String to use between root values;
+ * if null, no separator is printed.
+ * <p>
+ * Note: simply constructs a {@link SerializedString} out of parameter,
+ * calls {@link #SingleLinePrettyPrinter(SerializableString)}
+ *
+ * @param rootSeparator
+ * @since 2.1
+ */
+ public SingleLinePrettyPrinter(String rootSeparator) {
+ this((rootSeparator == null) ? null : new SerializedString(rootSeparator));
+ }
+
+ /**
+ * Constructor that specifies separator String to use between root values;
+ * if null, no separator is printed.
+ *
+ * @param rootSeparator
+ * @since 2.1
+ */
+ public SingleLinePrettyPrinter(SerializableString rootSeparator) {
+ _rootSeparator = rootSeparator;
+ }
+
+ public SingleLinePrettyPrinter(SingleLinePrettyPrinter base) {
+ this(base, base._rootSeparator);
+ }
+
+ public SingleLinePrettyPrinter(SingleLinePrettyPrinter base, SerializableString rootSeparator) {
+ _arrayIndenter = base._arrayIndenter;
+ _objectIndenter = base._objectIndenter;
+ _spacesInObjectEntries = base._spacesInObjectEntries;
+ _nesting = base._nesting;
+
+ _rootSeparator = rootSeparator;
+ }
+
+ public SingleLinePrettyPrinter withRootSeparator(SerializableString rootSeparator) {
+ if (_rootSeparator == rootSeparator || (rootSeparator != null && rootSeparator.equals(_rootSeparator))) {
+ return this;
+ }
+ return new SingleLinePrettyPrinter(this, rootSeparator);
+ }
+
+ /**
+ * @since 2.6.0
+ */
+ public SingleLinePrettyPrinter withRootSeparator(String rootSeparator) {
+ return withRootSeparator((rootSeparator == null) ? null : new SerializedString(rootSeparator));
+ }
+
+ public void indentArraysWith(Indenter i) {
+ _arrayIndenter = (i == null) ? NopIndenter.instance : i;
+ }
+
+ public void indentObjectsWith(Indenter i) {
+ _objectIndenter = (i == null) ? NopIndenter.instance : i;
+ }
+
+ /**
+ * @deprecated Since 2.3 use {@link #withSpacesInObjectEntries} and {@link #withoutSpacesInObjectEntries()}
+ */
+ @Deprecated
+ public void spacesInObjectEntries(boolean b) {
+ _spacesInObjectEntries = b;
+ }
+
+ /**
+ * @since 2.3
+ */
+ public SingleLinePrettyPrinter withArrayIndenter(Indenter i) {
+ if (i == null) {
+ i = NopIndenter.instance;
+ }
+ if (_arrayIndenter == i) {
+ return this;
+ }
+ SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this);
+ pp._arrayIndenter = i;
+ return pp;
+ }
+
+ /**
+ * @since 2.3
+ */
+ public SingleLinePrettyPrinter withObjectIndenter(Indenter i) {
+ if (i == null) {
+ i = NopIndenter.instance;
+ }
+ if (_objectIndenter == i) {
+ return this;
+ }
+ SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this);
+ pp._objectIndenter = i;
+ return pp;
+ }
+
+ /**
+ * "Mutant factory" method that will return a pretty printer instance
+ * that does use spaces inside object entries; if 'this' instance already
+ * does this, it is returned; if not, a new instance will be constructed
+ * and returned.
+ *
+ * @since 2.3
+ */
+ public SingleLinePrettyPrinter withSpacesInObjectEntries() {
+ return _withSpaces(true);
+ }
+
+ /**
+ * "Mutant factory" method that will return a pretty printer instance
+ * that does not use spaces inside object entries; if 'this' instance already
+ * does this, it is returned; if not, a new instance will be constructed
+ * and returned.
+ *
+ * @since 2.3
+ */
+ public SingleLinePrettyPrinter withoutSpacesInObjectEntries() {
+ return _withSpaces(false);
+ }
+
+ protected SingleLinePrettyPrinter _withSpaces(boolean state) {
+ if (_spacesInObjectEntries == state) {
+ return this;
+ }
+ SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this);
+ pp._spacesInObjectEntries = state;
+ return pp;
+ }
+
+ /*
+ /**********************************************************
+ /* Instantiatable impl
+ /**********************************************************
+ */
+
+ @Override
+ public SingleLinePrettyPrinter createInstance() {
+ return new SingleLinePrettyPrinter(this);
+ }
+
+ /*
+ /**********************************************************
+ /* PrettyPrinter impl
+ /**********************************************************
+ */
+
+ @Override
+ public void writeRootValueSeparator(JsonGenerator jg) throws IOException {
+ if (_rootSeparator != null) {
+ jg.writeRaw(_rootSeparator);
+ }
+ }
+
+ @Override
+ public void writeStartObject(JsonGenerator jg) throws IOException {
+ jg.writeRaw('{');
+ ++_nesting;
+ }
+
+ @Override
+ public void beforeObjectEntries(JsonGenerator jg) throws IOException {
+ _objectIndenter.writeIndentation(jg, _nesting);
+ }
+
+ /**
+ * Method called after an object field has been output, but
+ * before the value is output.
+ * <p>
+ * Default handling (without pretty-printing) will output a single
+ * colon to separate the two. Pretty-printer is
+ * to output a colon as well, but can surround that with other
+ * (white-space) decoration.
+ */
+ @Override
+ public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
+ if (_spacesInObjectEntries) {
+ jg.writeRaw(": ");
+ } else {
+ jg.writeRaw(':');
+ }
+ }
+
+ /**
+ * Method called after an object entry (field:value) has been completely
+ * output, and before another value is to be output.
+ * <p>
+ * Default handling (without pretty-printing) will output a single
+ * comma to separate the two. Pretty-printer is
+ * to output a comma as well, but can surround that with other
+ * (white-space) decoration.
+ */
+ @Override
+ public void writeObjectEntrySeparator(JsonGenerator jg) throws IOException {
+ jg.writeRaw(',');
+ _objectIndenter.writeIndentation(jg, _nesting);
+ }
+
+ @Override
+ public void writeEndObject(JsonGenerator jg, int nrOfEntries) throws IOException {
+ --_nesting;
+ if (nrOfEntries > 1) {
+ _objectIndenter.writeIndentation(jg, _nesting);
+ } else {
+ jg.writeRaw(' ');
+ }
+ jg.writeRaw('}');
+ }
+
+ @Override
+ public void writeStartArray(JsonGenerator jg) throws IOException {
+ ++_nesting;
+ jg.writeRaw('[');
+ }
+
+ @Override
+ public void beforeArrayValues(JsonGenerator jg) throws IOException {
+ _arrayIndenter.writeIndentation(jg, _nesting);
+ }
+
+ /**
+ * Method called after an array value has been completely
+ * output, and before another value is to be output.
+ * <p>
+ * Default handling (without pretty-printing) will output a single
+ * comma to separate the two. Pretty-printer is
+ * to output a comma as well, but can surround that with other
+ * (white-space) decoration.
+ */
+ @Override
+ public void writeArrayValueSeparator(JsonGenerator gen) throws IOException {
+ gen.writeRaw(',');
+ _arrayIndenter.writeIndentation(gen, _nesting);
+ }
+
+ @Override
+ public void writeEndArray(JsonGenerator gen, int nrOfValues) throws IOException {
+ --_nesting;
+
+ if (_nesting == 0) {
+ gen.writeRaw('\n');
+ }
+ if (nrOfValues > 1) {
+ _arrayIndenter.writeIndentation(gen, _nesting);
+ } else {
+ gen.writeRaw(' ');
+ }
+ gen.writeRaw(']');
+ }
+
+ /*
+ /**********************************************************
+ /* Helper classes
+ /**********************************************************
+ */
+
+ /**
+ * Dummy implementation that adds no indentation whatsoever
+ */
+ public static class NopIndenter implements Indenter, java.io.Serializable {
+ public static final NopIndenter instance = new NopIndenter();
+
+ @Override
+ public void writeIndentation(JsonGenerator jg, int level) throws IOException {
+ }
+
+ @Override
+ public boolean isInline() {
+ return true;
+ }
+ }
+
+ /**
+ * This is a very simple indenter that only adds a
+ * single space for indentation. It is used as the default
+ * indenter for array values.
+ */
+ public static class FixedSpaceIndenter extends NopIndenter {
+ @SuppressWarnings("hiding")
+ public static final FixedSpaceIndenter instance = new FixedSpaceIndenter();
+
+ @Override
+ public void writeIndentation(JsonGenerator jg, int level) throws IOException {
+ jg.writeRaw(' ');
+ }
+
+ @Override
+ public boolean isInline() {
+ return true;
+ }
+ }
+}
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
index bfe0e33..07a7cc5 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
@@ -31,18 +31,20 @@
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.Arrays;
+import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.*;
import org.apache.asterix.common.config.GlobalConfig;
import org.apache.asterix.common.utils.ServletUtil.Servlets;
import org.apache.asterix.test.base.ComparisonException;
@@ -67,9 +69,7 @@
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.util.EntityUtils;
import org.apache.hyracks.util.StorageUtil;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class TestExecutor {
@@ -398,9 +398,10 @@
try {
// First try to parse the response for a JSON error response.
- JSONObject result = new JSONObject(errorBody);
- String[] errors = { result.getJSONArray("error-code").getString(0), result.getString("summary"),
- result.getString("stacktrace") };
+ ObjectMapper om = new ObjectMapper();
+ JsonNode result = om.readTree(errorBody);
+ String[] errors = { result.get("error-code").asText(), result.get("summary").asText(),
+ result.get("stacktrace").asText() };
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errors[2]);
exceptionMsg = "HTTP operation failed: " + errors[0] + "\nSTATUS LINE: " + httpResponse.getStatusLine()
+ "\nSUMMARY: " + errors[1] + "\nSTACKTRACE: " + errors[2];
@@ -540,15 +541,16 @@
throw new NullPointerException("Statement parameter required.");
}
RequestBuilder builder = RequestBuilder.post(endpoint);
- JSONObject content = new JSONObject();
- try {
- for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) {
- content.put(param.getName(), param.getValue());
- }
- } catch (JSONException e) {
- throw new IllegalArgumentException("Request object construction failed.", e);
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode content = om.createObjectNode();
+ for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) {
+ content.put(param.getName(), param.getValue());
}
- builder.setEntity(new StringEntity(content.toString(), ContentType.APPLICATION_JSON));
+ try {
+ builder.setEntity(new StringEntity(om.writeValueAsString(content), ContentType.APPLICATION_JSON));
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
@@ -1024,11 +1026,11 @@
StringWriter actual = new StringWriter();
IOUtils.copy(executeJSONGet, actual, StandardCharsets.UTF_8);
String config = actual.toString();
- String nodePid = StringUtils.substringBetween(config, "\"pid\": ", ",").trim();
- if (nodePid == null) {
- throw new IllegalArgumentException("Coud not find process for node id: " + nodeId);
+ int nodePid = new ObjectMapper().readValue(config, ObjectNode.class).get("pid").asInt();
+ if (nodePid <= 1) {
+ throw new IllegalArgumentException("Could not retrieve node pid from admin API");
}
- ProcessBuilder pb = new ProcessBuilder("kill", "-9", nodePid);
+ ProcessBuilder pb = new ProcessBuilder("kill", "-9", Integer.toString(nodePid));
pb.start().waitFor();
}
@@ -1122,15 +1124,22 @@
ArrayList<String> toBeDropped = new ArrayList<>();
InputStream resultStream = executeQueryService("select dv.DataverseName from Metadata.`Dataverse` as dv;",
getEndpoint(Servlets.QUERY_SERVICE));
- resultStream = ResultExtractor.extract(resultStream);
- StringWriter sw = new StringWriter();
- IOUtils.copy(resultStream, sw, StandardCharsets.UTF_8.name());
- JSONArray result = new JSONArray(sw.toString());
- for (int i = 0; i < result.length(); ++i) {
- JSONObject json = result.getJSONObject(i);
- String dvName = json.getString("DataverseName");
- if (!dvName.equals("Metadata") && !dvName.equals("Default")) {
- toBeDropped.add(dvName);
+ String out = IOUtils.toString(resultStream);
+ ObjectMapper om = new ObjectMapper();
+ om.setConfig(om.getDeserializationConfig().with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT));
+ JsonNode result;
+ try {
+ result = om.readValue(out, ObjectNode.class).get("results");
+ } catch (JsonMappingException e) {
+ result = om.createArrayNode();
+ }
+ for (int i = 0; i < result.size(); i++) {
+ JsonNode json = result.get(i);
+ if (json != null) {
+ String dvName = json.get("DataverseName").asText();
+ if (!dvName.equals("Metadata") && !dvName.equals("Default")) {
+ toBeDropped.add(dvName);
+ }
}
}
if (!toBeDropped.isEmpty()) {
@@ -1151,4 +1160,5 @@
throw th;
}
}
+
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java
index 06aafdd..7a3a376 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java
@@ -18,12 +18,13 @@
*/
package org.apache.asterix.external.feed.message;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.active.EntityId;
import org.apache.asterix.external.feed.management.FeedConnectionId;
import org.apache.asterix.external.util.FeedConstants;
import org.apache.asterix.external.util.FeedUtils.FeedRuntimeType;
-import org.json.JSONException;
-import org.json.JSONObject;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* @deprecated A feed control message indicating the need to end the feed. This message is dispatched
@@ -82,8 +83,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject obj = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode obj = om.createObjectNode();
obj.put(FeedConstants.MessageConstants.MESSAGE_TYPE, messageType.name());
obj.put(FeedConstants.MessageConstants.DATAVERSE, connectionId.getFeedId().getDataverse());
obj.put(FeedConstants.MessageConstants.FEED, connectionId.getFeedId().getEntityName());
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
index d23d490..95a5cd1 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
@@ -18,20 +18,20 @@
*/
package org.apache.asterix.external.parser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.builders.AbvsBuilderFactory;
import org.apache.asterix.builders.IARecordBuilder;
import org.apache.asterix.builders.IAsterixListBuilder;
import org.apache.asterix.builders.ListBuilderFactory;
-import org.apache.asterix.builders.OrderedListBuilder;
import org.apache.asterix.builders.RecordBuilderFactory;
+import org.apache.asterix.builders.UnorderedListBuilder;
import org.apache.asterix.external.api.IRawRecord;
import org.apache.asterix.external.api.IRecordDataParser;
import org.apache.asterix.om.base.AMutablePoint;
import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.AUnionType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.util.container.IObjectPool;
@@ -40,12 +40,10 @@
import org.apache.hyracks.data.std.api.IMutableValueStorage;
import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
import org.apache.hyracks.util.string.UTF8StringWriter;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import java.io.DataOutput;
import java.io.IOException;
+import java.util.Iterator;
public class TweetParser extends AbstractDataParser implements IRecordDataParser<String> {
private final IObjectPool<IARecordBuilder, ATypeTag> recordBuilderPool = new ListObjectPool<>(
@@ -62,121 +60,85 @@
aPoint = new AMutablePoint(0, 0);
}
- private void parseJSONArray(JSONArray jArray, DataOutput output, AOrderedListType orderedListType)
- throws IOException, JSONException {
+ private void parseUnorderedList(JsonNode jArray, DataOutput output) throws IOException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
- OrderedListBuilder orderedList = (OrderedListBuilder) getOrderedListBuilder();
+ UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder();
- orderedList.reset(orderedListType);
- for (int iter1 = 0; iter1 < jArray.length(); iter1++) {
+ unorderedListBuilder.reset(null);
+ for (int iter1 = 0; iter1 < jArray.size(); iter1++) {
itemBuffer.reset();
- if (writeField(jArray.get(iter1), orderedListType == null ? null : orderedListType.getItemType(),
- itemBuffer.getDataOutput())) {
- orderedList.addItem(itemBuffer);
+ if (writeField(jArray.get(iter1), null, itemBuffer.getDataOutput())) {
+ unorderedListBuilder.addItem(itemBuffer);
}
}
- orderedList.write(output, true);
+ unorderedListBuilder.write(output, true);
}
- private boolean writeFieldWithFieldType(Object fieldObj, IAType fieldType, DataOutput out)
- throws HyracksDataException {
+ private boolean writeField(JsonNode fieldObj, IAType fieldType, DataOutput out) throws IOException {
boolean writeResult = true;
- IAType chkFieldType;
- chkFieldType = fieldType instanceof AUnionType ? ((AUnionType) fieldType).getActualType() : fieldType;
- try {
- switch (chkFieldType.getTypeTag()) {
+ if (fieldType != null) {
+ switch (fieldType.getTypeTag()) {
case STRING:
- out.write(fieldType.getTypeTag().serialize());
- utf8Writer.writeUTF8(fieldObj.toString(), out);
+ out.write(BuiltinType.ASTRING.getTypeTag().serialize());
+ utf8Writer.writeUTF8(fieldObj.asText(), out);
break;
case INT64:
- out.write(fieldType.getTypeTag().serialize());
- if (fieldObj instanceof Integer) {
- out.writeLong(((Integer) fieldObj).longValue());
- } else {
- out.writeLong((Long) fieldObj);
- }
+ aInt64.setValue(fieldObj.asLong());
int64Serde.serialize(aInt64, out);
break;
case INT32:
- out.write(fieldType.getTypeTag().serialize());
- out.writeInt((Integer) fieldObj);
+ out.write(BuiltinType.AINT32.getTypeTag().serialize());
+ out.writeInt(fieldObj.asInt());
break;
case DOUBLE:
- out.write(fieldType.getTypeTag().serialize());
- out.writeDouble((Double) fieldObj);
+ out.write(BuiltinType.ADOUBLE.getTypeTag().serialize());
+ out.writeDouble(fieldObj.asDouble());
break;
case BOOLEAN:
- out.write(fieldType.getTypeTag().serialize());
- out.writeBoolean((Boolean) fieldObj);
+ out.write(BuiltinType.ABOOLEAN.getTypeTag().serialize());
+ out.writeBoolean(fieldObj.asBoolean());
break;
case RECORD:
- if (((JSONObject) fieldObj).length() != 0) {
- writeResult = writeRecord((JSONObject) fieldObj, out, (ARecordType) chkFieldType);
- } else {
- writeResult = false;
- }
- break;
- case ORDEREDLIST:
- if (((JSONArray) fieldObj).length() != 0) {
- parseJSONArray((JSONArray) fieldObj, out, (AOrderedListType) chkFieldType);
- } else {
- writeResult = false;
- }
+ writeRecord(fieldObj, out, (ARecordType) fieldType);
break;
default:
writeResult = false;
}
- } catch (IOException | JSONException e) {
- throw new HyracksDataException(e);
- }
- return writeResult;
- }
-
- private boolean writeFieldWithoutFieldType(Object fieldObj, DataOutput out) throws HyracksDataException {
- boolean writeResult = true;
- try {
- if (fieldObj == JSONObject.NULL) {
+ } else {
+ if (fieldObj.isNull()) {
nullSerde.serialize(ANull.NULL, out);
- } else if (fieldObj instanceof Integer) {
+ } else if (fieldObj.isInt()) {
out.write(BuiltinType.AINT32.getTypeTag().serialize());
- out.writeInt((Integer) fieldObj);
- } else if (fieldObj instanceof Boolean) {
+ out.writeInt(fieldObj.asInt());
+ } else if (fieldObj.isBoolean()) {
out.write(BuiltinType.ABOOLEAN.getTypeTag().serialize());
- out.writeBoolean((Boolean) fieldObj);
- } else if (fieldObj instanceof Double) {
+ out.writeBoolean(fieldObj.asBoolean());
+ } else if (fieldObj.isDouble()) {
out.write(BuiltinType.ADOUBLE.getTypeTag().serialize());
- out.writeDouble((Double) fieldObj);
- } else if (fieldObj instanceof Long) {
+ out.writeDouble(fieldObj.asDouble());
+ } else if (fieldObj.isLong()) {
out.write(BuiltinType.AINT64.getTypeTag().serialize());
- out.writeLong((Long) fieldObj);
- } else if (fieldObj instanceof String) {
+ out.writeLong(fieldObj.asLong());
+ } else if (fieldObj.isTextual()) {
out.write(BuiltinType.ASTRING.getTypeTag().serialize());
- utf8Writer.writeUTF8((String) fieldObj, out);
- } else if (fieldObj instanceof JSONArray) {
- if (((JSONArray) fieldObj).length() != 0) {
- parseJSONArray((JSONArray) fieldObj, out, null);
+ utf8Writer.writeUTF8(fieldObj.asText(), out);
+ } else if (fieldObj.isArray()) {
+ if ((fieldObj).size() != 0) {
+ parseUnorderedList(fieldObj, out);
} else {
writeResult = false;
}
- } else if (fieldObj instanceof JSONObject) {
- if (((JSONObject) fieldObj).length() != 0) {
- writeResult = writeRecord((JSONObject) fieldObj, out, null);
+ } else if (fieldObj.isObject()) {
+ if ((fieldObj).size() != 0) {
+ writeRecord(fieldObj, out, null);
} else {
writeResult = false;
}
}
- } catch (IOException | JSONException e) {
- throw new HyracksDataException(e);
}
return writeResult;
}
- private boolean writeField(Object fieldObj, IAType fieldType, DataOutput out) throws HyracksDataException {
- return fieldType == null ? writeFieldWithoutFieldType(fieldObj, out)
- : writeFieldWithFieldType(fieldObj, fieldType, out);
- }
-
private int checkAttrNameIdx(String[] nameList, String name) {
int idx = 0;
if (nameList != null) {
@@ -190,13 +152,11 @@
return -1;
}
- public boolean writeRecord(JSONObject obj, DataOutput out, ARecordType curRecType)
- throws IOException, JSONException {
+ public void writeRecord(JsonNode obj, DataOutput out, ARecordType curRecType) throws IOException {
IAType[] curTypes = null;
String[] curFNames = null;
int fieldN;
int attrIdx;
- boolean writeRecord = false;
ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
@@ -216,9 +176,8 @@
for (int iter1 = 0; iter1 < fieldN; iter1++) {
fieldValueBuffer.reset();
DataOutput fieldOutput = fieldValueBuffer.getDataOutput();
- if (obj.isNull(curFNames[iter1])) {
- if (curRecType.getFieldType(curFNames[iter1]) != null
- && !(curRecType.getFieldType(curFNames[iter1]) instanceof AUnionType)) {
+ if (obj.get(curFNames[iter1]).isNull()) {
+ if (curRecType.isClosedField(curFNames[iter1])) {
throw new HyracksDataException("Closed field " + curFNames[iter1] + " has null value.");
} else {
continue;
@@ -226,15 +185,18 @@
} else {
if (writeField(obj.get(curFNames[iter1]), curTypes[iter1], fieldOutput)) {
recBuilder.addField(iter1, fieldValueBuffer);
- writeRecord = true;
}
}
}
} else {
//open record type
+ int closedFieldCount = 0;
IAType curFieldType = null;
- for (String attrName : JSONObject.getNames(obj)) {
- if (obj.isNull(attrName) || obj.length() == 0) {
+ String attrName;
+ Iterator<String> iter = obj.fieldNames();
+ while (iter.hasNext()) {
+ attrName = iter.next();
+ if (obj.get(attrName).isNull() || obj.size() == 0) {
continue;
}
attrIdx = checkAttrNameIdx(curFNames, attrName);
@@ -245,29 +207,29 @@
fieldNameBuffer.reset();
DataOutput fieldOutput = fieldValueBuffer.getDataOutput();
if (writeField(obj.get(attrName), curFieldType, fieldOutput)) {
- writeRecord = true;
if (attrIdx == -1) {
aString.setValue(attrName);
stringSerde.serialize(aString, fieldNameBuffer.getDataOutput());
recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
} else {
recBuilder.addField(attrIdx, fieldValueBuffer);
+ closedFieldCount++;
}
}
}
+ if (curRecType != null && closedFieldCount < curFNames.length) {
+ throw new HyracksDataException("Non-null field is null");
+ }
}
- if (writeRecord) {
- recBuilder.write(out, true);
- }
- return writeRecord;
+ recBuilder.write(out, true);
}
private IARecordBuilder getRecordBuilder() {
return recordBuilderPool.allocate(ATypeTag.RECORD);
}
- private IAsterixListBuilder getOrderedListBuilder() {
- return listBuilderPool.allocate(ATypeTag.ORDEREDLIST);
+ private IAsterixListBuilder getUnorderedListBuilder() {
+ return listBuilderPool.allocate(ATypeTag.UNORDEREDLIST);
}
private ArrayBackedValueStorage getTempBuffer() {
@@ -279,9 +241,9 @@
try {
//TODO get rid of this temporary json
resetPools();
- JSONObject jsObj = new JSONObject(record.get());
- writeRecord(jsObj, out, recordType);
- } catch (JSONException | IOException e) {
+ ObjectMapper om = new ObjectMapper();
+ writeRecord(om.readTree(record.get()), out, recordType);
+ } catch (IOException e) {
throw new HyracksDataException(e);
}
}
diff --git a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm
index b155305..579caac 100644
--- a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm
+++ b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm
@@ -1,10 +1,34 @@
{
- "metadata_node": "asterix_nc1",
- "partitions": {
- "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1",
- "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1",
- "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
+ "metadata_node" : "asterix_nc1",
+ "partitions" : {
+ "0" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 0
},
- "state": "ACTIVE"
+ "1" : {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc1",
+ "active" : true,
+ "iodeviceNum" : 1
+ },
+ "2" : {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "3" : {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ }
+ },
+ "state" : "ACTIVE"
}
\ No newline at end of file
diff --git a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm
index 6b31475..5f58ff7 100644
--- a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm
+++ b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm
@@ -1,10 +1,34 @@
{
- "metadata_node": "asterix_nc2",
- "partitions": {
- "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc2",
- "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc2",
- "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2",
- "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2"
+ "metadata_node" : "asterix_nc2",
+ "partitions" : {
+ "0" : {
+ "partitionId" : 0,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
},
- "state": "ACTIVE"
+ "1" : {
+ "partitionId" : 1,
+ "nodeId" : "asterix_nc1",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ },
+ "2" : {
+ "partitionId" : 2,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 0
+ },
+ "3" : {
+ "partitionId" : 3,
+ "nodeId" : "asterix_nc2",
+ "activeNodeId" : "asterix_nc2",
+ "active" : true,
+ "iodeviceNum" : 1
+ }
+ },
+ "state" : "ACTIVE"
}
\ No newline at end of file
diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml
index dccbcb1..2fa86b4 100644
--- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml
+++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml
@@ -48,9 +48,12 @@
<version>2.2.1</version>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <type>jar</type>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
</dependency>
</dependencies>
</project>
diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
index d7479bc..909edc3 100644
--- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
+++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
@@ -33,7 +33,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
-import org.json.JSONException;
/**
* @goal generate-record-manager
@@ -95,8 +94,6 @@
type.addToMap(typeMap);
} catch (FileNotFoundException fnfe) {
throw new MojoExecutionException("could not find type description file " + inputFiles[i], fnfe);
- } catch (JSONException jse) {
- throw new MojoExecutionException("could not parse type description file " + inputFiles[i], jse);
} catch (IOException e) {
throw new MojoExecutionException("error closing type description file " + inputFiles[i], e);
}
diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java
index 6702a8f..d322371 100644
--- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java
+++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java
@@ -19,26 +19,41 @@
package org.apache.asterix.recordmanagergenerator;
+import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class RecordType {
enum Type {
- BYTE (1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append", "TypeUtil.Byte.appendFixed"),
- SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "TypeUtil.Short.append", "TypeUtil.Short.appendFixed"),
- INT (4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append", "TypeUtil.Int.appendFixed"),
- GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "TypeUtil.Global.append", "TypeUtil.Global.appendFixed");
+ BYTE(1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append", "TypeUtil.Byte.appendFixed"),
+ SHORT(
+ 2,
+ "short",
+ "getShort",
+ "putShort",
+ "(short)0xdead",
+ "TypeUtil.Short.append",
+ "TypeUtil.Short.appendFixed"),
+ INT(4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append", "TypeUtil.Int.appendFixed"),
+ GLOBAL(
+ 8,
+ "long",
+ "getLong",
+ "putLong",
+ "0xdeadbeefdeadbeefl",
+ "TypeUtil.Global.append",
+ "TypeUtil.Global.appendFixed");
- Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender, String tabAppender) {
+ Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender,
+ String tabAppender) {
this.size = size;
this.javaType = javaType;
this.bbGetter = bbGetter;
@@ -73,10 +88,10 @@
this.accessible = accessible;
}
- public static Field fromJSON(JSONObject obj) throws JSONException {
- String name = obj.getString("name");
- Type type = parseType(obj.getString("type"));
- String initial = obj.optString("initial", null);
+ public static Field fromJSON(JsonNode obj) {
+ String name = obj.get("name").asText();
+ Type type = parseType(obj.get("type").asText());
+ String initial = obj.get("initial") == null ? null : obj.get("initial").asText();
return new Field(name, type, initial, -1, true);
}
@@ -96,7 +111,7 @@
String methodName(String prefix) {
String words[] = name.split(" ");
- assert(words.length > 0);
+ assert words.length > 0;
StringBuilder sb = new StringBuilder(prefix);
for (int j = 0; j < words.length; ++j) {
String word = words[j];
@@ -108,11 +123,8 @@
StringBuilder appendMemoryManagerGetMethod(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("public ")
- .append(type.javaType)
- .append(' ')
- .append(methodName("get"))
- .append("(int slotNum) {\n");
+ sb.append("public ").append(type.javaType).append(' ').append(methodName("get"))
+ .append("(int slotNum) {\n");
sb = indent(sb, indent, level + 1);
sb.append("final Buffer buf = buffers.get(slotNum / NO_SLOTS);\n");
sb = indent(sb, indent, level + 1);
@@ -120,11 +132,8 @@
sb = indent(sb, indent, level + 1);
sb.append("final ByteBuffer b = buf.bb;\n");
sb = indent(sb, indent, level + 1);
- sb.append("return b.")
- .append(type.bbGetter)
- .append("((slotNum % NO_SLOTS) * ITEM_SIZE + ")
- .append(offsetName())
- .append(");\n");
+ sb.append("return b.").append(type.bbGetter).append("((slotNum % NO_SLOTS) * ITEM_SIZE + ")
+ .append(offsetName()).append(");\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -132,19 +141,13 @@
StringBuilder appendMemoryManagerSetMethod(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("public void ")
- .append(methodName("set"))
- .append("(int slotNum, ")
- .append(type.javaType)
- .append(" value) {\n");
+ sb.append("public void ").append(methodName("set")).append("(int slotNum, ").append(type.javaType)
+ .append(" value) {\n");
sb = indent(sb, indent, level + 1);
sb.append("final ByteBuffer b = buffers.get(slotNum / NO_SLOTS).bb;\n");
sb = indent(sb, indent, level + 1);
- sb.append("b.")
- .append(type.bbSetter)
- .append("((slotNum % NO_SLOTS) * ITEM_SIZE + ")
- .append(offsetName())
- .append(", value);\n");
+ sb.append("b.").append(type.bbSetter).append("((slotNum % NO_SLOTS) * ITEM_SIZE + ").append(offsetName())
+ .append(", value);\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -152,23 +155,18 @@
StringBuilder appendArenaManagerGetMethod(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("public ")
- .append(type.javaType)
- .append(' ')
- .append(methodName("get"))
- .append("(long slotNum) {\n");
+ sb.append("public ").append(type.javaType).append(' ').append(methodName("get"))
+ .append("(long slotNum) {\n");
if (initial != null) {
- sb = indent(sb, indent, level + 1);
- sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
+ sb = indent(sb, indent, level + 1);
+ sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n");
sb = indent(sb, indent, level + 1);
- sb.append("return get(arenaId).")
- .append(methodName("get"))
- .append("(localId);\n");
+ sb.append("return get(arenaId).").append(methodName("get")).append("(localId);\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -176,23 +174,18 @@
StringBuilder appendArenaManagerSetMethod(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("public void ")
- .append(methodName("set"))
- .append("(long slotNum, ")
- .append(type.javaType)
- .append(" value) {\n");
+ sb.append("public void ").append(methodName("set")).append("(long slotNum, ").append(type.javaType)
+ .append(" value) {\n");
if (initial != null) {
- sb = indent(sb, indent, level + 1);
- sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
+ sb = indent(sb, indent, level + 1);
+ sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n");
sb = indent(sb, indent, level + 1);
- sb.append("get(arenaId).")
- .append(methodName("set"))
- .append("(localId, value);\n");
+ sb.append("get(arenaId).").append(methodName("set")).append("(localId, value);\n");
sb = indent(sb, indent, level);
sb.append("}\n");
return sb;
@@ -200,11 +193,7 @@
StringBuilder appendInitializers(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("bb.")
- .append(type.bbSetter)
- .append("(slotNum * ITEM_SIZE + ")
- .append(offsetName())
- .append(", ");
+ sb.append("bb.").append(type.bbSetter).append("(slotNum * ITEM_SIZE + ").append(offsetName()).append(", ");
if (initial != null) {
sb.append(initial);
} else {
@@ -219,17 +208,11 @@
return sb;
}
sb = indent(sb, indent, level);
- sb.append("if (bb.")
- .append(type.bbGetter)
- .append("(itemOffset + ")
- .append(offsetName())
- .append(") == ")
- .append(type.deadMemInitializer)
- .append(") {\n");
+ sb.append("if (bb.").append(type.bbGetter).append("(itemOffset + ").append(offsetName()).append(") == ")
+ .append(type.deadMemInitializer).append(") {\n");
sb = indent(sb, indent, level + 1);
- sb.append("String msg = \"invalid value in field ")
- .append(offsetName())
- .append(" of slot \" + TypeUtil.Global.toString(slotNum);\n");
+ sb.append("String msg = \"invalid value in field ").append(offsetName())
+ .append(" of slot \" + TypeUtil.Global.toString(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("throw new IllegalStateException(msg);\n");
sb = indent(sb, indent, level);
@@ -239,7 +222,7 @@
String offsetName() {
String words[] = name.split(" ");
- assert(words.length > 0);
+ assert (words.length > 0);
StringBuilder sb = new StringBuilder(words[0].toUpperCase());
for (int j = 1; j < words.length; ++j) {
sb.append("_").append(words[j].toUpperCase());
@@ -271,18 +254,17 @@
addField("next free slot", Type.INT, "-1", false);
}
- public static RecordType read(Reader reader) throws JSONException {
- JSONTokener tok = new JSONTokener(reader);
- JSONObject obj = new JSONObject(tok);
- return fromJSON(obj);
+ public static RecordType read(Reader reader) throws IOException {
+ ObjectNode node = new ObjectMapper().readValue(reader, ObjectNode.class);
+ return fromJSON(node);
}
- public static RecordType fromJSON(JSONObject obj) throws JSONException {
- RecordType result = new RecordType(obj.getString("name"));
- JSONArray fields = obj.getJSONArray("fields");
- for (int i = 0; i < fields.length(); ++i) {
- JSONObject field = fields.getJSONObject(i);
- result.fields.add(Field.fromJSON(field));
+ public static RecordType fromJSON(ObjectNode obj) {
+ RecordType result = new RecordType(obj.get("name").asText());
+ JsonNode fields = obj.get("fields");
+ for (int i = 0; i < fields.size(); i++) {
+ JsonNode n = fields.get(i);
+ result.fields.add(Field.fromJSON(n));
}
return result;
}
@@ -298,7 +280,7 @@
}
private void addField(String name, Type type, String initial, boolean accessible) {
- if (! modifiable) {
+ if (!modifiable) {
throw new IllegalStateException("cannot modify type anmore");
}
fields.add(new Field(name, type, initial, -1, accessible));
@@ -319,7 +301,9 @@
field.offset = totalSize;
final int size = field.type.size;
totalSize += size;
- if (size > alignment) alignment = size;
+ if (size > alignment) {
+ alignment = size;
+ }
}
if (totalSize % alignment != 0) {
totalSize = ((totalSize / alignment) + 1) * alignment;
@@ -340,17 +324,12 @@
StringBuilder appendConstants(StringBuilder sb, String indent, int level) {
sb = indent(sb, indent, level);
- sb.append("public static int ITEM_SIZE = ")
- .append(totalSize)
- .append(";\n");
+ sb.append("public static int ITEM_SIZE = ").append(totalSize).append(";\n");
for (int i = 0; i < fields.size(); ++i) {
final Field field = fields.get(i);
sb = indent(sb, indent, level);
- sb.append("public static int ")
- .append(field.offsetName())
- .append(" = ")
- .append(field.offset).append("; // size: ")
- .append(field.type.size).append("\n");
+ sb.append("public static int ").append(field.offsetName()).append(" = ").append(field.offset)
+ .append("; // size: ").append(field.type.size).append("\n");
}
return sb;
}
@@ -366,22 +345,14 @@
for (int i = 0; i < fields.size(); ++i) {
final Field field = fields.get(i);
sb = indent(sb, indent, level);
- sb.append("sb.append(\"")
- .append(padRight(field.name, maxNameWidth))
- .append(" | \");\n");
+ sb.append("sb.append(\"").append(padRight(field.name, maxNameWidth)).append(" | \");\n");
sb = indent(sb, indent, level);
sb.append("for (int i = 0; i < NO_SLOTS; ++i) {\n");
sb = indent(sb, indent, level + 1);
- sb.append(field.type.javaType)
- .append(" value = bb.")
- .append(field.type.bbGetter)
- .append("(i * ITEM_SIZE + ")
- .append(field.offsetName())
- .append(");\n");
+ sb.append(field.type.javaType).append(" value = bb.").append(field.type.bbGetter)
+ .append("(i * ITEM_SIZE + ").append(field.offsetName()).append(");\n");
sb = indent(sb, indent, level + 1);
- sb.append("sb = ")
- .append(field.type.tabAppender)
- .append("(sb, value);\n");
+ sb.append("sb = ").append(field.type.tabAppender).append("(sb, value);\n");
sb = indent(sb, indent, level + 1);
sb.append("sb.append(\" | \");\n");
sb = indent(sb, indent, level);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java
index b3ee50e..db87ce0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java
@@ -18,13 +18,13 @@
*/
package org.apache.asterix.om.base;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ABinary implements IAObject {
@@ -115,15 +115,16 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
int start = getStart();
- JSONArray byteArray = new JSONArray();
+ ArrayNode byteArray = om.createArrayNode();
for (int i = 0; i < getLength(); i++) {
- byteArray.put(bytes[start + i]);
+ byteArray.add(bytes[start + i]);
}
- json.put("ABinary", byteArray);
+ json.set("ABinary", byteArray);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java
index 503c920..a15dbad 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java
@@ -18,9 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -139,14 +139,15 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONArray bitArray = new JSONArray();
+ ArrayNode bitArray = om.createArrayNode();
for (int i = 0; i < intArray.length; i++) {
- bitArray.put(intArray[i]);
+ bitArray.add(intArray[i]);
}
- json.put("ABitArray", bitArray);
+ json.set("ABitArray", bitArray);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
index 2a56cff..a1011d8 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java
@@ -18,12 +18,12 @@
*/
package org.apache.asterix.om.base;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public final class ABoolean implements IAObject {
@@ -80,7 +80,7 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- return new JSONObject().put("ABoolean", bVal);
+ public ObjectNode toJSON() {
+ return new ObjectMapper().createObjectNode().put("ABoolean", bVal);
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java
index a99bcda..4878d7a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -82,13 +82,14 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject circle = new JSONObject();
- circle.put("center", center);
+ ObjectNode circle = om.createObjectNode();
+ circle.set("center", center.toJSON());
circle.put("radius", radius);
- json.put("ACircle", circle);
+ json.set("ACircle", circle);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java
index 789ad31..9373f90 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java
@@ -20,8 +20,8 @@
import java.io.IOException;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -96,8 +96,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ADate", chrononTimeInDay);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java
index f3592e3..75f653e 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java
@@ -20,13 +20,13 @@
import java.io.IOException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* ADateTime type represents the timestamp values.
@@ -136,8 +136,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ADateTime", chrononTime);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java
index cb298b7..d31b8c8 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -42,12 +43,13 @@
* @see org.apache.hyracks.api.dataflow.value.JSONSerializable#toJSON()
*/
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject duration = new JSONObject();
+ ObjectNode duration = om.createObjectNode();
duration.put("milliseconds", chrononInMillisecond);
- json.put("ADuration", duration);
+ json.set("ADuration", duration);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java
index 4746773..7a2fe06 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -78,8 +79,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ADouble", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java
index 27b551b..a3f23d3 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -117,13 +118,14 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject duration = new JSONObject();
+ ObjectNode duration = om.createObjectNode();
duration.put("months", chrononInMonth);
duration.put("milliseconds", chrononInMillisecond);
- json.put("ADuration", duration);
+ json.set("ADuration", duration);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java
index 50d1825..f29e659 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -78,8 +79,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AFloat", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java
index 11dd486..934ef0a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -68,8 +69,10 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AInt16", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java
index 5bbcf77..38a87d7 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -93,8 +94,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AInt32", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java
index 9047833..02bc8b0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -67,8 +68,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AInt64", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java
index 8360d99..5623d37 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -67,8 +68,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AInt8", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java
index 5fa99a9..9dfaf3b 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java
@@ -20,8 +20,7 @@
import java.io.IOException;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -156,7 +155,7 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
+ public ObjectNode toJSON() {
// TODO(madhusudancs): Remove this method when a printer based JSON serializer is implemented.
return null;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java
index 4908fa8..9134a3c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -75,13 +75,14 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject line = new JSONObject();
- line.put("p1", p1);
- line.put("p2", p2);
- json.put("ALine", line);
+ ObjectNode line = om.createObjectNode();
+ line.set("p1", p1.toJSON());
+ line.set("p2", p2.toJSON());
+ json.set("ALine", line);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java
index 6c357e6..2455311 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java
@@ -18,12 +18,12 @@
*/
package org.apache.asterix.om.base;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
// This class represents a MISSING object.
public class AMissing implements IAObject {
@@ -59,8 +59,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AMissing", "missing");
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java
index 859ebb3..ebf7975 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java
@@ -19,12 +19,12 @@
package org.apache.asterix.om.base;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ANull implements IAObject {
@@ -59,8 +59,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ANull", "null");
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java
index 7e67e0a..8138a51 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java
@@ -21,14 +21,14 @@
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AOrderedList implements IACollection {
@@ -126,14 +126,15 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONArray list = new JSONArray();
+ ArrayNode list = om.createArrayNode();
for (IAObject v : values) {
- list.put(v.toJSON());
+ list.add(v.toJSON());
}
- json.put("AOrderedList", list);
+ json.set("AOrderedList", list);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint.java
index c1de289..a847cff 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -75,13 +75,13 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
-
- JSONObject point = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
+ ObjectNode point = om.createObjectNode();
point.put("x", x);
point.put("y", y);
- json.put("APoint", point);
+ json.set("APoint", point);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint3D.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint3D.java
index 28b29e7..7b8ad94 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint3D.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APoint3D.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -81,14 +81,15 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject point = new JSONObject();
+ ObjectNode point = om.createObjectNode();
point.put("x", x);
point.put("y", y);
point.put("z", z);
- json.put("APoint3D", point);
+ json.set("APoint3D", point);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APolygon.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APolygon.java
index 142c4a0..7a3a167 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APolygon.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/APolygon.java
@@ -18,9 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -95,14 +95,15 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONArray polygon = new JSONArray();
+ ArrayNode polygon = om.createArrayNode();
for (int i = 0; i < points.length; i++) {
- polygon.put(points[i].toJSON());
+ polygon.add(points[i].toJSON());
}
- json.put("APolygon", polygon);
+ json.set("APolygon", polygon);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARecord.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARecord.java
index c35f000..cda4d2b 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARecord.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARecord.java
@@ -18,12 +18,13 @@
*/
package org.apache.asterix.om.base;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class ARecord implements IAObject {
public static final ARecord EMPTY_OPEN_RECORD = new ARecord(ARecordType.FULLY_OPEN_RECORD_TYPE, new IAObject[] {});
@@ -104,16 +105,17 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONArray record = new JSONArray();
+ ArrayNode record = om.createArrayNode();
for (int i = 0; i < fields.length; i++) {
- JSONObject item = new JSONObject();
- item.put(type.getFieldNames()[i], fields[i]);
- record.put(item);
+ ObjectNode item = om.createObjectNode();
+ item.set(type.getFieldNames()[i], fields[i].toJSON());
+ record.add(item);
}
- json.put("ARecord", record);
+ json.set("ARecord", record);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARectangle.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARectangle.java
index 2bb780a..4bff3a8 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARectangle.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ARectangle.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -75,13 +75,14 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject rectangle = new JSONObject();
- rectangle.put("p1", p1);
- rectangle.put("p2", p2);
- json.put("ARectangle", rectangle);
+ ObjectNode rectangle = om.createObjectNode();
+ rectangle.set("p1", p1.toJSON());
+ rectangle.set("p2", p2.toJSON());
+ json.set("ARectangle", rectangle);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AString.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AString.java
index a1a89fe..b0cedbc 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AString.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AString.java
@@ -20,12 +20,13 @@
import java.io.Serializable;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AString implements IAObject, Serializable {
@@ -78,8 +79,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AString", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ATime.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ATime.java
index 7cc303e..2a9e6da 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ATime.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ATime.java
@@ -20,8 +20,8 @@
import java.io.IOException;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -112,8 +112,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ATime", chrononTime);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUUID.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUUID.java
index 025866c..2c7f531 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUUID.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUUID.java
@@ -24,13 +24,13 @@
import java.io.IOException;
import java.util.Arrays;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AUUID implements IAObject {
@@ -57,8 +57,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("AUUID", toString());
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUnorderedList.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUnorderedList.java
index 8f19b7e..62043f2 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUnorderedList.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AUnorderedList.java
@@ -21,13 +21,13 @@
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.AUnorderedListType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AUnorderedList implements IACollection {
@@ -117,14 +117,15 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONArray list = new JSONArray();
+ ArrayNode list = om.createArrayNode();
for (IAObject v : values) {
- list.put(v.toJSON());
+ list.add(v.toJSON());
}
- json.put("AUnorderedList", list);
+ json.set("AUnorderedList", list);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AYearMonthDuration.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AYearMonthDuration.java
index 8fd21dc..ce8e7c5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AYearMonthDuration.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AYearMonthDuration.java
@@ -18,8 +18,9 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -50,12 +51,13 @@
* @see org.apache.hyracks.api.dataflow.value.JSONSerializable#toJSON()
*/
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
- JSONObject duration = new JSONObject();
+ ObjectNode duration = om.createObjectNode();
duration.put("months", chrononInMonth);
- json.put("ADuration", duration);
+ json.set("ADuration", duration);
return json;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ShortWithoutTypeInfo.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ShortWithoutTypeInfo.java
index e1206ac..b600995 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ShortWithoutTypeInfo.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ShortWithoutTypeInfo.java
@@ -18,8 +18,8 @@
*/
package org.apache.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.types.BuiltinType;
@@ -91,8 +91,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject json = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode json = om.createObjectNode();
json.put("ShortWithoutTypeInfo", value);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
index d523124..9f7f360 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
@@ -18,9 +18,9 @@
*/
package org.apache.asterix.om.types;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.om.base.IAObject;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AOrderedListType extends AbstractCollectionType {
@@ -76,10 +76,11 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", AOrderedListType.class.getName());
- type.put("item-type", itemType.toJSON());
+ type.set("item-type", itemType.toJSON());
return type;
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
index fc1108f..4ce1a6d 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
@@ -26,15 +26,15 @@
import java.util.Map;
import java.util.Set;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.annotations.IRecordTypeAnnotation;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.util.NonTaggedFormatUtil;
import org.apache.asterix.om.visitors.IOMVisitor;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* ARecordType is read-only and shared by different partitions at runtime.
@@ -327,8 +327,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", ARecordType.class.getName());
type.put("name", typeName);
if (isOpen) {
@@ -337,14 +338,14 @@
type.put("open", false);
}
- JSONArray fields = new JSONArray();
+ ArrayNode fields = om.createArrayNode();
for (int i = 0; i < fieldNames.length; i++) {
- JSONObject field = new JSONObject();
- field.put(fieldNames[i], fieldTypes[i].toJSON());
- fields.put(field);
+ ObjectNode field = om.createObjectNode();
+ field.set(fieldNames[i], fieldTypes[i].toJSON());
+ fields.add(field);
}
- type.put("fields", fields);
+ type.set("fields", fields);
return type;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
index 9eb2b88..af06108 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
@@ -22,12 +22,12 @@
import java.util.Iterator;
import java.util.List;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AUnionType extends AbstractComplexType {
@@ -203,21 +203,22 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", AUnionType.class.getName());
- JSONArray fields = new JSONArray();
+ ArrayNode fields = om.createArrayNode();
Iterator<IAType> iter = unionList.iterator();
if (iter.hasNext()) {
IAType t0 = iter.next();
- fields.put(t0.toJSON());
+ fields.add(t0.toJSON());
while (iter.hasNext()) {
- fields.put(iter.next().toJSON());
+ fields.add(iter.next().toJSON());
}
}
- type.put("fields", fields);
+ type.set("fields", fields);
return type;
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
index febc6ad..b4705ac 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
@@ -18,10 +18,10 @@
*/
package org.apache.asterix.om.types;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.om.base.AUnorderedList;
import org.apache.asterix.om.base.IAObject;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public class AUnorderedListType extends AbstractCollectionType {
@@ -77,10 +77,11 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", AUnorderedListType.class.getName());
- type.put("item-type", itemType.toJSON());
+ type.set("item-type", itemType.toJSON());
return type;
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
index 809578b..42745f4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
@@ -18,11 +18,11 @@
*/
package org.apache.asterix.om.types;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.visitors.IOMVisitor;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.node.ObjectNode;
public abstract class BuiltinType implements IAType {
@@ -63,8 +63,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ASTERIX_TYPE");
return type;
}
@@ -90,8 +91,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AInt8");
return type;
}
@@ -117,8 +119,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AInt16");
return type;
}
@@ -144,8 +147,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AInt32");
return type;
}
@@ -171,8 +175,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AInt64");
return type;
}
@@ -198,8 +203,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ABinary");
return type;
}
@@ -225,8 +231,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AFloat");
return type;
}
@@ -252,8 +259,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ADouble");
return type;
}
@@ -279,8 +287,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AString");
return type;
}
@@ -306,8 +315,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AMISSING");
return type;
}
@@ -333,8 +343,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ANULL");
return type;
}
@@ -360,8 +371,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ABoolean");
return type;
}
@@ -387,8 +399,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ATime");
return type;
}
@@ -414,8 +427,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ADate");
return type;
}
@@ -441,8 +455,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ADateTime");
return type;
}
@@ -468,8 +483,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ADuration");
return type;
}
@@ -495,8 +511,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "AYearMonthDuration");
return type;
}
@@ -522,8 +539,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ADayTimeDuration");
return type;
}
@@ -549,7 +567,7 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
+ public ObjectNode toJSON() {
return null;
}
};
@@ -574,8 +592,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "APoint");
return type;
}
@@ -601,8 +620,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "APoint3D");
return type;
}
@@ -628,8 +648,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ALINE");
return type;
}
@@ -655,8 +676,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "APOLYGON");
return type;
}
@@ -682,8 +704,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ACIRCLE");
return type;
}
@@ -709,8 +732,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ARECTANGLE");
return type;
}
@@ -736,8 +760,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ABitArray");
return type;
}
@@ -762,8 +787,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", getDisplayName());
return type;
}
@@ -794,8 +820,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "ANY");
return type;
}
@@ -826,8 +853,9 @@
}
@Override
- public JSONObject toJSON() throws JSONException {
- JSONObject type = new JSONObject();
+ public ObjectNode toJSON() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode type = om.createObjectNode();
type.put("type", "SHORTWITHOUTTYPEINFO");
return type;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/JSONDeserializerForTypes.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/JSONDeserializerForTypes.java
index b646ea1..8e8993a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/JSONDeserializerForTypes.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/JSONDeserializerForTypes.java
@@ -23,9 +23,11 @@
import java.util.ArrayList;
import java.util.List;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.AUnionType;
@@ -43,26 +45,26 @@
* @return an valid AsterixDB type.
* @throws Exception
*/
- public static IAType convertFromJSON(JSONObject typeInJSON) throws Exception {
- String typeName = typeInJSON.getString("type");
+ public static IAType convertFromJSON(JsonNode typeInJSON) throws Exception {
+ String typeName = typeInJSON.get("type").asText();
// Deals with ordered list.
if (typeName.equals(AOrderedListType.class.getName())) {
- IAType itemType = convertFromJSON((JSONObject) typeInJSON.get("item-type"));
+ IAType itemType = convertFromJSON(typeInJSON.get("item-type"));
return new AOrderedListType(itemType, "ordered-list");
}
// Deals with unordered list.
if (typeName.equals(AUnorderedListType.class.getName())) {
- IAType itemType = convertFromJSON((JSONObject) typeInJSON.get("item-type"));
+ IAType itemType = convertFromJSON(typeInJSON.get("item-type"));
return new AUnorderedListType(itemType, "unordered-list");
}
// Deals with Union Type.
if (typeName.equals(AUnionType.class.getName())) {
List<IAType> unionTypes = new ArrayList<IAType>();
- JSONArray fields = (JSONArray) typeInJSON.get("fields");
- for (int i = 0; i < fields.length(); i++) {
- JSONObject fieldType = (JSONObject) fields.get(i);
+ JsonNode fields = typeInJSON.get("fields");
+ for (int i = 0; i < fields.size(); i++) {
+ JsonNode fieldType = fields.get(i);
unionTypes.add(convertFromJSON(fieldType));
}
return new AUnionType(unionTypes, "union");
@@ -70,17 +72,17 @@
// Deals with record types.
if (typeName.equals(ARecordType.class.getName())) {
- String name = typeInJSON.getString("name");
- boolean openType = typeInJSON.getBoolean("open");
- JSONArray fields = typeInJSON.getJSONArray("fields");
- String[] fieldNames = new String[fields.length()];
- IAType[] fieldTypes = new IAType[fields.length()];
- for (int i = 0; i < fields.length(); ++i) {
- JSONObject field = (JSONObject) fields.get(i);
- JSONArray names = field.names();
- String fieldName = names.getString(0);
+ String name = typeInJSON.get("name").asText();
+ boolean openType = typeInJSON.get("open").asBoolean();
+ JsonNode fields = typeInJSON.get("fields");
+ String[] fieldNames = new String[fields.size()];
+ IAType[] fieldTypes = new IAType[fields.size()];
+ for (int i = 0; i < fields.size(); ++i) {
+ JsonNode field = fields.get(i);
+ List<String> names = Lists.newArrayList(field.fieldNames());
+ String fieldName = names.get(0);
fieldNames[i] = fieldName;
- fieldTypes[i] = convertFromJSON((JSONObject) field.get(fieldName));
+ fieldTypes[i] = convertFromJSON(field.get(fieldName));
}
return new ARecordType(name, fieldNames, fieldTypes, openType);
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/util/ClusterStateManager.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/util/ClusterStateManager.java
index 3ba1965..c79524a 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/util/ClusterStateManager.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/util/ClusterStateManager.java
@@ -31,6 +31,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.asterix.common.api.IClusterManagementWork.ClusterState;
import org.apache.asterix.common.cluster.ClusterPartition;
import org.apache.asterix.common.config.ReplicationProperties;
@@ -53,8 +55,8 @@
import org.apache.hyracks.api.application.IClusterLifecycleListener.ClusterEventType;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.exceptions.HyracksException;
-import org.json.JSONException;
-import org.json.JSONObject;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* A holder class for properties related to the Asterix cluster.
@@ -633,12 +635,15 @@
return metadataNodeActive;
}
- public synchronized JSONObject getClusterStateDescription() throws JSONException {
- JSONObject stateDescription = new JSONObject();
+ public synchronized ObjectNode getClusterStateDescription() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode stateDescription = om.createObjectNode();
stateDescription.put("state", state.name());
stateDescription.put("metadata_node", currentMetadataNode);
+ ArrayNode ncs = om.createArrayNode();
+ stateDescription.set("ncs",ncs);
for (Map.Entry<String, ClusterPartition[]> entry : node2PartitionsMap.entrySet()) {
- JSONObject nodeJSON = new JSONObject();
+ ObjectNode nodeJSON = om.createObjectNode();
nodeJSON.put("node_id", entry.getKey());
boolean allActive = true;
boolean anyActive = false;
@@ -657,17 +662,18 @@
: allActive ? "ACTIVE"
: anyActive ? "PARTIALLY_ACTIVE"
: "INACTIVE");
- nodeJSON.put("partitions", partitions);
- stateDescription.accumulate("ncs", nodeJSON);
+ nodeJSON.putPOJO("partitions", partitions);
+ ncs.add(nodeJSON);
}
return stateDescription;
}
- public synchronized JSONObject getClusterStateSummary() throws JSONException {
- JSONObject stateDescription = new JSONObject();
+ public synchronized ObjectNode getClusterStateSummary() {
+ ObjectMapper om = new ObjectMapper();
+ ObjectNode stateDescription = om.createObjectNode();
stateDescription.put("state", state.name());
- stateDescription.put("metadata_node", currentMetadataNode);
- stateDescription.put("partitions", clusterPartitions);
+ stateDescription.putPOJO("metadata_node", currentMetadataNode);
+ stateDescription.putPOJO("partitions", clusterPartitions);
return stateDescription;
}
}
diff --git a/asterixdb/pom.xml b/asterixdb/pom.xml
index ee5067d..675d549 100644
--- a/asterixdb/pom.xml
+++ b/asterixdb/pom.xml
@@ -68,7 +68,6 @@
<junit.version>4.12</junit.version>
<commons.io.version>2.5</commons.io.version>
<servlet.api.version>3.1.0</servlet.api.version>
- <json.version>20090211</json.version>
<jacoco.version>0.7.6.201602180812</jacoco.version>
</properties>
@@ -809,12 +808,6 @@
<type>test-jar</type>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>${json.version}</version>
- <type>jar</type>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.api.version}</version>
@@ -845,6 +838,16 @@
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.8.4</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.8.4</version>
+ </dependency>
</dependencies>
</dependencyManagement>
</project>