Search in sources :

Example 1 with DataRepoSnapshotResource

use of bio.terra.workspace.model.DataRepoSnapshotResource 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 2 with DataRepoSnapshotResource

use of bio.terra.workspace.model.DataRepoSnapshotResource 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 3 with DataRepoSnapshotResource

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

the class ReferencedDataRepoSnapshotLifecycle method testGetReference.

private void testGetReference(DataRepoSnapshotResource snapshotResource, ReferencedGcpResourceApi referencedGcpResourceApi, ResourceApi resourceApi) throws Exception {
    // Read the reference
    DataRepoSnapshotResource fetchedSnapshot = referencedGcpResourceApi.getDataRepoSnapshotReference(getWorkspaceId(), snapshotResourceId);
    assertEquals(snapshotResource, fetchedSnapshot);
    // Enumerate the reference
    ResourceList referenceList = resourceApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    null, /*stewardShipType=*/
    null);
    assertEquals(1, referenceList.getResources().size());
    assertEquals(StewardshipType.REFERENCED, referenceList.getResources().get(0).getMetadata().getStewardshipType());
    assertEquals(ResourceType.DATA_REPO_SNAPSHOT, referenceList.getResources().get(0).getMetadata().getResourceType());
}
Also used : ResourceList(bio.terra.workspace.model.ResourceList) DataRepoSnapshotResource(bio.terra.workspace.model.DataRepoSnapshotResource)

Aggregations

DataRepoSnapshotResource (bio.terra.workspace.model.DataRepoSnapshotResource)3 ReferencedGcpResourceApi (bio.terra.workspace.api.ReferencedGcpResourceApi)2 ResourceApi (bio.terra.workspace.api.ResourceApi)2 ResourceList (bio.terra.workspace.model.ResourceList)2 GrantRoleRequestBody (bio.terra.workspace.model.GrantRoleRequestBody)1