Search in sources :

Example 1 with SnapshotNotFoundException

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

the class DrsService method parseAndValidateDrsId.

private DrsId parseAndValidateDrsId(String drsObjectId) {
    DrsId drsId = drsIdService.fromObjectId(drsObjectId);
    try {
        UUID snapshotId = UUID.fromString(drsId.getSnapshotId());
        snapshotDao.retrieveSummaryById(snapshotId);
        return drsId;
    } catch (IllegalArgumentException ex) {
        throw new InvalidDrsIdException("Invalid object id format '" + drsObjectId + "'", ex);
    } catch (SnapshotNotFoundException ex) {
        throw new DrsObjectNotFoundException("No snapshot found for DRS object id '" + drsObjectId + "'", ex);
    }
}
Also used : InvalidDrsIdException(bio.terra.service.filedata.exception.InvalidDrsIdException) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) DrsObjectNotFoundException(bio.terra.service.filedata.exception.DrsObjectNotFoundException) UUID(java.util.UUID)

Example 2 with SnapshotNotFoundException

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

the class DeleteSnapshotPrimaryDataStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    try {
        // this fault is used by the SnapshotConnectedTest > testOverlappingDeletes
        if (configService.testInsertFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_STOP_FAULT)) {
            logger.info("SNAPSHOT_DELETE_LOCK_CONFLICT_STOP_FAULT");
            while (!configService.testInsertFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT)) {
                logger.info("Sleeping for CONTINUE FAULT");
                TimeUnit.SECONDS.sleep(5);
            }
            logger.info("SNAPSHOT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT");
        }
        Snapshot snapshot = snapshotService.retrieve(snapshotId);
        bigQueryPdao.deleteSnapshot(snapshot);
        // Remove snapshot file references from the underlying datasets
        for (SnapshotSource snapshotSource : snapshot.getSnapshotSources()) {
            Dataset dataset = datasetService.retrieve(snapshotSource.getDataset().getId());
            dependencyDao.deleteSnapshotFileDependencies(dataset, snapshotId.toString());
        }
        fileDao.deleteFilesFromSnapshot(snapshot);
    } catch (SnapshotNotFoundException | DatasetNotFoundException nfe) {
    // If we do not find the snapshot or dataset, we assume things are already clean
    }
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) Dataset(bio.terra.service.dataset.Dataset) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) SnapshotSource(bio.terra.service.snapshot.SnapshotSource) DatasetNotFoundException(bio.terra.service.dataset.exception.DatasetNotFoundException)

Example 3 with SnapshotNotFoundException

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

the class CreateSnapshotMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    try {
        Snapshot snapshot = snapshotService.makeSnapshotFromSnapshotRequest(snapshotReq);
        UUID snapshotId = snapshotDao.createAndLock(snapshot, context.getFlightId());
        FlightMap workingMap = context.getWorkingMap();
        workingMap.put(SnapshotWorkingMapKeys.SNAPSHOT_ID, snapshotId);
        SnapshotSummary snapshotSummary = snapshotDao.retrieveSummaryById(snapshot.getId());
        SnapshotSummaryModel response = snapshotService.makeSummaryModelFromSummary(snapshotSummary);
        FlightUtils.setResponse(context, response, HttpStatus.CREATED);
        return StepResult.getStepResultSuccess();
    } catch (InvalidSnapshotException isEx) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, isEx);
    } catch (SnapshotNotFoundException ex) {
        FlightUtils.setErrorResponse(context, ex.toString(), HttpStatus.BAD_REQUEST);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, ex);
    }
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotSummary(bio.terra.service.snapshot.SnapshotSummary) InvalidSnapshotException(bio.terra.service.snapshot.exception.InvalidSnapshotException) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult)

Example 4 with SnapshotNotFoundException

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

the class SnapshotDao method getExclusiveLockState.

/**
 * This method is protected because it's for use in tests only.
 * Currently, we don't expose the lock state of a snapshot outside of the DAO for other API code to consume.
 * @param id
 * @return the flightid that holds an exclusive lock. null if none.
 */
protected String getExclusiveLockState(UUID id) {
    try {
        String sql = "SELECT flightid FROM snapshot WHERE id = :id";
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("id", id);
        return jdbcTemplate.queryForObject(sql, params, String.class);
    } catch (EmptyResultDataAccessException ex) {
        throw new SnapshotNotFoundException("Snapshot not found for id " + id);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 5 with SnapshotNotFoundException

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

the class SnapshotDao method retrieveSnapshotByName.

public Snapshot retrieveSnapshotByName(String name) {
    String sql = "SELECT * FROM snapshot WHERE name = :name";
    MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", name);
    Snapshot snapshot = retrieveWorker(sql, params);
    if (snapshot == null) {
        throw new SnapshotNotFoundException("Snapshot not found - name: '" + name + "'");
    }
    return snapshot;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException)

Aggregations

SnapshotNotFoundException (bio.terra.service.snapshot.exception.SnapshotNotFoundException)9 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)5 Snapshot (bio.terra.service.snapshot.Snapshot)3 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)3 UUID (java.util.UUID)2 DeleteResponseModel (bio.terra.model.DeleteResponseModel)1 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)1 Dataset (bio.terra.service.dataset.Dataset)1 DatasetNotFoundException (bio.terra.service.dataset.exception.DatasetNotFoundException)1 DrsObjectNotFoundException (bio.terra.service.filedata.exception.DrsObjectNotFoundException)1 InvalidDrsIdException (bio.terra.service.filedata.exception.InvalidDrsIdException)1 SnapshotSource (bio.terra.service.snapshot.SnapshotSource)1 SnapshotSummary (bio.terra.service.snapshot.SnapshotSummary)1 InvalidSnapshotException (bio.terra.service.snapshot.exception.InvalidSnapshotException)1 FlightMap (bio.terra.stairway.FlightMap)1 StepResult (bio.terra.stairway.StepResult)1