Search in sources :

Example 6 with GetVmStatsAnswer

use of com.cloud.agent.api.GetVmStatsAnswer in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
    List<String> vmNames = cmd.getVmNames();
    try {
        HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
        Connect conn = LibvirtConnection.getConnection();
        for (String vmName : vmNames) {
            VmStatsEntry statEntry = getVmStat(conn, vmName);
            if (statEntry == null) {
                continue;
            }
            vmStatsNameMap.put(vmName, statEntry);
        }
        return new GetVmStatsAnswer(cmd, vmStatsNameMap);
    } catch (LibvirtException e) {
        s_logger.debug("Can't get vm stats: " + e.toString());
        return new GetVmStatsAnswer(cmd, null);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 7 with GetVmStatsAnswer

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

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<String, VmStatsEntry>();
        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 (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.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 8 with GetVmStatsAnswer

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

the class OvmResourceBase method execute.

protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
    List<String> vmNames = cmd.getVmNames();
    HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
    for (String vmName : vmNames) {
        try {
            VmStatsEntry e = getVmStat(vmName);
            vmStatsNameMap.put(vmName, e);
        } catch (XmlRpcException e) {
            s_logger.debug("Get vm stat for " + vmName + " failed", e);
            continue;
        }
    }
    return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 9 with GetVmStatsAnswer

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

the class MockVmManagerImpl method getVmStats.

@Override
public Answer getVmStats(final GetVmStatsCommand cmd) {
    final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
    final List<String> vmNames = cmd.getVmNames();
    for (final String vmName : vmNames) {
        final VmStatsEntry entry = new VmStatsEntry(0, 0, 0, 0, 0, 0, 0, "vm");
        // default values 256 KBps
        entry.setNetworkReadKBs(32768);
        entry.setNetworkWriteKBs(16384);
        entry.setCPUUtilization(10);
        entry.setNumCPUs(1);
        vmStatsNameMap.put(vmName, entry);
    }
    return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 10 with GetVmStatsAnswer

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

the class VmwareResource method execute.

protected Answer execute(GetVmStatsCommand cmd) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Executing resource GetVmStatsCommand: " + _gson.toJson(cmd));
    }
    HashMap<String, VmStatsEntry> vmStatsMap = null;
    try {
        HashMap<String, PowerState> vmPowerStates = getVmStates();
        // getVmNames should return all i-x-y values.
        List<String> requestedVmNames = cmd.getVmNames();
        List<String> vmNames = new ArrayList<String>();
        if (requestedVmNames != null) {
            for (String vmName : requestedVmNames) {
                if (vmPowerStates.get(vmName) != null) {
                    vmNames.add(vmName);
                }
            }
        }
        if (vmNames != null) {
            vmStatsMap = getVmStats(vmNames);
        }
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        s_logger.error("Unable to execute GetVmStatsCommand due to : " + VmwareHelper.getExceptionMessage(e), e);
    }
    Answer answer = new GetVmStatsAnswer(cmd, vmStatsMap);
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Report GetVmStatsAnswer: " + _gson.toJson(answer));
    }
    return answer;
}
Also used : ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) ArrayList(java.util.ArrayList) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) RemoteException(java.rmi.RemoteException) PowerState(com.cloud.vm.VirtualMachine.PowerState) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

Aggregations

GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)11 VmStatsEntry (com.cloud.agent.api.VmStatsEntry)9 HashMap (java.util.HashMap)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ArrayList (java.util.ArrayList)5 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)3 Answer (com.cloud.agent.api.Answer)2 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)2 StartAnswer (com.cloud.agent.api.StartAnswer)2 Test (org.junit.Test)2 Connect (org.libvirt.Connect)2 LibvirtException (org.libvirt.LibvirtException)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 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)1 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)1 DeleteVMSnapshotAnswer (com.cloud.agent.api.DeleteVMSnapshotAnswer)1