You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Wei ZHOU <us...@gmail.com> on 2013/06/05 11:56:11 UTC

Re: git commit: updated refs/heads/master to 9fe7846

Kishan,

What do you think about change some codes to "name like
'systemvm-xenserver-%' " ?
If we use other templates, the upgrade maybe fail.

-Wei


2013/6/5 <ki...@apache.org>

> Updated Branches:
>   refs/heads/master 91b15711b -> 9fe7846d7
>
>
> CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system templates
>
>
> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
> Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
> Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
> Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>
> Branch: refs/heads/master
> Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
> Parents: 91b1571
> Author: Harikrishna Patnala <ha...@citrix.com>
> Authored: Mon Jun 3 12:33:58 2013 +0530
> Committer: Kishan Kavala <ki...@cloud.com>
> Committed: Wed Jun 5 15:14:04 2013 +0530
>
> ----------------------------------------------------------------------
>  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209 ++++++++++++++-
>  1 files changed, 204 insertions(+), 5 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
> --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> @@ -112,16 +112,215 @@ public class Upgrade410to420 implements DbUpgrade {
>      }
>
>      private void updateSystemVmTemplates(Connection conn) {
> -           PreparedStatement sql = null;
> +
> +        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
> +            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;
> +                    }
> +                }
> +            } 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 xenserer 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();
> +                } 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");
> +                    }
> +                }
> +            } 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();
> +                } 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();
> +                } 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");
> +                    }
> +                }
> +            } 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();
> +                } else {
> +                    if (Hyperv){
> +                        throw new CloudRuntimeException("4.2.0 HyperV
> SystemVm template not found. Cannot upgrade system Vms");
> +                    } else {
> +                        s_logger.warn("4.2.0 Hyperv SystemVm template not
> found. Hyperv hypervisor is not used, so not failing upgrade");
> +                    }
> +                }
> +            } 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();
> +                } 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 {
> +            try {
> +                if (rs != null) {
> +                    rs.close();
> +                }
> +
> +                if (pstmt != null) {
> +                    pstmt.close();
> +                }
> +            } catch (SQLException e) {
> +            }
> +        }
> +        pstmt = null;
>          try {
> -            sql = conn.prepareStatement("update vm_template set
> image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> -            sql.executeUpdate();
> +            pstmt = conn.prepareStatement("update vm_template set
> image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> +            pstmt.executeUpdate();
>          } catch (SQLException e) {
>              throw new CloudRuntimeException("Failed to upgrade vm
> template data store uuid: " + e.toString());
>          } finally {
> -            if (sql != null) {
> +            if (pstmt != null) {
>                  try {
> -                    sql.close();
> +                    pstmt.close();
>                  } catch (SQLException e) {
>                  }
>              }
>
>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Chiradeep Vittal <Ch...@citrix.com>.
Seems to be a 4.2 feature
commit 10b6c1c6c8f8c2ec49145a901fb083e7f362f3a1
Author: Harikrishna Patnala <ha...@citrix.com>
Date:   Tue Apr 30 16:41:25 2013 +0530

    CLOUDSTACK-741: Granular Global Parameters Added parameters to cluster
level cluster.storage.allocated.capacity.notificationthreshold
cluster.storage.capacity.notificationthreshold
    
    CLOUDSTACK-2036
    global parameter for Router Template ID functionality added
    We use 5 parameters to set the router template name for each hypervisor



On 6/7/13 12:44 PM, "Marcus Sorensen" <sh...@gmail.com> wrote:

>4.1 is the same, but it does away with the router.template.kvm config
>parameter. It literally just matches the last row in the vm_template
>field that is type 'SYSTEM' and your hypervisor type.  It also has a
>router.template.id field that seems to do nothing.
>
>I'm assuming the other system vms work the same way...
>
>On Fri, Jun 7, 2013 at 1:36 PM, Marcus Sorensen <sh...@gmail.com>
>wrote:
>> Ok, here's what I've figured out so far (for master branch, 4.1 seems
>> different):
>>
>> Specifically for routers, given the hypervisor KVM, it searches the
>> table vm_template for type='SYSTEM' and hypervisor_type='KVM' and
>> chooses the last registered template.
>>
>> There is a 'router.template.kvm' config option, not in the
>> configuration table by default. If that exists, it is supposed to take
>> the value of that config option and search the 'name' field of the
>> vm_template table as well(add to the filter).
>>
>> There is another config parameter called router.template.id, which
>> seems to do nothing in master code. There are references to things
>> that set it in the configuration table, but that's about it. This
>> seems bad because it's exposed to the user but doesn't do anything.
>>
>> So, back to the original question of how to update a system VM
>> template. It looks like you'd register a new template, manually set
>> its type to 'SYSTEM' in the database (or how else can you set it?),
>> and that's it. If you want a particular one out of several SYSTEM
>> templates, rather than the latest, you'd set the router.template.kvm
>> parameter to the name text matching the particular template.
>>
>> Now on to 4.1....
>>
>> On Fri, Jun 7, 2013 at 12:42 PM, Marcus Sorensen <sh...@gmail.com>
>>wrote:
>>> Ok. That gives me a place to start digging to figure out how to do
>>> this. I'll update the thread when I find out, just for future
>>> reference.
>>>
>>> On Fri, Jun 7, 2013 at 12:06 PM, Chiradeep Vittal
>>> <Ch...@citrix.com> wrote:
>>>>  _configServer.getConfigValue(Config.RouterTemplate***.key(),
>>>>                 VMTemplateVO template =
>>>> _templateDao.findRoutingTemplate(hType, templateName);
>>>>
>>>>
>>>>
>>>> On 6/7/13 8:55 AM, "Marcus Sorensen" <sh...@gmail.com> wrote:
>>>>
>>>>>I'm not sure if this fits in the discussion, I was asking Wei how
>>>>>cloudstack chooses the system vm template during normal operation. I
>>>>>get how the upgrades work, but I don't get how cloudstack chooses the
>>>>>system template to use when actually deploying:
>>>>>
>>>>>I'm looking at it from a different perspective, not a CS
>>>>>upgrade, but say we have to roll a new systemvm template for an
>>>>>existing CS version. Say we rolled 4.2, with a new template, and then
>>>>>two months later we realize that the template is missing dnsmasq or
>>>>>something, and we have to have everyone install a new template. Do we
>>>>>actually have to overwrite the existing template in-place on secondary
>>>>>storage, then on each primary storage while the system vms are down?
>>>>>Or can we register a new template, and the new template gets installed
>>>>>on primary storage as system vms are rebooted.
>>>>>
>>>>> I saw that the upgrade scripts had that 'select max' statement, but
>>>>>that just fetches the id for installing the template to secondary
>>>>>storage. When I deploy a router, how does cloudstack select the
>>>>>template for that?
>>>>>
>>>>>On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com>
>>>>>wrote:
>>>>>> In my point view, we ask users register new template in the upgrade
>>>>>> instruction in release notes. If they do not register, it is their
>>>>>> fault. If they do but upgrade fails, it is our fault.
>>>>>>
>>>>>> I admit that it is a good way to change each upgrade process and
>>>>>> remove old templates when we use new template. It is not large work.
>>>>>>
>>>>>> -Wei
>>>>>>
>>>>>> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>>>>>>> In the mentioned example, when new template for 4.3 is introduced,
>>>>>>>we
>>>>>>>should
>>>>>>> remove template upgrade code in Upgrade41to42. This will make
>>>>>>>upgrade
>>>>>>> succeed even when systemvm-kvm-4.2 is not in database.
>>>>>>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3
>>>>>>>will
>>>>>>>succeed
>>>>>>> even though the required systemvm-kvm-4.3 is not in database.
>>>>>>>
>>>>>>> So, every time a new system vm template is added, template upgrade
>>>>>>>from
>>>>>>> previous version should be removed.
>>>>>>>
>>>>>>> ________________________________________
>>>>>>> From: Wei ZHOU [ustcweizhou@gmail.com]
>>>>>>> Sent: Wednesday, June 05, 2013 3:56 PM
>>>>>>> To: dev@cloudstack.apache.org
>>>>>>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>>>
>>>>>>> Kishan,
>>>>>>>
>>>>>>> I know.
>>>>>>>
>>>>>>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>>>>>>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>>>>>>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>>>>>>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail
>>>>>>>in
>>>>>>>the
>>>>>>> Upgrade41to42.
>>>>>>>
>>>>>>> -Wei
>>>>>>>
>>>>>>>
>>>>>>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>>>>>>
>>>>>>>> Wei,
>>>>>>>>  If we use other templates, system Vms may not work. Only 4.2
>>>>>>>>templates
>>>>>>>> should be used when upgrading to 4.2.
>>>>>>>>
>>>>>>>> > -----Original Message-----
>>>>>>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>>>>>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>>>>>>> > To: dev@cloudstack.apache.org
>>>>>>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>>>> >
>>>>>>>> > Kishan,
>>>>>>>> >
>>>>>>>> > What do you think about change some codes to "name like
>>>>>>>>'systemvm-
>>>>>>>> > xenserver-%' " ?
>>>>>>>> > If we use other templates, the upgrade maybe fail.
>>>>>>>> >
>>>>>>>> > -Wei
>>>>>>>> >
>>>>>>>> >
>>>>>>>> > 2013/6/5 <ki...@apache.org>
>>>>>>>> >
>>>>>>>> > > Updated Branches:
>>>>>>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>>>>>>> > > templates
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>> > > Project:
>>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>>>>>>> > > Commit:
>>>>>>>> > > 
>>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>>>>>>> > > Tree:
>>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>>>>>>> > > Diff:
>>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>>>>>>> > >
>>>>>>>> > > Branch: refs/heads/master
>>>>>>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>>>>>>> > > Parents: 91b1571
>>>>>>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>>>>>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>>>>>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>>>>>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>>-------------------------------------------------------------------
>>>>>>>>---
>>>>>>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>>>>>>> > >               -
>>>>>>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>>>>>>> > >
>>>>>>>>-------------------------------------------------------------------
>>>>>>>>---
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/eng
>>>>>>>>ine
>>>>>>>> > > /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 1584973..955ea56 100644
>>>>>>>> > > --- 
>>>>>>>>a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>>>> > >     
>>>>>>>>b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>>>>>>> > DbUpgrade {
>>>>>>>> > >      }
>>>>>>>> > >
>>>>>>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>>>>>>> > > -           PreparedStatement sql = null;
>>>>>>>> > >
>>>>>>>> > >          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
>>>>>>>> > >              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;
>>>>>>>> > >                      }
>>>>>>>> > >                  }
>>>>>>>> > >              } 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 xenserer 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();
>>>>>>>> > >                  } 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");
>>>>>>>> > >                      }
>>>>>>>> > >                  }
>>>>>>>> > >              } 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();
>>>>>>>> > >                  } 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();
>>>>>>>> > >                  } 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");
>>>>>>>> > >                      }
>>>>>>>> > >                  }
>>>>>>>> > >              } 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();
>>>>>>>> > >                  } else {
>>>>>>>> > >                      if (Hyperv){
>>>>>>>> > >                          throw new
>>>>>>>>CloudRuntimeException("4.2.0
>>>>>>>>HyperV
>>>>>>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>>>>>>> > >                      } else {
>>>>>>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm
>>>>>>>>template
>>>>>>>> > >   not
>>>>>>>> > > found. Hyperv hypervisor is not used, so not failing
>>>>>>>>upgrade");
>>>>>>>> > >                      }
>>>>>>>> > >                  }
>>>>>>>> > >              } 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();
>>>>>>>> > >                  } 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 {
>>>>>>>> > >              try {
>>>>>>>> > >                  if (rs != null) {
>>>>>>>> > >                      rs.close();
>>>>>>>> > >                  }
>>>>>>>> > >
>>>>>>>> > >                  if (pstmt != null) {
>>>>>>>> > >                      pstmt.close();
>>>>>>>> > >                  }
>>>>>>>> > >              } catch (SQLException e) {
>>>>>>>> > >              }
>>>>>>>> > >          }
>>>>>>>> > >          pstmt = null;
>>>>>>>> > >          try {
>>>>>>>> > > -            sql = conn.prepareStatement("update vm_template
>>>>>>>>set
>>>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>>>'BUILTIN'");
>>>>>>>> > > -            sql.executeUpdate();
>>>>>>>> > >              pstmt = conn.prepareStatement("update
>>>>>>>>vm_template set
>>>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>>>'BUILTIN'");
>>>>>>>> > >              pstmt.executeUpdate();
>>>>>>>> > >          } catch (SQLException e) {
>>>>>>>> > >              throw new CloudRuntimeException("Failed to
>>>>>>>>upgrade vm
>>>>>>>> > > template data store uuid: "   e.toString());
>>>>>>>> > >          } finally {
>>>>>>>> > > -            if (sql != null) {
>>>>>>>> > >              if (pstmt != null) {
>>>>>>>> > >                  try {
>>>>>>>> > > -                    sql.close();
>>>>>>>> > >                      pstmt.close();
>>>>>>>> > >                  } catch (SQLException e) {
>>>>>>>> > >                  }
>>>>>>>> > >              }
>>>>>>>> > >
>>>>>>>> > >
>>>>>>>>
>>>>>>>
>>>>


Re: git commit: updated refs/heads/master to 9fe7846

Posted by Marcus Sorensen <sh...@gmail.com>.
4.1 is the same, but it does away with the router.template.kvm config
parameter. It literally just matches the last row in the vm_template
field that is type 'SYSTEM' and your hypervisor type.  It also has a
router.template.id field that seems to do nothing.

I'm assuming the other system vms work the same way...

On Fri, Jun 7, 2013 at 1:36 PM, Marcus Sorensen <sh...@gmail.com> wrote:
> Ok, here's what I've figured out so far (for master branch, 4.1 seems
> different):
>
> Specifically for routers, given the hypervisor KVM, it searches the
> table vm_template for type='SYSTEM' and hypervisor_type='KVM' and
> chooses the last registered template.
>
> There is a 'router.template.kvm' config option, not in the
> configuration table by default. If that exists, it is supposed to take
> the value of that config option and search the 'name' field of the
> vm_template table as well(add to the filter).
>
> There is another config parameter called router.template.id, which
> seems to do nothing in master code. There are references to things
> that set it in the configuration table, but that's about it. This
> seems bad because it's exposed to the user but doesn't do anything.
>
> So, back to the original question of how to update a system VM
> template. It looks like you'd register a new template, manually set
> its type to 'SYSTEM' in the database (or how else can you set it?),
> and that's it. If you want a particular one out of several SYSTEM
> templates, rather than the latest, you'd set the router.template.kvm
> parameter to the name text matching the particular template.
>
> Now on to 4.1....
>
> On Fri, Jun 7, 2013 at 12:42 PM, Marcus Sorensen <sh...@gmail.com> wrote:
>> Ok. That gives me a place to start digging to figure out how to do
>> this. I'll update the thread when I find out, just for future
>> reference.
>>
>> On Fri, Jun 7, 2013 at 12:06 PM, Chiradeep Vittal
>> <Ch...@citrix.com> wrote:
>>>  _configServer.getConfigValue(Config.RouterTemplate***.key(),
>>>                 VMTemplateVO template =
>>> _templateDao.findRoutingTemplate(hType, templateName);
>>>
>>>
>>>
>>> On 6/7/13 8:55 AM, "Marcus Sorensen" <sh...@gmail.com> wrote:
>>>
>>>>I'm not sure if this fits in the discussion, I was asking Wei how
>>>>cloudstack chooses the system vm template during normal operation. I
>>>>get how the upgrades work, but I don't get how cloudstack chooses the
>>>>system template to use when actually deploying:
>>>>
>>>>I'm looking at it from a different perspective, not a CS
>>>>upgrade, but say we have to roll a new systemvm template for an
>>>>existing CS version. Say we rolled 4.2, with a new template, and then
>>>>two months later we realize that the template is missing dnsmasq or
>>>>something, and we have to have everyone install a new template. Do we
>>>>actually have to overwrite the existing template in-place on secondary
>>>>storage, then on each primary storage while the system vms are down?
>>>>Or can we register a new template, and the new template gets installed
>>>>on primary storage as system vms are rebooted.
>>>>
>>>> I saw that the upgrade scripts had that 'select max' statement, but
>>>>that just fetches the id for installing the template to secondary
>>>>storage. When I deploy a router, how does cloudstack select the
>>>>template for that?
>>>>
>>>>On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com> wrote:
>>>>> In my point view, we ask users register new template in the upgrade
>>>>> instruction in release notes. If they do not register, it is their
>>>>> fault. If they do but upgrade fails, it is our fault.
>>>>>
>>>>> I admit that it is a good way to change each upgrade process and
>>>>> remove old templates when we use new template. It is not large work.
>>>>>
>>>>> -Wei
>>>>>
>>>>> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>>>>>> In the mentioned example, when new template for 4.3 is introduced, we
>>>>>>should
>>>>>> remove template upgrade code in Upgrade41to42. This will make upgrade
>>>>>> succeed even when systemvm-kvm-4.2 is not in database.
>>>>>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will
>>>>>>succeed
>>>>>> even though the required systemvm-kvm-4.3 is not in database.
>>>>>>
>>>>>> So, every time a new system vm template is added, template upgrade from
>>>>>> previous version should be removed.
>>>>>>
>>>>>> ________________________________________
>>>>>> From: Wei ZHOU [ustcweizhou@gmail.com]
>>>>>> Sent: Wednesday, June 05, 2013 3:56 PM
>>>>>> To: dev@cloudstack.apache.org
>>>>>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>>
>>>>>> Kishan,
>>>>>>
>>>>>> I know.
>>>>>>
>>>>>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>>>>>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>>>>>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>>>>>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in
>>>>>>the
>>>>>> Upgrade41to42.
>>>>>>
>>>>>> -Wei
>>>>>>
>>>>>>
>>>>>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>>>>>
>>>>>>> Wei,
>>>>>>>  If we use other templates, system Vms may not work. Only 4.2
>>>>>>>templates
>>>>>>> should be used when upgrading to 4.2.
>>>>>>>
>>>>>>> > -----Original Message-----
>>>>>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>>>>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>>>>>> > To: dev@cloudstack.apache.org
>>>>>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>>> >
>>>>>>> > Kishan,
>>>>>>> >
>>>>>>> > What do you think about change some codes to "name like 'systemvm-
>>>>>>> > xenserver-%' " ?
>>>>>>> > If we use other templates, the upgrade maybe fail.
>>>>>>> >
>>>>>>> > -Wei
>>>>>>> >
>>>>>>> >
>>>>>>> > 2013/6/5 <ki...@apache.org>
>>>>>>> >
>>>>>>> > > Updated Branches:
>>>>>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>>>>>> > >
>>>>>>> > >
>>>>>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>>>>>> > > templates
>>>>>>> > >
>>>>>>> > >
>>>>>>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>>>>>> > > Commit:
>>>>>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>>>>>> > > Tree:
>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>>>>>> > > Diff:
>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>>>>>> > >
>>>>>>> > > Branch: refs/heads/master
>>>>>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>>>>>> > > Parents: 91b1571
>>>>>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>>>>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>>>>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>>>>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>>>>>> > >
>>>>>>> > >
>>>>>>>----------------------------------------------------------------------
>>>>>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>>>>>> > >               -
>>>>>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>>>>>> > >
>>>>>>>----------------------------------------------------------------------
>>>>>>> > >
>>>>>>> > >
>>>>>>> > >
>>>>>>> > >
>>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>>>>>>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>>>>>> > DbUpgrade {
>>>>>>> > >      }
>>>>>>> > >
>>>>>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>>>>>> > > -           PreparedStatement sql = null;
>>>>>>> > >
>>>>>>> > >          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
>>>>>>> > >              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;
>>>>>>> > >                      }
>>>>>>> > >                  }
>>>>>>> > >              } 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 xenserer 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();
>>>>>>> > >                  } 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");
>>>>>>> > >                      }
>>>>>>> > >                  }
>>>>>>> > >              } 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();
>>>>>>> > >                  } 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();
>>>>>>> > >                  } 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");
>>>>>>> > >                      }
>>>>>>> > >                  }
>>>>>>> > >              } 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();
>>>>>>> > >                  } else {
>>>>>>> > >                      if (Hyperv){
>>>>>>> > >                          throw new CloudRuntimeException("4.2.0
>>>>>>>HyperV
>>>>>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>>>>>> > >                      } else {
>>>>>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm
>>>>>>>template
>>>>>>> > >   not
>>>>>>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>>>>>>> > >                      }
>>>>>>> > >                  }
>>>>>>> > >              } 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();
>>>>>>> > >                  } 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 {
>>>>>>> > >              try {
>>>>>>> > >                  if (rs != null) {
>>>>>>> > >                      rs.close();
>>>>>>> > >                  }
>>>>>>> > >
>>>>>>> > >                  if (pstmt != null) {
>>>>>>> > >                      pstmt.close();
>>>>>>> > >                  }
>>>>>>> > >              } catch (SQLException e) {
>>>>>>> > >              }
>>>>>>> > >          }
>>>>>>> > >          pstmt = null;
>>>>>>> > >          try {
>>>>>>> > > -            sql = conn.prepareStatement("update vm_template set
>>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>>'BUILTIN'");
>>>>>>> > > -            sql.executeUpdate();
>>>>>>> > >              pstmt = conn.prepareStatement("update vm_template set
>>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>>'BUILTIN'");
>>>>>>> > >              pstmt.executeUpdate();
>>>>>>> > >          } catch (SQLException e) {
>>>>>>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>>>>>>> > > template data store uuid: "   e.toString());
>>>>>>> > >          } finally {
>>>>>>> > > -            if (sql != null) {
>>>>>>> > >              if (pstmt != null) {
>>>>>>> > >                  try {
>>>>>>> > > -                    sql.close();
>>>>>>> > >                      pstmt.close();
>>>>>>> > >                  } catch (SQLException e) {
>>>>>>> > >                  }
>>>>>>> > >              }
>>>>>>> > >
>>>>>>> > >
>>>>>>>
>>>>>>
>>>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Marcus Sorensen <sh...@gmail.com>.
Ok, here's what I've figured out so far (for master branch, 4.1 seems
different):

Specifically for routers, given the hypervisor KVM, it searches the
table vm_template for type='SYSTEM' and hypervisor_type='KVM' and
chooses the last registered template.

There is a 'router.template.kvm' config option, not in the
configuration table by default. If that exists, it is supposed to take
the value of that config option and search the 'name' field of the
vm_template table as well(add to the filter).

There is another config parameter called router.template.id, which
seems to do nothing in master code. There are references to things
that set it in the configuration table, but that's about it. This
seems bad because it's exposed to the user but doesn't do anything.

So, back to the original question of how to update a system VM
template. It looks like you'd register a new template, manually set
its type to 'SYSTEM' in the database (or how else can you set it?),
and that's it. If you want a particular one out of several SYSTEM
templates, rather than the latest, you'd set the router.template.kvm
parameter to the name text matching the particular template.

Now on to 4.1....

On Fri, Jun 7, 2013 at 12:42 PM, Marcus Sorensen <sh...@gmail.com> wrote:
> Ok. That gives me a place to start digging to figure out how to do
> this. I'll update the thread when I find out, just for future
> reference.
>
> On Fri, Jun 7, 2013 at 12:06 PM, Chiradeep Vittal
> <Ch...@citrix.com> wrote:
>>  _configServer.getConfigValue(Config.RouterTemplate***.key(),
>>                 VMTemplateVO template =
>> _templateDao.findRoutingTemplate(hType, templateName);
>>
>>
>>
>> On 6/7/13 8:55 AM, "Marcus Sorensen" <sh...@gmail.com> wrote:
>>
>>>I'm not sure if this fits in the discussion, I was asking Wei how
>>>cloudstack chooses the system vm template during normal operation. I
>>>get how the upgrades work, but I don't get how cloudstack chooses the
>>>system template to use when actually deploying:
>>>
>>>I'm looking at it from a different perspective, not a CS
>>>upgrade, but say we have to roll a new systemvm template for an
>>>existing CS version. Say we rolled 4.2, with a new template, and then
>>>two months later we realize that the template is missing dnsmasq or
>>>something, and we have to have everyone install a new template. Do we
>>>actually have to overwrite the existing template in-place on secondary
>>>storage, then on each primary storage while the system vms are down?
>>>Or can we register a new template, and the new template gets installed
>>>on primary storage as system vms are rebooted.
>>>
>>> I saw that the upgrade scripts had that 'select max' statement, but
>>>that just fetches the id for installing the template to secondary
>>>storage. When I deploy a router, how does cloudstack select the
>>>template for that?
>>>
>>>On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com> wrote:
>>>> In my point view, we ask users register new template in the upgrade
>>>> instruction in release notes. If they do not register, it is their
>>>> fault. If they do but upgrade fails, it is our fault.
>>>>
>>>> I admit that it is a good way to change each upgrade process and
>>>> remove old templates when we use new template. It is not large work.
>>>>
>>>> -Wei
>>>>
>>>> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>>>>> In the mentioned example, when new template for 4.3 is introduced, we
>>>>>should
>>>>> remove template upgrade code in Upgrade41to42. This will make upgrade
>>>>> succeed even when systemvm-kvm-4.2 is not in database.
>>>>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will
>>>>>succeed
>>>>> even though the required systemvm-kvm-4.3 is not in database.
>>>>>
>>>>> So, every time a new system vm template is added, template upgrade from
>>>>> previous version should be removed.
>>>>>
>>>>> ________________________________________
>>>>> From: Wei ZHOU [ustcweizhou@gmail.com]
>>>>> Sent: Wednesday, June 05, 2013 3:56 PM
>>>>> To: dev@cloudstack.apache.org
>>>>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>
>>>>> Kishan,
>>>>>
>>>>> I know.
>>>>>
>>>>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>>>>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>>>>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>>>>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in
>>>>>the
>>>>> Upgrade41to42.
>>>>>
>>>>> -Wei
>>>>>
>>>>>
>>>>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>>>>
>>>>>> Wei,
>>>>>>  If we use other templates, system Vms may not work. Only 4.2
>>>>>>templates
>>>>>> should be used when upgrading to 4.2.
>>>>>>
>>>>>> > -----Original Message-----
>>>>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>>>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>>>>> > To: dev@cloudstack.apache.org
>>>>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>>> >
>>>>>> > Kishan,
>>>>>> >
>>>>>> > What do you think about change some codes to "name like 'systemvm-
>>>>>> > xenserver-%' " ?
>>>>>> > If we use other templates, the upgrade maybe fail.
>>>>>> >
>>>>>> > -Wei
>>>>>> >
>>>>>> >
>>>>>> > 2013/6/5 <ki...@apache.org>
>>>>>> >
>>>>>> > > Updated Branches:
>>>>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>>>>> > >
>>>>>> > >
>>>>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>>>>> > > templates
>>>>>> > >
>>>>>> > >
>>>>>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>>>>> > > Commit:
>>>>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>>>>> > > Tree:
>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>>>>> > > Diff:
>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>>>>> > >
>>>>>> > > Branch: refs/heads/master
>>>>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>>>>> > > Parents: 91b1571
>>>>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>>>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>>>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>>>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>>>>> > >
>>>>>> > >
>>>>>>----------------------------------------------------------------------
>>>>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>>>>> > >               -
>>>>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>>>>> > >
>>>>>>----------------------------------------------------------------------
>>>>>> > >
>>>>>> > >
>>>>>> > >
>>>>>> > >
>>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>>>>>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>>>>> > DbUpgrade {
>>>>>> > >      }
>>>>>> > >
>>>>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>>>>> > > -           PreparedStatement sql = null;
>>>>>> > >
>>>>>> > >          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
>>>>>> > >              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;
>>>>>> > >                      }
>>>>>> > >                  }
>>>>>> > >              } 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 xenserer 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();
>>>>>> > >                  } 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");
>>>>>> > >                      }
>>>>>> > >                  }
>>>>>> > >              } 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();
>>>>>> > >                  } 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();
>>>>>> > >                  } 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");
>>>>>> > >                      }
>>>>>> > >                  }
>>>>>> > >              } 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();
>>>>>> > >                  } else {
>>>>>> > >                      if (Hyperv){
>>>>>> > >                          throw new CloudRuntimeException("4.2.0
>>>>>>HyperV
>>>>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>>>>> > >                      } else {
>>>>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm
>>>>>>template
>>>>>> > >   not
>>>>>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>>>>>> > >                      }
>>>>>> > >                  }
>>>>>> > >              } 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();
>>>>>> > >                  } 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 {
>>>>>> > >              try {
>>>>>> > >                  if (rs != null) {
>>>>>> > >                      rs.close();
>>>>>> > >                  }
>>>>>> > >
>>>>>> > >                  if (pstmt != null) {
>>>>>> > >                      pstmt.close();
>>>>>> > >                  }
>>>>>> > >              } catch (SQLException e) {
>>>>>> > >              }
>>>>>> > >          }
>>>>>> > >          pstmt = null;
>>>>>> > >          try {
>>>>>> > > -            sql = conn.prepareStatement("update vm_template set
>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>'BUILTIN'");
>>>>>> > > -            sql.executeUpdate();
>>>>>> > >              pstmt = conn.prepareStatement("update vm_template set
>>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>>'BUILTIN'");
>>>>>> > >              pstmt.executeUpdate();
>>>>>> > >          } catch (SQLException e) {
>>>>>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>>>>>> > > template data store uuid: "   e.toString());
>>>>>> > >          } finally {
>>>>>> > > -            if (sql != null) {
>>>>>> > >              if (pstmt != null) {
>>>>>> > >                  try {
>>>>>> > > -                    sql.close();
>>>>>> > >                      pstmt.close();
>>>>>> > >                  } catch (SQLException e) {
>>>>>> > >                  }
>>>>>> > >              }
>>>>>> > >
>>>>>> > >
>>>>>>
>>>>>
>>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Marcus Sorensen <sh...@gmail.com>.
Ok. That gives me a place to start digging to figure out how to do
this. I'll update the thread when I find out, just for future
reference.

On Fri, Jun 7, 2013 at 12:06 PM, Chiradeep Vittal
<Ch...@citrix.com> wrote:
>  _configServer.getConfigValue(Config.RouterTemplate***.key(),
>                 VMTemplateVO template =
> _templateDao.findRoutingTemplate(hType, templateName);
>
>
>
> On 6/7/13 8:55 AM, "Marcus Sorensen" <sh...@gmail.com> wrote:
>
>>I'm not sure if this fits in the discussion, I was asking Wei how
>>cloudstack chooses the system vm template during normal operation. I
>>get how the upgrades work, but I don't get how cloudstack chooses the
>>system template to use when actually deploying:
>>
>>I'm looking at it from a different perspective, not a CS
>>upgrade, but say we have to roll a new systemvm template for an
>>existing CS version. Say we rolled 4.2, with a new template, and then
>>two months later we realize that the template is missing dnsmasq or
>>something, and we have to have everyone install a new template. Do we
>>actually have to overwrite the existing template in-place on secondary
>>storage, then on each primary storage while the system vms are down?
>>Or can we register a new template, and the new template gets installed
>>on primary storage as system vms are rebooted.
>>
>> I saw that the upgrade scripts had that 'select max' statement, but
>>that just fetches the id for installing the template to secondary
>>storage. When I deploy a router, how does cloudstack select the
>>template for that?
>>
>>On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com> wrote:
>>> In my point view, we ask users register new template in the upgrade
>>> instruction in release notes. If they do not register, it is their
>>> fault. If they do but upgrade fails, it is our fault.
>>>
>>> I admit that it is a good way to change each upgrade process and
>>> remove old templates when we use new template. It is not large work.
>>>
>>> -Wei
>>>
>>> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>>>> In the mentioned example, when new template for 4.3 is introduced, we
>>>>should
>>>> remove template upgrade code in Upgrade41to42. This will make upgrade
>>>> succeed even when systemvm-kvm-4.2 is not in database.
>>>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will
>>>>succeed
>>>> even though the required systemvm-kvm-4.3 is not in database.
>>>>
>>>> So, every time a new system vm template is added, template upgrade from
>>>> previous version should be removed.
>>>>
>>>> ________________________________________
>>>> From: Wei ZHOU [ustcweizhou@gmail.com]
>>>> Sent: Wednesday, June 05, 2013 3:56 PM
>>>> To: dev@cloudstack.apache.org
>>>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>
>>>> Kishan,
>>>>
>>>> I know.
>>>>
>>>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>>>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>>>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>>>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in
>>>>the
>>>> Upgrade41to42.
>>>>
>>>> -Wei
>>>>
>>>>
>>>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>>>
>>>>> Wei,
>>>>>  If we use other templates, system Vms may not work. Only 4.2
>>>>>templates
>>>>> should be used when upgrading to 4.2.
>>>>>
>>>>> > -----Original Message-----
>>>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>>>> > To: dev@cloudstack.apache.org
>>>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>>> >
>>>>> > Kishan,
>>>>> >
>>>>> > What do you think about change some codes to "name like 'systemvm-
>>>>> > xenserver-%' " ?
>>>>> > If we use other templates, the upgrade maybe fail.
>>>>> >
>>>>> > -Wei
>>>>> >
>>>>> >
>>>>> > 2013/6/5 <ki...@apache.org>
>>>>> >
>>>>> > > Updated Branches:
>>>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>>>> > >
>>>>> > >
>>>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>>>> > > templates
>>>>> > >
>>>>> > >
>>>>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>>>> > > Commit:
>>>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>>>> > > Tree:
>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>>>> > > Diff:
>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>>>> > >
>>>>> > > Branch: refs/heads/master
>>>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>>>> > > Parents: 91b1571
>>>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>>>> > >
>>>>> > >
>>>>>----------------------------------------------------------------------
>>>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>>>> > >               -
>>>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>>>> > >
>>>>>----------------------------------------------------------------------
>>>>> > >
>>>>> > >
>>>>> > >
>>>>> > >
>>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>>>>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>>>> > DbUpgrade {
>>>>> > >      }
>>>>> > >
>>>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>>>> > > -           PreparedStatement sql = null;
>>>>> > >
>>>>> > >          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
>>>>> > >              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;
>>>>> > >                      }
>>>>> > >                  }
>>>>> > >              } 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 xenserer 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();
>>>>> > >                  } 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");
>>>>> > >                      }
>>>>> > >                  }
>>>>> > >              } 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();
>>>>> > >                  } 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();
>>>>> > >                  } 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");
>>>>> > >                      }
>>>>> > >                  }
>>>>> > >              } 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();
>>>>> > >                  } else {
>>>>> > >                      if (Hyperv){
>>>>> > >                          throw new CloudRuntimeException("4.2.0
>>>>>HyperV
>>>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>>>> > >                      } else {
>>>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm
>>>>>template
>>>>> > >   not
>>>>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>>>>> > >                      }
>>>>> > >                  }
>>>>> > >              } 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();
>>>>> > >                  } 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 {
>>>>> > >              try {
>>>>> > >                  if (rs != null) {
>>>>> > >                      rs.close();
>>>>> > >                  }
>>>>> > >
>>>>> > >                  if (pstmt != null) {
>>>>> > >                      pstmt.close();
>>>>> > >                  }
>>>>> > >              } catch (SQLException e) {
>>>>> > >              }
>>>>> > >          }
>>>>> > >          pstmt = null;
>>>>> > >          try {
>>>>> > > -            sql = conn.prepareStatement("update vm_template set
>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>'BUILTIN'");
>>>>> > > -            sql.executeUpdate();
>>>>> > >              pstmt = conn.prepareStatement("update vm_template set
>>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>>'BUILTIN'");
>>>>> > >              pstmt.executeUpdate();
>>>>> > >          } catch (SQLException e) {
>>>>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>>>>> > > template data store uuid: "   e.toString());
>>>>> > >          } finally {
>>>>> > > -            if (sql != null) {
>>>>> > >              if (pstmt != null) {
>>>>> > >                  try {
>>>>> > > -                    sql.close();
>>>>> > >                      pstmt.close();
>>>>> > >                  } catch (SQLException e) {
>>>>> > >                  }
>>>>> > >              }
>>>>> > >
>>>>> > >
>>>>>
>>>>
>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Chiradeep Vittal <Ch...@citrix.com>.
 _configServer.getConfigValue(Config.RouterTemplate***.key(), 		
                VMTemplateVO template =
_templateDao.findRoutingTemplate(hType, templateName);



On 6/7/13 8:55 AM, "Marcus Sorensen" <sh...@gmail.com> wrote:

>I'm not sure if this fits in the discussion, I was asking Wei how
>cloudstack chooses the system vm template during normal operation. I
>get how the upgrades work, but I don't get how cloudstack chooses the
>system template to use when actually deploying:
>
>I'm looking at it from a different perspective, not a CS
>upgrade, but say we have to roll a new systemvm template for an
>existing CS version. Say we rolled 4.2, with a new template, and then
>two months later we realize that the template is missing dnsmasq or
>something, and we have to have everyone install a new template. Do we
>actually have to overwrite the existing template in-place on secondary
>storage, then on each primary storage while the system vms are down?
>Or can we register a new template, and the new template gets installed
>on primary storage as system vms are rebooted.
>
> I saw that the upgrade scripts had that 'select max' statement, but
>that just fetches the id for installing the template to secondary
>storage. When I deploy a router, how does cloudstack select the
>template for that?
>
>On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com> wrote:
>> In my point view, we ask users register new template in the upgrade
>> instruction in release notes. If they do not register, it is their
>> fault. If they do but upgrade fails, it is our fault.
>>
>> I admit that it is a good way to change each upgrade process and
>> remove old templates when we use new template. It is not large work.
>>
>> -Wei
>>
>> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>>> In the mentioned example, when new template for 4.3 is introduced, we
>>>should
>>> remove template upgrade code in Upgrade41to42. This will make upgrade
>>> succeed even when systemvm-kvm-4.2 is not in database.
>>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will
>>>succeed
>>> even though the required systemvm-kvm-4.3 is not in database.
>>>
>>> So, every time a new system vm template is added, template upgrade from
>>> previous version should be removed.
>>>
>>> ________________________________________
>>> From: Wei ZHOU [ustcweizhou@gmail.com]
>>> Sent: Wednesday, June 05, 2013 3:56 PM
>>> To: dev@cloudstack.apache.org
>>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>
>>> Kishan,
>>>
>>> I know.
>>>
>>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in
>>>the
>>> Upgrade41to42.
>>>
>>> -Wei
>>>
>>>
>>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>>
>>>> Wei,
>>>>  If we use other templates, system Vms may not work. Only 4.2
>>>>templates
>>>> should be used when upgrading to 4.2.
>>>>
>>>> > -----Original Message-----
>>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>>> > To: dev@cloudstack.apache.org
>>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>>> >
>>>> > Kishan,
>>>> >
>>>> > What do you think about change some codes to "name like 'systemvm-
>>>> > xenserver-%' " ?
>>>> > If we use other templates, the upgrade maybe fail.
>>>> >
>>>> > -Wei
>>>> >
>>>> >
>>>> > 2013/6/5 <ki...@apache.org>
>>>> >
>>>> > > Updated Branches:
>>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>>> > >
>>>> > >
>>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>>> > > templates
>>>> > >
>>>> > >
>>>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>>> > > Commit:
>>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>>> > > Tree: 
>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>>> > > Diff: 
>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>>> > >
>>>> > > Branch: refs/heads/master
>>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>>> > > Parents: 91b1571
>>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>>> > >
>>>> > > 
>>>>----------------------------------------------------------------------
>>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>>> > >               -
>>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>>> > > 
>>>>----------------------------------------------------------------------
>>>> > >
>>>> > >
>>>> > >
>>>> > > 
>>>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>>>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>>> > DbUpgrade {
>>>> > >      }
>>>> > >
>>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>>> > > -           PreparedStatement sql = null;
>>>> > >
>>>> > >          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
>>>> > >              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;
>>>> > >                      }
>>>> > >                  }
>>>> > >              } 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 xenserer 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();
>>>> > >                  } 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");
>>>> > >                      }
>>>> > >                  }
>>>> > >              } 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();
>>>> > >                  } 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();
>>>> > >                  } 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");
>>>> > >                      }
>>>> > >                  }
>>>> > >              } 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();
>>>> > >                  } else {
>>>> > >                      if (Hyperv){
>>>> > >                          throw new CloudRuntimeException("4.2.0
>>>>HyperV
>>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>>> > >                      } else {
>>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm
>>>>template
>>>> > >   not
>>>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>>>> > >                      }
>>>> > >                  }
>>>> > >              } 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();
>>>> > >                  } 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 {
>>>> > >              try {
>>>> > >                  if (rs != null) {
>>>> > >                      rs.close();
>>>> > >                  }
>>>> > >
>>>> > >                  if (pstmt != null) {
>>>> > >                      pstmt.close();
>>>> > >                  }
>>>> > >              } catch (SQLException e) {
>>>> > >              }
>>>> > >          }
>>>> > >          pstmt = null;
>>>> > >          try {
>>>> > > -            sql = conn.prepareStatement("update vm_template set
>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>'BUILTIN'");
>>>> > > -            sql.executeUpdate();
>>>> > >              pstmt = conn.prepareStatement("update vm_template set
>>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type =
>>>>'BUILTIN'");
>>>> > >              pstmt.executeUpdate();
>>>> > >          } catch (SQLException e) {
>>>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>>>> > > template data store uuid: "   e.toString());
>>>> > >          } finally {
>>>> > > -            if (sql != null) {
>>>> > >              if (pstmt != null) {
>>>> > >                  try {
>>>> > > -                    sql.close();
>>>> > >                      pstmt.close();
>>>> > >                  } catch (SQLException e) {
>>>> > >                  }
>>>> > >              }
>>>> > >
>>>> > >
>>>>
>>>


Re: git commit: updated refs/heads/master to 9fe7846

Posted by Marcus Sorensen <sh...@gmail.com>.
I'm not sure if this fits in the discussion, I was asking Wei how
cloudstack chooses the system vm template during normal operation. I
get how the upgrades work, but I don't get how cloudstack chooses the
system template to use when actually deploying:

I'm looking at it from a different perspective, not a CS
upgrade, but say we have to roll a new systemvm template for an
existing CS version. Say we rolled 4.2, with a new template, and then
two months later we realize that the template is missing dnsmasq or
something, and we have to have everyone install a new template. Do we
actually have to overwrite the existing template in-place on secondary
storage, then on each primary storage while the system vms are down?
Or can we register a new template, and the new template gets installed
on primary storage as system vms are rebooted.

 I saw that the upgrade scripts had that 'select max' statement, but
that just fetches the id for installing the template to secondary
storage. When I deploy a router, how does cloudstack select the
template for that?

On Fri, Jun 7, 2013 at 12:15 AM, Wei ZHOU <us...@gmail.com> wrote:
> In my point view, we ask users register new template in the upgrade
> instruction in release notes. If they do not register, it is their
> fault. If they do but upgrade fails, it is our fault.
>
> I admit that it is a good way to change each upgrade process and
> remove old templates when we use new template. It is not large work.
>
> -Wei
>
> 2013/6/6, Kishan Kavala <Ki...@citrix.com>:
>> In the mentioned example, when new template for 4.3 is introduced, we should
>> remove template upgrade code in Upgrade41to42. This will make upgrade
>> succeed even when systemvm-kvm-4.2 is not in database.
>> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will succeed
>> even though the required systemvm-kvm-4.3 is not in database.
>>
>> So, every time a new system vm template is added, template upgrade from
>> previous version should be removed.
>>
>> ________________________________________
>> From: Wei ZHOU [ustcweizhou@gmail.com]
>> Sent: Wednesday, June 05, 2013 3:56 PM
>> To: dev@cloudstack.apache.org
>> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>
>> Kishan,
>>
>> I know.
>>
>> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in the
>> Upgrade41to42.
>>
>> -Wei
>>
>>
>> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>>
>>> Wei,
>>>  If we use other templates, system Vms may not work. Only 4.2 templates
>>> should be used when upgrading to 4.2.
>>>
>>> > -----Original Message-----
>>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>>> > Sent: Wednesday, 5 June 2013 3:26 PM
>>> > To: dev@cloudstack.apache.org
>>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>>> >
>>> > Kishan,
>>> >
>>> > What do you think about change some codes to "name like 'systemvm-
>>> > xenserver-%' " ?
>>> > If we use other templates, the upgrade maybe fail.
>>> >
>>> > -Wei
>>> >
>>> >
>>> > 2013/6/5 <ki...@apache.org>
>>> >
>>> > > Updated Branches:
>>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>>> > >
>>> > >
>>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>>> > > templates
>>> > >
>>> > >
>>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>>> > > Commit:
>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>>> > > Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>>> > > Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>>> > >
>>> > > Branch: refs/heads/master
>>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>>> > > Parents: 91b1571
>>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>>> > > Committer: Kishan Kavala <ki...@cloud.com>
>>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>>> > >
>>> > > ----------------------------------------------------------------------
>>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>>> > >               -
>>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>>> > > ----------------------------------------------------------------------
>>> > >
>>> > >
>>> > >
>>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>>> > DbUpgrade {
>>> > >      }
>>> > >
>>> > >      private void updateSystemVmTemplates(Connection conn) {
>>> > > -           PreparedStatement sql = null;
>>> > >
>>> > >          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
>>> > >              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;
>>> > >                      }
>>> > >                  }
>>> > >              } 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 xenserer 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();
>>> > >                  } 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");
>>> > >                      }
>>> > >                  }
>>> > >              } 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();
>>> > >                  } 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();
>>> > >                  } 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");
>>> > >                      }
>>> > >                  }
>>> > >              } 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();
>>> > >                  } else {
>>> > >                      if (Hyperv){
>>> > >                          throw new CloudRuntimeException("4.2.0 HyperV
>>> > > SystemVm template not found. Cannot upgrade system Vms");
>>> > >                      } else {
>>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm template
>>> > >   not
>>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>>> > >                      }
>>> > >                  }
>>> > >              } 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();
>>> > >                  } 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 {
>>> > >              try {
>>> > >                  if (rs != null) {
>>> > >                      rs.close();
>>> > >                  }
>>> > >
>>> > >                  if (pstmt != null) {
>>> > >                      pstmt.close();
>>> > >                  }
>>> > >              } catch (SQLException e) {
>>> > >              }
>>> > >          }
>>> > >          pstmt = null;
>>> > >          try {
>>> > > -            sql = conn.prepareStatement("update vm_template set
>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>>> > > -            sql.executeUpdate();
>>> > >              pstmt = conn.prepareStatement("update vm_template set
>>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>>> > >              pstmt.executeUpdate();
>>> > >          } catch (SQLException e) {
>>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>>> > > template data store uuid: "   e.toString());
>>> > >          } finally {
>>> > > -            if (sql != null) {
>>> > >              if (pstmt != null) {
>>> > >                  try {
>>> > > -                    sql.close();
>>> > >                      pstmt.close();
>>> > >                  } catch (SQLException e) {
>>> > >                  }
>>> > >              }
>>> > >
>>> > >
>>>
>>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Wei ZHOU <us...@gmail.com>.
In my point view, we ask users register new template in the upgrade
instruction in release notes. If they do not register, it is their
fault. If they do but upgrade fails, it is our fault.

I admit that it is a good way to change each upgrade process and
remove old templates when we use new template. It is not large work.

-Wei

2013/6/6, Kishan Kavala <Ki...@citrix.com>:
> In the mentioned example, when new template for 4.3 is introduced, we should
> remove template upgrade code in Upgrade41to42. This will make upgrade
> succeed even when systemvm-kvm-4.2 is not in database.
> On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will succeed
> even though the required systemvm-kvm-4.3 is not in database.
>
> So, every time a new system vm template is added, template upgrade from
> previous version should be removed.
>
> ________________________________________
> From: Wei ZHOU [ustcweizhou@gmail.com]
> Sent: Wednesday, June 05, 2013 3:56 PM
> To: dev@cloudstack.apache.org
> Subject: Re: git commit: updated refs/heads/master to 9fe7846
>
> Kishan,
>
> I know.
>
> If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
> systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
> systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
> The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in the
> Upgrade41to42.
>
> -Wei
>
>
> 2013/6/5 Kishan Kavala <Ki...@citrix.com>
>
>> Wei,
>>  If we use other templates, system Vms may not work. Only 4.2 templates
>> should be used when upgrading to 4.2.
>>
>> > -----Original Message-----
>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>> > Sent: Wednesday, 5 June 2013 3:26 PM
>> > To: dev@cloudstack.apache.org
>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>> >
>> > Kishan,
>> >
>> > What do you think about change some codes to "name like 'systemvm-
>> > xenserver-%' " ?
>> > If we use other templates, the upgrade maybe fail.
>> >
>> > -Wei
>> >
>> >
>> > 2013/6/5 <ki...@apache.org>
>> >
>> > > Updated Branches:
>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>> > >
>> > >
>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>> > > templates
>> > >
>> > >
>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>> > > Commit:
>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>> > > Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>> > > Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>> > >
>> > > Branch: refs/heads/master
>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>> > > Parents: 91b1571
>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>> > > Authored: Mon Jun 3 12:33:58 2013  0530
>> > > Committer: Kishan Kavala <ki...@cloud.com>
>> > > Committed: Wed Jun 5 15:14:04 2013  0530
>> > >
>> > > ----------------------------------------------------------------------
>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>> > >               -
>> > >  1 files changed, 204 insertions( ), 5 deletions(-)
>> > > ----------------------------------------------------------------------
>> > >
>> > >
>> > >
>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>> > >     b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>> > > @@ -112,16  112,215 @@ public class Upgrade410to420 implements
>> > DbUpgrade {
>> > >      }
>> > >
>> > >      private void updateSystemVmTemplates(Connection conn) {
>> > > -           PreparedStatement sql = null;
>> > >
>> > >          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
>> > >              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;
>> > >                      }
>> > >                  }
>> > >              } 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 xenserer 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();
>> > >                  } 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");
>> > >                      }
>> > >                  }
>> > >              } 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();
>> > >                  } 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();
>> > >                  } 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");
>> > >                      }
>> > >                  }
>> > >              } 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();
>> > >                  } else {
>> > >                      if (Hyperv){
>> > >                          throw new CloudRuntimeException("4.2.0 HyperV
>> > > SystemVm template not found. Cannot upgrade system Vms");
>> > >                      } else {
>> > >                          s_logger.warn("4.2.0 Hyperv SystemVm template
>> > >   not
>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>> > >                      }
>> > >                  }
>> > >              } 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();
>> > >                  } 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 {
>> > >              try {
>> > >                  if (rs != null) {
>> > >                      rs.close();
>> > >                  }
>> > >
>> > >                  if (pstmt != null) {
>> > >                      pstmt.close();
>> > >                  }
>> > >              } catch (SQLException e) {
>> > >              }
>> > >          }
>> > >          pstmt = null;
>> > >          try {
>> > > -            sql = conn.prepareStatement("update vm_template set
>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>> > > -            sql.executeUpdate();
>> > >              pstmt = conn.prepareStatement("update vm_template set
>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>> > >              pstmt.executeUpdate();
>> > >          } catch (SQLException e) {
>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>> > > template data store uuid: "   e.toString());
>> > >          } finally {
>> > > -            if (sql != null) {
>> > >              if (pstmt != null) {
>> > >                  try {
>> > > -                    sql.close();
>> > >                      pstmt.close();
>> > >                  } catch (SQLException e) {
>> > >                  }
>> > >              }
>> > >
>> > >
>>
>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Alena Prokharchyk <Al...@citrix.com>.
On 6/5/13 10:50 AM, "Kishan Kavala" <Ki...@citrix.com> wrote:

>In the mentioned example, when new template for 4.3 is introduced, we
>should remove template upgrade code in Upgrade41to42. This will make
>upgrade succeed even when systemvm-kvm-4.2 is not in database.
>On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will
>succeed even though the required systemvm-kvm-4.3 is not in database.
>
>So, every time a new system vm template is added, template upgrade from
>previous version should be removed.


Kishan is right, all the obsolete templates should be removed. But we
should also take into consideration the fact that the template you are
trying to remove, might not exist. Here is the scenario:

Customer 1 wants to upgrade from 3.x to 4.2


The 3.0.x-4.0 upgrade code expects to see 4.0 system template, but as the
final upgrade version of the code is 4.2, its not good to ask people to
predownload 2 templates - 4.0 and 4.2 (and for all hypervisors!) - as 4.0
template is useless when upgrade to 4.2. And with every new release this
number will grow.

What  upgrade code should do instead:
 
1) INSERT IGNORE fake DB records for the templates to vm_template table,
expected by the previous upgrade paths.
2) Expect only the template of the final version to be pre-downloaded
3) In the final upgrade step, upgrade all system vms to the template of
the final version
4) Mark all other system templates as removed in the DB

