DaanHoogland commented on a change in pull request #4748:
URL: https://github.com/apache/cloudstack/pull/4748#discussion_r597480536
##########
File path:
server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
##########
@@ -570,6 +572,14 @@ public boolean delete(TemplateProfile profile) {
if (success) {
if ((imageStores != null && imageStores.size() > 1) &&
(profile.getZoneIdList() != null)) {
//if template is stored in more than one image stores, and the
zone id is not null, then don't delete other templates.
+ List<VMTemplateZoneVO> templateZones =
templateZoneDao.listByTemplateId(template.getId());
+ List<Long> zoneIds =
templateZones.stream().map(VMTemplateZoneVO::getZoneId).collect(Collectors.toList());
+ if (zoneIds.size() > 0) {
+ return success;
+ }
+ template.setRemoved(new Date());
+ template.setState(State.Inactive);
+ templateDao.update(template.getId(), template);
Review comment:
`delete()` ranges from line 454 to line 621. It deserves its own worker
class. I won't ask that (hint hint, wink wink) but can you at least extract
your new bit to a separate method?
##########
File path:
server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
##########
@@ -585,6 +595,7 @@ public boolean delete(TemplateProfile profile) {
if (iStores == null || iStores.size() == 0) {
// Mark template as Inactive.
template.setState(VirtualMachineTemplate.State.Inactive);
+ templateDao.remove(template.getId());
Review comment:
There's a `templateDao` member in this class and a `_tmpltDao` in
`TemplateAdapterBase`, and though I like the first name better, its presence is
pollution/technical debt. I think you should use the one from the based class.
##########
File path: server/src/main/java/com/cloud/storage/StorageManagerImpl.java
##########
@@ -1324,6 +1324,11 @@ public void cleanupStorage(boolean recurring) {
s_logger.warn("Unable to destroy uploaded template
" + template.getUuid() + ". Error details: " + th.getMessage());
}
}
+ List<VMTemplateVO> vmTemplateVOS =
_templateDao.listUnRemovedTemplatesByStates(VirtualMachineTemplate.State.Inactive);
+ for (VMTemplateVO template: vmTemplateVOS) {
+ template.setRemoved(new Date());
+ _templateDao.update(template.getId(), template);
+ }
Review comment:
Can you extract this? method already reaches from l1156-1339. ( a `class
StorageCleaner` required :| )
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]