Search in sources :

Example 6 with FenceAnswer

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;
}
Also used : FenceCommand(com.cloud.agent.api.FenceCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) FenceAnswer(com.cloud.agent.api.FenceAnswer) HostVO(com.cloud.host.HostVO)

Example 7 with FenceAnswer

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());
    }
}
Also used : Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) FenceAnswer(com.cloud.agent.api.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 8 with FenceAnswer

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());
    }
}
Also used : NfsStoragePool(com.cloud.agent.resource.computing.KVMHABase.NfsStoragePool) ExecutorService(java.util.concurrent.ExecutorService) FenceAnswer(com.cloud.agent.api.FenceAnswer) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with FenceAnswer

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

Example 10 with FenceAnswer

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());
    }
}
Also used : KVMHAChecker(com.cloud.hypervisor.kvm.resource.KVMHAChecker) KVMHAMonitor(com.cloud.hypervisor.kvm.resource.KVMHAMonitor) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) ExecutorService(java.util.concurrent.ExecutorService) FenceAnswer(com.cloud.agent.api.FenceAnswer) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

FenceAnswer (com.cloud.agent.api.FenceAnswer)10 FenceCommand (com.cloud.agent.api.FenceCommand)6 HostVO (com.cloud.host.HostVO)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)5 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)5 Connection (com.xensource.xenapi.Connection)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 VM (com.xensource.xenapi.VM)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 Answer (com.cloud.agent.api.Answer)1 NfsStoragePool (com.cloud.agent.resource.computing.KVMHABase.NfsStoragePool)1 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)1 KVMHAChecker (com.cloud.hypervisor.kvm.resource.KVMHAChecker)1 KVMHAMonitor (com.cloud.hypervisor.kvm.resource.KVMHAMonitor)1 VirtualMachine (com.cloud.vm.VirtualMachine)1 VBD (com.xensource.xenapi.VBD)1 VDI (com.xensource.xenapi.VDI)1 HashSet (java.util.HashSet)1