Search in sources :

Example 1 with DatasetDataProjectSummary

use of bio.terra.service.dataset.DatasetDataProjectSummary 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 2 with DatasetDataProjectSummary

use of bio.terra.service.dataset.DatasetDataProjectSummary in project jade-data-repo by DataBiosphere.

the class DataLocationService method getOrCreateProject.

/**
 * Fetch existing DatasetDataProject for the Dataset.
 * Create a new one if none exists already.
 * Note that there can be only one project for a Dataset. This is assumed throughout the application logic, most of
 * which currently resides in the Flights, and they would not work correctly if this one-to-one mapping were ever
 * violated. For this reason, the check for an existing project below needs to stay at the beginning of this method.
 * @param dataset
 * @return a populated and valid DatasetDataProject
 */
public DatasetDataProject getOrCreateProject(Dataset dataset) throws InterruptedException {
    // check if for an existing DatasetDataProject first, and return here if found one
    Optional<DatasetDataProject> existingDataProject = getProject(dataset);
    if (existingDataProject.isPresent()) {
        return existingDataProject.get();
    }
    // if we've made it here, then we need to create a new cloud resource and DatasetDataProject
    // TODO: if we are in production, don't reuse projects we don't know about
    // TODO: add a property to specify which people can view data projects
    GoogleProjectRequest googleProjectRequest = new GoogleProjectRequest().projectId(dataLocationSelector.projectIdForDataset(dataset)).profileId(dataset.getDefaultProfileId()).serviceIds(DATA_PROJECT_SERVICE_IDS).roleIdentityMapping(getStewardPolicy());
    GoogleProjectResource googleProjectResource = resourceService.getOrCreateProject(googleProjectRequest);
    // create the DatasetDataProjectSummary object first, which just holds all the IDs
    DatasetDataProjectSummary datasetDataProjectSummary = new DatasetDataProjectSummary().projectResourceId(googleProjectResource.getRepositoryId()).datasetId(dataset.getId());
    UUID datasetDataProjectId = dataProjectDao.createDatasetDataProject(datasetDataProjectSummary);
    datasetDataProjectSummary.id(datasetDataProjectId);
    // then create the DatasetDataProject object from the summary
    return new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource);
}
Also used : GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) GoogleProjectRequest(bio.terra.service.resourcemanagement.google.GoogleProjectRequest) DatasetDataProjectSummary(bio.terra.service.dataset.DatasetDataProjectSummary) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject) UUID(java.util.UUID)

Aggregations

DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)2 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)2 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)1 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)1 GoogleProjectRequest (bio.terra.service.resourcemanagement.google.GoogleProjectRequest)1 UUID (java.util.UUID)1