CLOUDSTACK-8103: Vmsync marks VM as stopped even after failing to stop it in HV

During vmsync if StopCommand (issued as part of PowerOff/PowerMissing report) fails to stop VM (since VM is running on HV),
don't transition VM state to "Stopped" in CS db. Also added a check to throw ConcurrentOperationException if vm state is not
"Running" after start operation.

(cherry picked from commit 788fe5a273)
This commit is contained in:
Koushik Das 2014-12-22 10:52:13 +05:30 committed by Daan Hoogland
parent 79fc9d2687
commit 145b4a1f2c
2 changed files with 11 additions and 1 deletions

View File

@ -4288,7 +4288,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineGuru vmGuru = getVmGuru(vm);
VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
sendStop(vmGuru, profile, true, true);
if (!sendStop(vmGuru, profile, true, true)) {
// In case StopCommand fails, don't proceed further
return;
}
try {
stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOffReport, null);

View File

@ -3122,6 +3122,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
try {
vmParamPair = startVirtualMachine(vmId, hostId, additonalParams, deploymentPlannerToUse);
vm = vmParamPair.first();
// At this point VM should be in "Running" state
UserVmVO tmpVm = _vmDao.findById(vm.getId());
if (!tmpVm.getState().equals(State.Running)) {
// Some other thread changed state of VM, possibly vmsync
throw new ConcurrentOperationException("VM " + tmpVm + " unexpectedly went to " + tmpVm.getState() + " state");
}
} finally {
updateVmStateForFailedVmCreation(vm.getId(), hostId);
}