mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
systemvm-registration: update seeded template_store_ref sizes (#10317)
This commit is contained in:
parent
a627ab67c2
commit
c09720a19a
@ -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;
|
String filePath = null;
|
||||||
try {
|
try {
|
||||||
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
|
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
|
||||||
@ -345,6 +345,9 @@ public class SystemVmTemplateRegistration {
|
|||||||
String templatePath = filePath + File.separator + partialDirPath;
|
String templatePath = filePath + File.separator + partialDirPath;
|
||||||
File templateProps = new File(templatePath + "/template.properties");
|
File templateProps = new File(templatePath + "/template.properties");
|
||||||
if (templateProps.exists()) {
|
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");
|
LOGGER.info("SystemVM template already seeded, skipping registration");
|
||||||
return true;
|
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) {
|
public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hypervisorType) {
|
||||||
vmInstanceDao.updateSystemVmTemplateId(templateId, 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);
|
File tmpFile = new File(path);
|
||||||
Long size = null;
|
Long size = null;
|
||||||
Long physicalSize = 0L;
|
Long physicalSize = 0L;
|
||||||
@ -572,8 +590,13 @@ public class SystemVmTemplateRegistration {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOGGER.warn("Failed to read from template.properties", ex);
|
LOGGER.warn("Failed to read from template.properties", ex);
|
||||||
}
|
}
|
||||||
details.setSize(size);
|
return new Pair<>(size, physicalSize);
|
||||||
details.setPhysicalSize(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) {
|
private void updateTemplateTablesOnFailure(long templateId) {
|
||||||
@ -797,7 +820,7 @@ public class SystemVmTemplateRegistration {
|
|||||||
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
|
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
|
||||||
if (templateDataStoreVO != null) {
|
if (templateDataStoreVO != null) {
|
||||||
String installPath = templateDataStoreVO.getInstallPath();
|
String installPath = templateDataStoreVO.getInstallPath();
|
||||||
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
|
if (validateIfSeeded(templateDataStoreVO, storeUrlAndId.first(), installPath, nfsVersion)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3452,8 +3452,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||||||
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
|
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
|
||||||
if (templateVO != null) {
|
if (templateVO != null) {
|
||||||
try {
|
try {
|
||||||
if (SystemVmTemplateRegistration.validateIfSeeded(
|
if (systemVmTemplateRegistration.validateIfSeeded(
|
||||||
url, templateVO.getInstallPath(), nfsVersion)) {
|
templateVO, url, templateVO.getInstallPath(), nfsVersion)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user