Search in sources :

Example 26 with AzureCloudContext

use of bio.terra.workspace.service.workspace.model.AzureCloudContext 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();
}
Also used : ManagementException(com.azure.core.management.exception.ManagementException) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) StorageManager(com.azure.resourcemanager.storage.StorageManager) StepResult(bio.terra.stairway.StepResult)

Example 27 with AzureCloudContext

use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.

the class CreateAzureContextFlightTest method successCreatesContext.

@Test
void successCreatesContext() throws Exception {
    UUID workspaceId = azureTestUtils.createWorkspace(workspaceService);
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    // There should be no cloud context initially.
    assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isEmpty());
    String jobId = UUID.randomUUID().toString();
    workspaceService.createAzureCloudContext(workspaceId, jobId, userRequest, /* resultPath */
    null, azureTestUtils.getAzureCloudContext());
    // Wait for the job to complete
    FlightState flightState = StairwayTestUtils.pollUntilComplete(jobId, jobService.getStairway(), Duration.ofSeconds(30), STAIRWAY_FLIGHT_TIMEOUT);
    assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
    // Flight should have created a cloud context.
    assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isPresent());
    AzureCloudContext azureCloudContext = workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).get();
    assertEquals(azureCloudContext, azureTestUtils.getAzureCloudContext());
}
Also used : FlightState(bio.terra.stairway.FlightState) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 28 with AzureCloudContext

use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.

the class AzureTestUtils method createAzureContextInputParameters.

/**
 * Create the FlightMap input parameters required for the {@link CreateAzureContextFlight}.
 */
public FlightMap createAzureContextInputParameters(UUID workspaceId, AuthenticatedUserRequest userRequest) {
    AzureCloudContext azureCloudContext = getAzureCloudContext();
    FlightMap inputs = new FlightMap();
    inputs.put(JobMapKeys.REQUEST.getKeyName(), azureCloudContext);
    inputs.put(WorkspaceFlightMapKeys.WORKSPACE_ID, workspaceId.toString());
    inputs.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
    return inputs;
}
Also used : AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightMap(bio.terra.stairway.FlightMap)

Example 29 with AzureCloudContext

use of bio.terra.workspace.service.workspace.model.AzureCloudContext in project terra-workspace-manager by DataBiosphere.

the class CreateDbAzureCloudContextFinishStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
    AzureCloudContext azureCloudContext = flightContext.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AzureCloudContext.class);
    // Create the cloud context; throws if the context already exists.
    azureCloudContextService.createAzureCloudContextFinish(workspaceId, azureCloudContext, flightContext.getFlightId());
    CloudContextHolder cch = new CloudContextHolder();
    cch.setAzureCloudContext(azureCloudContext);
    FlightUtils.setResponse(flightContext, cch, HttpStatus.OK);
    return StepResult.getStepResultSuccess();
}
Also used : AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) CloudContextHolder(bio.terra.workspace.service.workspace.model.CloudContextHolder)

Aggregations

AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)29 StepResult (bio.terra.stairway.StepResult)23 ManagementException (com.azure.core.management.exception.ManagementException)17 ComputeManager (com.azure.resourcemanager.compute.ComputeManager)16 DuplicateResourceException (bio.terra.workspace.service.resource.exception.DuplicateResourceException)6 RelayManager (com.azure.resourcemanager.relay.RelayManager)4 StorageManager (com.azure.resourcemanager.storage.StorageManager)3 BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)2 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 Test (org.junit.jupiter.api.Test)2 FlightMap (bio.terra.stairway.FlightMap)1 FlightState (bio.terra.stairway.FlightState)1 InternalLogicException (bio.terra.workspace.common.exception.InternalLogicException)1 ControlledAzureDiskResource (bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource)1 ControlledAzureIpResource (bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource)1 ControlledAzureNetworkResource (bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)1 CloudContextRequiredException (bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)1 CloudContextHolder (bio.terra.workspace.service.workspace.model.CloudContextHolder)1 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)1 Workspace (bio.terra.workspace.service.workspace.model.Workspace)1