Skip to content

Commit 9071c47

Browse files
Deployment plan fixes for VM with last host
- Consider last host when it is not in maintenance - Fail deployment when user requests for last host consideration and last host doesn't exists or in maintenance
1 parent f0a0936 commit 9071c47

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,26 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
384384
boolean considerLastHost = vm.getLastHostId() != null && haVmTag == null &&
385385
(considerLastHostStr == null || Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr));
386386
if (considerLastHost) {
387+
logger.debug("This VM has last host_id: {}", vm.getLastHostId());
387388
HostVO host = _hostDao.findById(vm.getLastHostId());
388-
logger.debug("This VM has last host_id specified, trying to choose the same host: " + host);
389-
lastHost = host;
389+
if (host == null) {
390+
if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
391+
throw new CloudRuntimeException("Failed to deploy VM, last host doesn't exists");
392+
}
393+
} else {
394+
if (host.isInMaintenanceStates()) {
395+
if (Boolean.TRUE.toString().equalsIgnoreCase(considerLastHostStr)) {
396+
throw new CloudRuntimeException("Failed to deploy VM, last host is in maintenance state");
397+
}
398+
} else {
399+
logger.debug("VM's last {}, trying to choose the same host", host);
400+
lastHost = host;
390401

391-
DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
392-
if (deployDestination != null) {
393-
return deployDestination;
402+
DeployDestination deployDestination = deployInVmLastHost(vmProfile, plan, avoids, planner, vm, dc, offering, cpuRequested, ramRequested, volumesRequireEncryption);
403+
if (deployDestination != null) {
404+
return deployDestination;
405+
}
406+
}
394407
}
395408
}
396409

@@ -1474,7 +1487,7 @@ private Pair<Boolean, Boolean> findVMStorageRequirements(VirtualMachineProfile v
14741487

14751488
protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(List<Host> suitableHosts, Map<Volume, List<StoragePool>> suitableVolumeStoragePools,
14761489
ExcludeList avoid, PlannerResourceUsage resourceUsageRequired, List<Volume> readyAndReusedVolumes, List<Long> preferredHosts, VirtualMachine vm) {
1477-
logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
1490+
logger.debug("Trying to find a potential host and associated storage pools from the suitable host/pool lists for this VM");
14781491

14791492
boolean hostCanAccessPool = false;
14801493
boolean haveEnoughSpace = false;

server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ public Long migrate(final HaWorkVO work) {
833833
if (checkAndCancelWorkIfNeeded(work)) {
834834
return null;
835835
}
836-
logger.info("Migration attempt: for VM {}from host {}. Starting attempt: {}/{} times.", vm, srcHost, 1 + work.getTimesTried(), _maxRetries);
836+
logger.info("Migration attempt: for {} from {}. Starting attempt: {}/{} times.", vm, srcHost, 1 + work.getTimesTried(), _maxRetries);
837837

838838
if (VirtualMachine.State.Stopped.equals(vm.getState())) {
839839
logger.info(String.format("vm %s is Stopped, skipping migrate.", vm));
@@ -843,7 +843,7 @@ public Long migrate(final HaWorkVO work) {
843843
logger.info(String.format("VM %s is running on a different host %s, skipping migration", vm, vm.getHostId()));
844844
return null;
845845
}
846-
logger.info("Migration attempt: for VM " + vm.getUuid() + "from host id " + srcHostId +
846+
logger.info("Migration attempt: for VM " + vm.getUuid() + " from host id " + srcHostId +
847847
". Starting attempt: " + (1 + work.getTimesTried()) + "/" + _maxRetries + " times.");
848848

849849
try {

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ private boolean doMaintain(final long hostId) {
14171417
throw new CloudRuntimeException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
14181418
}
14191419
} else {
1420-
logger.info("Maintenance: scheduling migration of VM {} from host {}", vm, host);
1420+
logger.info("Maintenance: scheduling migration of {} from {}", vm, host);
14211421
_haMgr.scheduleMigration(vm, HighAvailabilityManager.ReasonType.HostMaintenance);
14221422
}
14231423
}

0 commit comments

Comments
 (0)