Skip to content

Commit 09f9415

Browse files
weizhouapachedhslove
authored andcommitted
systemvm: add template_zone_ref record when add a new zone with same hypervisor type (apache#8395)
1 parent 49f43da commit 09f9415

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

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

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

493-
private void createCrossZonesTemplateZoneRefEntries(VMTemplateVO template) {
493+
private void createCrossZonesTemplateZoneRefEntries(Long templateId) {
494494
List<DataCenterVO> dcs = dataCenterDao.listAll();
495495
for (DataCenterVO dc : dcs) {
496-
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), template.getId());
496+
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), templateId);
497497
if (templateZoneVO == null) {
498-
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));
498+
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template (id: %s) and zone: %s", templateId, dc));
499499
}
500500
}
501501
}
@@ -625,8 +625,9 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp
625625
throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name()));
626626
}
627627
templateId = template.getId();
628-
createCrossZonesTemplateZoneRefEntries(template);
629628
}
629+
createCrossZonesTemplateZoneRefEntries(templateId);
630+
630631
details.setId(templateId);
631632
String destTempFolderName = String.valueOf(templateId);
632633
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + destTempFolderName;

0 commit comments

Comments
 (0)