Skip to content

Commit 7fa4715

Browse files
committed
perform VM HA based on agent state report.
1 parent 8e27120 commit 7fa4715

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,12 @@ public void scheduleRestart(VMInstanceVO vm, boolean investigate) {
393393
}
394394
}
395395

396-
HaWorkVO work =
397-
new HaWorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled, hostId, vm.getState(), maxRetries + 1, vm.getUpdated());
396+
if (hostId == null) {
397+
hostId = vm.getLastHostId();
398+
}
399+
400+
HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled,
401+
hostId != null ? hostId : 0L, vm.getState(), maxRetries + 1, vm.getUpdated());
398402
_haDao.persist(work);
399403

400404
if (s_logger.isInfoEnabled()) {
@@ -962,15 +966,15 @@ public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event eve
962966
if (oldState == State.Running && event == VirtualMachine.Event.FollowAgentPowerOffReport && newState == State.Stopped) {
963967
final VMInstanceVO vm = _instanceDao.findById(vo.getId());
964968
if (vm.isHaEnabled()) {
965-
if (vm.getState() == State.Stopped)
969+
if (vm.getState() != State.Stopped)
966970
s_logger.warn("Sanity check failed. postStateTransitionEvent reports transited to Stopped but VM " + vm + " is still at state " + vm.getState());
967971

968972
s_logger.info("Detected out-of-band stop of a HA enabled VM " + vm.getInstanceName() + ", will schedule restart");
969973
_executor.submit(new ManagedContextRunnable() {
970974
@Override
971975
protected void runInContext() {
972976
try {
973-
scheduleRestart(vm, true);
977+
scheduleRestart(vm, false);
974978
} catch (Exception e) {
975979
s_logger.warn("Unexpected exception when scheduling a HA restart", e);
976980
}

0 commit comments

Comments
 (0)