sureshanaparti commented on code in PR #13654:
URL: https://github.com/apache/cloudstack/pull/13654#discussion_r4739596856


##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -1083,8 +1084,62 @@ private void findAvoiSetForRouterVM(ExcludeList avoids, 
VirtualMachine vm, List<
     }
 
     private void findAvoidSetForNonExplicitUserVM(ExcludeList avoids, 
VirtualMachine vm, List<Long> allPodsInDc, List<Long> allClustersInDc, 
List<Long> allHostsInDc) {
+        if (allPodsInDc.isEmpty() && allClustersInDc.isEmpty() && 
allHostsInDc.isEmpty()) {
+            // Nothing in this DC is dedicated to anyone, so there is nothing 
to avoid or to check dedication for.
+            return;
+        }
+
+        long vmAccountId = vm.getAccountId();
+        long vmDomainId = vm.getDomainId();
+
+        // If the VM owner's domain has an ExplicitDedication domain-level 
affinity group,
+        // resources dedicated to that domain are accessible to the VM owner 
as well.
+        boolean hasDomainExplicitDedicationGroup =
+                _affinityGroupDao.findDomainLevelGroupByType(vmDomainId, 
EXPLICIT_DEDICATION_AFFINITY_GROUP_TYPE) != null;
+
+        // Sort by id ascending, no pagination — retrieve all dedicated 
resources for this domain/account
+        Filter filter = new Filter(DedicatedResourceVO.class, "id", true);
+
+        // Only query the resource types that have dedicated entries in this 
DC.
+        if (!allPodsInDc.isEmpty()) {
+            Set<Long> allowedDedicatedPodIds = new HashSet<>();
+            for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null, 
filter).first()) {
+                allowedDedicatedPodIds.add(vo.getPodId());
+            }
+            if (hasDomainExplicitDedicationGroup) {
+                for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null, 
filter).first()) {
+                    allowedDedicatedPodIds.add(vo.getPodId());
+                }
+            }
+            allPodsInDc.removeAll(allowedDedicatedPodIds);
+        }
+        if (!allClustersInDc.isEmpty()) {
+            Set<Long> allowedDedicatedClusterIds = new HashSet<>();
+            for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null, 
filter).first()) {
+                allowedDedicatedClusterIds.add(vo.getClusterId());
+            }
+            if (hasDomainExplicitDedicationGroup) {
+                for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null, 
filter).first()) {
+                    allowedDedicatedClusterIds.add(vo.getClusterId());
+                }
+            }
+            allClustersInDc.removeAll(allowedDedicatedClusterIds);
+        }
+        if (!allHostsInDc.isEmpty()) {
+            Set<Long> allowedDedicatedHostIds = new HashSet<>();
+            for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null, 
filter).first()) {
+                allowedDedicatedHostIds.add(vo.getHostId());
+            }
+            if (hasDomainExplicitDedicationGroup) {
+                for (DedicatedResourceVO vo : 
_dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null, 
filter).first()) {
+                    allowedDedicatedHostIds.add(vo.getHostId());
+                }
+            }
+            allHostsInDc.removeAll(allowedDedicatedHostIds);
+        }

Review Comment:
   can move pods, cluster, hosts to methods and return the set?



-- 
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]

Reply via email to