Search in sources :

Example 6 with VolumeStatsEntry

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

the class VmwareResource method execute.

protected GetVolumeStatsAnswer execute(GetVolumeStatsCommand cmd) {
    try {
        VmwareHypervisorHost srcHyperHost = getHyperHost(getServiceContext());
        ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, cmd.getPoolUuid());
        assert (morDs != null);
        DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(getServiceContext(), morDs);
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
        DatacenterMO dcMo = new DatacenterMO(getServiceContext(), dcMor);
        HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
        for (String chainInfo : cmd.getVolumeUuids()) {
            if (chainInfo != null) {
                VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
                if (infoInChain != null) {
                    String[] disks = infoInChain.getDiskChain();
                    if (disks.length > 0) {
                        for (String diskPath : disks) {
                            DatastoreFile file = new DatastoreFile(diskPath);
                            VirtualMachineMO vmMo = dcMo.findVm(file.getDir());
                            Pair<VirtualDisk, String> vds = vmMo.getDiskDevice(file.getFileName(), true);
                            long virtualsize = vds.first().getCapacityInKB() * 1024;
                            long physicalsize = primaryStorageDatastoreMo.fileDiskSize(file.getPath());
                            if (statEntry.containsKey(chainInfo)) {
                                VolumeStatsEntry vse = statEntry.get(chainInfo);
                                if (vse != null) {
                                    vse.setPhysicalSize(vse.getPhysicalSize() + physicalsize);
                                }
                            } else {
                                VolumeStatsEntry vse = new VolumeStatsEntry(chainInfo, physicalsize, virtualsize);
                                statEntry.put(chainInfo, vse);
                            }
                        }
                    }
                }
            }
        }
        s_logger.debug(String.format("Volume Stats Entry is: [%s].", _gson.toJson(statEntry)));
        return new GetVolumeStatsAnswer(cmd, "", statEntry);
    } catch (Exception e) {
        s_logger.error(String.format("VOLSTAT GetVolumeStatsCommand failed due to [%s].", VmwareHelper.getExceptionMessage(e)), e);
    }
    return new GetVolumeStatsAnswer(cmd, "", null);
}
Also used : VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) HashMap(java.util.HashMap) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) VirtualDisk(com.vmware.vim25.VirtualDisk) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Example 7 with VolumeStatsEntry

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

the class CitrixGetVolumeStatsCommandWrapper method execute.

@Override
public Answer execute(final GetVolumeStatsCommand cmd, final CitrixResourceBase citrixResourceBase) {
    Connection conn = citrixResourceBase.getConnection();
    HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
    for (String volumeUuid : cmd.getVolumeUuids()) {
        VDI vdi = citrixResourceBase.getVDIbyUuid(conn, volumeUuid, false);
        if (vdi != null) {
            try {
                VolumeStatsEntry vse = new VolumeStatsEntry(volumeUuid, vdi.getPhysicalUtilisation(conn), vdi.getVirtualSize(conn));
                statEntry.put(volumeUuid, vse);
            } catch (Exception e) {
                s_logger.warn("Unable to get volume stats", e);
                statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1, -1));
            }
        } else {
            s_logger.warn("VDI not found for path " + volumeUuid);
            statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1L, -1L));
        }
    }
    return new GetVolumeStatsAnswer(cmd, "", statEntry);
}
Also used : VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Aggregations

VolumeStatsEntry (com.cloud.agent.api.VolumeStatsEntry)7 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)5 HashMap (java.util.HashMap)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 GetVolumeStatsCommand (com.cloud.agent.api.GetVolumeStatsCommand)2 ConfigurationException (javax.naming.ConfigurationException)2 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)2 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)2 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 Answer (com.cloud.agent.api.Answer)1 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)1 GetVmNetworkStatsAnswer (com.cloud.agent.api.GetVmNetworkStatsAnswer)1 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)1 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)1 StartAnswer (com.cloud.agent.api.StartAnswer)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 HostVO (com.cloud.host.HostVO)1 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)1 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)1