use of com.azure.storage.blob.BlobUrlParts in project azure-vm-agents-plugin by jenkinsci.
the class IntegrationTest method containerExists.
protected boolean containerExists(String storageURI) {
try {
BlobUrlParts blobUrlParts = BlobUrlParts.parse(storageURI);
String storageAccountName = blobUrlParts.getAccountName();
final String containerName = blobUrlParts.getBlobContainerName();
StorageAccount storageAccount = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, storageAccountName);
List<StorageAccountKey> storageKeys = storageAccount.getKeys();
if (storageKeys.isEmpty()) {
return false;
} else {
String storageAccountKey = storageKeys.get(0).value();
BlobServiceClient account = new BlobServiceClientBuilder().credential(new StorageSharedKeyCredential(storageAccountName, storageAccountKey)).endpoint(storageAccount.endPoints().primary().blob()).buildClient();
BlobContainerClient blobClient = account.getBlobContainerClient(containerName);
return blobClient.exists();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return false;
}
}
use of com.azure.storage.blob.BlobUrlParts in project azure-vm-agents-plugin by jenkinsci.
the class AzureVMManagementServiceDelegate method removeStorageBlob.
public void removeStorageBlob(URI blobURI, String resourceGroupName) throws Exception {
// Obtain container, storage account, and blob name
BlobUrlParts blobUrlParts = BlobUrlParts.parse(blobURI.toURL());
String storageAccountName = blobUrlParts.getAccountName();
String containerName = blobUrlParts.getBlobContainerName();
String blobName = blobUrlParts.getBlobName();
LOGGER.log(Level.INFO, "removeStorageBlob: Removing blob {0}, in container {1} of storage account {2}", new Object[] { blobName, containerName, storageAccountName });
BlobContainerClient container = getCloudBlobContainer(azureClient, resourceGroupName, storageAccountName, containerName);
container.getBlobClient(blobName).delete();
if (containerName.startsWith("jnk")) {
PagedIterable<BlobItem> 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();
}
}
use of com.azure.storage.blob.BlobUrlParts in project azure-vm-agents-plugin by jenkinsci.
the class IntegrationTest method blobExists.
protected boolean blobExists(String storageURI) {
try {
BlobUrlParts blobUrlParts = BlobUrlParts.parse(storageURI);
String storageAccountName = blobUrlParts.getAccountName();
final String containerName = blobUrlParts.getBlobContainerName();
final String blobName = blobUrlParts.getBlobName();
StorageAccount storageAccount = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, storageAccountName);
List<StorageAccountKey> storageKeys = storageAccount.getKeys();
if (storageKeys.isEmpty()) {
return false;
} else {
String storageAccountKey = storageKeys.get(0).value();
BlobServiceClient account = new BlobServiceClientBuilder().credential(new StorageSharedKeyCredential(storageAccountName, storageAccountKey)).endpoint(storageAccount.endPoints().primary().blob()).buildClient();
BlobContainerClient blobClient = account.getBlobContainerClient(containerName);
return blobClient.getBlobClient(blobName).exists();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return false;
}
}
Aggregations