Search in sources :

Example 11 with QuotaStorage

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

the class QuotaDaoImpl method getAllQuotaIncludingConsumption.

/**
 * Get all the full quotas. Including consumption data. This call is very heavy and should be used really and with
 * caution. It was created to support cache initialization
 *
 * @return all quota in DB (including consumption calculation)
 */
@Override
public List<Quota> getAllQuotaIncludingConsumption() {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    // get thin quota (only basic quota meta data)
    List<Quota> allThinQuota = getCallsHandler().executeReadList("getAllThinQuota", getQuotaMetaDataFromResultSet(), parameterSource);
    if (!allThinQuota.isEmpty()) {
        Map<Guid, Quota> allQuotaMap = new HashMap<>();
        for (Quota quota : allThinQuota) {
            allQuotaMap.put(quota.getId(), quota);
        }
        List<QuotaStorage> quotaStorageList = getAllQuotaStorageIncludingConsumption();
        List<QuotaCluster> quotaClusterList = getAllQuotaClusterIncludingConsumption();
        for (QuotaStorage quotaStorage : quotaStorageList) {
            Quota quota = allQuotaMap.get(quotaStorage.getQuotaId());
            if (quota != null) {
                if (quotaStorage.getStorageId() == null || quotaStorage.getStorageId().equals(Guid.Empty)) {
                    quota.setGlobalQuotaStorage(quotaStorage);
                } else {
                    if (quota.getQuotaStorages() == null) {
                        quota.setQuotaStorages(new ArrayList<>());
                    }
                    quota.getQuotaStorages().add(quotaStorage);
                }
            }
        }
        for (QuotaCluster quotaCluster : quotaClusterList) {
            Quota quota = allQuotaMap.get(quotaCluster.getQuotaId());
            if (quota != null) {
                if (quotaCluster.getClusterId() == null || quotaCluster.getClusterId().equals(Guid.Empty)) {
                    quota.setGlobalQuotaCluster(quotaCluster);
                } else {
                    if (quota.getQuotaClusters() == null) {
                        quota.setQuotaClusters(new ArrayList<>());
                    }
                    quota.getQuotaClusters().add(quotaCluster);
                }
            }
        }
    }
    // The thin quota were all filled
    return allThinQuota;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) HashMap(java.util.HashMap) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 12 with QuotaStorage

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

the class QuotaDaoTest method testQuotaStorageByQuotaGuidWithGeneralDefaultNoDefault.

/**
 * Asserts that when {@link QuotaDao#getQuotaStorageByQuotaGuidWithGeneralDefault(Guid)} is called
 * with a specific quota, all the relevant storages are returned
 */
@Test
public void testQuotaStorageByQuotaGuidWithGeneralDefaultNoDefault() {
    List<QuotaStorage> quotaStorageList = dao.getQuotaStorageByQuotaGuidWithGeneralDefault(FixturesTool.QUOTA_SPECIFIC);
    assertNotNull(quotaStorageList);
    assertEquals("wrong number of quotas returned", 1, quotaStorageList.size());
    for (QuotaStorage group : quotaStorageList) {
        assertNotNull("Storage ID should not be null in specific mode", group.getStorageId());
        assertNotNull("Storage name should not be null in specific mode", group.getStorageName());
    }
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Test(org.junit.Test)

Example 13 with QuotaStorage

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

the class QuotaDaoTest method setQuotaGlobalLimitations.

private static void setQuotaGlobalLimitations(Quota quota) {
    QuotaStorage quotaStorage = new QuotaStorage();
    QuotaCluster quotaCluster = new QuotaCluster();
    // Set Quota storage capacity definition.
    quotaStorage.setStorageSizeGB(10000L);
    quotaStorage.setStorageSizeGBUsage(0d);
    // Set Quota cluster virtual memory definition.
    quotaCluster.setMemSizeMB(16000000L);
    quotaCluster.setMemSizeMBUsage(0L);
    // Set Quota cluster virtual CPU definition.
    quotaCluster.setVirtualCpu(2880);
    quotaCluster.setVirtualCpuUsage(0);
    quota.setGlobalQuotaStorage(quotaStorage);
    quota.setGlobalQuotaCluster(quotaCluster);
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 14 with QuotaStorage

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

the class QuotaDaoTest method getSpecificQuotaStorage.

private static QuotaStorage getSpecificQuotaStorage(Guid quotaId) {
    QuotaStorage quotaStorage = new QuotaStorage();
    quotaStorage.setQuotaId(quotaId);
    quotaStorage.setQuotaStorageId(Guid.newGuid());
    quotaStorage.setStorageId(FixturesTool.STORAGE_DOMAIN_NFS_MASTER);
    quotaStorage.setStorageSizeGB(10000L);
    quotaStorage.setStorageSizeGBUsage(0d);
    return quotaStorage;
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage)

Example 15 with QuotaStorage

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

the class QuotaDaoTest method testSpecificAndGeneralQuotaLimitations.

@Test
public void testSpecificAndGeneralQuotaLimitations() throws Exception {
    // Set new Quota definition.
    Quota quota = createGeneralQuota();
    quota.setQuotaClusters(getQuotaCluster(getSpecificQuotaCluster(quota.getId())));
    quota.setQuotaStorages(getQuotaStorage(null));
    quota.setGlobalQuotaStorage(new QuotaStorage(null, null, null, 10000L, 0d));
    dao.save(quota);
    Quota quotaEntity = dao.getById(quota.getId());
    assertNotNull(quotaEntity);
    assertEquals(quota, quotaEntity);
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) Test(org.junit.Test)

Aggregations

QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)30 Quota (org.ovirt.engine.core.common.businessentities.Quota)16 QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)14 Guid (org.ovirt.engine.core.compat.Guid)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 ActionType (org.ovirt.engine.core.common.action.ActionType)3 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)3 Inject (com.google.inject.Inject)2 List (java.util.List)2 Map (java.util.Map)2 QuotaStorageLimits (org.ovirt.engine.api.model.QuotaStorageLimits)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 IdParameters (org.ovirt.engine.core.common.action.IdParameters)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 SearchType (org.ovirt.engine.core.common.interfaces.SearchType)2 ApplicationMode (org.ovirt.engine.core.common.mode.ApplicationMode)2