Skip to content

Commit 04492ba

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-5690: Added upgarde template support for 4.3 64 bit templates. Changed min required version for VR to 4.3
1 parent 694d39d commit 04492ba

3 files changed

Lines changed: 138 additions & 160 deletions

File tree

‎api/src/com/cloud/network/VirtualNetworkApplianceService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws Concu
7171

7272
List<Long> upgradeRouterTemplate(UpgradeRouterTemplateCmd cmd);
7373

74-
public static final String _minVRVersion = "4.2.0";
74+
public static final String _minVRVersion = "4.3.0";
7575
}

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

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
import java.sql.Types;
2828
import java.util.ArrayList;
2929
import java.util.HashMap;
30-
import java.util.HashSet;
3130
import java.util.Iterator;
3231
import java.util.List;
3332
import java.util.Map;
34-
import java.util.Set;
3533
import java.util.UUID;
3634

3735
import org.apache.log4j.Logger;
@@ -83,7 +81,6 @@ public void performDataMigration(Connection conn) {
8381
persistVswitchConfiguration(conn);
8482
createPlaceHolderNics(conn);
8583
updateRemoteAccessVpn(conn);
86-
updateSystemVmTemplates(conn);
8784
updateOverCommitRatioClusterDetails(conn);
8885
updatePrimaryStore(conn);
8986
addEgressFwRulesForSRXGuestNw(conn);
@@ -629,162 +626,6 @@ private void dropUploadTable(Connection conn) {
629626

630627
}
631628

632-
private void updateSystemVmTemplates(Connection conn) {
633-
// TODO: system vm template migration after storage refactoring
634-
PreparedStatement pstmt = null;
635-
ResultSet rs = null;
636-
s_logger.debug("Updating System Vm template IDs");
637-
try{
638-
//Get all hypervisors in use
639-
Set<HypervisorType> hypervisorsListInUse = new HashSet<HypervisorType>();
640-
try {
641-
pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
642-
rs = pstmt.executeQuery();
643-
while(rs.next()){
644-
switch (HypervisorType.getType(rs.getString(1))) {
645-
case XenServer: hypervisorsListInUse.add(HypervisorType.XenServer);
646-
break;
647-
case KVM: hypervisorsListInUse.add(HypervisorType.KVM);
648-
break;
649-
case VMware: hypervisorsListInUse.add(HypervisorType.VMware);
650-
break;
651-
case Hyperv: hypervisorsListInUse.add(HypervisorType.Hyperv);
652-
break;
653-
case LXC: hypervisorsListInUse.add(HypervisorType.LXC);
654-
break;
655-
}
656-
}
657-
} catch (SQLException e) {
658-
throw new CloudRuntimeException("Error while listing hypervisors in use", e);
659-
}
660-
661-
Map<HypervisorType, String> NewTemplateNameList = new HashMap<HypervisorType, String>(){
662-
{ put(HypervisorType.XenServer, "systemvm-xenserver-4.2");
663-
put(HypervisorType.VMware, "systemvm-vmware-4.2");
664-
put(HypervisorType.KVM, "systemvm-kvm-4.2");
665-
put(HypervisorType.LXC, "systemvm-lxc-4.2");
666-
put(HypervisorType.Hyperv, "systemvm-hyperv-4.2");
667-
}
668-
};
669-
670-
Map<HypervisorType, String> routerTemplateConfigurationNames = new HashMap<HypervisorType, String>(){
671-
{ put(HypervisorType.XenServer, "router.template.xen");
672-
put(HypervisorType.VMware, "router.template.vmware");
673-
put(HypervisorType.KVM, "router.template.kvm");
674-
put(HypervisorType.LXC, "router.template.lxc");
675-
put(HypervisorType.Hyperv, "router.template.hyperv");
676-
}
677-
};
678-
679-
Map<HypervisorType, String> newTemplateUrl = new HashMap<HypervisorType, String>(){
680-
{ put(HypervisorType.XenServer, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-07-12-master-xen.vhd.bz2");
681-
put(HypervisorType.VMware, "http://download.cloud.com/templates/4.2/systemvmtemplate-4.2-vh7.ova");
682-
put(HypervisorType.KVM, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2");
683-
put(HypervisorType.LXC, "http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2");
684-
put(HypervisorType.Hyperv, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2");
685-
}
686-
};
687-
688-
Map<HypervisorType, String> newTemplateChecksum = new HashMap<HypervisorType, String>(){
689-
{ put(HypervisorType.XenServer, "fb1b6e032a160d86f2c28feb5add6d83");
690-
put(HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596");
691-
put(HypervisorType.KVM, "6cea42b2633841648040becb588bd8f0");
692-
put(HypervisorType.LXC, "2755de1f9ef2ce4d6f2bee2efbb4da92");
693-
put(HypervisorType.Hyperv, "fb1b6e032a160d86f2c28feb5add6d83");
694-
}
695-
};
696-
697-
for (Map.Entry<HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
698-
s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
699-
try {
700-
//Get 4.2.0 system Vm template Id for corresponding hypervisor
701-
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1");
702-
pstmt.setString(1, hypervisorAndTemplateName.getValue());
703-
rs = pstmt.executeQuery();
704-
if(rs.next()){
705-
long templateId = rs.getLong(1);
706-
rs.close();
707-
pstmt.close();
708-
// Mark the old system templates as removed
709-
pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET removed = now() WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null");
710-
pstmt.setString(1, hypervisorAndTemplateName.getKey().toString());
711-
pstmt.executeUpdate();
712-
pstmt.close();
713-
// change template type to SYSTEM
714-
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
715-
pstmt.setLong(1, templateId);
716-
pstmt.executeUpdate();
717-
pstmt.close();
718-
// update templete ID of system Vms
719-
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");
720-
pstmt.setLong(1, templateId);
721-
pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
722-
pstmt.executeUpdate();
723-
pstmt.close();
724-
// Change value of global configuration parameter router.template.* for the corresponding hypervisor
725-
pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");
726-
pstmt.setString(1, hypervisorAndTemplateName.getValue());
727-
pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
728-
pstmt.executeUpdate();
729-
pstmt.close();
730-
} else {
731-
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
732-
throw new CloudRuntimeException("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
733-
} else {
734-
s_logger.warn("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade");
735-
// Update the latest template URLs for corresponding hypervisor
736-
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");
737-
pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
738-
pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
739-
pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
740-
pstmt.executeUpdate();
741-
pstmt.close();
742-
}
743-
}
744-
} catch (SQLException e) {
745-
throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e);
746-
}
747-
}
748-
try {
749-
pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` set dynamically_scalable = 1 where name = ? and type = 'SYSTEM'");
750-
pstmt.setString(1, NewTemplateNameList.get(HypervisorType.VMware));
751-
pstmt.executeUpdate();
752-
pstmt.close();
753-
} catch (SQLException e) {
754-
throw new CloudRuntimeException("Error while updating dynamically_scalable flag to 1 for SYSTEM template systemvm-vmware-4.2");
755-
}
756-
s_logger.debug("Updating System Vm Template IDs Complete");
757-
}
758-
finally {
759-
try {
760-
if (rs != null) {
761-
rs.close();
762-
}
763-
764-
if (pstmt != null) {
765-
pstmt.close();
766-
}
767-
} catch (SQLException e) {
768-
}
769-
}
770-
/*
771-
pstmt = null;
772-
try {
773-
pstmt = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
774-
pstmt.executeUpdate();
775-
} catch (SQLException e) {
776-
throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
777-
} finally {
778-
if (pstmt != null) {
779-
try {
780-
pstmt.close();
781-
} catch (SQLException e) {
782-
}
783-
}
784-
}
785-
*/
786-
}
787-
788629
//KVM snapshot flag: only turn on if Customers is using snapshot;
789630
private void setKVMSnapshotFlag(Connection conn) {
790631
s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. ");

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

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
import java.sql.ResultSet;
2525
import java.sql.SQLException;
2626
import java.sql.Types;
27+
import java.util.HashMap;
28+
import java.util.HashSet;
29+
import java.util.Map;
30+
import java.util.Set;
2731

32+
import com.cloud.hypervisor.Hypervisor;
2833
import org.apache.commons.lang.StringUtils;
2934
import org.apache.log4j.Logger;
3035

@@ -64,6 +69,7 @@ public File[] getPrepareScripts() {
6469
public void performDataMigration(Connection conn) {
6570
encryptLdapConfigParams(conn);
6671
upgradeMemoryOfSsvmOffering(conn);
72+
updateSystemVmTemplates(conn);
6773
}
6874

6975
private void upgradeMemoryOfSsvmOffering(Connection conn) {
@@ -183,6 +189,137 @@ private void encryptLdapConfigParams(Connection conn) {
183189

184190
}
185191

192+
private void updateSystemVmTemplates(Connection conn) {
193+
PreparedStatement pstmt = null;
194+
ResultSet rs = null;
195+
s_logger.debug("Updating System Vm template IDs");
196+
try{
197+
//Get all hypervisors in use
198+
Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
199+
try {
200+
pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
201+
rs = pstmt.executeQuery();
202+
while(rs.next()){
203+
switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
204+
case XenServer: hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
205+
break;
206+
case KVM: hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
207+
break;
208+
case VMware: hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
209+
break;
210+
case Hyperv: hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
211+
break;
212+
case LXC: hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
213+
break;
214+
}
215+
}
216+
} catch (SQLException e) {
217+
throw new CloudRuntimeException("Error while listing hypervisors in use", e);
218+
}
219+
220+
Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>(){
221+
{ put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.3");
222+
put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.3");
223+
put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.3");
224+
put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.3");
225+
put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.3");
226+
}
227+
};
228+
229+
Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>(){
230+
{ put(Hypervisor.HypervisorType.XenServer, "router.template.xen");
231+
put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
232+
put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
233+
put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
234+
put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
235+
}
236+
};
237+
238+
Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>(){
239+
{ put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-xen.vhd.bz2");
240+
put(Hypervisor.HypervisorType.VMware, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-vh7.ova");
241+
put(Hypervisor.HypervisorType.KVM, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-kvm.qcow2.bz2");
242+
put(Hypervisor.HypervisorType.LXC, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-kvm.qcow2.bz2");
243+
put(Hypervisor.HypervisorType.Hyperv, "http://download.cloud.com/templates/4.3/systemvm64template-2013-12-23-hyperv.vhd.bz2");
244+
}
245+
};
246+
247+
Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>(){
248+
{ put(Hypervisor.HypervisorType.XenServer, "74b92f031cc5c2089ee89efb81344dcf");
249+
put(Hypervisor.HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596");
250+
put(Hypervisor.HypervisorType.KVM, "85a1bed07bf43cbf022451cb2ecae4ff");
251+
put(Hypervisor.HypervisorType.LXC, "85a1bed07bf43cbf022451cb2ecae4ff");
252+
put(Hypervisor.HypervisorType.Hyperv, "5df45ee6ebe1b703a8805f4e1f4d0818");
253+
}
254+
};
255+
256+
for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
257+
s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
258+
try {
259+
//Get 4.3.0 system Vm template Id for corresponding hypervisor
260+
pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1");
261+
pstmt.setString(1, hypervisorAndTemplateName.getValue());
262+
rs = pstmt.executeQuery();
263+
if(rs.next()){
264+
long templateId = rs.getLong(1);
265+
rs.close();
266+
pstmt.close();
267+
// Mark the old system templates as removed
268+
pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET removed = now() WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null");
269+
pstmt.setString(1, hypervisorAndTemplateName.getKey().toString());
270+
pstmt.executeUpdate();
271+
pstmt.close();
272+
// change template type to SYSTEM
273+
pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");
274+
pstmt.setLong(1, templateId);
275+
pstmt.executeUpdate();
276+
pstmt.close();
277+
// update templete ID of system Vms
278+
pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");
279+
pstmt.setLong(1, templateId);
280+
pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
281+
pstmt.executeUpdate();
282+
pstmt.close();
283+
// Change value of global configuration parameter router.template.* for the corresponding hypervisor
284+
pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");
285+
pstmt.setString(1, hypervisorAndTemplateName.getValue());
286+
pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
287+
pstmt.executeUpdate();
288+
pstmt.close();
289+
} else {
290+
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
291+
throw new CloudRuntimeException("4.3.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
292+
} else {
293+
s_logger.warn("4.3.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade");
294+
// Update the latest template URLs for corresponding hypervisor
295+
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");
296+
pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
297+
pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
298+
pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
299+
pstmt.executeUpdate();
300+
pstmt.close();
301+
}
302+
}
303+
} catch (SQLException e) {
304+
throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e);
305+
}
306+
}
307+
s_logger.debug("Updating System Vm Template IDs Complete");
308+
}
309+
finally {
310+
try {
311+
if (rs != null) {
312+
rs.close();
313+
}
314+
315+
if (pstmt != null) {
316+
pstmt.close();
317+
}
318+
} catch (SQLException e) {
319+
}
320+
}
321+
}
322+
186323
@Override
187324
public File[] getCleanupScripts() {
188325
String script = Script.findScript("", "db/schema-421to430-cleanup.sql");

0 commit comments

Comments
 (0)