/** * @since 3.14 */ public boolean update(final ODatabaseDocumentTx db, final BlobStoreConfiguration entity) { return update.execute(db, entity, entity.getName()); }
private void delete(final BlobStore blobStore) { detect(blobStore, blobId -> { log.info("Deleting orphaned blob {} from blobstore {}", blobId, blobStore.getBlobStoreConfiguration().getName()); blobStore.deleteHard(new BlobId(blobId)); }); }
@Subscribe public void on(final BlobStoreConfigurationCreatedEvent event) { handleRemoteOnly(event, evt -> { // only create if not tracked String name = evt.getName(); if (!stores.containsKey(name)) { store.list().stream() .filter(c -> c.getName().equals(name)) .findFirst() .ifPresent(c -> { try { BlobStore blobStore = newBlobStore(c); track(name, blobStore); blobStore.start(); } catch (Exception e) { log.warn("create blob store from remote event failed: {}", name, e); } }); } }); }
@Override public void close() { try { blobStore.deleteHard(blob.getId()); } catch (BlobStoreException e) { log.debug("Unable to delete blob {} in blob store {}", blob.getId(), blobStore.getBlobStoreConfiguration().getName(), e); } }
try { BlobStore blobStore = newBlobStore(configuration); track(configuration.getName(), blobStore);
@Override public boolean isPromotable(final String blobStoreName) { BlobStore blobStore = get(blobStoreName); return blobStore != null && blobStore.isGroupable() && blobStore.isWritable() && !store.findParent(blobStore.getBlobStoreConfiguration().getName()).isPresent(); }
@Subscribe @AllowConcurrentEvents public void on(final BlobStoreEvent event) { if (isRecording()) { BlobStore blobStore = event.getBlobStore(); BlobStoreConfiguration configuration = blobStore.getBlobStoreConfiguration(); AuditData data = new AuditData(); data.setDomain(DOMAIN); data.setType(type(event.getClass())); data.setContext(configuration.getName()); Map<String, String> attributes = data.getAttributes(); attributes.put("name", configuration.getName()); attributes.put("type", configuration.getType()); record(data); } } }
@Override @Guarded(by = STARTED) public BlobStore create(final BlobStoreConfiguration configuration) throws Exception { checkNotNull(configuration); log.debug("Creating BlobStore: {} with attributes: {}", configuration.getName(), configuration.getAttributes()); BlobStoreDescriptor blobStoreDescriptor = blobStoreDescriptors.get(configuration.getType()); blobStoreDescriptor.validateConfig(configuration); BlobStore blobStore = newBlobStore(configuration); try { store.create(configuration); } catch (Exception e) { try { blobStore.remove(); } catch (Exception removeException) { // if an error occurs on remove log and rethrow original to avoid losing the root cause log.error("Error removing BlobStore {} after create failed", configuration.getName(), removeException); } throw e; } track(configuration.getName(), blobStore); blobStore.start(); eventManager.post(new BlobStoreCreatedEvent(blobStore)); return blobStore; }
@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(); } } }
/** * The blob reference this instance is pointing to. */ @Nonnull public BlobRef getBlobRef() { return new BlobRef( nodeAccess.getId(), blobStore.getBlobStoreConfiguration().getName(), getBlob().getId().asUniqueString()); }
@Override protected void writeFields(final ODocument document, final BlobStoreConfiguration entity) { document.field(P_NAME, entity.getName()); document.field(P_TYPE, entity.getType()); document.field(P_ATTRIBUTES, entity.getAttributes()); }
@Override @Guarded(by = STARTED) public BlobStore update(final BlobStoreConfiguration configuration) throws Exception { checkNotNull(configuration); BlobStore blobStore = get(configuration.getName()); checkNotNull(blobStore); log.debug("Updating BlobStore: {} with attributes: {}", configuration.getName(), configuration.getAttributes()); BlobStoreDescriptor blobStoreDescriptor = blobStoreDescriptors.get(configuration.getType()); blobStoreDescriptor.validateConfig(configuration); BlobStoreConfiguration currentConfig = blobStore.getBlobStoreConfiguration(); blobStore.stop(); try { blobStore.init(configuration); blobStore.start(); store.update(configuration); eventManager.post(new BlobStoreUpdatedEvent(blobStore)); } catch (Exception e) { log.error("Failed to update configuration", e); if (blobStore.isStarted()) { blobStore.stop(); } blobStore.init(currentConfig); blobStore.start(); throw new BlobStoreException("Failed to start blob store with new configuration.", null); } return blobStore; }
@Override public void check(final Repository repository, final BlobStore blobStore, final Supplier<Boolean> isCancelled) { log.info("Checking integrity of assets in repository '{}' with blob store '{}'", repository.getName(), blobStore.getBlobStoreConfiguration().getName()); ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); long processed = 0;