From 1a592994759a5e0ba49221da70e8c59fb5860e22 Mon Sep 17 00:00:00 2001 From: Dexter Amundsen Date: Fri, 21 Jul 2023 09:46:08 -0700 Subject: [PATCH] GCP files (#1394) --- ...eApiControllerAiNotebookConnectedTest.java | 17 +- ...ceApiControllerBqDatasetConnectedTest.java | 189 ++-- ...ontrollerDataprocClusterConnectedTest.java | 25 +- ...ApiControllerGceInstanceConnectedTest.java | 17 +- ...ceApiControllerGcsBucketConnectedTest.java | 15 +- ...ontrolledGcpResourceApiControllerTest.java | 19 +- ...ceControllerBqDataTableConnectedTest.java} | 53 +- ...ourceControllerBqDatasetConnectedTest.java | 40 +- ...ourceControllerGcsBucketConnectedTest.java | 4 +- ...ourceControllerGcsObjectConnectedTest.java | 4 +- .../ReferencedGcpResourceControllerTest.java | 22 +- .../ReferencedResourceCloneConnectedTest.java | 4 +- .../ResourceApiControllerConnectedTest.java | 24 +- .../controller/TempGrantConnectedTest.java | 34 +- .../workspace/common/utils/MockGcpApi.java | 869 ++++++++++++++++ .../workspace/common/utils/MockMvcUtils.java | 950 +----------------- .../AnyResourceStateFailureTest.java | 34 +- .../GcpResourceStateFailureTest.java | 48 +- .../GcpCloudContextConnectedTest.java | 4 +- 19 files changed, 1219 insertions(+), 1153 deletions(-) rename service/src/test/java/bio/terra/workspace/app/controller/{ReferencedGcpResourceControllerBqTableConnectedTest.java => ReferencedGcpResourceControllerBqDataTableConnectedTest.java} (92%) create mode 100644 service/src/test/java/bio/terra/workspace/common/utils/MockGcpApi.java diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerAiNotebookConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerAiNotebookConnectedTest.java index 540f44baf8..be64757020 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerAiNotebookConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerAiNotebookConnectedTest.java @@ -7,6 +7,7 @@ import bio.terra.stairway.FlightDebugInfo; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.StairwayTestUtils; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.connected.UserAccessUtils; import bio.terra.workspace.generated.model.ApiAccessScope; @@ -44,6 +45,7 @@ public class ControlledGcpResourceApiControllerAiNotebookConnectedTest extends BaseConnectedTest { @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired UserAccessUtils userAccessUtils; @Autowired JobService jobService; @@ -84,7 +86,7 @@ public void createAiNotebookInstance_correctZone() throws Exception { .value("asia-east1"))); ApiGcpAiNotebookInstanceResource notebook = - mockMvcUtils + mockGcpApi .createAiNotebookInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null) .getAiNotebookInstance(); @@ -98,7 +100,7 @@ public void createAiNotebookInstance_correctZone() throws Exception { userAccessUtils.getDefaultUserEmail()); notebook = - mockMvcUtils + mockGcpApi .createAiNotebookInstance( userAccessUtils.defaultUserAuthRequest(), workspaceId, "europe-west1-b") .getAiNotebookInstance(); @@ -120,13 +122,14 @@ public void createAiNotebookInstance_correctZone() throws Exception { @Test public void createAiNotebookInstance_duplicateInstanceId() throws Exception { var duplicateName = "not-unique-name"; - mockMvcUtils - .createAiNotebookInstanceAndWait( - userAccessUtils.defaultUserAuthRequest(), workspaceId, duplicateName, null) - .getAiNotebookInstance(); + ApiGcpAiNotebookInstanceResource unused = + mockGcpApi + .createAiNotebookInstanceAndWait( + userAccessUtils.defaultUserAuthRequest(), workspaceId, duplicateName, null) + .getAiNotebookInstance(); ApiErrorReport errorReport = - mockMvcUtils + mockGcpApi .createAiNotebookInstanceAndExpect( userAccessUtils.defaultUserAuthRequest(), workspaceId, diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerBqDatasetConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerBqDatasetConnectedTest.java index dba740c9d7..25ef124908 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerBqDatasetConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerBqDatasetConnectedTest.java @@ -2,7 +2,7 @@ import static bio.terra.workspace.common.GcsBucketUtils.waitForProjectAccess; import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertApiBqDatasetEquals; import static bio.terra.workspace.common.utils.MockMvcUtils.assertControlledResourceMetadata; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; @@ -19,10 +19,12 @@ import bio.terra.workspace.common.GcpCloudUtils; import bio.terra.workspace.common.StairwayTestUtils; import bio.terra.workspace.common.fixtures.PolicyFixtures; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.connected.UserAccessUtils; import bio.terra.workspace.generated.model.ApiAccessScope; +import bio.terra.workspace.generated.model.ApiCloneControlledGcpBigQueryDatasetResult; import bio.terra.workspace.generated.model.ApiCloningInstructionsEnum; import bio.terra.workspace.generated.model.ApiCloudPlatform; import bio.terra.workspace.generated.model.ApiErrorReport; @@ -82,6 +84,7 @@ public class ControlledGcpResourceApiControllerBqDatasetConnectedTest extends Ba @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @Autowired UserAccessUtils userAccessUtils; @Autowired JobService jobService; @@ -150,7 +153,7 @@ public void setup() throws Exception { // It is easier to make two dataset and do clone both directions than to // get different permissions on users. sourceResource = - mockMvcUtils + mockGcpApi .createControlledBqDataset( defaultUserRequest, workspaceId, @@ -168,7 +171,7 @@ public void setup() throws Exception { sourceDatasetName); source2Resource = - mockMvcUtils + mockGcpApi .createControlledBqDataset( defaultUserRequest, workspaceId2, @@ -224,7 +227,7 @@ public void create() throws Exception { // Assert resource returned by get ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( + mockGcpApi.getControlledBqDataset( defaultUserRequest, workspaceId, sourceResource.getMetadata().getResourceId()); assertApiBqDatasetEquals(sourceResource, gotResource); @@ -252,7 +255,7 @@ public void update() throws Exception { userAccessUtils.secondUser().getAuthenticatedRequest(); ApiGcpBigQueryDatasetResource updatedResource = - mockMvcUtils.updateControlledBqDataset( + mockGcpApi.updateControlledBqDataset( writerUserRequest, workspaceId, sourceResource.getMetadata().getResourceId(), @@ -261,7 +264,7 @@ public void update() throws Exception { newCloningInstruction); ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( + mockGcpApi.getControlledBqDataset( ownerUserRequest, workspaceId, sourceResource.getMetadata().getResourceId()); assertEquals(updatedResource, gotResource); assertBqDataset( @@ -276,7 +279,7 @@ public void update() throws Exception { ownerUserRequest.getEmail(), writerUserRequest.getEmail()); - mockMvcUtils.updateControlledBqDataset( + mockGcpApi.updateControlledBqDataset( ownerUserRequest, workspaceId, sourceResource.getMetadata().getResourceId(), @@ -289,35 +292,30 @@ public void update() throws Exception { public void update_throws409() throws Exception { var oldName = sourceResource.getMetadata().getName(); var newName = TestUtils.appendRandomNumber("newdatatableresourcename"); + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); - mockMvcUtils.createReferencedBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - newName, - projectId, - sourceDatasetName); + mockGcpApi.createReferencedBqDataset( + userRequest, workspaceId, newName, projectId, sourceDatasetName); mockMvcUtils.updateResource( ApiGcpBigQueryDatasetResource.class, - CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, + CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, workspaceId, sourceResource.getMetadata().getResourceId(), objectMapper.writeValueAsString( new ApiUpdateControlledGcpBigQueryDatasetRequestBody().name(newName)), - userAccessUtils.defaultUserAuthRequest(), + userRequest, HttpStatus.SC_CONFLICT); ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - sourceResource.getMetadata().getResourceId()); + mockGcpApi.getControlledBqDataset( + userRequest, workspaceId, sourceResource.getMetadata().getResourceId()); assertEquals(oldName, gotResource.getMetadata().getName()); } @Test public void clone_requesterNoReadAccessOnSourceWorkspace_throws403() throws Exception { - mockMvcUtils.cloneControlledBqDatasetAsync( + mockGcpApi.cloneControlledBqDatasetAsync( userAccessUtils.noBillingUser().getAuthenticatedRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -334,7 +332,7 @@ public void clone_requesterNoReadAccessOnSourceWorkspace_throws403() throws Exce @Test public void clone_requesterNoWriteAccessOnDestWorkspace_throws403() throws Exception { - mockMvcUtils.cloneControlledBqDatasetAsync( + mockGcpApi.cloneControlledBqDatasetAsync( userAccessUtils.secondUser().getAuthenticatedRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -351,7 +349,7 @@ public void clone_requesterNoWriteAccessOnDestWorkspace_throws403() throws Excep @Test public void clone_requestContainsInvalidField_throws400() throws Exception { - mockMvcUtils.cloneControlledBqDatasetAsync( + mockGcpApi.cloneControlledBqDatasetAsync( userAccessUtils.defaultUser().getAuthenticatedRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -371,8 +369,9 @@ public void clone_userWithWriteAccessOnDestWorkspace_succeeds() throws Exception var destResourceName = TestUtils.appendRandomNumber("clonedbq"); AuthenticatedUserRequest userRequest = userAccessUtils.secondUser().getAuthenticatedRequest(); logger.info(">>Cloning user is {}", userRequest.getEmail()); + ApiGcpBigQueryDatasetResource clonedBqDataset = - mockMvcUtils.cloneControlledBqDataset( + mockGcpApi.cloneControlledBqDatasetAndWait( userRequest, workspaceId2, source2Resource.getMetadata().getResourceId(), @@ -383,7 +382,6 @@ public void clone_userWithWriteAccessOnDestWorkspace_succeeds() throws Exception /*destLocation=*/ null, // should get location from source resource /*defaultTableLifetime=*/ null, /*defaultPartitionLifetime=*/ null); - assertClonedControlledBqDataset( clonedBqDataset, workspaceId, @@ -397,7 +395,7 @@ public void clone_userWithWriteAccessOnDestWorkspace_succeeds() throws Exception source2Resource.getMetadata().getResourceId(), userRequest); - mockMvcUtils.deleteBqDataset( + mockGcpApi.deleteBqDataset( userAccessUtils.defaultUserAuthRequest(), clonedBqDataset.getMetadata().getWorkspaceId(), clonedBqDataset.getMetadata().getResourceId(), @@ -407,16 +405,24 @@ public void clone_userWithWriteAccessOnDestWorkspace_succeeds() throws Exception // Tests getUniquenessCheckAttributes() works @Test void clone_duplicateDatasetName_jobThrows409() throws Exception { - ApiErrorReport errorReport = - mockMvcUtils.cloneControlledBqDataset_jobError( - userAccessUtils.defaultUserAuthRequest(), + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); + ApiCloneControlledGcpBigQueryDatasetResult result = + mockGcpApi.cloneControlledBqDatasetAsync( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId, ApiCloningInstructionsEnum.RESOURCE, /*destResourceName=*/ null, /*destDatasetName=*/ sourceDatasetName, - HttpStatus.SC_CONFLICT); + /*destLocation=*/ null, + /*defaultTableLifetime=*/ null, + /*defaultPartitionLifetime=*/ null, + List.of(HttpStatus.SC_ACCEPTED), + /*shouldUndo=*/ false); + ApiErrorReport errorReport = + mockGcpApi.cloneControlledBqDatasetAndExpectError( + userRequest, workspaceId, result.getJobReport().getId(), HttpStatus.SC_CONFLICT); assertThat( errorReport.getMessage(), equalTo("A resource with matching attributes already exists")); } @@ -424,9 +430,11 @@ void clone_duplicateDatasetName_jobThrows409() throws Exception { @Test void clone_copyNothing() throws Exception { String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); + ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.cloneControlledBqDataset( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId, @@ -438,12 +446,12 @@ void clone_copyNothing() throws Exception { assertNull(clonedResource); // Assert clone doesn't exist. There's no resource ID, so search on resource name. - mockMvcUtils.assertNoResourceWithName( - userAccessUtils.defaultUserAuthRequest(), workspaceId, destResourceName); + mockMvcUtils.assertNoResourceWithName(userRequest, workspaceId, destResourceName); } @Test void clone_copyDefinition() throws Exception { + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); // Source resource is in us-west4 // Clone resource to EUROPE_LOCATION @@ -452,8 +460,8 @@ void clone_copyDefinition() throws Exception { Long defaultPartitionLifetime = 6201L; String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.cloneControlledBqDatasetAndWait( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId2, @@ -476,29 +484,25 @@ void clone_copyDefinition() throws Exception { /*expectedCreatedBy=*/ userAccessUtils.getDefaultUserEmail(), workspaceId, sourceResource.getMetadata().getResourceId(), - userAccessUtils.defaultUserAuthRequest()); + userRequest); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId2, - clonedResource.getMetadata().getResourceId()); + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getControlledBqDataset( + userRequest, workspaceId2, clonedResource.getMetadata().getResourceId()); assertApiBqDatasetEquals(clonedResource, gotResource); // Call GCP directly cloudUtils.assertDatasetHasNoTables( - userAccessUtils.defaultUserAuthRequest(), - projectId2, - gotResource.getAttributes().getDatasetId()); + userRequest, projectId2, gotResource.getAttributes().getDatasetId()); assertBqDatasetAttributes( projectId2, gotResource.getAttributes().getDatasetId(), EUROPE_LOCATION, DEFAULT_TABLE_LIFETIME, DEFAULT_PARTITION_LIFETIME); - mockMvcUtils.deleteBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.deleteBqDataset( + userRequest, workspaceId2, gotResource.getMetadata().getResourceId(), /*isControlled=*/ StewardshipType.REFERENCED); @@ -506,6 +510,7 @@ void clone_copyDefinition() throws Exception { @Test void clone_copyResource_sameWorkspace() throws Exception { + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); // Source resource is in us-west4 // Clone resource to europe location @@ -515,8 +520,8 @@ void clone_copyResource_sameWorkspace() throws Exception { String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); String destDatasetName = TestUtils.appendRandomNumber("dest-dataset-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.cloneControlledBqDatasetAndWait( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId, @@ -539,14 +544,12 @@ void clone_copyResource_sameWorkspace() throws Exception { /*expectedCreatedBy=*/ userAccessUtils.getDefaultUserEmail(), workspaceId, sourceResource.getMetadata().getResourceId(), - userAccessUtils.defaultUserAuthRequest()); + userRequest); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - clonedResource.getMetadata().getResourceId()); + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getControlledBqDataset( + userRequest, workspaceId, clonedResource.getMetadata().getResourceId()); assertApiBqDatasetEquals(clonedResource, gotResource); // Call GCP directly @@ -564,6 +567,7 @@ void clone_copyResource_sameWorkspace() throws Exception { @Test void clone_copyResource_differentWorkspace() throws Exception { + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); // Source resource is in us-west4 // Clone resource to europe location @@ -574,8 +578,8 @@ void clone_copyResource_differentWorkspace() throws Exception { String destDatasetName = TestUtils.appendRandomNumber("dest-dataset-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.cloneControlledBqDatasetAndWait( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId2, @@ -598,14 +602,12 @@ void clone_copyResource_differentWorkspace() throws Exception { userAccessUtils.getDefaultUserEmail(), workspaceId, sourceResource.getMetadata().getResourceId(), - userAccessUtils.defaultUserAuthRequest()); + userRequest); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId2, - clonedResource.getMetadata().getResourceId()); + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getControlledBqDataset( + userRequest, workspaceId2, clonedResource.getMetadata().getResourceId()); assertApiBqDatasetEquals(clonedResource, gotResource); // Call GCP directly @@ -623,13 +625,14 @@ void clone_copyResource_differentWorkspace() throws Exception { @Test void clone_copyReference() throws Exception { + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); // Source resource is COPY_DEFINITION // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneControlledBqDataset( - userAccessUtils.defaultUserAuthRequest(), + mockGcpApi.cloneControlledBqDataset( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId, @@ -652,14 +655,12 @@ void clone_copyReference() throws Exception { /*expectedCreatedBy=*/ userAccessUtils.getDefaultUserEmail(), workspaceId, sourceResource.getMetadata().getResourceId(), - userAccessUtils.defaultUserAuthRequest()); + userRequest); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getReferencedBqDataset( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - clonedResource.getMetadata().getResourceId()); + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getReferencedBqDataset( + userRequest, workspaceId, clonedResource.getMetadata().getResourceId()); assertApiBqDatasetEquals(clonedResource, gotResource); } @@ -692,7 +693,7 @@ void clone_policiesMerged() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); - mockMvcUtils.cloneControlledBqDataset( + mockGcpApi.cloneControlledBqDataset( userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -712,11 +713,41 @@ void clone_policiesMerged() throws Exception { mockMvcUtils.deletePolicies(userRequest, workspaceId2); } + private void cloneControlledBqDataset_undo( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + String destResourceName) + throws Exception { + ApiCloneControlledGcpBigQueryDatasetResult result = + mockGcpApi.cloneControlledBqDatasetAsync( + userRequest, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + /*destDatasetName=*/ null, + /*destLocation=*/ null, + /*defaultTableLifetime=*/ null, + /*defaultPartitionLifetime=*/ null, + List.of(HttpStatus.SC_ACCEPTED), + /*shouldUndo=*/ true); + mockGcpApi.cloneControlledBqDatasetAndExpectError( + userRequest, + sourceWorkspaceId, + result.getJobReport().getId(), + HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + @Test void clone_copyResource_undo() throws Exception { + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); - mockMvcUtils.cloneControlledBqDataset_undo( - userAccessUtils.defaultUserAuthRequest(), + cloneControlledBqDataset_undo( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId2, @@ -724,15 +755,16 @@ void clone_copyResource_undo() throws Exception { destResourceName); // Assert clone doesn't exist. There's no resource ID, so search on resource name. - mockMvcUtils.assertNoResourceWithName( - userAccessUtils.defaultUserAuthRequest(), workspaceId2, destResourceName); + mockMvcUtils.assertNoResourceWithName(userRequest, workspaceId2, destResourceName); } @Test void clone_copyReference_undo() throws Exception { String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); - mockMvcUtils.cloneControlledBqDataset_undo( - userAccessUtils.defaultUserAuthRequest(), + AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest(); + + cloneControlledBqDataset_undo( + userRequest, /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), /*destWorkspaceId=*/ workspaceId2, @@ -740,8 +772,7 @@ void clone_copyReference_undo() throws Exception { destResourceName); // Assert clone doesn't exist. There's no resource ID, so search on resource name. - mockMvcUtils.assertNoResourceWithName( - userAccessUtils.defaultUserAuthRequest(), workspaceId, destResourceName); + mockMvcUtils.assertNoResourceWithName(userRequest, workspaceId, destResourceName); } private void assertBqDataset( diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerDataprocClusterConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerDataprocClusterConnectedTest.java index affba75f79..972451317d 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerDataprocClusterConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerDataprocClusterConnectedTest.java @@ -7,6 +7,7 @@ import bio.terra.stairway.FlightDebugInfo; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.StairwayTestUtils; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.connected.UserAccessUtils; @@ -47,6 +48,7 @@ public class ControlledGcpResourceApiControllerDataprocClusterConnectedTest extends BaseConnectedTest { @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired UserAccessUtils userAccessUtils; @Autowired JobService jobService; @@ -121,7 +123,7 @@ public void createDataprocCluster() throws Exception { .value("asia-east1"))); ApiGcpDataprocClusterResource cluster = - mockMvcUtils + mockGcpApi .createDataprocCluster( userAccessUtils.defaultUserAuthRequest(), workspaceId, @@ -146,18 +148,19 @@ public void createDataprocCluster() throws Exception { @Test public void createDataprocCluster_duplicateInstanceId() throws Exception { var duplicateName = "not-unique-name"; - mockMvcUtils - .createDataprocClusterAndWait( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - "asia-east1", - stagingBucketUuid, - tempBucketUuid, - duplicateName) - .getDataprocCluster(); + ApiGcpDataprocClusterResource unused = + mockGcpApi + .createDataprocClusterAndWait( + userAccessUtils.defaultUserAuthRequest(), + workspaceId, + "asia-east1", + stagingBucketUuid, + tempBucketUuid, + duplicateName) + .getDataprocCluster(); ApiErrorReport errorReport = - mockMvcUtils + mockGcpApi .createDataprocClusterAndExpect( userAccessUtils.defaultUserAuthRequest(), workspaceId, diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGceInstanceConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGceInstanceConnectedTest.java index c1a879f246..812c1df926 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGceInstanceConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGceInstanceConnectedTest.java @@ -7,6 +7,7 @@ import bio.terra.stairway.FlightDebugInfo; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.StairwayTestUtils; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.connected.UserAccessUtils; import bio.terra.workspace.generated.model.ApiAccessScope; @@ -44,6 +45,7 @@ public class ControlledGcpResourceApiControllerGceInstanceConnectedTest extends BaseConnectedTest { @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired UserAccessUtils userAccessUtils; @Autowired JobService jobService; @@ -84,7 +86,7 @@ public void createGceInstance_correctZone() throws Exception { .value("asia-east1"))); ApiGcpGceInstanceResource instance = - mockMvcUtils + mockGcpApi .createGceInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null) .getGceInstance(); @@ -98,7 +100,7 @@ public void createGceInstance_correctZone() throws Exception { userAccessUtils.getDefaultUserEmail()); instance = - mockMvcUtils + mockGcpApi .createGceInstance( userAccessUtils.defaultUserAuthRequest(), workspaceId, "europe-west1-b") .getGceInstance(); @@ -120,13 +122,14 @@ public void createGceInstance_correctZone() throws Exception { @Test public void createGceInstance_duplicateInstanceId() throws Exception { var duplicateName = "not-unique-name"; - mockMvcUtils - .createGceInstanceAndWait( - userAccessUtils.defaultUserAuthRequest(), workspaceId, duplicateName, null) - .getGceInstance(); + ApiGcpGceInstanceResource unused = + mockGcpApi + .createGceInstanceAndWait( + userAccessUtils.defaultUserAuthRequest(), workspaceId, duplicateName, null) + .getGceInstance(); ApiErrorReport errorReport = - mockMvcUtils + mockGcpApi .createGceInstanceAndExpect( userAccessUtils.defaultUserAuthRequest(), workspaceId, diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGcsBucketConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGcsBucketConnectedTest.java index 2497833317..259c68e251 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGcsBucketConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerGcsBucketConnectedTest.java @@ -6,9 +6,9 @@ import static bio.terra.workspace.common.GcsBucketUtils.buildSignedUrlListObject; import static bio.terra.workspace.common.GcsBucketUtils.waitForProjectAccess; import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.LOAD_SIGNED_URL_LIST_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.LOAD_SIGNED_URL_LIST_RESULT_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.LOAD_SIGNED_URL_LIST_ALPHA_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.LOAD_SIGNED_URL_LIST_RESULT_ALPHA_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertApiGcsBucketEquals; import static bio.terra.workspace.common.utils.MockMvcUtils.assertControlledResourceMetadata; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; @@ -401,7 +401,7 @@ public void update_throws409() throws Exception { mockMvcUtils.updateResource( ApiGcpGcsBucketResource.class, - CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, sourceBucket.getMetadata().getResourceId(), objectMapper.writeValueAsString( @@ -923,7 +923,7 @@ private void loadSignedUrlListExpectError( mockMvcUtils.postExpect( userRequest, objectMapper.writeValueAsString(requestBody), - String.format(LOAD_SIGNED_URL_LIST_PATH_FORMAT, workspaceId, bucketId), + String.format(LOAD_SIGNED_URL_LIST_ALPHA_PATH_FORMAT, workspaceId, bucketId), httpStatus); } @@ -934,7 +934,7 @@ private ApiLoadUrlListResult loadSignedUrlList( var serializedResponse = mockMvcUtils.getSerializedResponseForPost( userRequest, - String.format(LOAD_SIGNED_URL_LIST_PATH_FORMAT, workspaceId, bucketId), + String.format(LOAD_SIGNED_URL_LIST_ALPHA_PATH_FORMAT, workspaceId, bucketId), objectMapper.writeValueAsString(requestBody)); var result = objectMapper.readValue(serializedResponse, ApiLoadUrlListResult.class); String jobId = result.getJobReport().getId(); @@ -954,7 +954,8 @@ private ApiLoadUrlListResult getLoadSignedUrlListResult( String serializedResponse = mockMvcUtils.getSerializedResponseForGetJobResult( userRequest, - String.format(LOAD_SIGNED_URL_LIST_RESULT_PATH_FORMAT, workspaceId, resourceId, jobId)); + String.format( + LOAD_SIGNED_URL_LIST_RESULT_ALPHA_PATH_FORMAT, workspaceId, resourceId, jobId)); return objectMapper.readValue(serializedResponse, ApiLoadUrlListResult.class); } } diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerTest.java index 0e02e9ae13..d66500fd70 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ControlledGcpResourceApiControllerTest.java @@ -1,9 +1,9 @@ package bio.terra.workspace.app.controller; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.GENERATE_GCP_AI_NOTEBOOK_NAME_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.GENERATE_GCP_BQ_DATASET_NAME_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.GENERATE_GCP_GCS_BUCKET_NAME_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.GENERATE_NAME_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.GENERATE_NAME_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.GENERATE_NAME_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.USER_REQUEST; import static bio.terra.workspace.common.utils.MockMvcUtils.addAuth; import static bio.terra.workspace.service.workspace.model.WorkspaceConstants.ResourceProperties.FOLDER_ID_KEY; @@ -83,7 +83,8 @@ public void getCloudNameFromGcsBucketName() throws Exception { mockMvc .perform( addAuth( - post(String.format(GENERATE_GCP_GCS_BUCKET_NAME_PATH_FORMAT, workspaceId)) + post(String.format( + GENERATE_NAME_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId)) .contentType(MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8") @@ -113,7 +114,8 @@ public void getCloudNameFromBigQueryDatasetName() throws Exception { mockMvc .perform( addAuth( - post(String.format(GENERATE_GCP_BQ_DATASET_NAME_PATH_FORMAT, workspaceId)) + post(String.format( + GENERATE_NAME_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, workspaceId)) .contentType(MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8") @@ -141,7 +143,8 @@ public void getCloudNameFromAiNotebookInstanceName() throws Exception { mockMvc .perform( addAuth( - post(String.format(GENERATE_GCP_AI_NOTEBOOK_NAME_PATH_FORMAT, workspaceId)) + post(String.format( + GENERATE_NAME_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT, workspaceId)) .contentType(MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8") @@ -173,7 +176,7 @@ public void createBigQueryDataset_resourceContainsInvalidFolderId_throws400() th mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(datasetCreationRequest), - String.format(CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT, workspaceId), + String.format(CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, workspaceId), HttpStatus.SC_BAD_REQUEST); } } diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqTableConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDataTableConnectedTest.java similarity index 92% rename from service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqTableConnectedTest.java rename to service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDataTableConnectedTest.java index 4750346159..5c55803a41 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqTableConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDataTableConnectedTest.java @@ -1,8 +1,7 @@ package bio.terra.workspace.app.controller; import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.assertApiBqDataTableEquals; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -13,6 +12,7 @@ import bio.terra.workspace.app.configuration.external.FeatureConfiguration; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.fixtures.PolicyFixtures; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.connected.UserAccessUtils; @@ -50,12 +50,13 @@ // time creating and deleting GCP contexts. @Tag("connectedPlus") @TestInstance(Lifecycle.PER_CLASS) -public class ReferencedGcpResourceControllerBqTableConnectedTest extends BaseConnectedTest { +public class ReferencedGcpResourceControllerBqDataTableConnectedTest extends BaseConnectedTest { private static final Logger logger = - LoggerFactory.getLogger(ReferencedGcpResourceControllerBqTableConnectedTest.class); + LoggerFactory.getLogger(ReferencedGcpResourceControllerBqDataTableConnectedTest.class); @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @Autowired UserAccessUtils userAccessUtils; @Autowired FeatureConfiguration features; @@ -95,7 +96,7 @@ void setUpPerTest() throws Exception { sourceDatasetName = TestUtils.appendRandomNumber("source-dataset-name"); sourceTableId = TestUtils.appendRandomNumber("source-table-id"); sourceResource = - mockMvcUtils.createReferencedBqTable( + mockGcpApi.createReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResourceName, @@ -129,7 +130,7 @@ public void create() throws Exception { // Assert resource returned by get ApiGcpBigQueryDataTableResource gotResource = - mockMvcUtils.getReferencedBqTable( + mockGcpApi.getReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId()); @@ -151,7 +152,7 @@ public void update() throws Exception { var newDataset = TestUtils.appendRandomNumber("newdataset"); var newTable = TestUtils.appendRandomNumber("newtable"); ApiGcpBigQueryDataTableResource updatedResource = - mockMvcUtils.updateReferencedBqTable( + mockGcpApi.updateReferencedBqDataTable( userAccessUtils.secondUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId(), @@ -182,7 +183,7 @@ public void update() throws Exception { @Test public void update_throws409() throws Exception { var newName = TestUtils.appendRandomNumber("newdatatableresourcename"); - mockMvcUtils.createReferencedBqTable( + mockGcpApi.createReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId, newName, @@ -195,13 +196,13 @@ public void update_throws409() throws Exception { objectMapper.writeValueAsString( new ApiUpdateBigQueryDatasetReferenceRequestBody().name(newName)), String.format( - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, + REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, workspaceId, sourceResource.getMetadata().getResourceId()), HttpStatus.SC_CONFLICT); ApiGcpBigQueryDataTableResource gotResource = - mockMvcUtils.getReferencedBqTable( + mockGcpApi.getReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId()); @@ -210,7 +211,7 @@ public void update_throws409() throws Exception { @Test public void clone_requesterNoReadAccessOnSourceWorkspace_throws403() throws Exception { - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTableAndExpect( userAccessUtils.secondUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -233,7 +234,7 @@ public void clone_requesterNoWriteAccessOnDestWorkspace_throws403() throws Excep WsmIamRole.READER, userAccessUtils.getSecondUserEmail()); - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTableAndExpect( userAccessUtils.secondUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -268,7 +269,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce userAccessUtils.getSecondUserEmail()); ApiGcpBigQueryDataTableResource clonedResource = - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTable( userAccessUtils.secondUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId(), @@ -296,7 +297,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce workspaceId2, WsmIamRole.WRITER, userAccessUtils.getSecondUserEmail()); - mockMvcUtils.deleteBqDataTable( + mockGcpApi.deleteBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId2, clonedResource.getMetadata().getResourceId()); @@ -306,7 +307,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce void clone_copyNothing() throws Exception { String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDataTableResource clonedResource = - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -327,7 +328,7 @@ void clone_copyReference_sameWorkspace() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDataTableResource clonedResource = - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -348,8 +349,8 @@ void clone_copyReference_sameWorkspace() throws Exception { userAccessUtils.defaultUserAuthRequest()); // Assert resource returned by get - final ApiGcpBigQueryDataTableResource gotResource = - mockMvcUtils.getReferencedBqTable( + ApiGcpBigQueryDataTableResource gotResource = + mockGcpApi.getReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId, clonedResource.getMetadata().getResourceId()); @@ -361,7 +362,7 @@ void clone_copyReference_differentWorkspace() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDataTableResource clonedResource = - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -382,8 +383,8 @@ void clone_copyReference_differentWorkspace() throws Exception { userAccessUtils.defaultUserAuthRequest()); // Assert resource returned by get - final ApiGcpBigQueryDataTableResource gotResource = - mockMvcUtils.getReferencedBqTable( + ApiGcpBigQueryDataTableResource gotResource = + mockGcpApi.getReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), workspaceId2, clonedResource.getMetadata().getResourceId()); @@ -418,7 +419,7 @@ void clone_policiesMerged() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTable( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -498,4 +499,12 @@ private void assertClonedBqTable( assertEquals(expectedDatasetName, actualResource.getAttributes().getDatasetId()); assertEquals(expectedTableId, actualResource.getAttributes().getDataTableId()); } + + private static void assertApiBqDataTableEquals( + ApiGcpBigQueryDataTableResource expectedDataTable, + ApiGcpBigQueryDataTableResource actualDataTable) { + MockMvcUtils.assertResourceMetadataEquals( + expectedDataTable.getMetadata(), actualDataTable.getMetadata()); + assertEquals(expectedDataTable.getAttributes(), actualDataTable.getAttributes()); + } } diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDatasetConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDatasetConnectedTest.java index d86a4964b5..58f8bcfcde 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDatasetConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerBqDatasetConnectedTest.java @@ -1,6 +1,6 @@ package bio.terra.workspace.app.controller; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_BQ_DATASET_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertApiBqDatasetEquals; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,6 +12,7 @@ import bio.terra.workspace.app.configuration.external.FeatureConfiguration; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.fixtures.PolicyFixtures; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.connected.UserAccessUtils; @@ -56,6 +57,7 @@ public class ReferencedGcpResourceControllerBqDatasetConnectedTest extends BaseC @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @Autowired UserAccessUtils userAccessUtils; @Autowired FeatureConfiguration features; @@ -94,7 +96,7 @@ void setUpPerTest() throws Exception { sourceResourceName = TestUtils.appendRandomNumber("source-resource-name"); sourceDatasetName = TestUtils.appendRandomNumber("source-dataset-name"); sourceResource = - mockMvcUtils.createReferencedBqDataset( + mockGcpApi.createReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResourceName, @@ -126,7 +128,7 @@ public void create() throws Exception { // Assert resource returned by get ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getReferencedBqDataset( + mockGcpApi.getReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId()); @@ -146,7 +148,7 @@ public void update() throws Exception { var newCloningInstruction = ApiCloningInstructionsEnum.REFERENCE; var newDataset = TestUtils.appendRandomNumber("newdataset"); ApiGcpBigQueryDatasetResource updatedResource = - mockMvcUtils.updateReferencedBqDataset( + mockGcpApi.updateReferencedBqDataset( userAccessUtils.secondUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId(), @@ -176,7 +178,7 @@ public void update() throws Exception { @Test public void update_throws409() throws Exception { var newName = TestUtils.appendRandomNumber("newdataSetresourcename"); - mockMvcUtils.createReferencedBqDataset( + mockGcpApi.createReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, newName, @@ -188,13 +190,13 @@ public void update_throws409() throws Exception { objectMapper.writeValueAsString( new ApiUpdateBigQueryDatasetReferenceRequestBody().name(newName)), String.format( - REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, + REFERENCED_GCP_BQ_DATASET_PATH_FORMAT, workspaceId, sourceResource.getMetadata().getResourceId()), HttpStatus.SC_CONFLICT); ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getReferencedBqDataset( + mockGcpApi.getReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, sourceResource.getMetadata().getResourceId()); @@ -203,7 +205,7 @@ public void update_throws409() throws Exception { @Test public void clone_requesterNoReadAccessOnSourceWorkspace_throws403() throws Exception { - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDatasetAndExpect( userAccessUtils.secondUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -226,7 +228,7 @@ public void clone_requesterNoWriteAccessOnDestWorkspace_throws403() throws Excep WsmIamRole.READER, userAccessUtils.getSecondUserEmail()); - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDatasetAndExpect( userAccessUtils.secondUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -261,7 +263,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce userAccessUtils.getSecondUserEmail()); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDataset( userAccessUtils.secondUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, /*sourceResourceId=*/ sourceResource.getMetadata().getResourceId(), @@ -291,7 +293,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce workspaceId2, WsmIamRole.WRITER, userAccessUtils.getSecondUserEmail()); - mockMvcUtils.deleteBqDataset( + mockGcpApi.deleteBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId2, clonedResource.getMetadata().getResourceId(), @@ -302,7 +304,7 @@ public void clone_secondUserHasWriteAccessOnDestWorkspace_succeeds() throws Exce void clone_copyNothing() throws Exception { String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -323,7 +325,7 @@ void clone_copyReference_sameWorkspace() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -345,8 +347,8 @@ void clone_copyReference_sameWorkspace() throws Exception { userAccessUtils.defaultUserAuthRequest()); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getReferencedBqDataset( + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, clonedResource.getMetadata().getResourceId()); @@ -358,7 +360,7 @@ void clone_copyReference_differentWorkspace() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); ApiGcpBigQueryDatasetResource clonedResource = - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), @@ -380,8 +382,8 @@ void clone_copyReference_differentWorkspace() throws Exception { userAccessUtils.defaultUserAuthRequest()); // Assert resource returned by get - final ApiGcpBigQueryDatasetResource gotResource = - mockMvcUtils.getReferencedBqDataset( + ApiGcpBigQueryDatasetResource gotResource = + mockGcpApi.getReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId2, clonedResource.getMetadata().getResourceId()); @@ -416,7 +418,7 @@ void clone_policiesMerged() throws Exception { // Clone resource String destResourceName = TestUtils.appendRandomNumber("dest-resource-name"); - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDataset( userAccessUtils.defaultUserAuthRequest(), /*sourceWorkspaceId=*/ workspaceId, sourceResource.getMetadata().getResourceId(), diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsBucketConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsBucketConnectedTest.java index 16d34b640c..74df344bae 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsBucketConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsBucketConnectedTest.java @@ -1,7 +1,7 @@ package bio.terra.workspace.app.controller; import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertApiGcsBucketEquals; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; import static org.hamcrest.MatcherAssert.assertThat; @@ -206,7 +206,7 @@ public void update_throws409() throws Exception { objectMapper.writeValueAsString( new ApiUpdateBigQueryDatasetReferenceRequestBody().name(newName)), String.format( - REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, sourceResource.getMetadata().getResourceId()), HttpStatus.SC_CONFLICT); diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsObjectConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsObjectConnectedTest.java index f0ef09d6f7..4fc41aefe2 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsObjectConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerGcsObjectConnectedTest.java @@ -1,7 +1,7 @@ package bio.terra.workspace.app.controller; import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.assertResourceMetadata; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -184,7 +184,7 @@ public void update_throws409() throws Exception { objectMapper.writeValueAsString( new ApiUpdateBigQueryDatasetReferenceRequestBody().name(newName)), String.format( - REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT, + REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT, workspaceId, sourceResource.getMetadata().getResourceId()), HttpStatus.SC_CONFLICT); diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerTest.java index 8054e2ae55..f05581a877 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedGcpResourceControllerTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.when; import bio.terra.workspace.common.BaseUnitTest; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.generated.model.ApiCloningInstructionsEnum; import bio.terra.workspace.service.iam.model.SamConstants; @@ -26,6 +27,7 @@ public class ReferencedGcpResourceControllerTest extends BaseUnitTest { @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @BeforeEach @@ -55,7 +57,6 @@ public void setUp() throws InterruptedException { @Test public void cloneReferencedDataRepoSnapshot_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedDataRepoSnapshot( USER_REQUEST, workspaceId, @@ -69,7 +70,6 @@ public void cloneReferencedDataRepoSnapshot_copyDefinition_throws400() throws Ex @Test public void cloneReferencedDataRepoSnapshot_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedDataRepoSnapshot( USER_REQUEST, workspaceId, @@ -83,8 +83,7 @@ public void cloneReferencedDataRepoSnapshot_copyResource_throws400() throws Exce @Test public void cloneReferencedBqDataset_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDatasetAndExpect( USER_REQUEST, workspaceId, /*sourceResourceId=*/ UUID.randomUUID(), @@ -97,8 +96,7 @@ public void cloneReferencedBqDataset_copyDefinition_throws400() throws Exception @Test public void cloneReferencedBqDataset_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - - mockMvcUtils.cloneReferencedBqDataset( + mockGcpApi.cloneReferencedBqDatasetAndExpect( USER_REQUEST, workspaceId, /*sourceResourceId=*/ UUID.randomUUID(), @@ -111,8 +109,7 @@ public void cloneReferencedBqDataset_copyResource_throws400() throws Exception { @Test public void cloneReferencedBqTable_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTableAndExpect( USER_REQUEST, workspaceId, /*sourceResourceId=*/ UUID.randomUUID(), @@ -125,8 +122,7 @@ public void cloneReferencedBqTable_copyDefinition_throws400() throws Exception { @Test public void cloneReferencedBqTable_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - - mockMvcUtils.cloneReferencedBqTable( + mockGcpApi.cloneReferencedBqDataTableAndExpect( USER_REQUEST, workspaceId, /*sourceResourceId=*/ UUID.randomUUID(), @@ -139,7 +135,6 @@ public void cloneReferencedBqTable_copyResource_throws400() throws Exception { @Test public void cloneReferencedGcsBucket_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGcsBucket( USER_REQUEST, workspaceId, @@ -153,7 +148,6 @@ public void cloneReferencedGcsBucket_copyDefinition_throws400() throws Exception @Test public void cloneReferencedGcsBucket_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGcsBucket( USER_REQUEST, workspaceId, @@ -167,7 +161,6 @@ public void cloneReferencedGcsBucket_copyResource_throws400() throws Exception { @Test public void cloneReferencedGcsObject_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGcsObject( USER_REQUEST, workspaceId, @@ -181,7 +174,6 @@ public void cloneReferencedGcsObject_copyDefinition_throws400() throws Exception @Test public void cloneReferencedGcsObject_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGcsObject( USER_REQUEST, workspaceId, @@ -195,7 +187,6 @@ public void cloneReferencedGcsObject_copyResource_throws400() throws Exception { @Test public void cloneReferencedGitRepo_copyDefinition_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGitRepo( USER_REQUEST, workspaceId, @@ -209,7 +200,6 @@ public void cloneReferencedGitRepo_copyDefinition_throws400() throws Exception { @Test public void cloneReferencedGitRepo_copyResource_throws400() throws Exception { UUID workspaceId = mockMvcUtils.createWorkspaceWithoutCloudContext(USER_REQUEST).getId(); - mockMvcUtils.cloneReferencedGitRepo( USER_REQUEST, workspaceId, diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedResourceCloneConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedResourceCloneConnectedTest.java index 85fce96124..b31f67df1a 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ReferencedResourceCloneConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ReferencedResourceCloneConnectedTest.java @@ -3,8 +3,8 @@ import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.RESOURCE_DESCRIPTION; import static bio.terra.workspace.common.fixtures.PolicyFixtures.IOWA_REGION; import static bio.terra.workspace.common.fixtures.WorkspaceFixtures.DEFAULT_SPEND_PROFILE_NAME; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.CLONE_WORKSPACE_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -373,7 +373,7 @@ private void workspaceSetup(ApiCloningInstructionsEnum cloningInstructions) thro String serializedResponse = mockMvcUtils.getSerializedResponseForPost( userAccessUtils.defaultUserAuthRequest(), - REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT, + CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, sourceWorkspaceId, objectMapper.writeValueAsString(request)); sourceResource = objectMapper.readValue(serializedResponse, ApiGcpGcsBucketResource.class); diff --git a/service/src/test/java/bio/terra/workspace/app/controller/ResourceApiControllerConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/ResourceApiControllerConnectedTest.java index f55d185b6b..ee04c294f0 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/ResourceApiControllerConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/ResourceApiControllerConnectedTest.java @@ -14,6 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import bio.terra.workspace.common.BaseConnectedTest; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.connected.UserAccessUtils; import bio.terra.workspace.connected.WorkspaceConnectedTestUtils; @@ -46,8 +47,9 @@ public class ResourceApiControllerConnectedTest extends BaseConnectedTest { @Autowired MockMvc mockMvc; - @Autowired ObjectMapper objectMapper; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; + @Autowired ObjectMapper objectMapper; @Autowired UserAccessUtils userAccessUtils; @Autowired WorkspaceConnectedTestUtils connectedTestUtils; @@ -72,7 +74,7 @@ class UpdateResourceProperties { public void updateResourceProperties_newPropertiesAdded() throws Exception { // Create resource with properties foo -> bar. ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); var folderIdKey = "terra_workspace_folder_id"; @@ -91,7 +93,7 @@ public void updateResourceProperties_newPropertiesAdded() throws Exception { // Get the updated resource and assert that the new properties are added. ApiGcpBigQueryDatasetResource updatedResource = - mockMvcUtils.getControlledBqDataset( + mockGcpApi.getControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, resourceId); assertEquals( expectedProperties, @@ -107,7 +109,7 @@ public void updateResourceProperties_newPropertiesAdded() throws Exception { // Get the updated resource and assert terra_workspace_folder_id has new UUID. ApiGcpBigQueryDatasetResource updatedResource2 = - mockMvcUtils.getControlledBqDataset( + mockGcpApi.getControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, resourceId); assertEquals( newFolderId.toString(), @@ -126,7 +128,7 @@ public void updateResourceProperties_resourceDoesNotExist_throws404() throws Exc @Test public void updateResourceProperties_propertiesIsEmpty_throws400() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); @@ -137,7 +139,7 @@ public void updateResourceProperties_propertiesIsEmpty_throws400() throws Except @Test public void updateResourceProperties_folderIdNotUuid_throws400() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); @@ -148,7 +150,7 @@ public void updateResourceProperties_folderIdNotUuid_throws400() throws Exceptio @Test public void updateResourceProperties_readOnlyPermission_throws403() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); mockMvcUtils.grantRole( @@ -172,7 +174,7 @@ class DeleteResourceProperties { @Test public void deleteResourceProperties_propertiesDeleted() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); updateResourcePropertiesExpectCode( @@ -185,7 +187,7 @@ public void deleteResourceProperties_propertiesDeleted() throws Exception { workspaceId, resourceId, List.of("foo", "sweet", "cute"), HttpStatus.SC_NO_CONTENT); ApiGcpBigQueryDatasetResource updatedResource = - mockMvcUtils.getControlledBqDataset( + mockGcpApi.getControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, resourceId); assertTrue(convertApiPropertyToMap(updatedResource.getMetadata().getProperties()).isEmpty()); } @@ -199,7 +201,7 @@ public void deleteResourceProperties_resourceDoesNotExist_throws404() throws Exc @Test public void deleteResourceProperties_propertiesIsEmpty_throws400() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); @@ -210,7 +212,7 @@ public void deleteResourceProperties_propertiesIsEmpty_throws400() throws Except @Test public void deleteResourceProperties_readOnlyPermission_throws403() throws Exception { ApiCreatedControlledGcpBigQueryDataset resource = - mockMvcUtils.createControlledBqDataset( + mockGcpApi.createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId); UUID resourceId = resource.getResourceId(); updateResourcePropertiesExpectCode( diff --git a/service/src/test/java/bio/terra/workspace/app/controller/TempGrantConnectedTest.java b/service/src/test/java/bio/terra/workspace/app/controller/TempGrantConnectedTest.java index 25328c032e..32f1d39d51 100644 --- a/service/src/test/java/bio/terra/workspace/app/controller/TempGrantConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/app/controller/TempGrantConnectedTest.java @@ -5,10 +5,13 @@ import bio.terra.workspace.app.configuration.external.FeatureConfiguration; import bio.terra.workspace.common.BaseConnectedTest; import bio.terra.workspace.common.GcpCloudUtils; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.connected.UserAccessUtils; +import bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceResource; import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetResource; +import bio.terra.workspace.generated.model.ApiGcpGcsBucketResource; import bio.terra.workspace.generated.model.ApiWorkspaceDescription; import bio.terra.workspace.service.crl.CrlService; import bio.terra.workspace.service.iam.SamService; @@ -34,6 +37,7 @@ public class TempGrantConnectedTest extends BaseConnectedTest { @Autowired MockMvc mockMvc; @Autowired MockMvcUtils mockMvcUtils; + @Autowired MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @Autowired UserAccessUtils userAccessUtils; @Autowired JobService jobService; @@ -72,16 +76,17 @@ public void setupAndWaitBucket() throws Exception { String sourceResourceName = TestUtils.appendRandomNumber("source-resource-name"); String sourceBucketName = TestUtils.appendRandomNumber("source-bucket-name"); - mockMvcUtils - .createControlledGcsBucket( - userAccessUtils.defaultUserAuthRequest(), - workspaceId, - sourceResourceName, - sourceBucketName, - null, - null, - null) - .getGcpBucket(); + ApiGcpGcsBucketResource unused = + mockMvcUtils + .createControlledGcsBucket( + userAccessUtils.defaultUserAuthRequest(), + workspaceId, + sourceResourceName, + sourceBucketName, + null, + null, + null) + .getGcpBucket(); addFileToBucket( userAccessUtils.defaultUser().getGoogleCredentials(), projectId, sourceBucketName); @@ -104,9 +109,10 @@ public void setupAndWaitNotebook() throws Exception { logger.info("Created workspace {} with project {}", workspaceId, projectId); - mockMvcUtils - .createAiNotebookInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null) - .getAiNotebookInstance(); + ApiGcpAiNotebookInstanceResource unused = + mockGcpApi + .createAiNotebookInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null) + .getAiNotebookInstance(); // So I can end the test and run cleanup when I'm done debugging while (!timeToFinish) { @@ -131,7 +137,7 @@ public void setupAndWaitBigQuery() throws Exception { String sourceDatasetName = TestUtils.appendRandomNumber("sourcedatasetname"); ApiGcpBigQueryDatasetResource resource = - mockMvcUtils + mockGcpApi .createControlledBqDataset( userAccessUtils.defaultUserAuthRequest(), workspaceId, diff --git a/service/src/test/java/bio/terra/workspace/common/utils/MockGcpApi.java b/service/src/test/java/bio/terra/workspace/common/utils/MockGcpApi.java new file mode 100644 index 0000000000..2daafd7c8e --- /dev/null +++ b/service/src/test/java/bio/terra/workspace/common/utils/MockGcpApi.java @@ -0,0 +1,869 @@ +package bio.terra.workspace.common.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import bio.terra.stairway.FlightDebugInfo; +import bio.terra.stairway.Step; +import bio.terra.stairway.StepStatus; +import bio.terra.workspace.common.StairwayTestUtils; +import bio.terra.workspace.common.fixtures.ControlledGcpResourceFixtures; +import bio.terra.workspace.common.fixtures.ControlledResourceFixtures; +import bio.terra.workspace.common.fixtures.ReferenceResourceFixtures; +import bio.terra.workspace.generated.model.ApiCloneControlledGcpBigQueryDatasetRequest; +import bio.terra.workspace.generated.model.ApiCloneControlledGcpBigQueryDatasetResult; +import bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult; +import bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult; +import bio.terra.workspace.generated.model.ApiCloningInstructionsEnum; +import bio.terra.workspace.generated.model.ApiCreateControlledGcpAiNotebookInstanceRequestBody; +import bio.terra.workspace.generated.model.ApiCreateControlledGcpBigQueryDatasetRequestBody; +import bio.terra.workspace.generated.model.ApiCreateControlledGcpDataprocClusterRequestBody; +import bio.terra.workspace.generated.model.ApiCreateControlledGcpGceInstanceRequestBody; +import bio.terra.workspace.generated.model.ApiCreateGcpBigQueryDataTableReferenceRequestBody; +import bio.terra.workspace.generated.model.ApiCreateGcpBigQueryDatasetReferenceRequestBody; +import bio.terra.workspace.generated.model.ApiCreatedControlledGcpAiNotebookInstanceResult; +import bio.terra.workspace.generated.model.ApiCreatedControlledGcpBigQueryDataset; +import bio.terra.workspace.generated.model.ApiCreatedControlledGcpDataprocClusterResult; +import bio.terra.workspace.generated.model.ApiCreatedControlledGcpGceInstanceResult; +import bio.terra.workspace.generated.model.ApiErrorReport; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableAttributes; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableResource; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetAttributes; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetCreationParameters; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetResource; +import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetUpdateParameters; +import bio.terra.workspace.generated.model.ApiJobControl; +import bio.terra.workspace.generated.model.ApiJobReport.StatusEnum; +import bio.terra.workspace.generated.model.ApiUpdateBigQueryDataTableReferenceRequestBody; +import bio.terra.workspace.generated.model.ApiUpdateBigQueryDatasetReferenceRequestBody; +import bio.terra.workspace.generated.model.ApiUpdateControlledGcpBigQueryDatasetRequestBody; +import bio.terra.workspace.service.iam.AuthenticatedUserRequest; +import bio.terra.workspace.service.job.JobService; +import bio.terra.workspace.service.resource.controlled.flight.clone.CheckControlledResourceAuthStep; +import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.CompleteTableCopyJobsStep; +import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.CreateTableCopyJobsStep; +import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.SetReferencedDestinationBigQueryDatasetInWorkingMapStep; +import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.SetReferencedDestinationBigQueryDatasetResponseStep; +import bio.terra.workspace.service.resource.controlled.model.AccessScopeType; +import bio.terra.workspace.service.resource.model.StewardshipType; +import bio.terra.workspace.service.resource.referenced.flight.create.CreateReferenceMetadataStep; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; +import com.google.common.collect.ImmutableList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.stereotype.Component; +import org.springframework.test.web.servlet.MockMvc; + +@Component +public class MockGcpApi { + private static final Logger logger = LoggerFactory.getLogger(MockGcpApi.class); + + @Autowired private MockMvc mockMvc; + @Autowired private MockMvcUtils mockMvcUtils; + @Autowired private ObjectMapper objectMapper; + @Autowired private JobService jobService; + + // GCS Bucket (Controlled) + public static final String CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/controlled/gcp/buckets"; + public static final String GENERATE_NAME_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT + "/generateName"; + public static final String CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT + "/%s"; + public static final String CLONE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT = + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT + "/clone"; + public static final String CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT + "/clone-result/%s"; + + // GCS Bucket (Referenced) + public static final String CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/referenced/gcp/buckets"; + public static final String REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT = + CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT + "/%s"; + public static final String CLONE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT = + REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT + "/clone"; + + // GCS Bucket (alpha1) + public static final String LOAD_SIGNED_URL_LIST_ALPHA_PATH_FORMAT = + "/api/workspaces/alpha1/%s/resources/controlled/gcp/buckets/%s/load"; + public static final String LOAD_SIGNED_URL_LIST_RESULT_ALPHA_PATH_FORMAT = + LOAD_SIGNED_URL_LIST_ALPHA_PATH_FORMAT + "/result/%s"; + + // GCS Object + public static final String CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/referenced/gcp/bucket/objects"; + public static final String REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT = + CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT + "/%s"; + public static final String CLONE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT = + REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT + "/clone"; + + // BQ Dataset (Controlled) + public static final String CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets"; + public static final String GENERATE_NAME_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT + "/generateName"; + public static final String CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT + "/%s"; + public static final String CLONE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT = + CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT + "/clone"; + public static final String CLONE_RESULT_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT + "/clone-result/%s"; + + public ApiCreatedControlledGcpBigQueryDataset createControlledBqDataset( + AuthenticatedUserRequest userRequest, UUID workspaceId) throws Exception { + return createControlledBqDataset( + userRequest, + workspaceId, + /*resourceName=*/ TestUtils.appendRandomNumber("resource-name"), + /*datasetName=*/ TestUtils.appendRandomNumber("dataset-name"), + /*location=*/ null, + /*defaultTableLifetime=*/ null, + /*defaultPartitionTableLifetime=*/ null); + } + + public ApiCreatedControlledGcpBigQueryDataset createControlledBqDataset( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String resourceName, + String datasetName, + @Nullable String location, + @Nullable Long defaultTableLifetime, + @Nullable Long defaultPartitionLifetime) + throws Exception { + ApiGcpBigQueryDatasetCreationParameters creationParameters = + new ApiGcpBigQueryDatasetCreationParameters().datasetId(datasetName); + if (location != null) { + creationParameters.setLocation(location); + } + if (defaultTableLifetime != null) { + creationParameters.setDefaultTableLifetime(defaultTableLifetime); + } + if (defaultPartitionLifetime != null) { + creationParameters.defaultPartitionLifetime(defaultPartitionLifetime); + } + ApiCreateControlledGcpBigQueryDatasetRequestBody request = + new ApiCreateControlledGcpBigQueryDatasetRequestBody() + .common( + ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() + .name(resourceName)) + .dataset(creationParameters); + + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + return objectMapper.readValue(serializedResponse, ApiCreatedControlledGcpBigQueryDataset.class); + } + + public void deleteBqDataset( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + UUID resourceId, + StewardshipType stewardshipType) + throws Exception { + mockMvcUtils.deleteResource( + userRequest, + workspaceId, + resourceId, + StewardshipType.CONTROLLED.equals(stewardshipType) + ? CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT + : REFERENCED_GCP_BQ_DATASET_PATH_FORMAT); + } + + public ApiGcpBigQueryDatasetResource getControlledBqDataset( + AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { + return getBqDataset( + userRequest, workspaceId, resourceId, CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT); + } + + private ApiGcpBigQueryDatasetResource getBqDataset( + AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId, String path) + throws Exception { + String serializedResponse = + mockMvcUtils.getSerializedResponseForGet(userRequest, path, workspaceId, resourceId); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); + } + + public ApiGcpBigQueryDatasetResource updateControlledBqDataset( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + UUID resourceId, + String newName, + String newDescription, + ApiCloningInstructionsEnum newCloningInstruction) + throws Exception { + ApiUpdateControlledGcpBigQueryDatasetRequestBody requestBody = + new ApiUpdateControlledGcpBigQueryDatasetRequestBody() + .name(newName) + .description(newDescription) + .updateParameters( + new ApiGcpBigQueryDatasetUpdateParameters() + .cloningInstructions(newCloningInstruction)); + return mockMvcUtils.updateResource( + ApiGcpBigQueryDatasetResource.class, + CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, + workspaceId, + resourceId, + objectMapper.writeValueAsString(requestBody), + userRequest, + HttpStatus.SC_OK); + } + + public ApiGcpBigQueryDatasetResource cloneControlledBqDataset( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName, + @Nullable String destDatasetName) + throws Exception { + return cloneControlledBqDatasetAndWait( + userRequest, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + destDatasetName, + /*location=*/ null, + /*defaultTableLifetime=*/ null, + /*defaultPartitionLifetime=*/ null); + } + + public ApiGcpBigQueryDatasetResource cloneControlledBqDatasetAndWait( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName, + @Nullable String destDatasetName, + @Nullable String destLocation, + @Nullable Long defaultTableLifetime, + @Nullable Long defaultPartitionLifetime) + throws Exception { + ApiCloneControlledGcpBigQueryDatasetResult result = + cloneControlledBqDatasetAsync( + userRequest, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + destDatasetName, + destLocation, + defaultTableLifetime, + defaultPartitionLifetime, + // clone_copyNothing sometimes returns SC_OK, even for the initial call. So accept both + // to avoid flakes. + MockMvcUtils.JOB_SUCCESS_CODES, + /*shouldUndo=*/ false); + + String jobId = result.getJobReport().getId(); + while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { + Thread.sleep(/*millis=*/ 5000); + result = + mockMvcUtils.getCreateResourceJobResult( + ApiCloneControlledGcpBigQueryDatasetResult.class, + userRequest, + CLONE_RESULT_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, + sourceWorkspaceId, + jobId); + } + assertEquals(StatusEnum.SUCCEEDED, result.getJobReport().getStatus()); + logger.info( + "Controlled BQ dataset clone of resource %s completed. ".formatted(sourceResourceId)); + return result.getDataset().getDataset(); + } + + /** Call cloneBigQueryDataset() and return immediately; don't wait for flight to finish. */ + public ApiCloneControlledGcpBigQueryDatasetResult cloneControlledBqDatasetAsync( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName, + @Nullable String destDatasetName, + @Nullable String destLocation, + @Nullable Long defaultTableLifetime, + @Nullable Long defaultPartitionLifetime, + List expectedCodes, + boolean shouldUndo) + throws Exception { + // Retry to ensure steps are idempotent + Map retryableStepsMap = new HashMap<>(); + List> retryableSteps = + ImmutableList.of( + CheckControlledResourceAuthStep.class, + SetReferencedDestinationBigQueryDatasetInWorkingMapStep.class, + CreateReferenceMetadataStep.class, + SetReferencedDestinationBigQueryDatasetResponseStep.class, + CreateTableCopyJobsStep.class, + CompleteTableCopyJobsStep.class); + retryableSteps.forEach( + step -> retryableStepsMap.put(step.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY)); + jobService.setFlightDebugInfoForTest( + FlightDebugInfo.newBuilder() + .doStepFailures(retryableStepsMap) + .lastStepFailure(shouldUndo) + .build()); + + ApiCloneControlledGcpBigQueryDatasetRequest request = + new ApiCloneControlledGcpBigQueryDatasetRequest() + .destinationWorkspaceId(destWorkspaceId) + .cloningInstructions(cloningInstructions) + .location(destLocation) + .defaultTableLifetime(defaultTableLifetime) + .defaultPartitionLifetime(defaultPartitionLifetime) + .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())); + if (!StringUtils.isEmpty(destResourceName)) { + request.name(destResourceName); + } + if (!StringUtils.isEmpty(destDatasetName)) { + request.destinationDatasetName(destDatasetName); + } + + MockHttpServletResponse response = + mockMvc + .perform( + MockMvcUtils.addJsonContentType( + MockMvcUtils.addAuth( + post(CLONE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT.formatted( + sourceWorkspaceId, sourceResourceId)) + .content(objectMapper.writeValueAsString(request)), + userRequest))) + .andExpect(status().is(MockMvcUtils.getExpectedCodesMatcher(expectedCodes))) + .andReturn() + .getResponse(); + + // Disable the debug info post flight + jobService.setFlightDebugInfoForTest(null); + if (mockMvcUtils.isErrorResponse(response)) { + return null; + } + + String serializedResponse = response.getContentAsString(); + return objectMapper.readValue( + serializedResponse, ApiCloneControlledGcpBigQueryDatasetResult.class); + } + + public ApiErrorReport cloneControlledBqDatasetAndExpectError( + AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId, int expectedCode) + throws Exception { + // While job is running, cloneBigQueryDataset returns ApiCloneControlledGcpBigQueryDatasetResult + // After job fails, cloneBigQueryDataset returns ApiCloneControlledGcpBigQueryDatasetResult OR + // ApiErrorReport. + ApiCloneControlledGcpBigQueryDatasetResult result = + mockMvcUtils.getCreateResourceJobResult( + ApiCloneControlledGcpBigQueryDatasetResult.class, + userRequest, + CLONE_RESULT_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, + workspaceId, + jobId); + + ApiErrorReport errorReport; + while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { + Thread.sleep(/*millis=*/ 3000); + String serializedResponse = + mockMvcUtils.getSerializedResponseForGetJobResult_error( + userRequest, CLONE_RESULT_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, workspaceId, jobId); + try { + result = + objectMapper.readValue( + serializedResponse, ApiCloneControlledGcpBigQueryDatasetResult.class); + } catch (UnrecognizedPropertyException e) { + errorReport = objectMapper.readValue(serializedResponse, ApiErrorReport.class); + assertEquals(expectedCode, errorReport.getStatusCode()); + return errorReport; + } + } + // Job failed and cloneBigQueryData returned ApiCloneControlledGcpBigQueryDatasetResult + assertEquals(StatusEnum.FAILED, result.getJobReport().getStatus()); + return result.getErrorReport(); + } + + // BQ Dataset (Referenced) + public static final String CREATE_REFERENCED_GCP_BQ_DATASETS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatasets"; + public static final String REFERENCED_GCP_BQ_DATASET_PATH_FORMAT = + CREATE_REFERENCED_GCP_BQ_DATASETS_PATH_FORMAT + "/%s"; + public static final String CLONE_REFERENCED_GCP_BQ_DATASET_PATH_FORMAT = + REFERENCED_GCP_BQ_DATASET_PATH_FORMAT + "/clone"; + + public ApiGcpBigQueryDatasetResource createReferencedBqDataset( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String resourceName, + String projectId, + String datasetName) + throws Exception { + ApiGcpBigQueryDatasetAttributes creationParameters = + new ApiGcpBigQueryDatasetAttributes().projectId(projectId).datasetId(datasetName); + ApiCreateGcpBigQueryDatasetReferenceRequestBody request = + new ApiCreateGcpBigQueryDatasetReferenceRequestBody() + .metadata( + ReferenceResourceFixtures.makeDefaultReferencedResourceFieldsApi() + .name(resourceName)) + .dataset(creationParameters); + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_REFERENCED_GCP_BQ_DATASETS_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); + } + + public ApiGcpBigQueryDatasetResource getReferencedBqDataset( + AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { + return getBqDataset( + userRequest, workspaceId, resourceId, REFERENCED_GCP_BQ_DATASET_PATH_FORMAT); + } + + public ApiGcpBigQueryDatasetResource updateReferencedBqDataset( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + UUID resourceId, + String newName, + String newDescription, + ApiCloningInstructionsEnum newCloningInstruction, + String newBqDataset) + throws Exception { + ApiUpdateBigQueryDatasetReferenceRequestBody requestBody = + new ApiUpdateBigQueryDatasetReferenceRequestBody() + .name(newName) + .description(newDescription) + .cloningInstructions(newCloningInstruction) + .datasetId(newBqDataset); + var serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + String.format(REFERENCED_GCP_BQ_DATASET_PATH_FORMAT, workspaceId, resourceId), + objectMapper.writeValueAsString(requestBody)); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); + } + + public ApiGcpBigQueryDatasetResource cloneReferencedBqDataset( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName) + throws Exception { + return cloneReferencedBqDatasetAndExpect( + userRequest, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + HttpStatus.SC_OK); + } + + public ApiGcpBigQueryDatasetResource cloneReferencedBqDatasetAndExpect( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName, + int expectedCode) + throws Exception { + MockHttpServletResponse response = + mockMvcUtils.cloneReferencedResource( + userRequest, + CLONE_REFERENCED_GCP_BQ_DATASET_PATH_FORMAT, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + expectedCode); + if (mockMvcUtils.isErrorResponse(response)) { + return null; + } + + String serializedResponse = response.getContentAsString(); + return objectMapper + .readValue(serializedResponse, ApiCloneReferencedGcpBigQueryDatasetResourceResult.class) + .getResource(); + } + + // BQ Data Table + public static final String CREATE_REFERENCED_GCP_BQ_DATA_TABLES_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatatables"; + public static final String REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT = + CREATE_REFERENCED_GCP_BQ_DATA_TABLES_PATH_FORMAT + "/%s"; + public static final String CLONE_REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT = + REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT + "/clone"; + + public ApiGcpBigQueryDataTableResource createReferencedBqDataTable( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String resourceName, + String projectId, + String datasetName, + String tableId) + throws Exception { + ApiGcpBigQueryDataTableAttributes creationParameters = + new ApiGcpBigQueryDataTableAttributes() + .projectId(projectId) + .datasetId(datasetName) + .dataTableId(tableId); + ApiCreateGcpBigQueryDataTableReferenceRequestBody request = + new ApiCreateGcpBigQueryDataTableReferenceRequestBody() + .metadata( + ReferenceResourceFixtures.makeDefaultReferencedResourceFieldsApi() + .name(resourceName)) + .dataTable(creationParameters); + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_REFERENCED_GCP_BQ_DATA_TABLES_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); + } + + public void deleteBqDataTable( + AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { + mockMvcUtils.deleteResource( + userRequest, workspaceId, resourceId, REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT); + } + + public ApiGcpBigQueryDataTableResource getReferencedBqDataTable( + AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { + String serializedResponse = + mockMvcUtils.getSerializedResponseForGet( + userRequest, REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, workspaceId, resourceId); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); + } + + public ApiGcpBigQueryDataTableResource updateReferencedBqDataTable( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + UUID resourceId, + String newName, + String newDescription, + ApiCloningInstructionsEnum newCloningInstruction, + String newProjectId, + String newDataset, + String newTable) + throws Exception { + ApiUpdateBigQueryDataTableReferenceRequestBody requestBody = + new ApiUpdateBigQueryDataTableReferenceRequestBody() + .name(newName) + .description(newDescription) + .cloningInstructions(newCloningInstruction) + .projectId(newProjectId) + .datasetId(newDataset) + .dataTableId(newTable); + var serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + String.format(REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, workspaceId, resourceId), + objectMapper.writeValueAsString(requestBody)); + return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); + } + + public ApiGcpBigQueryDataTableResource cloneReferencedBqDataTable( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName) + throws Exception { + return cloneReferencedBqDataTableAndExpect( + userRequest, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + HttpStatus.SC_OK); + } + + public ApiGcpBigQueryDataTableResource cloneReferencedBqDataTableAndExpect( + AuthenticatedUserRequest userRequest, + UUID sourceWorkspaceId, + UUID sourceResourceId, + UUID destWorkspaceId, + ApiCloningInstructionsEnum cloningInstructions, + @Nullable String destResourceName, + int expectedCode) + throws Exception { + MockHttpServletResponse response = + mockMvcUtils.cloneReferencedResource( + userRequest, + CLONE_REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, + sourceWorkspaceId, + sourceResourceId, + destWorkspaceId, + cloningInstructions, + destResourceName, + expectedCode); + if (mockMvcUtils.isErrorResponse(response)) { + return null; + } + + String serializedResponse = response.getContentAsString(); + return objectMapper + .readValue(serializedResponse, ApiCloneReferencedGcpBigQueryDataTableResourceResult.class) + .getResource(); + } + + // AI Notebook + public static final String CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/controlled/gcp/ai-notebook-instances"; + public static final String GENERATE_NAME_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT + "/generateName"; + public static final String CREATE_RESULT_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT + "/create-result/%s"; + public static final String CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT + "/%s"; + + public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstance( + AuthenticatedUserRequest userRequest, UUID workspaceId, @Nullable String location) + throws Exception { + return createAiNotebookInstanceAndWait( + userRequest, workspaceId, /*instanceId=*/ null, location); + } + + public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstanceAndWait( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + @Nullable String instanceId, + @Nullable String location) + throws Exception { + return createAiNotebookInstanceAndExpect( + userRequest, workspaceId, instanceId, location, StatusEnum.SUCCEEDED); + } + + public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstanceAndExpect( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + @Nullable String instanceId, + @Nullable String location, + StatusEnum jobStatus) + throws Exception { + ApiCreateControlledGcpAiNotebookInstanceRequestBody request = + new ApiCreateControlledGcpAiNotebookInstanceRequestBody() + .common( + ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() + .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) + .name(TestUtils.appendRandomNumber("ai-notebook"))) + .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) + .aiNotebookInstance( + ControlledGcpResourceFixtures.defaultNotebookCreationParameters() + .location(location) + .instanceId( + Optional.ofNullable(instanceId) + .orElse(TestUtils.appendRandomNumber("instance-id")))); + + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + ApiCreatedControlledGcpAiNotebookInstanceResult result = + objectMapper.readValue( + serializedResponse, ApiCreatedControlledGcpAiNotebookInstanceResult.class); + + String jobId = result.getJobReport().getId(); + while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { + TimeUnit.SECONDS.sleep(5); + result = + mockMvcUtils.getCreateResourceJobResult( + ApiCreatedControlledGcpAiNotebookInstanceResult.class, + userRequest, + CREATE_RESULT_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT, + workspaceId, + jobId); + } + assertEquals(jobStatus, result.getJobReport().getStatus()); + + return result; + } + + // GCE Instance + public static final String CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/controlled/gcp/gce-instances"; + public static final String GENERATE_NAME_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT + "/generateName"; + public static final String CREATE_RESULT_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT + "/create-result/%s"; + public static final String CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT = + CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT + "/%s"; + + public ApiCreatedControlledGcpGceInstanceResult createGceInstance( + AuthenticatedUserRequest userRequest, UUID workspaceId, @Nullable String zone) + throws Exception { + return createGceInstanceAndWait(userRequest, workspaceId, /*instanceId=*/ null, zone); + } + + public ApiCreatedControlledGcpGceInstanceResult createGceInstanceAndWait( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + @Nullable String instanceId, + @Nullable String zone) + throws Exception { + return createGceInstanceAndExpect( + userRequest, workspaceId, instanceId, zone, StatusEnum.SUCCEEDED); + } + + public ApiCreatedControlledGcpGceInstanceResult createGceInstanceAndExpect( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + @Nullable String instanceId, + @Nullable String zone, + StatusEnum jobStatus) + throws Exception { + ApiCreateControlledGcpGceInstanceRequestBody request = + new ApiCreateControlledGcpGceInstanceRequestBody() + .common( + ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() + .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) + .name(TestUtils.appendRandomNumber("gce-instance"))) + .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) + .gceInstance( + ControlledGcpResourceFixtures.defaultGceInstanceCreationParameters() + .zone(zone) + .instanceId( + Optional.ofNullable(instanceId) + .orElse(TestUtils.appendRandomNumber("instance-id")))); + + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + ApiCreatedControlledGcpGceInstanceResult result = + objectMapper.readValue(serializedResponse, ApiCreatedControlledGcpGceInstanceResult.class); + + String jobId = result.getJobReport().getId(); + while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { + Thread.sleep(/*millis=*/ 5000); + result = + mockMvcUtils.getCreateResourceJobResult( + ApiCreatedControlledGcpGceInstanceResult.class, + userRequest, + CREATE_RESULT_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT, + workspaceId, + jobId); + } + assertEquals(jobStatus, result.getJobReport().getStatus()); + + return result; + } + + // DataProc Cluster + public static final String CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT = + "/api/workspaces/v1/%s/resources/controlled/gcp/dataproc-clusters"; + public static final String GENERATE_NAME_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT + "/generateName"; + public static final String CREATE_RESULT_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT + "/create-result/%s"; + public static final String CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT = + CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT + "/%s"; + + public ApiCreatedControlledGcpDataprocClusterResult createDataprocCluster( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String region, + UUID stagingBucketId, + UUID tempBucketId) + throws Exception { + return createDataprocClusterAndWait( + userRequest, workspaceId, region, stagingBucketId, tempBucketId, /*clusterId=*/ null); + } + + public ApiCreatedControlledGcpDataprocClusterResult createDataprocClusterAndWait( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String region, + UUID stagingBucketId, + UUID tempBucketId, + @Nullable String clusterId) + throws Exception { + return createDataprocClusterAndExpect( + userRequest, + workspaceId, + region, + stagingBucketId, + tempBucketId, + clusterId, + StatusEnum.SUCCEEDED); + } + + public ApiCreatedControlledGcpDataprocClusterResult createDataprocClusterAndExpect( + AuthenticatedUserRequest userRequest, + UUID workspaceId, + String region, + UUID stagingBucketId, + UUID tempBucketId, + @Nullable String clusterId, + StatusEnum jobStatus) + throws Exception { + ApiCreateControlledGcpDataprocClusterRequestBody request = + new ApiCreateControlledGcpDataprocClusterRequestBody() + .common( + ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() + .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) + .name(TestUtils.appendRandomNumber("dataproc-cluster"))) + .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) + .dataprocCluster( + ControlledGcpResourceFixtures.defaultDataprocClusterCreationParameters() + .region(region) + .clusterId( + Optional.ofNullable(clusterId) + .orElse(TestUtils.appendRandomNumber("cluster-id"))) + .configBucket(stagingBucketId) + .tempBucket(tempBucketId)); + + String serializedResponse = + mockMvcUtils.getSerializedResponseForPost( + userRequest, + CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT, + workspaceId, + objectMapper.writeValueAsString(request)); + ApiCreatedControlledGcpDataprocClusterResult result = + objectMapper.readValue( + serializedResponse, ApiCreatedControlledGcpDataprocClusterResult.class); + + String jobId = result.getJobReport().getId(); + while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { + Thread.sleep(/*millis=*/ 5000); + result = + mockMvcUtils.getCreateResourceJobResult( + ApiCreatedControlledGcpDataprocClusterResult.class, + userRequest, + CREATE_RESULT_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT, + workspaceId, + jobId); + } + assertEquals(jobStatus, result.getJobReport().getStatus()); + + return result; + } +} diff --git a/service/src/test/java/bio/terra/workspace/common/utils/MockMvcUtils.java b/service/src/test/java/bio/terra/workspace/common/utils/MockMvcUtils.java index c0db379ff6..c271e446a0 100644 --- a/service/src/test/java/bio/terra/workspace/common/utils/MockMvcUtils.java +++ b/service/src/test/java/bio/terra/workspace/common/utils/MockMvcUtils.java @@ -3,6 +3,16 @@ import static bio.terra.workspace.common.fixtures.ControlledResourceFixtures.DEFAULT_RESOURCE_PROPERTIES; import static bio.terra.workspace.common.fixtures.WorkspaceFixtures.DEFAULT_USER_EMAIL; import static bio.terra.workspace.common.fixtures.WorkspaceFixtures.DEFAULT_USER_SUBJECT_ID; +import static bio.terra.workspace.common.utils.MockGcpApi.CLONE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CLONE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CLONE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT; import static bio.terra.workspace.db.WorkspaceActivityLogDao.ACTIVITY_LOG_CHANGE_DETAILS_ROW_MAPPER; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; @@ -25,7 +35,6 @@ import bio.terra.stairway.StepStatus; import bio.terra.workspace.app.controller.shared.PropertiesUtils; import bio.terra.workspace.common.StairwayTestUtils; -import bio.terra.workspace.common.fixtures.ControlledGcpResourceFixtures; import bio.terra.workspace.common.fixtures.ControlledResourceFixtures; import bio.terra.workspace.common.fixtures.PolicyFixtures; import bio.terra.workspace.common.fixtures.ReferenceResourceFixtures; @@ -35,12 +44,8 @@ import bio.terra.workspace.generated.model.ApiAccessScope; import bio.terra.workspace.generated.model.ApiCloneControlledFlexibleResourceRequest; import bio.terra.workspace.generated.model.ApiCloneControlledFlexibleResourceResult; -import bio.terra.workspace.generated.model.ApiCloneControlledGcpBigQueryDatasetRequest; -import bio.terra.workspace.generated.model.ApiCloneControlledGcpBigQueryDatasetResult; import bio.terra.workspace.generated.model.ApiCloneControlledGcpGcsBucketRequest; import bio.terra.workspace.generated.model.ApiCloneControlledGcpGcsBucketResult; -import bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult; -import bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult; import bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult; import bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult; import bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsObjectResourceResult; @@ -55,23 +60,13 @@ import bio.terra.workspace.generated.model.ApiCreateCloudContextRequest; import bio.terra.workspace.generated.model.ApiCreateCloudContextResult; import bio.terra.workspace.generated.model.ApiCreateControlledFlexibleResourceRequestBody; -import bio.terra.workspace.generated.model.ApiCreateControlledGcpAiNotebookInstanceRequestBody; -import bio.terra.workspace.generated.model.ApiCreateControlledGcpBigQueryDatasetRequestBody; -import bio.terra.workspace.generated.model.ApiCreateControlledGcpDataprocClusterRequestBody; -import bio.terra.workspace.generated.model.ApiCreateControlledGcpGceInstanceRequestBody; import bio.terra.workspace.generated.model.ApiCreateControlledGcpGcsBucketRequestBody; import bio.terra.workspace.generated.model.ApiCreateDataRepoSnapshotReferenceRequestBody; -import bio.terra.workspace.generated.model.ApiCreateGcpBigQueryDataTableReferenceRequestBody; -import bio.terra.workspace.generated.model.ApiCreateGcpBigQueryDatasetReferenceRequestBody; import bio.terra.workspace.generated.model.ApiCreateGcpGcsBucketReferenceRequestBody; import bio.terra.workspace.generated.model.ApiCreateGcpGcsObjectReferenceRequestBody; import bio.terra.workspace.generated.model.ApiCreateGitRepoReferenceRequestBody; import bio.terra.workspace.generated.model.ApiCreateWorkspaceRequestBody; import bio.terra.workspace.generated.model.ApiCreatedControlledFlexibleResource; -import bio.terra.workspace.generated.model.ApiCreatedControlledGcpAiNotebookInstanceResult; -import bio.terra.workspace.generated.model.ApiCreatedControlledGcpBigQueryDataset; -import bio.terra.workspace.generated.model.ApiCreatedControlledGcpDataprocClusterResult; -import bio.terra.workspace.generated.model.ApiCreatedControlledGcpGceInstanceResult; import bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket; import bio.terra.workspace.generated.model.ApiCreatedWorkspace; import bio.terra.workspace.generated.model.ApiDataRepoSnapshotAttributes; @@ -81,12 +76,7 @@ import bio.terra.workspace.generated.model.ApiFlexibleResource; import bio.terra.workspace.generated.model.ApiFlexibleResourceAttributes; import bio.terra.workspace.generated.model.ApiFlexibleResourceUpdateParameters; -import bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableAttributes; -import bio.terra.workspace.generated.model.ApiGcpBigQueryDataTableResource; -import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetAttributes; -import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetCreationParameters; import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetResource; -import bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetUpdateParameters; import bio.terra.workspace.generated.model.ApiGcpGcsBucketAttributes; import bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters; import bio.terra.workspace.generated.model.ApiGcpGcsBucketDefaultStorageClass; @@ -116,10 +106,7 @@ import bio.terra.workspace.generated.model.ApiResourceType; import bio.terra.workspace.generated.model.ApiState; import bio.terra.workspace.generated.model.ApiStewardshipType; -import bio.terra.workspace.generated.model.ApiUpdateBigQueryDataTableReferenceRequestBody; -import bio.terra.workspace.generated.model.ApiUpdateBigQueryDatasetReferenceRequestBody; import bio.terra.workspace.generated.model.ApiUpdateControlledFlexibleResourceRequestBody; -import bio.terra.workspace.generated.model.ApiUpdateControlledGcpBigQueryDatasetRequestBody; import bio.terra.workspace.generated.model.ApiUpdateControlledGcpGcsBucketRequestBody; import bio.terra.workspace.generated.model.ApiUpdateDataRepoSnapshotReferenceRequestBody; import bio.terra.workspace.generated.model.ApiUpdateGcsBucketObjectReferenceRequestBody; @@ -146,12 +133,7 @@ import bio.terra.workspace.service.resource.controlled.flight.clone.bucket.SetReferencedDestinationGcsBucketInWorkingMapStep; import bio.terra.workspace.service.resource.controlled.flight.clone.bucket.SetReferencedDestinationGcsBucketResponseStep; import bio.terra.workspace.service.resource.controlled.flight.clone.bucket.TransferGcsBucketToGcsBucketStep; -import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.CompleteTableCopyJobsStep; -import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.CreateTableCopyJobsStep; -import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.SetReferencedDestinationBigQueryDatasetInWorkingMapStep; -import bio.terra.workspace.service.resource.controlled.flight.clone.dataset.SetReferencedDestinationBigQueryDatasetResponseStep; import bio.terra.workspace.service.resource.controlled.flight.update.RetrieveControlledResourceMetadataStep; -import bio.terra.workspace.service.resource.controlled.model.AccessScopeType; import bio.terra.workspace.service.resource.model.StewardshipType; import bio.terra.workspace.service.resource.model.WsmResourceType; import bio.terra.workspace.service.resource.referenced.flight.create.CreateReferenceMetadataStep; @@ -241,88 +223,18 @@ public class MockMvcUtils { "/api/workspaces/v1/%s/cloudcontexts/GCP"; public static final String GET_CLOUD_CONTEXT_PATH_FORMAT = "/api/workspaces/v1/%s/cloudcontexts/result/%s"; - public static final String GET_REFERENCED_GCP_GCS_BUCKET_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/buckets/%s"; - public static final String CLONE_CONTROLLED_GCP_GCS_BUCKET_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/buckets/%s/clone"; - public static final String CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKET_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/buckets/clone-result/%s"; - public static final String GENERATE_GCP_GCS_BUCKET_NAME_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/buckets/generateName"; - public static final String GENERATE_GCP_BQ_DATASET_NAME_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets/generateName"; - public static final String GENERATE_GCP_AI_NOTEBOOK_NAME_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/ai-notebook-instances/generateName"; - public static final String GENERATE_GCP_GCE_INSTANCE_NAME_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/gce-instances/generateName"; - public static final String GENERATE_GCP_DATAPROC_CLUSTER_NAME_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/dataproc-clusters/generateName"; public static final String FOLDERS_V1_PATH_FORMAT = "/api/workspaces/v1/%s/folders"; public static final String FOLDER_V1_PATH_FORMAT = "/api/workspaces/v1/%s/folders/%s"; public static final String FOLDER_PROPERTIES_V1_PATH_FORMAT = "/api/workspaces/v1/%s/folders/%s/properties"; public static final String RESOURCE_PROPERTIES_V1_PATH_FORMAT = "/api/workspaces/v1/%s/resources/%s/properties"; - public static final String CONTROLLED_GCP_AI_NOTEBOOKS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/ai-notebook-instances"; - public static final String CONTROLLED_GCP_AI_NOTEBOOK_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/ai-notebook-instances/%s"; - public static final String CONTROLLED_GCP_AI_NOTEBOOKS_V1_RESULT_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/ai-notebook-instances/create-result/%s"; - public static final String CONTROLLED_GCP_GCE_INSTANCES_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/gce-instances"; - public static final String CONTROLLED_GCP_GCE_INSTANCE_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/gce-instances/%s"; - public static final String CONTROLLED_GCP_GCE_INSTANCES_V1_RESULT_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/gce-instances/create-result/%s"; - public static final String CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/dataproc-clusters"; - public static final String CONTROLLED_GCP_DATAPROC_CLUSTER_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/dataproc-clusters/%s"; - public static final String CONTROLLED_GCP_DATAPROC_CLUSTERS_RESULT_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/dataproc-clusters/create-result/%s"; - public static final String CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets"; - public static final String CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets/%s"; - public static final String CLONE_CONTROLLED_GCP_BIG_QUERY_DATASET_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets/%s/clone"; - public static final String CLONE_RESULT_CONTROLLED_GCP_BIG_QUERY_DATASET_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/bqdatasets/clone-result/%s"; - public static final String CONTROLLED_GCP_GCS_BUCKETS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/buckets"; - public static final String CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/controlled/gcp/buckets/%s"; public static final String REFERENCED_DATA_REPO_SNAPSHOTS_V1_PATH_FORMAT = "/api/workspaces/v1/%s/resources/referenced/datarepo/snapshots"; public static final String REFERENCED_DATA_REPO_SNAPSHOT_V1_PATH_FORMAT = "/api/workspaces/v1/%s/resources/referenced/datarepo/snapshots/%s"; public static final String CLONE_REFERENCED_DATA_REPO_SNAPSHOT_V1_PATH_FORMAT = "/api/workspaces/v1/%s/resources/referenced/datarepo/snapshots/%s/clone"; - public static final String REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/buckets"; - public static final String REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/buckets/%s"; - public static final String CLONE_REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/buckets/%s/clone"; - public static final String REFERENCED_GCP_GCS_OBJECTS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bucket/objects"; - public static final String REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bucket/objects/%s"; - public static final String CLONE_REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bucket/objects/%s/clone"; - public static final String REFERENCED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatasets"; - public static final String REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatasets/%s"; - public static final String CLONE_REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatasets/%s/clone"; - public static final String REFERENCED_GCP_BIG_QUERY_DATA_TABLES_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatatables"; - public static final String REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatatables/%s"; - public static final String CLONE_REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT = - "/api/workspaces/v1/%s/resources/referenced/gcp/bigquerydatatables/%s/clone"; public static final String REFERENCED_GIT_REPOS_V1_PATH_FORMAT = "/api/workspaces/v1/%s/resources/referenced/gitrepos"; public static final String REFERENCED_GIT_REPO_V1_PATH_FORMAT = @@ -339,10 +251,7 @@ public class MockMvcUtils { "/api/workspaces/v1/%s/resources/controlled/any/flexibleResources/%s/clone"; public static final String UPDATE_POLICIES_PATH_FORMAT = "/api/workspaces/v1/%s/policies"; public static final String POLICY_V1_GET_REGION_INFO_PATH = "/api/policies/v1/getLocationInfo"; - public static final String LOAD_SIGNED_URL_LIST_PATH_FORMAT = - "/api/workspaces/alpha1/%s/resources/controlled/gcp/buckets/%s/load"; - public static final String LOAD_SIGNED_URL_LIST_RESULT_PATH_FORMAT = - "/api/workspaces/alpha1/%s/resources/controlled/gcp/buckets/%s/load/result/%s"; + // Only use this if you are mocking SAM. If you're using real SAM, // use userAccessUtils.defaultUserAuthRequest() instead. public static final AuthenticatedUserRequest USER_REQUEST = @@ -827,295 +736,14 @@ public void assertWorkspace( assertEquals(expectedLastUpdatedByEmail, actualWorkspace.getLastUpdatedBy()); } - public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstance( - AuthenticatedUserRequest userRequest, UUID workspaceId, @Nullable String location) - throws Exception { - return createAiNotebookInstanceAndWait( - userRequest, workspaceId, /*instanceId=*/ null, location); - } - - public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstanceAndWait( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - @Nullable String instanceId, - @Nullable String location) - throws Exception { - return createAiNotebookInstanceAndExpect( - userRequest, workspaceId, instanceId, location, StatusEnum.SUCCEEDED); - } - - public ApiCreatedControlledGcpAiNotebookInstanceResult createAiNotebookInstanceAndExpect( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - @Nullable String instanceId, - @Nullable String location, - StatusEnum jobStatus) - throws Exception { - ApiCreateControlledGcpAiNotebookInstanceRequestBody request = - new ApiCreateControlledGcpAiNotebookInstanceRequestBody() - .common( - ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() - .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) - .name(TestUtils.appendRandomNumber("ai-notebook"))) - .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) - .aiNotebookInstance( - ControlledGcpResourceFixtures.defaultNotebookCreationParameters() - .location(location) - .instanceId( - Optional.ofNullable(instanceId) - .orElse(TestUtils.appendRandomNumber("instance-id")))); - - String serializedResponse = - getSerializedResponseForPost( - userRequest, - CONTROLLED_GCP_AI_NOTEBOOKS_V1_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - ApiCreatedControlledGcpAiNotebookInstanceResult result = - objectMapper.readValue( - serializedResponse, ApiCreatedControlledGcpAiNotebookInstanceResult.class); - String jobId = result.getJobReport().getId(); - while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { - TimeUnit.SECONDS.sleep(5); - result = getAiNotebookInstanceResult(userRequest, workspaceId, jobId); - } - assertEquals(jobStatus, result.getJobReport().getStatus()); - - return result; - } - - private ApiCreatedControlledGcpAiNotebookInstanceResult getAiNotebookInstanceResult( - AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId) throws Exception { - String serializedResponse = - getSerializedResponseForGetJobResult( - userRequest, CONTROLLED_GCP_AI_NOTEBOOKS_V1_RESULT_PATH_FORMAT, workspaceId, jobId); - return objectMapper.readValue( - serializedResponse, ApiCreatedControlledGcpAiNotebookInstanceResult.class); - } - - public ApiCreatedControlledGcpGceInstanceResult createGceInstance( - AuthenticatedUserRequest userRequest, UUID workspaceId, @Nullable String zone) - throws Exception { - return createGceInstanceAndWait(userRequest, workspaceId, /*instanceId=*/ null, zone); - } - - public ApiCreatedControlledGcpGceInstanceResult createGceInstanceAndWait( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - @Nullable String instanceId, - @Nullable String zone) - throws Exception { - return createGceInstanceAndExpect( - userRequest, workspaceId, instanceId, zone, StatusEnum.SUCCEEDED); - } - - public ApiCreatedControlledGcpGceInstanceResult createGceInstanceAndExpect( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - @Nullable String instanceId, - @Nullable String zone, - StatusEnum jobStatus) - throws Exception { - ApiCreateControlledGcpGceInstanceRequestBody request = - new ApiCreateControlledGcpGceInstanceRequestBody() - .common( - ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() - .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) - .name(TestUtils.appendRandomNumber("gce-instance"))) - .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) - .gceInstance( - ControlledGcpResourceFixtures.defaultGceInstanceCreationParameters() - .zone(zone) - .instanceId( - Optional.ofNullable(instanceId) - .orElse(TestUtils.appendRandomNumber("instance-id")))); - - String serializedResponse = - getSerializedResponseForPost( - userRequest, - CONTROLLED_GCP_GCE_INSTANCES_V1_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - ApiCreatedControlledGcpGceInstanceResult result = - objectMapper.readValue(serializedResponse, ApiCreatedControlledGcpGceInstanceResult.class); - String jobId = result.getJobReport().getId(); - while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { - Thread.sleep(/*millis=*/ 5000); - result = getGceInstanceResult(userRequest, workspaceId, jobId); - } - assertEquals(jobStatus, result.getJobReport().getStatus()); - - return result; - } - - private ApiCreatedControlledGcpGceInstanceResult getGceInstanceResult( - AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId) throws Exception { - String serializedResponse = - getSerializedResponseForGetJobResult( - userRequest, CONTROLLED_GCP_GCE_INSTANCES_V1_RESULT_PATH_FORMAT, workspaceId, jobId); - return objectMapper.readValue( - serializedResponse, ApiCreatedControlledGcpGceInstanceResult.class); - } - - public ApiCreatedControlledGcpDataprocClusterResult createDataprocCluster( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String region, - UUID stagingBucketId, - UUID tempBucketId) - throws Exception { - return createDataprocClusterAndWait( - userRequest, workspaceId, region, stagingBucketId, tempBucketId, /*clusterId=*/ null); - } - - public ApiCreatedControlledGcpDataprocClusterResult createDataprocClusterAndWait( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String region, - UUID stagingBucketId, - UUID tempBucketId, - @Nullable String clusterId) - throws Exception { - return createDataprocClusterAndExpect( - userRequest, - workspaceId, - region, - stagingBucketId, - tempBucketId, - clusterId, - StatusEnum.SUCCEEDED); - } - - public ApiCreatedControlledGcpDataprocClusterResult createDataprocClusterAndExpect( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String region, - UUID stagingBucketId, - UUID tempBucketId, - @Nullable String clusterId, - StatusEnum jobStatus) - throws Exception { - ApiCreateControlledGcpDataprocClusterRequestBody request = - new ApiCreateControlledGcpDataprocClusterRequestBody() - .common( - ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() - .accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE.toApiModel()) - .name(TestUtils.appendRandomNumber("dataproc-cluster"))) - .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())) - .dataprocCluster( - ControlledGcpResourceFixtures.defaultDataprocClusterCreationParameters() - .region(region) - .clusterId( - Optional.ofNullable(clusterId) - .orElse(TestUtils.appendRandomNumber("cluster-id"))) - .configBucket(stagingBucketId) - .tempBucket(tempBucketId)); - - String serializedResponse = - getSerializedResponseForPost( - userRequest, - CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - ApiCreatedControlledGcpDataprocClusterResult result = - objectMapper.readValue( - serializedResponse, ApiCreatedControlledGcpDataprocClusterResult.class); - String jobId = result.getJobReport().getId(); - while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { - Thread.sleep(/*millis=*/ 5000); - result = getDataprocClusterResult(userRequest, workspaceId, jobId); - } - assertEquals(jobStatus, result.getJobReport().getStatus()); - - return result; - } - - private ApiCreatedControlledGcpDataprocClusterResult getDataprocClusterResult( - AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId) throws Exception { - String serializedResponse = - getSerializedResponseForGetJobResult( - userRequest, CONTROLLED_GCP_DATAPROC_CLUSTERS_RESULT_PATH_FORMAT, workspaceId, jobId); - return objectMapper.readValue( - serializedResponse, ApiCreatedControlledGcpDataprocClusterResult.class); - } - - public ApiCreatedControlledGcpBigQueryDataset createControlledBqDataset( - AuthenticatedUserRequest userRequest, UUID workspaceId) throws Exception { - return createControlledBqDataset( - userRequest, - workspaceId, - /*resourceName=*/ TestUtils.appendRandomNumber("resource-name"), - /*datasetName=*/ TestUtils.appendRandomNumber("dataset-name"), - /*location=*/ null, - /*defaultTableLifetime=*/ null, - /*defaultPartitionTableLifetime=*/ null); - } - - public ApiCreatedControlledGcpBigQueryDataset createControlledBqDataset( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String resourceName, - String datasetName, - @Nullable String location, - @Nullable Long defaultTableLifetime, - @Nullable Long defaultPartitionLifetime) - throws Exception { - ApiGcpBigQueryDatasetCreationParameters creationParameters = - new ApiGcpBigQueryDatasetCreationParameters().datasetId(datasetName); - if (location != null) { - creationParameters.setLocation(location); - } - if (defaultTableLifetime != null) { - creationParameters.setDefaultTableLifetime(defaultTableLifetime); - } - if (defaultPartitionLifetime != null) { - creationParameters.defaultPartitionLifetime(defaultPartitionLifetime); - } - ApiCreateControlledGcpBigQueryDatasetRequestBody request = - new ApiCreateControlledGcpBigQueryDatasetRequestBody() - .common( - ControlledResourceFixtures.makeDefaultControlledResourceFieldsApi() - .name(resourceName)) - .dataset(creationParameters); - - String serializedResponse = - getSerializedResponseForPost( - userRequest, - CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - return objectMapper.readValue(serializedResponse, ApiCreatedControlledGcpBigQueryDataset.class); - } - - public void deleteBqDataset( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - UUID resourceId, - StewardshipType stewardshipType) - throws Exception { - deleteResource( - userRequest, - workspaceId, - resourceId, - StewardshipType.CONTROLLED.equals(stewardshipType) - ? CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT - : REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT); - } - - public void deleteBqDataTable( - AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - deleteResource( - userRequest, workspaceId, resourceId, REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT); - } - public void deleteReferencedGcsBucket( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - deleteResource(userRequest, workspaceId, resourceId, REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT); + deleteResource(userRequest, workspaceId, resourceId, REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT); } public void deleteGcsObject( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - deleteResource(userRequest, workspaceId, resourceId, REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT); + deleteResource(userRequest, workspaceId, resourceId, REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT); } public void deleteDataRepoSnapshot( @@ -1129,7 +757,7 @@ public void deleteGitRepo(AuthenticatedUserRequest userRequest, UUID workspaceId deleteResource(userRequest, workspaceId, resourceId, REFERENCED_GIT_REPO_V1_PATH_FORMAT); } - private void deleteResource( + public void deleteResource( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId, String path) throws Exception { mockMvc @@ -1137,279 +765,6 @@ private void deleteResource( .andExpect(status().is(HttpStatus.SC_NO_CONTENT)); } - public ApiGcpBigQueryDatasetResource getControlledBqDataset( - AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - return getBqDataset( - userRequest, workspaceId, resourceId, CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT); - } - - public ApiGcpBigQueryDatasetResource updateControlledBqDataset( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - UUID resourceId, - String newName, - String newDescription, - ApiCloningInstructionsEnum newCloningInstruction) - throws Exception { - ApiUpdateControlledGcpBigQueryDatasetRequestBody requestBody = - new ApiUpdateControlledGcpBigQueryDatasetRequestBody() - .name(newName) - .description(newDescription) - .updateParameters( - new ApiGcpBigQueryDatasetUpdateParameters() - .cloningInstructions(newCloningInstruction)); - return updateResource( - ApiGcpBigQueryDatasetResource.class, - CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, - workspaceId, - resourceId, - objectMapper.writeValueAsString(requestBody), - userRequest, - HttpStatus.SC_OK); - } - - private ApiGcpBigQueryDatasetResource getBqDataset( - AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId, String path) - throws Exception { - String serializedResponse = - getSerializedResponseForGet(userRequest, path, workspaceId, resourceId); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); - } - - public ApiGcpBigQueryDatasetResource cloneControlledBqDataset( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - @Nullable String destDatasetName) - throws Exception { - return cloneControlledBqDataset( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - destDatasetName, - /*location=*/ null, - /*defaultTableLifetime=*/ null, - /*defaultPartitionLifetime=*/ null); - } - - /** Call cloneBigQueryDataset() and wait for flight to finish. */ - public ApiGcpBigQueryDatasetResource cloneControlledBqDataset( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - @Nullable String destDatasetName, - @Nullable String destLocation, - @Nullable Long defaultTableLifetime, - @Nullable Long defaultPartitionLifetime) - throws Exception { - ApiCloneControlledGcpBigQueryDatasetResult result = - cloneControlledBqDatasetAsync( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - destDatasetName, - destLocation, - defaultTableLifetime, - defaultPartitionLifetime, - // clone_copyNothing sometimes returns SC_OK, even for the initial call. So accept both - // to avoid flakes. - JOB_SUCCESS_CODES, - /*shouldUndo=*/ false); - String jobId = result.getJobReport().getId(); - while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { - Thread.sleep(/*millis=*/ 5000); - result = getCloneControlledBqDatasetResult(userRequest, sourceWorkspaceId, jobId); - } - assertEquals(StatusEnum.SUCCEEDED, result.getJobReport().getStatus()); - logger.info( - "Controlled BQ dataset clone of resource %s completed. ".formatted(sourceResourceId)); - return result.getDataset().getDataset(); - } - - /** Call cloneBigQueryDataset(), wait for flight to finish, return JobError. */ - public ApiErrorReport cloneControlledBqDataset_jobError( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - @Nullable String destDatasetName, - int expectedCode) - throws Exception { - ApiCloneControlledGcpBigQueryDatasetResult result = - cloneControlledBqDatasetAsync( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - destDatasetName, - /*destLocation=*/ null, - /*defaultTableLifetime=*/ null, - /*defaultPartitionLifetime=*/ null, - List.of(HttpStatus.SC_ACCEPTED), - /*shouldUndo=*/ false); - return cloneControlledBqDataset_waitForJobError( - userRequest, sourceWorkspaceId, result.getJobReport().getId(), expectedCode); - } - - public void cloneControlledBqDataset_undo( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - String destResourceName) - throws Exception { - ApiCloneControlledGcpBigQueryDatasetResult result = - cloneControlledBqDatasetAsync( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - /*destDatasetName=*/ null, - /*destLocation=*/ null, - /*defaultTableLifetime=*/ null, - /*defaultPartitionLifetime=*/ null, - List.of(HttpStatus.SC_ACCEPTED), - /*shouldUndo=*/ true); - cloneControlledBqDataset_waitForJobError( - userRequest, - sourceWorkspaceId, - result.getJobReport().getId(), - HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - - /** Call cloneBigQueryDataset() and return immediately; don't wait for flight to finish. */ - public ApiCloneControlledGcpBigQueryDatasetResult cloneControlledBqDatasetAsync( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - @Nullable String destDatasetName, - @Nullable String destLocation, - @Nullable Long defaultTableLifetime, - @Nullable Long defaultPartitionLifetime, - List expectedCodes, - boolean shouldUndo) - throws Exception { - // Retry to ensure steps are idempotent - Map retryableStepsMap = new HashMap<>(); - List> retryableSteps = - ImmutableList.of( - CheckControlledResourceAuthStep.class, - SetReferencedDestinationBigQueryDatasetInWorkingMapStep.class, - CreateReferenceMetadataStep.class, - SetReferencedDestinationBigQueryDatasetResponseStep.class, - CreateTableCopyJobsStep.class, - CompleteTableCopyJobsStep.class); - retryableSteps.forEach( - step -> retryableStepsMap.put(step.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY)); - jobService.setFlightDebugInfoForTest( - FlightDebugInfo.newBuilder() - .doStepFailures(retryableStepsMap) - .lastStepFailure(shouldUndo) - .build()); - - ApiCloneControlledGcpBigQueryDatasetRequest request = - new ApiCloneControlledGcpBigQueryDatasetRequest() - .destinationWorkspaceId(destWorkspaceId) - .cloningInstructions(cloningInstructions) - .location(destLocation) - .defaultTableLifetime(defaultTableLifetime) - .defaultPartitionLifetime(defaultPartitionLifetime) - .jobControl(new ApiJobControl().id(UUID.randomUUID().toString())); - if (!StringUtils.isEmpty(destResourceName)) { - request.name(destResourceName); - } - if (!StringUtils.isEmpty(destDatasetName)) { - request.destinationDatasetName(destDatasetName); - } - - MockHttpServletResponse response = - mockMvc - .perform( - addJsonContentType( - addAuth( - post(CLONE_CONTROLLED_GCP_BIG_QUERY_DATASET_FORMAT.formatted( - sourceWorkspaceId, sourceResourceId)) - .content(objectMapper.writeValueAsString(request)), - userRequest))) - .andExpect(status().is(getExpectedCodesMatcher(expectedCodes))) - .andReturn() - .getResponse(); - - // Disable the debug info post flight - jobService.setFlightDebugInfoForTest(null); - - if (isErrorResponse(response)) { - return null; - } - - String serializedResponse = response.getContentAsString(); - return objectMapper.readValue( - serializedResponse, ApiCloneControlledGcpBigQueryDatasetResult.class); - } - - private ApiErrorReport cloneControlledBqDataset_waitForJobError( - AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId, int expectedCode) - throws Exception { - // While job is running, cloneBigQueryDataset returns ApiCloneControlledGcpBigQueryDatasetResult - // After job fails, cloneBigQueryData returns ApiCloneControlledGcpBigQueryDatasetResult OR - // ApiErrorReport. - ApiCloneControlledGcpBigQueryDatasetResult result = - getCloneControlledBqDatasetResult(userRequest, workspaceId, jobId); - ApiErrorReport errorReport; - while (StairwayTestUtils.jobIsRunning(result.getJobReport())) { - Thread.sleep(/*millis=*/ 3000); - String serializedResponse = - getSerializedResponseForGetJobResult_error( - userRequest, - CLONE_RESULT_CONTROLLED_GCP_BIG_QUERY_DATASET_FORMAT, - workspaceId, - jobId); - try { - result = - objectMapper.readValue( - serializedResponse, ApiCloneControlledGcpBigQueryDatasetResult.class); - } catch (UnrecognizedPropertyException e) { - errorReport = objectMapper.readValue(serializedResponse, ApiErrorReport.class); - assertEquals(expectedCode, errorReport.getStatusCode()); - return errorReport; - } - } - // Job failed and cloneBigQueryData returned ApiCloneControlledGcpBigQueryDatasetResult - assertEquals(StatusEnum.FAILED, result.getJobReport().getStatus()); - return result.getErrorReport(); - } - - private ApiCloneControlledGcpBigQueryDatasetResult getCloneControlledBqDatasetResult( - AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId) throws Exception { - String serializedResponse = - getSerializedResponseForGetJobResult( - userRequest, CLONE_RESULT_CONTROLLED_GCP_BIG_QUERY_DATASET_FORMAT, workspaceId, jobId); - return objectMapper.readValue( - serializedResponse, ApiCloneControlledGcpBigQueryDatasetResult.class); - } - public ApiCreatedControlledGcpGcsBucket createControlledGcsBucket( AuthenticatedUserRequest userRequest, UUID workspaceId, @@ -1434,7 +789,7 @@ public ApiCreatedControlledGcpGcsBucket createControlledGcsBucket( String serializedResponse = getSerializedResponseForPost( userRequest, - CONTROLLED_GCP_GCS_BUCKETS_V1_PATH_FORMAT, + CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, objectMapper.writeValueAsString(request)); return objectMapper.readValue(serializedResponse, ApiCreatedControlledGcpGcsBucket.class); @@ -1444,7 +799,7 @@ public ApiGcpGcsBucketResource getControlledGcsBucket( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { String serializedGetResponse = getSerializedResponseForGet( - userRequest, CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT, workspaceId, resourceId); + userRequest, CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, resourceId); return objectMapper.readValue(serializedGetResponse, ApiGcpGcsBucketResource.class); } @@ -1464,7 +819,7 @@ public ApiGcpGcsBucketResource updateControlledGcsBucket( new ApiGcpGcsBucketUpdateParameters().cloningInstructions(newCloningInstruction)); return updateResource( ApiGcpGcsBucketResource.class, - CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, resourceId, objectMapper.writeValueAsString(requestBody), @@ -1558,7 +913,7 @@ public void cloneControlledGcsBucket_undo( // to avoid flakes. JOB_SUCCESS_CODES, /*shouldUndo=*/ true); - cloneControlledBqDataset_waitForJobError( + cloneControlledGcsBucket_waitForJobError( userRequest, sourceWorkspaceId, result.getJobReport().getId(), @@ -1622,7 +977,7 @@ public ApiCloneControlledGcpGcsBucketResult cloneControlledGcsBucketAsync( .perform( addJsonContentType( addAuth( - post(CLONE_CONTROLLED_GCP_GCS_BUCKET_FORMAT.formatted( + post(CLONE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT.formatted( sourceWorkspaceId, sourceResourceId)) .content(objectMapper.writeValueAsString(request)), userRequest))) @@ -1651,7 +1006,7 @@ private ApiErrorReport cloneControlledGcsBucket_waitForJobError( Thread.sleep(/*millis=*/ 3000); String serializedResponse = getSerializedResponseForGetJobResult_error( - userRequest, CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKET_FORMAT, workspaceId, jobId); + userRequest, CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, jobId); try { result = objectMapper.readValue(serializedResponse, ApiCloneControlledGcpGcsBucketResult.class); @@ -1670,7 +1025,7 @@ private ApiCloneControlledGcpGcsBucketResult getCloneControlledGcsBucketResult( AuthenticatedUserRequest userRequest, UUID workspaceId, String jobId) throws Exception { String serializedResponse = getSerializedResponseForGetJobResult( - userRequest, CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKET_FORMAT, workspaceId, jobId); + userRequest, CLONE_RESULT_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, jobId); return objectMapper.readValue(serializedResponse, ApiCloneControlledGcpGcsBucketResult.class); } @@ -2038,222 +1393,6 @@ public ApiDataRepoSnapshotResource cloneReferencedDataRepoSnapshot( .getResource(); } - public ApiGcpBigQueryDatasetResource createReferencedBqDataset( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String resourceName, - String projectId, - String datasetName) - throws Exception { - ApiGcpBigQueryDatasetAttributes creationParameters = - new ApiGcpBigQueryDatasetAttributes().projectId(projectId).datasetId(datasetName); - ApiCreateGcpBigQueryDatasetReferenceRequestBody request = - new ApiCreateGcpBigQueryDatasetReferenceRequestBody() - .metadata( - ReferenceResourceFixtures.makeDefaultReferencedResourceFieldsApi() - .name(resourceName)) - .dataset(creationParameters); - String serializedResponse = - getSerializedResponseForPost( - userRequest, - REFERENCED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); - } - - public ApiGcpBigQueryDatasetResource getReferencedBqDataset( - AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - return getBqDataset( - userRequest, workspaceId, resourceId, REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT); - } - - public ApiGcpBigQueryDatasetResource updateReferencedBqDataset( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - UUID resourceId, - String newName, - String newDescription, - ApiCloningInstructionsEnum newCloningInstruction, - String newBqDataset) - throws Exception { - ApiUpdateBigQueryDatasetReferenceRequestBody requestBody = - new ApiUpdateBigQueryDatasetReferenceRequestBody() - .name(newName) - .description(newDescription) - .cloningInstructions(newCloningInstruction) - .datasetId(newBqDataset); - var serializedResponse = - getSerializedResponseForPost( - userRequest, - String.format(REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, workspaceId, resourceId), - objectMapper.writeValueAsString(requestBody)); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDatasetResource.class); - } - - public ApiGcpBigQueryDatasetResource cloneReferencedBqDataset( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName) - throws Exception { - return cloneReferencedBqDataset( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - HttpStatus.SC_OK); - } - - public ApiGcpBigQueryDatasetResource cloneReferencedBqDataset( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - int expectedCode) - throws Exception { - MockHttpServletResponse response = - cloneReferencedResource( - userRequest, - CLONE_REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - expectedCode); - - if (isErrorResponse(response)) { - return null; - } - - String serializedResponse = response.getContentAsString(); - return objectMapper - .readValue(serializedResponse, ApiCloneReferencedGcpBigQueryDatasetResourceResult.class) - .getResource(); - } - - public ApiGcpBigQueryDataTableResource createReferencedBqTable( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - String resourceName, - String projectId, - String datasetName, - String tableId) - throws Exception { - ApiGcpBigQueryDataTableAttributes creationParameters = - new ApiGcpBigQueryDataTableAttributes() - .projectId(projectId) - .datasetId(datasetName) - .dataTableId(tableId); - ApiCreateGcpBigQueryDataTableReferenceRequestBody request = - new ApiCreateGcpBigQueryDataTableReferenceRequestBody() - .metadata( - ReferenceResourceFixtures.makeDefaultReferencedResourceFieldsApi() - .name(resourceName)) - .dataTable(creationParameters); - String serializedResponse = - getSerializedResponseForPost( - userRequest, - REFERENCED_GCP_BIG_QUERY_DATA_TABLES_V1_PATH_FORMAT, - workspaceId, - objectMapper.writeValueAsString(request)); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); - } - - public ApiGcpBigQueryDataTableResource getReferencedBqTable( - AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { - String serializedResponse = - getSerializedResponseForGet( - userRequest, - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, - workspaceId, - resourceId); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); - } - - public ApiGcpBigQueryDataTableResource updateReferencedBqTable( - AuthenticatedUserRequest userRequest, - UUID workspaceId, - UUID resourceId, - String newName, - String newDescription, - ApiCloningInstructionsEnum newCloningInstruction, - String newProjectId, - String newDataset, - String newTable) - throws Exception { - ApiUpdateBigQueryDataTableReferenceRequestBody requestBody = - new ApiUpdateBigQueryDataTableReferenceRequestBody() - .name(newName) - .description(newDescription) - .cloningInstructions(newCloningInstruction) - .projectId(newProjectId) - .datasetId(newDataset) - .dataTableId(newTable); - var serializedResponse = - getSerializedResponseForPost( - userRequest, - String.format( - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, workspaceId, resourceId), - objectMapper.writeValueAsString(requestBody)); - return objectMapper.readValue(serializedResponse, ApiGcpBigQueryDataTableResource.class); - } - - public ApiGcpBigQueryDataTableResource cloneReferencedBqTable( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName) - throws Exception { - return cloneReferencedBqTable( - userRequest, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - HttpStatus.SC_OK); - } - - public ApiGcpBigQueryDataTableResource cloneReferencedBqTable( - AuthenticatedUserRequest userRequest, - UUID sourceWorkspaceId, - UUID sourceResourceId, - UUID destWorkspaceId, - ApiCloningInstructionsEnum cloningInstructions, - @Nullable String destResourceName, - int expectedCode) - throws Exception { - MockHttpServletResponse response = - cloneReferencedResource( - userRequest, - CLONE_REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, - sourceWorkspaceId, - sourceResourceId, - destWorkspaceId, - cloningInstructions, - destResourceName, - expectedCode); - - if (isErrorResponse(response)) { - return null; - } - - String serializedResponse = response.getContentAsString(); - return objectMapper - .readValue(serializedResponse, ApiCloneReferencedGcpBigQueryDataTableResourceResult.class) - .getResource(); - } - public ApiGcpGcsBucketResource createReferencedGcsBucket( AuthenticatedUserRequest userRequest, UUID workspaceId, @@ -2271,7 +1410,7 @@ public ApiGcpGcsBucketResource createReferencedGcsBucket( String serializedResponse = getSerializedResponseForPost( userRequest, - REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT, + CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, objectMapper.writeValueAsString(request)); return objectMapper.readValue(serializedResponse, ApiGcpGcsBucketResource.class); @@ -2281,7 +1420,7 @@ public ApiGcpGcsBucketResource getReferencedGcsBucket( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { String serializedResponse = getSerializedResponseForGet( - userRequest, REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT, workspaceId, resourceId); + userRequest, REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, resourceId); return objectMapper.readValue(serializedResponse, ApiGcpGcsBucketResource.class); } @@ -2303,7 +1442,7 @@ public ApiGcpGcsBucketResource updateReferencedGcsBucket( var serializedResponse = getSerializedResponseForPost( userRequest, - String.format(REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT, workspaceId, resourceId), + String.format(REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, workspaceId, resourceId), objectMapper.writeValueAsString(requestBody)); return objectMapper.readValue(serializedResponse, ApiGcpGcsBucketResource.class); } @@ -2338,7 +1477,7 @@ public ApiGcpGcsBucketResource cloneReferencedGcsBucket( MockHttpServletResponse response = cloneReferencedResource( userRequest, - CLONE_REFERENCED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + CLONE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT, sourceWorkspaceId, sourceResourceId, destWorkspaceId, @@ -2374,7 +1513,7 @@ public ApiGcpGcsObjectResource createReferencedGcsObject( String serializedResponse = getSerializedResponseForPost( userRequest, - REFERENCED_GCP_GCS_OBJECTS_V1_PATH_FORMAT, + CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT, workspaceId, objectMapper.writeValueAsString(request)); return objectMapper.readValue(serializedResponse, ApiGcpGcsObjectResource.class); @@ -2384,7 +1523,7 @@ public ApiGcpGcsObjectResource getReferencedGcsObject( AuthenticatedUserRequest userRequest, UUID workspaceId, UUID resourceId) throws Exception { String serializedResponse = getSerializedResponseForGet( - userRequest, REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT, workspaceId, resourceId); + userRequest, REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT, workspaceId, resourceId); return objectMapper.readValue(serializedResponse, ApiGcpGcsObjectResource.class); } @@ -2410,7 +1549,7 @@ public ApiGcpGcsObjectResource updateReferencedGcsObject( var serializedResponse = getSerializedResponseForPost( userRequest, - String.format(REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT, workspaceId, resourceId), + String.format(REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT, workspaceId, resourceId), objectMapper.writeValueAsString(updateRequest)); return objectMapper.readValue(serializedResponse, ApiGcpGcsObjectResource.class); } @@ -2445,7 +1584,7 @@ public ApiGcpGcsObjectResource cloneReferencedGcsObject( MockHttpServletResponse response = cloneReferencedResource( userRequest, - CLONE_REFERENCED_GCP_GCS_OBJECT_V1_PATH_FORMAT, + CLONE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT, sourceWorkspaceId, sourceResourceId, destWorkspaceId, @@ -2608,7 +1747,7 @@ public ApiGitRepoResource cloneReferencedGitRepo( .getResource(); } - private MockHttpServletResponse cloneReferencedResource( + public MockHttpServletResponse cloneReferencedResource( AuthenticatedUserRequest userRequest, String path, UUID sourceWorkspaceId, @@ -2850,6 +1989,18 @@ public ApiJobReport getJobReport(String path, AuthenticatedUserRequest userReque return objectMapper.readValue(serializedResponse, ApiJobResult.class).getJobReport(); } + public T getCreateResourceJobResult( + Class classType, + AuthenticatedUserRequest userRequest, + String path, + UUID workspaceId, + String jobId) + throws Exception { + String serializedResponse = + getSerializedResponseForGetJobResult(userRequest, path, workspaceId, jobId); + return objectMapper.readValue(serializedResponse, classType); + } + private String getSerializedResponseForGet( AuthenticatedUserRequest userRequest, String path, UUID workspaceId) throws Exception { return mockMvc @@ -2860,7 +2011,7 @@ private String getSerializedResponseForGet( .getContentAsString(); } - protected String getSerializedResponseForGet( + public String getSerializedResponseForGet( AuthenticatedUserRequest userRequest, String path, UUID workspaceId, UUID resourceId) throws Exception { return mockMvc @@ -2871,7 +2022,7 @@ protected String getSerializedResponseForGet( .getContentAsString(); } - private String getSerializedResponseForGetJobResult( + public String getSerializedResponseForGetJobResult( AuthenticatedUserRequest userRequest, String path, UUID workspaceId, String jobId) throws Exception { return mockMvc @@ -2892,7 +2043,7 @@ public String getSerializedResponseForGetJobResult( .getContentAsString(); } - private String getSerializedResponseForGetJobResult_error( + public String getSerializedResponseForGetJobResult_error( AuthenticatedUserRequest userRequest, String path, UUID workspaceId, String jobId) throws Exception { return mockMvc @@ -3015,13 +2166,6 @@ public static void assertApiBqDatasetEquals( assertEquals(expectedDataset.getAttributes(), actualDataset.getAttributes()); } - public static void assertApiBqDataTableEquals( - ApiGcpBigQueryDataTableResource expectedDataTable, - ApiGcpBigQueryDataTableResource actualDataTable) { - assertResourceMetadataEquals(expectedDataTable.getMetadata(), actualDataTable.getMetadata()); - assertEquals(expectedDataTable.getAttributes(), actualDataTable.getAttributes()); - } - public static void assertApiFlexibleResourceEquals( ApiFlexibleResource expectedFlexibleResource, ApiFlexibleResource actualFlexibleResource) { assertResourceMetadataEquals( @@ -3036,7 +2180,7 @@ public static void assertApiDataRepoEquals( } // I can't figure out the proper way to do this - private static Matcher getExpectedCodesMatcher(List expectedCodes) { + public static Matcher getExpectedCodesMatcher(List expectedCodes) { if (expectedCodes.size() == 1) { return equalTo(expectedCodes.get(0)); } else if (expectedCodes.size() == 2) { @@ -3159,7 +2303,7 @@ public static ApiWsmPolicyInput buildWsmRegionPolicyInput(String location) { * @param response response from a mock api request * @return true if this was an error; false otherwise */ - private boolean isErrorResponse(MockHttpServletResponse response) throws Exception { + public boolean isErrorResponse(MockHttpServletResponse response) throws Exception { // not an error if (response.getStatus() < 300) { return false; diff --git a/service/src/test/java/bio/terra/workspace/service/resource/statetests/AnyResourceStateFailureTest.java b/service/src/test/java/bio/terra/workspace/service/resource/statetests/AnyResourceStateFailureTest.java index 4c56ffd60f..5436645f9a 100644 --- a/service/src/test/java/bio/terra/workspace/service/resource/statetests/AnyResourceStateFailureTest.java +++ b/service/src/test/java/bio/terra/workspace/service/resource/statetests/AnyResourceStateFailureTest.java @@ -1,14 +1,14 @@ package bio.terra.workspace.service.resource.statetests; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_BQ_DATASETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_BQ_DATA_TABLES_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_BQ_DATASET_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_FLEXIBLE_RESOURCES_V1_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_DATA_REPO_SNAPSHOTS_V1_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_DATA_REPO_SNAPSHOT_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATA_TABLES_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GCP_GCS_OBJECTS_V1_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GIT_REPOS_V1_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.REFERENCED_GIT_REPO_V1_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.USER_REQUEST; @@ -137,7 +137,7 @@ void testNoContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(refBqDatasetRequest), - REFERENCED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_REFERENCED_GCP_BQ_DATASETS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Referenced BQ data table @@ -152,7 +152,7 @@ void testNoContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(refBqDataTableRequest), - REFERENCED_GCP_BIG_QUERY_DATA_TABLES_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_REFERENCED_GCP_BQ_DATA_TABLES_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Referenced Bucket @@ -163,7 +163,7 @@ void testNoContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(refBucketRequest), - REFERENCED_GCP_GCS_BUCKETS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_REFERENCED_GCP_GCS_BUCKETS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Referenced Bucket Object @@ -174,7 +174,7 @@ void testNoContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(refBucketObjectRequest), - REFERENCED_GCP_GCS_OBJECTS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_REFERENCED_GCP_GCS_OBJECTS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); } @@ -264,10 +264,10 @@ void testNoContextResourceModifyValidation() throws Exception { stateTestUtils.postResourceExpectConflict( workspaceUuid, bqResource.getResourceId(), - REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, + REFERENCED_GCP_BQ_DATASET_PATH_FORMAT, objectMapper.writeValueAsString(bqUpdateRequest)); stateTestUtils.deleteResourceExpectConflict( - workspaceUuid, bqResource.getResourceId(), REFERENCED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT); + workspaceUuid, bqResource.getResourceId(), REFERENCED_GCP_BQ_DATASET_PATH_FORMAT); // GCP-Referenced BQ data table var bqTableUpdateRequest = @@ -275,20 +275,18 @@ void testNoContextResourceModifyValidation() throws Exception { stateTestUtils.postResourceExpectConflict( workspaceUuid, bqTable.getResourceId(), - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, + REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, objectMapper.writeValueAsString(bqTableUpdateRequest)); stateTestUtils.deleteResourceExpectConflict( - workspaceUuid, bqTable.getResourceId(), REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT); + workspaceUuid, bqTable.getResourceId(), REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT); // GCP-Referenced Bucket stateTestUtils.postResourceExpectConflict( workspaceUuid, bqResource.getResourceId(), - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT, + REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT, objectMapper.writeValueAsString(bqTableUpdateRequest)); stateTestUtils.deleteResourceExpectConflict( - workspaceUuid, - bqResource.getResourceId(), - REFERENCED_GCP_BIG_QUERY_DATA_TABLE_V1_PATH_FORMAT); + workspaceUuid, bqResource.getResourceId(), REFERENCED_GCP_BQ_DATA_TABLE_PATH_FORMAT); } } diff --git a/service/src/test/java/bio/terra/workspace/service/resource/statetests/GcpResourceStateFailureTest.java b/service/src/test/java/bio/terra/workspace/service/resource/statetests/GcpResourceStateFailureTest.java index 16bbe9d3ce..1810c75f45 100644 --- a/service/src/test/java/bio/terra/workspace/service/resource/statetests/GcpResourceStateFailureTest.java +++ b/service/src/test/java/bio/terra/workspace/service/resource/statetests/GcpResourceStateFailureTest.java @@ -1,14 +1,14 @@ package bio.terra.workspace.service.resource.statetests; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_AI_NOTEBOOKS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_AI_NOTEBOOK_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCE_INSTANCES_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCE_INSTANCE_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCS_BUCKETS_V1_PATH_FORMAT; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; import static bio.terra.workspace.common.utils.MockMvcUtils.USER_REQUEST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -18,6 +18,7 @@ import bio.terra.workspace.common.fixtures.ControlledGcpResourceFixtures; import bio.terra.workspace.common.fixtures.ControlledResourceFixtures; import bio.terra.workspace.common.fixtures.WorkspaceFixtures; +import bio.terra.workspace.common.utils.MockGcpApi; import bio.terra.workspace.common.utils.MockMvcUtils; import bio.terra.workspace.common.utils.TestUtils; import bio.terra.workspace.common.utils.WorkspaceUnitTestUtils; @@ -64,6 +65,7 @@ public class GcpResourceStateFailureTest extends BaseUnitTest { @Autowired private MockMvc mockMvc; @Autowired private MockMvcUtils mockMvcUtils; + @Autowired private MockGcpApi mockGcpApi; @Autowired ObjectMapper objectMapper; @Autowired ReferencedResourceService referencedResourceService; @Autowired ResourceDao resourceDao; @@ -115,7 +117,7 @@ void testGcpContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(instanceRequest), - CONTROLLED_GCP_GCE_INSTANCES_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Controlled Notebook @@ -132,7 +134,7 @@ void testGcpContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(notebookRequest), - CONTROLLED_GCP_AI_NOTEBOOKS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Controlled Dataproc cluster @@ -151,7 +153,7 @@ void testGcpContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(clusterRequest), - CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_CONTROLLED_GCP_DATAPROC_CLUSTERS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Controlled BigQuery @@ -165,7 +167,7 @@ void testGcpContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(bqRequest), - CONTROLLED_GCP_BIG_QUERY_DATASETS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); // GCP-Controlled Bucket @@ -178,7 +180,7 @@ void testGcpContextResourceCreateValidation() throws Exception { mockMvcUtils.postExpect( USER_REQUEST, objectMapper.writeValueAsString(bucketRequest), - CONTROLLED_GCP_GCS_BUCKETS_V1_PATH_FORMAT.formatted(workspace.workspaceId()), + CREATE_CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT.formatted(workspace.workspaceId()), HttpStatus.SC_CONFLICT); } @@ -218,7 +220,7 @@ void testGcpResourceModifyValidation() throws Exception { ApiGcpGceInstanceResource.class, workspaceUuid, instanceResource.getResourceId(), - CONTROLLED_GCP_GCE_INSTANCE_V1_PATH_FORMAT, + CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT, objectMapper.writeValueAsString(instanceRequestBody)); var instanceDeleteBody = new ApiDeleteControlledGcpGceInstanceRequest() @@ -226,7 +228,7 @@ void testGcpResourceModifyValidation() throws Exception { stateTestUtils.postResourceExpectConflict( workspaceUuid, instanceResource.getResourceId(), - CONTROLLED_GCP_GCE_INSTANCE_V1_PATH_FORMAT, + CONTROLLED_GCP_GCE_INSTANCES_PATH_FORMAT, objectMapper.writeValueAsString(instanceDeleteBody)); // GCP-Controlled Notebook @@ -236,7 +238,7 @@ void testGcpResourceModifyValidation() throws Exception { ApiGcpAiNotebookInstanceResource.class, workspaceUuid, notebookResource.getResourceId(), - CONTROLLED_GCP_AI_NOTEBOOK_V1_PATH_FORMAT, + CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT, objectMapper.writeValueAsString(notebookRequestBody)); var notebookDeleteBody = new ApiDeleteControlledGcpAiNotebookInstanceRequest() @@ -244,7 +246,7 @@ void testGcpResourceModifyValidation() throws Exception { stateTestUtils.postResourceExpectConflict( workspaceUuid, notebookResource.getResourceId(), - CONTROLLED_GCP_AI_NOTEBOOK_V1_PATH_FORMAT, + CONTROLLED_GCP_AI_NOTEBOOKS_PATH_FORMAT, objectMapper.writeValueAsString(notebookDeleteBody)); // GCP-Controlled BigQuery @@ -257,10 +259,10 @@ void testGcpResourceModifyValidation() throws Exception { ApiGcpBigQueryDatasetResource.class, workspaceUuid, bqResource.getResourceId(), - CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT, + CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT, objectMapper.writeValueAsString(bqRequestBody)); stateTestUtils.deleteResourceExpectConflict( - workspaceUuid, bqResource.getResourceId(), CONTROLLED_GCP_BIG_QUERY_DATASET_V1_PATH_FORMAT); + workspaceUuid, bqResource.getResourceId(), CONTROLLED_GCP_BQ_DATASETS_PATH_FORMAT); // GCP-Controlled bucket var bucketRequestBody = @@ -272,7 +274,7 @@ void testGcpResourceModifyValidation() throws Exception { ApiGcpGcsBucketResource.class, workspaceUuid, bucketResource.getResourceId(), - CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, objectMapper.writeValueAsString(bucketRequestBody)); var bucketDeleteBody = new ApiDeleteControlledGcpGcsBucketRequest() @@ -280,7 +282,7 @@ void testGcpResourceModifyValidation() throws Exception { stateTestUtils.postResourceExpectConflict( workspaceUuid, notebookResource.getResourceId(), - CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT, + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT, objectMapper.writeValueAsString(bucketDeleteBody)); } @@ -310,7 +312,7 @@ void testGcpResourceCloneValidation() throws Exception { WorkspaceFixtures.DEFAULT_SPEND_PROFILE_ID, createContextFlightId); - mockMvcUtils.cloneControlledBqDatasetAsync( + mockGcpApi.cloneControlledBqDatasetAsync( USER_REQUEST, workspaceUuid, bqResource.getResourceId(), diff --git a/service/src/test/java/bio/terra/workspace/service/workspace/GcpCloudContextConnectedTest.java b/service/src/test/java/bio/terra/workspace/service/workspace/GcpCloudContextConnectedTest.java index 0e10d672f5..f671523ca5 100644 --- a/service/src/test/java/bio/terra/workspace/service/workspace/GcpCloudContextConnectedTest.java +++ b/service/src/test/java/bio/terra/workspace/service/workspace/GcpCloudContextConnectedTest.java @@ -1,6 +1,6 @@ package bio.terra.workspace.service.workspace; -import static bio.terra.workspace.common.utils.MockMvcUtils.CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT; +import static bio.terra.workspace.common.utils.MockGcpApi.CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hibernate.validator.internal.util.Contracts.assertNotNull; @@ -180,7 +180,7 @@ void deleteWorkspaceWithGoogleContext() throws Exception { .perform( MockMvcUtils.addAuth( get( - CONTROLLED_GCP_GCS_BUCKET_V1_PATH_FORMAT.formatted( + CONTROLLED_GCP_GCS_BUCKETS_PATH_FORMAT.formatted( workspaceId, bucketResource.getMetadata().getResourceId())), userRequest)) .andExpect(status().isNotFound())