Search in sources :

Example 1 with VolumeStatsEntry

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

the class LibvirtGetVolumeStatsCommandWrapper method getVolumeStat.

private VolumeStatsEntry getVolumeStat(final LibvirtComputingResource libvirtComputingResource, final Connect conn, final String volumeUuid, final String storeUuid, final StoragePoolType poolType) throws LibvirtException {
    KVMStoragePool sourceKVMPool = libvirtComputingResource.getStoragePoolMgr().getStoragePool(poolType, storeUuid);
    if (sourceKVMPool == null) {
        return null;
    }
    KVMPhysicalDisk sourceKVMVolume = sourceKVMPool.getPhysicalDisk(volumeUuid);
    if (sourceKVMVolume == null) {
        return null;
    }
    return new VolumeStatsEntry(volumeUuid, sourceKVMVolume.getSize(), sourceKVMVolume.getVirtualSize());
}
Also used : KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)

Example 2 with VolumeStatsEntry

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

the class LibvirtGetVolumeStatsCommandWrapper method execute.

@Override
public Answer execute(final GetVolumeStatsCommand cmd, final LibvirtComputingResource libvirtComputingResource) {
    try {
        Connect conn = LibvirtConnection.getConnection();
        String storeUuid = cmd.getPoolUuid();
        StoragePoolType poolType = cmd.getPoolType();
        HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
        for (String volumeUuid : cmd.getVolumeUuids()) {
            VolumeStatsEntry volumeStatsEntry = getVolumeStat(libvirtComputingResource, conn, volumeUuid, storeUuid, poolType);
            if (volumeStatsEntry == null) {
                String msg = "Can't get disk stats as pool or disk details unavailable for volume: " + volumeUuid + " on the storage pool: " + storeUuid;
                return new GetVolumeStatsAnswer(cmd, msg, null);
            }
            statEntry.put(volumeUuid, volumeStatsEntry);
        }
        return new GetVolumeStatsAnswer(cmd, "", statEntry);
    } catch (LibvirtException | CloudRuntimeException e) {
        return new GetVolumeStatsAnswer(cmd, "Can't get vm disk stats: " + e.getMessage(), null);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) HashMap(java.util.HashMap) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Example 3 with VolumeStatsEntry

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

the class StorageManagerImpl method getVolumeStats.

@Override
public Answer getVolumeStats(StoragePool pool, Command cmd) {
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
    HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
    GetVolumeStatsCommand getVolumeStatsCommand = (GetVolumeStatsCommand) cmd;
    for (String volumeUuid : getVolumeStatsCommand.getVolumeUuids()) {
        Pair<Long, Long> volumeStats = primaryStoreDriver.getVolumeStats(pool, volumeUuid);
        if (volumeStats == null) {
            return new GetVolumeStatsAnswer(getVolumeStatsCommand, "Failed to get stats for volume: " + volumeUuid, null);
        } else {
            VolumeStatsEntry volumeStatsEntry = new VolumeStatsEntry(volumeUuid, volumeStats.first(), volumeStats.second());
            statEntry.put(volumeUuid, volumeStatsEntry);
        }
    }
    return new GetVolumeStatsAnswer(getVolumeStatsCommand, "", statEntry);
}
Also used : PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) HashMap(java.util.HashMap) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Example 4 with VolumeStatsEntry

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

the class UserVmManagerImpl method getVolumeStatistics.

@Override
public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) {
    List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up);
    StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid);
    HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>();
    for (HostVO neighbor : neighbors) {
        // - zone wide storage for specific hypervisortypes
        if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) {
            // skip this neighbour if their hypervisor type is not the same as that of the store
            continue;
        }
        List<String> volumeLocators = getVolumesByHost(neighbor, storagePool);
        if (!CollectionUtils.isEmpty(volumeLocators)) {
            GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators);
            Answer answer = null;
            DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
            DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
            if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver) storeDriver).canProvideVolumeStats()) {
                // Get volume stats from the pool directly instead of sending cmd to host
                answer = storageManager.getVolumeStats(storagePool, cmd);
            } else {
                if (timeout > 0) {
                    cmd.setWait(timeout / 1000);
                }
                answer = _agentMgr.easySend(neighbor.getId(), cmd);
            }
            if (answer != null && answer instanceof GetVolumeStatsAnswer) {
                GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer) answer;
                if (volstats.getVolumeStats() != null) {
                    volumeStatsByUuid.putAll(volstats.getVolumeStats());
                }
            }
        }
    }
    return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null;
}
Also used : VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) HostVO(com.cloud.host.HostVO) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) Answer(com.cloud.agent.api.Answer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer)

Example 5 with VolumeStatsEntry

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

the class MockStorageManagerImpl method getVolumeStat.

private VolumeStatsEntry getVolumeStat(final String volumeUuid) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        MockVolumeVO volume = _mockVolumeDao.findByUuid(volumeUuid);
        txn.commit();
        return new VolumeStatsEntry(volumeUuid, volume.getSize(), volume.getSize());
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding volume " + volumeUuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) VolumeStatsEntry(com.cloud.agent.api.VolumeStatsEntry) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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