Skip to content

Commit 48c8e64

Browse files
Harikrishna PatnalaKishan Kavala
authored andcommitted
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.
1 parent 3455a76 commit 48c8e64

5 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
334334
tmpltTypeHyperSearch.done();
335335

336336
readySystemTemplateSearch = createSearchBuilder();
337+
readySystemTemplateSearch.and("removed", readySystemTemplateSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
337338
readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
338339
SearchBuilder<TemplateDataStoreVO> templateDownloadSearch = _templateDataStoreDao.createSearchBuilder();
339340
templateDownloadSearch.and("downloadState", templateDownloadSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
@@ -800,7 +801,6 @@ public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hyperv
800801

801802
if (tmplts.size() > 0) {
802803
if (hypervisorType == HypervisorType.Any) {
803-
Collections.shuffle(tmplts);
804804
return tmplts.get(0);
805805
}
806806
for (VMTemplateVO tmplt : tmplts) {

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade412to420.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ private void updateSystemVmTemplates(Connection conn) {
301301
}
302302
};
303303

304+
Map<HypervisorType, String> newTemplateUrl = new HashMap<HypervisorType, String>(){
305+
{ put(HypervisorType.XenServer, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2");
306+
put(HypervisorType.VMware, "http://download.cloud.com/templates/4.2/systemvmtemplate-4.2-vh7.ova");
307+
put(HypervisorType.KVM, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2");
308+
put(HypervisorType.LXC, "http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2");
309+
put(HypervisorType.Hyperv, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2");
310+
}
311+
};
312+
313+
Map<HypervisorType, String> newTemplateChecksum = new HashMap<HypervisorType, String>(){
314+
{ put(HypervisorType.XenServer, "fb1b6e032a160d86f2c28feb5add6d83");
315+
put(HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596");
316+
put(HypervisorType.KVM, "6cea42b2633841648040becb588bd8f0");
317+
put(HypervisorType.LXC, "2755de1f9ef2ce4d6f2bee2efbb4da92");
318+
put(HypervisorType.Hyperv, "fb1b6e032a160d86f2c28feb5add6d83");
319+
}
320+
};
321+
304322
for (Map.Entry<HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
305323
s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
306324
try {
@@ -312,6 +330,11 @@ private void updateSystemVmTemplates(Connection conn) {
312330
long templateId = rs.getLong(1);
313331
rs.close();
314332
pstmt.close();
333+
// Mark the old system templates as removed
334+
pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET removed = now() WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null");
335+
pstmt.setString(1, hypervisorAndTemplateName.getKey().toString());
336+
pstmt.executeUpdate();
337+
pstmt.close();
315338
// change template type to SYSTEM
316339
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
317340
pstmt.setLong(1, templateId);
@@ -334,6 +357,13 @@ private void updateSystemVmTemplates(Connection conn) {
334357
throw new CloudRuntimeException("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
335358
} else {
336359
s_logger.warn("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade");
360+
// Update the latest template URLs for corresponding hypervisor
361+
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");
362+
pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
363+
pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
364+
pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
365+
pstmt.executeUpdate();
366+
pstmt.close();
337367
}
338368
}
339369
} catch (SQLException e) {

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,10 @@ public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationExce
647647
}
648648

649649
VMTemplateVO template = null;
650-
HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId);
651-
if (defaultHypervisor != HypervisorType.None) {
652-
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor);
653-
if (template == null) {
654-
throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor);
655-
}
656-
} else {
657-
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
658-
if (template == null) {
659-
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
660-
}
650+
HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
651+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
652+
if (template == null) {
653+
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
661654
}
662655

663656
Map<String, Object> context = createProxyInstance(dataCenterId, template);

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.Map;
2727
import java.util.Set;
28+
import java.util.Collections;
2829

2930
import javax.ejb.Local;
3031
import javax.inject.Inject;
@@ -1394,6 +1395,7 @@ public HypervisorType getAvailableHypervisor(long zoneId) {
13941395
if (defaultHype == HypervisorType.None) {
13951396
List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null);
13961397
if (supportedHypes.size() > 0) {
1398+
Collections.shuffle(supportedHypes);
13971399
defaultHype = supportedHypes.get(0);
13981400
}
13991401
}

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,17 +572,10 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
572572
}
573573

574574
VMTemplateVO template = null;
575-
HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId);
576-
if (defaultHypervisor != HypervisorType.None) {
577-
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor);
578-
if (template == null) {
579-
throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor);
580-
}
581-
} else {
582-
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
583-
if (template == null) {
584-
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
585-
}
575+
HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
576+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
577+
if (template == null) {
578+
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
586579
}
587580

588581
SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,

0 commit comments

Comments
 (0)