Search in sources :

Example 6 with GetVmDiskStatsCommand

use of com.cloud.agent.api.GetVmDiskStatsCommand in project cloudstack by apache.

the class UserVmManagerImpl method getVmDiskStatistics.

@Override
public HashMap<Long, List<VmDiskStatsEntry>> getVmDiskStatistics(long hostId, String hostName, List<Long> vmIds) throws CloudRuntimeException {
    HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = new HashMap<Long, List<VmDiskStatsEntry>>();
    if (vmIds.isEmpty()) {
        return vmDiskStatsById;
    }
    List<String> vmNames = new ArrayList<String>();
    for (Long vmId : vmIds) {
        UserVmVO vm = _vmDao.findById(vmId);
        vmNames.add(vm.getInstanceName());
    }
    Answer answer = _agentMgr.easySend(hostId, new GetVmDiskStatsCommand(vmNames, _hostDao.findById(hostId).getGuid(), hostName));
    if (answer == null || !answer.getResult()) {
        s_logger.warn("Unable to obtain VM disk statistics.");
        return null;
    } else {
        HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsByName = ((GetVmDiskStatsAnswer) answer).getVmDiskStatsMap();
        if (vmDiskStatsByName == null) {
            s_logger.warn("Unable to obtain VM disk statistics.");
            return null;
        }
        for (Map.Entry<String, List<VmDiskStatsEntry>> entry : vmDiskStatsByName.entrySet()) {
            vmDiskStatsById.put(vmIds.get(vmNames.indexOf(entry.getKey())), entry.getValue());
        }
    }
    return vmDiskStatsById;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmDiskStatsEntry(com.cloud.agent.api.VmDiskStatsEntry) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) 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) GetVmDiskStatsCommand(com.cloud.agent.api.GetVmDiskStatsCommand) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

GetVmDiskStatsCommand (com.cloud.agent.api.GetVmDiskStatsCommand)6 Answer (com.cloud.agent.api.Answer)5 ArrayList (java.util.ArrayList)4 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)2 StartAnswer (com.cloud.agent.api.StartAnswer)2 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)2 Test (org.junit.Test)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 CheckOnHostCommand (com.cloud.agent.api.CheckOnHostCommand)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1