private BlobStore newBlobStore(final BlobStoreConfiguration blobStoreConfiguration) throws Exception { BlobStore blobStore = blobStorePrototypes.get(blobStoreConfiguration.getType()).get(); blobStore.init(blobStoreConfiguration); return blobStore; }
@Override public long blobStoreUsageCount(final String blobStoreName) { long count = 0; for (BlobStore otherBlobStore : stores.values()) { BlobStoreConfiguration otherBlobStoreConfig = otherBlobStore.getBlobStoreConfiguration(); BlobStoreDescriptor otherBlobStoreDescriptor = blobStoreDescriptors.get(otherBlobStoreConfig.getType()); if (otherBlobStoreDescriptor.configHasDependencyOn(otherBlobStoreConfig, blobStoreName)) { count += 1; } } return count; }
public BlobStoreConfiguration copy(String name) { BlobStoreConfiguration clone = new BlobStoreConfiguration(); clone.setName(name); clone.setType(getType()); if (attributes != null && attributes.size() > 0) { String attribsJson; try { attribsJson = MAPPER.writer().writeValueAsString(getAttributes()); } catch (JsonProcessingException e) { throw new BlobStoreException("failed to marshal blob store configuration attributes to JSON", e, null); } Map<String, Map<String,Object>> clonedAttributes; try { clonedAttributes = MAPPER.readValue(attribsJson, new TypeReference<Map<String,Map<String,Object>>>(){}); } catch (IOException e) { throw new BlobStoreException("failed to parse blob store configuration attributes from JSON", e, null); } clone.setAttributes(clonedAttributes); } return clone; }
@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()); }
@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 @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; }