private void templateCreateUsage(VMTemplateVO template, long dcId) { if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), dcId, template.getId(), template.getName(), null, template.getSourceTemplateId(), 0L); _usageEventDao.persist(usageEvent); } }
if (rtngTmplt.getHypervisorType() == hostHyper) { toBeDownloaded.add(rtngTmplt); if (builtinTmplt.getHypervisorType() == hostHyper) { toBeDownloaded.add(builtinTmplt); 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);
@Override public long getGuestOSId() { return imageVO.getGuestOSId(); }
private boolean isPrivateTemplate(VMTemplateVO template){ // if public OR featured OR system template if(template.isPublicTemplate() || template.isFeatured() || template.getTemplateType() == TemplateType.SYSTEM) return false; else return true; }
@Override public void loadDetails(VMTemplateVO tmpl) { Map<String, String> details = _templateDetailsDao.listDetailsKeyPairs(tmpl.getId()); tmpl.setDetails(details); }
if (child_template.getParentTemplateId() != null) { String uniqueName = child_template.getUniqueName(); if (templateInfos.containsKey(uniqueName)) { templateInfos.remove(uniqueName); String uniqueName = tmplt.getUniqueName(); TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); if (templateInfos.containsKey(uniqueName)) { TemplateProp tmpltInfo = templateInfos.remove(uniqueName); 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); stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao); } catch (NoTransitionException e) { s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); } else if (tmplt.getUrl() == null) { 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);
private boolean createChildDataDiskTemplate(DatadiskTO dataDiskTemplate, VMTemplateVO template, TemplateInfo parentTemplate, DataStore imageStore, int diskCount) throws ExecutionException, InterruptedException { Storage.ImageFormat format = dataDiskTemplate.isIso() ? Storage.ImageFormat.ISO : template.getFormat(); String suffix = dataDiskTemplate.isIso() ? "-IsoDiskTemplate-" : "-DataDiskTemplate-"; TemplateType ttype = dataDiskTemplate.isIso() ? TemplateType.ISODISK : TemplateType.DATADISK; final long templateId = _templateDao.getNextInSequence(Long.class, "id"); long guestOsId = dataDiskTemplate.isIso() ? 1 : 0; String templateName = dataDiskTemplate.isIso() ? dataDiskTemplate.getPath().substring(dataDiskTemplate.getPath().lastIndexOf(File.separator) + 1) : template.getName() + suffix + diskCount; VMTemplateVO templateVO = new VMTemplateVO(templateId, templateName, format, false, false, false, ttype, template.getUrl(), template.requiresHvm(), template.getBits(), template.getAccountId(), null, templateName, false, guestOsId, false, template.getHypervisorType(), null, null, false, false, false); if (dataDiskTemplate.isIso()){ templateVO.setUniqueName(templateName); templateVO.setParentTemplateId(template.getId()); templateVO.setSize(dataDiskTemplate.getVirtualSize()); templateVO = _templateDao.persist(templateVO); TemplateInfo dataDiskTemplateInfo = imageFactory.getTemplate(templateVO.getId(), imageStore); AsyncCallFuture<TemplateApiResult> future = createDatadiskTemplateAsync(parentTemplate, dataDiskTemplateInfo, dataDiskTemplate.getPath(), dataDiskTemplate.getDiskId(), dataDiskTemplate.getFileSize(), dataDiskTemplate.isBootable()); _resourceLimitMgr.incrementResourceCount(template.getAccountId(), ResourceType.secondary_storage, templateVO.getSize()); } else { s_logger.debug("Since creation of Datadisk template: " + templateVO.getId() + " failed, delete other Datadisk templates that were created as part of parent" + " template download"); TemplateInfo parentTemplateInfo = imageFactory.getTemplate(templateVO.getParentTemplateId(), imageStore); cleanupDatadiskTemplates(parentTemplateInfo);
PublicSearch.and("public", PublicSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); UniqueNameSearch.and("uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ); NameSearch = createSearchBuilder(); NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ); NameAccountIdSearch.and("accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); PublicIsoSearch.and("public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ); PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ); PublicIsoSearch.and("state", PublicIsoSearch.entity().getState(), SearchCriteria.Op.EQ); UserIsoSearch.and("format", UserIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ); UserIsoSearch.and("type", UserIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); UserIsoSearch.and("state", UserIsoSearch.entity().getState(), SearchCriteria.Op.EQ); tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> hostHyperSearch = _hostDao.createSearchBuilder(); hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ); tmpltTypeHyperSearch.join("tmplHyper", hostHyperSearch, hostHyperSearch.entity().getHypervisorType(), tmpltTypeHyperSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER); hostHyperSearch.done(); readySystemTemplateSearch.and("state", readySystemTemplateSearch.entity().getState(), SearchCriteria.Op.EQ); readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None) { if (hypervisor == null || hypervisor == HypervisorType.None) { throw new InvalidParameterValueException("hypervisor parameter is needed to deploy VM or the hypervisor parameter value passed is invalid"); if (hypervisor != null && hypervisor != HypervisorType.None && hypervisor != template.getHypervisorType()) { throw new InvalidParameterValueException("Hypervisor passed to the deployVm call, is different from the hypervisor type of the template"); hypervisorType = template.getHypervisorType(); boolean isIso = Storage.ImageFormat.ISO == template.getFormat(); long size = 0; Long templateSize = _templateDao.findById(template.getId()).getSize(); if (templateSize != null) { size = templateSize; || (!dataDiskTemplate.getTemplateType().equals(TemplateType.DATADISK)) && (dataDiskTemplate.getState().equals(VirtualMachineTemplate.State.Active))) { throw new InvalidParameterValueException("Invalid template id specified for Datadisk template" + datadiskTemplateToDiskOffering.getKey()); if (!dataDiskTemplate.getParentTemplateId().equals(template.getId())) { throw new InvalidParameterValueException("Invalid Datadisk template. Specified Datadisk template" + dataDiskTemplateId + " doesn't belong to template " + template.getId()); if (dataDiskOffering.getDiskSize() < dataDiskTemplate.getSize()) { throw new InvalidParameterValueException("Invalid disk offering id " + dataDiskOffering.getId() + " specified for datadisk template " + dataDiskTemplateId + ". Disk offering size should be greater than or equal to the template size"); if (template.getTemplateType().equals(TemplateType.SYSTEM)) { throw new InvalidParameterValueException("Unable to use system template " + template.getId() + " to deploy a user vm");
@Override public void doInTransactionWithoutResult(TransactionStatus status) { VMTemplateVO tmpTemplate = _templateDao.findById(template.getId()); TemplateDataStoreVO tmpTemplateDataStore = _templateDataStoreDao.findById(templateDataStore.getId()); boolean sendAlert = false; templateUpdate.setSize(answer.getVirtualSize()); _templateDao.update(tmpTemplate.getId(), templateUpdate); stateMachine.transitTo(tmpTemplate, VirtualMachineTemplate.Event.OperationSucceeded, null, _templateDao); _resourceLimitMgr.incrementResourceCount(template.getAccountId(), Resource.ResourceType.secondary_storage, answer.getVirtualSize()); if (tmpTemplate.getFormat() == Storage.ImageFormat.ISO) { etype = EventTypes.EVENT_ISO_CREATE; UsageEventUtils.publishUsageEvent(etype, tmpTemplate.getAccountId(), tmpTemplateDataStore.getDataStoreId(), tmpTemplate.getId(), tmpTemplate.getName(), null, null, tmpTemplateDataStore.getPhysicalSize(), tmpTemplateDataStore.getSize(), VirtualMachineTemplate.class.getName(), tmpTemplate.getUuid()); s_logger.debug("Template " + tmpTemplate.getUuid() + " uploaded successfully"); 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); msg = "Template " + tmpTemplate.getUuid() + " failed to upload due to operation timed out"; s_logger.error(msg);
if (template == null || template.getRemoved() != null) { throw new InvalidParameterValueException("Unable to find template with id"); if (template.getTemplateType().equals(TemplateType.DATADISK)) { throw new InvalidParameterValueException("Template " + template.getId() + " is of type Datadisk. Cannot copy Datadisk templates."); if (template.getHypervisorType() == HypervisorType.BareMetal) { if (template.isCrossZones()) { s_logger.debug("Template " + templateId + " is cross-zone, don't need to copy"); return template; if (template.isCrossZones()) { if (template.getSize() != null) { long accountId = template.getAccountId(); _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
new ConsoleProxyVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), 0, serviceOffering.isOfferHA()); proxy.setDynamicallyScalable(template.isDynamicallyScalable()); proxy = _consoleProxyDao.persist(proxy); try {
TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore); TemplateOrVolumePostUploadCommand payload = new TemplateOrVolumePostUploadCommand(template.getId(), template.getUuid(), tmpl.getInstallPath(), tmpl .getChecksum(), tmpl.getType().toString(), template.getUniqueName(), template.getFormat().toString(), templateOnStore.getDataStore().getUri(), templateOnStore.getDataStore().getRole().toString()); payload.setAccountId(template.getAccountId()); payload.setRemoteEndPoint(ep.getPublicAddr()); payload.setRequiresHvm(template.requiresHvm()); payload.setDescription(template.getDisplayText()); payloads.add(payload);
@Override public long getId() { return imageVO.getId(); }
VMTemplateVO tmplt = _templateDao.findById(template.getId()); if (tmplt.isPublicTemplate()) { _messageBus.publish(null, TemplateManager.MESSAGE_REGISTER_PUBLIC_TEMPLATE_EVENT, PublishScope.LOCAL, tmplt.getId()); long accountId = tmplt.getAccountId(); if (template.getSize() != null) { if (tmplt.getFormat() == ImageFormat.ISO) { etype = EventTypes.EVENT_ISO_CREATE;
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId); internalLbVm.setRole(Role.INTERNAL_LB_VM); internalLbVm = _internalLbVmDao.persist(internalLbVm);
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); List<DataStore> imageStores = templateMgr.getImageStoreByTemplate(template.getId(), zoneId); s_logger.info("Unable to find image store still having template: " + template.getName() + ", so just mark the template removed"); } else { List<TemplateDataStoreVO> templateStores = _tmpltStoreDao.listByTemplateStore(template.getId(), storeId); for (TemplateDataStoreVO templateStore : templateStores) { if (templateStore.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) { String errorMsg = "Please specify a template that is not currently being downloaded."; s_logger.debug("Template: " + template.getName() + " is currently being downloaded to secondary storage host: " + store.getName() + "; cant' delete it."); throw new CloudRuntimeException(errorMsg); if (template.getFormat().equals(ImageFormat.ISO)) { eventType = EventTypes.EVENT_ISO_DELETE; } else { UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), sZoneId, template.getId(), null, VirtualMachineTemplate.class.getName(), template.getUuid()); List<VMTemplateVO> dataDiskTemplates = templateDao.listByParentTemplatetId(template.getId()); if (dataDiskTemplates != null && dataDiskTemplates.size() > 0) { s_logger.info("Template: " + template.getId() + " has Datadisk template(s) associated with it. Delete Datadisk templates before deleting the template"); for (VMTemplateVO dataDiskTemplate : dataDiskTemplates) { s_logger.info("Delete Datadisk template: " + dataDiskTemplate.getId() + " from image store: " + imageStore.getName()); AsyncCallFuture<TemplateApiResult> future = imageService.deleteTemplateAsync(imageFactory.getTemplate(dataDiskTemplate.getId(), imageStore)); try {
} else { sb = createSearchBuilder(); sb.and("public", sb.entity().isPublicTemplate(), SearchCriteria.Op.EQ); sb.and("format", sb.entity().getFormat(), SearchCriteria.Op.EQ); sb.and("type", sb.entity().getTemplateType(), SearchCriteria.Op.EQ); sb.and("bootable", sb.entity().isBootable(), SearchCriteria.Op.EQ); sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); sb.groupBy(sb.entity().getId()); sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
if (template.getFormat().equals(ImageFormat.ISO)) { throw new InvalidParameterValueException("Please provide a valid template"); if (!template.getFormat().equals(ImageFormat.ISO)) { throw new InvalidParameterValueException("Please provide a valid iso"); if (template.getRemoved() != null) { s_logger.error("unable to update permissions for " + mediaType + " with id " + id + " as it is removed "); throw new InvalidParameterValueException("unable to update permissions for " + mediaType + " with id " + id + " as it is removed "); boolean allowPublicUserTemplates = AllowPublicUserTemplates.valueIn(template.getAccountId()); if (!isAdmin && !allowPublicUserTemplates && isPublic != null && isPublic) { throw new InvalidParameterValueException("Only private " + mediaType + "s can be created."); Long ownerId = template.getAccountId(); if (ownerId == null) { throw new InvalidParameterValueException("Update template permissions is an invalid operation on template " + template.getName()); updatedTemplate.setPublicTemplate(isPublic.booleanValue()); updatedTemplate.setFeatured(isFeatured.booleanValue()); if (!template.getFormat().equals(ImageFormat.ISO) && !_accountMgr.isRootAdmin(caller.getId())) { throw new InvalidParameterValueException("Only ROOT admins are allowed to modify isExtractable attribute."); } else { updatedTemplate.setExtractable(isExtractable.booleanValue());
AsyncJobManager asyncMgr) { Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE; UploadVO uploadTemplateObj = new UploadVO(secStore.getId(), template.getId(), new Date(), Upload.Status.NOT_UPLOADED, type, url, Mode.FTP_UPLOAD); _uploadDao.persist(uploadTemplateObj); UploadCommand ucmd = new UploadCommand(template, url, vmTemplateHost.getInstallPath(), vmTemplateHost.getSize()); UploadListener ul = new UploadListener(secStore, _timer, _uploadDao, uploadTemplateObj, this, ucmd, template.getAccountId(), template.getName(), type, eventId, asyncJobId, asyncMgr); _listenerMap.put(uploadTemplateObj, ul); s_logger.warn("Unable to start upload of " + template.getUniqueName() + " from " + secStore.getName() + " to " + url, e); ul.setDisconnected(); ul.scheduleStatusCheck(RequestType.GET_OR_RESTART);