Search in sources :

Example 26 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method handleSysTemplateDownload.

@Override
public void handleSysTemplateDownload(final HypervisorType hostHyper, final Long dcId) {
    final Set<VMTemplateVO> toBeDownloaded = new HashSet<>();
    final List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(dcId));
    if (stores == null || stores.isEmpty()) {
        return;
    }
    /* Download all the templates in zone with the same hypervisortype */
    for (final DataStore store : stores) {
        final List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
        final List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
        for (final VMTemplateVO rtngTmplt : rtngTmplts) {
            if (rtngTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(rtngTmplt);
            }
        }
        for (final VMTemplateVO builtinTmplt : defaultBuiltin) {
            if (builtinTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(builtinTmplt);
            }
        }
        for (final VMTemplateVO template : toBeDownloaded) {
            final TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
            if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                associateTemplateToZone(template.getId(), dcId);
                s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
                final TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
                createTemplateAsync(tmplt, store, null);
            }
        }
    }
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) HashSet(java.util.HashSet)

Example 27 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore 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 28 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class ObjectInDataStoreManagerImpl method deleteIfNotReady.

@Override
public boolean deleteIfNotReady(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 && destTmpltPool.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                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 if (dataObj.getType() == DataObjectType.SNAPSHOT) {
            final SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
            if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                snapshotDataStoreDao.remove(destSnapshotStore.getId());
            }
            return true;
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                return true;
            case SNAPSHOT:
                final SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    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 && destVolumeStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    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() + "), no need to delete from object in store ref table");
    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)

Example 29 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class DefaultEndPointSelector method select.

@Override
public EndPoint select(final DataObject object) {
    final DataStore store = object.getDataStore();
    final EndPoint ep = select(store);
    if (ep != null) {
        return ep;
    }
    if (object instanceof TemplateInfo) {
        final TemplateInfo tmplInfo = (TemplateInfo) object;
        if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) {
            // for bootstrap system vm template downloading to region image store
            return LocalHostEndpoint.getEndpoint();
        }
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Example 30 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class VolumeDataFactoryImpl method getVolume.

@Override
public VolumeInfo getVolume(final long volumeId, final boolean toBeLiveMigrated) {
    final VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
    if (volumeVO == null) {
        return null;
    }
    VolumeObject vol;
    if (volumeVO.getPoolId() == null) {
        DataStore store = null;
        final VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
        }
        vol = VolumeObject.getVolumeObject(store, volumeVO, toBeLiveMigrated);
    } else {
        final DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
        vol = VolumeObject.getVolumeObject(store, volumeVO, toBeLiveMigrated);
    }
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Aggregations

DataStore (com.cloud.engine.subsystem.api.storage.DataStore)96 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)43 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 ExecutionException (java.util.concurrent.ExecutionException)23 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)19 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)17 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)17 ArrayList (java.util.ArrayList)17 VolumeVO (com.cloud.storage.VolumeVO)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)14 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)14 DB (com.cloud.utils.db.DB)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)12 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)12 ConfigurationException (javax.naming.ConfigurationException)12 Answer (com.cloud.agent.api.Answer)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)10