use of com.azure.storage.blob.models.ListBlobContainersOptions in project ats-framework by Axway.
the class BlobStorageOperations method listContainers.
private PagedIterable<BlobContainerItem> listContainers(String containerNamePrefix, long retrieveTimeoutSeconds, boolean retrieveMetadata) {
try {
StringBuilder message = new StringBuilder();
message.append("Listing");
BlobContainerListDetails bcld = new BlobContainerListDetails();
ListBlobContainersOptions lbco = new ListBlobContainersOptions();
message.append(" containers");
if (containerNamePrefix != null && !containerNamePrefix.isEmpty()) {
message.append(" with prefix '" + containerNamePrefix + "'");
lbco.setPrefix(containerNamePrefix);
}
if (log.isInfoEnabled()) {
message.append(" ...");
log.info(message.toString());
}
bcld.setRetrieveMetadata(retrieveMetadata);
lbco.setDetails(bcld);
if (retrieveTimeoutSeconds <= 0) {
// just a little less than too much
retrieveTimeoutSeconds = Integer.MAX_VALUE / 2;
}
PagedIterable<BlobContainerItem> blobContainers = serviceClient.listBlobContainers(lbco, Duration.ofSeconds(retrieveTimeoutSeconds));
log.info("Successfully listed " + blobContainers.stream().count() + " containers.");
return blobContainers;
} catch (Exception e) {
throw new AtsBlobStorageException("Could not list containers " + (!StringUtils.isNullOrEmpty(containerNamePrefix) ? "with prefix '" + containerNamePrefix + "'" : "") + " in " + retrieveTimeoutSeconds + " seconds", e);
}
}
use of com.azure.storage.blob.models.ListBlobContainersOptions in project ambry by linkedin.
the class AzureTokenResetTool method resetTokens.
/**
* Reset the offset token by deleting the blob from the container.
* @param containerPrefix the prefix used to filter on Azure containers
* (in case the storage account hosts multiple Ambry clusters).
* @return the number of tokens successfully reset.
*/
public static int resetTokens(String containerPrefix) throws BlobStorageException {
AtomicInteger tokensDeleted = new AtomicInteger(0);
ListBlobContainersOptions listOptions = new ListBlobContainersOptions().setPrefix(containerPrefix);
storageClient.listBlobContainers(listOptions, null).iterator().forEachRemaining(blobContainer -> {
BlockBlobClient blobClient = storageClient.getBlobContainerClient(blobContainer.getName()).getBlobClient(ReplicationConfig.REPLICA_TOKEN_FILE_NAME).getBlockBlobClient();
try {
if (blobClient.exists()) {
blobClient.delete();
tokensDeleted.incrementAndGet();
logger.info("Deleted token for partition {}", blobContainer.getName());
}
} catch (Exception ex) {
logger.error("Failed delete for {}", blobContainer.getName(), ex);
}
});
return tokensDeleted.get();
}
Aggregations