Search in sources :

Example 11 with TemplateDataStoreVO

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

the class TemplateDataStoreDaoImpl method findByTemplateZoneReady.

@Override
public TemplateDataStoreVO findByTemplateZoneReady(final long templateId, final Long zoneId) {
    List<DataStore> imgStores = null;
    imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
    if (imgStores != null) {
        Collections.shuffle(imgStores);
        for (final DataStore store : imgStores) {
            final List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
            if (sRes != null && sRes.size() > 0) {
                return sRes.get(0);
            }
        }
    }
    return null;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 12 with TemplateDataStoreVO

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

the class StorageCacheReplacementAlgorithmLRU method chooseOneToBeReplaced.

@Override
public DataObject chooseOneToBeReplaced(final DataStore store) {
    if (unusedTimeInterval == null) {
        unusedTimeInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementLRUTimeInterval.key()), 30);
    }
    final Calendar cal = Calendar.getInstance();
    cal.setTime(DateUtil.now());
    cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue());
    final Date bef = cal.getTime();
    final QueryBuilder<TemplateDataStoreVO> sc = QueryBuilder.create(TemplateDataStoreVO.class);
    sc.and(sc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    sc.and(sc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    sc.and(sc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    sc.and(sc.entity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole());
    sc.and(sc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    final TemplateDataStoreVO template = sc.find();
    if (template != null) {
        return templateFactory.getTemplate(template.getTemplateId(), store);
    }
    final QueryBuilder<VolumeDataStoreVO> volSc = QueryBuilder.create(VolumeDataStoreVO.class);
    volSc.and(volSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    volSc.and(volSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    volSc.and(volSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    volSc.and(volSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    final VolumeDataStoreVO volume = volSc.find();
    if (volume != null) {
        return volumeFactory.getVolume(volume.getVolumeId(), store);
    }
    final QueryBuilder<SnapshotDataStoreVO> snapshotSc = QueryBuilder.create(SnapshotDataStoreVO.class);
    snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
    snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
    snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
    snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ, store.getRole());
    snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
    final SnapshotDataStoreVO snapshot = snapshotSc.find();
    if (snapshot != null) {
        return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
    }
    return null;
}
Also used : Calendar(java.util.Calendar) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Example 13 with TemplateDataStoreVO

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

the class TemplateDataFactoryImpl method listTemplateOnCache.

@Override
public List<TemplateInfo> listTemplateOnCache(final long templateId) {
    final List<TemplateDataStoreVO> cacheTmpls = templateStoreDao.listOnCache(templateId);
    final List<TemplateInfo> tmplObjs = new ArrayList<>();
    for (final TemplateDataStoreVO cacheTmpl : cacheTmpls) {
        final long storeId = cacheTmpl.getDataStoreId();
        final DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
        final TemplateInfo tmplObj = getTemplate(templateId, store);
        tmplObjs.add(tmplObj);
    }
    return tmplObjs;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 14 with TemplateDataStoreVO

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

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

the class TemplateServiceImpl method copyTemplate.

@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(final TemplateInfo srcTemplate, final DataStore destStore) {
    // generate a URL from source template ssvm to download to destination data store
    final String url = generateCopyUrl(srcTemplate);
    if (url == null) {
        s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
        throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
    }
    final TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting source template url to " + url);
    }
    tmplForCopy.setUrl(url);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Mark template_store_ref entry as Creating");
    }
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final DataObject templateOnStore = destStore.create(tmplForCopy);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
    }
    try {
        final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
        final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
        destStore.getDriver().createAsync(destStore, templateOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
        final TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
        if (templateStoreVO != null) {
            final TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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