CLOUDSTACK-4123: 3.0.6 to ASF 4.2 Upgrade: On Adding VMWare Cluster to the Setup, 3.0.6 System VM Template for VMWare is downloaded instead of 4.2
Updating the new system template URLs for the existing templates during upgrade to 4.2. If new 4.2 system template is registered before upgrade then marking the old templates as removed during upgrade. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5404bf60 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5404bf60 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5404bf60 Branch: refs/heads/master Commit: 5404bf606395fb4ff58252df9511341416eb160a Parents: 3ba68a1 Author: Harikrishna Patnala <harikrishna.patn...@citrix.com> Authored: Sat Aug 10 15:36:06 2013 +0530 Committer: Kishan Kavala <kis...@cloud.com> Committed: Sat Aug 10 18:02:49 2013 +0530 ---------------------------------------------------------------------- .../cloud/storage/dao/VMTemplateDaoImpl.java | 2 +- .../com/cloud/upgrade/dao/Upgrade410to420.java | 30 ++++++++++++++++++++ .../consoleproxy/ConsoleProxyManagerImpl.java | 15 +++------- .../com/cloud/resource/ResourceManagerImpl.java | 2 ++ .../secondary/SecondaryStorageManagerImpl.java | 15 +++------- 5 files changed, 41 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5404bf60/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index 9f255c9..49a8e16 100755 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -336,6 +336,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem tmpltTypeHyperSearch.done(); readySystemTemplateSearch = createSearchBuilder(); + readySystemTemplateSearch.and("removed", readySystemTemplateSearch.entity().getRemoved(), SearchCriteria.Op.NULL); readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); SearchBuilder<TemplateDataStoreVO> templateDownloadSearch = _templateDataStoreDao.createSearchBuilder(); templateDownloadSearch.and("downloadState", templateDownloadSearch.entity().getDownloadState(), SearchCriteria.Op.EQ); @@ -802,7 +803,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem if (tmplts.size() > 0) { if (hypervisorType == HypervisorType.Any) { - Collections.shuffle(tmplts); return tmplts.get(0); } for (VMTemplateVO tmplt : tmplts) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5404bf60/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index fbec107..7ab7ab7 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -303,6 +303,24 @@ public class Upgrade410to420 implements DbUpgrade { } }; + Map<HypervisorType, String> newTemplateUrl = new HashMap<HypervisorType, String>(){ + { put(HypervisorType.XenServer, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2"); + put(HypervisorType.VMware, "http://download.cloud.com/templates/4.2/systemvmtemplate-4.2-vh7.ova"); + put(HypervisorType.KVM, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2"); + put(HypervisorType.LXC, "http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2"); + put(HypervisorType.Hyperv, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2"); + } + }; + + Map<HypervisorType, String> newTemplateChecksum = new HashMap<HypervisorType, String>(){ + { put(HypervisorType.XenServer, "fb1b6e032a160d86f2c28feb5add6d83"); + put(HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596"); + put(HypervisorType.KVM, "6cea42b2633841648040becb588bd8f0"); + put(HypervisorType.LXC, "2755de1f9ef2ce4d6f2bee2efbb4da92"); + put(HypervisorType.Hyperv, "fb1b6e032a160d86f2c28feb5add6d83"); + } + }; + for (Map.Entry<HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){ s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); try { @@ -314,6 +332,11 @@ public class Upgrade410to420 implements DbUpgrade { long templateId = rs.getLong(1); rs.close(); pstmt.close(); + // Mark the old system templates as removed + pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET removed = now() WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null"); + pstmt.setString(1, hypervisorAndTemplateName.getKey().toString()); + pstmt.executeUpdate(); + pstmt.close(); // change template type to SYSTEM pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?"); pstmt.setLong(1, templateId); @@ -336,6 +359,13 @@ public class Upgrade410to420 implements DbUpgrade { throw new CloudRuntimeException("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); } else { s_logger.warn("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); + // Update the latest template URLs for corresponding hypervisor + pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1"); + pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); + pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); + pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); + pstmt.executeUpdate(); + pstmt.close(); } } } catch (SQLException e) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5404bf60/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index c5faccb..3ce7acf 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -658,17 +658,10 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } VMTemplateVO template = null; - HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId); - if (defaultHypervisor != HypervisorType.None) { - template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor); - if (template == null) { - throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor); - } - } else { - template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any); - if (template == null) { - throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); - } + HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId); + template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor); + if (template == null) { + throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); } Map<String, Object> context = createProxyInstance(dataCenterId, template); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5404bf60/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index f060b57..090b7ca 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Collections; import javax.ejb.Local; import javax.inject.Inject; @@ -1397,6 +1398,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (defaultHype == HypervisorType.None) { List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null); if (supportedHypes.size() > 0) { + Collections.shuffle(supportedHypes); defaultHype = supportedHypes.get(0); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5404bf60/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index d1c148b..9e172d3 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -567,17 +567,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } VMTemplateVO template = null; - HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId); - if (defaultHypervisor != HypervisorType.None) { - template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor); - if (template == null) { - throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor); - } - } else { - template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any); - if (template == null) { - throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); - } + HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId); + template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor); + if (template == null) { + throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId); } SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,