use of com.microsoft.azure.storage.blob.CloudBlobContainer in project druid by druid-io.
the class AzureStorage method emptyCloudBlobDirectory.
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;
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.
the class AzureStorageServiceImpl method createContainer.
@Override
public void createContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
try {
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
logger.trace("creating container [{}]", container);
SocketAccess.doPrivilegedException(blobContainer::createIfNotExists);
} catch (IllegalArgumentException e) {
logger.trace((Supplier<?>) () -> new ParameterizedMessage("fails creating container [{}]", container), e);
throw new RepositoryException(container, e.getMessage(), e);
}
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.
the class AzureStorageServiceImpl method removeContainer.
@Override
public void removeContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
logger.trace("removing container [{}]", container);
SocketAccess.doPrivilegedException(blobContainer::deleteIfExists);
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.
the class AzureStorageServiceImpl method blobExists.
@Override
public boolean blobExists(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
if (blobContainer.exists()) {
CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
return SocketAccess.doPrivilegedException(azureBlob::exists);
}
return false;
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project hadoop by apache.
the class LocalSASKeyGeneratorImpl method getRelativeBlobSASUri.
/**
* Implementation for generation of Relative Path Blob SAS Uri.
*/
@Override
public URI getRelativeBlobSASUri(String accountName, String container, String relativePath) throws SASKeyGenerationException {
CloudBlobContainer sc = null;
CloudBlobClient client = null;
try {
CloudStorageAccount account = getSASKeyBasedStorageAccountInstance(accountName);
client = account.createCloudBlobClient();
sc = client.getContainerReference(container);
} catch (URISyntaxException uriSyntaxEx) {
throw new SASKeyGenerationException("Encountered URISyntaxException " + "while getting container references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
} catch (StorageException stoEx) {
throw new SASKeyGenerationException("Encountered StorageException while " + "getting container references for container " + container + " inside storage account : " + accountName, stoEx);
}
CloudBlockBlob blob = null;
try {
blob = sc.getBlockBlobReference(relativePath);
} catch (URISyntaxException uriSyntaxEx) {
throw new SASKeyGenerationException("Encountered URISyntaxException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
} catch (StorageException stoEx) {
throw new SASKeyGenerationException("Encountered StorageException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, stoEx);
}
try {
return client.getCredentials().transformUri(blob.getUri());
} catch (StorageException stoEx) {
throw new SASKeyGenerationException("Encountered StorageException while " + "generating SAS key for Blob: " + relativePath + " inside " + "container : " + container + " in Storage Account : " + accountName, stoEx);
} catch (URISyntaxException uriSyntaxEx) {
throw new SASKeyGenerationException("Encountered URISyntaxException " + "while generating SAS key for Blob: " + relativePath + " inside " + "container: " + container + " in Storage Account : " + accountName, uriSyntaxEx);
}
}
Aggregations