Search in sources :

Example 1 with GetVmStatsCommand

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

the class LibvirtComputingResourceTest method testGetVmStatsCommand.

@Test
public void testGetVmStatsCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
    final List<String> vms = new ArrayList<>();
    vms.add(vmName);
    final GetVmStatsCommand command = new GetVmStatsCommand(vms, uuid, "hostname");
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : 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) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) GetVmStatsCommand(com.cloud.legacymodel.communication.command.GetVmStatsCommand) Test(org.junit.Test)

Example 2 with GetVmStatsCommand

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

the class NotAValidCommand method testGetVmStatsCommand.

@Test
public void testGetVmStatsCommand() {
    final GetVmStatsCommand statsCommand = new GetVmStatsCommand(new ArrayList<>(), null, null);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(statsCommand, this.citrixResourceBase);
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) GetVmStatsCommand(com.cloud.legacymodel.communication.command.GetVmStatsCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with GetVmStatsCommand

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

the class UserVmManagerImpl method getVirtualMachineStatistics.

@Override
public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(final long hostId, final String hostName, final List<Long> vmIds) throws CloudRuntimeException {
    final HashMap<Long, VmStatsEntry> vmStatsById = new HashMap<>();
    if (vmIds.isEmpty()) {
        return vmStatsById;
    }
    final List<String> vmNames = new ArrayList<>();
    for (final Long vmId : vmIds) {
        final UserVmVO vm = _vmDao.findById(vmId);
        vmNames.add(vm.getInstanceName());
    }
    final Answer answer = _agentMgr.easySend(hostId, new GetVmStatsCommand(vmNames, _hostDao.findById(hostId).getGuid(), hostName));
    if (answer == null || !answer.getResult()) {
        s_logger.warn("Unable to obtain VM statistics.");
        return null;
    } else {
        final HashMap<String, VmStatsEntry> vmStatsByName = ((GetVmStatsAnswer) answer).getVmStatsMap();
        if (vmStatsByName == null) {
            s_logger.warn("Unable to obtain VM statistics.");
            return null;
        }
        for (final Map.Entry<String, VmStatsEntry> entry : vmStatsByName.entrySet()) {
            vmStatsById.put(vmIds.get(vmNames.indexOf(entry.getKey())), entry.getValue());
        }
    }
    return vmStatsById;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmStatsEntry(com.cloud.legacymodel.vm.VmStatsEntry) GetVmStatsCommand(com.cloud.legacymodel.communication.command.GetVmStatsCommand) GetVmDiskStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer) GetVmStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmStatsAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetVmStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmStatsAnswer) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)3 GetVmStatsCommand (com.cloud.legacymodel.communication.command.GetVmStatsCommand)3 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 GetVmDiskStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer)1 GetVmStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmStatsAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 RestoreVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer)1 StartAnswer (com.cloud.legacymodel.communication.answer.StartAnswer)1 VmStatsEntry (com.cloud.legacymodel.vm.VmStatsEntry)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Connect (org.libvirt.Connect)1