/** * Get the SHA1 from the {@link BlobAttributes} */ protected String getBlobSha1(final BlobAttributes blobAttributes) { BlobMetrics metrics = blobAttributes.getMetrics(); checkArgument(metrics != null, "Blob attributes are missing metrics"); String blobSha1 = metrics.getSha1Hash(); checkArgument(blobSha1 != null, "Blob metrics are missing SHA1 hash code"); return blobSha1; }
/** * Get the name from the {@link BlobAttributes} */ protected String getBlobName(final BlobAttributes blobAttributes) { return blobAttributes.getProperties().getProperty(HEADER_PREFIX + BLOB_NAME_HEADER); }
private void checkIfOrphaned(final Consumer<String> handler, final BlobId id, final BlobAttributes attributes) { String repositoryName = attributes.getHeaders().get(REPOSITORY_NAME_KEY); if (repositoryName != null) { String assetName = attributes.getHeaders().get(ASSET_NAME_KEY); Repository repository = repositoryManager.get(repositoryName); if (repository == null) { log.debug("Blob {} considered orphaned because repository with name {} no longer exists", id.asUniqueString(), repositoryName); handler.accept(id.asUniqueString()); } else { findAssociatedAsset(assetName, repository).ifPresent(asset -> { BlobRef blobRef = asset.blobRef(); if (blobRef != null && !blobRef.getBlobId().asUniqueString().equals(id.asUniqueString())) { if (!attributes.isDeleted()) { handler.accept(id.asUniqueString()); } else { log.debug("Blob {} in repository {} not considered orphaned because it is already marked soft-deleted", id.asUniqueString(), repositoryName); } } }); } } }
if (context.isPresent()) { Context c = context.get(); if (restore && c.restoreBlobStrategy != null && !c.blobAttributes.isDeleted()) { c.restoreBlobStrategy.restore(c.properties, c.blob, c.blobStoreName, dryRun);
failed++; else if (blobAttributes.isDeleted()) { log.warn(BLOB_PROPERTIES_MARKED_AS_DELETED, asset.name()); failed++;
/** * Check the asset for integrity. By default checks name and SHA1. * * @param blobAttributes the {@link BlobAttributes} from the {@link Blob} * @param asset the {@link Asset} * @return true if asset integrity is intact, false otherwise */ protected boolean checkAsset(final BlobAttributes blobAttributes, final Asset asset) { checkArgument(blobAttributes.getProperties() != null, "Blob attributes are missing properties"); return checkSha1(blobAttributes, asset) && checkName(blobAttributes, asset); }
private Optional<Context> buildContext(final String blobStoreName, final BlobStore blobStore, final BlobId blobId) { return Optional.of(new Context(blobStoreName, blobStore, blobId)) .map(c -> c.blob(c.blobStore.get(c.blobId, true))) .map(c -> c.blobAttributes(c.blobStore.getBlobAttributes(c.blobId))) .map(c -> c.properties(c.blobAttributes.getProperties())) .map(c -> c.repositoryName(c.properties.getProperty(HEADER_PREFIX + REPO_NAME_HEADER))) .map(c -> c.repository(repositoryManager.get(c.repositoryName))) .map(c -> c.restoreBlobStrategy(restoreBlobStrategies.get(c.repository.getFormat().getValue()))); }