@Override public List<MetricType.Blueprint> getMetricTypes() { try (Stream<MetricType.Blueprint> s = structure.getChildren(RelativePath.empty().get(), MetricType.class)) { return s.collect(toList()); } }
@Override public List<ResourceType.Blueprint> getResourceTypes() { try (Stream<ResourceType.Blueprint> s = structure.getChildren(RelativePath.empty().get(), ResourceType.class)) { return s.collect(toList()); } }
@Override public Path deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { String val = jp.getValueAsString(); if (val.isEmpty()) { return RelativePath.empty().get(); } return Path.fromString(jp.getValueAsString()); } }
@Override public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { AbstractHashTree.TopBuilder<?, ?, T, H> bld = topBuilderSupplier.get(); RelativePath.Extender emptyPath = RelativePath.empty(); deserializeChild(p, bld, emptyPath, ctxt); return bld.build(); }
@Override public List<Metric.Blueprint> getFeedMetrics() { try (Stream<Metric.Blueprint> s = structure.getChildren(RelativePath.empty().get(), Metric.class)) { return s.collect(toList()); } }
@Override public List<Resource.Blueprint> getFeedResources() { try (Stream<Resource.Blueprint> s = structure.getChildren(RelativePath.empty().get(), Resource.class)) { return s.collect(toList()); } }
@Override public void serialize(InventoryStructure<?> inventoryStructure, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { Object blueprint = inventoryStructure.getRoot(); InventoryStructure.EntityType blueprintType = InventoryStructure.EntityType.ofBlueprint(blueprint.getClass()); if (blueprintType == null) { throw new IllegalArgumentException("Unsupported type of root element: " + blueprint); } jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("type", blueprintType.name()); jsonGenerator.writeObjectField("data", inventoryStructure.getRoot()); jsonGenerator.writeFieldName("children"); jsonGenerator.writeStartObject(); serializeLevel(inventoryStructure, RelativePath.empty(), jsonGenerator); jsonGenerator.writeEndObject(); jsonGenerator.writeEndObject(); }
@Override default boolean exists() { try { flatData(RelativePath.empty().get()); return true; } catch (EntityNotFoundException | RelationNotFoundException ignored) { return false; } }
@Override default boolean anyExists() { return flatData(RelativePath.empty().get(), Pager.single()).hasNext(); } }
@Override public List<OperationType.Blueprint> getOperationTypes(ResourceType.Blueprint rt) { RelativePath p = rt.equals(structure.getRoot()) ? RelativePath.empty().get() : RelativePath.to().resourceType(rt.getId()).get(); try (Stream<OperationType.Blueprint> s = structure.getChildren(p, OperationType.class)) { return s.collect(toList()); } }
private Map.Entry<InventoryStructure<B>, SyncHash.Tree> treeHashAndStructure(Transaction<BE> tx) { BE root = tx.querySingle(context.select().get()); E entity = tx.convert(root, context.entityClass); SyncHash.Tree.Builder bld = SyncHash.Tree.builder(); InventoryStructure.Builder<B> structBld = InventoryStructure.of(Inventory.asBlueprint(entity)); bld.withPath(RelativePath.empty().get()).withHash(entity.getSyncHash()); //the closure is returned in a breadth-first manner Iterator<BE> closure = tx.getTransitiveClosureOver(root, outgoing, contains.name()); if (closure.hasNext()) { Function<BE, Entity<? extends Entity.Blueprint, ?>> convert = e -> (Entity<Entity.Blueprint, ?>) tx.convert(e, tx.extractType(e)); Stream<BE> st = StreamSupport.stream(Spliterators.spliteratorUnknownSize(closure, 0), false); Iterator<Entity<? extends Entity.Blueprint, ?>> entities = st.map(convert).iterator(); buildChildTree(tx, entity.getPath(), singletonList(bld), singletonList(structBld), new ArrayList<>(), new ArrayList<>(), entities.next(), entities); } return new SimpleImmutableEntry<>(structBld.build(), bld.build()); }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
private InventoryStructure<B> mergeTree(InventoryStructure<B> currentTree, InventoryStructure<B> newTree, SyncConfiguration configuration) { if (configuration.isDeepSearch()) { return mergeDeepTree(currentTree, RelativePath.empty().get(), InventoryStructure.Offline.copy(newTree).asBuilder(), configuration.getSyncedTypes()).build(); } else { return mergeShallowTree(currentTree, RelativePath.empty().get(), InventoryStructure.Offline.copy(newTree).asBuilder(), configuration.getSyncedTypes()).build(); } }
RelativePath.empty().get()));
syncTrees(tx, rootPath, RelativePath.empty().get(), root, newTree, newStructure, currentStructure); DBG.debugf("Done syncing the merged tree and the database state of root %s", rootPath);