use of bio.terra.service.resourcemanagement.google.GoogleProjectResource in project jade-data-repo by DataBiosphere.
the class GcsPdao method storageForBucket.
private Storage storageForBucket(GoogleBucketResource bucketResource) {
GoogleProjectResource projectResource = bucketResource.getProjectResource();
GcsProject gcsProject = gcsProjectFactory.get(projectResource.getGoogleProjectId());
return gcsProject.getStorage();
}
use of bio.terra.service.resourcemanagement.google.GoogleProjectResource in project jade-data-repo by DataBiosphere.
the class DataLocationService method getProject.
/**
* Fetch existing SnapshotDataProject for the Snapshot.
* Delete it if it's invalid, that is, the referenced cloud resource doesn't exist.
* @param snapshot
* @return a populated SnapshotDataProject if one exists, empty if not
*/
public Optional<SnapshotDataProject> getProject(Snapshot snapshot) {
SnapshotDataProjectSummary snapshotDataProjectSummary = null;
try {
// first, check if SnapshotDataProjectSummary (= mapping btw Snapshot ID and cloud Project ID) exists
snapshotDataProjectSummary = dataProjectDao.retrieveSnapshotDataProject(snapshot.getId());
// second, check if the referenced cloud resource exists
GoogleProjectResource googleProjectResource = resourceService.getProjectResourceById(snapshotDataProjectSummary.getProjectResourceId());
// if both exist, then create the DatasetDataProject object from the summary and return here
return Optional.of(new SnapshotDataProject(snapshotDataProjectSummary).googleProjectResource(googleProjectResource));
} catch (DataProjectNotFoundException projNfEx) {
// suppress exception here, will create later
} catch (GoogleResourceNotFoundException rsrcNfEx) {
// I don't think this null check will ever be false, but just in case
if (snapshotDataProjectSummary != null) {
logger.warn("metadata has a project resource id it can't resolve for snapshot: " + snapshot.getName());
dataProjectDao.deleteSnapshotDataProject(snapshotDataProjectSummary.getId());
}
}
// did not find a valid SnapshotDataProject for the given Snapshot
return Optional.empty();
}
use of bio.terra.service.resourcemanagement.google.GoogleProjectResource in project jade-data-repo by DataBiosphere.
the class DataLocationService method getOrCreateBucketForFile.
/**
* Fetch/create a project, then use that to fetch/create a bucket.
* The profileId is used to determine the project name.
* The flightId is used to lock the bucket metadata during possible creation.
* @param profileId
* @param flightId
* @return a reference to the bucket as a POJO GoogleBucketResource
* @throws CorruptMetadataException in two cases. 1) if the bucket already exists, but the metadata does not AND the
* application property allowReuseExistingBuckets=false. 2) if the metadata exists, but the bucket does not
*/
public GoogleBucketResource getOrCreateBucketForFile(String profileId, String flightId) throws InterruptedException {
// Every bucket needs to live in a project, so we get a project first (one will be created if it can't be found)
GoogleProjectResource projectResource = getProjectForFile(profileId);
BillingProfile profile = profileService.getProfileById(UUID.fromString(profileId));
GoogleBucketRequest googleBucketRequest = new GoogleBucketRequest().googleProjectResource(projectResource).bucketName(getBucketName(profileId)).profileId(UUID.fromString(profileId)).region(profile.getGcsRegion());
return resourceService.getOrCreateBucket(googleBucketRequest, flightId);
}
use of bio.terra.service.resourcemanagement.google.GoogleProjectResource 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);
}
use of bio.terra.service.resourcemanagement.google.GoogleProjectResource in project jade-data-repo by DataBiosphere.
the class DataLocationService method getProject.
/**
* Fetch existing DatasetDataProject for the Dataset.
* Delete it if it's invalid, that is, the referenced cloud resource doesn't exist.
* @param dataset
* @return a populated DatasetDataProject if one exists, empty if not
*/
public Optional<DatasetDataProject> getProject(Dataset dataset) {
DatasetDataProjectSummary datasetDataProjectSummary = null;
try {
// first, check if DatasetDataProjectSummary (= mapping btw Dataset ID and cloud Project ID) exists
datasetDataProjectSummary = dataProjectDao.retrieveDatasetDataProject(dataset.getId());
// second, check if the referenced cloud resource exists
GoogleProjectResource googleProjectResource = resourceService.getProjectResourceById(datasetDataProjectSummary.getProjectResourceId());
// if both exist, then create the DatasetDataProject object from the summary and return here
return Optional.of(new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource));
} catch (DataProjectNotFoundException projNfEx) {
// suppress exception here, will create later
} catch (GoogleResourceNotFoundException rsrcNfEx) {
// I don't think this null check will ever be false, but just in case
if (datasetDataProjectSummary != null) {
logger.warn("metadata has a project resource id it can't resolve for dataset: " + dataset.getName());
dataProjectDao.deleteDatasetDataProject(datasetDataProjectSummary.getId());
}
}
// did not find a valid DatasetDataProject for the given Dataset
return Optional.empty();
}
Aggregations