Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api/src/com/cloud/ha/Investigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions plugins/hypervisors/kvm/src/com/cloud/ha/KVMInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,23 @@ public Status isAgentAlive(Host agent) {
}

@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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public Status isAgentAlive(Host agent) {
}

@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();
}
}
8 changes: 4 additions & 4 deletions server/src/com/cloud/ha/CheckOnAgentInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ public Status isAgentAlive(Host agent) {
}

@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();
}
}
}
10 changes: 7 additions & 3 deletions server/src/com/cloud/ha/HighAvailabilityManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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;
Expand Down Expand Up @@ -481,10 +482,13 @@ protected Long restart(HaWorkVO work) {
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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -53,21 +53,21 @@ public Boolean isVmAlive(VirtualMachine vm, Host host) {

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);
if (nics.size() == 0) {
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) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public Boolean isVmAlive(VirtualMachine vm, Host host) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("unable to determine state of " + vm + " returning null");
}
return null;
throw new UnknownVM();
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions server/src/com/cloud/ha/UserVmDomRInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -100,7 +100,7 @@ public Boolean isVmAlive(VirtualMachine vm, Host host) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Returning null since we're unable to determine state of " + vm);
}
return null;
throw new UnknownVM();
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions server/src/com/cloud/ha/XenServerInvestigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ public Status isAgentAlive(Host agent) {
}

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