Search in sources :

Example 6 with VmStatsEntry

use of com.cloud.legacymodel.vm.VmStatsEntry 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

VmStatsEntry (com.cloud.legacymodel.vm.VmStatsEntry)6 HashMap (java.util.HashMap)4 GetVmStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmStatsAnswer)3 Map (java.util.Map)3 LibvirtDiskDef (com.cloud.agent.resource.kvm.xml.LibvirtDiskDef)2 InterfaceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef)2 ArrayList (java.util.ArrayList)2 Connect (org.libvirt.Connect)2 Domain (org.libvirt.Domain)2 DomainBlockStats (org.libvirt.DomainBlockStats)2 DomainInfo (org.libvirt.DomainInfo)2 DomainInterfaceStats (org.libvirt.DomainInterfaceStats)2 NodeInfo (org.libvirt.NodeInfo)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