Search in sources :

Example 46 with Quota

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

the class QuotaDaoImpl method getQuotaMetaDataFromResultSet.

private Quota getQuotaMetaDataFromResultSet(ResultSet rs) throws SQLException {
    Quota entity = new Quota();
    entity.setId(getGuidDefaultEmpty(rs, "quota_id"));
    entity.setStoragePoolId(getGuidDefaultEmpty(rs, "storage_pool_id"));
    entity.setStoragePoolName(rs.getString("storage_pool_name"));
    entity.setQuotaName((String) rs.getObject("quota_name"));
    entity.setDescription((String) rs.getObject("description"));
    entity.setThresholdClusterPercentage((Integer) rs.getObject("threshold_cluster_percentage"));
    entity.setThresholdStoragePercentage((Integer) rs.getObject("threshold_storage_percentage"));
    entity.setGraceClusterPercentage((Integer) rs.getObject("grace_cluster_percentage"));
    entity.setGraceStoragePercentage((Integer) rs.getObject("grace_storage_percentage"));
    entity.setQuotaEnforcementType(QuotaEnforcementTypeEnum.forValue(rs.getInt("quota_enforcement_type")));
    entity.setDefault(rs.getBoolean("is_default"));
    return entity;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota)

Example 47 with Quota

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

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

the class QuotaDaoTest method testGetQuotaByExistingNameWIthNoMatchingStoragePool.

/**
 * Test get Quota by Name, with name that does not exist for the storage pool.
 */
@Test
public void testGetQuotaByExistingNameWIthNoMatchingStoragePool() throws Exception {
    Quota quotaGeneralToSpecific = dao.getQuotaByQuotaName("Quota General", FixturesTool.STORAGE_POOL_RHEL6_ISCSI_OTHER);
    assertNull(quotaGeneralToSpecific);
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) Test(org.junit.Test)

Example 49 with Quota

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

the class QuotaDaoTest method testGetDefaultQuotaForStoragePool.

@Test
public void testGetDefaultQuotaForStoragePool() {
    Quota quota = dao.getDefaultQuotaForStoragePool(FixturesTool.STORAGE_POOL_NFS);
    assertNotNull(quota);
    assertEquals(FixturesTool.STORAGE_POOL_NFS, quota.getStoragePoolId());
    assertTrue(quota.isDefault());
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) Test(org.junit.Test)

Example 50 with Quota

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

the class QuotaDaoTest method createGeneralQuota.

private static Quota createGeneralQuota() {
    Quota quota = new Quota();
    Guid quotaId = Guid.newGuid();
    quota.setId(quotaId);
    quota.setStoragePoolId(FixturesTool.STORAGE_POOL_NFS);
    quota.setQuotaName("Watson");
    quota.setDescription("General quota");
    quota.setThresholdClusterPercentage(80);
    quota.setThresholdStoragePercentage(80);
    quota.setGraceClusterPercentage(20);
    quota.setGraceStoragePercentage(20);
    return quota;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) Guid(org.ovirt.engine.core.compat.Guid)

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