rhtyd commented on a change in pull request #2799: systemvmtemplate: new 4.11.2 
template and fixes
URL: https://github.com/apache/cloudstack/pull/2799#discussion_r209717214
 
 

 ##########
 File path: engine/schema/src/com/cloud/upgrade/dao/Upgrade41110to41120.java
 ##########
 @@ -0,0 +1,249 @@
+/*
+ * // 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 Upgrade41110to41120 implements DbUpgrade {
+    final static Logger LOG = Logger.getLogger(Upgrade41110to41120.class);
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[]{"4.11.1.0", "4.11.2.0"};
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "4.11.2.0";
+    }
+
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+
+    @Override
+    public InputStream[] getPrepareScripts() {
+        final String scriptFile = "META-INF/db/schema-41110to41120.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);
+    }
+
+    @SuppressWarnings("serial")
+    private 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.11.2");
+                put(Hypervisor.HypervisorType.VMware, 
"systemvm-vmware-4.11.2");
+                put(Hypervisor.HypervisorType.XenServer, 
"systemvm-xenserver-4.11.2");
+                put(Hypervisor.HypervisorType.Hyperv, 
"systemvm-hyperv-4.11.2");
+                put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.11.2");
+                put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.11.2");
+            }
+        };
+
+        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.11/systemvmtemplate-4.11.2-kvm.qcow2.bz2";);
+                put(Hypervisor.HypervisorType.VMware, 
"https://download.cloudstack.org/systemvm/4.11/systemvmtemplate-4.11.2-vmware.ova";);
+                put(Hypervisor.HypervisorType.XenServer, 
"https://download.cloudstack.org/systemvm/4.11/systemvmtemplate-4.11.2-xen.vhd.bz2";);
+                put(Hypervisor.HypervisorType.Hyperv, 
"https://download.cloudstack.org/systemvm/4.11/systemvmtemplate-4.11.2-hyperv.vhd.zip";);
+                put(Hypervisor.HypervisorType.LXC, 
"https://download.cloudstack.org/systemvm/4.11/systemvmtemplate-4.11.2-kvm.qcow2.bz2";);
+                put(Hypervisor.HypervisorType.Ovm3, 
"https://download.cloudstack.org/systemvm/4.11/systemvmtemplate-4.11.2-ovm.raw.bz2";);
+            }
+        };
+
+        final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new 
HashMap<Hypervisor.HypervisorType, String>() {
+            {
+                put(Hypervisor.HypervisorType.KVM, 
"6019c2ed1a13669dcf334fe380c776b0");
+                put(Hypervisor.HypervisorType.XenServer, 
"f2245e912c856ab610d91f88c362a1f9");
 
 Review comment:
   I'll update the hashes soon.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to