use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project asterixdb by apache.
the class ClusterApiServlet method get.
@Override
protected void get(IServletRequest request, IServletResponse response) throws IOException {
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
PrintWriter responseWriter = response.writer();
try {
ObjectNode json;
response.setStatus(HttpResponseStatus.OK);
switch(localPath(request)) {
case "":
json = getClusterStateJSON(request, "");
break;
case "/summary":
json = getClusterStateSummaryJSON();
break;
default:
throw new IllegalArgumentException();
}
responseWriter.write(JSONUtil.convertNode(json));
} catch (IllegalArgumentException e) {
// NOSONAR - exception not logged or rethrown
response.setStatus(HttpResponseStatus.NOT_FOUND);
} catch (Exception e) {
LOGGER.log(Level.INFO, "exception thrown for " + request, e);
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
responseWriter.write(e.toString());
}
responseWriter.flush();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project asterixdb by apache.
the class ClusterControllerDetailsApiServlet method get.
@Override
protected void get(IServletRequest request, IServletResponse response) throws IOException {
PrintWriter responseWriter = response.writer();
IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
try {
ObjectNode json;
response.setStatus(HttpResponseStatus.OK);
if ("".equals(localPath(request))) {
json = (ObjectNode) getClusterStateJSON(request, "../").get("cc");
} else {
json = processNode(request, hcc);
}
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
responseWriter.write(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json));
} catch (IllegalArgumentException e) {
// NOSONAR - exception not logged or rethrown
response.setStatus(HttpResponseStatus.NOT_FOUND);
} catch (Exception e) {
LOGGER.log(Level.INFO, "exception thrown for " + request, e);
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
responseWriter.write(e.toString());
}
responseWriter.flush();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project asterixdb by apache.
the class QueryWebInterfaceServlet method post.
@Override
protected void post(IServletRequest request, IServletResponse response) throws IOException {
HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
ExternalProperties externalProperties = appCtx.getExternalProperties();
response.setStatus(HttpResponseStatus.OK);
ObjectMapper om = new ObjectMapper();
ObjectNode obj = om.createObjectNode();
try {
PrintWriter out = response.writer();
obj.put("api_port", String.valueOf(externalProperties.getAPIServerPort()));
out.println(obj.toString());
return;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failure writing response", e);
}
try {
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failure setting response status", e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project asterixdb by apache.
the class DiagnosticsApiServlet method getClusterDiagnosticsJSON.
private ObjectNode getClusterDiagnosticsJSON() throws Exception {
ObjectMapper om = new ObjectMapper();
IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
ExecutorService executor = (ExecutorService) ctx.get(ServletConstants.EXECUTOR_SERVICE_ATTR);
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<ObjectNode>>> ncDataMap = new HashMap<>();
for (String nc : appCtx.getMetadataProperties().getNodeNames()) {
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);
}
ObjectNode result = om.createObjectNode();
result.putPOJO("cc", resolveFutures(ccFutureData));
List<Map<String, ?>> ncList = new ArrayList<>();
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.putPOJO("ncs", ncList);
result.putPOJO("date", new Date());
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project asterixdb by apache.
the class NodeControllerDetailsApiServlet method processNodeStats.
protected ObjectNode processNodeStats(IHyracksClientConnection hcc, String node) throws Exception {
final String details = hcc.getNodeDetailsJSON(node, true, false);
if (details == null) {
throw new IllegalArgumentException();
}
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<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", ((ArrayNode) gcCollectionTimes.get(i)).get(index));
gc.set("collection-count", ((ArrayNode) gcCollectionCounts.get(i)).get(index));
gcs.add(gc);
}
json.set("gcs", gcs);
return json;
}
Aggregations