Updated Branches:
  refs/heads/4.0 2163c14d8 -> 58b316c90

CLOUDSTACK-1151: 302 to 40 upgrade. Upgrade system template for Vmware.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/58b316c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/58b316c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/58b316c9

Branch: refs/heads/4.0
Commit: 58b316c907ee7afca45cbe609b6bab8fbd0f4541
Parents: 2163c14
Author: Kishan Kavala <[email protected]>
Authored: Thu Mar 7 14:06:10 2013 +0530
Committer: Kishan Kavala <[email protected]>
Committed: Thu Mar 7 14:06:10 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade302to40.java  |   50 +++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/58b316c9/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java 
b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
index 753f64e..2ee3738 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
@@ -71,6 +71,7 @@ public class Upgrade302to40 extends Upgrade30xBase implements 
DbUpgrade {
         fixForeignKeys(conn);
         setupExternalNetworkDevices(conn);
         fixZoneUsingExternalDevices(conn);
+        updateSystemVms(conn);
     }
 
     @Override
@@ -1030,4 +1031,53 @@ public class Upgrade302to40 extends Upgrade30xBase 
implements DbUpgrade {
             s_logger.info("Successfully upgraded networks using F5 and SRX 
devices to have a entry in the network_external_lb_device_map and 
network_external_firewall_device_map");
         }
     }
+
+    private void updateSystemVms(Connection conn){
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        boolean VMware = false;
+        try {
+            pstmt = conn.prepareStatement("select distinct(hypervisor_type) 
from `cloud`.`cluster` where removed is null");
+            rs = pstmt.executeQuery();
+            while(rs.next()){
+                if("VMware".equals(rs.getString(1))){
+                    VMware = true;
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Error while iterating through 
list of hypervisors in use", e);
+        }
+        // Just update the VMware system template. Other hypervisor templates 
are unchanged from previous 3.0.x versions.
+        s_logger.debug("Updating VMware System Vms");
+        try {
+            //Get 4.0 VMware system Vm template Id
+            pstmt = conn.prepareStatement("select id from 
`cloud`.`vm_template` where name = 'systemvm-vmware-4.0' and removed is null");
+            rs = pstmt.executeQuery();
+            if(rs.next()){
+                long templateId = rs.getLong(1);
+                rs.close();
+                pstmt.close();
+                // change template type to SYSTEM
+                pstmt = conn.prepareStatement("update `cloud`.`vm_template` 
set type='SYSTEM' where id = ?");
+                pstmt.setLong(1, templateId);
+                pstmt.executeUpdate();
+                pstmt.close();
+                // update templete ID of system Vms
+                pstmt = conn.prepareStatement("update `cloud`.`vm_instance` 
set vm_template_id = ? where type <> 'User' and hypervisor_type = 'VMware'");
+                pstmt.setLong(1, templateId);
+                pstmt.executeUpdate();
+                pstmt.close();
+            } else {
+                if (VMware){
+                    throw new CloudRuntimeException("4.0 VMware SystemVm 
template not found. Cannot upgrade system Vms");
+                } else {
+                    s_logger.warn("4.0 VMware SystemVm template not found. 
VMware hypervisor is not used, so not failing upgrade");
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Error while updating VMware 
systemVm template", e);
+        }
+        s_logger.debug("Updating System Vm Template IDs Complete");
+    }
+
 }

Reply via email to