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());
}
}
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());
}
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;
}
Aggregations