Search in sources :

Example 11 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster 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 QuotaCluster

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

the class QuotaDaoTest method testFetchSpecificQuotaUsageForGlobalCluster.

/**
 * Test scenario when there is a specific limitation on the storage pool, and we check limitation on the entire
 * storage pool.<BR/>
 * The value that should be returned, is the specific limitations and the specific usage on the storage pool.
 */
@Test
public void testFetchSpecificQuotaUsageForGlobalCluster() throws Exception {
    List<QuotaCluster> quotaClusterList = dao.getQuotaClusterByClusterGuid(null, FixturesTool.QUOTA_SPECIFIC);
    QuotaCluster quotaCluster = quotaClusterList.get(0);
    assertEquals(2, quotaClusterList.size());
    assertNotNull(quotaCluster);
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Example 13 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster 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 QuotaCluster

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

the class QuotaDaoTest method testFetchGlobalQuotaUsageForSpecificCluster.

/**
 * Test scenario when there is a global limitation on the storage pool, and we check if there is enough resources on a
 * specific vds group.<BR/>
 * The returned value from the query, should be the global limitation and the global usage on the storage pool.
 */
@Test
public void testFetchGlobalQuotaUsageForSpecificCluster() throws Exception {
    List<QuotaCluster> quotaClusterList = dao.getQuotaClusterByClusterGuid(FixturesTool.CLUSTER_RHEL6_ISCSI, FixturesTool.QUOTA_GENERAL);
    QuotaCluster quotaCluster = quotaClusterList.get(0);
    assertNotNull(quotaCluster);
    assertEquals(1, quotaClusterList.size());
    assertTrue(quotaCluster.getMemSizeMBUsage() > 0);
    assertTrue(quotaCluster.getVirtualCpuUsage() > 0);
    // Check if the global variable returns when null is initialization.
    assertEquals(Integer.valueOf(100), quotaCluster.getVirtualCpu());
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Example 15 with QuotaCluster

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

the class QuotaDaoTest method testFetchSpecificQuotaUsageForSpecificCluster.

/**
 * Test scenario when there is a specific limitation on the storage pool, and we check if there is enough resources on a
 * specific vds group.<BR/>
 * The returned value from the query, should be the specific limitation and the specific usage on the vds group.
 */
@Test
public void testFetchSpecificQuotaUsageForSpecificCluster() throws Exception {
    List<QuotaCluster> quotaClusterList = dao.getQuotaClusterByClusterGuid(FixturesTool.CLUSTER_RHEL6_ISCSI, FixturesTool.QUOTA_SPECIFIC);
    QuotaCluster quotaCluster = quotaClusterList.get(0);
    assertNotNull(quotaCluster);
    assertEquals(1, quotaClusterList.size());
    // Check if the global variable returns when null is initialization.
    assertEquals(Integer.valueOf(10), quotaCluster.getVirtualCpu());
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Test(org.junit.Test)

Aggregations

QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)36 Quota (org.ovirt.engine.core.common.businessentities.Quota)17 QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)14 Test (org.junit.Test)12 Guid (org.ovirt.engine.core.compat.Guid)8 ArrayList (java.util.ArrayList)5 ActionType (org.ovirt.engine.core.common.action.ActionType)3 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)3 Inject (com.google.inject.Inject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 QuotaClusterLimit (org.ovirt.engine.api.model.QuotaClusterLimit)2 QuotaClusterLimits (org.ovirt.engine.api.model.QuotaClusterLimits)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