/** * Deletes this temporary {@link AssetBlob} by clearing any locally ingested blobs. * * Note this shouldn't stop the current response from serving back temporary content, * it just makes sure non-persisted content is eventually cleaned up from the store. * * @since 3.4 */ void delete(final String reason) { if (ingestedBlob != null) { if (canonicalBlob != null) { // canonical redirect is in place, so it's safe to hard-delete the temp blob blobStore.deleteHard(ingestedBlob.getId()); } else { // no redirect, so the temp blob is all we have - use soft-delete so the bytes // will still be available on disk for streaming back in the current response, // while making sure it gets cleaned up on the next compact blobStore.delete(ingestedBlob.getId(), reason); } } }
/** * Parses the data field of an attachment in the JSON. The data is stored in a temp blob, and the blob ID is returned * as a string. */ private String parseAttachmentData() throws IOException { try { TempBlob tempBlob = readBinaryValueIntoTempBlob(); String id = tempBlob.getBlob().getId().toString(); tempBlobs.put(id, tempBlob); return id; } catch (Exception e) { throw new IOException("failed to process attachment data", e); } }
@Override public boolean create(final String path, final String mimeType, final InputStream inputStream) { if (exists(path)) { return false; } Map<String, String> blobMetadata = new HashMap<>(); blobMetadata.put(BlobStore.BLOB_NAME_HEADER, path); blobMetadata.put(BlobStore.CREATED_BY_HEADER, "Unknown"); blobMetadata.put("mimeType", mimeType); final Blob blob = blobStore.create(inputStream, blobMetadata); final RawBinaryMetadata item = new RawBinaryMetadata(path, blob.getId().asUniqueString(), mimeType); ORID rid; try (ODatabaseDocumentTx db = openDb()) { ODocument doc = entityAdapter.create(db, item); rid = doc.getIdentity(); } log.debug("Added item with RID: {}", rid); return true; }
@Override public AssetBlob createBlob(final String blobName, final TempBlob originalBlob, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, boolean skipContentVerification) throws IOException { checkNotNull(blobName); checkNotNull(originalBlob); if (!writePolicy.checkCreateAllowed()) { throw new IllegalOperationException("Repository is read only: " + repositoryName); } Map<String, String> storageHeadersMap = buildStorageHeaders(blobName, originalBlob, headers, declaredContentType, skipContentVerification); return blobTx.createByCopying( originalBlob.getBlob().getId(), storageHeadersMap, originalBlob.getHashes(), originalBlob.getHashesVerified() ); }
/** * The blob reference this instance is pointing to. */ @Nonnull public BlobRef getBlobRef() { return new BlobRef( nodeAccess.getId(), blobStore.getBlobStoreConfiguration().getName(), getBlob().getId().asUniqueString()); }
private void doRestore(StorageFacet storageFacet, RestoreBlobData blobData, T restoreData, boolean isDryRun) { String logPrefix = isDryRun ? dryRunPrefix.get() : ""; String path = getAssetPath(restoreData); String blobStoreName = blobData.getBlobStoreName(); String repoName = blobData.getRepository().getName(); String blobName = blobData.getBlobName(); Blob blob = blobData.getBlob(); UnitOfWork.begin(storageFacet.txSupplier()); try { if (assetExists(restoreData)) { log.debug( "Skipping as asset already exists, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}", blobStoreName, repoName, path, blobName, blob.getId()); return; } if (!isDryRun) { doCreateAssetFromBlob(blobData, restoreData, blob); } log.info("{}Restored asset, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}", logPrefix, blobStoreName, repoName, path, blobName, blob.getId()); } catch (Exception e) { log.error("Error while restoring asset: blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}", blobStoreName, repoName, path, blobName, blob.getId(), e); } finally { UnitOfWork.end(); } }
@Override public void restore(final Properties properties, final Blob blob, final String blobStoreName, final boolean isDryRun) { RestoreBlobData blobData = new RestoreBlobData(blob, properties, blobStoreName, repositoryManager); Optional<StorageFacet> storageFacet = blobData.getRepository().optionalFacet(StorageFacet.class); T restoreData = createRestoreData(blobData); if (storageFacet.isPresent() && canAttemptRestore(restoreData)) { doRestore(storageFacet.get(), blobData, restoreData, isDryRun); } else { log.debug("Skipping asset, blob store: {}, repository: {}, blob name: {}, blob id: {}", blobStoreName, blobData.getRepository().getName(), blobData.getBlobName(), blob.getId()); } }