weizhouapache commented on code in PR #11782:
URL: https://github.com/apache/cloudstack/pull/11782#discussion_r2401426748
##########
server/src/main/java/com/cloud/template/TemplateManagerImpl.java:
##########
@@ -1024,33 +1024,53 @@ public boolean delete(long userId, long templateId,
Long zoneId) {
return adapter.delete(new TemplateProfile(userId, template, zoneId));
}
+ private Boolean templateIsUnusedInPool(VMTemplateStoragePoolVO
templatePoolVO) {
+ VMTemplateVO template =
_tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
+
+ // If this is a routing template, consider it in use
+ if (template.getTemplateType() == TemplateType.SYSTEM) {
+ return false;
+ }
+
+ // If the template is not yet downloaded to the pool, consider it in
use
+ if (templatePoolVO.getDownloadState() != Status.DOWNLOADED) {
+ return false;
+ }
+
+ if (template.getFormat() == ImageFormat.ISO ||
_volumeDao.isAnyVolumeActivelyUsingTemplateOnPool(template.getId(),
templatePoolVO.getPoolId())) {
+ return false;
+ }
+ return true;
+ }
+
@Override
public List<VMTemplateStoragePoolVO>
getUnusedTemplatesInPool(StoragePoolVO pool) {
List<VMTemplateStoragePoolVO> unusedTemplatesInPool = new
ArrayList<VMTemplateStoragePoolVO>();
List<VMTemplateStoragePoolVO> allTemplatesInPool =
_tmpltPoolDao.listByPoolId(pool.getId());
for (VMTemplateStoragePoolVO templatePoolVO : allTemplatesInPool) {
- VMTemplateVO template =
_tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
-
- // If this is a routing template, consider it in use
- if (template.getTemplateType() == TemplateType.SYSTEM) {
- continue;
- }
-
- // If the template is not yet downloaded to the pool, consider it
in
- // use
- if (templatePoolVO.getDownloadState() != Status.DOWNLOADED) {
- continue;
- }
-
- if (template.getFormat() != ImageFormat.ISO &&
!_volumeDao.isAnyVolumeActivelyUsingTemplateOnPool(template.getId(),
pool.getId())) {
+ if (templateIsUnusedInPool(templatePoolVO)) {
unusedTemplatesInPool.add(templatePoolVO);
}
}
-
return unusedTemplatesInPool;
}
+ @Override
+ public void evictTemplateFromStoragePoolsForZones(Long templateId,
List<Long> zoneIds) {
+ List<Long> poolIds = new ArrayList<>();
+ if (zoneIds != null && !zoneIds.isEmpty()) {
Review Comment:
CollectionUtils.isNotEmpty ?
--
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]