This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.18 by this push:
     new 4e7c6682fd4 While starting VM with considerlasthost enabled, don't 
load host tags/details for the last host when it doesn't exist (#9037)
4e7c6682fd4 is described below

commit 4e7c6682fd4959787b6422e9e5ae5560f571d2d5
Author: Suresh Kumar Anaparti <[email protected]>
AuthorDate: Wed Jun 12 11:19:03 2024 +0530

    While starting VM with considerlasthost enabled, don't load host 
tags/details for the last host when it doesn't exist (#9037)
---
 .../deploy/DeploymentPlanningManagerImpl.java      | 176 +++++++++++----------
 1 file changed, 89 insertions(+), 87 deletions(-)

diff --git 
a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java 
b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index 0ef462bb96c..b70530ef6db 100644
--- a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -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());
-
-                        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 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;
+                _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());
+
+                            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);
                             }
 
-                            // 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);
+                            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;
                                 }
+
+                                // 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 ");

Reply via email to