[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16310937#comment-16310937
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10146:
---------------------------------------------

marcaurele commented on a change in pull request #2379: CLOUDSTACK-10146: 
Bypass Secondary Storage for KVM templates
URL: https://github.com/apache/cloudstack/pull/2379#discussion_r159595450
 
 

 ##########
 File path: 
engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
 ##########
 @@ -153,4 +164,67 @@ public TemplateInfo getReadyTemplateOnCache(long 
templateId) {
         return tmplObjs;
     }
 
+    /**
+     * Given existing spool refs, return one pool id existing on pools and refs
+     * @param existingRefs
+     * @param pools
+     * @return
+     */
+    private Long getOneMatchingPoolIdFromRefs(List<VMTemplateStoragePoolVO> 
existingRefs, List<StoragePoolVO> pools) {
+        for (VMTemplateStoragePoolVO ref : existingRefs) {
+            for (StoragePoolVO p : pools) {
+                if (ref.getPoolId() == p.getId()) {
+                    return p.getId();
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Retrieve storage pools with scope = cluster or zone matching clusterId 
or dataCenterId depending on their scope
+     * @param clusterId
+     * @param dataCenterId
+     * @param hypervisorType
+     * @return
+     */
+    private List<StoragePoolVO> getStoragePoolsFromClusterOrZone(Long 
clusterId, long dataCenterId, Hypervisor.HypervisorType hypervisorType) {
+        List<StoragePoolVO> pools = new ArrayList<>();
+        if (clusterId != null) {
+            List<StoragePoolVO> clusterPools = 
primaryDataStoreDao.listPoolsByCluster(clusterId);
+            pools.addAll(clusterPools);
+        }
+        List<StoragePoolVO> zonePools = 
primaryDataStoreDao.findZoneWideStoragePoolsByHypervisor(dataCenterId, 
hypervisorType);
+        pools.addAll(zonePools);
+        return pools;
+    }
+
+    @Override
+    public TemplateInfo getReadyBypassedTemplateOnPrimaryStore(long 
templateId, Long poolId, Long hostId) {
+        VMTemplateVO templateVO = imageDataDao.findById(templateId);
+        if (templateVO == null || !templateVO.isDirectDownload()) {
+            return null;
+        }
+        Long pool = poolId;
+        if (poolId == null) {
+            //Get ISO from existing pool ref
+            HostVO host = hostDao.findById(hostId);
+            List<StoragePoolVO> pools = 
getStoragePoolsFromClusterOrZone(host.getClusterId(), host.getDataCenterId(), 
host.getHypervisorType());
+            List<VMTemplateStoragePoolVO> existingRefs = 
templatePoolDao.listByTemplateId(templateId);
+            pool = getOneMatchingPoolIdFromRefs(existingRefs, pools);
+        }
+        VMTemplateStoragePoolVO spoolRef = 
templatePoolDao.findByPoolTemplate(pool, templateId);
 
 Review comment:
   `pool` can be null here, according to 
https://github.com/apache/cloudstack/pull/2379/files#diff-92e0bb0fd44a51c2c2234ae65d88fbbdR181

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Bypass Secondary Storage for KVM templates
> ------------------------------------------
>
>                 Key: CLOUDSTACK-10146
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10146
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>    Affects Versions: 4.11.0.0
>            Reporter: Nicolas Vazquez
>            Assignee: Nicolas Vazquez
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to