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();
}
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());
}
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;
}
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();
}
Aggregations