use of com.azure.resourcemanager.storage.StorageManager in project terra-workspace-manager by DataBiosphere.
the class GetAzureStorageStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
StorageManager storageManager = crlService.getStorageManager(azureCloudContext, azureConfig);
if (storageManager.storageAccounts().checkNameAvailability(resource.getStorageAccountName()).isAvailable()) {
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new DuplicateResourceException(String.format("An Azure Storage Account with name %s already exists", resource.getStorageAccountName())));
}
use of com.azure.resourcemanager.storage.StorageManager in project terra-workspace-manager by DataBiosphere.
the class CreateAzureStorageStep method undoStep.
/**
* Deletes the storage account if the account is available. If the storage account is available
* and deletes fails, the failure is considered fatal and must looked into it.
*
* @param context
* @return Step result.
* @throws InterruptedException
*/
@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
StorageManager storageManager = crlService.getStorageManager(azureCloudContext, azureConfig);
// then return success.
if (storageManager.storageAccounts().checkNameAvailability(resource.getStorageAccountName()).isAvailable()) {
logger.warn("Deletion of the storage account is not required. Storage account does not exist. {}", resource.getStorageAccountName());
return StepResult.getStepResultSuccess();
}
try {
logger.warn("Attempting to delete storage account: {}", resource.getStorageAccountName());
storageManager.storageAccounts().deleteByResourceGroup(azureCloudContext.getAzureResourceGroupId(), resource.getStorageAccountName());
logger.warn("Successfully deleted storage account: {}", resource.getStorageAccountName());
} catch (ManagementException e) {
logger.error("Failed to delete storage account: {}", resource.getStorageAccountName());
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
}
return StepResult.getStepResultSuccess();
}
use of com.azure.resourcemanager.storage.StorageManager in project terra-workspace-manager by DataBiosphere.
the class CreateAzureStorageStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
StorageManager storageManager = crlService.getStorageManager(azureCloudContext, azureConfig);
try {
storageManager.storageAccounts().define(resource.getStorageAccountName()).withRegion(resource.getRegion()).withExistingResourceGroup(azureCloudContext.getAzureResourceGroupId()).withHnsEnabled(true).withTag("workspaceId", resource.getWorkspaceId().toString()).withTag("resourceId", resource.getResourceId().toString()).create(Defaults.buildContext(CreateStorageAccountRequestData.builder().setName(resource.getStorageAccountName()).setRegion(Region.fromName(resource.getRegion())).setResourceGroupName(azureCloudContext.getAzureResourceGroupId()).build()));
} catch (ManagementException e) {
logger.error("Failed to create the Azure Storage account with the name: {} Error Code: {}", resource.getStorageAccountName(), e.getValue().getCode(), e);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.azure.resourcemanager.storage.StorageManager in project terra-workspace-manager by DataBiosphere.
the class CrlService method buildStorageManager.
private StorageManager buildStorageManager(AzureCloudContext azureCloudContext, AzureConfiguration azureConfig) {
TokenCredential azureCreds = getManagedAppCredentials(azureConfig);
AzureProfile azureProfile = new AzureProfile(azureCloudContext.getAzureTenantId(), azureCloudContext.getAzureSubscriptionId(), AzureEnvironment.AZURE);
// We must use FQDN because there are two `Defaults` symbols imported otherwise.
StorageManager manager = bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(clientConfig, StorageManager.configure()).authenticate(azureCreds, azureProfile);
return manager;
}
use of com.azure.resourcemanager.storage.StorageManager in project azure-maven-plugins by microsoft.
the class AzureStorageAccount method checkNameAvailability.
public CheckNameAvailabilityResultEntity checkNameAvailability(String subscriptionId, String name) {
StorageManager manager = StorageManagerFactory.create(subscriptionId);
CheckNameAvailabilityResult result = manager.storageAccounts().checkNameAvailability(name);
return new CheckNameAvailabilityResultEntity(result.isAvailable(), Optional.ofNullable(result.reason()).map(Reason::toString).orElse(null), result.message());
}
Aggregations