[NO ISSUE] Minor refactoring/cleanup of nc detail servlets
Change-Id: Ib62cd5a6e193e61d52121f45be3ae6067b16f29e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2476
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
index 992b85b..c4bd054 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.api.http.server;
+import static org.apache.asterix.api.http.server.NodeControllerDetailsHelper.fixupKeys;
import static org.apache.asterix.api.http.server.ServletConstants.HYRACKS_CONNECTION_ATTR;
import java.io.IOException;
@@ -135,7 +136,7 @@
return result;
}
- protected void resolveFutures(Map<String, Future<JsonNode>> futureMap, Map<String, JsonNode> outputMap,
+ public static void resolveFutures(Map<String, Future<JsonNode>> futureMap, Map<String, JsonNode> outputMap,
Map<String, JsonNode> errorMap) throws InterruptedException {
for (Map.Entry<String, Future<JsonNode>> entry : futureMap.entrySet()) {
try {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
index 8cb8cb6..09a07a1 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java
@@ -18,13 +18,12 @@
*/
package org.apache.asterix.api.http.server;
+import static org.apache.asterix.api.http.server.NodeControllerDetailsHelper.fixupKeys;
+import static org.apache.asterix.api.http.server.NodeControllerDetailsHelper.processNodeDetailsJSON;
import static org.apache.asterix.api.http.server.ServletConstants.HYRACKS_CONNECTION_ATTR;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import java.util.concurrent.ConcurrentMap;
import org.apache.asterix.common.cluster.ClusterPartition;
@@ -38,7 +37,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.netty.handler.codec.http.HttpResponseStatus;
@@ -124,68 +122,9 @@
}
}
- protected ObjectNode fixupKeys(ObjectNode json) {
- // TODO (mblow): generate the keys with _ to begin with
- List<String> keys = new ArrayList<>();
- for (Iterator<String> iter = json.fieldNames(); iter.hasNext();) {
- keys.add(iter.next());
- }
- for (String key : keys) {
- String newKey = key.replace('-', '_');
- if (!newKey.equals(key)) {
- json.set(newKey, json.remove(key));
- }
- }
- return json;
- }
-
protected ObjectNode processNodeStats(IHyracksClientConnection hcc, String node) throws Exception {
final String details = checkNullDetail(node, hcc.getNodeDetailsJSON(node, true, false));
- return processNodeDetailsJSON((ObjectNode) OBJECT_MAPPER.readTree(details));
- }
-
- protected ObjectNode processNodeDetailsJSON(ObjectNode json) {
- int index = json.get("rrd-ptr").asInt() - 1;
- json.remove("rrd-ptr");
-
- List<String> keys = new ArrayList<>();
- for (Iterator<String> iter = json.fieldNames(); iter.hasNext();) {
- keys.add(iter.next());
- }
- 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 {
- final JsonNode keyNode = json.get(key);
- if (keyNode instanceof ArrayNode) {
- final ArrayNode valueArray = (ArrayNode) keyNode;
- // fixup an index of -1 to the final element in the array (i.e. RRD_SIZE)
- if (index == -1) {
- index = valueArray.size() - 1;
- }
- final JsonNode value = valueArray.get(index);
- json.remove(key);
- json.set(key.replaceAll("s$", ""), value);
- }
- }
- }
- ArrayNode gcs = OBJECT_MAPPER.createArrayNode();
-
- for (int i = 0; i < gcNames.size(); i++) {
- ObjectNode gc = OBJECT_MAPPER.createObjectNode();
- gc.set("name", gcNames.get(i));
- gc.set("collection-time", gcCollectionTimes.get(i).get(index));
- gc.set("collection-count", gcCollectionCounts.get(i).get(index));
- fixupKeys(gc);
- gcs.add(gc);
- }
- json.set("gcs", gcs);
-
- return json;
+ return processNodeDetailsJSON((ObjectNode) OBJECT_MAPPER.readTree(details), OBJECT_MAPPER);
}
private ObjectNode processNodeConfig(IHyracksClientConnection hcc, String node) throws Exception {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsHelper.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsHelper.java
new file mode 100644
index 0000000..83aa496
--- /dev/null
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsHelper.java
@@ -0,0 +1,92 @@
+/*
+ * 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.api.http.server;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class NodeControllerDetailsHelper {
+ private NodeControllerDetailsHelper() {
+ }
+
+ public static ObjectNode fixupKeys(ObjectNode json) {
+ // TODO (mblow): generate the keys with _ to begin with
+ List<String> keys = new ArrayList<>();
+ for (Iterator<String> iter = json.fieldNames(); iter.hasNext();) {
+ keys.add(iter.next());
+ }
+ for (String key : keys) {
+ String newKey = key.replace('-', '_');
+ if (!newKey.equals(key)) {
+ json.set(newKey, json.remove(key));
+ }
+ }
+ return json;
+ }
+
+ public static ObjectNode processNodeDetailsJSON(ObjectNode json, ObjectMapper om) {
+ int index = json.get("rrd-ptr").asInt() - 1;
+ json.remove("rrd-ptr");
+
+ List<String> keys = new ArrayList<>();
+ for (Iterator<String> iter = json.fieldNames(); iter.hasNext();) {
+ keys.add(iter.next());
+ }
+ 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 {
+ final JsonNode keyNode = json.get(key);
+ if (keyNode instanceof ArrayNode) {
+ final ArrayNode valueArray = (ArrayNode) keyNode;
+ // fixup an index of -1 to the final element in the array (i.e. RRD_SIZE)
+ if (index == -1) {
+ index = valueArray.size() - 1;
+ }
+ final JsonNode value = valueArray.get(index);
+ json.remove(key);
+ json.set(key.replaceAll("s$", ""), value);
+ }
+ }
+ }
+ ArrayNode gcs = om.createArrayNode();
+
+ for (int i = 0; i < gcNames.size(); i++) {
+ ObjectNode gc = om.createObjectNode();
+ gc.set("name", gcNames.get(i));
+ gc.set("collection-time", gcCollectionTimes.get(i).get(index));
+ gc.set("collection-count", gcCollectionCounts.get(i).get(index));
+ fixupKeys(gc);
+ gcs.add(gc);
+ }
+ json.set("gcs", gcs);
+
+ return json;
+ }
+}