Search in sources :

Example 11 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class BucketResourceTest method twoThreadsCompeteForLockTest.

@Test
public // after it's been created, confirm it succeeds.
void twoThreadsCompeteForLockTest() throws Exception {
    String flightIdBase = "twoThreadsCompeteForLockTest";
    String bucketName = "twothreadscompeteforlocktest";
    bucketNames.add(bucketName);
    GoogleBucketRequest bucketRequest = buildBucketRequest(bucketName);
    BucketResourceLockTester resourceLockA = new BucketResourceLockTester(resourceService, bucketRequest, flightIdBase + "A");
    BucketResourceLockTester resourceLockB = new BucketResourceLockTester(resourceService, bucketRequest, flightIdBase + "B");
    BucketResourceLockTester resourceLockC = new BucketResourceLockTester(resourceService, bucketRequest, flightIdBase + "C");
    Thread threadA = new Thread(resourceLockA);
    Thread threadB = new Thread(resourceLockB);
    Thread threadC = new Thread(resourceLockC);
    configService.setFault(ConfigEnum.BUCKET_LOCK_CONFLICT_STOP_FAULT.name(), true);
    threadA.start();
    TimeUnit.SECONDS.sleep(1);
    threadB.start();
    threadB.join();
    assertTrue("Thread B did get a lock exception", resourceLockB.gotLockException());
    configService.setFault(ConfigEnum.BUCKET_LOCK_CONFLICT_CONTINUE_FAULT.name(), true);
    threadA.join();
    assertFalse("Thread A did not get a lock exception", resourceLockA.gotLockException());
    GoogleBucketResource bucketResource = resourceLockA.getBucketResource();
    assertNotNull("Thread A did create the bucket", bucketResource);
    checkBucketExists(bucketResource.getResourceId());
    threadC.start();
    threadC.join();
    assertFalse("Thread C did not get a lock exception", resourceLockC.gotLockException());
    assertNotNull("Thread C did get the bucket", resourceLockC.getBucketResource());
    deleteBucket(bucketResource.getName());
    checkBucketDeleted(bucketResource.getName(), bucketResource.getResourceId());
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) GoogleBucketRequest(bio.terra.service.resourcemanagement.google.GoogleBucketRequest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class BucketResourceTest method createAndDeleteBucketTest.

@Test
public // create and delete the bucket, checking that the metadata and cloud state match what is expected
void createAndDeleteBucketTest() throws Exception {
    String bucketName = "testbucket_createanddeletebuckettest";
    String flightId = "createAndDeleteBucketTest";
    bucketNames.add(bucketName);
    // create the bucket and metadata
    GoogleBucketRequest googleBucketRequest = buildBucketRequest(bucketName);
    GoogleBucketResource bucketResource = resourceService.getOrCreateBucket(googleBucketRequest, flightId);
    // check the bucket and metadata exist
    checkBucketExists(bucketResource.getResourceId());
    // delete the bucket and metadata
    deleteBucket(bucketResource.getName());
    checkBucketDeleted(bucketResource.getName(), bucketResource.getResourceId());
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) GoogleBucketRequest(bio.terra.service.resourcemanagement.google.GoogleBucketRequest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class BucketResourceTest method checkBucketExists.

private void checkBucketExists(UUID bucketResourceId) {
    // confirm the metadata row is unlocked and the bucket exists
    GoogleBucketResource bucketResource = resourceService.getBucketResourceById(bucketResourceId, false);
    assertNotNull("bucket metadata row exists", bucketResource);
    assertNull("bucket metadata is unlocked", bucketResource.getFlightId());
    Bucket bucket = storage.get(bucketResource.getName());
    assertNotNull("bucket exists in the cloud", bucket);
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) Bucket(com.google.cloud.storage.Bucket)

Example 14 with GoogleBucketResource

use of bio.terra.service.resourcemanagement.google.GoogleBucketResource in project jade-data-repo by DataBiosphere.

the class DrsService method drsObjectFromFSFile.

private DRSObject drsObjectFromFSFile(FSFile fsFile, String snapshotId, AuthenticatedUserRequest authUser) {
    DRSObject fileObject = makeCommonDrsObject(fsFile, snapshotId);
    GoogleBucketResource bucketResource = locationService.lookupBucketMetadata(fsFile.getBucketResourceId());
    DRSAccessURL gsAccessURL = new DRSAccessURL().url(fsFile.getGspath());
    DRSAccessMethod gsAccessMethod = new DRSAccessMethod().type(DRSAccessMethod.TypeEnum.GS).accessUrl(gsAccessURL).region(bucketResource.getRegion());
    DRSAccessURL httpsAccessURL = new DRSAccessURL().url(makeHttpsFromGs(fsFile.getGspath())).headers(makeAuthHeader(authUser));
    DRSAccessMethod httpsAccessMethod = new DRSAccessMethod().type(DRSAccessMethod.TypeEnum.HTTPS).accessUrl(httpsAccessURL).region(bucketResource.getRegion());
    List<DRSAccessMethod> accessMethods = new ArrayList<>();
    accessMethods.add(gsAccessMethod);
    accessMethods.add(httpsAccessMethod);
    fileObject.mimeType(fsFile.getMimeType()).checksums(fileService.makeChecksums(fsFile)).accessMethods(accessMethods);
    return fileObject;
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) DRSAccessMethod(bio.terra.model.DRSAccessMethod) DRSAccessURL(bio.terra.model.DRSAccessURL) ArrayList(java.util.ArrayList) DRSObject(bio.terra.model.DRSObject)

Aggregations

GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)14 FlightMap (bio.terra.stairway.FlightMap)5 GoogleBucketRequest (bio.terra.service.resourcemanagement.google.GoogleBucketRequest)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Bucket (com.google.cloud.storage.Bucket)3 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)2 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)2 StepResult (bio.terra.stairway.StepResult)2 DRSAccessMethod (bio.terra.model.DRSAccessMethod)1 DRSAccessURL (bio.terra.model.DRSAccessURL)1 DRSObject (bio.terra.model.DRSObject)1 FileLoadModel (bio.terra.model.FileLoadModel)1 FSFile (bio.terra.service.filedata.FSFile)1 FSFileInfo (bio.terra.service.filedata.FSFileInfo)1 FSItem (bio.terra.service.filedata.FSItem)1 FireStoreFile (bio.terra.service.filedata.google.firestore.FireStoreFile)1 LoadCandidates (bio.terra.service.load.LoadCandidates)1 BucketLockException (bio.terra.service.resourcemanagement.exception.BucketLockException)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1