shwstppr commented on code in PR #12704:
URL: https://github.com/apache/cloudstack/pull/12704#discussion_r3842338897
##########
engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java:
##########
@@ -412,8 +412,47 @@ protected static MetadataTemplateDetails
getMetadataTemplateDetails(Hypervisor.H
return NewTemplateMap.get(getHypervisorArchKey(hypervisorType, arch));
}
- public VMTemplateVO getRegisteredTemplate(String templateName, CPU.CPUArch
arch) {
- return vmTemplateDao.findLatestTemplateByName(templateName, arch);
+ /**
+ * Finds a registered system VM Template matching the provided criteria.
+ *
+ * <p>The method first attempts to locate the latest template by {@code
templateName},
+ * {@code hypervisorType} and {@code arch}. If none is found and a
non-blank {@code url}
+ * is provided, it falls back to searching for an active system template
by the
+ * URL path segment (the substring after the last '/' in the URL).</p>
+ *
+ * @param templateName the template name to search for
+ * @param hypervisorType the hypervisor type
+ * @param arch the CPU architecture
+ * @param url optional download URL used as a fallback; may be {@code
null} or blank
+ * @return the matching {@code VMTemplateVO} if found; {@code null}
otherwise
+ */
+ public VMTemplateVO getRegisteredTemplate(String templateName,
Hypervisor.HypervisorType hypervisorType,
+ CPU.CPUArch arch, String url) {
+ VMTemplateVO registeredTemplate =
vmTemplateDao.findLatestTemplateByName(templateName, hypervisorType, arch);
+ if (registeredTemplate != null) {
+ LOGGER.debug("Found existing registered template for {}: {}",
+ getHypervisorArchLog(hypervisorType, arch),
registeredTemplate);
+ return registeredTemplate;
+ }
+ if (StringUtils.isBlank(url)) {
+ MetadataTemplateDetails details =
getMetadataTemplateDetails(hypervisorType, arch);
+ if (details != null) {
+ url = details.getUrl();
+ }
+ String urlPath = url.substring(url.lastIndexOf("/") + 1);
+ LOGGER.debug("No template found by name: {}, falling back to
search existing SYSTEM template by " +
+ "urlPath: {}, {}", templateName, urlPath,
getHypervisorArchLog(hypervisorType, arch));
+ registeredTemplate =
vmTemplateDao.findActiveSystemTemplateByHypervisorArchAndUrlPath(hypervisorType,
arch,
+ urlPath);
+ if (registeredTemplate != null) {
+ LOGGER.debug("Found existing registered template by urlPath:
{} for {}: {}",
+ getHypervisorArchLog(hypervisorType, arch),
registeredTemplate);
Review Comment:
```suggestion
urlPath, getHypervisorArchLog(hypervisorType, arch),
registeredTemplate);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]