use of com.cloud.legacymodel.communication.answer.FenceAnswer in project cosmic by MissionCriticalCloud.
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<>();
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.legacymodel.communication.answer.FenceAnswer in project cosmic by MissionCriticalCloud.
the class XenServerFencer method fenceOff.
@Override
public Boolean fenceOff(final VirtualMachine vm, final Host host) {
if (host.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
return null;
}
final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
final FenceCommand fence = new FenceCommand(vm, host);
for (final HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.XenServer) {
if (h.getStatus() != HostStatus.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
final FenceAnswer answer;
try {
final 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 (final AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
} catch (final 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.legacymodel.communication.answer.FenceAnswer in project cosmic by MissionCriticalCloud.
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<KvmHaBase.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) {
final 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());
}
}
use of com.cloud.legacymodel.communication.answer.FenceAnswer in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithHosts.
@Test
public void testWithHosts() throws AgentUnavailableException, OperationTimedoutException {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(HostStatus.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);
final HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(HostStatus.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
final 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.legacymodel.communication.answer.FenceAnswer in project cosmic by MissionCriticalCloud.
the class XenServer56FenceCommandWrapper 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) {
s_logger.info("Fence command for VM " + command.getVmName());
vm.powerStateReset(conn);
vm.destroy(conn);
}
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());
}
}
Aggregations