Skip to content

Commit 0e08a12

Browse files
systemvm: add template_zone_ref record when add a new zone with same hypervisor type (#8395)
1 parent 77df9ad commit 0e08a12

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,19 +482,19 @@ private VMTemplateZoneVO createOrUpdateTemplateZoneEntry(long zoneId, long templ
482482
templateZoneVO = vmTemplateZoneDao.persist(templateZoneVO);
483483
} else {
484484
templateZoneVO.setLastUpdated(new java.util.Date());
485-
if (vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
485+
if (!vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
486486
templateZoneVO = null;
487487
}
488488
}
489489
return templateZoneVO;
490490
}
491491

492-
private void createCrossZonesTemplateZoneRefEntries(VMTemplateVO template) {
492+
private void createCrossZonesTemplateZoneRefEntries(Long templateId) {
493493
List<DataCenterVO> dcs = dataCenterDao.listAll();
494494
for (DataCenterVO dc : dcs) {
495-
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), template.getId());
495+
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), templateId);
496496
if (templateZoneVO == null) {
497-
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template for hypervisor: %s and zone: %s", template.getHypervisorType().name(), dc));
497+
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template (id: %s) and zone: %s", templateId, dc));
498498
}
499499
}
500500
}
@@ -624,8 +624,9 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp
624624
throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name()));
625625
}
626626
templateId = template.getId();
627-
createCrossZonesTemplateZoneRefEntries(template);
628627
}
628+
createCrossZonesTemplateZoneRefEntries(templateId);
629+
629630
details.setId(templateId);
630631
String destTempFolderName = String.valueOf(templateId);
631632
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + destTempFolderName;

0 commit comments

Comments
 (0)