Search in sources :

Example 1 with KvmHaMonitor

use of com.cloud.agent.resource.kvm.ha.KvmHaMonitor 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 KvmHaMonitor

use of com.cloud.agent.resource.kvm.ha.KvmHaMonitor in project cosmic by MissionCriticalCloud.

the class LibvirtCheckOnHostCommandWrapper method execute.

@Override
public Answer execute(final CheckOnHostCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final ExecutorService executors = Executors.newSingleThreadExecutor();
    final KvmHaMonitor monitor = libvirtComputingResource.getMonitor();
    final List<KvmHaBase.NfsStoragePool> pools = monitor.getStoragePools();
    final HostTO host = command.getHost();
    final NetworkTO privateNetwork = host.getPrivateNetwork();
    final KvmHaChecker ha = new KvmHaChecker(pools, privateNetwork.getIp());
    final Future<Boolean> future = executors.submit(ha);
    try {
        final Boolean result = future.get();
        if (result) {
            return new Answer(command, false, "Heart is still beating...");
        } else {
            return new Answer(command);
        }
    } catch (final InterruptedException e) {
        return new Answer(command, false, "can't get status of host:");
    } catch (final ExecutionException e) {
        return new Answer(command, false, "can't get status of host:");
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ExecutorService(java.util.concurrent.ExecutorService) KvmHaChecker(com.cloud.agent.resource.kvm.ha.KvmHaChecker) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) HostTO(com.cloud.legacymodel.to.HostTO) NetworkTO(com.cloud.legacymodel.to.NetworkTO) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with KvmHaMonitor

use of com.cloud.agent.resource.kvm.ha.KvmHaMonitor 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 KvmHaMonitor

use of com.cloud.agent.resource.kvm.ha.KvmHaMonitor in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckOnHostCommand.

@Test
public void testCheckOnHostCommand() {
    final Host host = Mockito.mock(Host.class);
    final CheckOnHostCommand command = new CheckOnHostCommand(host);
    final KvmHaMonitor monitor = Mockito.mock(KvmHaMonitor.class);
    when(this.libvirtComputingResource.getMonitor()).thenReturn(monitor);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getMonitor();
}
Also used : CheckOnHostCommand(com.cloud.legacymodel.communication.command.CheckOnHostCommand) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) Host(com.cloud.legacymodel.dc.Host) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) Test(org.junit.Test)

Example 5 with KvmHaMonitor

use of com.cloud.agent.resource.kvm.ha.KvmHaMonitor in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResource method initMonitorThread.

private void initMonitorThread() {
    final String[] info = NetUtils.getNetworkParams(this._privateNic);
    this.monitor = new KvmHaMonitor(null, info[0], this.heartBeatPath);
    final Thread ha = new Thread(this.monitor);
    ha.start();
}
Also used : KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor)

Aggregations

KvmHaMonitor (com.cloud.agent.resource.kvm.ha.KvmHaMonitor)5 Answer (com.cloud.legacymodel.communication.answer.Answer)3 KvmHaChecker (com.cloud.agent.resource.kvm.ha.KvmHaChecker)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)2 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 Host (com.cloud.legacymodel.dc.Host)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.junit.Test)2 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)1 FenceAnswer (com.cloud.legacymodel.communication.answer.FenceAnswer)1 CheckOnHostCommand (com.cloud.legacymodel.communication.command.CheckOnHostCommand)1 FenceCommand (com.cloud.legacymodel.communication.command.FenceCommand)1 HostTO (com.cloud.legacymodel.to.HostTO)1 NetworkTO (com.cloud.legacymodel.to.NetworkTO)1 VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)1 ArrayList (java.util.ArrayList)1