Search in sources :

Example 6 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class DataLocationService method getOrCreateProject.

/**
 * Fetch existing SnapshotDataProject for the Snapshot.
 * Create a new one if none exists already.
 * @param snapshot
 * @return a populated and valid SnapshotDataProject
 */
public SnapshotDataProject getOrCreateProject(Snapshot snapshot) throws InterruptedException {
    // check if for an existing SnapshotDataProject first, and return here if found one
    Optional<SnapshotDataProject> existingDataProject = getProject(snapshot);
    if (existingDataProject.isPresent()) {
        return existingDataProject.get();
    }
    // if we've made it here, then we need to create a new cloud resource and SnapshotDataProject
    GoogleProjectRequest googleProjectRequest = new GoogleProjectRequest().projectId(dataLocationSelector.projectIdForSnapshot(snapshot)).profileId(snapshot.getProfileId()).serviceIds(DATA_PROJECT_SERVICE_IDS);
    GoogleProjectResource googleProjectResource = resourceService.getOrCreateProject(googleProjectRequest);
    // create the SnapshotDataProjectSummary object first, which just holds all the IDs
    SnapshotDataProjectSummary snapshotDataProjectSummary = new SnapshotDataProjectSummary().projectResourceId(googleProjectResource.getRepositoryId()).snapshotId(snapshot.getId());
    UUID snapshotDataProjectId = dataProjectDao.createSnapshotDataProject(snapshotDataProjectSummary);
    snapshotDataProjectSummary.id(snapshotDataProjectId);
    // then create the SnapshotDataProject object from the summary
    return new SnapshotDataProject(snapshotDataProjectSummary).googleProjectResource(googleProjectResource);
}
Also used : SnapshotDataProjectSummary(bio.terra.service.snapshot.SnapshotDataProjectSummary) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) UUID(java.util.UUID) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 7 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class FireStoreDao method deleteFilesFromSnapshot.

public void deleteFilesFromSnapshot(Snapshot snapshot) {
    SnapshotDataProject dataProject = dataLocationService.getProjectOrThrow(snapshot);
    Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
    String snapshotId = snapshot.getId().toString();
    directoryDao.deleteDirectoryEntriesFromCollection(firestore, snapshotId);
}
Also used : Firestore(com.google.cloud.firestore.Firestore) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Aggregations

SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)7 Firestore (com.google.cloud.firestore.Firestore)3 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 Snapshot (bio.terra.service.snapshot.Snapshot)2 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)2 PdaoException (bio.terra.common.exception.PdaoException)1 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 IamRole (bio.terra.service.iam.IamRole)1 DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)1 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)1 GoogleProjectRequest (bio.terra.service.resourcemanagement.google.GoogleProjectRequest)1 BigQueryProject (bio.terra.service.tabulardata.google.BigQueryProject)1 FlightMap (bio.terra.stairway.FlightMap)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 FieldValueList (com.google.cloud.bigquery.FieldValueList)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 TableResult (com.google.cloud.bigquery.TableResult)1 UUID (java.util.UUID)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1