systemvm: add template_zone_ref record when add a new zone with same hypervisor type (#8395)

This commit is contained in:
Wei Zhou 2024-04-25 08:41:59 +02:00 committed by GitHub
parent 77df9ad4d7
commit 0e08a126df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -482,19 +482,19 @@ public class SystemVmTemplateRegistration {
templateZoneVO = vmTemplateZoneDao.persist(templateZoneVO);
} else {
templateZoneVO.setLastUpdated(new java.util.Date());
if (vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
if (!vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
templateZoneVO = null;
}
}
return templateZoneVO;
}
private void createCrossZonesTemplateZoneRefEntries(VMTemplateVO template) {
private void createCrossZonesTemplateZoneRefEntries(Long templateId) {
List<DataCenterVO> dcs = dataCenterDao.listAll();
for (DataCenterVO dc : dcs) {
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), template.getId());
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), templateId);
if (templateZoneVO == null) {
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));
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template (id: %s) and zone: %s", templateId, dc));
}
}
}
@ -624,8 +624,9 @@ public class SystemVmTemplateRegistration {
throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name()));
}
templateId = template.getId();
createCrossZonesTemplateZoneRefEntries(template);
}
createCrossZonesTemplateZoneRefEntries(templateId);
details.setId(templateId);
String destTempFolderName = String.valueOf(templateId);
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + destTempFolderName;