Skip to content

Commit

Permalink
GCP files (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
dexamundsen authored Jul 21, 2023
1 parent fa9dcc0 commit 1a59299
Show file tree
Hide file tree
Showing 19 changed files with 1,219 additions and 1,153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@
public class ControlledGcpResourceApiControllerAiNotebookConnectedTest extends BaseConnectedTest {
@Autowired MockMvc mockMvc;
@Autowired MockMvcUtils mockMvcUtils;
@Autowired MockGcpApi mockGcpApi;
@Autowired UserAccessUtils userAccessUtils;
@Autowired JobService jobService;

Expand Down Expand Up @@ -84,7 +86,7 @@ public void createAiNotebookInstance_correctZone() throws Exception {
.value("asia-east1")));

ApiGcpAiNotebookInstanceResource notebook =
mockMvcUtils
mockGcpApi
.createAiNotebookInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null)
.getAiNotebookInstance();

Expand All @@ -98,7 +100,7 @@ public void createAiNotebookInstance_correctZone() throws Exception {
userAccessUtils.getDefaultUserEmail());

notebook =
mockMvcUtils
mockGcpApi
.createAiNotebookInstance(
userAccessUtils.defaultUserAuthRequest(), workspaceId, "europe-west1-b")
.getAiNotebookInstance();
Expand All @@ -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,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class ControlledGcpResourceApiControllerDataprocClusterConnectedTest
extends BaseConnectedTest {
@Autowired MockMvc mockMvc;
@Autowired MockMvcUtils mockMvcUtils;
@Autowired MockGcpApi mockGcpApi;
@Autowired UserAccessUtils userAccessUtils;
@Autowired JobService jobService;

Expand Down Expand Up @@ -121,7 +123,7 @@ public void createDataprocCluster() throws Exception {
.value("asia-east1")));

ApiGcpDataprocClusterResource cluster =
mockMvcUtils
mockGcpApi
.createDataprocCluster(
userAccessUtils.defaultUserAuthRequest(),
workspaceId,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@
public class ControlledGcpResourceApiControllerGceInstanceConnectedTest extends BaseConnectedTest {
@Autowired MockMvc mockMvc;
@Autowired MockMvcUtils mockMvcUtils;
@Autowired MockGcpApi mockGcpApi;
@Autowired UserAccessUtils userAccessUtils;
@Autowired JobService jobService;

Expand Down Expand Up @@ -84,7 +86,7 @@ public void createGceInstance_correctZone() throws Exception {
.value("asia-east1")));

ApiGcpGceInstanceResource instance =
mockMvcUtils
mockGcpApi
.createGceInstance(userAccessUtils.defaultUserAuthRequest(), workspaceId, null)
.getGceInstance();

Expand All @@ -98,7 +100,7 @@ public void createGceInstance_correctZone() throws Exception {
userAccessUtils.getDefaultUserEmail());

instance =
mockMvcUtils
mockGcpApi
.createGceInstance(
userAccessUtils.defaultUserAuthRequest(), workspaceId, "europe-west1-b")
.getGceInstance();
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 1a59299

Please sign in to comment.