Search in sources :

Example 1 with FenceCommand

use of com.cloud.legacymodel.communication.command.FenceCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testFenceCommand.

@Test
public void testFenceCommand() {
    final VirtualMachine vm = Mockito.mock(VirtualMachine.class);
    final Host host = Mockito.mock(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<>();
    pools.add(storagePool);
    when(this.libvirtComputingResource.getMonitor()).thenReturn(monitor);
    when(monitor.getStoragePools()).thenReturn(pools);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getMonitor();
    verify(monitor, times(1)).getStoragePools();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) ArrayList(java.util.ArrayList) Host(com.cloud.legacymodel.dc.Host) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Test(org.junit.Test)

Example 2 with FenceCommand

use of com.cloud.legacymodel.communication.command.FenceCommand 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 FenceCommand

use of com.cloud.legacymodel.communication.command.FenceCommand in project cosmic by MissionCriticalCloud.

the class XenServer56FP1WrapperTest method testFenceCommand.

@Test
public void testFenceCommand() {
    final VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
    final Host host = Mockito.mock(Host.class);
    final Connection conn = Mockito.mock(Connection.class);
    final FenceCommand fenceCommand = new FenceCommand(vm, host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer56Resource.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(fenceCommand, xenServer56Resource);
    verify(xenServer56Resource, times(1)).getConnection();
    verify(xenServer56Resource, times(1)).checkHeartbeat(fenceCommand.getHostGuid());
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) Connection(com.xensource.xenapi.Connection) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.legacymodel.dc.Host) Test(org.junit.Test)

Example 4 with FenceCommand

use of com.cloud.legacymodel.communication.command.FenceCommand in project cosmic by MissionCriticalCloud.

the class XenServer56WrapperTest method testFenceCommand.

@Test
public void testFenceCommand() {
    final VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
    final Host host = Mockito.mock(Host.class);
    final Connection conn = Mockito.mock(Connection.class);
    final FenceCommand fenceCommand = new FenceCommand(vm, host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.xenServer56Resource.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(fenceCommand, this.xenServer56Resource);
    verify(this.xenServer56Resource, times(1)).getConnection();
    verify(this.xenServer56Resource, times(1)).checkHeartbeat(fenceCommand.getHostGuid());
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) Connection(com.xensource.xenapi.Connection) VMInstanceVO(com.cloud.vm.VMInstanceVO) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.cloud.legacymodel.dc.Host) Test(org.junit.Test)

Example 5 with FenceCommand

use of com.cloud.legacymodel.communication.command.FenceCommand in project cosmic by MissionCriticalCloud.

the class KVMFencer method fenceOff.

@Override
public Boolean fenceOff(final VirtualMachine vm, final Host host) {
    if (host.getHypervisorType() != HypervisorType.KVM) {
        s_logger.warn("Don't know how to fence non kvm hosts " + host.getHypervisorType());
        return null;
    }
    final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
    final FenceCommand fence = new FenceCommand(vm, host);
    int i = 0;
    for (final HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.KVM) {
            if (h.getStatus() != HostStatus.Up) {
                continue;
            }
            i++;
            if (h.getId() == host.getId()) {
                continue;
            }
            final FenceAnswer answer;
            try {
                answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
            } catch (final AgentUnavailableException e) {
                s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
                continue;
            } catch (final 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;
}
Also used : 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)

Aggregations

FenceCommand (com.cloud.legacymodel.communication.command.FenceCommand)5 Answer (com.cloud.legacymodel.communication.answer.Answer)4 Host (com.cloud.legacymodel.dc.Host)3 Test (org.junit.Test)3 HostVO (com.cloud.host.HostVO)2 FenceAnswer (com.cloud.legacymodel.communication.answer.FenceAnswer)2 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)2 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 Connection (com.xensource.xenapi.Connection)2 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)1 KvmHaMonitor (com.cloud.agent.resource.kvm.ha.KvmHaMonitor)1 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)1 ArrayList (java.util.ArrayList)1