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.\"}");
}
}
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");
}
}
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;
}
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;
}
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());
}
}
Aggregations