CLOUDSTACK-2385: template download fails with Unexpected failure in Vmware.
Description: Putting in fix to allow download of guest VM templates that are available across zones. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/78922589 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/78922589 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/78922589 Branch: refs/heads/vmsync Commit: 78922589bbdc7914b9d4ce3b97a9fcf03d4b7b57 Parents: 1c924e5 Author: Vijayendra Bhamidipati <vijayendra.bhamidip...@citrix.com> Authored: Thu Jun 27 12:37:20 2013 -0700 Committer: Devdeep Singh <devd...@gmail.com> Committed: Fri Jun 28 23:08:36 2013 +0530 ---------------------------------------------------------------------- .../template/HypervisorTemplateAdapter.java | 104 ++++++++++--------- 1 file changed, 55 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/78922589/server/src/com/cloud/template/HypervisorTemplateAdapter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java index 92148c3..569d947 100755 --- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java @@ -308,60 +308,66 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { @Override public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd extractcmd) { - TemplateProfile profile = super.prepareExtractTemplate(extractcmd); - VMTemplateVO template = profile.getTemplate(); - Long zoneId = profile.getZoneId(); - Long templateId = template.getId(); - - if (template.getHypervisorType() == HypervisorType.VMware) { - PrepareOVAPackingCommand cmd = null; - String zoneName=""; - List<HostVO> secondaryStorageHosts; - if (!template.isCrossZones() && zoneId != null) { - DataCenterVO zone = _dcDao.findById(zoneId); - zoneName = zone.getName(); - List<DataStore> imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId())); - if (imageStores == null || imageStores.size() == 0) { - throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate()); + TemplateProfile profile = super.prepareExtractTemplate(extractcmd); + VMTemplateVO template = profile.getTemplate(); + Long zoneId = profile.getZoneId(); + Long templateId = template.getId(); + + // Simply return profile if non-ESX hypervisor. + if (template.getHypervisorType() == HypervisorType.VMware) { + PrepareOVAPackingCommand cmd = null; + String zoneName=""; + List<DataStore> imageStores = null; + + if (!template.isCrossZones()) { + if (zoneId == null) { + throw new CloudRuntimeException("ZoneId cannot be null for a template that is not available across zones"); } + // Else get the list of image stores in this zone's scope. + DataCenterVO zone = _dcDao.findById(zoneId); + zoneName = zone.getName(); + imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId())); + } else { + // template is available across zones. Get a list of all image stores. + imageStores = this.storeMgr.listImageStores(); + } + + if (imageStores == null || imageStores.size() == 0) { + throw new CloudRuntimeException("Unable to find an image store zone when trying to download template " + profile.getTemplate()); + } - s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); + s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); - // Make sure the template is downloaded to all the necessary secondary storage hosts + // Make sure the template is downloaded to all the necessary secondary storage hosts + + for (DataStore store : imageStores) { + long storeId = store.getId(); + List<TemplateDataStoreVO> templateStoreVOs = _tmpltStoreDao.listByTemplateStore(templateId, storeId); + for (TemplateDataStoreVO templateStoreVO : templateStoreVOs) { + if (templateStoreVO.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() + "."); + throw new CloudRuntimeException(errorMsg); + } + String installPath = templateStoreVO.getInstallPath(); + if (installPath != null) { + EndPoint ep = _epSelector.select(store); + if (ep == null) { + s_logger.warn("prepareOVAPacking (hyervisorTemplateAdapter): There is no secondary storage VM for secondary storage host " + store.getName()); + throw new CloudRuntimeException("PrepareExtractTemplate: can't locate ssvm for SecStorage Host."); + } + cmd = new PrepareOVAPackingCommand(store.getUri(), installPath); + cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); + Answer answer = ep.sendMessage(cmd); - for (DataStore store : imageStores) { - long storeId = store.getId(); - List<TemplateDataStoreVO> templateStoreVOs = _tmpltStoreDao.listByTemplateStore(templateId, storeId); - for (TemplateDataStoreVO templateStoreVO : templateStoreVOs) { - if (templateStoreVO.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() + "."); - throw new CloudRuntimeException(errorMsg); + if (answer == null || !answer.getResult()) { + s_logger.debug("Failed to create OVA for template " + templateStoreVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails())); + throw new CloudRuntimeException("PrepareExtractTemplate: Failed to create OVA for template extraction. "); } - String installPath = templateStoreVO.getInstallPath(); - if (installPath != null) { - EndPoint ep = _epSelector.select(store); - if (ep == null) { - s_logger.warn("prepareOVAPacking (hyervisorTemplateAdapter): There is no secondary storage VM for secondary storage host " + store.getName()); - throw new CloudRuntimeException("PrepareExtractTemplate: can't locate ssvm for SecStorage Host."); - } - //Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new PrepareOVAPackingCommand(secondaryStorageHost.getStorageUrl(), installPath)); - cmd = new PrepareOVAPackingCommand(store.getUri(), installPath); - cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); - Answer answer = ep.sendMessage(cmd); - - if (answer == null || !answer.getResult()) { - s_logger.debug("Failed to create OVA for template " + templateStoreVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails())); - throw new CloudRuntimeException("PrepareExtractTemplate: Failed to create OVA for template extraction. "); - } - } - } - } - } else { - s_logger.debug("Failed to create OVA for template " + template + " due to zone non-existing."); - throw new CloudRuntimeException("PrepareExtractTemplate: Failed to create OVA for template extraction. "); + } + } + } } - } return profile; - } + } }