use of bio.terra.service.filedata.exception.FileDependencyException in project jade-data-repo by DataBiosphere.
the class DeleteFileLookupStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
if (configService.testInsertFault(ConfigEnum.FILE_DELETE_LOCK_CONFLICT_STOP_FAULT)) {
logger.info("FILE_DELETE_LOCK_CONFLICT_STOP_FAULT");
while (!configService.testInsertFault(ConfigEnum.FILE_DELETE_LOCK_CONFLICT_CONTINUE_FAULT)) {
logger.info("Sleeping for CONTINUE FAULT");
TimeUnit.SECONDS.sleep(5);
}
logger.info("FILE_DELETE_LOCK_CONFLICT_CONTINUE_FAULT");
}
try {
// If we are restarting, we may have already retrieved and saved the file,
// so we check the working map before doing the lookup.
FlightMap workingMap = context.getWorkingMap();
FireStoreFile fireStoreFile = workingMap.get(FileMapKeys.FIRESTORE_FILE, FireStoreFile.class);
if (fireStoreFile == null) {
fireStoreFile = fileDao.lookupFile(dataset, fileId);
if (fireStoreFile != null) {
workingMap.put(FileMapKeys.FIRESTORE_FILE, fireStoreFile);
}
}
// steps know there is no file. If there is a file, check dependencies here.
if (fireStoreFile != null) {
if (dependencyDao.fileHasSnapshotReference(dataset, fireStoreFile.getFileId())) {
throw new FileDependencyException("File is used by at least one snapshot and cannot be deleted");
}
}
} catch (FileSystemAbortTransactionException rex) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, rex);
}
return StepResult.getStepResultSuccess();
}
Aggregations