Search in sources :

Example 1 with DatasetNotFoundException

use of bio.terra.service.dataset.exception.DatasetNotFoundException in project jade-data-repo by DataBiosphere.

the class DatasetDao method getExclusiveLock.

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

Example 2 with DatasetNotFoundException

use of bio.terra.service.dataset.exception.DatasetNotFoundException 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 DatasetNotFoundException

use of bio.terra.service.dataset.exception.DatasetNotFoundException in project jade-data-repo by DataBiosphere.

the class DatasetDao method getSharedLocks.

/**
 * TESTING ONLY. This method returns the internal state of the shared locks on a dataset.
 * It is protected because it's for use in tests only.
 * Currently, we don't expose the lock state of a dataset outside of the DAO for other API code to consume.
 * @param id the dataset id
 * @return the array of flight ids that hold shared locks. empty if no shared locks are taken out.
 */
protected String[] getSharedLocks(UUID id) {
    try {
        String sql = "SELECT sharedlock FROM dataset WHERE id = :id";
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("id", id);
        Array arr = jdbcTemplate.queryForObject(sql, params, Array.class);
        if (arr == null) {
            throw new CorruptMetadataException("Dataset shared locks array column should not be null. id " + id);
        }
        return (String[]) arr.getArray();
    } catch (EmptyResultDataAccessException | SQLException ex) {
        throw new DatasetNotFoundException("Dataset not found for id " + id);
    }
}
Also used : Array(java.sql.Array) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SQLException(java.sql.SQLException) DatasetNotFoundException(bio.terra.service.dataset.exception.DatasetNotFoundException) CorruptMetadataException(bio.terra.service.snapshot.exception.CorruptMetadataException)

Example 4 with DatasetNotFoundException

use of bio.terra.service.dataset.exception.DatasetNotFoundException in project jade-data-repo by DataBiosphere.

the class DatasetDao method retrieveSummaryByName.

public DatasetSummary retrieveSummaryByName(String name) {
    try {
        String sql = "SELECT " + "id, name, description, default_profile_id, additional_profile_ids, created_date " + "FROM dataset WHERE name = :name";
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", name);
        return jdbcTemplate.queryForObject(sql, params, new DatasetSummaryMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new DatasetNotFoundException("Dataset not found for name " + name);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DatasetNotFoundException(bio.terra.service.dataset.exception.DatasetNotFoundException)

Example 5 with DatasetNotFoundException

use of bio.terra.service.dataset.exception.DatasetNotFoundException in project jade-data-repo by DataBiosphere.

the class DatasetDao method retrieveSummaryById.

/**
 * Retrieves a DatasetSummary object from the dataset id.
 * @param id the dataset id
 * @param onlyRetrieveAvailable true to exclude datasets that are exclusively locked, false to include all datasets
 * @return the DatasetSummary object
 */
public DatasetSummary retrieveSummaryById(UUID id, boolean onlyRetrieveAvailable) {
    try {
        String sql = "SELECT " + "id, name, description, default_profile_id, additional_profile_ids, created_date " + "FROM dataset WHERE id = :id";
        if (onlyRetrieveAvailable) {
            // exclude datasets that are exclusively locked
            sql += " AND flightid IS NULL";
        }
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("id", id);
        return jdbcTemplate.queryForObject(sql, params, new DatasetSummaryMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new DatasetNotFoundException("Dataset not found for id " + id.toString());
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DatasetNotFoundException(bio.terra.service.dataset.exception.DatasetNotFoundException)

Aggregations

DatasetNotFoundException (bio.terra.service.dataset.exception.DatasetNotFoundException)6 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 Dataset (bio.terra.service.dataset.Dataset)1 Snapshot (bio.terra.service.snapshot.Snapshot)1 SnapshotSource (bio.terra.service.snapshot.SnapshotSource)1 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)1 SnapshotNotFoundException (bio.terra.service.snapshot.exception.SnapshotNotFoundException)1 Array (java.sql.Array)1 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1