Search in sources :

Example 1 with ApiAzureContext

use of bio.terra.workspace.generated.model.ApiAzureContext in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method buildWorkspaceDescription.

private ApiWorkspaceDescription buildWorkspaceDescription(Workspace workspace) {
    ApiGcpContext gcpContext = gcpCloudContextService.getGcpCloudContext(workspace.getWorkspaceId()).map(GcpCloudContext::toApi).orElse(null);
    ApiAzureContext azureContext = azureCloudContextService.getAzureCloudContext(workspace.getWorkspaceId()).map(AzureCloudContext::toApi).orElse(null);
    // Convert the property map to API format
    ApiProperties apiProperties = new ApiProperties();
    workspace.getProperties().forEach((k, v) -> apiProperties.add(new ApiProperty().key(k).value(v)));
    // When we have another cloud context, we will need to do a similar retrieval for it.
    return new ApiWorkspaceDescription().id(workspace.getWorkspaceId()).spendProfile(workspace.getSpendProfileId().map(SpendProfileId::getId).orElse(null)).stage(workspace.getWorkspaceStage().toApiModel()).gcpContext(gcpContext).azureContext(azureContext).displayName(workspace.getDisplayName().orElse(null)).description(workspace.getDescription().orElse(null)).properties(apiProperties);
}
Also used : ApiProperty(bio.terra.workspace.generated.model.ApiProperty) ApiProperties(bio.terra.workspace.generated.model.ApiProperties) ApiGcpContext(bio.terra.workspace.generated.model.ApiGcpContext) ApiWorkspaceDescription(bio.terra.workspace.generated.model.ApiWorkspaceDescription) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) ApiAzureContext(bio.terra.workspace.generated.model.ApiAzureContext)

Example 2 with ApiAzureContext

use of bio.terra.workspace.generated.model.ApiAzureContext in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method fetchCreateCloudContextResult.

private ApiCreateCloudContextResult fetchCreateCloudContextResult(String jobId, AuthenticatedUserRequest userRequest) {
    final AsyncJobResult<CloudContextHolder> jobResult = jobService.retrieveAsyncJobResult(jobId, CloudContextHolder.class, userRequest);
    ApiGcpContext gcpContext = null;
    ApiAzureContext azureContext = null;
    if (jobResult.getJobReport().getStatus().equals(StatusEnum.SUCCEEDED)) {
        gcpContext = Optional.ofNullable(jobResult.getResult().getGcpCloudContext()).map(c -> new ApiGcpContext().projectId(c.getGcpProjectId())).orElse(null);
        azureContext = Optional.ofNullable(jobResult.getResult().getAzureCloudContext()).map(c -> new ApiAzureContext().tenantId(c.getAzureTenantId()).subscriptionId(c.getAzureSubscriptionId()).resourceGroupId(c.getAzureResourceGroupId())).orElse(null);
    }
    return new ApiCreateCloudContextResult().jobReport(jobResult.getJobReport()).errorReport(jobResult.getApiErrorReport()).gcpContext(gcpContext).azureContext(azureContext);
}
Also used : ApiCreateCloudContextResult(bio.terra.workspace.generated.model.ApiCreateCloudContextResult) ApiGcpContext(bio.terra.workspace.generated.model.ApiGcpContext) CloudContextHolder(bio.terra.workspace.service.workspace.model.CloudContextHolder) ApiAzureContext(bio.terra.workspace.generated.model.ApiAzureContext)

Example 3 with ApiAzureContext

use of bio.terra.workspace.generated.model.ApiAzureContext in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method createCloudContext.

@Override
public ResponseEntity<ApiCreateCloudContextResult> createCloudContext(UUID id, @Valid ApiCreateCloudContextRequest body) {
    ControllerValidationUtils.validateCloudPlatform(body.getCloudPlatform());
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    String jobId = body.getJobControl().getId();
    String resultPath = getAsyncResultEndpoint(jobId);
    if (body.getCloudPlatform() == ApiCloudPlatform.AZURE) {
        ApiAzureContext azureContext = Optional.ofNullable(body.getAzureContext()).orElseThrow(() -> new CloudContextRequiredException("AzureContext is required when creating an azure cloud context for a workspace"));
        workspaceService.createAzureCloudContext(id, jobId, userRequest, resultPath, AzureCloudContext.fromApi(azureContext));
    } else {
        workspaceService.createGcpCloudContext(id, jobId, userRequest, resultPath);
    }
    ApiCreateCloudContextResult response = fetchCreateCloudContextResult(jobId, userRequest);
    return new ResponseEntity<>(response, getAsyncResponseCode(response.getJobReport()));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiCreateCloudContextResult(bio.terra.workspace.generated.model.ApiCreateCloudContextResult) CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureContext(bio.terra.workspace.generated.model.ApiAzureContext)

Aggregations

ApiAzureContext (bio.terra.workspace.generated.model.ApiAzureContext)3 ApiCreateCloudContextResult (bio.terra.workspace.generated.model.ApiCreateCloudContextResult)2 ApiGcpContext (bio.terra.workspace.generated.model.ApiGcpContext)2 ApiProperties (bio.terra.workspace.generated.model.ApiProperties)1 ApiProperty (bio.terra.workspace.generated.model.ApiProperty)1 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)1 CloudContextRequiredException (bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)1 CloudContextHolder (bio.terra.workspace.service.workspace.model.CloudContextHolder)1 ResponseEntity (org.springframework.http.ResponseEntity)1