Skip to content

Commit 6c346df

Browse files
committed
Merge remote-tracking branch 'origin/4.15'
Fix db upgrade path conflict, add 4.15.1.0->4.16.0.0 for master, bump systemvmtemplate version to 4.16. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 4aa7a96 + 8a9ae6f commit 6c346df

File tree

11 files changed

+415
-176
lines changed

11 files changed

+415
-176
lines changed

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
import com.cloud.upgrade.dao.Upgrade41300to41310;
7070
import com.cloud.upgrade.dao.Upgrade41310to41400;
7171
import com.cloud.upgrade.dao.Upgrade41400to41500;
72+
import com.cloud.upgrade.dao.Upgrade41500to41510;
73+
import com.cloud.upgrade.dao.Upgrade41510to41600;
7274
import com.cloud.upgrade.dao.Upgrade420to421;
7375
import com.cloud.upgrade.dao.Upgrade421to430;
7476
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -193,6 +195,9 @@ public DatabaseUpgradeChecker() {
193195
.next("4.13.0.0", new Upgrade41300to41310())
194196
.next("4.13.1.0", new Upgrade41310to41400())
195197
.next("4.14.0.0", new Upgrade41400to41500())
198+
.next("4.14.1.0", new Upgrade41400to41500())
199+
.next("4.15.0.0", new Upgrade41500to41510())
200+
.next("4.15.1.0", new Upgrade41510to41600())
196201
.build();
197202
}
198203

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323
import java.sql.ResultSet;
2424
import java.sql.SQLException;
2525
import java.util.ArrayList;
26-
import java.util.HashMap;
27-
import java.util.HashSet;
2826
import java.util.LinkedHashMap;
2927
import java.util.List;
3028
import java.util.Map;
31-
import java.util.Set;
3229

3330
import org.apache.log4j.Logger;
3431

35-
import com.cloud.hypervisor.Hypervisor;
3632
import com.cloud.utils.exception.CloudRuntimeException;
3733

