You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2014/09/30 13:23:55 UTC

git commit: updated refs/heads/master to d1e0a89

Repository: cloudstack
Updated Branches:
  refs/heads/master f1e3e83bb -> d1e0a8972


CLOUDSTACK-7197: Added new system template DB changes in 4.5 upgrade. Removed 4.3 DB upgrade code for system template


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

Branch: refs/heads/master
Commit: d1e0a8972b30b25e26339abf19d277c3b93fb7e6
Parents: f1e3e83
Author: Kishan Kavala <ki...@apache.org>
Authored: Tue Sep 30 12:02:56 2014 +0530
Committer: Kishan Kavala <ki...@apache.org>
Committed: Tue Sep 30 16:46:28 2014 +0530

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade421to430.java  | 136 -------------------
 .../com/cloud/upgrade/dao/Upgrade441to450.java  | 132 ++++++++++++++++++
 2 files changed, 132 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1e0a897/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
index 889cad4..fef29dd 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
@@ -24,15 +24,10 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
-import com.cloud.hypervisor.Hypervisor;
 import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
@@ -70,7 +65,6 @@ public class Upgrade421to430 implements DbUpgrade {
         encryptLdapConfigParams(conn);
         encryptImageStoreDetails(conn);
         upgradeMemoryOfSsvmOffering(conn);
-        updateSystemVmTemplates(conn);
     }
 
     private void upgradeMemoryOfSsvmOffering(Connection conn) {
@@ -196,136 +190,6 @@ public class Upgrade421to430 implements DbUpgrade {
 
     }
 
-    private void updateSystemVmTemplates(Connection conn) {
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-        s_logger.debug("Updating System Vm template IDs");
-        try{
-            //Get all hypervisors in use
-            Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
-            try {
-                pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
-                rs = pstmt.executeQuery();
-                while(rs.next()){
-                    switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
-                        case XenServer: hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
-                            break;
-                        case KVM:       hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
-                            break;
-                        case VMware:    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
-                            break;
-                        case Hyperv:    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
-                            break;
-                        case LXC:       hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
-                            break;
-                    }
-                }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while listing hypervisors in use", e);
-            }
-
-            Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>(){
-                {   put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.3");
-                    put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.3");
-                    put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.3");
-                    put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.3");
-                    put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.3");
-                }
-            };
-
-            Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>(){
-                {   put(Hypervisor.HypervisorType.XenServer, "router.template.xen");
-                    put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
-                    put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
-                    put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
-                    put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
-                }
-            };
-
-            Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>(){
-                {   put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-xen.vhd.bz2");
-                    put(Hypervisor.HypervisorType.VMware, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-vmware.ova");
-                    put(Hypervisor.HypervisorType.KVM, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-kvm.qcow2.bz2");
-                    put(Hypervisor.HypervisorType.LXC, "http://download.cloud.com/templates/4.3/systemvm64template-2014-01-14-master-kvm.qcow2.bz2");
-                    put(Hypervisor.HypervisorType.Hyperv, "http://download.cloud.com/templates/4.3/systemvm64template-2013-12-23-hyperv.vhd.bz2");
-                }
-            };
-
-            Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>(){
-                {   put(Hypervisor.HypervisorType.XenServer, "74b92f031cc5c2089ee89efb81344dcf");
-                    put(Hypervisor.HypervisorType.VMware, "ef593a061f3b7594ab0bfd9b0ed0a0d4");
-                    put(Hypervisor.HypervisorType.KVM, "85a1bed07bf43cbf022451cb2ecae4ff");
-                    put(Hypervisor.HypervisorType.LXC, "85a1bed07bf43cbf022451cb2ecae4ff");
-                    put(Hypervisor.HypervisorType.Hyperv, "5df45ee6ebe1b703a8805f4e1f4d0818");
-                }
-            };
-
-            for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
-                s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
-                try {
-                    //Get 4.3.0 system Vm template Id for corresponding hypervisor
-                    pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1");
-                    pstmt.setString(1, hypervisorAndTemplateName.getValue());
-                    rs = pstmt.executeQuery();
-                    if(rs.next()){
-                        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);
-                        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 = ?");
-                        pstmt.setLong(1, templateId);
-                        pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
-                        pstmt.executeUpdate();
-                        pstmt.close();
-                        // Change value of global configuration parameter router.template.* for the corresponding hypervisor
-                        pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");
-                        pstmt.setString(1, hypervisorAndTemplateName.getValue());
-                        pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
-                        pstmt.executeUpdate();
-                        pstmt.close();
-                    } else {
-                        if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
-                            throw new CloudRuntimeException("4.3.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
-                        } else {
-                            s_logger.warn("4.3.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) {
-                    throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e);
-                }
-            }
-            s_logger.debug("Updating System Vm Template IDs Complete");
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
     private void encryptImageStoreDetails(Connection conn) {
         s_logger.debug("Encrypting image store details");
         PreparedStatement pstmt = null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1e0a897/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java
index 21b2e13..cde661b 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java
@@ -19,11 +19,17 @@ package com.cloud.upgrade.dao;
 
 import java.io.File;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
+import com.cloud.hypervisor.Hypervisor;
 import org.apache.log4j.Logger;
 
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -59,6 +65,7 @@ public class Upgrade441to450 implements DbUpgrade {
 
     @Override
     public void performDataMigration(Connection conn) {
+        updateSystemVmTemplates(conn);
         dropInvalidKeyFromStoragePoolTable(conn);
         dropDuplicatedForeignKeyFromAsyncJobTable(conn);
     }
@@ -74,6 +81,131 @@ public class Upgrade441to450 implements DbUpgrade {
         return new File[] {new File(script)};
     }
 
+    private void updateSystemVmTemplates(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        s_logger.debug("Updating System Vm template IDs");
+        try{
+            //Get all hypervisors in use
+            Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
+            try {
+                pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");
+                rs = pstmt.executeQuery();
+                while(rs.next()){
+                    switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
+                        case XenServer: hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
+                            break;
+                        case KVM:       hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
+                            break;
+                        case VMware:    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
+                            break;
+                        case Hyperv:    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
+                            break;
+                        case LXC:       hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
+                            break;
+                    }
+                }
+            } catch (SQLException e) {
+                throw new CloudRuntimeException("Error while listing hypervisors in use", e);
+            }
+
+            Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>(){
+                {   put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.5");
+                    put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.5");
+                    put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.5");
+                    put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.5");
+                    put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.5");
+                }
+            };
+
+            Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>(){
+                {   put(Hypervisor.HypervisorType.XenServer, "router.template.xen");
+                    put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
+                    put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
+                    put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
+                    put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
+                }
+            };
+
+            Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>(){
+                {   put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-xen.vhd.bz2");
+                    put(Hypervisor.HypervisorType.VMware, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-vmware.ova");
+                    put(Hypervisor.HypervisorType.KVM, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2");
+                    put(Hypervisor.HypervisorType.LXC, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2");
+                    put(Hypervisor.HypervisorType.Hyperv, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-hyperv.vhd.zip");
+                }
+            };
+
+            Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>(){
+                {   put(Hypervisor.HypervisorType.XenServer, "2b15ab4401c2d655264732d3fc600241");
+                    put(Hypervisor.HypervisorType.VMware, "3106a79a4ce66cd7f6a7c50e93f2db57");
+                    put(Hypervisor.HypervisorType.KVM, "aa9f501fecd3de1daeb9e2f357f6f002");
+                    put(Hypervisor.HypervisorType.LXC, "aa9f501fecd3de1daeb9e2f357f6f002");
+                    put(Hypervisor.HypervisorType.Hyperv, "70bd30ea02ee9ed67d2c6b85c179cee9");
+                }
+            };
+
+            for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
+                s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
+                try {
+                    //Get 4.5.0 system Vm template Id for corresponding hypervisor
+                    pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1");
+                    pstmt.setString(1, hypervisorAndTemplateName.getValue());
+                    rs = pstmt.executeQuery();
+                    if(rs.next()){
+                        long templateId = rs.getLong(1);
+                        rs.close();
+                        pstmt.close();
+                        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 = ?");
+                        pstmt.setLong(1, templateId);
+                        pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
+                        pstmt.executeUpdate();
+                        pstmt.close();
+                        // Change value of global configuration parameter router.template.* for the corresponding hypervisor
+                        pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");
+                        pstmt.setString(1, hypervisorAndTemplateName.getValue());
+                        pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
+                        pstmt.executeUpdate();
+                        pstmt.close();
+                    } else {
+                        if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
+                            throw new CloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
+                        } else {
+                            s_logger.warn("4.5.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) {
+                    throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e);
+                }
+            }
+            s_logger.debug("Updating System Vm Template IDs Complete");
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+
     private void dropInvalidKeyFromStoragePoolTable(Connection conn) {
         HashMap<String, List<String>> uniqueKeys = new HashMap<String, List<String>>();
         List<String> keys = new ArrayList<String>();