Skip to content

Commit c06e69d

Browse files
committed
CLOUDSTACK-5391:
check for host cpu capability while stop starting a vm on the same host. Also changed the FirstFitAllocator to use the same method.
1 parent 25e51a5 commit c06e69d

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

‎server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
289289
continue;
290290
}
291291

292-
boolean numCpusGood = host.getCpus().intValue() >= offering.getCpu();
293-
boolean cpuFreqGood = host.getSpeed().intValue() >= offering.getSpeed();
294292
int cpu_requested = offering.getCpu() * offering.getSpeed();
295293
long ram_requested = offering.getRamSize() * 1024L * 1024L;
296294
Cluster cluster = _clusterDao.findById(host.getClusterId());
@@ -299,17 +297,18 @@ protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, V
299297
Float cpuOvercommitRatio = Float.parseFloat(clusterDetailsCpuOvercommit.getValue());
300298
Float memoryOvercommitRatio = Float.parseFloat(clusterDetailsRamOvercommmt.getValue());
301299

300+
boolean hostHasCpuCapability = _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed());
302301
boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio,
303302
considerReservedCapacity);
304303

305-
if (numCpusGood && cpuFreqGood && hostHasCapacity) {
304+
if (hostHasCpuCapability && hostHasCapacity) {
306305
if (s_logger.isDebugEnabled()) {
307306
s_logger.debug("Found a suitable host, adding to list: " + host.getId());
308307
}
309308
suitableHosts.add(host);
310309
} else {
311310
if (s_logger.isDebugEnabled()) {
312-
s_logger.debug("Not using host " + host.getId() + "; numCpusGood: " + numCpusGood + "; cpuFreqGood: " + cpuFreqGood + ", host has capacity?" + hostHasCapacity);
311+
s_logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + hostHasCpuCapability + ", host has capacity?" + hostHasCapacity);
313312
}
314313
avoid.addHost(host.getId());
315314
}

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
3232
import org.apache.cloudstack.affinity.AffinityGroupService;
33-
import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
33+
import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
3434
import org.apache.cloudstack.affinity.AffinityGroupVO;
3535
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
3636
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
@@ -56,11 +56,11 @@
5656
import com.cloud.dc.ClusterVO;
5757
import com.cloud.dc.DataCenter;
5858
import com.cloud.dc.DataCenterVO;
59-
import com.cloud.dc.DedicatedResourceVO;
59+
import com.cloud.dc.DedicatedResourceVO;
6060
import com.cloud.dc.Pod;
6161
import com.cloud.dc.dao.ClusterDao;
6262
import com.cloud.dc.dao.DataCenterDao;
63-
import com.cloud.dc.dao.DedicatedResourceDao;
63+
import com.cloud.dc.dao.DedicatedResourceDao;
6464
import com.cloud.dc.dao.HostPodDao;
6565
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
6666
import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
@@ -102,7 +102,7 @@
102102
import com.cloud.utils.db.TransactionCallback;
103103
import com.cloud.utils.db.TransactionCallbackNoReturn;
104104
import com.cloud.utils.db.TransactionStatus;
105-
import com.cloud.utils.exception.CloudRuntimeException;
105+
import com.cloud.utils.exception.CloudRuntimeException;
106106
import com.cloud.utils.fsm.StateListener;
107107
import com.cloud.vm.DiskProfile;
108108
import com.cloud.vm.ReservationContext;
@@ -176,7 +176,7 @@ public void setHostAllocators(List<HostAllocator> _hostAllocators) {
176176
@Inject protected HostDao _hostDao;
177177
@Inject protected HostPodDao _podDao;
178178
@Inject protected ClusterDao _clusterDao;
179-
@Inject protected DedicatedResourceDao _dedicatedDao;
179+
@Inject protected DedicatedResourceDao _dedicatedDao;
180180
@Inject protected GuestOSDao _guestOSDao = null;
181181
@Inject protected GuestOSCategoryDao _guestOSCategoryDao = null;
182182
@Inject protected DiskOfferingDao _diskOfferingDao;
@@ -216,7 +216,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
216216
// call affinitygroup chain
217217
VirtualMachine vm = vmProfile.getVirtualMachine();
218218
long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
219-
DataCenter dc = _dcDao.findById(vm.getDataCenterId());
219+
DataCenter dc = _dcDao.findById(vm.getDataCenterId());
220220

221221
if (vmGroupCount > 0) {
222222
for (AffinityGroupProcessor processor : _affinityProcessors) {
@@ -226,14 +226,14 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
226226

227227
if (vm.getType() == VirtualMachine.Type.User) {
228228
checkForNonDedicatedResources(vmProfile, dc, avoids);
229-
}
229+
}
230230
if (s_logger.isDebugEnabled()) {
231231
s_logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: "
232232
+ avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid());
233233
}
234234

235235
// call planners
236-
//DataCenter dc = _dcDao.findById(vm.getDataCenterId());
236+
//DataCenter dc = _dcDao.findById(vm.getDataCenterId());
237237
// check if datacenter is in avoid set
238238
if (avoids.shouldAvoid(dc)) {
239239
if (s_logger.isDebugEnabled()) {
@@ -308,7 +308,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
308308
List<Host> suitableHosts = new ArrayList<Host>();
309309
suitableHosts.add(host);
310310
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
311-
suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile, plan ,avoids));
311+
suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile, plan ,avoids));
312312
if (potentialResources != null) {
313313
Pod pod = _podDao.findById(host.getPodId());
314314
Cluster cluster = _clusterDao.findById(host.getClusterId());
@@ -350,7 +350,8 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
350350
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
351351
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
352352
if (_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true,
353-
cpuOvercommitRatio, memoryOvercommitRatio, true)) {
353+
cpuOvercommitRatio, memoryOvercommitRatio, true)
354+
&& _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed())) {
354355
s_logger.debug("The last host of this VM is UP and has enough capacity");
355356
s_logger.debug("Now checking for suitable pools under zone: " + host.getDataCenterId()
356357
+ ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());
@@ -362,13 +363,13 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
362363
vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
363364
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
364365
List<Volume> readyAndReusedVolumes = result.second();
365-
366+
366367
// choose the potential pool for this VM for this host
367368
if (!suitableVolumeStoragePools.isEmpty()) {
368369
List<Host> suitableHosts = new ArrayList<Host>();
369370
suitableHosts.add(host);
370371
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
371-
suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile, plan ,avoids));
372+
suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile, plan ,avoids));
372373
if (potentialResources != null) {
373374
Pod pod = _podDao.findById(host.getPodId());
374375
Cluster cluster = _clusterDao.findById(host.getClusterId());
@@ -418,7 +419,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
418419
resetAvoidSet(plannerAvoidOutput, plannerAvoidInput);
419420

420421
dest = checkClustersforDestination(clusterList, vmProfile, plan, avoids, dc,
421-
getPlannerUsage(planner, vmProfile, plan, avoids), plannerAvoidOutput);
422+
getPlannerUsage(planner, vmProfile, plan, avoids), plannerAvoidOutput);
422423
if (dest != null) {
423424
return dest;
424425
}
@@ -453,7 +454,7 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile,
453454
return dest;
454455
}
455456

