Search in sources :

Example 1 with FenceAnswer

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());
    }
}
Also used : Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) HashSet(java.util.HashSet)

Example 2 with FenceAnswer

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;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) HostVO(com.cloud.host.HostVO)

Example 3 with FenceAnswer

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());
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) KvmHaChecker(com.cloud.agent.resource.kvm.ha.KvmHaChecker) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with FenceAnswer

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));
}
Also used : FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Test(org.junit.Test)

Example 5 with FenceAnswer

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());
    }
}
Also used : VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) FenceAnswer(com.cloud.legacymodel.communication.answer.FenceAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Aggregations

FenceAnswer (com.cloud.legacymodel.communication.answer.FenceAnswer)6 HostVO (com.cloud.host.HostVO)3 FenceCommand (com.cloud.legacymodel.communication.command.FenceCommand)3 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)2 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)2 Connection (com.xensource.xenapi.Connection)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 VM (com.xensource.xenapi.VM)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 KvmHaChecker (com.cloud.agent.resource.kvm.ha.KvmHaChecker)1 KvmHaMonitor (com.cloud.agent.resource.kvm.ha.KvmHaMonitor)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)1 VBD (com.xensource.xenapi.VBD)1 VDI (com.xensource.xenapi.VDI)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1