Search in sources :

Example 1 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class EnumerateResources method doSetup.

@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
    // initialize workspace
    super.doSetup(testUsers, workspaceApi);
    assertThat("There must be two test users defined for this test.", testUsers != null && testUsers.size() == 2);
    TestUserSpecification workspaceOwner = testUsers.get(0);
    workspaceReader = testUsers.get(1);
    // static assumptions
    assertThat(PAGE_SIZE * 2, lessThan(RESOURCE_COUNT));
    assertThat(PAGE_SIZE * 3, greaterThan(RESOURCE_COUNT));
    ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
    ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
    ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
    ownerResourceApi = new ResourceApi(ownerApiClient);
    ApiClient readerApiClient = ClientTestUtils.getClientForTestUser(workspaceReader, server);
    readerResourceApi = new ResourceApi(readerApiClient);
    // Create a cloud context for the workspace
    CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
    // create the resources for the test
    logger.info("Creating {} resources", RESOURCE_COUNT);
    resourceList = MultiResourcesUtils.makeResources(ownerReferencedGcpResourceApi, ownerControlledGcpResourceApi, getWorkspaceId());
    logger.info("Created {} resources", resourceList.size());
}
Also used : ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) TestUserSpecification(bio.terra.testrunner.runner.config.TestUserSpecification) ApiClient(bio.terra.workspace.client.ApiClient)

Example 2 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class ReferencedDataRepoSnapshotLifecycle method testUpdateReference.

private void testUpdateReference(ReferencedGcpResourceApi ownerApi) throws Exception {
    ReferencedGcpResourceApi partialAccessApi = ClientTestUtils.getReferencedGcpResourceClient(partialAccessUser, server);
    ResourceApi partialAccessResourceApi = ClientTestUtils.getResourceClient(partialAccessUser, server);
    // Update snapshot's name and description
    String newSnapshotReferenceName = "newSnapshotReferenceName";
    String newSnapshotReferenceDescription = "a new description of another snapshot reference";
    updateDataRepoSnapshotReferenceResource(ownerApi, getWorkspaceId(), snapshotResourceId, newSnapshotReferenceName, newSnapshotReferenceDescription, /*instanceId=*/
    null, /*snapshot=*/
    null);
    DataRepoSnapshotResource snapshotResource = ownerApi.getDataRepoSnapshotReference(getWorkspaceId(), snapshotResourceId);
    assertEquals(newSnapshotReferenceName, snapshotResource.getMetadata().getName());
    assertEquals(newSnapshotReferenceDescription, snapshotResource.getMetadata().getDescription());
    assertFalse(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), snapshotResourceId));
    assertThrows(ApiException.class, () -> updateDataRepoSnapshotReferenceResource(partialAccessApi, getWorkspaceId(), snapshotResourceId, newSnapshotReferenceName, newSnapshotReferenceDescription, /*instanceId=*/
    null, snapshotId2));
    updateDataRepoSnapshotReferenceResource(ownerApi, getWorkspaceId(), snapshotResourceId, newSnapshotReferenceName, newSnapshotReferenceDescription, /*instanceId=*/
    null, snapshotId2);
    DataRepoSnapshotResource snapshotResourceSecondUpdate = ownerApi.getDataRepoSnapshotReference(getWorkspaceId(), snapshotResourceId);
    assertEquals(newSnapshotReferenceName, snapshotResourceSecondUpdate.getMetadata().getName());
    assertEquals(newSnapshotReferenceDescription, snapshotResourceSecondUpdate.getMetadata().getDescription());
    assertEquals(snapshotId2, snapshotResourceSecondUpdate.getAttributes().getSnapshot());
    assertEquals(tdrInstance, snapshotResourceSecondUpdate.getAttributes().getInstanceName());
    assertTrue(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), snapshotResourceId));
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) DataRepoSnapshotResource(bio.terra.workspace.model.DataRepoSnapshotResource)

Example 3 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class ReferencedDataRepoSnapshotLifecycle method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    ReferencedGcpResourceApi referencedGcpResourceApi = ClientTestUtils.getReferencedGcpResourceClient(testUser, server);
    // Add the "partial access" user as a workspace reader. This does not give them access to any
    // underlying referenced resources.
    workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(partialAccessUser.userEmail), getWorkspaceId(), IamRole.READER);
    // Create the reference
    DataRepoSnapshotResource snapshotResource = DataRepoUtils.makeDataRepoSnapshotReference(referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), snapshotId, tdrInstance);
    snapshotResourceId = snapshotResource.getMetadata().getResourceId();
    // Get the reference
    ResourceApi resourceApi = ClientTestUtils.getResourceClient(testUser, server);
    testGetReference(snapshotResource, referencedGcpResourceApi, resourceApi);
    // Create a second workspace to clone the reference into, owned by the same user
    testCloneReference(snapshotResource, referencedGcpResourceApi, workspaceApi);
    // Validate snapshot access
    testValidateReference(testUser);
    // Update reference
    testUpdateReference(referencedGcpResourceApi);
    // Delete the reference
    referencedGcpResourceApi.deleteDataRepoSnapshotReference(getWorkspaceId(), snapshotResourceId);
    // Enumerating all resources with no filters should be empty
    ResourceList enumerateResult = resourceApi.enumerateResources(getWorkspaceId(), 0, 100, null, null);
    assertTrue(enumerateResult.getResources().isEmpty());
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ResourceList(bio.terra.workspace.model.ResourceList) GrantRoleRequestBody(bio.terra.workspace.model.GrantRoleRequestBody) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) DataRepoSnapshotResource(bio.terra.workspace.model.DataRepoSnapshotResource)

Example 4 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class EnumerateJobs method doSetup.

