Skip to content

Commit 40e49a6

Browse files
committed
Merge pull request #1982 from Accelerite/CLOUDSTACK-9807
CLOUDSTACK-9807/CLOUDSTACK-9808 - Added upgrade changes for 4.10 system vm templateRemoved systemvm template upgrade code in 4.6 upgrade. Added 4.10 system vm template upgrade changes with new urls and md5sum Manual testing results: Updated min req version: mysql> select name, value from configuration where name = 'minreq.sysvmtemplate.version'; +------------------------------+----------+ | name | value | +------------------------------+----------+ | minreq.sysvmtemplate.version | 4.10.0.0 | +------------------------------+----------+ 1 row in set (0.00 sec) Update template for KVM: mysql> select * from vm_template where name = 'systemvm-kvm-4.10'\G *************************** 1. row *************************** id: 201 unique_name: 201-2-badc363a-507d-3802-942f-205d35c3b575 name: systemvm-kvm-4.10 uuid: 3526258d-d9a4-4c3d-8f15-3137eb5d7ab8 public: 0 featured: 0 type: SYSTEM hvm: 1 bits: 64 url: http://packages.shapeblue.com/systemvmtemplate/4.10/systemvm64template-4.10-kvm.qcow2.bz2 format: QCOW2 created: 2017-03-02 11:35:06 removed: NULL account_id: 2 checksum: NULL display_text: systemvm-kvm-4.10 enable_password: 0 enable_sshkey: 0 guest_os_id: 184 bootable: 1 prepopulate: 0 cross_zones: 1 extractable: 0 hypervisor_type: KVM source_template_id: NULL template_tag: NULL sort_key: 0 size: 5242880 state: Active update_count: 0 updated: NULL dynamically_scalable: 0 1 row in set (0.00 sec) * pr/1982: Bug-ID: CLOUDSTACK-9807: 4.10.0.0 systemvm template upgrade. Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
2 parents 61ce75e + 1ed7e3d commit 40e49a6

2 files changed

Lines changed: 166 additions & 176 deletions

File tree

engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
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.List;
29-
import java.util.Map;
30-
import java.util.Set;
3127

3228
import org.apache.log4j.Logger;
3329

34-
import com.cloud.hypervisor.Hypervisor;
3530
import com.cloud.utils.exception.CloudRuntimeException;
3631
import com.cloud.utils.script.Script;
3732

@@ -65,7 +60,6 @@ public File[] getPrepareScripts() {
6560

6661
@Override
6762
public void performDataMigration(final Connection conn) {
68-
updateSystemVmTemplates(conn);
6963
updateVMInstanceUserId(conn);
7064
addIndexForVMInstance(conn);
7165
}
@@ -170,174 +164,4 @@ public File[] getCleanupScripts() {
170164

171165
return new File[] { new File(script) };
172166
}
173-
174-
@SuppressWarnings("serial")
175-
private void updateSystemVmTemplates(final Connection conn) {
176-
s_logger.debug("Updating System Vm template IDs");
177-
// Get all hypervisors in use
178-
final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
179-
try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {
180-
while (rs.next()) {
181-
switch (Hypervisor.HypervisorType.getType(rs.getString(1))) {
182-
case XenServer:
183-
hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer);
184-
break;
185-
case KVM:
186-
hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM);
187-
break;
188-
case VMware:
189-
hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware);
190-
break;
191-
case Hyperv:
192-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv);
193-
break;
194-
case LXC:
195-
hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC);
196-
break;
197-
case Ovm3:
198-
hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3);
199-
break;
200-
default: // no action on cases Any, BareMetal, None, Ovm,
201-
// Parralels, Simulator and VirtualBox:
202-
break;
203-
}
204-
}
205-
} catch (final SQLException e) {
206-
s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage());
207-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e);
208-
}
209-
210-
final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() {
211-
{
212-
put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6");
213-
put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6");
214-
put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6");
215-
put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6");
216-
put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6");
217-
put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6");
218-
}
219-
};
220-
221-
final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() {
222-
{
223-
put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver");
224-
put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
225-
put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
226-
put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
227-
put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
228-
put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
229-
}
230-
};
231-
232-
final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() {
233-
{
234-
put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2");
235-
put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova");
236-
put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
237-
put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2");
238-
put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip");
239-
put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2");
240-
}
241-
};
242-
243-
final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() {
244-
{
245-
put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460");
246-
put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc");
247-
put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
248-
put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d");
249-
put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013");
250-
put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f");
251-
}
252-
};
253-
254-
for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
255-
s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
256-
try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
257-
// Get 4.6.0 system Vm template Id for corresponding hypervisor
258-
long templateId = -1;
259-
pstmt.setString(1, hypervisorAndTemplateName.getValue());
260-
try (ResultSet rs = pstmt.executeQuery()) {
261-
if (rs.next()) {
262-
templateId = rs.getLong(1);
263-
}
264-
} catch (final SQLException e) {
265-
s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
266-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
267-
}
268-
269-
// change template type to SYSTEM
270-
if (templateId != -1) {
271-
try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) {
272-
templ_type_pstmt.setLong(1, templateId);
273-
templ_type_pstmt.executeUpdate();
274-
} catch (final SQLException e) {
275-
s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage());
276-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
277-
}
278-
// update template ID of system Vms
279-
try (PreparedStatement update_templ_id_pstmt = conn
280-
.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) {
281-
update_templ_id_pstmt.setLong(1, templateId);
282-
update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString());
283-
update_templ_id_pstmt.executeUpdate();
284-
} catch (final Exception e) {
285-
s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId
286-
+ ": " + e.getMessage());
287-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to "
288-
+ templateId, e);
289-
}
290-
291-
// Change value of global configuration parameter
292-
// router.template.* for the corresponding hypervisor
293-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
294-
update_pstmt.setString(1, hypervisorAndTemplateName.getValue());
295-
update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()));
296-
update_pstmt.executeUpdate();
297-
} catch (final SQLException e) {
298-
s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to "
299-
+ hypervisorAndTemplateName.getValue() + ": " + e.getMessage());
300-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting "
301-
+ routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
302-
}
303-
304-
// Change value of global configuration parameter
305-
// minreq.sysvmtemplate.version for the ACS version
306-
try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
307-
update_pstmt.setString(1, getUpgradedVersion());
308-
update_pstmt.setString(2, "minreq.sysvmtemplate.version");
309-
update_pstmt.executeUpdate();
310-
} catch (final SQLException e) {
311-
s_logger.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0: " + e.getMessage());
312-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0", e);
313-
}
314-
} else {
315-
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) {
316-
throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
317-
} else {
318-
s_logger.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey()
319-
+ " hypervisor is not used, so not failing upgrade");
320-
// Update the latest template URLs for corresponding
321-
// hypervisor
322-
try (PreparedStatement update_templ_url_pstmt = conn
323-
.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) {
324-
update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey()));
325-
update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
326-
update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString());
327-
update_templ_url_pstmt.executeUpdate();
328-
} catch (final SQLException e) {
329-
s_logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
330-
+ hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage());
331-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type "
332-
+ hypervisorAndTemplateName.getKey().toString(), e);
333-
}
334-
}
335-
}
336-
} catch (final SQLException e) {
337-
s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage());
338-
throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
339-
}
340-
}
341-
s_logger.debug("Updating System Vm Template IDs Complete");
342-
}
343167
}

0 commit comments

Comments
 (0)