Github user koushik-das commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1853#discussion_r106590720
  
    --- Diff: server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java ---
    @@ -584,105 +583,64 @@ private void 
checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data
                 isExplicit = true;
             }
     
    -        List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
    -        List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
    -        allPodsInDc.retainAll(allDedicatedPods);
    -
    -        List<Long> allClustersInDc = 
_clusterDao.listAllCusters(dc.getId());
    -        List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters();
    -        allClustersInDc.retainAll(allDedicatedClusters);
    -
    -        List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId());
    -        List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts();
    -        allHostsInDc.retainAll(allDedicatedHosts);
    -
    -        //Only when the type is instance VM and not explicitly dedicated.
    -        if (vm.getType() == VirtualMachine.Type.User && !isExplicit) {
    -            //add explicitly dedicated resources in avoidList
    -
    -            avoids.addPodList(allPodsInDc);
    -            avoids.addClusterList(allClustersInDc);
    -            avoids.addHostList(allHostsInDc);
    -        }
    -
    -        //Handle the Virtual Router Case
    -        //No need to check the isExplicit. As both the cases are handled.
    -        if (vm.getType() == VirtualMachine.Type.DomainRouter) {
    -            long vmAccountId = vm.getAccountId();
    -            long vmDomainId = vm.getDomainId();
    -
    -            //Lists all explicitly dedicated resources from vm account ID 
or domain ID.
    -            List<Long> allPodsFromDedicatedID = new ArrayList<Long>();
    -            List<Long> allClustersFromDedicatedID = new ArrayList<Long>();
    -            List<Long> allHostsFromDedicatedID = new ArrayList<Long>();
    -
    -            //Whether the dedicated resources belong to Domain or not. If 
not, it may belongs to Account or no dedication.
    -            List<AffinityGroupDomainMapVO> domainGroupMappings = 
_affinityGroupDomainMapDao.listByDomain(vmDomainId);
    -
    -            //For temporary storage and indexing.
    -            List<DedicatedResourceVO> tempStorage;
    -
    -            if (domainGroupMappings == null || 
domainGroupMappings.isEmpty()) {
    -                //The dedicated resource belongs to VM Account ID.
    -
    -                tempStorage = _dedicatedDao.searchDedicatedPods(null, 
vmDomainId, vmAccountId, null).first();
    -
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allPodsFromDedicatedID.add(vo.getPodId());
    -                }
    -
    -                tempStorage.clear();
    -                tempStorage = _dedicatedDao.searchDedicatedClusters(null, 
vmDomainId, vmAccountId, null).first();
    +        if ((vm.getType() == VirtualMachine.Type.User && !isExplicit) || 
vm.getType() == VirtualMachine.Type.DomainRouter) {
    +            List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
    +            List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
    +            allPodsInDc.retainAll(allDedicatedPods);
     
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allClustersFromDedicatedID.add(vo.getClusterId());
    -                }
    +            List<Long> allClustersInDc = 
_clusterDao.listAllCusters(dc.getId());
    +            List<Long> allDedicatedClusters = 
_dedicatedDao.listAllClusters();
    +            allClustersInDc.retainAll(allDedicatedClusters);
     
    -                tempStorage.clear();
    -                tempStorage = _dedicatedDao.searchDedicatedHosts(null, 
vmDomainId, vmAccountId, null).first();
    +            List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId());
    +            List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts();
    +            allHostsInDc.retainAll(allDedicatedHosts);
     
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allHostsFromDedicatedID.add(vo.getHostId());
    -                }
    +            //Only when the type is instance VM and not explicitly 
dedicated.
    +            if (vm.getType() == VirtualMachine.Type.User && !isExplicit) {
    +                //add explicitly dedicated resources in avoidList
     
    -                //Remove the dedicated ones from main list
    -                allPodsInDc.removeAll(allPodsFromDedicatedID);
    -                allClustersInDc.removeAll(allClustersFromDedicatedID);
    -                allHostsInDc.removeAll(allHostsFromDedicatedID);
    +                avoids.addPodList(allPodsInDc);
    +                avoids.addClusterList(allClustersInDc);
    +                avoids.addHostList(allHostsInDc);
                 }
    -            else {
    -                //The dedicated resource belongs to VM Domain ID or No 
dedication.
     
    -                tempStorage = _dedicatedDao.searchDedicatedPods(null, 
vmDomainId, null, null).first();
    +            //Handle the Virtual Router Case
    +            //No need to check the isExplicit. As both the cases are 
handled.
    +            if (vm.getType() == VirtualMachine.Type.DomainRouter) {
    +                long vmAccountId = vm.getAccountId();
    +                long vmDomainId = vm.getDomainId();
     
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allPodsFromDedicatedID.add(vo.getPodId());
    -                }
    +                List<Long> allPodsFromDedicatedID = new ArrayList<Long>();
    +                List<Long> allClustersFromDedicatedID = new 
ArrayList<Long>();
    +                List<Long> allHostsFromDedicatedID = new ArrayList<Long>();
     
    -                tempStorage.clear();
    -                tempStorage = _dedicatedDao.searchDedicatedClusters(null, 
vmDomainId, null, null).first();
    -
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allClustersFromDedicatedID.add(vo.getClusterId());
    -                }
    +                for (DedicatedResourceVO vo : 
_dedicatedDao.listAvailableResources(vmAccountId, vmDomainId)) {
    +                    if (vo.getPodId() != null) {
    +                        allPodsFromDedicatedID.add(vo.getPodId());
    +                        continue;
    +                    }
     
    -                tempStorage.clear();
    -                tempStorage = _dedicatedDao.searchDedicatedHosts(null, 
vmDomainId, null, null).first();
    +                    if (vo.getClusterId() != null) {
    +                        allClustersFromDedicatedID.add(vo.getClusterId());
    +                        continue;
    +                    }
     
    -                for(DedicatedResourceVO vo : tempStorage) {
    -                    allHostsFromDedicatedID.add(vo.getHostId());
    +                    if (vo.getHostId() != null) {
    +                        allHostsFromDedicatedID.add(vo.getHostId());
    +                    }
                     }
     
                     //Remove the dedicated ones from main list
                     allPodsInDc.removeAll(allPodsFromDedicatedID);
    --- End diff --
    
    @anshul1886 As per the code for user VMs without explicit dedication, all 
dedicated resources are put in 'avoid' list so deployment happens in 
non-dedicated resources only. This part is clear. But for VR the opposite is 
happening as per the code. Can you explain the VR part from code?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to