456-
private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) {
457+
private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) {
457458
boolean isExplicit = false;
458459
VirtualMachine vm = vmProfile.getVirtualMachine();
459460

@@ -488,16 +489,16 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data
488489
}
489490

490491
// check affinity group of type Explicit dedication exists. If No put
491-
// dedicated pod/cluster/host in avoid list
492-
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
493-
494-
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()){
495-
isExplicit = true;
496-
}
497-
498-
if (!isExplicit) {
499-
//add explicitly dedicated resources in avoidList
500-
492+
// dedicated pod/cluster/host in avoid list
493+
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
494+
495+
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()){
496+
isExplicit = true;
497+
}
498+
499+
if (!isExplicit) {
500+
//add explicitly dedicated resources in avoidList
501+
501502
List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
502503
List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
503504
allPodsInDc.retainAll(allDedicatedPods);
@@ -511,10 +512,10 @@ private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, Data
511512
List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId());
512513
List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts();
513514
allHostsInDc.retainAll(allDedicatedHosts);
514-
avoids.addHostList(allHostsInDc);
515-
}
516-
}
517-
515+
avoids.addHostList(allHostsInDc);
516+
}
517+
}
518+
518519
private void resetAvoidSet(ExcludeList avoidSet, ExcludeList removeSet) {
519520
if (avoidSet.getDataCentersToAvoid() != null && removeSet.getDataCentersToAvoid() != null) {
520521
avoidSet.getDataCentersToAvoid().removeAll(removeSet.getDataCentersToAvoid());
@@ -533,9 +534,9 @@ private void resetAvoidSet(ExcludeList avoidSet, ExcludeList removeSet) {
533534
}
534535
}
535536

536-
private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException {
537+
private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException {
537538
if (planner != null && planner instanceof DeploymentClusterPlanner) {
538-
return ((DeploymentClusterPlanner) planner).getResourceUsage(vmProfile, plan, avoids);
539+
return ((DeploymentClusterPlanner) planner).getResourceUsage(vmProfile, plan, avoids);
539540
} else {
540541
return DeploymentPlanner.PlannerResourceUsage.Shared;
541542
}

0 commit comments

Comments
 (0)