Search in sources :

Example 6 with QuotaCluster

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;
}
Also used : QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 7 with QuotaCluster

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;
}
Also used : QuotaClusterLimits(org.ovirt.engine.api.model.QuotaClusterLimits) Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 8 with QuotaCluster

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;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 9 with QuotaCluster

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;
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) QuotaUsagePerUser(org.ovirt.engine.core.common.businessentities.QuotaUsagePerUser) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 10 with QuotaCluster

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());
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Guid(org.ovirt.engine.core.compat.Guid) 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