use of com.cloud.legacymodel.communication.answer.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.legacymodel.communication.answer.GetVmStatsAnswer in project cosmic by MissionCriticalCloud.
the class LibvirtGetVmStatsCommandWrapper method execute.
@Override
public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
final List<String> vmNames = command.getVmNames();
try {
final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<>();
for (final String vmName : vmNames) {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
try {
final VmStatsEntry statEntry = libvirtComputingResource.getVmStat(conn, vmName);
if (statEntry == null) {
continue;
}
vmStatsNameMap.put(vmName, statEntry);
} catch (final LibvirtException e) {
s_logger.warn("Can't get vm stats: " + e.toString() + ", continue");
}
}
return new GetVmStatsAnswer(command, vmStatsNameMap);
} catch (final LibvirtException e) {
s_logger.debug("Can't get vm stats: " + e.toString());
return new GetVmStatsAnswer(command, null);
}
}
use of com.cloud.legacymodel.communication.answer.GetVmStatsAnswer in project cosmic by MissionCriticalCloud.
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<>();
if (vmNames.size() == 0) {
return new GetVmStatsAnswer(command, vmStatsNameMap);
}
try {
// Determine the UUIDs of the requested VMs
final List<String> vmUUIDs = new ArrayList<>();
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