findbugs: Boolen function should not return null

This commit is contained in:
Daan Hoogland 2015-03-25 21:46:47 +01:00
parent 724699424e
commit 048212b117
11 changed files with 53 additions and 32 deletions

View File

@ -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;
};
}

View File

@ -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;
}

View File

@ -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

View File

@ -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) {

View File

@ -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();
}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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;
}
}