Search in sources :

Example 1 with FileDependencyException

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();
}
Also used : FireStoreFile(bio.terra.service.filedata.google.firestore.FireStoreFile) FlightMap(bio.terra.stairway.FlightMap) FileDependencyException(bio.terra.service.filedata.exception.FileDependencyException) FileSystemAbortTransactionException(bio.terra.service.filedata.exception.FileSystemAbortTransactionException) StepResult(bio.terra.stairway.StepResult)

Aggregations

FileDependencyException (bio.terra.service.filedata.exception.FileDependencyException)1 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)1 FireStoreFile (bio.terra.service.filedata.google.firestore.FireStoreFile)1 FlightMap (bio.terra.stairway.FlightMap)1 StepResult (bio.terra.stairway.StepResult)1