Search in sources :

Example 16 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method getDataStoreRole.

public static DataStoreRole getDataStoreRole(final Snapshot snapshot, final SnapshotDataStoreDao snapshotStoreDao, final DataStoreManager dataStoreMgr) {
    final SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotStore == null) {
        return DataStoreRole.Image;
    }
    final long storagePoolId = snapshotStore.getDataStoreId();
    final DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    final Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
    if (mapCapabilities != null) {
        final String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
        final Boolean supportsStorageSystemSnapshots = new Boolean(value);
        if (supportsStorageSystemSnapshots) {
            return DataStoreRole.Primary;
        }
    }
    return DataStoreRole.Image;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 17 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createTemplateResponses.

@Override
public List<TemplateResponse> createTemplateResponses(final ResponseView view, final long templateId, final Long snapshotId, final Long volumeId, final boolean readyOnly) {
    Long zoneId = null;
    if (snapshotId != null) {
        final Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
        final VolumeVO volume = findVolumeById(snapshot.getVolumeId());
        // if volume comes back null, use another technique to try to discover the zone
        if (volume == null) {
            final SnapshotDataStoreVO snapshotStore = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
            if (snapshotStore != null) {
                final long storagePoolId = snapshotStore.getDataStoreId();
                final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
                if (storagePool != null) {
                    zoneId = storagePool.getDataCenterId();
                }
            }
        } else {
            zoneId = volume.getDataCenterId();
        }
    } else {
        final VolumeVO volume = findVolumeById(volumeId);
        zoneId = volume.getDataCenterId();
    }
    if (zoneId == null) {
        throw new CloudRuntimeException("Unable to determine the zone ID");
    }
    return createTemplateResponses(view, templateId, zoneId, readyOnly);
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 18 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method deleteImageStore.

@Override
public boolean deleteImageStore(final DeleteImageStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that image store exists
    final ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the image
    // store to be deleted
    final List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
    }
    final List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
    }
    // search if there are user templates stored on this image store, excluding system, builtin templates
    final List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 19 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method deleteSecondaryStagingStore.

@Override
public boolean deleteSecondaryStagingStore(final DeleteSecondaryStagingStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that cache store exists
    final ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Cache store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the cache
    // store that is currently referenced
    final List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listActiveOnCache(storeId);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging snapshots currently in use!");
    }
    final List<VolumeDataStoreVO> volumes = _volumeStoreDao.listActiveOnCache(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging volumes currently in use!");
    }
    final List<TemplateDataStoreVO> templates = _templateStoreDao.listActiveOnCache(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete cache store with staging templates currently in use!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.ImageCache);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 20 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method getDataStoreRole.

public DataStoreRole getDataStoreRole(final Snapshot snapshot) {
    final SnapshotDataStoreVO snapshotStore = _snapshotDataStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotStore == null) {
        return DataStoreRole.Image;
    }
    final long storagePoolId = snapshotStore.getDataStoreId();
    final DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    final Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
    if (mapCapabilities != null) {
        final String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
        final Boolean supportsStorageSystemSnapshots = new Boolean(value);
        if (supportsStorageSystemSnapshots) {
            return DataStoreRole.Primary;
        }
    }
    return DataStoreRole.Image;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Aggregations

SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)34 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 SnapshotVO (com.cloud.storage.SnapshotVO)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 SnapshotStrategy (com.cloud.engine.subsystem.api.storage.SnapshotStrategy)4 DB (com.cloud.utils.db.DB)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 VolumeVO (com.cloud.storage.VolumeVO)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2