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;
}
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;
}
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);
}
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());
}
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;
}
Aggregations