mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
While starting VM with considerlasthost enabled, don't load host tags/details for the last host when it doesn't exist (#9037)
This commit is contained in:
parent
0b54fbb539
commit
4e7c6682fd
@ -415,105 +415,107 @@ StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
|
||||
s_logger.debug("This VM has last host_id specified, trying to choose the same host: " + vm.getLastHostId());
|
||||
|
||||
HostVO host = _hostDao.findById(vm.getLastHostId());
|
||||
_hostDao.loadHostTags(host);
|
||||
_hostDao.loadDetails(host);
|
||||
ServiceOfferingDetailsVO offeringDetails = null;
|
||||
if (host == null) {
|
||||
s_logger.debug("The last host of this VM cannot be found");
|
||||
} else if (avoids.shouldAvoid(host)) {
|
||||
s_logger.debug("The last host of this VM is in avoid set");
|
||||
} else if (plan.getClusterId() != null && host.getClusterId() != null
|
||||
&& !plan.getClusterId().equals(host.getClusterId())) {
|
||||
s_logger.debug("The last host of this VM cannot be picked as the plan specifies different clusterId: "
|
||||
+ plan.getClusterId());
|
||||
} else if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
|
||||
s_logger.debug("The last Host, hostId: " + host.getId() +
|
||||
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
|
||||
} else if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
|
||||
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
|
||||
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
|
||||
s_logger.debug("The last host of this VM does not have required GPU devices available");
|
||||
}
|
||||
} else if (volumesRequireEncryption && !Boolean.parseBoolean(host.getDetail(Host.HOST_VOLUME_ENCRYPTION))) {
|
||||
s_logger.warn(String.format("The last host of this VM %s does not support volume encryption, which is required by this VM.", host));
|
||||
} else {
|
||||
if (host.getStatus() == Status.Up) {
|
||||
if (checkVmProfileAndHost(vmProfile, host)) {
|
||||
long cluster_id = host.getClusterId();
|
||||
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,
|
||||
"cpuOvercommitRatio");
|
||||
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,
|
||||
"memoryOvercommitRatio");
|
||||
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
|
||||
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
|
||||
_hostDao.loadHostTags(host);
|
||||
_hostDao.loadDetails(host);
|
||||
if (avoids.shouldAvoid(host)) {
|
||||
s_logger.debug("The last host of this VM is in avoid set");
|
||||
} else if (plan.getClusterId() != null && host.getClusterId() != null
|
||||
&& !plan.getClusterId().equals(host.getClusterId())) {
|
||||
s_logger.debug("The last host of this VM cannot be picked as the plan specifies different clusterId: "
|
||||
+ plan.getClusterId());
|
||||
} else if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
|
||||
s_logger.debug("The last Host, hostId: " + host.getId() +
|
||||
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
|
||||
} else if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
|
||||
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
|
||||
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
|
||||
s_logger.debug("The last host of this VM does not have required GPU devices available");
|
||||
}
|
||||
} else if (volumesRequireEncryption && !Boolean.parseBoolean(host.getDetail(Host.HOST_VOLUME_ENCRYPTION))) {
|
||||
s_logger.warn(String.format("The last host of this VM %s does not support volume encryption, which is required by this VM.", host));
|
||||
} else {
|
||||
if (host.getStatus() == Status.Up) {
|
||||
if (checkVmProfileAndHost(vmProfile, host)) {
|
||||
long cluster_id = host.getClusterId();
|
||||
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,
|
||||
"cpuOvercommitRatio");
|
||||
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,
|
||||
"memoryOvercommitRatio");
|
||||
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
|
||||
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
|
||||
|
||||
boolean hostHasCpuCapability, hostHasCapacity = false;
|
||||
hostHasCpuCapability = _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed());
|
||||
boolean hostHasCpuCapability, hostHasCapacity = false;
|
||||
hostHasCpuCapability = _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed());
|
||||
|
||||
if (hostHasCpuCapability) {
|
||||
// first check from reserved capacity
|
||||
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true);
|
||||
if (hostHasCpuCapability) {
|
||||
// first check from reserved capacity
|
||||
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true);
|
||||
|
||||
// if not reserved, check the free capacity
|
||||
if (!hostHasCapacity)
|
||||
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true);
|
||||
}
|
||||
|
||||
boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile);
|
||||
if (hostHasCapacity
|
||||
&& hostHasCpuCapability) {
|
||||
s_logger.debug("The last host of this VM is UP and has enough capacity");
|
||||
s_logger.debug("Now checking for suitable pools under zone: " + host.getDataCenterId()
|
||||
+ ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());
|
||||
|
||||
Pod pod = _podDao.findById(host.getPodId());
|
||||
Cluster cluster = _clusterDao.findById(host.getClusterId());
|
||||
if (vm.getHypervisorType() == HypervisorType.BareMetal) {
|
||||
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, new HashMap<Volume, StoragePool>(), displayStorage);
|
||||
s_logger.debug("Returning Deployment Destination: " + dest);
|
||||
return dest;
|
||||
// if not reserved, check the free capacity
|
||||
if (!hostHasCapacity)
|
||||
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true);
|
||||
}
|
||||
|
||||
// search for storage under the zone, pod, cluster
|
||||
// of
|
||||
// the last host.
|
||||
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(),
|
||||
host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId(), null);
|
||||
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(
|
||||
vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
|
||||
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
|
||||
List<Volume> readyAndReusedVolumes = result.second();
|
||||
boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile);
|
||||
if (hostHasCapacity
|
||||
&& hostHasCpuCapability) {
|
||||
s_logger.debug("The last host of this VM is UP and has enough capacity");
|
||||
s_logger.debug("Now checking for suitable pools under zone: " + host.getDataCenterId()
|
||||
+ ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());
|
||||
|
||||
// choose the potential pool for this VM for this
|
||||
// host
|
||||
if (!suitableVolumeStoragePools.isEmpty()) {
|
||||
List<Host> suitableHosts = new ArrayList<Host>();
|
||||
suitableHosts.add(host);
|
||||
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
|
||||
suitableHosts, suitableVolumeStoragePools, avoids,
|
||||
getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes, plan.getPreferredHosts(), vm);
|
||||
if (potentialResources != null) {
|
||||
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
|
||||
// remove the reused vol<->pool from
|
||||
// destination, since we don't have to
|
||||
// prepare
|
||||
// this volume.
|
||||
for (Volume vol : readyAndReusedVolumes) {
|
||||
storageVolMap.remove(vol);
|
||||
}
|
||||
DeployDestination dest = new DeployDestination(dc, pod, cluster, host,
|
||||
storageVolMap, displayStorage);
|
||||
Pod pod = _podDao.findById(host.getPodId());
|
||||
Cluster cluster = _clusterDao.findById(host.getClusterId());
|
||||
if (vm.getHypervisorType() == HypervisorType.BareMetal) {
|
||||
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, new HashMap<Volume, StoragePool>(), displayStorage);
|
||||
s_logger.debug("Returning Deployment Destination: " + dest);
|
||||
return dest;
|
||||
}
|
||||
|
||||
// search for storage under the zone, pod, cluster
|
||||
// of
|
||||
// the last host.
|
||||
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(),
|
||||
host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId(), null);
|
||||
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(
|
||||
vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
|
||||
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
|
||||
List<Volume> readyAndReusedVolumes = result.second();
|
||||
|
||||
// choose the potential pool for this VM for this
|
||||
// host
|
||||
if (!suitableVolumeStoragePools.isEmpty()) {
|
||||
List<Host> suitableHosts = new ArrayList<Host>();
|
||||
suitableHosts.add(host);
|
||||
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
|
||||
suitableHosts, suitableVolumeStoragePools, avoids,
|
||||
getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes, plan.getPreferredHosts(), vm);
|
||||
if (potentialResources != null) {
|
||||
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
|
||||
// remove the reused vol<->pool from
|
||||
// destination, since we don't have to
|
||||
// prepare
|
||||
// this volume.
|
||||
for (Volume vol : readyAndReusedVolumes) {
|
||||
storageVolMap.remove(vol);
|
||||
}
|
||||
DeployDestination dest = new DeployDestination(dc, pod, cluster, host,
|
||||
storageVolMap, displayStorage);
|
||||
s_logger.debug("Returning Deployment Destination: " + dest);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("The last host of this VM does not have enough capacity");
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("The last host of this VM does not have enough capacity");
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("The last host of this VM is not UP or is not enabled, host status is: " + host.getStatus().name() + ", host resource state is: " +
|
||||
host.getResourceState());
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("The last host of this VM is not UP or is not enabled, host status is: " + host.getStatus().name() + ", host resource state is: " +
|
||||
host.getResourceState());
|
||||
}
|
||||
}
|
||||
s_logger.debug("Cannot choose the last host to deploy this VM ");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user