From f619e26c485cc8640ab74b18bebab474e3dbd5e9 Mon Sep 17 00:00:00 2001 From: prachi Date: Wed, 22 Feb 2012 17:03:40 -0800 Subject: [PATCH] Bug 13850 - VM stuck in starting state if it is started during the HA-Work of the corresponding router Reviewed-By: Kelven Changes: - Update the pending work Item to be DONE if we are changing the VM state during fullSync. --- .../cloud/vm/VirtualMachineManagerImpl.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 1d820f0eb97..0a7f09433f7 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1725,8 +1725,25 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene { s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent"); info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped); - vm.setState(State.Running); // set it as running and let HA take care of it + + // Bug 13850- grab outstanding work item if any for this VM state so that we mark it as DONE after we change VM state, else it will remain pending + ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState()); + if (work != null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Found an outstanding work item for this vm " + vm + " in state:" + vm.getState() + ", work id:" + work.getId()); + } + } + vm.setState(State.Running); // set it as running and let HA take care of it _vmDao.persist(vm); + + if (work != null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Updating outstanding work item to Done, id:" + work.getId()); + } + work.setStep(Step.Done); + _workDao.update(work.getId(), work); + } + castedVm = info.guru.findById(vm.getId()); try { Host host = _hostDao.findByGuid(info.getHostUuid());