Search in sources :

Example 1 with FenceCommand

use of com.cloud.agent.api.FenceCommand 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 2 with FenceCommand

use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testFenceCommand.

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

Example 3 with FenceCommand

use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.

the class KVMFencer method fenceOff.

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

use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.

the class Ovm3FenceBuilder method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.Ovm3) {
        LOGGER.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType());
        return null;
    } else {
        LOGGER.debug("Fencing " + vm + " on host " + host + " with params: " + fenceParams);
    }
    List<HostVO> hosts = resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);
    for (HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.Ovm3 && h.getStatus() == Status.Up && h.getId() != host.getId()) {
            FenceAnswer answer;
            try {
                answer = (FenceAnswer) agentMgr.send(h.getId(), fence);
            } catch (AgentUnavailableException | OperationTimedoutException e) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
                }
                continue;
            }
            if (answer != null && answer.getResult()) {
                return true;
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        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 5 with FenceCommand

use of com.cloud.agent.api.FenceCommand in project cloudstack by apache.

the class XenServerFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Don't know how to fence non XenServer 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.XenServer) {
            if (h.getStatus() != Status.Up) {
                continue;
            }
            if (h.getId() == host.getId()) {
                continue;
            }
            FenceAnswer answer;
            try {
                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 (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 : FenceAnswer(com.cloud.agent.api.FenceAnswer) Answer(com.cloud.agent.api.Answer) 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)

Aggregations

FenceCommand (com.cloud.agent.api.FenceCommand)10 Answer (com.cloud.agent.api.Answer)6 FenceAnswer (com.cloud.agent.api.FenceAnswer)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)5 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)5 HostVO (com.cloud.host.HostVO)5 Test (org.junit.Test)3 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)1 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)1 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)1 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)1 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)1