Search in sources :

Example 1 with GetVmStatsAnswer

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

Example 2 with GetVmStatsAnswer

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);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) VmStatsEntry(com.cloud.legacymodel.vm.VmStatsEntry) GetVmStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmStatsAnswer)

Example 3 with GetVmStatsAnswer

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);
    }
}
Also used : HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VmStatsEntry(com.cloud.legacymodel.vm.VmStatsEntry) VM(com.xensource.xenapi.VM) GetVmStatsAnswer(com.cloud.legacymodel.communication.answer.GetVmStatsAnswer) HashMap(java.util.HashMap) Map(java.util.Map) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

GetVmStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmStatsAnswer)3 VmStatsEntry (com.cloud.legacymodel.vm.VmStatsEntry)3 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Answer (com.cloud.legacymodel.communication.answer.Answer)1 GetVmDiskStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer)1 RestoreVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer)1 StartAnswer (com.cloud.legacymodel.communication.answer.StartAnswer)1 GetVmStatsCommand (com.cloud.legacymodel.communication.command.GetVmStatsCommand)1 Connection (com.xensource.xenapi.Connection)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VM (com.xensource.xenapi.VM)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Connect (org.libvirt.Connect)1 LibvirtException (org.libvirt.LibvirtException)1