use of com.cloud.agent.api.FenceAnswer 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.FenceAnswer in project cloudstack by apache.
the class XenServer56FP1FenceCommandWrapper method execute.
@Override
public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) {
final Connection conn = xenServer56.getConnection();
try {
final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid());
if (alive == null) {
s_logger.debug("Failed to check heartbeat, so unable to fence");
return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence");
}
if (alive) {
s_logger.debug("Heart beat is still going so unable to fence");
return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence");
}
final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName());
for (final VM vm : vms) {
final Set<VDI> vdis = new HashSet<VDI>();
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
final VDI vdi = vbd.getVDI(conn);
if (!xenServer56.isRefNull(vdi)) {
vdis.add(vdi);
}
}
s_logger.info("Fence command for VM " + command.getVmName());
vm.powerStateReset(conn);
vm.destroy(conn);
for (final VDI vdi : vdis) {
final Map<String, String> smConfig = vdi.getSmConfig(conn);
for (final String key : smConfig.keySet()) {
if (key.startsWith("host_")) {
vdi.removeFromSmConfig(conn, key);
break;
}
}
}
}
return new FenceAnswer(command);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
} catch (final XenAPIException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
} catch (final Exception e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
}
}
use of com.cloud.agent.api.FenceAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected FenceAnswer execute(FenceCommand cmd) {
ExecutorService executors = Executors.newSingleThreadExecutor();
List<NfsStoragePool> pools = _monitor.getStoragePools();
KVMHAChecker ha = new KVMHAChecker(pools, cmd.getHostIp());
Future<Boolean> future = executors.submit(ha);
try {
Boolean result = future.get();
if (result) {
return new FenceAnswer(cmd, false, "Heart is still beating...");
} else {
return new FenceAnswer(cmd);
}
} catch (InterruptedException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(cmd, false, e.getMessage());
} catch (ExecutionException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(cmd, false, e.getMessage());
}
}
use of com.cloud.agent.api.FenceAnswer in project cloudstack by apache.
the class KVMFencerTest method testWithHosts.
@Test
public void testWithHosts() throws AgentUnavailableException, OperationTimedoutException {
HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);
HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
FenceAnswer answer = new FenceAnswer(null, true, "ok");
Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenReturn(answer);
Assert.assertTrue(fencer.fenceOff(virtualMachine, host));
}
use of com.cloud.agent.api.FenceAnswer in project cloudstack by apache.
the class LibvirtFenceCommandWrapper method execute.
@Override
public Answer execute(final FenceCommand command, final LibvirtComputingResource libvirtComputingResource) {
final ExecutorService executors = Executors.newSingleThreadExecutor();
final KVMHAMonitor monitor = libvirtComputingResource.getMonitor();
final List<NfsStoragePool> pools = monitor.getStoragePools();
/**
* We can only safely fence off hosts when we use NFS
* On NFS primary storage pools hosts continuesly write
* a heartbeat. Disable Fencing Off for hosts without NFS
*/
if (pools.size() == 0) {
String logline = "No NFS storage pools found. No way to safely fence " + command.getVmName() + " on host " + command.getHostGuid();
s_logger.warn(logline);
return new FenceAnswer(command, false, logline);
}
final KVMHAChecker ha = new KVMHAChecker(pools, command.getHostIp());
final Future<Boolean> future = executors.submit(ha);
try {
final Boolean result = future.get();
if (result) {
return new FenceAnswer(command, false, "Heart is still beating...");
} else {
return new FenceAnswer(command);
}
} catch (final InterruptedException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
} catch (final ExecutionException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
}
}
Aggregations