From 2aeb46072c0c0370daef6a1ad1ce2e092a99bb62 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Fri, 26 Apr 2013 17:25:52 +0100 Subject: [PATCH] CLOUDSTACK-2195: Don't return a UserVM object if we fail to stop vm pass back null if we fail to connect to agent or stop the vm, rather than something that looks like success to the stopVirtualMachine api command. Testing: Applied to 4.1 branch, attempted to stop VM with KVM agent disconnected, finally saw it fail. The logs also showed why, which is good: 2013-04-25 17:37:09,933 ERROR [cloud.vm.VirtualMachineManagerImpl] (Job-Executor-1:job-44) Unable to stop vm, agent unavailable: com.cloud.exception.AgentUnavailableException: Resource [Host:1] is unreachable: Host 1: Host with specified id is not in the right state: Disconnected Started the KVM agent, and stopping succeeded. Signed-off-by: Chip Childers --- server/src/com/cloud/vm/UserVmManagerImpl.java | 9 +++++++-- server/src/com/cloud/vm/VirtualMachineManagerImpl.java | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 7bf04ec4965..865a1d3b6e7 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3685,9 +3685,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use UserVO user = _userDao.findById(userId); + boolean status = false; try { VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); - vmEntity.stop(new Long(userId).toString()); + status = vmEntity.stop(new Long(userId).toString()); + if (status) { + return _vmDao.findById(vmId); + } else { + return null; + } } catch (ResourceUnavailableException e) { throw new CloudRuntimeException( "Unable to contact the agent to stop the virtual machine " @@ -3698,7 +3704,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use + vm, e); } - return _vmDao.findById(vmId); } @Override diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 2c2986f52ef..f620c87d8b5 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1083,7 +1083,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac vmGuru.finalizeStop(profile, answer); } catch (AgentUnavailableException e) { + s_logger.warn("Unable to stop vm, agent unavailable: " + e.toString()); } catch (OperationTimedoutException e) { + s_logger.warn("Unable to stop vm, operation timed out: " + e.toString()); } finally { if (!stopped) { if (!forced) {