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();
}
}
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);
}
}
}
}
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);
}
}
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;
}
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);
}
}
}
Aggregations