Search in sources :

Example 76 with Quota

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;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota)

Example 77 with Quota

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;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 78 with Quota

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());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) Test(org.junit.Test)

Example 79 with Quota

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());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Example 80 with Quota

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());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) Test(org.junit.Test)

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