@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
    // initialize workspace
    super.doSetup(testUsers, workspaceApi);
    TestUserSpecification workspaceOwner = testUsers.get(0);
    // If we like the alpha1 API for job enumeration, then we can maybe piggyback on
    // the EnumerateResources test instead of creating our own set.
    ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
    ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
    ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
    alpha1Api = new Alpha1Api(ownerApiClient);
    // Create a cloud context for the workspace
    CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
    // create the resources for the test
    logger.info("Creating {} resources", RESOURCE_COUNT);
    resourceList = MultiResourcesUtils.makeResources(ownerReferencedGcpResourceApi, ownerControlledGcpResourceApi, getWorkspaceId());
    logger.info("Created {} resources", resourceList.size());
    logger.info("Cleaning up {} resources", resourceList.size());
    MultiResourcesUtils.cleanupResources(resourceList, ownerControlledGcpResourceApi, getWorkspaceId());
    logger.info("Cleaned up {} resources", resourceList.size());
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) Alpha1Api(bio.terra.workspace.api.Alpha1Api) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) TestUserSpecification(bio.terra.testrunner.runner.config.TestUserSpecification) ApiClient(bio.terra.workspace.client.ApiClient)

Example 5 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class DeleteGcpContextWithControlledResource method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    ControlledGcpResourceApi controlledResourceApi = ClientTestUtils.getControlledGcpResourceClient(testUser, server);
    ReferencedGcpResourceApi referencedResourceApi = ClientTestUtils.getReferencedGcpResourceClient(testUser, server);
    // Create a cloud context
    String projectId = CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
    logger.info("Created project {}", projectId);
    // Create a controlled BigQuery dataset
    GcpBigQueryDatasetResource controlledDataset = BqDatasetUtils.makeControlledBigQueryDatasetUserShared(controlledResourceApi, getWorkspaceId(), DATASET_RESOURCE_NAME, null, null);
    UUID controlledResourceId = controlledDataset.getMetadata().getResourceId();
    logger.info("Created controlled dataset {}", controlledResourceId);
    // Confirm the dataset was created in WSM
    GcpBigQueryDatasetResource fetchedControlledDataset = controlledResourceApi.getBigQueryDataset(getWorkspaceId(), controlledResourceId);
    assertEquals(controlledDataset, fetchedControlledDataset);
    // Create a reference to the controlled resource we just created
    String referenceName = "my-resource-name-" + UUID.randomUUID().toString();
    GcpBigQueryDatasetResource referencedDataset = BqDatasetUtils.makeBigQueryDatasetReference(controlledDataset.getAttributes(), referencedResourceApi, getWorkspaceId(), referenceName);
    // Confirm the reference was created in WSM
    GcpBigQueryDatasetResource fetchedDatasetReference = referencedResourceApi.getBigQueryDatasetReference(getWorkspaceId(), referencedDataset.getMetadata().getResourceId());
    assertEquals(referencedDataset, fetchedDatasetReference);
    // Delete the context, which should delete the controlled resource but not the reference.
    CloudContextMaker.deleteGcpCloudContext(getWorkspaceId(), workspaceApi);
    // Confirm the controlled resource was deleted.
    var noGcpContextException = assertThrows(ApiException.class, () -> controlledResourceApi.getBigQueryDataset(getWorkspaceId(), controlledResourceId));
    assertEquals(HttpStatus.SC_NOT_FOUND, noGcpContextException.getCode());
    // Confirm the referenced resource was not deleted (even though the underlying cloud resource
    // was).
    GcpBigQueryDatasetResource datasetReferenceAfterDelete = referencedResourceApi.getBigQueryDatasetReference(getWorkspaceId(), referencedDataset.getMetadata().getResourceId());
    assertEquals(referencedDataset, datasetReferenceAfterDelete);
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) UUID(java.util.UUID) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource)

Aggregations

ReferencedGcpResourceApi (bio.terra.workspace.api.ReferencedGcpResourceApi)18 ResourceApi (bio.terra.workspace.api.ResourceApi)10 ResourceList (bio.terra.workspace.model.ResourceList)6 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)4 GcpBigQueryDatasetResource (bio.terra.workspace.model.GcpBigQueryDatasetResource)4 GrantRoleRequestBody (bio.terra.workspace.model.GrantRoleRequestBody)4 TestUserSpecification (bio.terra.testrunner.runner.config.TestUserSpecification)3 GcpBigQueryDataTableResource (bio.terra.workspace.model.GcpBigQueryDataTableResource)3 GcpGcsBucketResource (bio.terra.workspace.model.GcpGcsBucketResource)3 GcpGcsObjectResource (bio.terra.workspace.model.GcpGcsObjectResource)3 ApiClient (bio.terra.workspace.client.ApiClient)2 DataRepoSnapshotResource (bio.terra.workspace.model.DataRepoSnapshotResource)2 UUID (java.util.UUID)2 Alpha1Api (bio.terra.workspace.api.Alpha1Api)1 GcpBigQueryDataTableAttributes (bio.terra.workspace.model.GcpBigQueryDataTableAttributes)1 GcpGcsObjectAttributes (bio.terra.workspace.model.GcpGcsObjectAttributes)1 GitRepoResource (bio.terra.workspace.model.GitRepoResource)1 UpdateBigQueryDataTableReferenceRequestBody (bio.terra.workspace.model.UpdateBigQueryDataTableReferenceRequestBody)1 UpdateBigQueryDatasetReferenceRequestBody (bio.terra.workspace.model.UpdateBigQueryDatasetReferenceRequestBody)1 UpdateGcsBucketObjectReferenceRequestBody (bio.terra.workspace.model.UpdateGcsBucketObjectReferenceRequestBody)1