mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
only clean details and annotations when this tamplate no longer exists on any zone (#10728)
This commit is contained in:
parent
7b68615bd9
commit
8c9216d11b
@ -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,27 +732,32 @@ 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);
|
|
||||||
|
|
||||||
// Remove comments (if any)
|
|
||||||
AnnotationService.EntityType entityType = template.getFormat().equals(ImageFormat.ISO) ?
|
|
||||||
AnnotationService.EntityType.ISO : AnnotationService.EntityType.TEMPLATE;
|
|
||||||
annotationDao.removeByEntityType(entityType.name(), template.getUuid());
|
|
||||||
|
|
||||||
|
List<VMTemplateZoneVO> zoneRegistrations = templateZoneDao.listByTemplateId(template.getId());
|
||||||
|
if (zoneRegistrations.isEmpty()) {
|
||||||
|
removeTemplateDetails(template);
|
||||||
|
removeTemplateAnnotations(template);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return success;
|
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
|
* removes details of the template and
|
||||||
* if the template is registered as deploy as is,
|
* 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
|
* 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()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user