@Override public void updateHashes(Element entity, Hashes hashes) { setNonNullProperty(entity, Constants.Property.__contentHash.name(), hashes.getContentHash()); setNonNullProperty(entity, Constants.Property.__syncHash.name(), hashes.getSyncHash()); updateIdentityHash(entity, hashes.getIdentityHash()); }
private Tree(RelativePath path, Hashes hash, Map<Path.Segment, Tree> children) { super(path, hash == null ? new Hashes(null, null, null) : hash, children); }
public static Tree treeOf(InventoryStructure<?> root, CanonicalPath rootPath) { return treeOf(root, rootPath, rp -> 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(); }
/** * 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(); } }
return Hashes.of(e); };
private void addHashChangeNotifications(AbstractElement<?, ?> entity, Hashes newHashes, List<Notification<?, ?>> notifications) { DBG.debugf("Adding hash change notifications to entity %s", entity.getPath()); if (entity instanceof Syncable) { Syncable el = (Syncable) entity; if (!Objects.equals(el.getSyncHash(), newHashes.getSyncHash())) { notifications.add(new Notification<>(el, el, syncHashChanged())); } } if (entity instanceof ContentHashable) { ContentHashable el = (ContentHashable) entity; if (!Objects.equals(el.getContentHash(), newHashes.getContentHash())) { notifications.add(new Notification<>(el, el, contentHashChanged())); } } if (entity instanceof IdentityHashable) { IdentityHashable el = (IdentityHashable) entity; if (!Objects.equals(el.getIdentityHash(), newHashes.getIdentityHash())) { notifications.add(new Notification<>(el, el, identityHashChanged())); } } }
private Hashes hashesOf(AbstractElement<?, ?> el) { String contentHash = null; String identityHash = null; String syncHash = null; if (el instanceof ContentHashable) { contentHash = ((ContentHashable) el).getContentHash(); } if (el instanceof IdentityHashable) { identityHash = ((IdentityHashable) el).getIdentityHash(); } if (el instanceof Syncable) { syncHash = ((Syncable) el).getSyncHash(); } return contentHash == null && identityHash == null && syncHash == null ? null : new Hashes(identityHash, contentHash, syncHash); }
public static Hashes of(Entity<?, ?> entity) { String contentHash = null; String identityHash = null; String syncHash = null; if (entity instanceof ContentHashable) { contentHash = ((ContentHashable) entity).getContentHash(); } if (entity instanceof IdentityHashable) { identityHash = ((IdentityHashable) entity).getIdentityHash(); } if (entity instanceof Syncable) { syncHash = ((Syncable) entity).getSyncHash(); } return new Hashes(identityHash, contentHash, syncHash); }
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); }
public static Tree treeOf(InventoryStructure<?> root, CanonicalPath rootPath, Function<RelativePath, Hashes> hashLoader) { Tree.AbstractBuilder<?>[] tbld = new Tree.AbstractBuilder[1]; Consumer<IntermediateHashContext> startChild = context -> { if (tbld[0] == null) { tbld[0] = Tree.builder(); } else { tbld[0] = tbld[0].startChild(); } }; BiConsumer<IntermediateHashContext, IntermediateHashResult> endChild = (ctx, result) -> { if (tbld[0] instanceof Tree.ChildBuilder) { tbld[0].withHash(new Hashes(result)).withPath(result.path); @SuppressWarnings("unchecked") Tree.AbstractBuilder<?> parent = ((Tree.ChildBuilder<?>) tbld[0]).getParent(); parent.addChild(((Tree.ChildBuilder<?>) tbld[0]).build()); tbld[0] = parent; } }; IntermediateHashResult res = ComputeHash.treeOf(root, rootPath, true, true, true, startChild, endChild, hashLoader); tbld[0].withPath(res.path).withHash(new Hashes(res)); return ((Tree.Builder)tbld[0]).build(); }