sureshanaparti commented on code in PR #9037:
URL: https://github.com/apache/cloudstack/pull/9037#discussion_r1593853373


##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -415,105 +415,107 @@ public DeployDestination 
planDeployment(VirtualMachineProfile vmProfile, Deploym
             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 {

Review Comment:
   @shwstppr there was some refactoring done on this code, in PR #7214 , will 
see if any further refactoring required (if so, that will be targeted to main, 
on a separate PR)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to