You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2021/02/24 12:09:47 UTC

[cloudstack] branch master updated (3177118 -> 1d8a497)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git.


    from 3177118  Externalize TLS version on Quota's mailing (#4583)
     add 5a3ae15  upgrade: check systemvm template before db changes (#4582)
     add a896760  storage: Secondary storage allow store deletion after successful data migration (#4615)
     add ccbcb08  server: Increase leniency to list templates on secondary stores that have been marked deleted by updating the db (#4713)
     new 1d8a497  Merge remote-tracking branch 'origin/4.15'

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../com/cloud/upgrade/DatabaseUpgradeChecker.java  | 32 ++++++++++++++++++++++
 .../upgrade/dao/DbUpgradeSystemVmTemplate.java}    |  7 +++--
 .../com/cloud/upgrade/dao/Upgrade41510to41600.java |  6 ++--
 .../cloud/api/query/dao/TemplateJoinDaoImpl.java   | 13 ++++++---
 .../cloud/template/HypervisorTemplateAdapter.java  |  4 +--
 5 files changed, 50 insertions(+), 12 deletions(-)
 copy engine/{orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHost.java => schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeSystemVmTemplate.java} (83%)


[cloudstack] 01/01: Merge remote-tracking branch 'origin/4.15'

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 1d8a4978e9136094b929ddd70d99241cf8abac92
Merge: 3177118 ccbcb08
Author: Rohit Yadav <ro...@shapeblue.com>
AuthorDate: Wed Feb 24 17:39:12 2021 +0530

    Merge remote-tracking branch 'origin/4.15'
    
    Signed-off-by: Rohit Yadav <ro...@shapeblue.com>

 .../com/cloud/upgrade/DatabaseUpgradeChecker.java  | 32 ++++++++++++++++++++++
 .../upgrade/dao/DbUpgradeSystemVmTemplate.java     | 25 +++++++++++++++++
 .../com/cloud/upgrade/dao/Upgrade41510to41600.java |  6 ++--
 .../cloud/api/query/dao/TemplateJoinDaoImpl.java   | 13 ++++++---
 .../cloud/template/HypervisorTemplateAdapter.java  |  4 +--
 5 files changed, 71 insertions(+), 9 deletions(-)

diff --cc engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41600.java
index 231d1e9,0000000..358fa57
mode 100644,000000..100644
--- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41600.java
+++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41600.java
@@@ -1,248 -1,0 +1,248 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +
 +package com.cloud.upgrade.dao;
 +
 +import java.io.InputStream;
 +import java.sql.Connection;
 +import java.sql.PreparedStatement;
 +import java.sql.ResultSet;
 +import java.sql.SQLException;
 +import java.util.HashMap;
 +import java.util.HashSet;
 +import java.util.Map;
 +import java.util.Set;
 +
 +import org.apache.log4j.Logger;
 +
 +import com.cloud.hypervisor.Hypervisor;
 +import com.cloud.utils.exception.CloudRuntimeException;
 +
- public class Upgrade41510to41600 implements DbUpgrade {
++public class Upgrade41510to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate {
 +
 +    final static Logger LOG = Logger.getLogger(Upgrade41510to41600.class);
 +
 +    @Override
 +    public String[] getUpgradableVersionRange() {
 +        return new String[] {"4.15.1.0", "4.16.0.0"};
 +    }
 +
 +    @Override
 +    public String getUpgradedVersion() {
 +        return "4.16.0.0";
 +    }
 +
 +    @Override
 +    public boolean supportsRollingUpgrade() {
 +        return false;
 +    }
 +
 +    @Override
 +    public InputStream[] getPrepareScripts() {
 +        final String scriptFile = "META-INF/db/schema-41510to41600.sql";
 +        final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
 +        if (script == null) {
 +            throw new CloudRuntimeException("Unable to find " + scriptFile);
 +        }
 +
 +        return new InputStream[] {script};
 +    }
 +
 +    @Override
 +    public void performDataMigration(Connection conn) {
-         updateSystemVmTemplates(conn);
 +    }
 +
++    @Override
 +    @SuppressWarnings("serial")
-     private void updateSystemVmTemplates(final Connection conn) {
++    public void updateSystemVmTemplates(final Connection conn) {
 +        LOG.debug("Updating System Vm template IDs");
 +        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:
 +                        break;
 +                }
 +            }
 +        } catch (final SQLException e) {
 +            LOG.error("updateSystemVmTemplates: Exception caught 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.KVM, "systemvm-kvm-4.16.0");
 +                put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.16.0");
 +                put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.16.0");
 +                put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.16.0");
 +                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.16.0");
 +                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.16.0");
 +            }
 +        };
 +
 +        final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
 +            {
 +                put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
 +                put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
 +                put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
 +                put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
 +                put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
 +                put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
 +            }
 +        };
 +
 +        final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
 +            {
 +                put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-kvm.qcow2.bz2");
 +                put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-vmware.ova");
 +                put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-xen.vhd.bz2");
 +                put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-hyperv.vhd.zip");
 +                put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-kvm.qcow2.bz2");
 +                put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.16/systemvmtemplate-4.16.0-ovm.raw.bz2");
 +            }
 +        };
 +
 +        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
 +            {
 +                put(Hypervisor.HypervisorType.KVM, "81b3e48bb934784a13555a43c5ef5ffb");
 +                put(Hypervisor.HypervisorType.XenServer, "1b178a5dbdbe090555515340144c6017");
 +                put(Hypervisor.HypervisorType.VMware, "e6a88e518c57d6f36c096c4204c3417f");
 +                put(Hypervisor.HypervisorType.Hyperv, "5c94da45337cf3e1910dcbe084d4b9ad");
 +                put(Hypervisor.HypervisorType.LXC, "81b3e48bb934784a13555a43c5ef5ffb");
 +                put(Hypervisor.HypervisorType.Ovm3, "875c5c65455fc06c4a012394410db375");
 +            }
 +        };
 +
 +        for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
 +            LOG.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 systemvm 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) {
 +                    LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage());
 +                    throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught 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) {
 +                        LOG.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 = ? and removed is NULL");) {
 +                        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) {
 +                        LOG.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) {
 +                        LOG.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, "4.16.0");
 +                        update_pstmt.setString(2, "minreq.sysvmtemplate.version");
 +                        update_pstmt.executeUpdate();
 +                    } catch (final SQLException e) {
 +                        LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.16.0: " + e.getMessage());
 +                        throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.16.0", e);
 +                    }
 +                } else {
 +                    if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) {
 +                        throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
 +                    } else {
 +                        LOG.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
 +                                .prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) {
 +                            update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
 +                            update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
 +                            update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
 +                            update_templ_url_pstmt.executeUpdate();
 +                        } catch (final SQLException e) {
 +                            LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
 +                                    + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage());
 +                            throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
 +                                    + hypervisorAndTemplateName.getKey().toString(), e);
 +                        }
 +                    }
 +                }
 +            } catch (final SQLException e) {
 +                LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
 +                throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
 +            }
 +        }
 +        LOG.debug("Updating System Vm Template IDs Complete");
 +    }
 +
 +    @Override
 +    public InputStream[] getCleanupScripts() {
 +        final String scriptFile = "META-INF/db/schema-41510to41600-cleanup.sql";
 +        final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
 +        if (script == null) {
 +            throw new CloudRuntimeException("Unable to find " + scriptFile);
 +        }
 +
 +        return new InputStream[] {script};
 +    }
 +}