You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by wilderrodrigues <gi...@git.apache.org> on 2015/11/09 15:34:56 UTC

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

GitHub user wilderrodrigues opened a pull request:

    https://github.com/apache/cloudstack/pull/1050

    CLOUDSTACK-9046 - Fix upgrade path from 4.4 and 4.5 to 4.6

    This PR fixes the upgrade path from 4.4.x/4.5.x to 4.6.0. We introduced the logic to update the database with the correct information about the SystemVMs.
    
    We tested this PR with by doing an upgrade from 4.4.4 to 4.6.0 and it works as expected.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ekholabs/cloudstack fix/upgrade_path-CLOUDSTACK-9046

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cloudstack/pull/1050.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1050
    
----
commit 4b503b45821976ada42a4f6cdd1894caa8794505
Author: Wilder Rodrigues <wr...@schubergphilis.com>
Date:   2015-11-09T09:06:19Z

    CLOUDSTACK-9046 - Add SystemVM upgrade from 4.5 to 4.6 in the Upgrade452to460.java file

commit 72e79bcaa6eacc0041694120f7ea53792dc68975
Author: Wilder Rodrigues <wr...@schubergphilis.com>
Date:   2015-11-09T13:38:17Z

    CLOUDSTACK-9046 - Add new ACS systemVMs website
    
       - Also change the URl in the SQL file.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281448
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    --- End diff --
    
    this one can go outside the for loop as well


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44282237
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    +                        templ_type_pstmt.setLong(1, templateId);
    +                        templ_type_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
    +                    }
    +                    // update template ID of system Vms
    +                    try (PreparedStatement update_templ_id_pstmt = conn
    +                            .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) {
    +                        update_templ_id_pstmt.setLong(1, templateId);
    +                        update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
    +                        update_templ_id_pstmt.executeUpdate();
    +                    } catch (final Exception e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
    +                                + ": " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
    +                                + templateId, e);
    +                    }
    +
    +                    // Change value of global configuration parameter
    +                    // router.template.* for the corresponding hypervisor
    +                    try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
    --- End diff --
    
    in a outermost try (byond any looping..?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by wilderrodrigues <gi...@git.apache.org>.
Github user wilderrodrigues commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281769
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    --- End diff --
    
    Same as commented above. In addition, if I change the code I will have the execute the whole upgrade procedure again.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281293
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    --- End diff --
    
    no biggy but this could go outside of the for loop


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281960
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    +                        templ_type_pstmt.setLong(1, templateId);
    +                        templ_type_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
    +                    }
    +                    // update template ID of system Vms
    +                    try (PreparedStatement update_templ_id_pstmt = conn
    +                            .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) {
    +                        update_templ_id_pstmt.setLong(1, templateId);
    +                        update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
    +                        update_templ_id_pstmt.executeUpdate();
    +                    } catch (final Exception e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
    +                                + ": " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
    +                                + templateId, e);
    +                    }
    +
    +                    // Change value of global configuration parameter
    +                    // router.template.* for the corresponding hypervisor
    +                    try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
    +                        update_pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                        update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
    +                        update_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to "
    +                                + hypervisorAndTemplateName.getValue() + ": " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting "
    +                                + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
    +                    }
    +
    +                    // Change value of global configuration parameter
    +                    // minreq.sysvmtemplate.version for the ACS version
    +                    try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
    +                        update_pstmt.setString(1, getUpgradedVersion());
    +                        update_pstmt.setString(2, "minreq.sysvmtemplate.version");
    +                        update_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0: " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0", e);
    +                    }
    +                } else {
    +                    if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) {
    +                        throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
    +                    } else {
    +                        s_logger.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey()
    +                                + " hypervisor is not used, so not failing upgrade");
    +                        // Update the latest template URLs for corresponding
    +                        // hypervisor
    +                        try (PreparedStatement update_templ_url_pstmt = conn
    --- End diff --
    
    declaring prepared statements can go in the outermost block.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/1050#issuecomment-155082167
  
    LGTM, I worked with @wilderrodrigues to debug the issues over the weekend and today. Together we made it work and this PR is the result. I was there when we tested it and have seen it working.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44282316
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    +                        templ_type_pstmt.setLong(1, templateId);
    +                        templ_type_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
    +                    }
    +                    // update template ID of system Vms
    +                    try (PreparedStatement update_templ_id_pstmt = conn
    +                            .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) {
    +                        update_templ_id_pstmt.setLong(1, templateId);
    +                        update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
    +                        update_templ_id_pstmt.executeUpdate();
    +                    } catch (final Exception e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
    +                                + ": " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
    +                                + templateId, e);
    +                    }
    +
    +                    // Change value of global configuration parameter
    +                    // router.template.* for the corresponding hypervisor
    +                    try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
    +                        update_pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                        update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
    +                        update_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to "
    +                                + hypervisorAndTemplateName.getValue() + ": " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting "
    +                                + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
    +                    }
    +
    +                    // Change value of global configuration parameter
    +                    // minreq.sysvmtemplate.version for the ACS version
    +                    try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
    --- End diff --
    
    I know this is c&p and not important but .... a prepared statement should go as prepared...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by borisroman <gi...@git.apache.org>.
