Search in sources :

Example 11 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceDaoTest method getWorkspacesFromList.

@Test
void getWorkspacesFromList() {
    Workspace realWorkspace = defaultWorkspace();
    workspaceDao.createWorkspace(realWorkspace);
    UUID fakeWorkspaceId = UUID.randomUUID();
    List<Workspace> workspaceList = workspaceDao.getWorkspacesMatchingList(ImmutableList.of(realWorkspace.getWorkspaceId(), fakeWorkspaceId), 0, 1);
    // The DAO should return all workspaces this user has access to, including realWorkspace but
    // not including the fake workspace id.
    assertThat(workspaceList, hasItem(equalTo(realWorkspace)));
    List<UUID> workspaceIdList = workspaceList.stream().map(Workspace::getWorkspaceId).collect(Collectors.toList());
    assertThat(workspaceIdList, not(hasItem(equalTo(fakeWorkspaceId))));
}
Also used : UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 12 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceDaoTest method listWorkspaceLimitEnforced.

@Test
void listWorkspaceLimitEnforced() {
    Workspace firstWorkspace = defaultWorkspace();
    workspaceDao.createWorkspace(firstWorkspace);
    UUID uuid = UUID.randomUUID();
    Workspace secondWorkspace = Workspace.builder().workspaceId(uuid).userFacingId("a" + uuid.toString()).workspaceStage(WorkspaceStage.RAWLS_WORKSPACE).build();
    workspaceDao.createWorkspace(secondWorkspace);
    List<Workspace> workspaceList = workspaceDao.getWorkspacesMatchingList(ImmutableList.of(firstWorkspace.getWorkspaceId(), secondWorkspace.getWorkspaceId()), 0, 1);
    assertThat(workspaceList.size(), equalTo(1));
    assertThat(workspaceList.get(0), in(ImmutableList.of(firstWorkspace, secondWorkspace)));
}
Also used : UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 13 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace 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(workspaceUuid);
    SpendProfileId spendProfileId = workspace.getSpendProfileId().orElseThrow(() -> MissingSpendProfileException.forWorkspace(workspaceUuid));
    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 14 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class AzureTestUtils method createWorkspace.

/**
 * Creates a workspace, returning its workspaceUuid.
 */
public UUID createWorkspace(WorkspaceService workspaceService) {
    UUID uuid = UUID.randomUUID();
    Workspace request = Workspace.builder().workspaceId(uuid).userFacingId("a" + uuid.toString()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    return workspaceService.createWorkspace(request, userAccessUtils.defaultUserAuthRequest());
}
Also used : UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 15 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class CreateWorkspaceStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws RetryException, InterruptedException {
    UUID workspaceUuid = workspace.getWorkspaceId();
    try {
        workspaceDao.createWorkspace(workspace);
    } catch (DuplicateWorkspaceException ex) {
        // This might be the result of a step re-running, or it might be an ID conflict. We can ignore
        // this if the existing workspace matches the one we were about to create, otherwise rethrow.
        Workspace existingWorkspace = workspaceDao.getWorkspace(workspaceUuid);
        if (!workspace.equals(existingWorkspace)) {
            throw ex;
        }
    }
    FlightUtils.setResponse(flightContext, workspaceUuid, HttpStatus.OK);
    logger.info("Workspace created with id {}", workspaceUuid);
    return StepResult.getStepResultSuccess();
}
Also used : DuplicateWorkspaceException(bio.terra.workspace.service.workspace.exceptions.DuplicateWorkspaceException) UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Aggregations

Workspace (bio.terra.workspace.service.workspace.model.Workspace)74 Test (org.junit.jupiter.api.Test)40 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)30 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)27 UUID (java.util.UUID)27 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)11 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 HashMap (java.util.HashMap)7 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)6 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)6 ResponseEntity (org.springframework.http.ResponseEntity)6 FlightMap (bio.terra.stairway.FlightMap)5 StepStatus (bio.terra.stairway.StepStatus)5 Traced (io.opencensus.contrib.spring.aop.Traced)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 ForbiddenException (bio.terra.common.exception.ForbiddenException)4 FlightState (bio.terra.stairway.FlightState)3 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)3 JobBuilder (bio.terra.workspace.service.job.JobBuilder)3