Search in sources :

Example 21 with QuotaStorage

use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.

the class QuotaListModel method editQuota.

private void editQuota(boolean isClone) {
    Quota outer_quota = getSelectedItem();
    final QuotaModel qModel = new QuotaModel();
    qModel.getName().setEntity(outer_quota.getQuotaName());
    qModel.getGraceCluster().setEntity(outer_quota.getGraceClusterPercentage());
    qModel.getThresholdCluster().setEntity(outer_quota.getThresholdClusterPercentage());
    qModel.getGraceStorage().setEntity(outer_quota.getGraceStoragePercentage());
    qModel.getThresholdStorage().setEntity(outer_quota.getThresholdStoragePercentage());
    qModel.getDescription().setEntity(outer_quota.getDescription());
    qModel.setTitle(isClone ? ConstantsManager.getInstance().getConstants().cloneQuotaTitle() : ConstantsManager.getInstance().getConstants().editQuotaTitle());
    if (isClone) {
        qModel.setHelpTag(HelpTag.clone_quota);
        // $NON-NLS-1$
        qModel.setHashName("clone_quota");
    } else {
        qModel.setHelpTag(HelpTag.edit_quota);
        // $NON-NLS-1$
        qModel.setHashName("edit_quota");
    }
    UICommand command;
    if (!isClone) {
        // $NON-NLS-1$
        command = UICommand.createDefaultOkUiCommand("OnCreateQuota", this);
    } else {
        // $NON-NLS-1$
        command = UICommand.createDefaultOkUiCommand("onCloneQuota", this);
        qModel.getName().setEntity(COPY_OF + outer_quota.getQuotaName());
        // $NON-NLS-1$
        qModel.getDescription().setEntity("");
        qModel.getCopyPermissions().setIsAvailable(true);
    }
    qModel.getCommands().add(command);
    // $NON-NLS-1$
    UICommand cancelCommand = UICommand.createCancelUiCommand("Cancel", this);
    qModel.getCommands().add(cancelCommand);
    AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(returnValue -> {
        final Quota quota = returnValue.getReturnValue();
        qModel.setEntity(quota);
        if (quota.getGlobalQuotaCluster() != null) {
            QuotaCluster cluster = ((ArrayList<QuotaCluster>) qModel.getQuotaClusters().getItems()).get(0);
            cluster.setMemSizeMB(quota.getGlobalQuotaCluster().getMemSizeMB());
            cluster.setVirtualCpu(quota.getGlobalQuotaCluster().getVirtualCpu());
            cluster.setMemSizeMBUsage(quota.getGlobalQuotaCluster().getMemSizeMBUsage());
            cluster.setVirtualCpuUsage(quota.getGlobalQuotaCluster().getVirtualCpuUsage());
            qModel.getGlobalClusterQuota().setEntity(true);
        }
        if (quota.getGlobalQuotaStorage() != null) {
            QuotaStorage storage = ((ArrayList<QuotaStorage>) qModel.getQuotaStorages().getItems()).get(0);
            storage.setStorageSizeGB(quota.getGlobalQuotaStorage().getStorageSizeGB());
            storage.setStorageSizeGBUsage(quota.getGlobalQuotaStorage().getStorageSizeGBUsage());
            qModel.getGlobalStorageQuota().setEntity(true);
        }
        setWindow(qModel);
        qModel.startProgress();
        qModel.getDataCenter().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
            StoragePool selectedDataCenter = qModel.getDataCenter().getSelectedItem();
            AsyncDataProvider.getInstance().getClusterList(new AsyncQuery<>(clusterList -> {
                if (clusterList == null || clusterList.size() == 0) {
                    qModel.getAllDataCenterClusters().setItems(new ArrayList<QuotaCluster>());
                    if (quota.getGlobalQuotaCluster() == null) {
                        qModel.getSpecificClusterQuota().setEntity(true);
                    }
                    return;
                }
                ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>();
                QuotaCluster quotaCluster;
                for (Cluster cluster : clusterList) {
                    quotaCluster = new QuotaCluster();
                    quotaCluster.setClusterId(cluster.getId());
                    quotaCluster.setClusterName(cluster.getName());
                    quotaCluster.setQuotaId(quota.getId());
                    boolean containCluster = false;
                    for (QuotaCluster iter : quota.getQuotaClusters()) {
                        if (quotaCluster.getClusterId().equals(iter.getClusterId())) {
                            quotaCluster.setQuotaClusterId(iter.getQuotaClusterId());
                            quotaCluster.setMemSizeMB(iter.getMemSizeMB());
                            quotaCluster.setVirtualCpu(iter.getVirtualCpu());
                            quotaCluster.setMemSizeMBUsage(iter.getMemSizeMBUsage());
                            quotaCluster.setVirtualCpuUsage(iter.getVirtualCpuUsage());
                            containCluster = true;
                            break;
                        }
                    }
                    if (!containCluster) {
                        quotaCluster.setMemSizeMB(null);
                        quotaCluster.setVirtualCpu(null);
                        quotaCluster.setMemSizeMBUsage((long) 0);
                        quotaCluster.setVirtualCpuUsage(0);
                    }
                    quotaClusterList.add(quotaCluster);
                }
                qModel.getAllDataCenterClusters().setItems(quotaClusterList);
                if (quota.getGlobalQuotaCluster() == null) {
                    qModel.getSpecificClusterQuota().setEntity(true);
                }
            }), selectedDataCenter.getId());
            AsyncDataProvider.getInstance().getStorageDomainList(new AsyncQuery<>(storageList -> {
                if (storageList == null || storageList.size() == 0) {
                    qModel.getAllDataCenterStorages().setItems(new ArrayList<QuotaStorage>());
                    if (quota.getGlobalQuotaStorage() == null) {
                        qModel.getSpecificStorageQuota().setEntity(true);
                    }
                    qModel.stopProgress();
                    return;
                }
                ArrayList<QuotaStorage> quotaStorageList = new ArrayList<>();
                QuotaStorage quotaStorage;
                for (StorageDomain storage : storageList) {
                    if (!storage.getStorageDomainType().isDataDomain()) {
                        continue;
                    }
                    quotaStorage = new QuotaStorage();
                    quotaStorage.setStorageId(storage.getId());
                    quotaStorage.setStorageName(storage.getStorageName());
                    quotaStorage.setQuotaId(quota.getId());
                    boolean containStorage = false;
                    for (QuotaStorage iter : quota.getQuotaStorages()) {
                        if (quotaStorage.getStorageId().equals(iter.getStorageId())) {
                            quotaStorage.setQuotaStorageId(iter.getQuotaStorageId());
                            quotaStorage.setStorageSizeGB(iter.getStorageSizeGB());
                            quotaStorage.setStorageSizeGBUsage(iter.getStorageSizeGBUsage());
                            containStorage = true;
                            break;
                        }
                    }
                    if (!containStorage) {
                        quotaStorage.setStorageSizeGB(null);
                        quotaStorage.setStorageSizeGBUsage(0.0);
                    }
                    quotaStorageList.add(quotaStorage);
                }
                qModel.getAllDataCenterStorages().setItems(quotaStorageList);
                if (quota.getGlobalQuotaStorage() == null) {
                    qModel.getSpecificStorageQuota().setEntity(true);
                }
                qModel.stopProgress();
            }), selectedDataCenter.getId());
        });
        ArrayList<StoragePool> dataCenterList = new ArrayList<>();
        StoragePool dataCenter = new StoragePool();
        dataCenter.setId(quota.getStoragePoolId());
        dataCenter.setName(quota.getStoragePoolName());
        dataCenterList.add(dataCenter);
        qModel.getDataCenter().setItems(dataCenterList);
        qModel.getDataCenter().setSelectedItem(dataCenter);
        qModel.getDataCenter().setIsChangeable(false);
    });
    IdQueryParameters quotaParameters = new IdQueryParameters(outer_quota.getId());
    Frontend.getInstance().runQuery(QueryType.GetQuotaByQuotaId, quotaParameters, asyncQuery);
}
Also used : SearchType(org.ovirt.engine.core.common.interfaces.SearchType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) SearchObjects(org.ovirt.engine.core.searchbackend.SearchObjects) Guid(org.ovirt.engine.core.compat.Guid) Inject(com.google.inject.Inject) QuotaCRUDParameters(org.ovirt.engine.core.common.action.QuotaCRUDParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) SearchStringMapping(org.ovirt.engine.ui.uicommonweb.models.SearchStringMapping) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) Quota(org.ovirt.engine.core.common.businessentities.Quota) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ListWithSimpleDetailsModel(org.ovirt.engine.ui.uicommonweb.models.ListWithSimpleDetailsModel) WebAdminApplicationPlaces(org.ovirt.engine.ui.uicommonweb.place.WebAdminApplicationPlaces) IdParameters(org.ovirt.engine.core.common.action.IdParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ArrayList(java.util.ArrayList) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 22 with QuotaStorage

use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.

the class QuotaModel method validateNotEmpty.

private boolean validateNotEmpty() {
    getSpecificClusterQuota().setIsValid(true);
    getSpecificStorageQuota().setIsValid(true);
    if (getGlobalClusterQuota().getEntity() || getGlobalStorageQuota().getEntity()) {
        return true;
    }
    if (getAllDataCenterClusters().getItems() != null) {
        for (QuotaCluster quotaCluster : getAllDataCenterClusters().getItems()) {
            if (quotaCluster.getMemSizeMB() != null) {
                return true;
            }
        }
    }
    if (getAllDataCenterStorages().getItems() != null) {
        for (QuotaStorage quotaStorage : getAllDataCenterStorages().getItems()) {
            if (quotaStorage.getStorageSizeGB() != null) {
                return true;
            }
        }
    }
    getSpecificClusterQuota().validateEntity(new IValidation[] { quotaEmptyValidation });
    getSpecificStorageQuota().validateEntity(new IValidation[] { quotaEmptyValidation });
    return false;
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 23 with QuotaStorage

use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.

the class QuotaManager method saveNewConsumptionValues.

private void saveNewConsumptionValues(Map<Guid, Quota> quotaMap, Map<Guid, Double> newUsedGlobalStorageSize, Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize) {
    // cache new storage size.
    for (Map.Entry<Guid, Double> entry : newUsedGlobalStorageSize.entrySet()) {
        Quota quota = quotaMap.get(entry.getKey());
        double value = entry.getValue();
        if (value < 0) {
            log.error("Quota id '{}' cached storage size is negative, removing from cache", entry.getKey());
            quotaMap.remove(entry.getKey());
            continue;
        }
        quota.getGlobalQuotaStorage().setStorageSizeGBUsage(value);
    }
    for (Map.Entry<Guid, Map<Guid, Double>> quotaStorageEntry : newUsedSpecificStorageSize.entrySet()) {
        Quota quota = quotaMap.get(quotaStorageEntry.getKey());
        for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
            if (quotaStorageEntry.getValue().containsKey(quotaStorage.getStorageId())) {
                double value = quotaStorageEntry.getValue().get(quotaStorage.getStorageId());
                if (value < 0) {
                    log.error("Quota id '{}' cached storage size is negative, removing from cache", quotaStorageEntry.getKey());
                    quotaMap.remove(quotaStorageEntry.getKey());
                    continue;
                }
                quotaStorage.setStorageSizeGBUsage(value);
            }
        }
    }
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with QuotaStorage

use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.

the class QuotaManager method checkConsumptionForSpecificStorageQuota.

private boolean checkConsumptionForSpecificStorageQuota(QuotaConsumptionParametersWrapper parameters, Map<Guid, Map<Guid, Double>> desiredStorageSizeQuotaMap, Map<Guid, Map<Guid, Double>> newUsedSpecificStorageSize, Guid quotaId, Quota quota, Pair<AuditLogType, AuditLogableBase> auditLogPair) {
    newUsedSpecificStorageSize.put(quotaId, new HashMap<>());
    for (Guid storageId : desiredStorageSizeQuotaMap.get(quotaId).keySet()) {
        boolean hasStorageId = false;
        for (QuotaStorage quotaStorage : quota.getQuotaStorages()) {
            if (quotaStorage.getStorageId().equals(storageId)) {
                hasStorageId = true;
                if (!QuotaStorage.UNLIMITED.equals(quotaStorage.getStorageSizeGB())) {
                    double storageUsagePercentage = quotaStorage.getStorageSizeGBUsage() / quotaStorage.getStorageSizeGB() * 100;
                    double storageRequestPercentage = desiredStorageSizeQuotaMap.get(quotaId).get(storageId) / quotaStorage.getStorageSizeGB() * 100;
                    if (!checkQuotaStorageLimits(parameters.getAuditLogable().getStoragePool().getQuotaEnforcementType(), quota, quotaStorage.getStorageSizeGB(), storageUsagePercentage, storageRequestPercentage, parameters.getValidationMessages(), auditLogPair)) {
                        return false;
                    }
                    newUsedSpecificStorageSize.get(quotaId).put(storageId, quotaStorage.getStorageSizeGBUsage() + desiredStorageSizeQuotaMap.get(quotaId).get(storageId));
                }
            }
        }
        if (!hasStorageId) {
            if (quota.getQuotaEnforcementType() == QuotaEnforcementTypeEnum.HARD_ENFORCEMENT) {
                parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN.toString());
                return false;
            } else {
                auditLogPair.setFirst(AuditLogType.MISSING_QUOTA_STORAGE_PARAMETERS_PERMISSIVE_MODE);
            }
        }
    }
    return true;
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Guid(org.ovirt.engine.core.compat.Guid)

Example 25 with QuotaStorage

use of org.ovirt.engine.core.common.businessentities.QuotaStorage in project ovirt-engine by oVirt.

the class QuotaDaoTest method testFetchSpecificAndGeneralQuotaForStorage.

@Test
public void testFetchSpecificAndGeneralQuotaForStorage() throws Exception {
    List<QuotaStorage> quotaStorageList = dao.getQuotaStorageByStorageGuid(null, FixturesTool.QUOTA_SPECIFIC_AND_GENERAL);
    QuotaStorage quotaStorage = quotaStorageList.get(0);
    assertEquals(1, quotaStorageList.size());
    assertNotNull(quotaStorage);
    // Check if the global variable returns when null is initialization.
    assertTrue(quotaStorage.getStorageSizeGBUsage() > 0);
}
Also used : QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) 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