Search in sources :

Example 6 with QuotaStorage

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

Example 7 with QuotaStorage

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

Example 8 with QuotaStorage

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;
}
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 9 with QuotaStorage

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

Example 10 with QuotaStorage

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

QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)30 Quota (org.ovirt.engine.core.common.businessentities.Quota)16 QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)14 Guid (org.ovirt.engine.core.compat.Guid)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 ActionType (org.ovirt.engine.core.common.action.ActionType)3 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)3 Inject (com.google.inject.Inject)2 List (java.util.List)2 Map (java.util.Map)2 QuotaStorageLimits (org.ovirt.engine.api.model.QuotaStorageLimits)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