use of com.cloud.agent.api.GetVmStatsAnswer 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;
}
use of com.cloud.agent.api.GetVmStatsAnswer in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testBadGetVmStatsCommand.
@Test
public final void testBadGetVmStatsCommand() {
// Sample GetVmStatsCommand
List<String> vmNames = new ArrayList<String>();
vmNames.add("FakeVM");
GetVmStatsCommand vmStatsCmd = new GetVmStatsCommand(vmNames, "1", "localhost");
GetVmStatsAnswer ans = (GetVmStatsAnswer) s_hypervresource.executeRequest(vmStatsCmd);
Assert.assertTrue(ans.getDetails(), ans.getResult());
}
use of com.cloud.agent.api.GetVmStatsAnswer in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testGetVmStatsCommand.
@Test
public final void testGetVmStatsCommand() {
// Sample GetVmStatsCommand
List<String> vmNames = new ArrayList<String>();
vmNames.add("i-2-11-VM");
GetVmStatsCommand cmd = new GetVmStatsCommand(vmNames, "1", "localhost");
s_hypervresource.executeRequest(cmd);
GetVmStatsAnswer ans = (GetVmStatsAnswer) s_hypervresource.executeRequest(cmd);
Assert.assertTrue(ans.getDetails(), ans.getResult());
}
use of com.cloud.agent.api.GetVmStatsAnswer in project cloudstack by apache.
the class Ovm3VmSupport method execute.
public GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
List<String> vmNames = cmd.getVmNames();
Map<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
for (String vmName : vmNames) {
VmStatsEntry e = getVmStat(vmName);
vmStatsNameMap.put(vmName, e);
}
return new GetVmStatsAnswer(cmd, (HashMap<String, VmStatsEntry>) vmStatsNameMap);
}
use of com.cloud.agent.api.GetVmStatsAnswer in project cloudstack by apache.
the class CitrixGetVmStatsCommandWrapper method execute.
@Override
public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final List<String> vmNames = command.getVmNames();
final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
if (vmNames.size() == 0) {
return new GetVmStatsAnswer(command, vmStatsNameMap);
}
try {
// Determine the UUIDs of the requested VMs
final List<String> vmUUIDs = new ArrayList<String>();
for (final String vmName : vmNames) {
final VM vm = citrixResourceBase.getVM(conn, vmName);
vmUUIDs.add(vm.getUuid(conn));
}
final HashMap<String, VmStatsEntry> vmStatsUUIDMap = citrixResourceBase.getVmStats(conn, command, vmUUIDs, command.getHostGuid());
if (vmStatsUUIDMap == null) {
return new GetVmStatsAnswer(command, vmStatsNameMap);
}
for (final Map.Entry<String, VmStatsEntry> entry : vmStatsUUIDMap.entrySet()) {
vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(entry.getKey())), entry.getValue());
}
return new GetVmStatsAnswer(command, vmStatsNameMap);
} catch (final XenAPIException e) {
final String msg = "Unable to get VM stats" + e.toString();
s_logger.warn(msg, e);
return new GetVmStatsAnswer(command, vmStatsNameMap);
} catch (final XmlRpcException e) {
final String msg = "Unable to get VM stats" + e.getMessage();
s_logger.warn(msg, e);
return new GetVmStatsAnswer(command, vmStatsNameMap);
}
}
Aggregations