private void updateDocWithNewName(final String originalName, final String newName, final ODocument doc) { BlobRef blobRef = BlobRef.parse(doc.field("blob_ref", String.class)); if (blobRef.getStore().equals(originalName)) { doc.field("blob_ref", new BlobRef(blobRef.getNode(), newName, blobRef.getBlob())).save(); } }
private void deleteBlob(final Set<String> deletedBlobStores, final BlobRef blobRef) { String blobStoreName = blobRef.getStore(); if (deletedBlobStores.contains(blobStoreName)) { return; } BlobStore blobStore = blobStoreManager.get(blobRef.getStore()); if (blobStore == null) { if (deletedBlobStores.add(blobStoreName)) { log.info("Not deleting blobs for blob store {}, blob store not found", blobStoreName); } return; } try { blobStore.delete(blobRef.getBlobId(), "Deleting Bucket"); } catch (InvalidStateException e) { if (deletedBlobStores.add(blobStoreName)) { log.info("Not deleting blobs for blob store {}, invalid state {}", blobStoreName, e.getInvalidState(), log.isDebugEnabled() ? e : null); } } catch (Exception e) { log.warn("Error deleting blob {}, skipping", blobRef, e); } } }
@Override @Timed public boolean test(final BlobStore blobStore, final BlobId blobId, final String blobName) { BlobRef blobRef = new BlobRef(ANY_NODE, blobStore.getBlobStoreConfiguration().getName(), blobId.asUniqueString()); try (ODatabaseDocumentTx tx = txSupplier.get()) { tx.begin(); List<ODocument> results = tx.command(assetBlobRefQuery).execute(blobName, blobRef.toString()); return !results.isEmpty(); } } }
public static BlobRef parse(final String spec) { final Matcher matcher = BLOB_REF_PATTERN.matcher(spec); checkArgument(matcher.matches(), "Not a valid blob reference"); return new BlobRef(matcher.group(2), matcher.group(1), matcher.group(3)); }
@Nullable public Blob get(BlobRef blobRef) { return blobStore.get(blobRef.getBlobId()); }
public BlobId getBlobId() { return new BlobId(getBlob()); }
@Override protected void writeFields(final ODocument document, final Asset entity) { super.writeFields(document, entity); EntityId componentId = entity.componentId(); document.field(P_COMPONENT, componentId != null ? componentEntityAdapter.recordIdentity(componentId) : null); document.field(P_NAME, entity.name()); document.field(P_SIZE, entity.size()); document.field(P_CONTENT_TYPE, entity.contentType()); document.field(P_CREATED_BY, entity.createdBy()); document.field(P_CREATED_BY_IP, entity.createdByIp()); BlobRef blobRef = entity.blobRef(); document.field(P_BLOB_REF, blobRef != null ? blobRef.toString() : null); DateTime lastDownloaded = entity.lastDownloaded(); document.field(P_LAST_DOWNLOADED, lastDownloaded != null ? lastDownloaded.toDate() : null); DateTime blobCreated = entity.blobCreated(); document.field(P_BLOB_CREATED, blobCreated != null ? blobCreated.toDate() : null); DateTime blobUpdated = entity.blobUpdated(); document.field(P_BLOB_UPDATED, blobUpdated != null ? blobUpdated.toDate() : null); }
entity.createdByIp(createdByIp); if (blobRef != null) { entity.blobRef(BlobRef.parse(blobRef));
/** * The blob reference this instance is pointing to. */ @Nonnull public BlobRef getBlobRef() { return new BlobRef( nodeAccess.getId(), blobStore.getBlobStoreConfiguration().getName(), getBlob().getId().asUniqueString()); }
public void commit() { for (Entry<BlobRef, String> deletionRequestEntry : deletionRequests.entrySet()) { try { blobStore.delete(deletionRequestEntry.getKey().getBlobId(), deletionRequestEntry.getValue()); } catch (Throwable t) { log.warn("Unable to delete old blob {} while committing transaction", deletionRequestEntry.getKey(), t); } } for (AssetBlob assetBlob : newlyCreatedBlobs) { try { if (!assetBlob.isAttached()) { assetBlob.delete("Removing unattached asset"); } } catch (Throwable t) { log.warn("Unable to delete new orphan blob {} while committing transaction", assetBlob.getBlobRef(), t); } } clearState(); }
.filter(asset -> Strings2.isEmpty(asset.createdBy())) .filter(asset -> asset.blobRef() != null).map(asset -> { BlobStore blobStore = blobStoreManager.get(asset.blobRef().getStore()); Blob blob = blobStore.get(asset.blobRef().getBlobId()); if (blob != null) { asset.createdBy(blob.getHeaders().get(BlobStore.CREATED_BY_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); } } }); } } }
BlobId blobId = blobRef.getBlobId();