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);
}
}
}
}
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;
}
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);
}
}
}
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();
}
}
}
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());
}
Aggregations