use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaManagerTest method getQuotaCluster.
private QuotaCluster getQuotaCluster(int vCpu, int vCpuUsed, long mem, long memUsed) {
QuotaCluster clusterQuota = new QuotaCluster();
clusterQuota.setVirtualCpu(vCpu);
clusterQuota.setVirtualCpuUsage(vCpuUsed);
clusterQuota.setMemSizeMB(mem);
clusterQuota.setMemSizeMBUsage(memUsed);
clusterQuota.setClusterId(DESTINATION_GUID);
return clusterQuota;
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class BackendQuotaClusterLimitsResource method list.
@Override
public QuotaClusterLimits list() {
Quota quota = getQuota();
QuotaClusterLimits limits = new QuotaClusterLimits();
if (quota.getGlobalQuotaCluster() != null) {
addLimit(quotaId.toString(), limits, quota);
} else if (quota.getQuotaClusters() != null) {
for (QuotaCluster quotaCluster : quota.getQuotaClusters()) {
addLimit(quotaCluster.getClusterId().toString(), limits, quota);
}
}
return limits;
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster in project ovirt-engine by oVirt.
the class QuotaManager method validateAndSetClusterQuota.
private boolean validateAndSetClusterQuota(QuotaConsumptionParametersWrapper parameters, Pair<AuditLogType, AuditLogableBase> auditLogPair) {
boolean result = true;
List<QuotaClusterConsumptionParameter> executed = new ArrayList<>();
for (QuotaConsumptionParameter parameter : parameters.getParameters()) {
QuotaClusterConsumptionParameter clusterConsumptionParameter;
if (parameter.getParameterType() != QuotaConsumptionParameter.ParameterType.CLUSTER) {
continue;
} else {
clusterConsumptionParameter = (QuotaClusterConsumptionParameter) parameter;
}
Quota quota = parameter.getQuota();
QuotaCluster quotaCluster = null;
if (quota.getGlobalQuotaCluster() != null) {
// global cluster quota
quotaCluster = quota.getGlobalQuotaCluster();
} else {
for (QuotaCluster cluster : quota.getQuotaClusters()) {
if (cluster.getClusterId().equals(clusterConsumptionParameter.getClusterId())) {
quotaCluster = cluster;
break;
}
}
}
if (quotaCluster == null) {
parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
result = false;
break;
}
long requestedMemory = clusterConsumptionParameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? clusterConsumptionParameter.getRequestedMemory() : -clusterConsumptionParameter.getRequestedMemory();
int requestedCpu = clusterConsumptionParameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? clusterConsumptionParameter.getRequestedCpu() : -clusterConsumptionParameter.getRequestedCpu();
if (checkQuotaClusterLimits(parameters.getAuditLogable().getStoragePool().getQuotaEnforcementType(), quota, quotaCluster, requestedMemory, requestedCpu, parameters.getValidationMessages(), auditLogPair)) {
executed.add(clusterConsumptionParameter);
} else {
result = false;
break;
}
}
// if result is false (one or more parameters did not pass) - roll back the parameters that did pass
if (!result) {
rollBackClusterConsumptionParameters(executed);
}
return result;
}
use of org.ovirt.engine.core.common.businessentities.QuotaCluster 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.QuotaCluster 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