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