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

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


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

commit 6fda757936bccc8a39c878081ec7e66a76b4e622
Author: Suresh Kumar Anaparti <sureshkumar.anapa...@gmail.com>
AuthorDate: Wed Jun 12 20:33:18 2024 +0530

    While starting VM with 'considerlasthost' enabled, don't load host 
tags/details for the last host when it doesn't exist [main] (#9063)
---
 .../src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java        | 4 ++++
 .../main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java    | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index 09c3e37bed9..4772a5ad92d 100755
--- 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++ 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1077,6 +1077,10 @@ public class VirtualMachineManagerImpl extends 
ManagerBase implements VirtualMac
             return;
         }
         Host lastHost = _hostDao.findById(vm.getLastHostId());
+        if (lastHost == null) {
+            logger.warn("Could not find last host with id [{}], skipping 
migrate VM [{}] across cluster check." , vm.getLastHostId(), vm.getUuid());
+            return;
+        }
         if (destinationClusterId.equals(lastHost.getClusterId())) {
             return;
         }
diff --git 
a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java 
b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index d97fcef7453..22670c52449 100644
--- a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -458,10 +458,9 @@ StateListener<State, VirtualMachine.Event, 
VirtualMachine>, Configurable {
             DeploymentPlanner planner, VirtualMachine vm, DataCenter dc, 
ServiceOffering offering, int cpuRequested, long ramRequested,
             boolean volumesRequireEncryption) throws 
InsufficientServerCapacityException {
         HostVO host = _hostDao.findById(vm.getLastHostId());
-        _hostDao.loadHostTags(host);
-        _hostDao.loadDetails(host);
-
         if (canUseLastHost(host, avoids, plan, vm, offering, 
volumesRequireEncryption)) {
+            _hostDao.loadHostTags(host);
+            _hostDao.loadDetails(host);
             if (host.getStatus() != Status.Up) {
                 logger.debug("Cannot deploy VM [{}] to the last host [{}] 
because this host is not in UP state or is not enabled. Host current status 
[{}] and resource status [{}].",
                         vm.getUuid(), host.getUuid(), host.getState().name(), 
host.getResourceState());

Reply via email to