The only one tricky part - when to execute #1. We might introduce some
pre-req sql script that is called before all other upgrade paths are
executed?

Let me know what you think,

-Alena.

>
>________________________________________
>From: Wei ZHOU [ustcweizhou@gmail.com]
>Sent: Wednesday, June 05, 2013 3:56 PM
>To: dev@cloudstack.apache.org
>Subject: Re: git commit: updated refs/heads/master to 9fe7846
>
>Kishan,
>
>I know.
>
>If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
>systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
>systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
>The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in the
>Upgrade41to42.
>
>-Wei
>
>
>2013/6/5 Kishan Kavala <Ki...@citrix.com>
>
>> Wei,
>>  If we use other templates, system Vms may not work. Only 4.2 templates
>> should be used when upgrading to 4.2.
>>
>> > -----Original Message-----
>> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
>> > Sent: Wednesday, 5 June 2013 3:26 PM
>> > To: dev@cloudstack.apache.org
>> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
>> >
>> > Kishan,
>> >
>> > What do you think about change some codes to "name like 'systemvm-
>> > xenserver-%' " ?
>> > If we use other templates, the upgrade maybe fail.
>> >
>> > -Wei
>> >
>> >
>> > 2013/6/5 <ki...@apache.org>
>> >
>> > > Updated Branches:
>> > >   refs/heads/master 91b15711b -> 9fe7846d7
>> > >
>> > >
>> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
>> > > templates
>> > >
>> > >
>> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
>> > > Commit:
>> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
>> > > Tree: 
>>http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
>> > > Diff: 
>>http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
>> > >
>> > > Branch: refs/heads/master
>> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
>> > > Parents: 91b1571
>> > > Author: Harikrishna Patnala <ha...@citrix.com>
>> > > Authored: Mon Jun 3 12:33:58 2013 +0530
>> > > Committer: Kishan Kavala <ki...@cloud.com>
>> > > Committed: Wed Jun 5 15:14:04 2013 +0530
>> > >
>> > > 
>>----------------------------------------------------------------------
>> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
>> > > ++++++++++++++-
>> > >  1 files changed, 204 insertions(+), 5 deletions(-)
>> > > 
>>----------------------------------------------------------------------
>> > >
>> > >
>> > >
>> > > 
>>http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
>> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>> > > +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
>> > > @@ -112,16 +112,215 @@ public class Upgrade410to420 implements
>> > DbUpgrade {
>> > >      }
>> > >
>> > >      private void updateSystemVmTemplates(Connection conn) {
>> > > -           PreparedStatement sql = null;
>> > > +
>> > > +        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
>> > > +            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;
>> > > +                    }
>> > > +                }
>> > > +            } 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 xenserer 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();
>> > > +                } 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");
>> > > +                    }
>> > > +                }
>> > > +            } 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();
>> > > +                } 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();
>> > > +                } 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");
>> > > +                    }
>> > > +                }
>> > > +            } 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();
>> > > +                } else {
>> > > +                    if (Hyperv){
>> > > +                        throw new CloudRuntimeException("4.2.0
>>HyperV
>> > > SystemVm template not found. Cannot upgrade system Vms");
>> > > +                    } else {
>> > > +                        s_logger.warn("4.2.0 Hyperv SystemVm
>>template
>> > > + not
>> > > found. Hyperv hypervisor is not used, so not failing upgrade");
>> > > +                    }
>> > > +                }
>> > > +            } 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();
>> > > +                } 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 {
>> > > +            try {
>> > > +                if (rs != null) {
>> > > +                    rs.close();
>> > > +                }
>> > > +
>> > > +                if (pstmt != null) {
>> > > +                    pstmt.close();
>> > > +                }
>> > > +            } catch (SQLException e) {
>> > > +            }
>> > > +        }
>> > > +        pstmt = null;
>> > >          try {
>> > > -            sql = conn.prepareStatement("update vm_template set
>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>> > > -            sql.executeUpdate();
>> > > +            pstmt = conn.prepareStatement("update vm_template set
>> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
>> > > +            pstmt.executeUpdate();
>> > >          } catch (SQLException e) {
>> > >              throw new CloudRuntimeException("Failed to upgrade vm
>> > > template data store uuid: " + e.toString());
>> > >          } finally {
>> > > -            if (sql != null) {
>> > > +            if (pstmt != null) {
>> > >                  try {
>> > > -                    sql.close();
>> > > +                    pstmt.close();
>> > >                  } catch (SQLException e) {
>> > >                  }
>> > >              }
>> > >
>> > >
>>
>



RE: git commit: updated refs/heads/master to 9fe7846

Posted by Kishan Kavala <Ki...@citrix.com>.
In the mentioned example, when new template for 4.3 is introduced, we should remove template upgrade code in Upgrade41to42. This will make upgrade succeed even when systemvm-kvm-4.2 is not in database.
On the other hand, if we allow 'systemvm-kvm-%', upgrade to 4.3 will succeed even though the required systemvm-kvm-4.3 is not in database.  

So, every time a new system vm template is added, template upgrade from previous version should be removed.

________________________________________
From: Wei ZHOU [ustcweizhou@gmail.com]
Sent: Wednesday, June 05, 2013 3:56 PM
To: dev@cloudstack.apache.org
Subject: Re: git commit: updated refs/heads/master to 9fe7846

Kishan,

I know.

If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in the
Upgrade41to42.

-Wei


2013/6/5 Kishan Kavala <Ki...@citrix.com>

> Wei,
>  If we use other templates, system Vms may not work. Only 4.2 templates
> should be used when upgrading to 4.2.
>
> > -----Original Message-----
> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
> > Sent: Wednesday, 5 June 2013 3:26 PM
> > To: dev@cloudstack.apache.org
> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
> >
> > Kishan,
> >
> > What do you think about change some codes to "name like 'systemvm-
> > xenserver-%' " ?
> > If we use other templates, the upgrade maybe fail.
> >
> > -Wei
> >
> >
> > 2013/6/5 <ki...@apache.org>
> >
> > > Updated Branches:
> > >   refs/heads/master 91b15711b -> 9fe7846d7
> > >
> > >
> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
> > > templates
> > >
> > >
> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
> > > Commit:
> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
> > > Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
> > > Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
> > >
> > > Branch: refs/heads/master
> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
> > > Parents: 91b1571
> > > Author: Harikrishna Patnala <ha...@citrix.com>
> > > Authored: Mon Jun 3 12:33:58 2013 +0530
> > > Committer: Kishan Kavala <ki...@cloud.com>
> > > Committed: Wed Jun 5 15:14:04 2013 +0530
> > >
> > > ----------------------------------------------------------------------
> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
> > > ++++++++++++++-
> > >  1 files changed, 204 insertions(+), 5 deletions(-)
> > > ----------------------------------------------------------------------
> > >
> > >
> > >
> > > http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > > +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > > @@ -112,16 +112,215 @@ public class Upgrade410to420 implements
> > DbUpgrade {
> > >      }
> > >
> > >      private void updateSystemVmTemplates(Connection conn) {
> > > -           PreparedStatement sql = null;
> > > +
> > > +        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
> > > +            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;
> > > +                    }
> > > +                }
> > > +            } 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 xenserer 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();
> > > +                } 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");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } 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();
> > > +                } 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");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } else {
> > > +                    if (Hyperv){
> > > +                        throw new CloudRuntimeException("4.2.0 HyperV
> > > SystemVm template not found. Cannot upgrade system Vms");
> > > +                    } else {
> > > +                        s_logger.warn("4.2.0 Hyperv SystemVm template
> > > + not
> > > found. Hyperv hypervisor is not used, so not failing upgrade");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } 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 {
> > > +            try {
> > > +                if (rs != null) {
> > > +                    rs.close();
> > > +                }
> > > +
> > > +                if (pstmt != null) {
> > > +                    pstmt.close();
> > > +                }
> > > +            } catch (SQLException e) {
> > > +            }
> > > +        }
> > > +        pstmt = null;
> > >          try {
> > > -            sql = conn.prepareStatement("update vm_template set
> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > > -            sql.executeUpdate();
> > > +            pstmt = conn.prepareStatement("update vm_template set
> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > > +            pstmt.executeUpdate();
> > >          } catch (SQLException e) {
> > >              throw new CloudRuntimeException("Failed to upgrade vm
> > > template data store uuid: " + e.toString());
> > >          } finally {
> > > -            if (sql != null) {
> > > +            if (pstmt != null) {
> > >                  try {
> > > -                    sql.close();
> > > +                    pstmt.close();
> > >                  } catch (SQLException e) {
> > >                  }
> > >              }
> > >
> > >
>

Re: git commit: updated refs/heads/master to 9fe7846

Posted by Wei ZHOU <us...@gmail.com>.
Kishan,

I know.

If we upgrade from 4.1 to 4.3 ( assume the systemvm template is
systemvm-kvm-4.3). We need to add systemvm-kvm-4.3 instead of
systemvm-kvm-4.2. Maybe systemvm-kvm-4.2 is not in database.
The upgrade includes Upgrade41to42 and Upgrade42to43. It will fail in the
Upgrade41to42.

-Wei


2013/6/5 Kishan Kavala <Ki...@citrix.com>

> Wei,
>  If we use other templates, system Vms may not work. Only 4.2 templates
> should be used when upgrading to 4.2.
>
> > -----Original Message-----
> > From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
> > Sent: Wednesday, 5 June 2013 3:26 PM
> > To: dev@cloudstack.apache.org
> > Subject: Re: git commit: updated refs/heads/master to 9fe7846
> >
> > Kishan,
> >
> > What do you think about change some codes to "name like 'systemvm-
> > xenserver-%' " ?
> > If we use other templates, the upgrade maybe fail.
> >
> > -Wei
> >
> >
> > 2013/6/5 <ki...@apache.org>
> >
> > > Updated Branches:
> > >   refs/heads/master 91b15711b -> 9fe7846d7
> > >
> > >
> > > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
> > > templates
> > >
> > >
> > > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
> > > Commit:
> > > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
> > > Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
> > > Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
> > >
> > > Branch: refs/heads/master
> > > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
> > > Parents: 91b1571
> > > Author: Harikrishna Patnala <ha...@citrix.com>
> > > Authored: Mon Jun 3 12:33:58 2013 +0530
> > > Committer: Kishan Kavala <ki...@cloud.com>
> > > Committed: Wed Jun 5 15:14:04 2013 +0530
> > >
> > > ----------------------------------------------------------------------
> > >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
> > > ++++++++++++++-
> > >  1 files changed, 204 insertions(+), 5 deletions(-)
> > > ----------------------------------------------------------------------
> > >
> > >
> > >
> > > http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
> > > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > > +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > > @@ -112,16 +112,215 @@ public class Upgrade410to420 implements
> > DbUpgrade {
> > >      }
> > >
> > >      private void updateSystemVmTemplates(Connection conn) {
> > > -           PreparedStatement sql = null;
> > > +
> > > +        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
> > > +            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;
> > > +                    }
> > > +                }
> > > +            } 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 xenserer 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();
> > > +                } 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");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } 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();
> > > +                } 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");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } else {
> > > +                    if (Hyperv){
> > > +                        throw new CloudRuntimeException("4.2.0 HyperV
> > > SystemVm template not found. Cannot upgrade system Vms");
> > > +                    } else {
> > > +                        s_logger.warn("4.2.0 Hyperv SystemVm template
> > > + not
> > > found. Hyperv hypervisor is not used, so not failing upgrade");
> > > +                    }
> > > +                }
> > > +            } 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();
> > > +                } 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 {
> > > +            try {
> > > +                if (rs != null) {
> > > +                    rs.close();
> > > +                }
> > > +
> > > +                if (pstmt != null) {
> > > +                    pstmt.close();
> > > +                }
> > > +            } catch (SQLException e) {
> > > +            }
> > > +        }
> > > +        pstmt = null;
> > >          try {
> > > -            sql = conn.prepareStatement("update vm_template set
> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > > -            sql.executeUpdate();
> > > +            pstmt = conn.prepareStatement("update vm_template set
> > > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > > +            pstmt.executeUpdate();
> > >          } catch (SQLException e) {
> > >              throw new CloudRuntimeException("Failed to upgrade vm
> > > template data store uuid: " + e.toString());
> > >          } finally {
> > > -            if (sql != null) {
> > > +            if (pstmt != null) {
> > >                  try {
> > > -                    sql.close();
> > > +                    pstmt.close();
> > >                  } catch (SQLException e) {
> > >                  }
> > >              }
> > >
> > >
>

RE: git commit: updated refs/heads/master to 9fe7846

Posted by Kishan Kavala <Ki...@citrix.com>.
Wei,
 If we use other templates, system Vms may not work. Only 4.2 templates should be used when upgrading to 4.2.

> -----Original Message-----
> From: Wei ZHOU [mailto:ustcweizhou@gmail.com]
> Sent: Wednesday, 5 June 2013 3:26 PM
> To: dev@cloudstack.apache.org
> Subject: Re: git commit: updated refs/heads/master to 9fe7846
> 
> Kishan,
> 
> What do you think about change some codes to "name like 'systemvm-
> xenserver-%' " ?
> If we use other templates, the upgrade maybe fail.
> 
> -Wei
> 
> 
> 2013/6/5 <ki...@apache.org>
> 
> > Updated Branches:
> >   refs/heads/master 91b15711b -> 9fe7846d7
> >
> >
> > CLOUDSTACK-2728: 41-42 DB upgrade: add step to upgrade system
> > templates
> >
> >
> > Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
> > Commit:
> > http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9fe7846d
> > Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9fe7846d
> > Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9fe7846d
> >
> > Branch: refs/heads/master
> > Commit: 9fe7846d72e401720e1dcbce52d021e2646429f1
> > Parents: 91b1571
> > Author: Harikrishna Patnala <ha...@citrix.com>
> > Authored: Mon Jun 3 12:33:58 2013 +0530
> > Committer: Kishan Kavala <ki...@cloud.com>
> > Committed: Wed Jun 5 15:14:04 2013 +0530
> >
> > ----------------------------------------------------------------------
> >  .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  209
> > ++++++++++++++-
> >  1 files changed, 204 insertions(+), 5 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> > http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9fe7846d/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 1584973..955ea56 100644
> > --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
> > @@ -112,16 +112,215 @@ public class Upgrade410to420 implements
> DbUpgrade {
> >      }
> >
> >      private void updateSystemVmTemplates(Connection conn) {
> > -           PreparedStatement sql = null;
> > +
> > +        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
> > +            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;
> > +                    }
> > +                }
> > +            } 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 xenserer 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();
> > +                } 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");
> > +                    }
> > +                }
> > +            } 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();
> > +                } 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();
> > +                } 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");
> > +                    }
> > +                }
> > +            } 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();
> > +                } else {
> > +                    if (Hyperv){
> > +                        throw new CloudRuntimeException("4.2.0 HyperV
> > SystemVm template not found. Cannot upgrade system Vms");
> > +                    } else {
> > +                        s_logger.warn("4.2.0 Hyperv SystemVm template
> > + not
> > found. Hyperv hypervisor is not used, so not failing upgrade");
> > +                    }
> > +                }
> > +            } 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();
> > +                } 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 {
> > +            try {
> > +                if (rs != null) {
> > +                    rs.close();
> > +                }
> > +
> > +                if (pstmt != null) {
> > +                    pstmt.close();
> > +                }
> > +            } catch (SQLException e) {
> > +            }
> > +        }
> > +        pstmt = null;
> >          try {
> > -            sql = conn.prepareStatement("update vm_template set
> > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > -            sql.executeUpdate();
> > +            pstmt = conn.prepareStatement("update vm_template set
> > image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
> > +            pstmt.executeUpdate();
> >          } catch (SQLException e) {
> >              throw new CloudRuntimeException("Failed to upgrade vm
> > template data store uuid: " + e.toString());
> >          } finally {
> > -            if (sql != null) {
> > +            if (pstmt != null) {
> >                  try {
> > -                    sql.close();
> > +                    pstmt.close();
> >                  } catch (SQLException e) {
> >                  }
> >              }
> >
> >