Skip to content

Commit 093cccf

Browse files
committed
Merge pull request #945 from nitin-maharana/CloudStack-Nitin11
CLOUDSTACK-8962: Dedicated cluster is used for virtual routers that belong to non-dedicated account Earlier the deployment planner was not handling the case of virtual routers.(In Explicit Dedication) It was only handling for all instance VMs/user VMs. Added code for checking the case of Virtual Routers. * pr/945: CLOUDSTACK-8962: Dedicated cluster is used for virtual routers that belong to non-dedicated account Signed-off-by: Remi Bergsma <[email protected]>
2 parents d8f9c23 + adcd23d commit 093cccf

File tree

2 files changed

+105
-13
lines changed

2 files changed

+105
-13
lines changed

server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.apache.cloudstack.affinity.AffinityGroupService;
3939
import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
4040
import org.apache.cloudstack.affinity.AffinityGroupVO;
41+
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
4142
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
4243
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
44+
import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
4345
import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
4446
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
4547
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@@ -147,6 +149,8 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy
147149
@Inject
148150
protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
149151
@Inject
152+
protected AffinityGroupDomainMapDao _affinityGroupDomainMapDao;
153+
@Inject
150154
AffinityGroupService _affinityGroupService;
151155
@Inject
152156
DataCenterDao _dcDao;
@@ -258,7 +262,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
258262
}
259263
}
260264

261-
if (vm.getType() == VirtualMachine.Type.User) {
265+
if (vm.getType() == VirtualMachine.Type.User || vm.getType() == VirtualMachine.Type.DomainRouter) {
262266
checkForNonDedicatedResources(vmProfile, dc, avoids);
263267
}
264268
if (s_logger.isDebugEnabled()) {
@@ -547,7 +551,7 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data
547551
boolean isExplicit = false;
548552
VirtualMachine vm = vmProfile.getVirtualMachine();
549553

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.
551555
DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId());
552556
if (dedicatedZone != null && !_accountMgr.isRootAdmin(vmProfile.getOwner().getId())) {
553557
long accountDomainId = vmProfile.getOwner().getDomainId();
@@ -582,22 +586,104 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data
582586
isExplicit = true;
583587
}
584588

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) {
586603
//add explicitly dedicated resources in avoidList
587604

588-
List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
589-
List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
590-
allPodsInDc.retainAll(allDedicatedPods);
591605
avoids.addPodList(allPodsInDc);
592-
593-
List<Long> allClustersInDc = _clusterDao.listAllCusters(dc.getId());
594-
List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters();
595-
allClustersInDc.retainAll(allDedicatedClusters);
596606
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+
}
597642

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);
601687
avoids.addHostList(allHostsInDc);
602688
}
603689
}

server/test/com/cloud/vm/DeploymentPlanningManagerImplTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28+
import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
2829
import org.junit.Before;
2930
import org.junit.BeforeClass;
3031
import org.junit.Test;
@@ -261,6 +262,11 @@ public ServiceOfferingDetailsDao serviceOfferingDetailsDao() {
261262
return Mockito.mock(ServiceOfferingDetailsDao.class);
262263
}
263264

265+
@Bean
266+
public AffinityGroupDomainMapDao affinityGroupDomainMapDao() {
267+
return Mockito.mock(AffinityGroupDomainMapDao.class);
268+
}
269+
264270
@Bean
265271
public DataStoreManager cataStoreManager() {
266272
return Mockito.mock(DataStoreManager.class);

0 commit comments

Comments
 (0)