mirror of https://github.com/apache/cloudstack.git
Fix bulk power state query missing VM lifecycle state field (#13027)
* Fix bulk power state query missing VM lifecycle state field The IdsPowerStateSelectSearch partial select did not include the VM lifecycle state, causing isPowerStateInSyncWithInstanceState to always return true when state was null. This prevented retry of failed StopCommands on subsequent ping cycles. * Add defensive check for instance host ID to prevent NPE Co-authored-by: Sachin R Doddaguni <s_rudrappadoddagu@apple.com> Co-authored-by: nvazquez <nicovazquez90@gmail.com>
This commit is contained in:
parent
0b169920f3
commit
ffebe8eaa6
|
|
@ -358,7 +358,8 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
IdsPowerStateSelectSearch.entity().getPowerHostId(),
|
||||
IdsPowerStateSelectSearch.entity().getPowerState(),
|
||||
IdsPowerStateSelectSearch.entity().getPowerStateUpdateCount(),
|
||||
IdsPowerStateSelectSearch.entity().getPowerStateUpdateTime());
|
||||
IdsPowerStateSelectSearch.entity().getPowerStateUpdateTime(),
|
||||
IdsPowerStateSelectSearch.entity().getState());
|
||||
IdsPowerStateSelectSearch.done();
|
||||
|
||||
CountByOfferingId = createSearchBuilder(Integer.class);
|
||||
|
|
@ -1105,10 +1106,14 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
|
||||
private boolean isPowerStateInSyncWithInstanceState(final VirtualMachine.PowerState powerState, final long powerHostId, final VMInstanceVO instance) {
|
||||
State instanceState = instance.getState();
|
||||
if (instanceState == null) {
|
||||
logger.warn("VM {} has null instance state during power state sync check, treating as out of sync", instance);
|
||||
return false;
|
||||
}
|
||||
if ((powerState == VirtualMachine.PowerState.PowerOff && instanceState == State.Running)
|
||||
|| (powerState == VirtualMachine.PowerState.PowerOn && instanceState == State.Stopped)) {
|
||||
HostVO instanceHost = hostDao.findById(instance.getHostId());
|
||||
HostVO powerHost = powerHostId == instance.getHostId() ? instanceHost : hostDao.findById(powerHostId);
|
||||
HostVO powerHost = instance.getHostId() != null && powerHostId == instance.getHostId() ? instanceHost : hostDao.findById(powerHostId);
|
||||
logger.debug("VM: {} on host: {} and power host : {} is in {} state, but power state is {}",
|
||||
instance, instanceHost, powerHost, instanceState, powerState);
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue