|
38 | 38 | import org.apache.cloudstack.affinity.AffinityGroupService; |
39 | 39 | import org.apache.cloudstack.affinity.AffinityGroupVMMapVO; |
40 | 40 | import org.apache.cloudstack.affinity.AffinityGroupVO; |
| 41 | +import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO; |
41 | 42 | import org.apache.cloudstack.affinity.dao.AffinityGroupDao; |
42 | 43 | import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; |
| 44 | +import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao; |
43 | 45 | import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; |
44 | 46 | import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao; |
45 | 47 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
@@ -147,6 +149,8 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy |
147 | 149 | @Inject |
148 | 150 | protected AffinityGroupVMMapDao _affinityGroupVMMapDao; |
149 | 151 | @Inject |
| 152 | + protected AffinityGroupDomainMapDao _affinityGroupDomainMapDao; |
| 153 | + @Inject |
150 | 154 | AffinityGroupService _affinityGroupService; |
151 | 155 | @Inject |
152 | 156 | DataCenterDao _dcDao; |
@@ -258,7 +262,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym |
258 | 262 | } |
259 | 263 | } |
260 | 264 |
|
261 | | - if (vm.getType() == VirtualMachine.Type.User) { |
| 265 | + if (vm.getType() == VirtualMachine.Type.User || vm.getType() == VirtualMachine.Type.DomainRouter) { |
262 | 266 | checkForNonDedicatedResources(vmProfile, dc, avoids); |
263 | 267 | } |
264 | 268 | if (s_logger.isDebugEnabled()) { |
@@ -547,7 +551,7 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data |
547 | 551 | boolean isExplicit = false; |
548 | 552 | VirtualMachine vm = vmProfile.getVirtualMachine(); |
549 | 553 |
|
550 | | - // check if zone is dedicated. if yes check if vm owner has acess to it. |
| 554 | + // check if zone is dedicated. if yes check if vm owner has access to it. |
551 | 555 | DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId()); |
552 | 556 | if (dedicatedZone != null && !_accountMgr.isRootAdmin(vmProfile.getOwner().getId())) { |
553 | 557 | long accountDomainId = vmProfile.getOwner().getDomainId(); |
@@ -582,22 +586,104 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data |
582 | 586 | isExplicit = true; |
583 | 587 | } |
584 | 588 |
|
585 | | - if (!isExplicit) { |
| 589 | + List<Long> allPodsInDc = _podDao.listAllPods(dc.getId()); |
| 590 | + List<Long> allDedicatedPods = _dedicatedDao.listAllPods(); |
| 591 | + allPodsInDc.retainAll(allDedicatedPods); |
| 592 | + |
| 593 | + List<Long> allClustersInDc = _clusterDao.listAllCusters(dc.getId()); |
| 594 | + List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters(); |
| 595 | + allClustersInDc.retainAll(allDedicatedClusters); |
| 596 | + |
| 597 | + List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId()); |
| 598 | + List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts(); |
| 599 | + allHostsInDc.retainAll(allDedicatedHosts); |
| 600 | + |
| 601 | + //Only when the type is instance VM and not explicitly dedicated. |
| 602 | + if (vm.getType() == VirtualMachine.Type.User && !isExplicit) { |
586 | 603 | //add explicitly dedicated resources in avoidList |
587 | 604 |
|
588 | | - List<Long> allPodsInDc = _podDao.listAllPods(dc.getId()); |
589 | | - List<Long> allDedicatedPods = _dedicatedDao.listAllPods(); |
590 | | - allPodsInDc.retainAll(allDedicatedPods); |
591 | 605 | avoids.addPodList(allPodsInDc); |
592 | | - |
593 | | - List<Long> allClustersInDc = _clusterDao.listAllCusters(dc.getId()); |
594 | | - List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters(); |
595 | | - allClustersInDc.retainAll(allDedicatedClusters); |
596 | 606 | avoids.addClusterList(allClustersInDc); |
| 607 | + avoids.addHostList(allHostsInDc); |
| 608 | + } |
| 609 | + |
| 610 | + //Handle the Virtual Router Case |
| 611 | + //No need to check the isExplicit. As both the cases are handled. |
| 612 | + if (vm.getType() == VirtualMachine.Type.DomainRouter) { |
| 613 | + long vmAccountId = vm.getAccountId(); |
| 614 | + long vmDomainId = vm.getDomainId(); |
| 615 | + |
| 616 | + //Lists all explicitly dedicated resources from vm account ID or domain ID. |
| 617 | + List<Long> allPodsFromDedicatedID = new ArrayList<Long>(); |
| 618 | + List<Long> allClustersFromDedicatedID = new ArrayList<Long>(); |
| 619 | + List<Long> allHostsFromDedicatedID = new ArrayList<Long>(); |
| 620 | + |
| 621 | + //Whether the dedicated resources belong to Domain or not. If not, it may belongs to Account or no dedication. |
| 622 | + List<AffinityGroupDomainMapVO> domainGroupMappings = _affinityGroupDomainMapDao.listByDomain(vmDomainId); |
| 623 | + |
| 624 | + //For temporary storage and indexing. |
| 625 | + List<DedicatedResourceVO> tempStorage; |
| 626 | + |
| 627 | + if (domainGroupMappings == null || domainGroupMappings.isEmpty()) { |
| 628 | + //The dedicated resource belongs to VM Account ID. |
| 629 | + |
| 630 | + tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null).first(); |
| 631 | + |
| 632 | + for(DedicatedResourceVO vo : tempStorage) { |
| 633 | + allPodsFromDedicatedID.add(vo.getPodId()); |
| 634 | + } |
| 635 | + |
| 636 | + tempStorage.clear(); |
| 637 | + tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null).first(); |
| 638 | + |
| 639 | + for(DedicatedResourceVO vo : tempStorage) { |
| 640 | + allClustersFromDedicatedID.add(vo.getClusterId()); |
| 641 | + } |
597 | 642 |
|
598 | | - List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId()); |
599 | | - List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts(); |
600 | | - allHostsInDc.retainAll(allDedicatedHosts); |
| 643 | + tempStorage.clear(); |
| 644 | + tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null).first(); |
| 645 | + |
| 646 | + for(DedicatedResourceVO vo : tempStorage) { |
| 647 | + allHostsFromDedicatedID.add(vo.getHostId()); |
| 648 | + } |
| 649 | + |
| 650 | + //Remove the dedicated ones from main list |
| 651 | + allPodsInDc.removeAll(allPodsFromDedicatedID); |
| 652 | + allClustersInDc.removeAll(allClustersFromDedicatedID); |
| 653 | + allHostsInDc.removeAll(allHostsFromDedicatedID); |
| 654 | + } |
| 655 | + else { |
| 656 | + //The dedicated resource belongs to VM Domain ID or No dedication. |
| 657 | + |
| 658 | + tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null).first(); |
| 659 | + |
| 660 | + for(DedicatedResourceVO vo : tempStorage) { |
| 661 | + allPodsFromDedicatedID.add(vo.getPodId()); |
| 662 | + } |
| 663 | + |
| 664 | + tempStorage.clear(); |
| 665 | + tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null).first(); |
| 666 | + |
| 667 | + for(DedicatedResourceVO vo : tempStorage) { |
| 668 | + allClustersFromDedicatedID.add(vo.getClusterId()); |
| 669 | + } |
| 670 | + |
| 671 | + tempStorage.clear(); |
| 672 | + tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null).first(); |
| 673 | + |
| 674 | + for(DedicatedResourceVO vo : tempStorage) { |
| 675 | + allHostsFromDedicatedID.add(vo.getHostId()); |
| 676 | + } |
| 677 | + |
| 678 | + //Remove the dedicated ones from main list |
| 679 | + allPodsInDc.removeAll(allPodsFromDedicatedID); |
| 680 | + allClustersInDc.removeAll(allClustersFromDedicatedID); |
| 681 | + allHostsInDc.removeAll(allHostsFromDedicatedID); |
| 682 | + } |
| 683 | + |
| 684 | + //Add in avoid list or no addition if no dedication |
| 685 | + avoids.addPodList(allPodsInDc); |
| 686 | + avoids.addClusterList(allClustersInDc); |
601 | 687 | avoids.addHostList(allHostsInDc); |
602 | 688 | } |
603 | 689 | } |
|
0 commit comments