Search in sources :

Example 6 with GoogleResourceNotFoundException

use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException in project jade-data-repo by DataBiosphere.

the class BucketResourceTest method bucketExistsBeforeMetadataTest.

@Test
public // bucket cloud resource exists, but the corresponding bucket_resource metadata row does not
void bucketExistsBeforeMetadataTest() throws Exception {
    logger.info("app property allowReuseExistingBuckets = " + resourceService.getAllowReuseExistingBuckets());
    String bucketName = "testbucket_bucketexistsbeforemetadatatest";
    String flightIdA = "bucketExistsBeforeMetadataTestA";
    bucketNames.add(bucketName);
    // create the bucket and metadata
    GoogleBucketRequest googleBucketRequest = buildBucketRequest(bucketName);
    GoogleBucketResource bucketResource = resourceService.getOrCreateBucket(googleBucketRequest, flightIdA);
    checkBucketExists(bucketResource.getResourceId());
    // delete the metadata only
    boolean rowDeleted = resourceDao.deleteBucketMetadata(bucketName, flightIdA);
    assertTrue("metadata row deleted", rowDeleted);
    // try to fetch the bucket again, check fails with not found exception
    boolean caughtNotFoundException = false;
    try {
        resourceService.getBucketResourceById(bucketResource.getResourceId(), true);
    } catch (GoogleResourceNotFoundException cmEx) {
        caughtNotFoundException = true;
    }
    assertTrue("fetch failed when metadata does not exist", caughtNotFoundException);
    // set application property allowReuseExistingBuckets=false
    // try to create bucket again, check fails with corrupt metadata exception
    resourceService.setAllowReuseExistingBuckets(false);
    String flightIdB = "bucketExistsBeforeMetadataTestB";
    boolean caughtCorruptMetadataException = false;
    try {
        resourceService.getOrCreateBucket(googleBucketRequest, flightIdB);
    } catch (CorruptMetadataException cmEx) {
        caughtCorruptMetadataException = true;
    }
    assertTrue("create failed when cloud resource already exists", caughtCorruptMetadataException);
    // set application property allowReuseExistingBuckets=true
    // try to create bucket again, check succeeds
    resourceService.setAllowReuseExistingBuckets(true);
    String flightIdC = "bucketExistsBeforeMetadataTestC";
    bucketResource = resourceService.getOrCreateBucket(googleBucketRequest, flightIdC);
    // check the bucket and metadata exist
    checkBucketExists(bucketResource.getResourceId());
    // delete the bucket and metadata
    deleteBucket(bucketResource.getName());
    checkBucketDeleted(bucketResource.getName(), bucketResource.getResourceId());
    // restore original value of application property allowReuseExistingBuckets, which was saved in setup
    // (this is also done in cleanup after all tests, in case this test errors out before reaching this line)
    resourceService.setAllowReuseExistingBuckets(allowReuseExistingBuckets);
}
Also used : GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) GoogleBucketRequest(bio.terra.service.resourcemanagement.google.GoogleBucketRequest) CorruptMetadataException(bio.terra.service.snapshot.exception.CorruptMetadataException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)6 DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)2 GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)2 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)1 GcsProject (bio.terra.service.filedata.google.gcs.GcsProject)1 GoogleBucketRequest (bio.terra.service.resourcemanagement.google.GoogleBucketRequest)1 SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)1 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)1 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)1 Project (com.google.api.services.cloudresourcemanager.model.Project)1 Bucket (com.google.cloud.storage.Bucket)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1