systemvm-registration: update seeded template_store_ref sizes (#10317)

This commit is contained in:
Rene Peinthor 2025-02-07 13:19:05 +01:00 committed by GitHub
parent a627ab67c2
commit c09720a19a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View File

@ -332,7 +332,7 @@ public class SystemVmTemplateRegistration {
}
};
public static boolean validateIfSeeded(String url, String path, String nfsVersion) {
public boolean validateIfSeeded(TemplateDataStoreVO templDataStoreVO, String url, String path, String nfsVersion) {
String filePath = null;
try {
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
@ -345,6 +345,9 @@ public class SystemVmTemplateRegistration {
String templatePath = filePath + File.separator + partialDirPath;
File templateProps = new File(templatePath + "/template.properties");
if (templateProps.exists()) {
Pair<Long, Long> templateSizes = readTemplatePropertiesSizes(templatePath + "/template.properties");
updateSeededTemplateDetails(templDataStoreVO.getTemplateId(), templDataStoreVO.getDataStoreId(),
templateSizes.first(), templateSizes.second());
LOGGER.info("SystemVM template already seeded, skipping registration");
return true;
}
@ -540,6 +543,21 @@ public class SystemVmTemplateRegistration {
}
}
public void updateSeededTemplateDetails(long templateId, long storeId, long size, long physicalSize) {
VMTemplateVO template = vmTemplateDao.findById(templateId);
template.setSize(size);
vmTemplateDao.update(template.getId(), template);
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeId, template.getId());
templateDataStoreVO.setSize(size);
templateDataStoreVO.setPhysicalSize(physicalSize);
templateDataStoreVO.setLastUpdated(new Date(DateUtil.currentGMTTime().getTime()));
boolean updated = templateDataStoreDao.update(templateDataStoreVO.getId(), templateDataStoreVO);
if (!updated) {
throw new CloudRuntimeException("Failed to update template_store_ref entry for seeded systemVM template");
}
}
public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hypervisorType) {
vmInstanceDao.updateSystemVmTemplateId(templateId, hypervisorType);
}
@ -553,7 +571,7 @@ public class SystemVmTemplateRegistration {
}
}
private static void readTemplateProperties(String path, SystemVMTemplateDetails details) {
private static Pair<Long, Long> readTemplatePropertiesSizes(String path) {
File tmpFile = new File(path);
Long size = null;
Long physicalSize = 0L;
@ -572,8 +590,13 @@ public class SystemVmTemplateRegistration {
} catch (IOException ex) {
LOGGER.warn("Failed to read from template.properties", ex);
}
details.setSize(size);
details.setPhysicalSize(physicalSize);
return new Pair<>(size, physicalSize);
}
public static void readTemplateProperties(String path, SystemVMTemplateDetails details) {
Pair<Long, Long> templateSizes = readTemplatePropertiesSizes(path);
details.setSize(templateSizes.first());
details.setPhysicalSize(templateSizes.second());
}
private void updateTemplateTablesOnFailure(long templateId) {
@ -797,7 +820,7 @@ public class SystemVmTemplateRegistration {
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
if (templateDataStoreVO != null) {
String installPath = templateDataStoreVO.getInstallPath();
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
if (validateIfSeeded(templateDataStoreVO, storeUrlAndId.first(), installPath, nfsVersion)) {
continue;
}
}

View File

@ -3452,8 +3452,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
if (templateVO != null) {
try {
if (SystemVmTemplateRegistration.validateIfSeeded(
url, templateVO.getInstallPath(), nfsVersion)) {
if (systemVmTemplateRegistration.validateIfSeeded(
templateVO, url, templateVO.getInstallPath(), nfsVersion)) {
continue;
}
} catch (Exception e) {