Skip to content

Commit 499ef4d

Browse files
weizhouapachedhslove
authored andcommitted
upgrade: consider multiple hypervisors and secondary storages (apache#10046)
1 parent a70dcd6 commit 499ef4d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,16 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
796796
Long templateId = getRegisteredTemplateId(hypervisorAndTemplateName);
797797
if (templateId != null) {
798798
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
799-
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
800-
String installPath = templateDataStoreVO.getInstallPath();
801-
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
802-
continue;
803-
} else if (templateVO != null) {
799+
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
800+
if (templateDataStoreVO != null) {
801+
String installPath = templateDataStoreVO.getInstallPath();
802+
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
803+
continue;
804+
}
805+
}
806+
if (templateVO != null) {
804807
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
808+
updateRegisteredTemplateDetails(templateId, hypervisorAndTemplateName);
805809
continue;
806810
}
807811
}
@@ -825,6 +829,11 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
825829
}
826830

827831
private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
832+
Pair<Hypervisor.HypervisorType, String> entry = new Pair<>(hypervisorAndTemplateName.getKey(), hypervisorAndTemplateName.getValue());
833+
updateRegisteredTemplateDetails(templateId, entry);
834+
}
835+
836+
private void updateRegisteredTemplateDetails(Long templateId, Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
828837
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
829838
templateVO.setTemplateType(Storage.TemplateType.SYSTEM);
830839
boolean updated = vmTemplateDao.update(templateVO.getId(), templateVO);
@@ -834,11 +843,11 @@ private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervis
834843
throw new CloudRuntimeException(errMsg);
835844
}
836845

837-
updateSystemVMEntries(templateId, hypervisorAndTemplateName.getKey());
846+
updateSystemVMEntries(templateId, hypervisorAndTemplateName.first());
838847

839848
// Change value of global configuration parameter router.template.* for the corresponding hypervisor and minreq.sysvmtemplate.version for the ACS version
840849
Map<String, String> configParams = new HashMap<>();
841-
configParams.put(RouterTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()), hypervisorAndTemplateName.getValue());
850+
configParams.put(RouterTemplateConfigurationNames.get(hypervisorAndTemplateName.first()), hypervisorAndTemplateName.second());
842851
configParams.put("minreq.sysvmtemplate.version", getSystemVmTemplateVersion());
843852
updateConfigurationParams(configParams);
844853
}

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
35383538
TemplateDataStoreVO templateVO = null;
35393539
if (templateId != null) {
35403540
vmTemplateVO = _templateDao.findById(templateId);
3541-
templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image);
3541+
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
35423542
if (templateVO != null) {
35433543
try {
35443544
if (SystemVmTemplateRegistration.validateIfSeeded(

0 commit comments

Comments
 (0)