From 0cf0523afec89d2b6ced94adde06d4db1d2d86ce Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Fri, 17 Aug 2012 15:59:35 -0700 Subject: [PATCH] CS-16042: 3.0.x to 3.0.5 Upgrade: VMWare : Upgrade Procedure for using the new Burbank System Template in place of Acton System Template Required Description: Modifying reference to system VM template for vmware for the 2.2.14 to 3.0 upgrade path so that it picks up the burbank template if upgrading from 2.2.14 to 3.0.5 or beyond, and the acton template if upgrading from 2.2.14 to 3.0.[0-4]. --- server/src/com/cloud/maint/Version.java | 5 ++++ .../cloud/upgrade/dao/Upgrade2214to30.java | 28 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/maint/Version.java b/server/src/com/cloud/maint/Version.java index f7ff7835b8d..80b0f3f9a9f 100644 --- a/server/src/com/cloud/maint/Version.java +++ b/server/src/com/cloud/maint/Version.java @@ -46,6 +46,11 @@ public class Version { String[] tokens = version.split("[.]"); return tokens[0] + "." + tokens[1]+ "." + tokens[2]; } + + public static String trimToPatchNormalized(String version) { + String[] tokens = version.split("[.]"); + return tokens[0] + tokens[1] + tokens[2]; + } public static void main(String[] args) { System.out.println("Result is " + compare(args[0], args[1])); diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java index 36450789368..f0943f8140b 100755 --- a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java @@ -27,6 +27,7 @@ import java.util.UUID; import org.apache.log4j.Logger; +import com.cloud.maint.Version; import com.cloud.offering.NetworkOffering; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.crypt.EncryptionSecretKeyChecker; @@ -666,7 +667,32 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { s_logger.debug("Updating VMware System Vms"); try { //Get 3.0.0 VMware system Vm template Id - pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.0' and removed is null"); + // First get the current version of the Mgmt server from the db. + String curDbVersion = ""; + String trimmedCurrentVersion = ""; + pstmt = conn.prepareStatement("select version from `cloud`.`version`"); + try { + rs = pstmt.executeQuery(); + if(rs.next()) { + curDbVersion = rs.getString(1); + rs.close(); + pstmt.close(); + } else + throw new CloudRuntimeException("Couldn't retrieve current version from db"); + } catch (SQLException e) { + throw new CloudRuntimeException("Encountered sql exception : Couldn't retrieve current version from db"); + } + if (curDbVersion != null) { + trimmedCurrentVersion = Version.trimToPatchNormalized(curDbVersion); + } + // If the current version is >= 3.0.5, use the new burbank template. + if (Long.valueOf(trimmedCurrentVersion).longValue() >= 305 ) { + s_logger.info("Using 3.0.5 vmware system vm template"); + pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.5' and removed is null"); + } else { + s_logger.info("Using 3.0.0 vmware system vm template"); + pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.0' and removed is null"); + } rs = pstmt.executeQuery(); if(rs.next()){ long templateId = rs.getLong(1);