Search in sources :

Example 21 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project graylog2-server by Graylog2.

the class JestUtilsTest method executeFailsWithCustomMessage.

@Test
public void executeFailsWithCustomMessage() throws Exception {
    final Ping request = new Ping.Builder().build();
    final JestResult resultMock = mock(JestResult.class);
    when(resultMock.isSucceeded()).thenReturn(false);
    final ObjectNode responseStub = objectMapper.createObjectNode();
    final ObjectNode errorStub = objectMapper.createObjectNode();
    responseStub.set("Message", new TextNode("Authorization header requires 'Credential' parameter."));
    errorStub.set("error", responseStub);
    when(resultMock.getJsonObject()).thenReturn(errorStub);
    when(clientMock.execute(request)).thenReturn(resultMock);
    try {
        JestUtils.execute(clientMock, request, () -> "BOOM");
        fail("Expected ElasticsearchException to be thrown");
    } catch (ElasticsearchException e) {
        assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}").hasNoSuppressedExceptions();
        assertThat(e.getErrorDetails()).containsExactly("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}");
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Ping(io.searchbox.core.Ping) TextNode(com.fasterxml.jackson.databind.node.TextNode) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) JestResult(io.searchbox.client.JestResult) Test(org.junit.Test)

Example 22 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.

the class RoaringBitmapJsonDeserialiser method deserialize.

@Override
public RoaringBitmap deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
    final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
    final TreeNode bitmapObject = treeNode.get(RoaringBitmapConstants.BITMAP_WRAPPER_OBJECT_NAME);
    if (null != bitmapObject) {
        final TextNode jsonNodes = (TextNode) bitmapObject.get(RoaringBitmapConstants.BITMAP_VALUE_FIELD_NAME);
        return (RoaringBitmap) bitmapSerialiser.deserialise(jsonNodes.binaryValue());
    } else {
        throw new IllegalArgumentException("Received null bitmap treenode");
    }
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 23 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.

the class HllSketchJsonDeserialiser method deserialize.

@Override
public HllSketch deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
    final HllSketch hllp;
    final TextNode jsonNodes = (TextNode) treeNode.get(HllSketchJsonConstants.BYTES);
    if (isNull(jsonNodes)) {
        final IntNode kNode = (IntNode) treeNode.get(HllSketchJsonConstants.LOG_K);
        final int k = nonNull(kNode) ? kNode.asInt(DEFAULT_LOG_K) : DEFAULT_LOG_K;
        hllp = new HllSketch(k);
    } else {
        hllp = HllSketch.heapify(jsonNodes.binaryValue());
    }
    final ArrayNode offers = (ArrayNode) treeNode.get(VALUES);
    if (nonNull(offers)) {
        for (final JsonNode offer : offers) {
            if (nonNull(offer)) {
                hllp.update(offer.asText());
            }
        }
    }
    return hllp;
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) IntNode(com.fasterxml.jackson.databind.node.IntNode) TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 24 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.

the class HyperLogLogPlusJsonDeserialiser method deserialize.

@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
    final TreeNode nestedHllp = treeNode.get("hyperLogLogPlus");
    if (nonNull(nestedHllp)) {
        treeNode = nestedHllp;
    }
    final HyperLogLogPlus hllp;
    final TextNode jsonNodes = (TextNode) treeNode.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
    if (isNull(jsonNodes)) {
        final IntNode pNode = (IntNode) treeNode.get("p");
        final IntNode spNode = (IntNode) treeNode.get("sp");
        final int p = nonNull(pNode) ? pNode.asInt(DEFAULT_P) : DEFAULT_P;
        final int sp = nonNull(spNode) ? spNode.asInt(DEFAULT_SP) : DEFAULT_SP;
        hllp = new HyperLogLogPlus(p, sp);
    } else {
        hllp = HyperLogLogPlus.Builder.build(jsonNodes.binaryValue());
    }
    final ArrayNode offers = (ArrayNode) treeNode.get("offers");
    if (nonNull(offers)) {
        for (final JsonNode offer : offers) {
            if (nonNull(offer)) {
                hllp.offer(offer.asText());
            }
        }
    }
    return hllp;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 25 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project flink by apache.

the class JsonGeneratorTest method testGeneratorWithoutAnyAttachements.

@Test
public void testGeneratorWithoutAnyAttachements() {
    try {
        JobVertex source1 = new JobVertex("source 1");
        JobVertex source2 = new JobVertex("source 2");
        source2.setInvokableClass(DummyInvokable.class);
        JobVertex source3 = new JobVertex("source 3");
        JobVertex intermediate1 = new JobVertex("intermediate 1");
        JobVertex intermediate2 = new JobVertex("intermediate 2");
        JobVertex join1 = new JobVertex("join 1");
        JobVertex join2 = new JobVertex("join 2");
        JobVertex sink1 = new JobVertex("sink 1");
        JobVertex sink2 = new JobVertex("sink 2");
        intermediate1.connectNewDataSetAsInput(source1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        intermediate2.connectNewDataSetAsInput(source2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
        join1.connectNewDataSetAsInput(intermediate1, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
        join1.connectNewDataSetAsInput(intermediate2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
        join2.connectNewDataSetAsInput(join1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        join2.connectNewDataSetAsInput(source3, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
        sink1.connectNewDataSetAsInput(join2, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        sink2.connectNewDataSetAsInput(join1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
        JobGraph jg = JobGraphTestUtils.batchJobGraph(source1, source2, source3, intermediate1, intermediate2, join1, join2, sink1, sink2);
        String plan = JsonPlanGenerator.generatePlan(jg);
        assertNotNull(plan);
        // validate the produced JSON
        ObjectMapper m = new ObjectMapper();
        JsonNode rootNode = m.readTree(plan);
        // core fields
        assertEquals(new TextNode(jg.getJobID().toString()), rootNode.get("jid"));
        assertEquals(new TextNode(jg.getName()), rootNode.get("name"));
        assertEquals(new TextNode(jg.getJobType().name()), rootNode.get("type"));
        assertTrue(rootNode.path("nodes").isArray());
        for (Iterator<JsonNode> iter = rootNode.path("nodes").elements(); iter.hasNext(); ) {
            JsonNode next = iter.next();
            JsonNode idNode = next.get("id");
            assertNotNull(idNode);
            assertTrue(idNode.isTextual());
            checkVertexExists(idNode.asText(), jg);
            String description = next.get("description").asText();
            assertTrue(description.startsWith("source") || description.startsWith("sink") || description.startsWith("intermediate") || description.startsWith("join"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) TextNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)96 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)35 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 IntNode (com.fasterxml.jackson.databind.node.IntNode)14 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 ArrayList (java.util.ArrayList)9 Scheduler (org.apache.kafka.common.utils.Scheduler)9 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)9 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)9 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)9 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)8