use of bio.terra.service.snapshot.SnapshotDataProjectSummary 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.snapshot.SnapshotDataProjectSummary 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);
}
Aggregations