use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaManager method checkAndFetchQuota.
// check that quota id is valid and fetch the quota from db (or cache). add the quota to the param
private boolean checkAndFetchQuota(QuotaConsumptionParametersWrapper parameters, QuotaConsumptionParameter param, Pair<AuditLogType, AuditLogableBase> auditLogPair) throws InvalidQuotaParametersException {
if (param.getQuotaGuid() == null || Guid.Empty.equals(param.getQuotaGuid())) {
param.setQuotaGuid(storagePoolDefaultQuotaIdMap.get(parameters.getStoragePoolId()));
}
Quota quota = fetchQuotaFromCache(param.getQuotaGuid(), parameters.getStoragePool().getId());
if (quota == null) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NO_LONGER_AVAILABLE_IN_SYSTEM.toString());
parameters.getValidationMessages().add(String.format("$VmName %1$s", parameters.getAuditLogable().getVmName()));
auditLogPair.setFirst(param.getParameterType() == QuotaConsumptionParameter.ParameterType.STORAGE ? AuditLogType.MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE : AuditLogType.MISSING_QUOTA_CLUSTER_PARAMETERS_PERMISSIVE_MODE);
log.error("The quota id '{}' is not found in backend and DB.", param.getQuotaGuid());
corruptedParameters.add(param);
return false;
}
param.setQuota(quota);
return true;
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaManager method validateAndSetStorageQuotaHelper.
private boolean validateAndSetStorageQuotaHelper(QuotaConsumptionParametersWrapper parameters, Pair<AuditLogType, AuditLogableBase> auditLogPair) {
Map<Guid, Quota> quotaMap = storagePoolQuotaMap.get(parameters.getStoragePoolId());
Map<Guid, Map<Guid, Double>> desiredStorageSizeQuotaMap = new HashMap<>();
Map<Guid, Double> newUsedGlobalStorageSize = new HashMap<>();
Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize = new HashMap<>();
generateDesiredStorageSizeQuotaMap(parameters, desiredStorageSizeQuotaMap);
for (Guid quotaId : desiredStorageSizeQuotaMap.keySet()) {
Quota quota = quotaMap.get(quotaId);
if (quota.getGlobalQuotaStorage() != null) {
if (!checkConsumptionForGlobalStorageQuota(parameters, desiredStorageSizeQuotaMap, newUsedGlobalStorageSize, quotaId, quota, auditLogPair)) {
return false;
}
} else {
if (!checkConsumptionForSpecificStorageQuota(parameters, desiredStorageSizeQuotaMap, newUsedSpecificStorageSize, quotaId, quota, auditLogPair)) {
return false;
}
}
}
saveNewConsumptionValues(quotaMap, newUsedGlobalStorageSize, newUsedSpecificStorageSize);
return true;
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaDaoTest method testGetQuotaByExistingName.
/**
* Test get Quota by Name, with name of specific Quota.
*/
@Test
public void testGetQuotaByExistingName() throws Exception {
Quota quotaGeneralToSpecific = dao.getQuotaByQuotaName("Quota General", FixturesTool.STORAGE_POOL_NFS);
assertEquals(dao.getById(FixturesTool.QUOTA_GENERAL).getQuotaName(), quotaGeneralToSpecific.getQuotaName());
assertEquals(dao.getById(FixturesTool.QUOTA_GENERAL).getId(), quotaGeneralToSpecific.getId());
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaDaoTest method testUpdateQuota.
/**
* Make Quota specific to be the same as Quota general and specific.
*/
@Test
public void testUpdateQuota() throws Exception {
Quota quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL);
// Save quotaName and cluster list for future check.
String quotaName = "New Temporary name";
List<QuotaCluster> quotaClusterList = getQuotaCluster(getSpecificQuotaCluster(quotaGeneralToSpecific.getId()));
Long newStorageLimit = 2345L;
// Check before the update, that the fields are not equal.
assertFalse(quotaName.equals(quotaGeneralToSpecific.getQuotaName()));
assertNotEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size());
assertFalse(quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB().equals(newStorageLimit));
// Update
quotaGeneralToSpecific.setQuotaName(quotaName);
quotaGeneralToSpecific.getGlobalQuotaStorage().setStorageSizeGB(newStorageLimit);
quotaGeneralToSpecific.setQuotaClusters(quotaClusterList);
dao.update(quotaGeneralToSpecific);
quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL);
// Check after the update, that the fields are equal now.
assertEquals(quotaName, quotaGeneralToSpecific.getQuotaName());
assertEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size());
assertEquals(newStorageLimit, quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB());
}
use of org.ovirt.engine.core.common.businessentities.Quota in project ovirt-engine by oVirt.
the class QuotaDaoTest method testRemoveQuota.
@Test
public void testRemoveQuota() throws Exception {
Quota quota = dao.getById(FixturesTool.QUOTA_SPECIFIC_AND_GENERAL);
assertNotNull(quota);
dao.remove(FixturesTool.QUOTA_SPECIFIC_AND_GENERAL);
assertNull(dao.getById(FixturesTool.QUOTA_SPECIFIC_AND_GENERAL));
assertEquals(0, dao.getQuotaClusterByQuotaGuid(FixturesTool.QUOTA_SPECIFIC_AND_GENERAL).size());
assertEquals(0, dao.getQuotaStorageByQuotaGuid(FixturesTool.QUOTA_SPECIFIC_AND_GENERAL).size());
}
Aggregations