Refine search
private static List<JmesPathExpression> getChildren(JsonNode jsonNode){ if(jsonNode.get("children").size() < 1) { throw new RuntimeException("Expected one or more arguments"); } Iterator<JsonNode> children = jsonNode.get("children").elements(); final List<JmesPathExpression> childrenList = new ArrayList<>(); while (children.hasNext()) { childrenList.add(fromAstJsonToAstJava(children.next())); } return childrenList; }
@Test public void reportSpan() throws Exception { reporter.report(mock(SpanContextInformation.class), getSpan(100)); elasticsearchClient.waitForCompletion(); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("type").asText()).as(spanJson.toString()).isEqualTo("jdbc"); assertThat(spanJson.get("method").asText()).as(spanJson.toString()).isEqualTo("SELECT"); assertThat(spanJson.get("db.statement")).as(spanJson.toString()).isNotNull(); assertThat(spanJson.get("db.statement").asText()).as(spanJson.toString()).isEqualTo("SELECT * from STAGEMONITOR where 1 < 2"); assertThat(spanJson.get("duration_ms").asInt()).as(spanJson.toString()).isEqualTo(100); assertThat(spanJson.get("name").asText()).as(spanJson.toString()).isEqualTo("ElasticsearchExternalSpanReporterIntegrationTest#test"); }
@Override public Set<IPersonAttributesGroupDefinition> deserialize( JsonParser jsonParser, DeserializationContext ctx) throws JsonProcessingException, IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // For now, we'll only support deserializing PAGS definitions WITHOUT members... if (node.elements().hasNext()) { throw new UnsupportedOperationException("Members not yet supported"); } return Collections.emptySet(); } }
/** * Deserialize an AccessControlList object. * @param jsonParser the json parser * @param deserializationContext deserializationcontext * @return * @throws IOException * @throws JsonProcessingException */ @Override public AccessControlList deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); String owner = node.get(OWNER_FIELD).asText(); String owningGroup = node.get(OWNING_GROUP_FIELD).asText(); List<String> stringEntries = new ArrayList<>(); Iterator<JsonNode> nodeIterator = node.get(STRING_ENTRY_FIELD).elements(); while (nodeIterator.hasNext()) { stringEntries.add(nodeIterator.next().asText()); } return AccessControlList.fromStringEntries(owner, owningGroup, stringEntries); } }
@Test public void testUpdateSpan() throws Exception { final Span span = tracer.buildSpan("Test#test") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .start(); span.finish(); elasticsearchClient.waitForCompletion(); refresh(); reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar")); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar"); }
@Override public Set<IPersonAttributesGroupDefinition> deserialize( JsonParser jsonParser, DeserializationContext ctx) throws JsonProcessingException, IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // For now, we'll only support deserializing PAGS definitions WITHOUT members... if (node.elements().hasNext()) { throw new UnsupportedOperationException("Members not yet supported"); } return Collections.emptySet(); } }
public List<String> getCurrentObject() throws NoSuchElementException { JsonNode resourceJsonNode = _inputRecordsJsonNode.get( _inputRecordsIndex); if (resourceJsonNode == null) { _log.error("Index: {}", _inputRecordsIndex); throw new NoSuchElementException("Index: " + _inputRecordsIndex); } List<String> resourceValues = new ArrayList<>(); Iterator<JsonNode> iterator = resourceJsonNode.elements(); while (iterator.hasNext()) { JsonNode jsonNode = iterator.next(); resourceValues.add(jsonNode.toString()); } if (_log.isDebugEnabled()) { _log.debug("Resource has been processed"); } return resourceValues; }
@Test public void testUpdateNotYetExistentSpan_eventuallyUpdates() throws Exception { final Span span = tracer.buildSpan("Test#test") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .start(); reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar")); span.finish(); elasticsearchClient.waitForCompletion(); refresh(); reporter.getUpdateReporter().flush(); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar"); }
/** * If subject is an array, this function returns true if * one of the elements in the array is equal to the provided search * value. * * @param subject Array * @param search JmesPath expression * @return True array contains search; * False otherwise */ private static BooleanNode doesArrayContain(JsonNode subject, JsonNode search) { Iterator<JsonNode> elements = subject.elements(); while (elements.hasNext()) { if (elements.next().equals(search)) { return BooleanNode.TRUE; } } return BooleanNode.FALSE; }
@Test public void reportSpan() throws Exception { final Map<String, String> parameters = new HashMap<>(); parameters.put("attr.Color", "Blue"); parameters.put("attr", "bla"); parameters.put("foo", "bar"); final Span span = tracer.buildSpan("Test#test") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .start(); SpanUtils.setParameters(span, parameters); span.setTag(SpanUtils.OPERATION_TYPE, "method_invocation"); span.setTag("foo.bar", "baz"); span.finish(); elasticsearchClient.waitForCompletion(); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); validateSpanJson(hits.get("hits").elements().next().get("_source")); }
@Override public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Bind> binds = new ArrayList<Bind>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<JsonNode> it = node.elements(); it.hasNext();) { JsonNode field = it.next(); binds.add(Bind.parse(field.asText())); } return new Binds(binds.toArray(new Bind[0])); } }
@Override public DynamicPojoRecordReader convert(JsonNode value) { LinkedHashMap<String, Class<?>> schema = mapper.convertValue(value.get("schema"), schemaType); ArrayList records = new ArrayList(schema.size()); final Iterator<JsonNode> recordsIterator = value.get("records").get(0).elements(); for (Class<?> fieldType : schema.values()) { records.add(mapper.convertValue(recordsIterator.next(), fieldType)); } int maxRecordsToRead = value.get("recordsPerBatch").asInt(); return new DynamicPojoRecordReader(schema, Collections.singletonList(records), maxRecordsToRead); } }
@Override public RangeBoundValue deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); if (node.isNull()) { return null; } else { List<Object> list; if (node.isArray()) { list = new ArrayList<>(); Iterator<JsonNode> iter = node.elements(); while (iter.hasNext()) { Object v = toValue(iter.next()); list.add(v); } } else { Object v = toValue(node); list = ImmutableList.of(v); } return new RangeBoundValue(list); } }
public static boolean hasValueOf(String value, JsonNode jsonNode) { if (jsonNode.isArray()) { Iterator<JsonNode> iterator = jsonNode.elements(); while (iterator.hasNext()) { JsonNode entryJsonNode = iterator.next(); String entry = entryJsonNode.asText(); if (entry.equals(value)) { return true; } } } else if (jsonNode.isValueNode()) { String entry = jsonNode.asText(); if (entry.equals(value)) { return true; } } return false; }
private Map<String, JFieldVar> removeFieldsExcludedFromEqualsAndHashCode(Map<String, JFieldVar> fields, JsonNode node) { Map<String, JFieldVar> filteredFields = new HashMap<>(fields); JsonNode properties = node.get("properties"); if (properties != null) { if (node.has("excludedFromEqualsAndHashCode")) { JsonNode excludedArray = node.get("excludedFromEqualsAndHashCode"); for (Iterator<JsonNode> iterator = excludedArray.elements(); iterator.hasNext(); ) { String excludedPropertyName = iterator.next().asText(); JsonNode excludedPropertyNode = properties.get(excludedPropertyName); filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(excludedPropertyName, excludedPropertyNode)); } } for (Iterator<Map.Entry<String, JsonNode>> iterator = properties.fields(); iterator.hasNext(); ) { Map.Entry<String, JsonNode> entry = iterator.next(); String propertyName = entry.getKey(); JsonNode propertyNode = entry.getValue(); if (propertyNode.has("excludedFromEqualsAndHashCode") && propertyNode.get("excludedFromEqualsAndHashCode").asBoolean()) { filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(propertyName, propertyNode)); } } } return filteredFields; }
Entry<String, JsonNode> principal; Iterator<JsonNode> elements; while (mapOfPrincipals.hasNext()) { principal = mapOfPrincipals.next(); schema = principal.getKey(); principalNode = principal.getValue(); elements = principalNode.elements(); while (elements.hasNext()) { principals.add(createPrincipal(schema, elements.next()));
@Override public Links deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final List<Link> binds = new ArrayList<Link>(); final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) { final JsonNode element = it.next(); if (!element.equals(NullNode.getInstance())) { binds.add(Link.parse(element.asText())); } } return new Links(binds.toArray(new Link[0])); } }
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) { if (!(source instanceof JsonNode)) { resultMap.put(propertyPrefix, source); return; } JsonNode element = (JsonNode) source; if (element.isArray()) { Iterator<JsonNode> nodes = element.elements(); while (nodes.hasNext()) { JsonNode cur = nodes.next(); if (cur.isArray()) { this.falttenCollection(propertyPrefix, cur.elements(), resultMap); } } } else if (element.isContainerNode()) { this.doFlatten(propertyPrefix, element.fields(), resultMap); } else { resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value")); } }