Github user borisroman commented on the pull request:

    https://github.com/apache/cloudstack/pull/1050#issuecomment-155116207
  
    LGTM :+1: 
    
    Deployed 4.5.2 from DEB packages on Ubuntu 14.04. Deployed a zone, deployed the systemvm's and spawned a uservm.
    
    Upgraded to 4.6 with packages build from this branch. Upgrade went ok! :+1: 
    
    ```
    INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) DB version = 4.5.2 Code Version = 4.6.0
    INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) Database upgrade must be performed from 4.5.2 to 4.6.0
    INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) Cleaning upgrades because all management server are now at the same version
    INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) Cleanup upgrade Upgrade452to460 to upgrade from 4.5.2-4.6.0 to 4.6.0
    INFO  [o.a.c.s.l.CloudStackExtendedLifeCycle] (main:null) Configuring CloudStack Components
    INFO  [o.a.c.s.l.CloudStackExtendedLifeCycle] (main:null) Done Configuring CloudStack Components
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on the pull request:

    https://github.com/apache/cloudstack/pull/1050#issuecomment-155084636
  
    some unimportant nitpicking but otherwise lgtm (code inspection only)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by wilderrodrigues <gi...@git.apache.org>.
Github user wilderrodrigues commented on the pull request:

    https://github.com/apache/cloudstack/pull/1050#issuecomment-155080182
  
    Ping @remibergsma @borisroman @DaanHoogland @wido 
    
    Tests were executed as described below:
    
    * Deploy 4.4.4
      - KVM Host
      - Management Server
      - 2 VMs running on Isolated Networks + 2Pub IPs + FW/PF
      - 2 VPCs  with 1 tier each + 1 VM per tier + ACL + PF
      - SSH into the 4 VMs to testify it was all fine with 4.4.4
    
    * Upgrade steps
      - Register SysteVM 4.5 and 4.6
        - Needed because we were upgrading from 4.4.4
      - Stop/Update the KVM agent
      - Stop/Update the Management Server
      - Check the Routers say "Requires Upgrade = YES"
      - SSH into SSVM/CPVM and check /etc/cloudstack-release file. It should say 4.4.1
      - Destroy SSVM/CPVM
      - Check again the /etc/cloudstack-release file. It should say 4.6.0
      - Reboot the Virtual Routers
      - Check the /etc/cloudstack-release. It should say 4.6.0
      - SSH into the VMs via the public IPs. It should be possible


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by wilderrodrigues <gi...@git.apache.org>.
Github user wilderrodrigues commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281534
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    --- End diff --
    
    Code is executed only once. I did not look, just cced the stuff from 4.4 to 4.5 and did some changes. Not really worthy changing and force pushing it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281597
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
    +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
    +                put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
    +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
    +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
    +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
    +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
    +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
    +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
    +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
    +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
    +                put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
    +                put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
    +                put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
    +                put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
    +            }
    +        };
    +
    +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
    +            {
    +                put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
    +                put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
    +                put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
    +                put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
    +                put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
    +            }
    +        };
    +
    +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
    +            s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
    +            try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
    +                // Get 4.6.0 system Vm template Id for corresponding hypervisor
    +                long templateId = -1;
    +                pstmt.setString(1, hypervisorAndTemplateName.getValue());
    +                try (ResultSet rs = pstmt.executeQuery()) {
    +                    if (rs.next()) {
    +                        templateId = rs.getLong(1);
    +                    }
    +                } catch (final SQLException e) {
    +                    s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
    +                    throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
    +                }
    +
    +                // change template type to SYSTEM
    +                if (templateId != -1) {
    +                    try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
    +                        templ_type_pstmt.setLong(1, templateId);
    +                        templ_type_pstmt.executeUpdate();
    +                    } catch (final SQLException e) {
    +                        s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
    +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
    +                    }
    +                    // update template ID of system Vms
    +                    try (PreparedStatement update_templ_id_pstmt = conn
    +                            .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) {
    --- End diff --
    
    can go outside as well


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cloudstack/pull/1050


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by wilderrodrigues <gi...@git.apache.org>.
Github user wilderrodrigues commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44282419
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    --- End diff --
    
    @DaanHoogland: do you get that this code was copied from the stuff written for 4.4/4.5? Sorry, but I won't change it for the following reasons:
    
    1. The PR was already tested and changes will force me to re-test it;
    2. This is code executed once - for upgrades only;
    3. This was copied from a code pushed in Commit ID 3cb78fc74221e521c205b21590e6d8a4a24e6b91;
    4. After working for several weekends, I don't have the energy to do it now.
    
    If you think it's a blocker, you can fork, change, test and push to the PR.
    
    Cheers,
    Wilder


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: CLOUDSTACK-9046 - Fix upgrade path from 4...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1050#discussion_r44281795
  
    --- Diff: engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java ---
    @@ -165,4 +171,173 @@ private void addIndexForVMInstance(Connection conn) {
             return new File[] { new File(script) };
         }
     
    +    @SuppressWarnings("serial")
    +    private void updateSystemVmTemplates(final Connection conn) {
    +        s_logger.debug("Updating System Vm template IDs");
    +        // Get all hypervisors in use
    +        final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
    +        try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
    +            while (rs.next()) {
    +                switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
    +                case XenServer:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
    +                    break;
    +                case KVM:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
    +                    break;
    +                case VMware:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
    +                    break;
    +                case Hyperv:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
    +                    break;
    +                case LXC:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
    +                    break;
    +                case Ovm3:
    +                    hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
    +                    break;
    +                default: // no action on cases Any, BareMetal, None, Ovm,
    +                    // Parralels, Simulator and VirtualBox:
    +                    break;
    +                }
    +            }
    +        } catch (final SQLException e) {
    +            s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
    +            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
    +        }
    +
    +        final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
    --- End diff --
    
    naming convention: var starting with capital


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---