Search in sources :

Example 71 with Quota

use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.

the class QuotaManager method saveNewConsumptionValues.

private void saveNewConsumptionValues(Map<Guid, Quota> quotaMap, Map<Guid, Double> newUsedGlobalStorageSize, Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize) {
    // cache new storage size.
    for (Map.Entry<Guid, Double> entry : newUsedGlobalStorageSize.entrySet()) {
        Quota quota = quotaMap.get(entry.getKey());
        double value = entry.getValue();
        if (value < 0) {
            log.error("Quota id '{}' cached storage size is negative, removing from cache", entry.getKey());
            quotaMap.remove(entry.getKey());
            continue;
        }
        quota.getGlobalQuotaStorage().setStorageSizeGBUsage(value);
    }
    for (Map.Entry<Guid, Map<Guid, Double>> quotaStorageEntry : newUsedSpecificStorageSize.entrySet()) {
        Quota quota = quotaMap.get(quotaStorageEntry.getKey());
        for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
            if (quotaStorageEntry.getValue().containsKey(quotaStorage.getStorageId())) {
                double value = quotaStorageEntry.getValue().get(quotaStorage.getStorageId());
                if (value < 0) {
                    log.error("Quota id '{}' cached storage size is negative, removing from cache", quotaStorageEntry.getKey());
                    quotaMap.remove(quotaStorageEntry.getKey());
                    continue;
                }
                quotaStorage.setStorageSizeGBUsage(value);
            }
        }
    }
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 72 with Quota

use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.

the class QuotaManager method checkClusterMatchQuota.

// In case this param is a QuotaVdsConsumptionParameter - check that it has a valid
// vds group id which is handled by this quota
private boolean checkClusterMatchQuota(QuotaConsumptionParametersWrapper parameters, QuotaClusterConsumptionParameter param) {
    Quota quota = param.getQuota();
    if (param.getClusterId() == null) {
        parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
        log.error("Quota Vds parameters from command '{}' are missing vds group id", parameters.getAuditLogable().getClass().getName());
        return false;
    }
    boolean clusterInQuota = false;
    if (quota.getGlobalQuotaCluster() != null) {
        clusterInQuota = true;
    } else {
        for (QuotaCluster cluster : quota.getQuotaClusters()) {
            if (cluster.getClusterId().equals(param.getClusterId())) {
                clusterInQuota = true;
                break;
            }
        }
    }
    if (!clusterInQuota) {
        parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
        log.error("Quota Vds parameters from command '{}'. Vds group does not match quota", parameters.getAuditLogable().getClass().getName());
        return false;
    }
    return true;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 73 with Quota

use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.

the class QuotaManager method rollBackClusterConsumptionParameters.

private void rollBackClusterConsumptionParameters(List<QuotaClusterConsumptionParameter> executed) {
    for (QuotaClusterConsumptionParameter parameter : executed) {
        long requestedMemory = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedMemory() : parameter.getRequestedMemory();
        int requestedCpu = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedCpu() : parameter.getRequestedCpu();
        QuotaCluster quotaCluster = null;
        Quota quota = parameter.getQuota();
        if (quota.getGlobalQuotaCluster() != null) {
            // global cluster quota
            quotaCluster = quota.getGlobalQuotaCluster();
        } else {
            for (QuotaCluster cluster : quota.getQuotaClusters()) {
                if (cluster.getClusterId().equals(parameter.getClusterId())) {
                    quotaCluster = cluster;
                    break;
                }
            }
        }
        if (quotaCluster != null) {
            long newMemory = requestedMemory + quotaCluster.getMemSizeMBUsage();
            int newVcpu = requestedCpu + quotaCluster.getVirtualCpuUsage();
            cacheNewValues(quotaCluster, newMemory, newVcpu);
        }
    }
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 74 with Quota

use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.

the class QuotaManager method updateUsage.

/**
 * REturn a list of QuotaUsagePerUser representing the status of all the quotas in quotaIdsList
 *
 * @param quotaList
 *            quota list
 */
public void updateUsage(List<Quota> quotaList) {
    List<Quota> needToCache = new ArrayList<>();
    if (quotaList == null) {
        return;
    }
    lock.readLock().lock();
    try {
        for (Quota quotaExternal : quotaList) {
            // look for the quota in the cache
            Map<Guid, Quota> quotaMap = storagePoolQuotaMap.get(quotaExternal.getStoragePoolId());
            Quota quota = null;
            if (quotaMap != null) {
                quota = quotaMap.get(quotaExternal.getId());
            }
            // if quota not in cache look for it in DB and add it to cache
            if (quota == null) {
                needToCache.add(quotaExternal);
            } else {
                copyUsageData(quota, quotaExternal);
            }
        }
    } finally {
        lock.readLock().unlock();
    }
    // if some of the quota are not in cache and need to be cached
    if (!needToCache.isEmpty()) {
        lock.writeLock().lock();
        try {
            for (Quota quotaExternal : needToCache) {
                addStoragePoolToCache(quotaExternal.getStoragePoolId());
                Quota quota = fetchQuotaFromCache(quotaExternal.getId(), quotaExternal.getStoragePoolId());
                if (quota != null) {
                    copyUsageData(quota, quotaExternal);
                }
            }
        } finally {
            lock.writeLock().unlock();
        }
    }
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 75 with Quota

use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.

the class QuotaManager method addStoragePoolToCache.

private void addStoragePoolToCache(Guid storagePoolId) {
    if (storagePoolQuotaMap.containsKey(storagePoolId)) {
        return;
    }
    storagePoolQuotaMap.put(storagePoolId, new HashMap<>());
    Quota defaultQuota = getQuotaDao().getDefaultQuotaForStoragePool(storagePoolId);
    storagePoolDefaultQuotaIdMap.put(storagePoolId, defaultQuota.getId());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota)

Aggregations

Quota (org.ovirt.engine.core.common.businessentities.Quota)101 ArrayList (java.util.ArrayList)23 Guid (org.ovirt.engine.core.compat.Guid)22 Test (org.junit.Test)17 QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)17 QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)16 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)12 HashMap (java.util.HashMap)9 List (java.util.List)9 QueryType (org.ovirt.engine.core.common.queries.QueryType)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)8 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)6 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)6 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)6 Map (java.util.Map)5 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)5 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)5 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)5