Skip to content

Commit 1a86b86

Browse files
committed
Update VM's state if powerstate & state are not in sync
1 parent 1925040 commit 1a86b86

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,31 @@ public Boolean doInTransaction(TransactionStatus status) {
921921
instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
922922
needToUpdate = true;
923923
update(instanceId, instance);
924+
} else {
925+
switch (instance.getState()) {
926+
case Starting:
927+
case Running:
928+
if (powerState == VirtualMachine.PowerState.PowerOff) {
929+
s_logger.debug(String.format("VM id: %d on host id: %d and power host id: %d is in %s state, but power state is %s",
930+
instanceId, instance.getHostId(), powerHostId, instance.getState(), powerState));
931+
instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
932+
instance.setPowerStateUpdateCount(1);
933+
needToUpdate = true;
934+
update(instanceId, instance);
935+
}
936+
break;
937+
case Stopping:
938+
case Stopped:
939+
if (powerState == VirtualMachine.PowerState.PowerOn) {
940+
s_logger.debug(String.format("VM id: %d on host id: %d and power host id: %d is in %s state, but power state is %s",
941+
instanceId, instance.getHostId(), powerHostId, instance.getState(), powerState));
942+
instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
943+
instance.setPowerStateUpdateCount(1);
944+
needToUpdate = true;
945+
update(instanceId, instance);
946+
}
947+
break;
948+
}
924949
}
925950
}
926951
}

0 commit comments

Comments
 (0)