Search in sources :

Example 1 with GetVmStatsAnswer

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) Answer(com.cloud.agent.api.Answer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) GetVmStatsAnswer(com.cloud.agent.api.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.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());
}
Also used : ArrayList(java.util.ArrayList) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) Test(org.junit.Test)

Example 3 with GetVmStatsAnswer

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());
}
Also used : ArrayList(java.util.ArrayList) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) Test(org.junit.Test)

Example 4 with GetVmStatsAnswer

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);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 5 with GetVmStatsAnswer

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

Aggregations

GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)14 VmStatsEntry (com.cloud.agent.api.VmStatsEntry)12 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)4 Map (java.util.Map)4 Answer (com.cloud.agent.api.Answer)3 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)3 StartAnswer (com.cloud.agent.api.StartAnswer)3 XmlRpcException (org.apache.xmlrpc.XmlRpcException)3 Connect (org.libvirt.Connect)3 LibvirtException (org.libvirt.LibvirtException)3 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)2 Test (org.junit.Test)2 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1