Search in sources :

Example 1 with GoogleResourceNotFoundException

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();
}
Also used : SnapshotDataProjectSummary(bio.terra.service.snapshot.SnapshotDataProjectSummary) GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 2 with GoogleResourceNotFoundException

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);
}
Also used : GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) Bucket(com.google.cloud.storage.Bucket)

Example 3 with GoogleResourceNotFoundException

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);
}
Also used : Project(com.google.api.services.cloudresourcemanager.model.Project) GcsProject(bio.terra.service.filedata.google.gcs.GcsProject) GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) UUID(java.util.UUID)

Example 4 with GoogleResourceNotFoundException

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();
}
Also used : GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) DatasetDataProjectSummary(bio.terra.service.dataset.DatasetDataProjectSummary) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject)

Example 5 with GoogleResourceNotFoundException

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));
    }
}
Also used : GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)6 DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)2 GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)2 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)1 GcsProject (bio.terra.service.filedata.google.gcs.GcsProject)1 GoogleBucketRequest (bio.terra.service.resourcemanagement.google.GoogleBucketRequest)1 SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)1 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)1 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)1 Project (com.google.api.services.cloudresourcemanager.model.Project)1 Bucket (com.google.cloud.storage.Bucket)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1