use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.
the class AzureWorkspaceTest method createGetDeleteAzureContext.
@Test
void createGetDeleteAzureContext() {
AuthenticatedUserRequest userRequest = new AuthenticatedUserRequest().token(Optional.of("fake-token")).email("fake@email.com").subjectId("fakeID123");
Workspace request = Workspace.builder().workspaceId(UUID.randomUUID()).spendProfileId(spendUtils.defaultSpendId()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
workspaceService.createWorkspace(request, userRequest);
String jobId = UUID.randomUUID().toString();
AzureCloudContext azureCloudContext = new AzureCloudContext(azureTestConfiguration.getTenantId(), azureTestConfiguration.getSubscriptionId(), azureTestConfiguration.getManagedResourceGroupId());
workspaceService.createAzureCloudContext(request.getWorkspaceId(), jobId, userRequest, "/fake/value", azureCloudContext);
jobService.waitForJob(jobId);
assertNull(jobService.retrieveJobResult(jobId, Object.class, userRequest).getException());
assertTrue(testUtils.getAuthorizedAzureCloudContext(request.getWorkspaceId(), userRequest).isPresent());
workspaceService.deleteAzureCloudContext(request.getWorkspaceId(), userRequest);
assertTrue(testUtils.getAuthorizedAzureCloudContext(request.getWorkspaceId(), userRequest).isEmpty());
}
use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.
the class ValidateMRGStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
AzureCloudContext azureCloudContext = flightContext.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AzureCloudContext.class);
try {
ResourceManager resourceManager = crlService.getResourceManager(azureCloudContext, azureConfig);
resourceManager.resourceGroups().getByName(azureCloudContext.getAzureResourceGroupId());
} catch (Exception azureError) {
throw new CloudContextRequiredException("Invalid Azure cloud context", azureError);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.workspace.model.AzureCloudContext 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 bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.
the class GetAzureIpStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
ComputeManager computeManager = crlService.getComputeManager(azureCloudContext, azureConfig);
try {
computeManager.networkManager().publicIpAddresses().getByResourceGroup(azureCloudContext.getAzureResourceGroupId(), resource.getIpName());
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new DuplicateResourceException(String.format("An Azure IP with name %s already exists in resource group %s", azureCloudContext.getAzureResourceGroupId(), resource.getIpName())));
} catch (ManagementException e) {
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/common-deployment-errors
if (StringUtils.equals(e.getValue().getCode(), "ResourceNotFound")) {
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
}
use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.
the class CreateAzureNetworkStep method undoStep.
@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
ComputeManager computeManager = crlService.getComputeManager(azureCloudContext, azureConfig);
try {
computeManager.networkManager().networks().deleteByResourceGroup(azureCloudContext.getAzureResourceGroupId(), resource.getNetworkName());
} catch (ManagementException e) {
// Stairway steps may run multiple times, so we may already have deleted this resource.
if (StringUtils.equals(e.getValue().getCode(), "ResourceNotFound")) {
logger.info("Azure Network {} in managed resource group {} already deleted", resource.getNetworkName(), azureCloudContext.getAzureResourceGroupId());
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
Aggregations