Search in sources :

Example 6 with Workspace

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

the class WorkspaceServiceTest method createMcWorkspaceUndoSteps.

@Test
void createMcWorkspaceUndoSteps() {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).build();
    // Retry undo steps once and fail at the end of the flight.
    Map<String, StepStatus> retrySteps = new HashMap<>();
    retrySteps.put(CreateWorkspaceAuthzStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(CreateWorkspaceStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().undoStepFailures(retrySteps).lastStepFailure(true).build();
    jobService.setFlightDebugInfoForTest(debugInfo);
    // Service methods which wait for a flight to complete will throw an
    // InvalidResultStateException when that flight fails without a cause, which occurs when a
    // flight fails via debugInfo.
    assertThrows(InvalidResultStateException.class, () -> workspaceService.createWorkspace(request, USER_REQUEST));
    assertThrows(WorkspaceNotFoundException.class, () -> workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST));
}
Also used : FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) HashMap(java.util.HashMap) CreateWorkspaceStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep) StepStatus(bio.terra.stairway.StepStatus) CreateWorkspaceAuthzStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceAuthzStep) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 7 with Workspace

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

the class WorkspaceServiceTest method createMcWorkspaceDoSteps.

@Test
void createMcWorkspaceDoSteps() {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).build();
    Map<String, StepStatus> retrySteps = new HashMap<>();
    retrySteps.put(CreateWorkspaceAuthzStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(CreateWorkspaceStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build();
    jobService.setFlightDebugInfoForTest(debugInfo);
    UUID createdId = workspaceService.createWorkspace(request, USER_REQUEST);
    assertEquals(createdId, request.getWorkspaceId());
}
Also used : FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) HashMap(java.util.HashMap) CreateWorkspaceStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep) StepStatus(bio.terra.stairway.StepStatus) UUID(java.util.UUID) CreateWorkspaceAuthzStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceAuthzStep) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 8 with Workspace

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

the class WorkspaceServiceTest method deleteWorkspaceWithGoogleContext.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void deleteWorkspaceWithGoogleContext() throws Exception {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).spendProfileId(spendUtils.defaultSpendId()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    String jobId = UUID.randomUUID().toString();
    workspaceService.createGcpCloudContext(request.getWorkspaceId(), jobId, USER_REQUEST, "/fake/value");
    jobService.waitForJob(jobId);
    assertNull(jobService.retrieveJobResult(jobId, Object.class, USER_REQUEST).getException());
    Workspace workspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    String projectId = workspaceService.getAuthorizedRequiredGcpProject(workspace.getWorkspaceId(), USER_REQUEST);
    // Verify project exists by retrieving it.
    crl.getCloudResourceManagerCow().projects().get(projectId).execute();
    workspaceService.deleteWorkspace(request.getWorkspaceId(), USER_REQUEST);
    // Check that project is now being deleted.
    Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
    assertEquals("DELETE_REQUESTED", project.getState());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 9 with Workspace

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

the class WorkspaceServiceTest method createRawlsWorkspaceDoSteps.

@Test
void createRawlsWorkspaceDoSteps() throws InterruptedException {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).workspaceStage(WorkspaceStage.RAWLS_WORKSPACE).build();
    // Ensure the auth check in CheckSamWorkspaceAuthzStep always succeeds.
    doReturn(true).when(mockSamService).isAuthorized(any(), any(), any(), any());
    Map<String, StepStatus> retrySteps = new HashMap<>();
    retrySteps.put(CheckSamWorkspaceAuthzStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(CreateWorkspaceStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build();
    jobService.setFlightDebugInfoForTest(debugInfo);
    UUID createdId = workspaceService.createWorkspace(request, USER_REQUEST);
    assertEquals(createdId, request.getWorkspaceId());
}
Also used : FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) HashMap(java.util.HashMap) CreateWorkspaceStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep) StepStatus(bio.terra.stairway.StepStatus) UUID(java.util.UUID) CheckSamWorkspaceAuthzStep(bio.terra.workspace.service.workspace.flight.CheckSamWorkspaceAuthzStep) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 10 with Workspace

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

the class WorkspaceServiceTest method duplicateWorkspaceIdRequestsRejected.

@Test
void duplicateWorkspaceIdRequestsRejected() {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    Workspace duplicateWorkspace = defaultRequestBuilder(request.getWorkspaceId()).description("slightly different workspace").build();
    assertThrows(DuplicateWorkspaceException.class, () -> workspaceService.createWorkspace(duplicateWorkspace, USER_REQUEST));
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Aggregations

Workspace (bio.terra.workspace.service.workspace.model.Workspace)56 Test (org.junit.jupiter.api.Test)32 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)23 UUID (java.util.UUID)13 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)9 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 HashMap (java.util.HashMap)6 FlightMap (bio.terra.stairway.FlightMap)5 StepStatus (bio.terra.stairway.StepStatus)5 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)5 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)5 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Traced (io.opencensus.contrib.spring.aop.Traced)4 FlightState (bio.terra.stairway.FlightState)3 ControlledBigQueryDatasetResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)3 CreateWorkspaceStep (bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3