Skip to content

Commit ca792ef

Browse files
author
Anurag Awasthi
committed
Added additional check for migrating VMs
1 parent 06c4521 commit ca792ef

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ protected boolean attemptMaintain(HostVO host) throws NoTransitionException {
14091409

14101410
// Step 0: First gather if VMs have pending HAWork for migration with retries left.
14111411
final List<VMInstanceVO> allVmsOnHost = _vmDao.listByHostId(hostId);
1412+
final boolean hasMigratingAwayVms = CollectionUtils.isNotEmpty(_vmDao.listVmsMigratingFromHost(hostId));
14121413
boolean hasPendingMigrationRetries = false;
14131414
for (VMInstanceVO vmInstanceVO : allVmsOnHost) {
14141415
if (_haMgr.hasPendingMigrationsWork(vmInstanceVO.getId())) {
@@ -1419,7 +1420,7 @@ protected boolean attemptMaintain(HostVO host) throws NoTransitionException {
14191420
}
14201421

14211422
// Step 1: If there are no VMs in migrating, running, starting, stopping, error or unknown state we can safely move the host to maintenance.
1422-
if (CollectionUtils.isEmpty(_vmDao.findByHostInStates(host.getId(),
1423+
if (!hasMigratingAwayVms && CollectionUtils.isEmpty(_vmDao.findByHostInStates(host.getId(),
14231424
State.Migrating, State.Running, State.Starting, State.Stopping, State.Error, State.Unknown))) {
14241425
if (hasPendingMigrationRetries) {
14251426
s_logger.error("There should not be pending retries VMs for this host as there are no running, migrating," +
@@ -1431,7 +1432,6 @@ protected boolean attemptMaintain(HostVO host) throws NoTransitionException {
14311432
// Step 2: Gather relevant VMs' states on the host and then based on them we can determine if
14321433
final List<VMInstanceVO> failedMigrations = new ArrayList<>(_vmDao.listNonMigratingVmsByHostEqualsLastHost(hostId));
14331434
final List<VMInstanceVO> errorVms = new ArrayList<>(_vmDao.findByHostInStates(hostId, State.Unknown, State.Error));
1434-
final boolean hasMigratingAwayVms = CollectionUtils.isNotEmpty(_vmDao.listVmsMigratingFromHost(hostId));
14351435
final boolean hasRunningVms = CollectionUtils.isNotEmpty(_vmDao.findByHostInStates(hostId, State.Running));
14361436
final boolean hasFailedMigrations = CollectionUtils.isNotEmpty(failedMigrations);
14371437
final boolean hasVmsInFailureStates = CollectionUtils.isNotEmpty(errorVms);

0 commit comments

Comments
 (0)