Search in sources :

Example 6 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project zeppelin by apache.

the class SparkRInterpreter method interpret.

@Override
public InterpreterResult interpret(String lines, InterpreterContext interpreterContext) {
    SparkInterpreter sparkInterpreter = getSparkInterpreter();
    sparkInterpreter.populateSparkWebUrl(interpreterContext);
    String jobGroup = Utils.buildJobGroupId(interpreterContext);
    sparkInterpreter.getSparkContext().setJobGroup(jobGroup, "Zeppelin", false);
    String imageWidth = getProperty("zeppelin.R.image.width");
    String[] sl = lines.split("\n");
    if (sl[0].contains("{") && sl[0].contains("}")) {
        String jsonConfig = sl[0].substring(sl[0].indexOf("{"), sl[0].indexOf("}") + 1);
        ObjectMapper m = new ObjectMapper();
        try {
            JsonNode rootNode = m.readTree(jsonConfig);
            JsonNode imageWidthNode = rootNode.path("imageWidth");
            if (!imageWidthNode.isMissingNode())
                imageWidth = imageWidthNode.textValue();
        } catch (Exception e) {
            logger.warn("Can not parse json config: " + jsonConfig, e);
        } finally {
            lines = lines.replace(jsonConfig, "");
        }
    }
    String setJobGroup = "";
    // assign setJobGroup to dummy__, otherwise it would print NULL for this statement
    if (Utils.isSpark2()) {
        setJobGroup = "dummy__ <- setJobGroup(\"" + jobGroup + "\", \"zeppelin sparkR job group description\", TRUE)";
    } else if (getSparkInterpreter().getSparkVersion().newerThanEquals(SparkVersion.SPARK_1_5_0)) {
        setJobGroup = "dummy__ <- setJobGroup(sc, \"" + jobGroup + "\", \"zeppelin sparkR job group description\", TRUE)";
    }
    logger.debug("set JobGroup:" + setJobGroup);
    lines = setJobGroup + "\n" + lines;
    try {
        // render output with knitr
        if (useKnitr()) {
            zeppelinR.setInterpreterOutput(null);
            zeppelinR.set(".zcmd", "\n```{r " + renderOptions + "}\n" + lines + "\n```");
            zeppelinR.eval(".zres <- knit2html(text=.zcmd)");
            String html = zeppelinR.getS0(".zres");
            RDisplay rDisplay = render(html, imageWidth);
            return new InterpreterResult(rDisplay.code(), rDisplay.type(), rDisplay.content());
        } else {
            // alternatively, stream the output (without knitr)
            zeppelinR.setInterpreterOutput(interpreterContext.out);
            zeppelinR.eval(lines);
            return new InterpreterResult(InterpreterResult.Code.SUCCESS, "");
        }
    } catch (Exception e) {
        logger.error("Exception while connecting to R", e);
        return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage());
    } finally {
        try {
        } catch (Exception e) {
        // Do nothing...
        }
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 7 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project hive by apache.

the class TestCodahaleMetrics method testFileReporting.

@Test
public void testFileReporting() throws Exception {
    int runs = 5;
    for (int i = 0; i < runs; i++) {
        MetricsFactory.getInstance().incrementCounter("count2");
    }
    byte[] jsonData = MetricsTestUtils.getFileData(jsonReportFile.getAbsolutePath(), 2000, 3);
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode rootNode = objectMapper.readTree(jsonData);
    JsonNode countersNode = rootNode.path("counters");
    JsonNode methodCounterNode = countersNode.path("count2");
    JsonNode countNode = methodCounterNode.path("count");
    Assert.assertEquals(countNode.asInt(), 5);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project pinot by linkedin.

the class AutoLoadPinotMetricsService method loadDatasets.

/**
   * Reads all table names in pinot, and loads their schema
   * @throws IOException
   */
private void loadDatasets() throws IOException {
    JsonNode tables = autoLoadPinotMetricsUtils.getAllTablesFromPinot();
    for (JsonNode table : tables) {
        String dataset = table.asText();
        Schema schema = autoLoadPinotMetricsUtils.getSchemaFromPinot(dataset);
        if (schema != null) {
            if (!autoLoadPinotMetricsUtils.verifySchemaCorrectness(schema)) {
                LOG.info("Skipping {} due to incorrect schema", dataset);
            } else {
                allDatasets.add(dataset);
                allSchemas.put(dataset, schema);
            }
        }
    }
}
Also used : Schema(com.linkedin.pinot.common.data.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project pinot by linkedin.

the class AutoLoadPinotMetricsUtils method getAllTablesFromPinot.

public JsonNode getAllTablesFromPinot() throws IOException {
    HttpGet tablesReq = new HttpGet(PINOT_TABLES_ENDPOINT);
    LOG.info("Retrieving datasets: {}", tablesReq);
    CloseableHttpResponse tablesRes = pinotControllerClient.execute(pinotControllerHost, tablesReq);
    JsonNode tables = null;
    try {
        if (tablesRes.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(tablesRes.getStatusLine().toString());
        }
        InputStream tablesContent = tablesRes.getEntity().getContent();
        tables = new ObjectMapper().readTree(tablesContent).get("tables");
    } catch (Exception e) {
        LOG.error("Exception in loading collections", e);
    } finally {
        if (tablesRes.getEntity() != null) {
            EntityUtils.consume(tablesRes.getEntity());
        }
        tablesRes.close();
    }
    return tables;
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 10 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jmxtrans by jmxtrans.

the class JsonUtils method parseProcess.

/**
	 * Uses jackson to load json configuration from a File into a full object
	 * tree representation of that json.
	 */
public JmxProcess parseProcess(File file) throws IOException {
    JsonNode jsonNode = mapper.readTree(file);
    JmxProcess jmx = mapper.treeToValue(jsonNode, JmxProcess.class);
    jmx.setName(file.getName());
    return jmx;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4105 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)277 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70