Search in sources :

Example 96 with ObjectNode

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 97 with ObjectNode

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();
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 98 with ObjectNode

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ExternalProperties(org.apache.asterix.common.config.ExternalProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 99 with ObjectNode

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;
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 100 with ObjectNode

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2446 JsonNode (com.fasterxml.jackson.databind.JsonNode)556 Test (org.junit.Test)556 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)509 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)370 IOException (java.io.IOException)214 ArrayList (java.util.ArrayList)119 HashMap (java.util.HashMap)107 Map (java.util.Map)106 List (java.util.List)96 StringEntity (org.apache.http.entity.StringEntity)94 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)81 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)57 AbstractRpcLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest)54 TextNode (com.fasterxml.jackson.databind.node.TextNode)52 File (java.io.File)51 Task (org.activiti.engine.task.Task)51