Search in sources :

Example 1 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class FireStoreDao method snapshotCompute.

public void snapshotCompute(Snapshot snapshot) {
    SnapshotDataProject dataProject = dataLocationService.getProjectOrThrow(snapshot);
    Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
    String snapshotId = snapshot.getId().toString();
    FireStoreDirectoryEntry topDir = directoryDao.retrieveByPath(firestore, snapshotId, "/");
    // step. So there is nothing to compute
    if (topDir != null) {
        computeDirectory(firestore, snapshotId, topDir);
    }
}
Also used : Firestore(com.google.cloud.firestore.Firestore) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 2 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject 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 3 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class SnapshotAuthzBqJobUserStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    Snapshot snapshot = snapshotService.retrieveByName(snapshotName);
    SnapshotDataProject projectForSnapshot = dataLocationService.getOrCreateProject(snapshot);
    Map<IamRole, String> policyMap = workingMap.get(SnapshotWorkingMapKeys.POLICY_MAP, Map.class);
    // Allow the custodian to make queries in this project.
    // The underlying service provides retries so we do not need to retry this operation
    resourceService.grantPoliciesBqJobUser(projectForSnapshot.getGoogleProjectId(), Collections.singletonList(policyMap.get(IamRole.CUSTODIAN)));
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) IamRole(bio.terra.service.iam.IamRole) FlightMap(bio.terra.stairway.FlightMap) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 4 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class EncodeFileTest method getFileRefIdFromSnapshot.

private String getFileRefIdFromSnapshot(SnapshotSummaryModel snapshotSummary) throws InterruptedException {
    Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotSummary.getName());
    SnapshotDataProject dataProject = dataLocationService.getOrCreateProject(snapshot);
    BigQueryProject bigQueryProject = BigQueryProject.get(dataProject.getGoogleProjectId());
    StringBuilder builder = new StringBuilder().append("SELECT file_ref FROM `").append(dataProject.getGoogleProjectId()).append('.').append(snapshot.getName()).append(".file` AS T").append(" WHERE T.file_ref IS NOT NULL LIMIT 1");
    String sql = builder.toString();
    try {
        QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(sql).build();
        TableResult result = bigQueryProject.getBigQuery().query(queryConfig);
        FieldValueList row = result.iterateAll().iterator().next();
        FieldValue idValue = row.get(0);
        String drsUri = idValue.getStringValue();
        return drsUri;
    } catch (InterruptedException ie) {
        throw new PdaoException("get file ref id from snapshot unexpectedly interrupted", ie);
    }
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) TableResult(com.google.cloud.bigquery.TableResult) BigQueryProject(bio.terra.service.tabulardata.google.BigQueryProject) PdaoException(bio.terra.common.exception.PdaoException) FieldValueList(com.google.cloud.bigquery.FieldValueList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FieldValue(com.google.cloud.bigquery.FieldValue) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 5 with SnapshotDataProject

use of bio.terra.service.snapshot.SnapshotDataProject in project jade-data-repo by DataBiosphere.

the class FireStoreDao method addFilesToSnapshot.

public void addFilesToSnapshot(Dataset dataset, Snapshot snapshot, List<String> refIds) {
    DatasetDataProject datasetDataProject = dataLocationService.getProjectOrThrow(dataset);
    Firestore datasetFirestore = FireStoreProject.get(datasetDataProject.getGoogleProjectId()).getFirestore();
    SnapshotDataProject snapshotDataProject = dataLocationService.getProjectOrThrow(snapshot);
    Firestore snapshotFirestore = FireStoreProject.get(snapshotDataProject.getGoogleProjectId()).getFirestore();
    String datasetId = dataset.getId().toString();
    // TODO: Do we need to make sure the dataset name does not contain characters that are invalid for paths?
    // Added the work to figure that out to DR-325
    String datasetName = dataset.getName();
    String snapshotId = snapshot.getId().toString();
    for (String fileId : refIds) {
        directoryDao.addEntryToSnapshot(datasetFirestore, datasetId, datasetName, snapshotFirestore, snapshotId, fileId);
    }
}
Also used : Firestore(com.google.cloud.firestore.Firestore) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Aggregations

SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)7 Firestore (com.google.cloud.firestore.Firestore)3 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 Snapshot (bio.terra.service.snapshot.Snapshot)2 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)2 PdaoException (bio.terra.common.exception.PdaoException)1 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 IamRole (bio.terra.service.iam.IamRole)1 DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)1 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)1 GoogleProjectRequest (bio.terra.service.resourcemanagement.google.GoogleProjectRequest)1 BigQueryProject (bio.terra.service.tabulardata.google.BigQueryProject)1 FlightMap (bio.terra.stairway.FlightMap)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 FieldValueList (com.google.cloud.bigquery.FieldValueList)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 TableResult (com.google.cloud.bigquery.TableResult)1 UUID (java.util.UUID)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1