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.
This commit is contained in:
Koushik Das 2014-12-22 10:52:13 +05:30
parent c5d3a73c67
commit 788fe5a273
2 changed files with 11 additions and 1 deletions

View File

@ -3688,7 +3688,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

@ -3194,6 +3194,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);
}