Skip to content

Commit ffebe8e

Browse files
sureshanapartiSachin R Doddaguninvazquez
authored
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>
1 parent 0b16992 commit ffebe8e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ protected void init() {
358358
IdsPowerStateSelectSearch.entity().getPowerHostId(),
359359
IdsPowerStateSelectSearch.entity().getPowerState(),
360360
IdsPowerStateSelectSearch.entity().getPowerStateUpdateCount(),
361-
IdsPowerStateSelectSearch.entity().getPowerStateUpdateTime());
361+
IdsPowerStateSelectSearch.entity().getPowerStateUpdateTime(),
362+
IdsPowerStateSelectSearch.entity().getState());
362363
IdsPowerStateSelectSearch.done();
363364

364365
CountByOfferingId = createSearchBuilder(Integer.class);
@@ -1105,10 +1106,14 @@ public Map<Long, VirtualMachine.PowerState> updatePowerState(
11051106

11061107
private boolean isPowerStateInSyncWithInstanceState(final VirtualMachine.PowerState powerState, final long powerHostId, final VMInstanceVO instance) {
11071108
State instanceState = instance.getState();
1109+
if (instanceState == null) {
1110+
logger.warn("VM {} has null instance state during power state sync check, treating as out of sync", instance);
1111+
return false;
1112+
}
11081113
if ((powerState == VirtualMachine.PowerState.PowerOff && instanceState == State.Running)
11091114
|| (powerState == VirtualMachine.PowerState.PowerOn && instanceState == State.Stopped)) {
11101115
HostVO instanceHost = hostDao.findById(instance.getHostId());
1111-
HostVO powerHost = powerHostId == instance.getHostId() ? instanceHost : hostDao.findById(powerHostId);
1116+
HostVO powerHost = instance.getHostId() != null && powerHostId == instance.getHostId() ? instanceHost : hostDao.findById(powerHostId);
11121117
logger.debug("VM: {} on host: {} and power host : {} is in {} state, but power state is {}",
11131118
instance, instanceHost, powerHost, instanceState, powerState);
11141119
return false;

0 commit comments

Comments
 (0)