Search in sources :

Example 51 with Workspace

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

the class SamServiceTest method createWorkspaceForUser.

private UUID createWorkspaceForUser(AuthenticatedUserRequest userRequest) {
    UUID uuid = UUID.randomUUID();
    Workspace request = Workspace.builder().workspaceId(uuid).userFacingId("a" + uuid.toString()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    return workspaceService.createWorkspace(request, userRequest);
}
Also used : UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 52 with Workspace

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

the class ControlledResourceServiceTest method createDefaultPrivateAiNotebookInstance.

/**
 * Create a controlled AI Notebook instance with default private settings.
 */
private ControlledAiNotebookInstanceResource createDefaultPrivateAiNotebookInstance(String instanceId, UserAccessUtils.TestUser user) {
    Workspace workspace = reusableWorkspace(user);
    ApiGcpAiNotebookInstanceCreationParameters creationParameters = ControlledResourceFixtures.defaultNotebookCreationParameters().instanceId(instanceId).location(DEFAULT_NOTEBOOK_LOCATION);
    ControlledAiNotebookInstanceResource resource = makeNotebookTestResource(workspace.getWorkspaceId(), instanceId, instanceId);
    String createJobId = controlledResourceService.createAiNotebookInstance(resource, creationParameters, DEFAULT_ROLE, new ApiJobControl().id(UUID.randomUUID().toString()), null, user.getAuthenticatedRequest());
    jobService.waitForJob(createJobId);
    JobService.JobResultOrException<ControlledAiNotebookInstanceResource> creationResult = jobService.retrieveJobResult(createJobId, ControlledAiNotebookInstanceResource.class, user.getAuthenticatedRequest());
    assertNull(creationResult.getException(), "Error creating controlled AI notebook instance");
    assertNotNull(creationResult.getResult(), "Unexpected null created controlled AI notebook instance");
    return creationResult.getResult();
}
Also used : JobService(bio.terra.workspace.service.job.JobService) Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 53 with Workspace

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

the class AzureDisabledTest method azureDisabledTest.

@Test
public void azureDisabledTest() throws InterruptedException {
    Workspace request = Workspace.builder().workspaceId(UUID.randomUUID()).userFacingId("a" + UUID.randomUUID()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    UUID workspaceUuid = workspaceService.createWorkspace(request, userAccessUtils.defaultUserAuthRequest());
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    final UUID uuid = UUID.randomUUID();
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.createAzureCloudContext(workspaceUuid, uuid.toString(), userRequest, null, null));
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.getAuthorizedAzureCloudContext(workspaceUuid, userRequest));
    final ApiAzureIpCreationParameters ipCreationParameters = ControlledResourceFixtures.getAzureIpCreationParameters();
    ControlledResourceFields commonFields = ControlledResourceFixtures.makeDefaultControlledResourceFields(workspaceUuid);
    ControlledAzureIpResource ipResource = ControlledAzureIpResource.builder().common(commonFields).ipName(ipCreationParameters.getName()).region(ipCreationParameters.getRegion()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(ipResource, null, userRequest, ipCreationParameters));
    final ApiAzureDiskCreationParameters diskCreationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
    ControlledAzureDiskResource diskResource = ControlledAzureDiskResource.builder().common(commonFields).diskName(diskCreationParameters.getName()).region(diskCreationParameters.getRegion()).size(diskCreationParameters.getSize()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(diskResource, null, userRequest, diskCreationParameters));
    final ApiAzureNetworkCreationParameters networkCreationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    ControlledAzureNetworkResource networkResource = ControlledAzureNetworkResource.builder().common(commonFields).networkName(networkCreationParameters.getName()).region(networkCreationParameters.getRegion()).subnetName(networkCreationParameters.getSubnetName()).addressSpaceCidr(networkCreationParameters.getAddressSpaceCidr()).subnetAddressCidr(networkCreationParameters.getSubnetAddressCidr()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(networkResource, null, userRequest, networkCreationParameters));
    final ApiAzureVmCreationParameters vmCreationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    ControlledAzureVmResource vmResource = ControlledAzureVmResource.builder().common(commonFields).vmName(vmCreationParameters.getName()).vmSize(vmCreationParameters.getVmSize()).vmImage(AzureVmUtils.getImageData(vmCreationParameters.getVmImage())).region(vmCreationParameters.getRegion()).ipId(ipResource.getResourceId()).diskId(diskResource.getResourceId()).networkId(networkResource.getResourceId()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createAzureVm(vmResource, vmCreationParameters, null, null, null, userRequest));
}
Also used : ApiAzureIpCreationParameters(bio.terra.workspace.generated.model.ApiAzureIpCreationParameters) ControlledAzureIpResource(bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource) ControlledAzureVmResource(bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource) ControlledAzureDiskResource(bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) UUID(java.util.UUID) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) ApiAzureDiskCreationParameters(bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test)

Example 54 with Workspace

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

the class StoreControlledResourceMetadataStepTest method testEntersInfo.

@Test
public void testEntersInfo() throws InterruptedException, RetryException {
    // Generate a fake workspace and cloud context so that the
    // database insert will pass FK constraints.
    UUID workspaceUuid = UUID.randomUUID();
    Workspace workspace = Workspace.builder().workspaceStage(WorkspaceStage.RAWLS_WORKSPACE).workspaceId(workspaceUuid).userFacingId("a" + workspaceUuid).build();
    workspaceDao.createWorkspace(workspace);
    gcpCloudContextService.createGcpCloudContextStart(workspaceUuid, "flight-testentersinfo");
    gcpCloudContextService.createGcpCloudContextFinish(workspaceUuid, new GcpCloudContext("fake-project"), "flight-testentersinfo");
    StoreMetadataStep storeGoogleBucketMetadataStep = new StoreMetadataStep(resourceDao);
    // Stub the flight map as of this step
    ControlledGcsBucketResource bucketResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceUuid).build();
    final FlightMap inputFlightMap = new FlightMap();
    inputFlightMap.put(ResourceKeys.RESOURCE, bucketResource);
    inputFlightMap.makeImmutable();
    doReturn(inputFlightMap).when(mockFlightContext).getInputParameters();
    final StepResult result = storeGoogleBucketMetadataStep.doStep(mockFlightContext);
    assertThat(result, equalTo(StepResult.getStepResultSuccess()));
    WsmResource daoResource = resourceDao.getResource(bucketResource.getWorkspaceId(), bucketResource.getResourceId());
    assertThat(daoResource.getResourceType(), equalTo(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET));
    ControlledGcsBucketResource daoBucket = (ControlledGcsBucketResource) daoResource;
    assertThat(bucketResource, equalTo(daoBucket));
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) StoreMetadataStep(bio.terra.workspace.service.resource.controlled.flight.create.StoreMetadataStep) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 55 with Workspace

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

the class ReferencedResourceServiceTest method createMcTestWorkspace.

/**
 * Test utility which creates a workspace with a random ID, no spend profile, and stage
 * MC_WORKSPACE. Returns the generated workspace ID.
 */
private UUID createMcTestWorkspace() {
    UUID uuid = UUID.randomUUID();
    Workspace request = Workspace.builder().workspaceId(uuid).userFacingId("a" + uuid.toString()).spendProfileId(null).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    return workspaceService.createWorkspace(request, USER_REQUEST);
}
Also used : 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