cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject git commit: updated refs/heads/master-6-17-stable to f927030
Date Wed, 03 Jul 2013 11:45:17 GMT
Updated Branches:
  refs/heads/master-6-17-stable ed4a1496b -> f9270304e


CLOUDSTACK-3324: Fix/Improve upgrade system vm template 41 to 42

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>


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

Branch: refs/heads/master-6-17-stable
Commit: f9270304e00633a30f6954acd36aaeb0f2907f98
Parents: ed4a149
Author: Harikrishna Patnala <harikrishna.patnala@citrix.com>
Authored: Tue Jul 2 21:42:00 2013 +0530
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Wed Jul 3 17:04:39 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 246 +++++--------------
 1 file changed, 66 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f9270304/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index d465af9..b9daa6d 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -32,6 +32,11 @@ import java.sql.Types;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
 import com.cloud.network.vpc.NetworkACL;
 
 public class Upgrade410to420 implements DbUpgrade {
@@ -117,208 +122,89 @@ public class Upgrade410to420 implements DbUpgrade {
 
         PreparedStatement pstmt = null;
         ResultSet rs = null;
-        boolean xenserver = false;
-        boolean kvm = false;
-        boolean VMware = false;
-        boolean Hyperv = false;
-        boolean LXC = false;
         s_logger.debug("Updating System Vm template IDs");
         try{
             //Get all hypervisors in use
+            Set<HypervisorType> hypervisorsListInUse = new HashSet<HypervisorType>();
             try {
                 pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster`
where removed is null");
                 rs = pstmt.executeQuery();
                 while(rs.next()){
-                    if("XenServer".equals(rs.getString(1))){
-                        xenserver = true;
-                    } else if("KVM".equals(rs.getString(1))){
-                        kvm = true;
-                    } else if("VMware".equals(rs.getString(1))){
-                        VMware = true;
-                    } else if("Hyperv".equals(rs.getString(1))) {
-                        Hyperv = true;
-                    } else if("LXC".equals(rs.getString(1))) {
-                        LXC = true;
+                    switch (HypervisorType.getType(rs.getString(1))) {
+                        case XenServer: hypervisorsListInUse.add(HypervisorType.XenServer);
+                                        break;
+                        case KVM:       hypervisorsListInUse.add(HypervisorType.KVM);
+                                        break;
+                        case VMware:    hypervisorsListInUse.add(HypervisorType.VMware);
+                                        break;
+                        case Hyperv:    hypervisorsListInUse.add(HypervisorType.Hyperv);
+                                        break;
+                        case LXC:       hypervisorsListInUse.add(HypervisorType.LXC);
+                                        break;
                     }
                 }
             } catch (SQLException e) {
                 throw new CloudRuntimeException("Error while listing hypervisors in use",
e);
             }
 
-            s_logger.debug("Updating XenSever System Vms");
-            //XenServer
-            try {
-                //Get 4.2.0 XenServer system Vm template Id
-                pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name like 'systemvm-xenserver-4.2' and removed is null order by id desc limit 1");
-                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 = 'XenServer'");
-                    pstmt.setLong(1, templateId);
-                    pstmt.executeUpdate();
-                    pstmt.close();
-                    // Change value of global configuration parameter router.template.xen
-                    pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.xen', 'systemvm-xenserver-4.2',
'Name of the default router template on Xenserver')");
-                    pstmt.execute();
-                    pstmt.close();
-                } else {
-                    if (xenserver){
-                        throw new CloudRuntimeException("4.2.0 XenServer SystemVm template
not found. Cannot upgrade system Vms");
-                    } else {
-                        s_logger.warn("4.2.0 XenServer SystemVm template not found. XenServer
hypervisor is not used, so not failing upgrade");
-                    }
+            Map<HypervisorType, String> NewTemplateNameList = new HashMap<HypervisorType,
String>(){
+                {   put(HypervisorType.XenServer, "systemvm-xenserver-4.2");
+                    put(HypervisorType.VMware, "systemvm-vmware-4.2");
+                    put(HypervisorType.KVM, "systemvm-kvm-4.2");
+                    put(HypervisorType.LXC, "systemvm-lxc-4.2");
+                    put(HypervisorType.Hyperv, "systemvm-hyperv-4.2");
                 }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while updating XenServer systemVm
template", e);
-            }
+            };
 
-            //KVM
-            s_logger.debug("Updating KVM System Vms");
-            try {
-                //Get 4.2.0 KVM system Vm template Id
-                pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name = 'systemvm-kvm-4.2' and removed is null order by id desc limit 1");
-                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 = 'KVM'");
-                    pstmt.setLong(1, templateId);
-                    pstmt.executeUpdate();
-                    pstmt.close();
-                    // Change value of global configuration parameter router.template.kvm
-                    pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.kvm', 'systemvm-kvm-4.2',
'Name of the default router template on KVM')");
-                    pstmt.execute();
-                    pstmt.close();
-                } else {
-                    if (kvm){
-                        throw new CloudRuntimeException("4.2.0 KVM SystemVm template not
found. Cannot upgrade system Vms");
-                    } else {
-                        s_logger.warn("4.2.0 KVM SystemVm template not found. KVM hypervisor
is not used, so not failing upgrade");
-                    }
-                }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while updating KVM systemVm template",
e);
-            }
-
-            //VMware
-            s_logger.debug("Updating VMware System Vms");
-            try {
-                //Get 4.2.0 VMware system Vm template Id
-                pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name = 'systemvm-vmware-4.2' and removed is null order by id desc limit 1");
-                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();
-                    // Change value of global configuration parameter router.template.vmware
-                    pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.vmware', 'systemvm-vmware-4.2',
'Name of the default router template on Vmware')");
-                    pstmt.execute();
-                    pstmt.close();
-                } else {
-                    if (VMware){
-                        throw new CloudRuntimeException("4.2.0 VMware SystemVm template not
found. Cannot upgrade system Vms");
-                    } else {
-                        s_logger.warn("4.2.0 VMware SystemVm template not found. VMware hypervisor
is not used, so not failing upgrade");
-                    }
+            Map<HypervisorType, String> routerTemplateConfigurationNames = new HashMap<HypervisorType,
String>(){
+                {   put(HypervisorType.XenServer, "router.template.xen");
+                    put(HypervisorType.VMware, "router.template.vmware");
+                    put(HypervisorType.KVM, "router.template.kvm");
+                    put(HypervisorType.LXC, "router.template.lxc");
+                    put(HypervisorType.Hyperv, "router.template.hyperv");
                 }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while updating VMware systemVm template",
e);
-            }
+            };
 
-            //Hyperv
-            s_logger.debug("Updating Hyperv System Vms");
-            try {
-                //Get 4.2.0 Hyperv system Vm template Id
-                pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name = 'systemvm-hyperv-4.2' and removed is null order by id desc limit 1");
-                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 = 'Hyperv'");
-                    pstmt.setLong(1, templateId);
-                    pstmt.executeUpdate();
-                    pstmt.close();
-                    // Change value of global configuration parameter router.template.hyperv
-                    pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.hyperv', 'systemvm-hyperv-4.2',
'Name of the default router template on Hyperv')");
-                    pstmt.execute();
-                    pstmt.close();
-                } else {
-                    if (Hyperv){
-                        throw new CloudRuntimeException("4.2.0 HyperV SystemVm template not
found. Cannot upgrade system Vms");
+            for (Map.Entry<HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){
+                s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System
Vms");
+                try {
+                    //Get 4.2.0 system Vm template Id for corresponding hypervisor
+                    pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name like ? 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();
+                        // 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("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', ?, ?, 'Name of the default router template
on Xenserver')");
+                        pstmt.setString(1, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
+                        pstmt.setString(2, hypervisorAndTemplateName.getValue());
+                        pstmt.execute();
+                        pstmt.close();
                     } else {
-                        s_logger.warn("4.2.0 Hyperv SystemVm template not found. Hyperv hypervisor
is not used, so not failing upgrade");
+                        if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
+                            throw new CloudRuntimeException("4.2.0 " + hypervisorAndTemplateName.getKey()
+ " SystemVm template not found. Cannot upgrade system Vms");
+                        } else {
+                            s_logger.warn("4.2.0 " + hypervisorAndTemplateName.getKey() +
" SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not
used, so not failing upgrade");
+                        }
                     }
+                } catch (SQLException e) {
+                    throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey()
+" systemVm template", e);
                 }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while updating Hyperv systemVm template",
e);
             }
 
-            //LXC
-            s_logger.debug("Updating LXC System Vms");
-            try {
-                //Get 4.2.0 LXC system Vm template Id
-                pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where
name = 'systemvm-lxc-4.2' and removed is null order by id desc limit 1");
-                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 = 'LXC'");
-                    pstmt.setLong(1, templateId);
-                    pstmt.executeUpdate();
-                    pstmt.close();
-                    // Change value of global configuration parameter router.template.lxc
-                    pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration`
VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.lxc', 'systemvm-lxc-4.2',
'Name of the default router template on LXC')");
-                    pstmt.execute();
-                    pstmt.close();
-                } else {
-                    if (LXC){
-                        throw new CloudRuntimeException("4.2.0 LXC SystemVm template not
found. Cannot upgrade system Vms");
-                    } else {
-                        s_logger.warn("4.2.0 LXC SystemVm template not found. LXC hypervisor
is not used, so not failing upgrade");
-                    }
-                }
-            } catch (SQLException e) {
-                throw new CloudRuntimeException("Error while updating LXC systemVm template",
e);
-            }
             s_logger.debug("Updating System Vm Template IDs Complete");
         }
         finally {


Mime
View raw message