This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.19 by this push:
new 8c9216d11b6 only clean details and annotations when this tamplate no
longer exists on any zone (#10728)
8c9216d11b6 is described below
commit 8c9216d11b63d2edbb4c5dbc30c974f25357a4b8
Author: dahn <[email protected]>
AuthorDate: Thu Apr 17 12:55:21 2025 +0200
only clean details and annotations when this tamplate no longer exists on
any zone (#10728)
---
.../cloud/template/HypervisorTemplateAdapter.java | 35 ++++++++++++----------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git
a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
index 0090b35fb21..47a8f0a5468 100644
--- a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
@@ -295,7 +295,7 @@ public class HypervisorTemplateAdapter extends
TemplateAdapterBase {
}
/**
- * For each zone ID in {@link TemplateProfile#zoneIdList}, verifies if
there is active heuristic rules for allocating template and returns the
+ * For each zone ID in {@link TemplateProfile#getZoneIdList()}, verifies
if there is active heuristic rules for allocating template and returns the
* {@link DataStore} returned by the heuristic rule. If there is not an
active heuristic rule, then allocate it to a random {@link DataStore}, if the
ISO/template is private
* or allocate it to all {@link DataStore} in the zone, if it is public.
* @param profile
@@ -456,10 +456,10 @@ public class HypervisorTemplateAdapter extends
TemplateAdapterBase {
/**
* If the template/ISO is marked as private, then it is allocated to a
random secondary storage; otherwise, allocates to every storage pool in every
zone given by the
- * {@link TemplateProfile#zoneIdList}.
+ * {@link TemplateProfile#getZoneIdList()}.
*/
private void postUploadAllocation(List<DataStore> imageStores,
VMTemplateVO template, List<TemplateOrVolumePostUploadCommand> payloads) {
- Set<Long> zoneSet = new HashSet<Long>();
+ Set<Long> zoneSet = new HashSet<>();
Collections.shuffle(imageStores);
for (DataStore imageStore : imageStores) {
Long zoneId_is = imageStore.getScope().getScopeId();
@@ -702,8 +702,8 @@ public class HypervisorTemplateAdapter extends
TemplateAdapterBase {
}
// delete all cache entries for this template
- List<TemplateInfo> cacheTmpls =
imageFactory.listTemplateOnCache(template.getId());
- for (TemplateInfo tmplOnCache : cacheTmpls) {
+ List<TemplateInfo> cachedTemplates =
imageFactory.listTemplateOnCache(template.getId());
+ for (TemplateInfo tmplOnCache : cachedTemplates) {
s_logger.info("Delete template: " + tmplOnCache.getId() + "
from image cache store: " + tmplOnCache.getDataStore().getName());
tmplOnCache.delete();
}
@@ -732,27 +732,32 @@ public class HypervisorTemplateAdapter extends
TemplateAdapterBase {
}
// remove its related ACL permission
- Pair<Class<?>, Long> tmplt = new Pair<Class<?>,
Long>(VirtualMachineTemplate.class, template.getId());
- _messageBus.publish(_name,
EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, tmplt);
-
- checkAndRemoveTemplateDetails(template);
-
- // Remove comments (if any)
- AnnotationService.EntityType entityType =
template.getFormat().equals(ImageFormat.ISO) ?
- AnnotationService.EntityType.ISO :
AnnotationService.EntityType.TEMPLATE;
- annotationDao.removeByEntityType(entityType.name(),
template.getUuid());
+ Pair<Class<?>, Long> templateClassForId = new
Pair<>(VirtualMachineTemplate.class, template.getId());
+ _messageBus.publish(_name,
EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL,
templateClassForId);
+ List<VMTemplateZoneVO> zoneRegistrations =
templateZoneDao.listByTemplateId(template.getId());
+ if (zoneRegistrations.isEmpty()) {
+ removeTemplateDetails(template);
+ removeTemplateAnnotations(template);
+ }
}
return success;
}
+ private void removeTemplateAnnotations(VMTemplateVO template) {
+ // Remove comments (if any)
+ AnnotationService.EntityType entityType =
template.getFormat().equals(ImageFormat.ISO) ?
+ AnnotationService.EntityType.ISO :
AnnotationService.EntityType.TEMPLATE;
+ annotationDao.removeByEntityType(entityType.name(),
template.getUuid());
+ }
+
/**
* removes details of the template and
* if the template is registered as deploy as is,
* then it also deletes the details related to deploy as is only if there
are no VMs using the template
* @param template
*/
- void checkAndRemoveTemplateDetails(VMTemplateVO template) {
+ private void removeTemplateDetails(VMTemplateVO template) {
templateDetailsDao.removeDetails(template.getId());
if (template.isDeployAsIs()) {