static Hashes of(InventoryStructure<?> inventory, CanonicalPath rootPath, boolean computeIdentity, boolean computeContent, boolean computeSync) { ComputeHash.HashConstructor ctor = new ComputeHash.HashConstructor(new ComputeHash.DigestComputingWriter( ComputeHash.newDigest())); IntermediateHashResult res = ComputeHash.computeHash(rootPath, inventory.getRoot(), ComputeHash.HashableView.of(inventory), ctor, computeIdentity, computeContent, computeSync, rp -> null, rp -> null); return new Hashes(res.identityHash, res.contentHash, res.syncHash); }
@Override public Updater<Update, Metric> update() { return new Updater<>((u) -> new Metric(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), getType(), u.getCollectionInterval(), u.getProperties())); }
@Override public Updater<Update, Resource> update() { return new Updater<>((u) -> new Resource(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), getType(), u.getProperties())); }
@Override public Updater<Update, MetricType> update() { return new Updater<>((u) -> new MetricType(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), valueOrDefault(u.unit, this.unit), metricDataType, u.getProperties(), valueOrDefault(u.getCollectionInterval(), collectionInterval))); }
@Override public Updater<Update, Feed> update() { return new Updater<>((u) -> new Feed(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), u.getProperties())); }
@Override public Updater<Update, OperationType> update() { return new Updater<>((u) -> new OperationType(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), u.getProperties())); }
@Override public Updater<Update, ResourceType> update() { return new Updater<>((u) -> new ResourceType(u.getName(), getPath(), getIdentityHash(), getContentHash(), getSyncHash(), u.getProperties())); }
/** * The entity path is currently only required for resources, which base their content hash on the resource type * path which can be specified using a relative or canonical path in the blueprint. For the content hash to be * consistent we need to convert to just a single representation of the path. * * @param entity the entity to produce the hash of * @param entityPath the canonical path of the entity (can be null for all but resources) * @return the content hash of the entity */ public static String of(Entity.Blueprint entity, CanonicalPath entityPath) { return ComputeHash.of(InventoryStructure.of(entity).build(), entityPath, false, true, false).getContentHash(); } }
@Override public Updater<Update, Tenant> update() { return new Updater<>((u) -> new Tenant(u.getName(), getPath(), getContentHash(), u.getProperties())); }
@Override public Updater<Update, Environment> update() { return new Updater<>((u) -> new Environment(u.getName(), getPath(), getContentHash(), u.getProperties())); }
/** * You can use this method if you have an existing inventory structure and want to make modifications to it. * * @return a builder seeded with this inventory structure */ public InventoryStructure.Builder<Root> asBuilder() { RelativePath rootPath = EmptyRelativePath.I; Object attachment = getNode(rootPath).getAttachment(); return new InventoryStructure.Builder<>(root, attachment, EmptyRelativePath.I, entities, children); }
@Override public T visitRelationship(Relationship relationship, Void parameter) { return entityType.cast(relationship.update().with(Relationship.Update.builder() .withProperties(filteredProperties).build())); }
@Override public Updater<Update, MetadataPack> update() { return new Updater<>((u) -> new MetadataPack(getPath(), u.getProperties())); }
/** * By providing an empty relative path, one can retrieve the attachment of the root entity. * @param path the path to the entity in the inventory structure * @return the object attached to the entity by the inventory structure builder or null if the path is not known */ default FullNode getNode(RelativePath path) { Entity.Blueprint bl = get(path); return bl == null ? null : new FullNode(bl, null); }
public static String of(InventoryStructure<?> inventory) { //identity hash is not dependent on the root path - I.e. no relative paths in the inventory structure are used //to compute the identity hash... return ComputeHash.of(inventory, null, true, false, false).getIdentityHash(); }
/** * The root path is required so that paths in the blueprints can be correctly relativized. * * @param structure the structure to compute the root hash of. * @param rootPath the canonical path of the root of the inventory structure * @return the sync hash of the root of the structure */ public static String of(InventoryStructure<?> structure, CanonicalPath rootPath) { return ComputeHash.of(structure, rootPath, true, true, true).getSyncHash(); }
/** * You can use this method if you have an existing inventory structure and want to make modifications to it. * * @return a builder seeded with this inventory structure */ public InventoryStructure.Builder<Root> asBuilder() { RelativePath rootPath = EmptyRelativePath.I; Object attachment = getNode(rootPath).getAttachment(); return new InventoryStructure.Builder<>(root, attachment, EmptyRelativePath.I, entities, children); }
/** * By providing an empty relative path, one can retrieve the attachment of the root entity. * @param path the path to the entity in the inventory structure * @return the object attached to the entity by the inventory structure builder or null if the path is not known */ default FullNode getNode(RelativePath path) { Entity.Blueprint bl = get(path); return bl == null ? null : new FullNode(bl, null); }