[NO ISSUE][MISC] Add ability to write messages to json object, etc.
- minor cleanup
Change-Id: Ib0a3a0bc2269c3bfa65a08a3c0a77aeb45b16e5d
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/15223
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/BaseClientRequest.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/BaseClientRequest.java
index eaca53b..99cda09 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/BaseClientRequest.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/BaseClientRequest.java
@@ -90,7 +90,7 @@
@Override
public String toJson() {
- return JSONUtil.convertNodeOrThrow(asJson());
+ return JSONUtil.convertNodeUnchecked(asJson());
}
protected ObjectNode asJson() {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
index 6b5cae2..284929f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
@@ -181,10 +181,9 @@
@Override
public synchronized IActiveEntityEventsListener[] getEventListeners() {
if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("getEventListeners() was called");
- LOGGER.trace("returning " + entityEventListeners.size() + " Listeners");
+ LOGGER.trace("getEventListeners() returning {} listeners", entityEventListeners.size());
}
- return entityEventListeners.values().toArray(new IActiveEntityEventsListener[entityEventListeners.size()]);
+ return entityEventListeners.values().toArray(IActiveEntityEventsListener[]::new);
}
@Override
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/fields/AbstractCodedMessagePrinter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/fields/AbstractCodedMessagePrinter.java
index 6270c4c..f1eb315 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/fields/AbstractCodedMessagePrinter.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/fields/AbstractCodedMessagePrinter.java
@@ -26,6 +26,9 @@
import org.apache.asterix.common.api.IResponseFieldPrinter;
import org.apache.hyracks.util.JSONUtil;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public abstract class AbstractCodedMessagePrinter implements IResponseFieldPrinter {
private enum CodedMessageField {
@@ -68,4 +71,14 @@
}
pw.print("]");
}
+
+ public ObjectNode appendTo(ObjectNode objectNode) {
+ ArrayNode array = objectNode.putArray(getName());
+ messages.forEach(codedMessage -> {
+ ObjectNode error = array.addObject();
+ error.put(CodedMessageField.CODE.str(), codedMessage.getCode());
+ error.put(CodedMessageField.MSG.str(), codedMessage.getMessage());
+ });
+ return objectNode;
+ }
}
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/RequestReference.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/RequestReference.java
index eb08c09..78b6b3b 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/RequestReference.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/RequestReference.java
@@ -79,6 +79,6 @@
object.put("time", time);
object.put("userAgent", userAgent);
object.put("remoteAddr", remoteAddr);
- return JSONUtil.convertNodeOrThrow(object);
+ return JSONUtil.convertNodeUnchecked(object);
}
}
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/JSONUtil.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/JSONUtil.java
index 5c1b292..f937e97 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/JSONUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/JSONUtil.java
@@ -35,6 +35,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.util.concurrent.UncheckedExecutionException;
public class JSONUtil {
@@ -53,11 +54,11 @@
return SORTED_MAPPER.writeValueAsString(SORTED_MAPPER.treeToValue(node, Object.class));
}
- public static String convertNodeOrThrow(final JsonNode node) {
+ public static String convertNodeUnchecked(final JsonNode node) throws UncheckedExecutionException {
try {
return convertNode(node);
} catch (JsonProcessingException e) {
- throw new IllegalStateException(e);
+ throw new UncheckedExecutionException(e);
}
}