use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class CreateDatasetPrimaryDataStep method undoStep.
@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
Dataset dataset = getDataset(context);
// get the cloud project for the dataset if it exists
Optional<DatasetDataProject> optDataProject = dataLocationService.getProject(dataset);
if (optDataProject.isPresent()) {
// there can only be primary data to delete if a cloud project exists for the dataset
pdao.deleteDataset(dataset);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDao method lookupFile.
public FireStoreFile lookupFile(Dataset dataset, String fileId) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
String datasetId = dataset.getId().toString();
return fileDao.retrieveFileMetadata(firestore, datasetId, fileId);
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDependencyDao method storeSnapshotFileDependency.
public void storeSnapshotFileDependency(Dataset dataset, String snapshotId, String fileId) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
ApiFuture<Void> transaction = fireStoreProject.getFirestore().runTransaction(xn -> {
Query query = depColl.whereEqualTo("fileId", fileId).whereEqualTo("snapshotId", snapshotId);
ApiFuture<QuerySnapshot> querySnapshot = query.get();
// There should be zero or one documents. Since we keep track of greater than one reference using the
// reference count.
List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
switch(documents.size()) {
case 0:
{
// no dependency yet. Let's make one
FireStoreDependency fireStoreDependency = new FireStoreDependency().snapshotId(snapshotId).fileId(fileId).refCount(1L);
DocumentReference docRef = depColl.document();
xn.set(docRef, fireStoreDependency);
break;
}
case 1:
{
// existing dependency; increment the reference count
QueryDocumentSnapshot docSnap = documents.get(0);
FireStoreDependency fireStoreDependency = docSnap.toObject(FireStoreDependency.class);
fireStoreDependency.refCount(fireStoreDependency.getRefCount() + 1);
xn.set(docSnap.getReference(), fireStoreDependency);
break;
}
default:
throw new FileSystemCorruptException("Found more than one document for a file dependency");
}
return null;
});
fireStoreUtils.transactionGet("store dependency", transaction);
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDependencyDao method deleteSnapshotFileDependencies.
public void deleteSnapshotFileDependencies(Dataset dataset, String snapshotId) throws InterruptedException {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
Query query = depColl.whereEqualTo("snapshotId", snapshotId);
ApiFuture<QuerySnapshot> querySnapshot = query.get();
try {
List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
for (DocumentSnapshot docSnap : documents) {
logger.info("deleting: " + docSnap.toString());
docSnap.getReference().delete();
}
} catch (ExecutionException ex) {
throw new FileSystemExecutionException("delete dependencies - execution exception", ex);
}
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDependencyDao method removeSnapshotFileDependency.
public void removeSnapshotFileDependency(Dataset dataset, String snapshotId, String fileId) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
ApiFuture<Void> transaction = fireStoreProject.getFirestore().runTransaction(xn -> {
Query query = depColl.whereEqualTo("fileId", fileId).whereEqualTo("snapshotId", snapshotId);
ApiFuture<QuerySnapshot> querySnapshot = query.get();
List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
if (documents.size() == 0) {
// No file - nothing to delete
return null;
}
if (documents.size() > 1) {
throw new FileSystemCorruptException("Found more than one document for a file dependency");
}
QueryDocumentSnapshot docSnap = documents.get(0);
FireStoreDependency fireStoreDependency = docSnap.toObject(FireStoreDependency.class);
if (fireStoreDependency.getRefCount() <= 1) {
xn.delete(docSnap.getReference());
} else {
fireStoreDependency.refCount(fireStoreDependency.getRefCount() - 1);
xn.set(docSnap.getReference(), fireStoreDependency);
}
return null;
});
fireStoreUtils.transactionGet("delete dependency", transaction);
}
Aggregations