Search in sources :

Example 11 with DatasetDataProject

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

the class FireStoreDao method lookupDirectoryEntryByPath.

public FireStoreDirectoryEntry lookupDirectoryEntryByPath(Dataset dataset, String path) {
    DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
    Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
    String datasetId = dataset.getId().toString();
    return directoryDao.retrieveByPath(firestore, datasetId, path);
}
Also used : Firestore(com.google.cloud.firestore.Firestore) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject)

Example 12 with DatasetDataProject

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

the class FireStoreDao method validateRefIds.

public List<String> validateRefIds(Dataset dataset, List<String> refIdArray) {
    DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
    Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
    String datasetId = dataset.getId().toString();
    return directoryDao.validateRefIds(firestore, datasetId, refIdArray);
}
Also used : Firestore(com.google.cloud.firestore.Firestore) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject)

Example 13 with DatasetDataProject

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

use of bio.terra.service.dataset.DatasetDataProject 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)

Example 15 with DatasetDataProject

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

the class FireStoreDao method deleteDirectoryEntry.

public boolean deleteDirectoryEntry(Dataset dataset, String fileId) {
    DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
    Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
    String datasetId = dataset.getId().toString();
    return directoryDao.deleteDirectoryEntry(firestore, datasetId, fileId);
}
Also used : Firestore(com.google.cloud.firestore.Firestore) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject)

Aggregations

DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)20 Firestore (com.google.cloud.firestore.Firestore)10 CollectionReference (com.google.cloud.firestore.CollectionReference)6 Query (com.google.cloud.firestore.Query)5 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)4 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)4 Dataset (bio.terra.service.dataset.Dataset)2 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)2 FileSystemCorruptException (bio.terra.service.filedata.exception.FileSystemCorruptException)2 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)2 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)2 ExecutionException (java.util.concurrent.ExecutionException)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 SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)1 DocumentReference (com.google.cloud.firestore.DocumentReference)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1