Search in sources :

Example 1 with TemplateDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO in project cloudstack by apache.

the class StorageCacheReplacementAlgorithmLRUTest method testSelectObjectFailed.

@Test
public void testSelectObjectFailed() {
    cacheReplacementAlgorithm.setUnusedTimeInterval(1);
    try {
        VMTemplateVO template = new VMTemplateVO();
        template.setTemplateType(Storage.TemplateType.USER);
        template.setUrl(UUID.randomUUID().toString());
        template.setUniqueName(UUID.randomUUID().toString());
        template.setName(UUID.randomUUID().toString());
        template.setPublicTemplate(true);
        template.setFeatured(true);
        template.setRequiresHvm(true);
        template.setBits(64);
        template.setFormat(Storage.ImageFormat.VHD);
        template.setEnablePassword(true);
        template.setEnableSshKey(true);
        template.setGuestOSId(1);
        template.setBootable(true);
        template.setPrepopulate(true);
        template.setCrossZones(true);
        template.setExtractable(true);
        template = templateDao.persist(template);
        VMTemplateVO template2 = new VMTemplateVO();
        template2.setTemplateType(Storage.TemplateType.USER);
        template2.setUrl(UUID.randomUUID().toString());
        template2.setUniqueName(UUID.randomUUID().toString());
        template2.setName(UUID.randomUUID().toString());
        template2.setPublicTemplate(true);
        template2.setFeatured(true);
        template2.setRequiresHvm(true);
        template2.setBits(64);
        template2.setFormat(Storage.ImageFormat.VHD);
        template2.setEnablePassword(true);
        template2.setEnableSshKey(true);
        template2.setGuestOSId(1);
        template2.setBootable(true);
        template2.setPrepopulate(true);
        template2.setCrossZones(true);
        template2.setExtractable(true);
        template2 = templateDao.persist(template2);
        ImageStoreVO imageStoreVO = new ImageStoreVO();
        imageStoreVO.setRole(DataStoreRole.ImageCache);
        imageStoreVO.setName(UUID.randomUUID().toString());
        imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
        imageStoreVO.setProtocol("nfs");
        imageStoreVO.setUrl(UUID.randomUUID().toString());
        imageStoreVO = imageStoreDao.persist(imageStoreVO);
        Date date = DateUtil.now();
        TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
        templateStoreVO1.setLastUpdated(date);
        templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO1.setDataStoreId(imageStoreVO.getId());
        templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO1.setCopy(true);
        templateStoreVO1.setTemplateId(template.getId());
        templateDataStoreDao.persist(templateStoreVO1);
        TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
        templateStoreVO2.setLastUpdated(date);
        templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO2.setDataStoreId(imageStoreVO.getId());
        templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO2.setCopy(true);
        templateStoreVO2.setTemplateId(template2.getId());
        templateDataStoreDao.persist(templateStoreVO2);
        DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
        Assert.assertNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date) Test(org.junit.Test)

Example 2 with TemplateDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO in project cloudstack by apache.

the class TemplateServiceImpl method handleSysTemplateDownload.

@Override
public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) {
    Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
    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 (DataStore store : stores) {
        List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
        List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
        for (VMTemplateVO rtngTmplt : rtngTmplts) {
            if (rtngTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(rtngTmplt);
            }
        }
        for (VMTemplateVO builtinTmplt : defaultBuiltin) {
            if (builtinTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(builtinTmplt);
            }
        }
        for (VMTemplateVO template : toBeDownloaded) {
            TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
            if (tmpltHost == null) {
                associateTemplateToZone(template.getId(), dcId);
                s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
                TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
                createTemplateAsync(tmplt, store, null);
            }
        }
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) HashSet(java.util.HashSet)

Example 3 with TemplateDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO in project cloudstack by apache.

the class TemplateObject method incRefCount.

@Override
public void incRefCount() {
    if (dataStore == null) {
        return;
    }
    if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
        TemplateDataStoreVO store = templateStoreDao.findByStoreTemplate(dataStore.getId(), getId());
        store.incrRefCnt();
        store.setLastUpdated(new Date());
        templateStoreDao.update(store.getId(), store);
    }
}
Also used : TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Example 4 with TemplateDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO in project cloudstack by apache.

the class TemplateServiceImpl method copyTemplate.

@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(TemplateInfo srcTemplate, DataStore destStore) {
    // Need to understand what is the background to use two different urls for copy and extract.
    if (srcTemplate.getFormat() == ImageFormat.OVA) {
        ImageStoreEntity tmpltStore = (ImageStoreEntity) srcTemplate.getDataStore();
        tmpltStore.createEntityExtractUrl(srcTemplate.getInstallPath(), srcTemplate.getFormat(), srcTemplate);
    }
    // generate a URL from source template ssvm to download to destination data store
    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 ");
    }
    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");
    }
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    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 {
        TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, (TemplateObject) templateOnStore, future);
        AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
        destStore.getDriver().createAsync(destStore, templateOnStore, caller);
    } catch (CloudRuntimeException ex) {
        // clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
        TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
        if (templateStoreVO != null) {
            TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ImageStoreEntity(org.apache.cloudstack.storage.image.datastore.ImageStoreEntity)

Example 5 with TemplateDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO in project cloudstack by apache.

the class TemplateServiceImpl method addSystemVMTemplatesToSecondary.

@Override
public void addSystemVMTemplatesToSecondary(DataStore store) {
    long storeId = store.getId();
    List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
    for (VMTemplateVO tmplt : rtngTmplts) {
        TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
        if (tmpltStore == null) {
            tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + '/', tmplt.getUrl());
            tmpltStore.setSize(0L);
            // no size information for
            tmpltStore.setPhysicalSize(0);
            // pre-seeded system vm templates
            tmpltStore.setDataStoreRole(store.getRole());
            _vmTemplateStoreDao.persist(tmpltStore);
        }
    }
}
Also used : VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Aggregations

TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)46 VMTemplateVO (com.cloud.storage.VMTemplateVO)22 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)22 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 Date (java.util.Date)13 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)7 TemplateApiResult (org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)7 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 DB (com.cloud.utils.db.DB)6 ExecutionException (java.util.concurrent.ExecutionException)6 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ConfigurationException (javax.naming.ConfigurationException)5 ImageStoreEntity (org.apache.cloudstack.storage.image.datastore.ImageStoreEntity)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4