You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "DaanHoogland (via GitHub)" <gi...@apache.org> on 2025/11/14 08:34:00 UTC

Re: [PR] Deployment plan fixes for VM with last host, and last host in maintenance [cloudstack]

DaanHoogland commented on code in PR #12062:
URL: https://github.com/apache/cloudstack/pull/12062#discussion_r2526454921


##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -384,13 +384,25 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
         boolean considerLastHost = vm.getLastHostId() != null && haVmTag == null &&
                 (considerLastHostStr == null || Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr));
         if (considerLastHost) {
+            logger.debug("This VM has last host_id: {}", vm.getLastHostId());
             HostVO host = _hostDao.findById(vm.getLastHostId());
-            logger.debug("This VM has last host_id specified, trying to choose the same host: " + host);
-            lastHost = host;
-
-            DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
-            if (deployDestination != null) {
-                return deployDestination;
+            if (host == null) {
+                if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
+                    throw new CloudRuntimeException(String.format("Failed to deploy VM %s, last host doesn't exist", vm.getName()));
+                }

Review Comment:
   it seems to me that if last host doesn’t exist we should just try any other host.



##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -384,13 +384,25 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
         boolean considerLastHost = vm.getLastHostId() != null && haVmTag == null &&
                 (considerLastHostStr == null || Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr));
         if (considerLastHost) {
+            logger.debug("This VM has last host_id: {}", vm.getLastHostId());
             HostVO host = _hostDao.findById(vm.getLastHostId());
-            logger.debug("This VM has last host_id specified, trying to choose the same host: " + host);
-            lastHost = host;
-
-            DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
-            if (deployDestination != null) {
-                return deployDestination;
+            if (host == null) {
+                if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
+                    throw new CloudRuntimeException(String.format("Failed to deploy VM %s, last host doesn't exist", vm.getName()));
+                }
+            } else {
+                logger.debug("VM's last host is {}, trying to choose the same host if it is not in maintenance state", host);
+                if (host.isInMaintenanceStates()) {
+                    if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
+                        throw new CloudRuntimeException(String.format("Failed to deploy VM %s, last host %s is in maintenance state", vm.getName(), host.getName()));
+                    }
+                } else {
+                    lastHost = host;
+                    DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
+                    if (deployDestination != null) {
+                        return deployDestination;
+                    }
+                }

Review Comment:
   can you extract, for instance to checkPlanAvoidingManitenance() or so



##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -384,13 +384,25 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
         boolean considerLastHost = vm.getLastHostId() != null && haVmTag == null &&
                 (considerLastHostStr == null || Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr));
         if (considerLastHost) {
+            logger.debug("This VM has last host_id: {}", vm.getLastHostId());
             HostVO host = _hostDao.findById(vm.getLastHostId());
-            logger.debug("This VM has last host_id specified, trying to choose the same host: " + host);
-            lastHost = host;
-
-            DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
-            if (deployDestination != null) {
-                return deployDestination;
+            if (host == null) {
+                if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
+                    throw new CloudRuntimeException(String.format("Failed to deploy VM %s, last host doesn't exist", vm.getName()));
+                }
+            } else {
+                logger.debug("VM's last host is {}, trying to choose the same host if it is not in maintenance state", host);
+                if (host.isInMaintenanceStates()) {
+                    if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
+                        throw new CloudRuntimeException(String.format("Failed to deploy VM %s, last host %s is in maintenance state", vm.getName(), host.getName()));
+                    }

Review Comment:
   same here. it is `considerLastHost`, not `’demand’LastHost`, right?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org