public List<String> emptyCloudBlobDirectory(final String containerName, final String virtualDirPath) throws StorageException, URISyntaxException { List<String> deletedFiles = new ArrayList<>(); CloudBlobContainer container = getCloudBlobContainer(containerName); for (ListBlobItem blobItem : container.listBlobs(virtualDirPath, true, null, null, null)) { CloudBlob cloudBlob = (CloudBlob) blobItem; log.info("Removing file[%s] from Azure.", cloudBlob.getName()); if (cloudBlob.deleteIfExists()) { deletedFiles.add(cloudBlob.getName()); } } if (deletedFiles.isEmpty()) { log.warn("No files were deleted on the following Azure path: [%s]", virtualDirPath); } return deletedFiles; }
blob.deleteIfExists(DeleteSnapshotsOption.valueOf(deleteSnapshotOptions), null, null, operationContext); session.transfer(flowFile, REL_SUCCESS);
/** * Deletes the blob if it exists. * <p> * A blob that has snapshots cannot be deleted unless the snapshots are also deleted. If a blob has snapshots, use * the {@link DeleteSnapshotsOption#DELETE_SNAPSHOTS_ONLY} or {@link DeleteSnapshotsOption#INCLUDE_SNAPSHOTS} value * in the <code>deleteSnapshotsOption</code> parameter to specify how the snapshots should be handled when the blob * is deleted. * * @return <code>true</code> if the blob was deleted; otherwise, <code>false</code>. * * @throws StorageException * If a storage service error occurred. * */ @DoesServiceRequest public final boolean deleteIfExists() throws StorageException { return this .deleteIfExists(DeleteSnapshotsOption.NONE, null /* accessCondition */, null /* options */, null /* opContext */); }
public static void deleteAllEntries(CloudBlobDirectory directory) throws IOException { Stream<CloudBlob> blobs = getBlobs(directory); blobs.forEach(b -> { try { b.deleteIfExists(); } catch (StorageException e) { log.error("Can't delete blob {}", b.getUri().getPath(), e); } }); }
public static void deleteAllEntries(CloudBlobDirectory directory) throws IOException { Stream<CloudBlob> blobs = getBlobs(directory); blobs.forEach(b -> { try { b.deleteIfExists(); } catch (StorageException e) { log.error("Can't delete blob {}", b.getUri().getPath(), e); } }); }
/** * Deletes the blob if it exists. * <p> * A blob that has snapshots cannot be deleted unless the snapshots are also deleted. If a blob has snapshots, use * the {@link DeleteSnapshotsOption#DELETE_SNAPSHOTS_ONLY} or {@link DeleteSnapshotsOption#INCLUDE_SNAPSHOTS} value * in the <code>deleteSnapshotsOption</code> parameter to specify how the snapshots should be handled when the blob * is deleted. * * @return <code>true</code> if the blob was deleted; otherwise, <code>false</code>. * * @throws StorageException * If a storage service error occurred. * */ @DoesServiceRequest public final boolean deleteIfExists() throws StorageException { return this .deleteIfExists(DeleteSnapshotsOption.NONE, null /* accessCondition */, null /* options */, null /* opContext */); }
for (ListBlobItem item : metaDir.listBlobs(prefix)) { if (item instanceof CloudBlob) { if (((CloudBlob)item).deleteIfExists()) { total++;
public List<String> emptyCloudBlobDirectory(final String containerName, final String virtualDirPath) throws StorageException, URISyntaxException { List<String> deletedFiles = new ArrayList<>(); CloudBlobContainer container = getCloudBlobContainer(containerName); for (ListBlobItem blobItem : container.listBlobs(virtualDirPath, true, null, null, null)) { CloudBlob cloudBlob = (CloudBlob) blobItem; log.info("Removing file[%s] from Azure.", cloudBlob.getName()); if (cloudBlob.deleteIfExists()) { deletedFiles.add(cloudBlob.getName()); } } if (deletedFiles.isEmpty()) { log.warn("No files were deleted on the following Azure path: [%s]", virtualDirPath); } return deletedFiles; }
public void deleteBlobFile(@NotNull String connectionString, @NotNull BlobFile blobFile) throws AzureCmdException { try { CloudBlobClient client = getCloudBlobClient(connectionString); String containerName = blobFile.getContainerName(); CloudBlobContainer container = client.getContainerReference(containerName); CloudBlob blob = getCloudBlob(container, blobFile); blob.deleteIfExists(); } catch (Throwable t) { throw new AzureCmdException("Error deleting the Blob File", t); } }
@Override protected void removeAll(String clustername) { if (clustername == null) { return; } clustername = sanitize(clustername); Iterable<ListBlobItem> listBlobItems = containerReference.listBlobs(clustername); for (ListBlobItem blobItem : listBlobItems) { try { // If the item is a blob and not a virtual directory. if (blobItem instanceof CloudBlob) { CloudBlob blob = (CloudBlob) blobItem; boolean deleted = blob.deleteIfExists(); if (deleted) { log.trace("Deleted file '%s'.", blob.getName()); } else { log.debug("Tried to delete file '%s' but it was already deleted.", blob.getName()); } } } catch (Exception e) { log.error("Error deleting ping data for cluster '" + clustername + "'.", e); } } }
@Override protected void removeAll(String clustername) { if (clustername == null) { return; } clustername = sanitize(clustername); Iterable<ListBlobItem> listBlobItems = containerReference.listBlobs(clustername); for (ListBlobItem blobItem : listBlobItems) { try { // If the item is a blob and not a virtual directory. if (blobItem instanceof CloudBlob) { CloudBlob blob = (CloudBlob) blobItem; boolean deleted = blob.deleteIfExists(); if (deleted) { log.trace("Deleted file '%s'.", blob.getName()); } else { log.debug("Tried to delete file '%s' but it was already deleted.", blob.getName()); } } } catch (Exception e) { log.error("Error deleting ping data for cluster '" + clustername + "'.", e); } } }