only clean details and annotations when this tamplate no longer exists on any zone (#10728)

This commit is contained in:
dahn 2025-04-17 12:55:21 +02:00 committed by GitHub
parent 7b68615bd9
commit 8c9216d11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 * {@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. * or allocate it to all {@link DataStore} in the zone, if it is public.
* @param profile * @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 * 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) { 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); Collections.shuffle(imageStores);
for (DataStore imageStore : imageStores) { for (DataStore imageStore : imageStores) {
Long zoneId_is = imageStore.getScope().getScopeId(); Long zoneId_is = imageStore.getScope().getScopeId();
@ -702,8 +702,8 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
} }
// delete all cache entries for this template // delete all cache entries for this template
List<TemplateInfo> cacheTmpls = imageFactory.listTemplateOnCache(template.getId()); List<TemplateInfo> cachedTemplates = imageFactory.listTemplateOnCache(template.getId());
for (TemplateInfo tmplOnCache : cacheTmpls) { for (TemplateInfo tmplOnCache : cachedTemplates) {
s_logger.info("Delete template: " + tmplOnCache.getId() + " from image cache store: " + tmplOnCache.getDataStore().getName()); s_logger.info("Delete template: " + tmplOnCache.getId() + " from image cache store: " + tmplOnCache.getDataStore().getName());
tmplOnCache.delete(); tmplOnCache.delete();
} }
@ -732,18 +732,23 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
} }
// remove its related ACL permission // remove its related ACL permission
Pair<Class<?>, Long> tmplt = new Pair<Class<?>, Long>(VirtualMachineTemplate.class, template.getId()); Pair<Class<?>, Long> templateClassForId = new Pair<>(VirtualMachineTemplate.class, template.getId());
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, tmplt); _messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, templateClassForId);
checkAndRemoveTemplateDetails(template); 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) // Remove comments (if any)
AnnotationService.EntityType entityType = template.getFormat().equals(ImageFormat.ISO) ? AnnotationService.EntityType entityType = template.getFormat().equals(ImageFormat.ISO) ?
AnnotationService.EntityType.ISO : AnnotationService.EntityType.TEMPLATE; AnnotationService.EntityType.ISO : AnnotationService.EntityType.TEMPLATE;
annotationDao.removeByEntityType(entityType.name(), template.getUuid()); annotationDao.removeByEntityType(entityType.name(), template.getUuid());
}
return success;
} }
/** /**
@ -752,7 +757,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
* then it also deletes the details related to deploy as is only if there are no VMs using the template * then it also deletes the details related to deploy as is only if there are no VMs using the template
* @param template * @param template
*/ */
void checkAndRemoveTemplateDetails(VMTemplateVO template) { private void removeTemplateDetails(VMTemplateVO template) {
templateDetailsDao.removeDetails(template.getId()); templateDetailsDao.removeDetails(template.getId());
if (template.isDeployAsIs()) { if (template.isDeployAsIs()) {