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