use of bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ResourceDaoTest method listAndDeleteControlledResourceInContext.
@Test
public void listAndDeleteControlledResourceInContext() {
UUID workspaceId = createGcpWorkspace();
ControlledGcsBucketResource bucket = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId).build();
ControlledBigQueryDatasetResource dataset = ControlledResourceFixtures.makeDefaultControlledBigQueryBuilder(workspaceId).build();
resourceDao.createControlledResource(bucket);
resourceDao.createControlledResource(dataset);
List<ControlledResource> gcpList = resourceDao.listControlledResources(workspaceId, CloudPlatform.GCP);
List<ControlledResource> azureList = resourceDao.listControlledResources(workspaceId, CloudPlatform.AZURE);
List<ControlledResource> allCloudList = resourceDao.listControlledResources(workspaceId, null);
assertTrue(azureList.isEmpty());
assertThat(gcpList, containsInAnyOrder(bucket, dataset));
assertThat(allCloudList, containsInAnyOrder(bucket, dataset));
assertTrue(resourceDao.deleteAllControlledResources(workspaceId, CloudPlatform.GCP));
assertFalse(resourceDao.deleteAllControlledResources(workspaceId, CloudPlatform.AZURE));
List<ControlledResource> listAfterDeletion = resourceDao.listControlledResources(workspaceId, CloudPlatform.GCP);
assertTrue(listAfterDeletion.isEmpty());
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ControlledGcpResourceApiController method getBigQueryDataset.
@Override
public ResponseEntity<ApiGcpBigQueryDatasetResource> getBigQueryDataset(UUID workspaceId, UUID resourceId) {
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControlledResource controlledResource = controlledResourceService.getControlledResource(workspaceId, resourceId, userRequest);
ControlledBigQueryDatasetResource resource = controlledResource.castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
return new ResponseEntity<>(resource.toApiResource(), HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ControlledGcpResourceApiController method createBigQueryDataset.
@Override
public ResponseEntity<ApiCreatedControlledGcpBigQueryDataset> createBigQueryDataset(UUID workspaceId, ApiCreateControlledGcpBigQueryDatasetRequestBody body) {
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
// We need to retrieve the project id so it can be used in the BQ dataset attributes.
String projectId = workspaceService.getAuthorizedRequiredGcpProject(workspaceId, userRequest);
ControlledBigQueryDatasetResource resource = ControlledBigQueryDatasetResource.builder().datasetName(Optional.ofNullable(body.getDataset().getDatasetId()).orElse(body.getCommon().getName())).projectId(projectId).common(commonFields).build();
final ControlledBigQueryDatasetResource createdDataset = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getDataset()).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
var response = new ApiCreatedControlledGcpBigQueryDataset().resourceId(createdDataset.getResourceId()).bigQueryDataset(createdDataset.toApiResource());
return new ResponseEntity<>(response, HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDeleteFlightTest method cannotUndoWorkspaceDelete.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void cannotUndoWorkspaceDelete() throws Exception {
// Create a workspace with a controlled resource
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
Workspace workspace = connectedTestUtils.createWorkspaceWithGcpContext(userRequest);
ControlledBigQueryDatasetResource dataset = ControlledResourceFixtures.makeDefaultControlledBigQueryBuilder(workspace.getWorkspaceId()).build();
var creationParameters = ControlledResourceFixtures.defaultBigQueryDatasetCreationParameters().datasetId(dataset.getDatasetName());
controlledResourceService.createControlledResourceSync(dataset, null, userRequest, creationParameters).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
ControlledBigQueryDatasetResource gotResource = controlledResourceService.getControlledResource(workspace.getWorkspaceId(), dataset.getResourceId(), userRequest).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
assertEquals(dataset, gotResource);
FlightMap deleteParameters = new FlightMap();
deleteParameters.put(WorkspaceFlightMapKeys.WORKSPACE_ID, workspace.getWorkspaceId().toString());
deleteParameters.put(WorkspaceFlightMapKeys.WORKSPACE_STAGE, workspace.getWorkspaceStage().name());
deleteParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
// Deletion steps can't be undone, so if the flight fails at the end, this should be marked as
// a dismal failure and the deletion should persist.
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().lastStepFailure(true).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), WorkspaceDeleteFlight.class, deleteParameters, DELETION_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.FATAL, flightState.getFlightStatus());
// Verify the resource and workspace are still deleted, as delete steps have no undo.
assertThrows(WorkspaceNotFoundException.class, () -> controlledResourceService.getControlledResource(dataset.getWorkspaceId(), dataset.getResourceId(), userRequest));
assertThrows(WorkspaceNotFoundException.class, () -> workspaceService.getWorkspace(workspace.getWorkspaceId(), userRequest));
}
use of bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource in project terra-workspace-manager by DataBiosphere.
the class ControlledResourceServiceTest method deleteBqDatasetDo.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void deleteBqDatasetDo() throws Exception {
String datasetId = ControlledResourceFixtures.uniqueDatasetId();
String location = "us-central1";
ApiGcpBigQueryDatasetCreationParameters creationParameters = new ApiGcpBigQueryDatasetCreationParameters().datasetId(datasetId).location(location);
ControlledBigQueryDatasetResource resource = ControlledResourceFixtures.makeDefaultControlledBigQueryBuilder(workspace.getWorkspaceId()).datasetName(datasetId).build();
ControlledBigQueryDatasetResource createdDataset = controlledResourceService.createControlledResourceSync(resource, null, user.getAuthenticatedRequest(), creationParameters).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
assertEquals(resource, createdDataset);
// Test idempotency of delete by retrying steps once.
Map<String, StepStatus> retrySteps = new HashMap<>();
retrySteps.put(DeleteMetadataStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
retrySteps.put(DeleteBigQueryDatasetStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
// Do not test lastStepFailure, as this flight has no undo steps, only dismal failure.
jobService.setFlightDebugInfoForTest(FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build());
controlledResourceService.deleteControlledResourceSync(resource.getWorkspaceId(), resource.getResourceId(), user.getAuthenticatedRequest());
BigQueryCow bqCow = crlService.createWsmSaBigQueryCow();
GoogleJsonResponseException getException = assertThrows(GoogleJsonResponseException.class, () -> bqCow.datasets().get(projectId, resource.getDatasetName()).execute());
assertEquals(HttpStatus.NOT_FOUND.value(), getException.getStatusCode());
assertThrows(ResourceNotFoundException.class, () -> controlledResourceService.getControlledResource(workspace.getWorkspaceId(), resource.getResourceId(), user.getAuthenticatedRequest()));
}
Aggregations