use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class BackendQuotaStorageLimitsResource method list.
@Override
public QuotaStorageLimits list() {
Quota quota = getQuota();
QuotaStorageLimits limits = new QuotaStorageLimits();
if (quota.getGlobalQuotaStorage() != null) {
addLimit(quotaId.toString(), limits, quota);
} else if (quota.getQuotaStorages() != null) {
for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
addLimit(quotaStorage.getStorageId().toString(), limits, quota);
}
}
return limits;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaManager method checkStoragePoolMatchQuota.
// In case this param is a QuotaStorageConsumptionParameter - check that it has a valid
// storage domain id which is handled by this quota
private boolean checkStoragePoolMatchQuota(QuotaConsumptionParametersWrapper parameters, QuotaStorageConsumptionParameter param) {
Quota quota = param.getQuota();
if (param.getStorageDomainId() == null) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
log.error("Quota storage parameters from command '{}' are missing storage domain id", parameters.getAuditLogable().getClass().getName());
return false;
}
boolean storageDomainInQuota = false;
if (quota.getGlobalQuotaStorage() != null) {
storageDomainInQuota = true;
} else {
for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
if (quotaStorage.getStorageId().equals(param.getStorageDomainId())) {
storageDomainInQuota = true;
break;
}
}
}
if (!storageDomainInQuota) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN.toString());
log.error("Quota storage parameters from command '{}'. Storage domain does not match quota", parameters.getAuditLogable().getClass().getName());
return false;
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaManager method addQuotaEntry.
private QuotaUsagePerUser addQuotaEntry(Quota quota) {
// if quota is not null (found in cache or DB) - add entry to quotaPerUserUsageEntityMap
if (quota != null) {
long storageLimit = 0;
double storageUsage = 0;
int cpuLimit = 0;
int cpuUsage = 0;
long memLimit = 0;
long memUsage = 0;
// calc storage
if (quota.getGlobalQuotaStorage() != null) {
storageLimit = quota.getGlobalQuotaStorage().getStorageSizeGB();
storageUsage = quota.getGlobalQuotaStorage().getStorageSizeGBUsage();
} else {
for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
// once storage was set unlimited it will remain so
if (QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
// Do not break because usage is still counting
storageLimit = QuotaStorage.UNLIMITED;
}
if (storageLimit != QuotaStorage.UNLIMITED) {
storageLimit += quotaStorage.getStorageSizeGB();
}
storageUsage += quotaStorage.getStorageSizeGBUsage();
}
}
// calc cpu and mem
if (quota.getGlobalQuotaCluster() != null) {
memLimit = quota.getGlobalQuotaCluster().getMemSizeMB();
memUsage = quota.getGlobalQuotaCluster().getMemSizeMBUsage();
cpuLimit = quota.getGlobalQuotaCluster().getVirtualCpu();
cpuUsage = quota.getGlobalQuotaCluster().getVirtualCpuUsage();
} else {
for (QuotaCluster quotaCluster : quota.getQuotaClusters()) {
// once mem was set unlimited it will remain so
if (QuotaCluster.UNLIMITED_MEM.equals(quotaCluster.getMemSizeMB())) {
// Do not break because usage is still counting
memLimit = QuotaCluster.UNLIMITED_MEM;
}
if (memLimit != QuotaCluster.UNLIMITED_MEM) {
memLimit += quotaCluster.getMemSizeMB();
}
// once cpu was set unlimited it will remain so
if (QuotaCluster.UNLIMITED_VCPU.equals(quotaCluster.getVirtualCpu())) {
// Do not break because usage is still counting
cpuLimit = QuotaCluster.UNLIMITED_VCPU;
}
if (cpuLimit != QuotaCluster.UNLIMITED_VCPU) {
cpuLimit += quotaCluster.getVirtualCpu();
}
memUsage += quotaCluster.getMemSizeMBUsage();
cpuUsage += quotaCluster.getVirtualCpuUsage();
}
}
return new QuotaUsagePerUser(quota.getId(), quota.getQuotaName(), storageLimit, storageUsage, cpuLimit, cpuUsage, memLimit, memUsage);
}
return null;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class QuotaMapper method map.
@Mapping(from = QuotaStorageLimit.class, to = org.ovirt.engine.core.common.businessentities.Quota.class)
public static org.ovirt.engine.core.common.businessentities.Quota map(QuotaStorageLimit model, org.ovirt.engine.core.common.businessentities.Quota template) {
org.ovirt.engine.core.common.businessentities.Quota entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.Quota();
QuotaStorage quotaStorage = new QuotaStorage();
if (model.isSetLimit()) {
quotaStorage.setStorageSizeGB(model.getLimit());
}
// specific SD
if (model.isSetStorageDomain() && model.getStorageDomain().isSetId()) {
quotaStorage.setStorageId(GuidUtils.asGuid(model.getStorageDomain().getId()));
entity.getQuotaStorages().add(quotaStorage);
} else {
// global
entity.setGlobalQuotaStorage(quotaStorage);
}
return entity;
}
use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.
the class UpdateQuotaCommandTest method testExecuteCommand.
@Test
public void testExecuteCommand() {
// Execute the command
command.executeCommand();
Quota parameterQuota = command.getParameters().getQuota();
Guid quotaId = parameterQuota.getId();
for (QuotaStorage quotaStorage : parameterQuota.getQuotaStorages()) {
assertNotNull("Quota Storage should have been assigned an ID", quotaStorage.getQuotaStorageId());
assertEquals("Wrong Qutoa ID on Quota Storage", quotaId, quotaStorage.getQuotaId());
}
for (QuotaCluster quotaCluster : parameterQuota.getQuotaClusters()) {
assertNotNull("Quota Cluster should have been assigned an ID", quotaCluster.getQuotaClusterId());
assertEquals("Wrong Qutoa ID on Quota Cluster", quotaId, quotaCluster.getQuotaId());
}
// Verify the quota was updated in the database
verify(quotaDao).update(parameterQuota);
// Assert the return value
assertTrue("Execution should be successful", command.getReturnValue().getSucceeded());
}
Aggregations