@Override public List<TemplateInfo> listTemplateOnCache(long templateId) { List<TemplateDataStoreVO> cacheTmpls = templateStoreDao.listOnCache(templateId); List<TemplateInfo> tmplObjs = new ArrayList<TemplateInfo>(); for (TemplateDataStoreVO cacheTmpl : cacheTmpls) { long storeId = cacheTmpl.getDataStoreId(); DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache); TemplateInfo tmplObj = getTemplate(templateId, store); tmplObjs.add(tmplObj); } return tmplObjs; }
s_logger.info("Duplicate " + tmpls.size() + " template cache store records to region store"); for (TemplateDataStoreVO tmpl : tmpls) { long templateId = tmpl.getTemplateId(); VMTemplateVO template = _tmpltDao.findById(templateId); if (template == null) { TemplateDataStoreVO tmpStore = findByStoreTemplate(storeId, tmpl.getTemplateId()); if (tmpStore != null) { s_logger.info("There is already entry for template " + tmpl.getTemplateId() + " on region store " + storeId); continue; s_logger.info("Persisting an entry for template " + tmpl.getTemplateId() + " on region store " + storeId); TemplateDataStoreVO ts = new TemplateDataStoreVO(); ts.setTemplateId(tmpl.getTemplateId()); ts.setDataStoreId(storeId); ts.setDataStoreRole(DataStoreRole.Image); ts.setState(tmpl.getState()); ts.setDownloadPercent(tmpl.getDownloadPercent()); ts.setDownloadState(tmpl.getDownloadState()); ts.setSize(tmpl.getSize()); ts.setPhysicalSize(tmpl.getPhysicalSize()); ts.setErrorString(tmpl.getErrorString()); ts.setDownloadUrl(tmpl.getDownloadUrl()); ts.setRefCnt(tmpl.getRefCnt()); persist(ts); tmpl.incrRefCnt(); this.update(tmpl.getId(), tmpl);
@Override public boolean equals(Object obj) { if (obj instanceof TemplateDataStoreVO) { TemplateDataStoreVO other = (TemplateDataStoreVO)obj; return (templateId == other.getTemplateId() && dataStoreId == other.getDataStoreId()); } return false; }
@Override public TemplateDataStoreVO createTemplateDirectDownloadEntry(long templateId, Long size) { TemplateDataStoreVO templateDataStoreVO = new TemplateDataStoreVO(); templateDataStoreVO.setTemplateId(templateId); templateDataStoreVO.setDataStoreRole(DataStoreRole.Image); templateDataStoreVO.setState(State.Ready); templateDataStoreVO.setDownloadState(Status.BYPASSED); templateDataStoreVO.setSize(size == null ? 0l : size); return templateDataStoreVO; }
if (tmpltStore != null) { s_logger.info("Template Sync found " + uniqueName + " already in the image store"); if (tmpltStore.getDownloadState() != Status.DOWNLOADED) { tmpltStore.setErrorString(""); tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId(); tmpltStore.setErrorString(msg); s_logger.info(msg); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, zoneId, null, msg, msg); if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) { s_logger.info("Template Sync found " + uniqueName + " on image store " + storeId + " uploaded using SSVM as corrupted, marking it as failed"); tmpltStore.setState(State.Failed); try { stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao); msg = "Private template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + " is corrupted, please check in image store: " + tmpltStore.getDataStoreId(); s_logger.warn(msg); } else { s_logger.info("Removing template_store_ref entry for corrupted template " + tmplt.getName()); _vmTemplateStoreDao.remove(tmpltStore.getId()); toBeDownloaded.add(tmplt); if(tmpltStore.getDownloadState() != Status.DOWNLOADED) { String etype = EventTypes.EVENT_TEMPLATE_CREATE; if (tmplt.getFormat() == ImageFormat.ISO) { tmpltStore.setDownloadPercent(100); tmpltStore.setDownloadState(Status.DOWNLOADED);
@Override public void doInTransactionWithoutResult(TransactionStatus status) { VMTemplateVO tmpTemplate = _templateDao.findById(template.getId()); TemplateDataStoreVO tmpTemplateDataStore = _templateDataStoreDao.findById(templateDataStore.getId()); boolean sendAlert = false; String msg = null; switch (answer.getStatus()) { case COMPLETED: tmpTemplateDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED); tmpTemplateDataStore.setState(State.Ready); tmpTemplateDataStore.setInstallPath(answer.getInstallPath()); tmpTemplateDataStore.setPhysicalSize(answer.getPhysicalSize()); tmpTemplateDataStore.setSize(answer.getVirtualSize()); tmpTemplateDataStore.setDownloadPercent(100); tmpTemplateDataStore.setExtractUrl(null); UsageEventUtils.publishUsageEvent(etype, tmpTemplate.getAccountId(), tmpTemplateDataStore.getDataStoreId(), tmpTemplate.getId(), tmpTemplate.getName(), null, null, tmpTemplateDataStore.getPhysicalSize(), tmpTemplateDataStore.getSize(), VirtualMachineTemplate.class.getName(), tmpTemplate.getUuid()); case IN_PROGRESS: if (tmpTemplate.getState() == VirtualMachineTemplate.State.NotUploaded) { tmpTemplateDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS); stateMachine.transitTo(tmpTemplate, VirtualMachineTemplate.Event.UploadRequested, null, _templateDao); tmpTemplateDataStore.setDownloadPercent(answer.getDownloadPercent()); } else if (tmpTemplate.getState() == VirtualMachineTemplate.State.UploadInProgress) { // check for timeout if (System.currentTimeMillis() - tmpTemplateDataStore.getCreated().getTime() > _uploadOperationTimeout) { tmpTemplateDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); tmpTemplateDataStore.setState(State.Failed); stateMachine.transitTo(tmpTemplate, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao);
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); storeSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); storeSearch.done(); cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); cacheSearch.and("destroyed", cacheSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ); cacheSearch.done(); templateSearch.and("template_id", templateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); templateSearch.and("destroyed", templateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); templateSearch.done(); templateRoleSearch.and("template_id", templateRoleSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); templateRoleSearch.and("store_role", templateRoleSearch.entity().getDataStoreRole(), SearchCriteria.Op.EQ); templateRoleSearch.and("destroyed", templateRoleSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); templateRoleSearch.and("state", templateRoleSearch.entity().getState(), SearchCriteria.Op.EQ); templateRoleSearch.done(); updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ); updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ); updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ); updateStateSearch.done(); storeTemplateSearch.and("template_id", storeTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ); storeTemplateSearch.and("store_id", storeTemplateSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); storeTemplateSearch.and("destroyed", storeTemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); storeTemplateSearch.done();
if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { if (s_logger.isDebugEnabled()) { s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); updateBuilder.setDownloadPercent(answer.getDownloadPct()); updateBuilder.setDownloadState(answer.getDownloadStatus()); updateBuilder.setLastUpdated(new Date()); updateBuilder.setErrorString(answer.getErrorString()); updateBuilder.setJobId(answer.getJobId()); updateBuilder.setLocalDownloadPath(answer.getDownloadPath()); updateBuilder.setInstallPath(answer.getInstallPath()); updateBuilder.setSize(answer.getTemplateSize()); updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize()); _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), templateOnImageStore.getExtractUrlCreated()); if (downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval) { // URL hasnt expired yet continue; s_logger.debug("Removing download url " + templateOnImageStore.getExtractUrl() + " for template id " + templateOnImageStore.getTemplateId()); ImageStoreEntity secStore = (ImageStoreEntity)_dataStoreMgr.getDataStore(templateOnImageStore.getDataStoreId(), DataStoreRole.Image); secStore.deleteExtractUrl(templateOnImageStore.getInstallPath(), templateOnImageStore.getExtractUrl(), Upload.Type.TEMPLATE); templateOnImageStore.setExtractUrl(null); templateOnImageStore.setExtractUrlCreated(null); _templateStoreDao.update(templateOnImageStore.getId(), templateOnImageStore); } catch (Throwable th) { s_logger.warn("caught exception while deleting download url " + templateOnImageStore.getExtractUrl() + " for template id " + templateOnImageStore.getTemplateId(), th);
TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData(); TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), getId()); templateStoreRef.setInstallPath(newTemplate.getPath()); templateStoreRef.setDownloadPercent(100); templateStoreRef.setDownloadState(Status.DOWNLOADED); templateStoreRef.setSize(newTemplate.getSize()); if (newTemplate.getPhysicalSize() != null) { templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize()); templateStoreDao.update(templateStoreRef.getId(), templateStoreRef); if (getDataStore().getRole() == DataStoreRole.Image) { VMTemplateVO templateVO = imageDao.findById(getId()); TemplateObjectTO dataDiskTemplate = createAnswer.getDataDiskTemplate(); TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), dataDiskTemplate.getId()); templateStoreRef.setInstallPath(dataDiskTemplate.getPath()); templateStoreRef.setDownloadPercent(100); templateStoreRef.setDownloadState(Status.DOWNLOADED); templateStoreRef.setSize(dataDiskTemplate.getSize()); templateStoreRef.setPhysicalSize(dataDiskTemplate.getPhysicalSize()); templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
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); TemplateDataStoreVO template = sc.find(); if (template != null) { return templateFactory.getTemplate(template.getTemplateId(), store);
for (TemplateDataStoreVO templateDataStore : templateDataStores) { try { DataStore dataStore = storeMgr.getDataStore(templateDataStore.getDataStoreId(), DataStoreRole.Image); EndPoint ep = _epSelector.select(dataStore, templateDataStore.getExtractUrl()); if (ep == null) { s_logger.warn("There is no secondary storage VM for image store " + dataStore.getName()); continue; VMTemplateVO template = _templateDao.findById(templateDataStore.getTemplateId()); if (template == null) { s_logger.warn("Template with id " + templateDataStore.getTemplateId() + " not found"); continue; s_logger.warn("No or invalid answer corresponding to UploadStatusCommand for template " + templateDataStore.getTemplateId()); continue; s_logger.warn("Exception while checking status for uploaded template " + templateDataStore.getExtractUrl() + ". Error details: " + th.getMessage()); if (s_logger.isTraceEnabled()) { s_logger.trace("Exception details: ", th);
TemplateDataStoreVO ts = new TemplateDataStoreVO(); ts.setTemplateId(obj.getId()); ts.setDataStoreId(dataStore.getId()); ts.setDataStoreRole(dataStore.getRole()); String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + ts.setInstallPath(installPath); ts.setState(ObjectInDataStoreStateMachine.State.Allocated); ts = templateDataStoreDao.persist(ts); break;
@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); tmpltStore.setPhysicalSize(0); // no size information for // pre-seeded system vm templates tmpltStore.setDataStoreRole(store.getRole()); _vmTemplateStoreDao.persist(tmpltStore); } } }
if (vmTemplateStore == null) { vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri()); vmTemplateStore.setDataStoreRole(store.getRole()); vmTemplateStore = _vmTemplateStoreDao.persist(vmTemplateStore); } else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) { downloadJobExists = true; dcmd.setProxy(getHttpProxy()); if (downloadJobExists) { dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART); if (vmTemplateStore.isCopy()) { dcmd.setCreds(TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd); dl.setCurrState(vmTemplateStore.getDownloadState());
templateSizeSearch.select("sum", Func.SUM, templateSizeSearch.entity().getSize()); templateSizeSearch.and("downloadState", templateSizeSearch.entity().getDownloadState(), Op.EQ); templateSizeSearch.and("destroyed", templateSizeSearch.entity().getDestroyed(), Op.EQ); SearchBuilder<VMTemplateVO> join1 = _vmTemplateDao.createSearchBuilder(); join1.and("accountId", join1.entity().getAccountId(), Op.EQ); templateSizeSearch.join("templates", join1, templateSizeSearch.entity().getTemplateId(), join1.entity().getId(), JoinBuilder.JoinType.INNER); templateSizeSearch.done();
@Override public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) { TemplateDataStoreVO dataObj = (TemplateDataStoreVO)vo; Long oldUpdated = dataObj.getUpdatedCount(); Date oldUpdatedTime = dataObj.getUpdated(); sc.setParameters("id", dataObj.getId()); sc.setParameters("state", currentState); sc.setParameters("updatedCount", dataObj.getUpdatedCount()); dataObj.incrUpdatedCount(); TemplateDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString()); str.append(": DB Data={id=") .append(dbVol.getId()) .append("; state=") .append(dbVol.getState()) .append("; updatecount=") .append(dbVol.getUpdatedCount()) .append(";updatedTime=") .append(dbVol.getUpdated()); str.append(": New Data={id=") .append(dataObj.getId()) .append("; state=") .append(nextState) .append(event) .append("; updatecount=")
tmpltStoreRef = _tmplStoreDao.findByStoreTemplate(store.getId(), templateId); if (tmpltStoreRef != null) { if (tmpltStoreRef.getDownloadState() == com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { tmpltStore = (ImageStoreEntity)store; break; if(tmpltStoreRef.getExtractUrl() != null){ return tmpltStoreRef.getExtractUrl(); tmpltStoreRef.setExtractUrl(extractUrl); tmpltStoreRef.setExtractUrlCreated(DateUtil.now()); _tmplStoreDao.update(tmpltStoreRef.getId(), tmpltStoreRef); return extractUrl;
_resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()).longValue()); if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) { return true; // already downloaded on this image store if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != Status.DOWNLOAD_IN_PROGRESS) { _tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId()); UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltStore.getPhysicalSize(), srcTmpltStore.getSize(), template.getClass().getName(), template.getUuid());
@Override public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId) { TemplateDataStoreVO templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, dataCenterId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED); if (templateStoreRef == null) { throw new CloudRuntimeException("Template " + templateId + " has not been completely downloaded to zone " + dataCenterId); } DataStore store = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image); String isoPath = store.getUri() + "/" + templateStoreRef.getInstallPath(); return new Pair<String, String>(isoPath, store.getUri()); }