diff --git a/api/src/com/cloud/ha/Investigator.java b/api/src/com/cloud/ha/Investigator.java index 7dd8b3f503c..cbf5d30916f 100644 --- a/api/src/com/cloud/ha/Investigator.java +++ b/api/src/com/cloud/ha/Investigator.java @@ -27,7 +27,16 @@ public interface Investigator extends Adapter { * * @param vm to work on. */ - public Boolean isVmAlive(VirtualMachine vm, Host host); + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM; public Status isAgentAlive(Host agent); + + class UnknownVM extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + }; } diff --git a/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java b/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java index 65498e450b0..8b94672e4ca 100644 --- a/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java +++ b/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java @@ -44,10 +44,10 @@ public class HypervInvestigator extends AdapterBase implements Investigator { @Inject ResourceManager _resourceMgr; @Override - public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) { + public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws UnknownVM { Status status = isAgentAlive(host); if (status == null) { - return null; + throw new UnknownVM(); } return status == Status.Up ? true : null; } diff --git a/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java b/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java index e750ced7e11..b519312a012 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java +++ b/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java @@ -47,12 +47,16 @@ public class KVMInvestigator extends AdapterBase implements Investigator { ResourceManager _resourceMgr; @Override - public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) { + public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws UnknownVM { Status status = isAgentAlive(host); if (status == null) { - return null; + throw new UnknownVM(); + } + if (status == Status.Up) { + return true; + } else { + throw new UnknownVM(); } - return status == Status.Up ? true : null; } @Override diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java index b80661b8d64..56f904bc922 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java @@ -46,10 +46,10 @@ public class Ovm3Investigator extends AdapterBase implements Investigator { ResourceManager resourceMgr; @Override - public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) { + public Boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws UnknownVM { LOGGER.debug("isVmAlive: " + vm.getHostName() + " on " + host.getName()); if (host.getHypervisorType() != Hypervisor.HypervisorType.Ovm3) { - return null; + throw new UnknownVM(); } Status status = isAgentAlive(host); if (status == null) { diff --git a/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java b/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java index 7191ae3dab1..9366b83078c 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java +++ b/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java @@ -80,23 +80,23 @@ public class SimulatorInvestigator extends AdapterBase implements Investigator { } @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName()); try { Answer answer = _agentMgr.send(vm.getHostId(), cmd); if (!answer.getResult()) { s_logger.debug("Unable to get vm state on " + vm.toString()); - return null; + throw new UnknownVM(); } CheckVirtualMachineAnswer cvmAnswer = (CheckVirtualMachineAnswer)answer; s_logger.debug("Agent responded with state " + cvmAnswer.getState().toString()); return cvmAnswer.getState() == PowerState.PowerOn; } catch (AgentUnavailableException e) { s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage()); - return null; + throw new UnknownVM(); } catch (OperationTimedoutException e) { s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage()); - return null; + throw new UnknownVM(); } } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java index 7042d53e9c1..0fda96ac466 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java +++ b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java @@ -38,10 +38,10 @@ public class VmwareInvestigator extends AdapterBase implements Investigator { } @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { if (vm.getHypervisorType() == HypervisorType.VMware) return true; - return null; + throw new UnknownVM(); } } diff --git a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java index b3611992fc9..fdb587bccf3 100644 --- a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java +++ b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java @@ -47,23 +47,23 @@ public class CheckOnAgentInvestigator extends AdapterBase implements Investigato } @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName()); try { CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer)_agentMgr.send(vm.getHostId(), cmd); if (!answer.getResult()) { s_logger.debug("Unable to get vm state on " + vm.toString()); - return null; + throw new UnknownVM(); } s_logger.debug("Agent responded with state " + answer.getState().toString()); return answer.getState() == PowerState.PowerOn; } catch (AgentUnavailableException e) { s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage()); - return null; + throw new UnknownVM(); } catch (OperationTimedoutException e) { s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage()); - return null; + throw new UnknownVM(); } } } diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index 7cc63dff251..f15889d1d38 100644 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -55,6 +55,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.ha.Investigator.UnknownVM; import com.cloud.ha.dao.HighAvailabilityDao; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -481,10 +482,13 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai Investigator investigator = null; for (Investigator it : investigators) { investigator = it; - alive = investigator.isVmAlive(vm, host); - s_logger.info(investigator.getName() + " found " + vm + "to be alive? " + alive); - if (alive != null) { + try + { + alive = investigator.isVmAlive(vm, host); + s_logger.info(investigator.getName() + " found " + vm + " to be alive? " + alive); break; + } catch (UnknownVM e) { + s_logger.info(investigator.getName() + " could not find " + vm); } } diff --git a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java index 95e803f54ac..3f1b17f4548 100644 --- a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java +++ b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java @@ -42,7 +42,7 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { private final NetworkModel _networkMgr = null; @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { if (!vm.getType().isUsedBySystem()) { s_logger.debug("Not a System Vm, unable to determine state of " + vm + " returning null"); } @@ -53,13 +53,13 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { if (vm.getHostId() == null) { s_logger.debug("There's no host id for " + vm); - return null; + throw new UnknownVM(); } HostVO vmHost = _hostDao.findById(vm.getHostId()); if (vmHost == null) { s_logger.debug("Unable to retrieve the host by using id " + vm.getHostId()); - return null; + throw new UnknownVM(); } List nics = _networkMgr.getNicsForTraffic(vm.getId(), TrafficType.Management); @@ -67,7 +67,7 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find a management nic, cannot ping this system VM, unable to determine state of " + vm + " returning null"); } - return null; + throw new UnknownVM(); } for (Nic nic : nics) { @@ -105,7 +105,7 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { if (s_logger.isDebugEnabled()) { s_logger.debug("unable to determine state of " + vm + " returning null"); } - return null; + throw new UnknownVM(); } @Override diff --git a/server/src/com/cloud/ha/UserVmDomRInvestigator.java b/server/src/com/cloud/ha/UserVmDomRInvestigator.java index d6f72790f93..b3a5ec1a939 100644 --- a/server/src/com/cloud/ha/UserVmDomRInvestigator.java +++ b/server/src/com/cloud/ha/UserVmDomRInvestigator.java @@ -53,12 +53,12 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { private final VpcVirtualNetworkApplianceManager _vnaMgr = null; @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { if (vm.getType() != VirtualMachine.Type.User) { if (s_logger.isDebugEnabled()) { s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null"); } - return null; + throw new UnknownVM(); } if (s_logger.isDebugEnabled()) { @@ -100,7 +100,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { if (s_logger.isDebugEnabled()) { s_logger.debug("Returning null since we're unable to determine state of " + vm); } - return null; + throw new UnknownVM(); } @Override diff --git a/server/src/com/cloud/ha/XenServerInvestigator.java b/server/src/com/cloud/ha/XenServerInvestigator.java index cce449cc768..b6549f839f5 100644 --- a/server/src/com/cloud/ha/XenServerInvestigator.java +++ b/server/src/com/cloud/ha/XenServerInvestigator.java @@ -77,11 +77,15 @@ public class XenServerInvestigator extends AdapterBase implements Investigator { } @Override - public Boolean isVmAlive(VirtualMachine vm, Host host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { Status status = isAgentAlive(host); if (status == null) { - return null; + throw new UnknownVM(); + } + if (status == Status.Up) { + return true; + } else { + throw new UnknownVM(); } - return status == Status.Up ? true : null; } }