Search in sources :

Example 1 with ApiCreateCloudContextResult

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

the class WorkspaceApiController method getCreateCloudContextResult.

@Override
public ResponseEntity<ApiCreateCloudContextResult> getCreateCloudContextResult(UUID id, String jobId) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    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) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Example 2 with ApiCreateCloudContextResult

use of bio.terra.workspace.generated.model.ApiCreateCloudContextResult 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 ApiCreateCloudContextResult

use of bio.terra.workspace.generated.model.ApiCreateCloudContextResult 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

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