Search in sources :

Example 16 with TemplateDataStoreVO

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

the class ObjectInDataStoreManagerImpl method delete.

@Override
public boolean delete(final DataObject dataObj) {
    final long objId = dataObj.getId();
    final DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            final VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId);
            if (destTmpltPool != null) {
                return templatePoolDao.remove(destTmpltPool.getId());
            } else {
                s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
                return true;
            }
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                final TemplateDataStoreVO destTmpltStore = templateDataStoreDao.findByStoreTemplate(dataStore.getId(), objId);
                if (destTmpltStore != null) {
                    return templateDataStoreDao.remove(destTmpltStore.getId());
                } else {
                    s_logger.warn("Template " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case SNAPSHOT:
                final SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null) {
                    return snapshotDataStoreDao.remove(destSnapshotStore.getId());
                } else {
                    s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case VOLUME:
                final VolumeDataStoreVO destVolumeStore = volumeDataStoreDao.findByStoreVolume(dataStore.getId(), objId);
                if (destVolumeStore != null) {
                    return volumeDataStoreDao.remove(destVolumeStore.getId());
                } else {
                    s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
        }
    }
    s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + ")");
    return false;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 17 with TemplateDataStoreVO

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

the class ConsoleProxyManagerImpl method isZoneReady.

public boolean isZoneReady(final Map<Long, ZoneHostInfo> zoneHostInfoMap, final long dataCenterId) {
    final ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
    if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) {
        final VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
        if (template == null) {
            logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch console proxy vm");
            return false;
        }
        final TemplateDataStoreVO templateHostRef = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, Status.DOWNLOADED);
        if (templateHostRef != null) {
            boolean useLocalStorage = false;
            final Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
            if (useLocal != null) {
                useLocalStorage = useLocal.booleanValue();
            }
            final List<Pair<Long, Integer>> l = _consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, useLocalStorage);
            if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
                return true;
            } else {
                logger.debug("Primary storage is not ready, wait until it is ready to launch console proxy");
            }
        } else {
            logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
        }
    }
    return false;
}
Also used : ZoneHostInfo(com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) Pair(com.cloud.utils.Pair)

Example 18 with TemplateDataStoreVO

use of com.cloud.storage.datastore.db.TemplateDataStoreVO 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 19 with TemplateDataStoreVO

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

the class TemplateManagerImpl method getImageStoreByTemplate.

// find image store where this template is located
@Override
public List<DataStore> getImageStoreByTemplate(final long templateId, final Long zoneId) {
    // find all eligible image stores for this zone scope
    final List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
    if (imageStores == null || imageStores.size() == 0) {
        return null;
    }
    final List<DataStore> stores = new ArrayList<>();
    for (final DataStore store : imageStores) {
        // check if the template is stored there
        final List<TemplateDataStoreVO> storeTmpl = _tmplStoreDao.listByTemplateStore(templateId, store.getId());
        if (storeTmpl != null && storeTmpl.size() > 0) {
            stores.add(store);
        }
    }
    return stores;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 20 with TemplateDataStoreVO

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

the class TemplateManagerImpl method prepareTemplateForCreate.

@Override
@DB
public VMTemplateStoragePoolVO prepareTemplateForCreate(final VMTemplateVO templ, final StoragePool pool) {
    final VMTemplateVO template = _tmpltDao.findById(templ.getId(), true);
    final long poolId = pool.getId();
    final long templateId = template.getId();
    final VMTemplateStoragePoolVO templateStoragePoolRef;
    final TemplateDataStoreVO templateStoreRef;
    templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
    if (templateStoragePoolRef != null) {
        templateStoragePoolRef.setMarkedForGC(false);
        _tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
        if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
            }
            return templateStoragePoolRef;
        }
    }
    templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, pool.getDataCenterId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    if (templateStoreRef == null) {
        s_logger.error("Unable to find a secondary storage host who has completely downloaded the template.");
        return null;
    }
    final List<StoragePoolHostVO> vos = _poolHostDao.listByHostStatus(poolId, com.cloud.host.Status.Up);
    if (vos == null || vos.isEmpty()) {
        throw new CloudRuntimeException("Cannot download " + templateId + " to poolId " + poolId + " since there is no host in the Up state connected to this pool");
    }
    if (templateStoragePoolRef == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Downloading template " + templateId + " to pool " + poolId);
        }
        final DataStore srcSecStore = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
        final TemplateInfo srcTemplate = _tmplFactory.getTemplate(templateId, srcSecStore);
        final AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.prepareTemplateOnPrimary(srcTemplate, pool);
        try {
            final TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("prepare template failed:" + result.getResult());
                return null;
            }
            return _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
        } catch (final Exception ex) {
            s_logger.debug("failed to copy template from image store:" + srcSecStore.getName() + " to primary storage");
        }
    }
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateApiResult(com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) DB(com.cloud.utils.db.DB)

Aggregations

TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)39 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)17 VMTemplateVO (com.cloud.storage.VMTemplateVO)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)11 Date (java.util.Date)9 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)6 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)5 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 URISyntaxException (java.net.URISyntaxException)5 ExecutionException (java.util.concurrent.ExecutionException)5 ConfigurationException (javax.naming.ConfigurationException)5 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)3