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.
This commit is contained in:
Harikrishna Patnala 2013-08-10 15:36:06 +05:30 committed by Kishan Kavala
parent 3455a76237
commit 48c8e64ae9
5 changed files with 41 additions and 23 deletions

View File

@ -334,6 +334,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);
@ -800,7 +801,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) {

View File

@ -301,6 +301,24 @@ public class Upgrade412to420 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 {
@ -312,6 +330,11 @@ public class Upgrade412to420 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);
@ -334,6 +357,13 @@ public class Upgrade412to420 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) {

View File

@ -647,17 +647,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);

View File

@ -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;
@ -1394,6 +1395,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);
}
}

View File

@ -572,17 +572,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,