public boolean deleteBlobBlockIfExist(final CloudBlockBlob block) throws StorageException { return block.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, AzureStorageUtils.getTalendOperationContext()); }
public boolean deleteBlobBlockIfExist(final CloudBlockBlob block) throws StorageException { return block.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, AzureStorageUtils.getTalendOperationContext()); }
protected void deleteBlobDir(CloudBlobContainer container, String path) throws StorageException { for (ListBlobItem blobItem : container.listBlobs(path)) { if (blobItem instanceof CloudBlockBlob) { ((CloudBlockBlob)blobItem).deleteIfExists(); } else { String subdir = blobItem.getUri().getPath().replaceAll("^/[^/]*?/", ""); deleteBlobDir(container, subdir); } } }
@Override protected void doRemove(String fullPath) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); blob.deleteIfExists(); } catch (Exception e) { throw E.unexpected(e); } }
@Override public CompletableFuture<Void> deleteLease(CompleteLease lease) { CompletableFuture<Void> future = null; TRACE_LOGGER.info(this.hostContext.withHostAndPartition(lease, "Deleting lease")); try { ((AzureBlobLease) lease).getBlob().deleteIfExists(); future = CompletableFuture.completedFuture(null); } catch (StorageException e) { TRACE_LOGGER.error(this.hostContext.withHostAndPartition(lease, "Exception deleting lease"), e); future = new CompletableFuture<Void>(); future.completeExceptionally(LoggingUtils.wrapException(e, EventProcessorHostActionStrings.DELETING_LEASE)); } return future; }
@Override public boolean deleteMetadataRecord(String name) { long start = System.currentTimeMillis(); ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); CloudBlockBlob blob = getAzureContainer().getBlockBlobReference(addMetaKeyPrefix(name)); boolean result = blob.deleteIfExists(); LOG.debug("Metadata record {}. metadataName={} duration={}", result ? "deleted" : "delete requested, but it does not exist (perhaps already deleted)", name, (System.currentTimeMillis() - start)); return result; } catch (StorageException e) { LOG.info("Error deleting metadata record. metadataName={}", name, e); } catch (DataStoreException | URISyntaxException e) { LOG.debug("Error deleting metadata record. metadataName={}", name, e); } finally { if (contextClassLoader != null) { Thread.currentThread().setContextClassLoader(contextClassLoader); } } return false; }
@Override public void deleteRecord(DataIdentifier identifier) throws DataStoreException { if (null == identifier) throw new NullPointerException("identifier"); String key = getKeyName(identifier); long start = System.currentTimeMillis(); ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); boolean result = getAzureContainer().getBlockBlobReference(key).deleteIfExists(); LOG.debug("Blob {}. identifier={} duration={}", result ? "deleted" : "delete requested, but it does not exist (perhaps already deleted)", key, (System.currentTimeMillis() - start)); } catch (StorageException e) { LOG.info("Error deleting blob. identifier={}", key, e); throw new DataStoreException(e); } catch (URISyntaxException e) { throw new DataStoreException(e); } finally { if (contextClassLoader != null) { Thread.currentThread().setContextClassLoader(contextClassLoader); } } }
private CompletableFuture<Void> deleteStoreInternal(BlobRequestOptions options) { CompletableFuture<Void> future = null; try { for (ListBlobItem blob : this.eventHubContainer.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), options, null)) { if (blob instanceof CloudBlobDirectory) { for (ListBlobItem subBlob : ((CloudBlobDirectory) blob).listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), options, null)) { ((CloudBlockBlob) subBlob).deleteIfExists(DeleteSnapshotsOption.NONE, null, options, null); } } else if (blob instanceof CloudBlockBlob) { ((CloudBlockBlob) blob).deleteIfExists(DeleteSnapshotsOption.NONE, null, options, null); } } this.eventHubContainer.deleteIfExists(null, options, null); future = CompletableFuture.completedFuture(null); } catch (StorageException | URISyntaxException e) { TRACE_LOGGER.error(this.hostContext.withHost("Failure while deleting lease store"), e); future = new CompletableFuture<Void>(); future.completeExceptionally(new CompletionException(e)); } return future; }
public void removeStorageBlob(URI blobURI, String resourceGroupName) throws Exception { // Obtain container, storage account, and blob name String storageAccountName = blobURI.getHost().split("\\.")[0]; String containerName = PathUtility.getContainerNameFromUri(blobURI, false); String blobName = PathUtility.getBlobNameFromURI(blobURI, false); LOGGER.log(Level.INFO, "removeStorageBlob: Removing blob {0}, in container {1} of storage account {2}", new Object[]{blobName, containerName, storageAccountName}); CloudBlobContainer container = getCloudBlobContainer(azureClient, resourceGroupName, storageAccountName, containerName); container.getBlockBlobReference(blobName).deleteIfExists(); if (containerName.startsWith("jnk")) { Iterable<ListBlobItem> blobs = container.listBlobs(); if (blobs.iterator().hasNext()) { // the container is not empty return; } // the container is empty and we should delete it LOGGER.log(Level.INFO, "removeStorageBlob: Removing empty container ", containerName); container.delete(); } }
public static void deleteBlob(final CloudStorageAccount storageAccount, final String containerName, final String blobName) throws Exception { final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName); if (blobContainer.exists()) { final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName); blob.deleteIfExists(); } }
String importBlobName = "devices.txt"; CloudBlockBlob importBlob = importContainer.getBlockBlobReference(importBlobName); importBlob.deleteIfExists(); importBlob.upload(stream, blobToImport.length);
@Override protected void remove(final String clustername, final Address addr) { if (clustername == null || addr == null) { return; } String filename = addressToFilename(clustername, addr); try { CloudBlockBlob blob = containerReference.getBlockBlobReference(filename); boolean deleted = blob.deleteIfExists(); if (deleted) { log.debug("Tried to delete file '%s' but it was already deleted.", filename); } else { log.trace("Deleted file '%s'.", filename); } } catch (Exception ex) { log.error("Error deleting files.", ex); } }
@Override protected void remove(final String clustername, final Address addr) { if (clustername == null || addr == null) { return; } String filename = addressToFilename(clustername, addr); try { CloudBlockBlob blob = containerReference.getBlockBlobReference(filename); boolean deleted = blob.deleteIfExists(); if (deleted) { log.debug("Tried to delete file '%s' but it was already deleted.", filename); } else { log.trace("Deleted file '%s'.", filename); } } catch (Exception ex) { log.error("Error deleting files.", ex); } }
InputStream stream = new ByteArrayInputStream(blobToImport); CloudBlockBlob importBlob = container.getBlockBlobReference(DeviceManagerImportSample.importBlobName); importBlob.deleteIfExists(); importBlob.upload(stream, blobToImport.length);
blob1.deleteIfExists(); blob2.deleteIfExists(); blob3.deleteIfExists();
assertFalse(blob1.deleteIfExists()); assertTrue(blob1.deleteIfExists()); assertFalse(blob1.deleteIfExists()); assertFalse(blob1.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, ctx));
blockBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); blockBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); blockBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_ONLY); try { blockBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context);
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlockBlobUploadStandardTier() throws StorageException, IOException, URISyntaxException { for (StandardBlobTier standardBlobTier : StandardBlobTier.values()) { if (standardBlobTier == StandardBlobTier.UNKNOWN) { continue; } final String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlob"); final CloudBlockBlob blob = this.container.getBlockBlobReference(blobName); blob.uploadText("text"); blob.uploadStandardBlobTier(standardBlobTier); assertEquals(standardBlobTier, blob.getProperties().getStandardBlobTier()); assertNull(blob.getProperties().getPremiumPageBlobTier()); assertNull(blob.getProperties().getRehydrationStatus()); CloudBlockBlob blob2 = this.container.getBlockBlobReference(blobName); blob2.downloadAttributes(); assertEquals(standardBlobTier, blob2.getProperties().getStandardBlobTier()); assertNull(blob2.getProperties().getPremiumPageBlobTier()); assertNull(blob2.getProperties().getRehydrationStatus()); CloudBlockBlob blob3 = (CloudBlockBlob)this.container.listBlobs().iterator().next(); assertEquals(standardBlobTier, blob3.getProperties().getStandardBlobTier()); assertNull(blob3.getProperties().getPremiumPageBlobTier()); assertNull(blob3.getProperties().getRehydrationStatus()); blob.deleteIfExists(); } }