cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/3] git commit: updated refs/heads/hotfix/findbugs-unknownvm-as-null to 6a82173
Date Thu, 26 Mar 2015 13:20:07 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/hotfix/findbugs-unknownvm-as-null [created] 6a821730c


findbugs: Boolen function should not return null

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/048212b1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/048212b1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/048212b1

Branch: refs/heads/hotfix/findbugs-unknownvm-as-null
Commit: 048212b1176158c379fcb9c9a9c9d51784c406e2
Parents: 7246994
Author: Daan Hoogland <dhoogland@schubergphilis.com>
Authored: Wed Mar 25 21:46:47 2015 +0100
Committer: Daan Hoogland <dhoogland@schubergphilis.com>
Committed: Wed Mar 25 21:46:47 2015 +0100

----------------------------------------------------------------------
 api/src/com/cloud/ha/Investigator.java                   | 11 ++++++++++-
 .../hyperv/src/com/cloud/ha/HypervInvestigator.java      |  4 ++--
 .../kvm/src/com/cloud/ha/KVMInvestigator.java            | 10 +++++++---
 .../src/main/java/com/cloud/ha/Ovm3Investigator.java     |  4 ++--
 .../src/com/cloud/ha/SimulatorInvestigator.java          |  8 ++++----
 .../vmware/src/com/cloud/ha/VmwareInvestigator.java      |  4 ++--
 server/src/com/cloud/ha/CheckOnAgentInvestigator.java    |  8 ++++----
 server/src/com/cloud/ha/HighAvailabilityManagerImpl.java | 10 +++++++---
 .../com/cloud/ha/ManagementIPSystemVMInvestigator.java   | 10 +++++-----
 server/src/com/cloud/ha/UserVmDomRInvestigator.java      |  6 +++---
 server/src/com/cloud/ha/XenServerInvestigator.java       | 10 +++++++---
 11 files changed, 53 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/api/src/com/cloud/ha/Investigator.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/ha/Investigator.java b/api/src/com/cloud/ha/Investigator.java
index 7dd8b3f..cbf5d30 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;
+
+    };
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java b/plugins/hypervisors/hyperv/src/com/cloud/ha/HypervInvestigator.java
index 65498e4..8b94672 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;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java b/plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java
index e750ced..b519312 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java
----------------------------------------------------------------------
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 b80661b..56f904b 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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java b/plugins/hypervisors/simulator/src/com/cloud/ha/SimulatorInvestigator.java
index 7191ae3..9366b83 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();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java
index 7042d53..0fda96a 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();
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/server/src/com/cloud/ha/CheckOnAgentInvestigator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java
index b361199..fdb587b 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();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
index 7cc63df..f15889d 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);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java
index 95e803f..3f1b17f 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<? extends Nic> 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/server/src/com/cloud/ha/UserVmDomRInvestigator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/UserVmDomRInvestigator.java b/server/src/com/cloud/ha/UserVmDomRInvestigator.java
index d6f7279..b3a5ec1 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/048212b1/server/src/com/cloud/ha/XenServerInvestigator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/ha/XenServerInvestigator.java b/server/src/com/cloud/ha/XenServerInvestigator.java
index cce449c..b6549f8 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;
     }
 }


Mime
View raw message