From 5404bf606395fb4ff58252df9511341416eb160a Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Sat, 10 Aug 2013 15:36:06 +0530 Subject: [PATCH] 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. --- .../cloud/storage/dao/VMTemplateDaoImpl.java | 2 +- .../cloud/upgrade/dao/Upgrade410to420.java | 30 +++++++++++++++++++ .../consoleproxy/ConsoleProxyManagerImpl.java | 15 +++------- .../cloud/resource/ResourceManagerImpl.java | 2 ++ .../SecondaryStorageManagerImpl.java | 15 +++------- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index 9f255c9ab55..49a8e16b827 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 implem tmpltTypeHyperSearch.done(); readySystemTemplateSearch = createSearchBuilder(); + readySystemTemplateSearch.and("removed", readySystemTemplateSearch.entity().getRemoved(), SearchCriteria.Op.NULL); readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); SearchBuilder templateDownloadSearch = _templateDataStoreDao.createSearchBuilder(); templateDownloadSearch.and("downloadState", templateDownloadSearch.entity().getDownloadState(), SearchCriteria.Op.EQ); @@ -802,7 +803,6 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem if (tmplts.size() > 0) { if (hypervisorType == HypervisorType.Any) { - Collections.shuffle(tmplts); return tmplts.get(0); } for (VMTemplateVO tmplt : tmplts) { diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index fbec107ba2c..7ab7ab78299 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 newTemplateUrl = new HashMap(){ + { 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 newTemplateChecksum = new HashMap(){ + { put(HypervisorType.XenServer, "fb1b6e032a160d86f2c28feb5add6d83"); + put(HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596"); + put(HypervisorType.KVM, "6cea42b2633841648040becb588bd8f0"); + put(HypervisorType.LXC, "2755de1f9ef2ce4d6f2bee2efbb4da92"); + put(HypervisorType.Hyperv, "fb1b6e032a160d86f2c28feb5add6d83"); + } + }; + for (Map.Entry 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) { diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index c5faccbcc29..3ce7acfbacf 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 context = createProxyInstance(dataCenterId, template); diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index f060b57a369..090b7ca06d6 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 supportedHypes = getSupportedHypervisorTypes(zoneId, false, null); if (supportedHypes.size() > 0) { + Collections.shuffle(supportedHypes); defaultHype = supportedHypes.get(0); } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index d1c148b2cf5..9e172d35979 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,