use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.
the class OvmFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.Ovm) {
s_logger.debug("Don't know how to fence non Ovm hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() != HypervisorType.Ovm) {
continue;
}
if (h.getStatus() != Status.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.
the class LibvirtComputingResourceTest method testFenceCommand.
@Test
public void testFenceCommand() {
final VirtualMachine vm = Mockito.mock(VirtualMachine.class);
;
final com.cloud.host.Host host = Mockito.mock(com.cloud.host.Host.class);
final FenceCommand command = new FenceCommand(vm, host);
final KVMHAMonitor monitor = Mockito.mock(KVMHAMonitor.class);
final NfsStoragePool storagePool = Mockito.mock(NfsStoragePool.class);
final List<NfsStoragePool> pools = new ArrayList<NfsStoragePool>();
pools.add(storagePool);
when(libvirtComputingResource.getMonitor()).thenReturn(monitor);
when(monitor.getStoragePools()).thenReturn(pools);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getMonitor();
verify(monitor, times(1)).getStoragePools();
}
use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.
the class KVMFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC) {
s_logger.warn("Don't know how to fence non kvm hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
int i = 0;
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.KVM || h.getHypervisorType() == HypervisorType.LXC) {
if (h.getStatus() != Status.Up) {
continue;
}
i++;
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException e) {
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
continue;
} catch (OperationTimedoutException e) {
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to fence off host: " + host.getId(), "Fencing off host " + host.getId() + " did not succeed after asking " + i + " hosts. " + "Check Agent logs for more information.");
s_logger.error("Unable to fence off " + vm.toString() + " on " + host.toString());
return false;
}
use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.
the class Ovm3FenceBuilder method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.Ovm3) {
LOGGER.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType());
return null;
} else {
LOGGER.debug("Fencing " + vm + " on host " + host + " with params: " + fenceParams);
}
List<HostVO> hosts = resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.Ovm3 && h.getStatus() == Status.Up && h.getId() != host.getId()) {
FenceAnswer answer;
try {
answer = (FenceAnswer) agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException | OperationTimedoutException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.
the class XenServerFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.XenServer) {
if (h.getStatus() != Status.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
Answer ans = _agentMgr.send(h.getId(), fence);
if (!(ans instanceof FenceAnswer)) {
s_logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails());
continue;
}
answer = (FenceAnswer) ans;
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
Aggregations