3834
public class Upgrade41400to41500 implements DbUpgrade {
@@ -67,178 +63,9 @@ public InputStream[] getPrepareScripts() {
6763

6864
@Override
6965
public void performDataMigration(Connection conn) {
70-
updateSystemVmTemplates(conn);
7166
addRolePermissionsForNewReadOnlyAndSupportRoles(conn);
7267
}
7368

74-
@SuppressWarnings("serial")
75-
private void updateSystemVmTemplates(final Connection conn) {
76-
LOG.debug("Updating System Vm template IDs");
77-
final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
78-
try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
79-
while (rs.next()) {
80-
switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
81-
case XenServer:
82-
hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
83-
break;
84-
case KVM:
85-
hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
86-
break;
87-
case VMware:
88-
hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
89-
break;
90-
case Hyperv:
91-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
92-
break;
93-
case LXC:
94-
hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
95-
break;
96-
case Ovm3:
97-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
98-
break;
99-
default:
100-
break;
101-
}
102-
}
103-
} catch (final SQLException e) {
104-
LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage());
105-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
106-
}
107-
108-
final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
109-
{
110-
put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.0");
111-
put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.0");
112-
put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.0");
113-
put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.0");
114-
put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.0");
115-
put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.0");
116-
}
117-
};
118-
119-
final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
120-
{
121-
put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
122-
put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
123-
put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
124-
put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
125-
put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
126-
put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
127-
}
128-
};
129-
130-
final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
131-
{
132-
put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2");
133-
put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-vmware.ova");
134-
put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-xen.vhd.bz2");
135-
put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-hyperv.vhd.zip");
136-
put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2");
137-
put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.0-ovm.raw.bz2");
138-
}
139-
};
140-
141-
final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
142-
{
143-
put(Hypervisor.HypervisorType.KVM, "81b3e48bb934784a13555a43c5ef5ffb");
144-
put(Hypervisor.HypervisorType.XenServer, "1b178a5dbdbe090555515340144c6017");
145-
put(Hypervisor.HypervisorType.VMware, "e6a88e518c57d6f36c096c4204c3417f");
146-
put(Hypervisor.HypervisorType.Hyperv, "5c94da45337cf3e1910dcbe084d4b9ad");
147-
put(Hypervisor.HypervisorType.LXC, "81b3e48bb934784a13555a43c5ef5ffb");
148-
put(Hypervisor.HypervisorType.Ovm3, "875c5c65455fc06c4a012394410db375");
149-
}
150-
};
151-
152-
for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
153-
LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
154-
try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
155-
// Get systemvm template id for corresponding hypervisor
156-
long templateId = -1;
157-
pstmt.setString(1, hypervisorAndTemplateName.getValue());
158-
try (ResultSet rs = pstmt.executeQuery()) {
159-
if (rs.next()) {
160-
templateId = rs.getLong(1);
161-
}
162-
} catch (final SQLException e) {
163-
LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage());
164-
throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e);
165-
}
166-
167-
// change template type to SYSTEM
168-
if (templateId != -1) {
169-
try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
170-
templ_type_pstmt.setLong(1, templateId);
171-
templ_type_pstmt.executeUpdate();
172-
} catch (final SQLException e) {
173-
LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
174-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
175-
}
176-
// update template ID of system Vms
177-
try (PreparedStatement update_templ_id_pstmt = conn
178-
.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ? and removed is NULL");) {
179-
update_templ_id_pstmt.setLong(1, templateId);
180-
update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
181-
update_templ_id_pstmt.executeUpdate();
182-
} catch (final Exception e) {
183-
LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
184-
+ ": " + e.getMessage());
185-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
186-
+ templateId, e);
187-
}
188-
189-
// Change value of global configuration parameter
190-
// router.template.* for the corresponding hypervisor
191-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
192-
update_pstmt.setString(1, hypervisorAndTemplateName.getValue());
193-
update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
194-
update_pstmt.executeUpdate();
195-
} catch (final SQLException e) {
196-
LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to "
197-
+ hypervisorAndTemplateName.getValue() + ": " + e.getMessage());
198-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting "
199-
+ routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
200-
}
201-
202-
// Change value of global configuration parameter
203-
// minreq.sysvmtemplate.version for the ACS version
204-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
205-
update_pstmt.setString(1, "4.15.0");
206-
update_pstmt.setString(2, "minreq.sysvmtemplate.version");
207-
update_pstmt.executeUpdate();
208-
} catch (final SQLException e) {
209-
LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0: " + e.getMessage());
210-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.0", e);
211-
}
212-
} else {
213-
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) {
214-
throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
215-
} else {
216-
LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey()
217-
+ " hypervisor is not used, so not failing upgrade");
218-
// Update the latest template URLs for corresponding
219-
// hypervisor
220-
try (PreparedStatement update_templ_url_pstmt = conn
221-
.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) {
222-
update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
223-
update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
224-
update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
225-
update_templ_url_pstmt.executeUpdate();
226-
} catch (final SQLException e) {
227-
LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
228-
+ hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage());
229-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
230-
+ hypervisorAndTemplateName.getKey().toString(), e);
231-
}
232-
}
233-
}
234-
} catch (final SQLException e) {
235-
LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
236-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
237-
}
238-
}
239-
LOG.debug("Updating System Vm Template IDs Complete");
240-
}
241-
24269
private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection conn) {
24370
addRolePermissionsForReadOnlyAdmin(conn);
24471
addRolePermissionsForReadOnlyUser(conn);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.upgrade.dao;
19+
20+
import java.io.InputStream;
21+
import java.sql.Connection;
22+
23+
import org.apache.log4j.Logger;
24+
25+
import com.cloud.utils.exception.CloudRuntimeException;
26+
27+
public class Upgrade41500to41510 implements DbUpgrade {
28+
29+
final static Logger LOG = Logger.getLogger(Upgrade41500to41510.class);
30+
31+
@Override
32+
public String[] getUpgradableVersionRange() {
33+
return new String[] {"4.15.0.0", "4.15.1.0"};
34+
}
35+
36+
@Override
37+
public String getUpgradedVersion() {
38+
return "4.15.1.0";
39+
}
40+
41+
@Override
42+
public boolean supportsRollingUpgrade() {
43+
return false;
44+
}
45+
46+
@Override
47+
public InputStream[] getPrepareScripts() {
48+
final String scriptFile = "META-INF/db/schema-41500to41510.sql";
49+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
50+
if (script == null) {
51+
throw new CloudRuntimeException("Unable to find " + scriptFile);
52+
}
53+
54+
return new InputStream[] {script};
55+
}
56+
57+
@Override
58+
public void performDataMigration(Connection conn) {
59+
}
60+
61+
@Override
62+
public InputStream[] getCleanupScripts() {
63+
final String scriptFile = "META-INF/db/schema-41500to41510-cleanup.sql";
64+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
65+
if (script == null) {
66+
throw new CloudRuntimeException("Unable to find " + scriptFile);
67+
}
68+
69+
return new InputStream[] {script};
70+
}
71+
}

0 commit comments

Comments
 (0)