use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.
the class AzureStorageService method deleteBlobDirectory.
void deleteBlobDirectory(String container, String path) throws URISyntaxException, StorageException, IOException {
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true)) {
// uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
// this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
final String blobPath = blobItem.getUri().getPath().substring(1 + container.length() + 1);
try {
deleteBlob(container, blobPath);
} catch (URISyntaxException | StorageException e) {
throw new IOException("Deleting directory [" + path + "] failed");
}
}
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.
the class AzureStorageService method doesContainerExist.
public boolean doesContainerExist(String container) throws URISyntaxException, StorageException {
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
return blobContainer.exists(null, null, client.v2().get());
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.
the class AzureStorageService method buildClient.
protected CloudBlobClient buildClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
final CloudBlobClient client = createClient(azureStorageSettings);
// Set timeout option if the user sets cloud.azure.storage.timeout or
// cloud.azure.storage.xxx.timeout (it's negative by default)
final long timeout = azureStorageSettings.getTimeout().getMillis();
if (timeout > 0) {
if (timeout > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Timeout [" + azureStorageSettings.getTimeout() + "] exceeds 2,147,483,647ms.");
}
client.getDefaultRequestOptions().setTimeoutIntervalInMs((int) timeout);
}
// We define a default exponential retry policy
client.getDefaultRequestOptions().setRetryPolicyFactory(new RetryExponentialRetry(RetryPolicy.DEFAULT_CLIENT_BACKOFF, azureStorageSettings.getMaxRetries()));
client.getDefaultRequestOptions().setLocationMode(azureStorageSettings.getLocationMode());
return client;
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.
the class AzureStorageService method listBlobsByPrefix.
public Map<String, BlobMetadata> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
// NOTE: this should be here: if (prefix == null) prefix = "";
// however, this is really inefficient since deleteBlobsByPrefix enumerates everything and
// then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix!
final var blobsBuilder = new HashMap<String, BlobMetadata>();
final EnumSet<BlobListingDetails> enumBlobListingDetails = EnumSet.of(BlobListingDetails.METADATA);
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
LOGGER.trace(() -> new ParameterizedMessage("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix));
for (final ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix), false, enumBlobListingDetails, null, client.v2().get())) {
final URI uri = blobItem.getUri();
LOGGER.trace(() -> new ParameterizedMessage("blob url [{}]", uri));
// uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
// this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
final String blobPath = uri.getPath().substring(1 + container.length() + 1);
if (blobItem instanceof CloudBlob) {
final BlobProperties properties = ((CloudBlob) blobItem).getProperties();
final String name = blobPath.substring(keyPath.length());
LOGGER.trace(() -> new ParameterizedMessage("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength()));
blobsBuilder.put(name, new PlainBlobMetadata(name, properties.getLength()));
}
}
return Map.copyOf(blobsBuilder);
}
use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.
the class AzureStorageServiceTests method testGetSelectedClientDefaultTimeout.
public void testGetSelectedClientDefaultTimeout() {
final Settings timeoutSettings = Settings.builder().put(buildClientCredSettings()).build();
final AzureStorageService azureStorageService = storageServiceWithSettings(timeoutSettings);
final CloudBlobClient client = azureStorageService.client().v1();
assertThat(client.getDefaultRequestOptions().getTimeoutIntervalInMs(), nullValue());
}
Aggregations