Skip to content

Commit c09720a

Browse files
authored
systemvm-registration: update seeded template_store_ref sizes (#10317)
1 parent a627ab6 commit c09720a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void setUpdated(Date updated) {
332332
}
333333
};
334334

335-
public static boolean validateIfSeeded(String url, String path, String nfsVersion) {
335+
public boolean validateIfSeeded(TemplateDataStoreVO templDataStoreVO, String url, String path, String nfsVersion) {
336336
String filePath = null;
337337
try {
338338
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
@@ -345,6 +345,9 @@ public static boolean validateIfSeeded(String url, String path, String nfsVersio
345345
String templatePath = filePath + File.separator + partialDirPath;
346346
File templateProps = new File(templatePath + "/template.properties");
347347
if (templateProps.exists()) {
348+
Pair<Long, Long> templateSizes = readTemplatePropertiesSizes(templatePath + "/template.properties");
349+
updateSeededTemplateDetails(templDataStoreVO.getTemplateId(), templDataStoreVO.getDataStoreId(),
350+
templateSizes.first(), templateSizes.second());
348351
LOGGER.info("SystemVM template already seeded, skipping registration");
349352
return true;
350353
}
@@ -540,6 +543,21 @@ public void updateTemplateDetails(SystemVMTemplateDetails details) {
540543
}
541544
}
542545

546+
public void updateSeededTemplateDetails(long templateId, long storeId, long size, long physicalSize) {
547+
VMTemplateVO template = vmTemplateDao.findById(templateId);
548+
template.setSize(size);
549+
vmTemplateDao.update(template.getId(), template);
550+
551+
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeId, template.getId());
552+
templateDataStoreVO.setSize(size);
553+
templateDataStoreVO.setPhysicalSize(physicalSize);
554+
templateDataStoreVO.setLastUpdated(new Date(DateUtil.currentGMTTime().getTime()));
555+
boolean updated = templateDataStoreDao.update(templateDataStoreVO.getId(), templateDataStoreVO);
556+
if (!updated) {
557+
throw new CloudRuntimeException("Failed to update template_store_ref entry for seeded systemVM template");
558+
}
559+
}
560+
543561
public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hypervisorType) {
544562
vmInstanceDao.updateSystemVmTemplateId(templateId, hypervisorType);
545563
}
@@ -553,7 +571,7 @@ public void updateConfigurationParams(Map<String, String> configParams) {
553571
}
554572
}
555573

556-
private static void readTemplateProperties(String path, SystemVMTemplateDetails details) {
574+
private static Pair<Long, Long> readTemplatePropertiesSizes(String path) {
557575
File tmpFile = new File(path);
558576
Long size = null;
559577
Long physicalSize = 0L;
@@ -572,8 +590,13 @@ private static void readTemplateProperties(String path, SystemVMTemplateDetails
572590
} catch (IOException ex) {
573591
LOGGER.warn("Failed to read from template.properties", ex);
574592
}
575-
details.setSize(size);
576-
details.setPhysicalSize(physicalSize);
593+
return new Pair<>(size, physicalSize);
594+
}
595+
596+
public static void readTemplateProperties(String path, SystemVMTemplateDetails details) {
597+
Pair<Long, Long> templateSizes = readTemplatePropertiesSizes(path);
598+
details.setSize(templateSizes.first());
599+
details.setPhysicalSize(templateSizes.second());
577600
}
578601

579602
private void updateTemplateTablesOnFailure(long templateId) {
@@ -797,7 +820,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
797820
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
798821
if (templateDataStoreVO != null) {
799822
String installPath = templateDataStoreVO.getInstallPath();
800-
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
823+
if (validateIfSeeded(templateDataStoreVO, storeUrlAndId.first(), installPath, nfsVersion)) {
801824
continue;
802825
}
803826
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,8 +3452,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
34523452
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
34533453
if (templateVO != null) {
34543454
try {
3455-
if (SystemVmTemplateRegistration.validateIfSeeded(
3456-
url, templateVO.getInstallPath(), nfsVersion)) {
3455+
if (systemVmTemplateRegistration.validateIfSeeded(
3456+
templateVO, url, templateVO.getInstallPath(), nfsVersion)) {
34573457
continue;
34583458
}
34593459
} catch (Exception e) {

0 commit comments

Comments
 (0)