use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException 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.exception.GoogleResourceNotFoundException in project jade-data-repo by DataBiosphere.
the class BucketResourceTest method checkBucketDeleted.
private void checkBucketDeleted(String bucketName, UUID bucketResourceId) {
// confirm the bucket and metadata row no longer exist
Bucket bucket = storage.get(bucketName);
assertNull("bucket no longer exists", bucket);
boolean exceptionThrown = false;
try {
GoogleBucketResource bucketResource = resourceService.getBucketResourceById(bucketResourceId, false);
logger.info("bucketResource = " + bucketResource);
} catch (GoogleResourceNotFoundException grnfEx) {
exceptionThrown = true;
}
assertTrue("bucket metadata row no longer exists", exceptionThrown);
}
use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException in project jade-data-repo by DataBiosphere.
the class GoogleResourceService method getOrCreateProject.
public GoogleProjectResource getOrCreateProject(GoogleProjectRequest projectRequest) throws InterruptedException {
// Naive: this implements a 1-project-per-profile approach. If there is already a Google project for this
// profile we will look up the project by id, otherwise we will generate one and look it up
String googleProjectId = projectRequest.getProjectId();
try {
return resourceDao.retrieveProjectByGoogleProjectId(googleProjectId);
} catch (GoogleResourceNotFoundException e) {
logger.info("no project resource found for projectId: {}", googleProjectId);
}
// it's possible that the project exists already but it is not stored in the metadata table
// TODO: ensure that the ownership, read/write perms are correct!
Project existingProject = getProject(googleProjectId);
if (existingProject != null) {
GoogleProjectResource googleProjectResource = new GoogleProjectResource(projectRequest).googleProjectId(googleProjectId).googleProjectNumber(existingProject.getProjectNumber().toString());
enableServices(googleProjectResource);
enableIamPermissions(googleProjectResource.getRoleIdentityMapping(), googleProjectId);
UUID id = resourceDao.createProject(googleProjectResource);
return googleProjectResource.repositoryId(id);
}
return newProject(projectRequest, googleProjectId);
}
use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException 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();
}
use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException in project jade-data-repo by DataBiosphere.
the class GoogleResourceDao method retrieveProjectBy.
private GoogleProjectResource retrieveProjectBy(String column, Object value) {
try {
String sql = String.format("SELECT * FROM project_resource WHERE %s = :%s LIMIT 1", column, column);
MapSqlParameterSource params = new MapSqlParameterSource().addValue(column, value);
return jdbcTemplate.queryForObject(sql, params, new DataProjectMapper());
} catch (EmptyResultDataAccessException ex) {
throw new GoogleResourceNotFoundException(String.format("Project not found for %s: %s", column, value));
}
}
Aggregations