Search in sources :

Example 1 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method testWithSpendProfile.

@Test
void testWithSpendProfile() {
    SpendProfileId spendProfileId = new SpendProfileId("foo");
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).spendProfileId(spendProfileId).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    Workspace createdWorkspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    assertEquals(request.getWorkspaceId(), createdWorkspace.getWorkspaceId());
    assertEquals(spendProfileId, createdWorkspace.getSpendProfileId().orElse(null));
}
Also used : SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 2 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId 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 3 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class WorkspaceDao method createWorkspace.

/**
 * Persists a workspace to DB. Returns ID of persisted workspace on success.
 *
 * @param workspace all properties of the workspace to create
 * @return workspace id
 */
@WriteTransaction
public UUID createWorkspace(Workspace workspace) {
    final String sql = "INSERT INTO workspace (workspace_id, display_name, description, spend_profile, properties, workspace_stage) " + "values (:workspace_id, :display_name, :description, :spend_profile," + " cast(:properties AS jsonb), :workspace_stage)";
    final String workspaceId = workspace.getWorkspaceId().toString();
    MapSqlParameterSource params = new MapSqlParameterSource().addValue("workspace_id", workspaceId).addValue("display_name", workspace.getDisplayName().orElse(null)).addValue("description", workspace.getDescription().orElse(null)).addValue("spend_profile", workspace.getSpendProfileId().map(SpendProfileId::getId).orElse(null)).addValue("properties", DbSerDes.propertiesToJson(workspace.getProperties())).addValue("workspace_stage", workspace.getWorkspaceStage().toString());
    try {
        jdbcTemplate.update(sql, params);
        logger.info("Inserted record for workspace {}", workspaceId);
    } catch (DuplicateKeyException e) {
        throw new DuplicateWorkspaceException(String.format("Workspace with id %s already exists - display name %s stage %s", workspaceId, workspace.getDisplayName().toString(), workspace.getWorkspaceStage().toString()), e);
    }
    return workspace.getWorkspaceId();
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DuplicateWorkspaceException(bio.terra.workspace.service.workspace.exceptions.DuplicateWorkspaceException) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) WriteTransaction(bio.terra.common.db.WriteTransaction)

Example 4 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class CheckSpendProfileStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    FlightMap workingMap = context.getWorkingMap();
    Workspace workspace = workspaceDao.getWorkspace(workspaceId);
    SpendProfileId spendProfileId = workspace.getSpendProfileId().orElseThrow(() -> MissingSpendProfileException.forWorkspace(workspaceId));
    SpendProfile spendProfile = spendProfileService.authorizeLinking(spendProfileId, userRequest);
    if (spendProfile.billingAccountId().isEmpty()) {
        throw NoBillingAccountException.forSpendProfile(spendProfileId);
    }
    workingMap.put(BILLING_ACCOUNT_ID, spendProfile.billingAccountId());
    return StepResult.getStepResultSuccess();
}
Also used : FlightMap(bio.terra.stairway.FlightMap) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) Workspace(bio.terra.workspace.service.workspace.model.Workspace) SpendProfile(bio.terra.workspace.service.spendprofile.SpendProfile)

Example 5 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class WorkspaceDaoTest method setup.

@BeforeEach
void setup() {
    workspaceId = UUID.randomUUID();
    spendProfileId = new SpendProfileId("foo");
}
Also used : SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)8 Workspace (bio.terra.workspace.service.workspace.model.Workspace)5 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)2 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)2 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 ResponseEntity (org.springframework.http.ResponseEntity)2 WriteTransaction (bio.terra.common.db.WriteTransaction)1 FlightMap (bio.terra.stairway.FlightMap)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiAzureContext (bio.terra.workspace.generated.model.ApiAzureContext)1 ApiCloneWorkspaceResult (bio.terra.workspace.generated.model.ApiCloneWorkspaceResult)1 ApiGcpContext (bio.terra.workspace.generated.model.ApiGcpContext)1 ApiProperties (bio.terra.workspace.generated.model.ApiProperties)1 ApiProperty (bio.terra.workspace.generated.model.ApiProperty)1 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)1 ApiWorkspaceStageModel (bio.terra.workspace.generated.model.ApiWorkspaceStageModel)1 SpendProfile (bio.terra.workspace.service.spendprofile.SpendProfile)1