You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) {
246
+
s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms");
247
+
try (PreparedStatementpstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) {
248
+
//Get 4.5.0 system Vm template Id for corresponding hypervisor
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
274
-
thrownewCloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
275
-
} else {
276
-
s_logger.warn("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade");
277
-
// Update the latest template URLs for corresponding hypervisor
278
-
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");
thrownewCloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e);
288
-
}
289
-
}
290
-
s_logger.debug("Updating System Vm Template IDs Complete");
291
-
} finally {
292
-
try {
293
-
if (rs != null) {
294
-
rs.close();
255
+
} catch (SQLExceptione)
256
+
{
257
+
s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: "+e.getMessage());
258
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
295
259
}
296
260
297
-
if (pstmt != null) {
298
-
pstmt.close();
261
+
// change template type to SYSTEM
262
+
if (templateId != -1) {
263
+
try(PreparedStatementtempl_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");)
264
+
{
265
+
templ_type_pstmt.setLong(1, templateId);
266
+
templ_type_pstmt.executeUpdate();
267
+
}
268
+
catch (SQLExceptione)
269
+
{
270
+
s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': "+e.getMessage());
271
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e);
272
+
}
273
+
// update template ID of system Vms
274
+
try(PreparedStatementupdate_templ_id_pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");)
s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + ": "+e.getMessage());
282
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId, e);
283
+
}
284
+
// Change value of global configuration parameter router.template.* for the corresponding hypervisor
285
+
try(PreparedStatementupdate_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) {
s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue() + ": "+e.getMessage());
292
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e);
293
+
}
294
+
} else {
295
+
if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){
296
+
thrownewCloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms");
297
+
} else {
298
+
s_logger.warn("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade");
299
+
// Update the latest template URLs for corresponding hypervisor
300
+
try(PreparedStatementupdate_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");) {
s_logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString() + ": "+e.getMessage());
308
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString(), e);
309
+
}
310
+
}
299
311
}
300
312
} catch (SQLExceptione) {
301
-
s_logger.debug("exception while cleaning resources during sytemvm upgrade.", e);
313
+
s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: "+e.getMessage());
314
+
thrownewCloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e);
302
315
}
303
316
}
317
+
s_logger.debug("Updating System Vm Template IDs Complete");
0 commit comments