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


##########
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:
   done



##########
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:
   done



##########
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:
   done



-- 
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