Search in sources :

Example 21 with QuotaCluster

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

the class QuotaListModel method createQuota.

protected void createQuota(boolean populateDataCenter) {
    final QuotaModel qModel = new QuotaModel();
    qModel.setTitle(ConstantsManager.getInstance().getConstants().newQuotaTitle());
    qModel.setHelpTag(HelpTag.new_quota);
    // $NON-NLS-1$
    qModel.setHashName("new_quota");
    Quota newQuota = new Quota();
    qModel.setEntity(newQuota);
    setWindow(qModel);
    qModel.startProgress();
    if (populateDataCenter) {
        AsyncDataProvider.getInstance().getDataCenterList(new AsyncQuery<>(dataCenterList -> {
            if (dataCenterList == null || dataCenterList.size() == 0) {
                return;
            }
            QuotaModel quotaModel = (QuotaModel) getWindow();
            quotaModel.getDataCenter().setItems(dataCenterList);
            quotaModel.getDataCenter().setSelectedItem(dataCenterList.get(0));
        }));
    }
    qModel.getDataCenter().getSelectedItemChangedEvent().addListener((ev, sender, args) -> {
        StoragePool selectedDataCenter = qModel.getDataCenter().getSelectedItem();
        if (selectedDataCenter == null) {
            return;
        }
        AsyncDataProvider.getInstance().getClusterList(new AsyncQuery<>(clusterList -> {
            if (clusterList == null || clusterList.size() == 0) {
                qModel.getAllDataCenterClusters().setItems(new ArrayList<QuotaCluster>());
                return;
            }
            ArrayList<QuotaCluster> quotaClusterList = new ArrayList<>();
            QuotaCluster quotaCluster;
            for (Cluster cluster : clusterList) {
                quotaCluster = new QuotaCluster();
                quotaCluster.setClusterId(cluster.getId());
                quotaCluster.setClusterName(cluster.getName());
                quotaCluster.setMemSizeMB(null);
                quotaCluster.setMemSizeMBUsage((long) 0);
                quotaCluster.setVirtualCpu(null);
                quotaCluster.setVirtualCpuUsage(0);
                quotaClusterList.add(quotaCluster);
            }
            qModel.getAllDataCenterClusters().setItems(quotaClusterList);
        }), selectedDataCenter.getId());
        AsyncDataProvider.getInstance().getStorageDomainList(new AsyncQuery<>(storageList -> {
            if (storageList == null || storageList.size() == 0) {
                qModel.getAllDataCenterStorages().setItems(new ArrayList<QuotaStorage>());
                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.setStorageSizeGB(null);
                quotaStorage.setStorageSizeGBUsage((double) 0);
                quotaStorageList.add(quotaStorage);
            }
            qModel.getAllDataCenterStorages().setItems(quotaStorageList);
            qModel.stopProgress();
        }), selectedDataCenter.getId());
    });
    // $NON-NLS-1$
    UICommand command = UICommand.createDefaultOkUiCommand("OnCreateQuota", this);
    qModel.getCommands().add(command);
    // $NON-NLS-1$
    qModel.getCommands().add(UICommand.createCancelUiCommand("Cancel", this));
}
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) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 22 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster 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 23 with QuotaCluster

use of org.ovirt.engine.core.common.businessentities.QuotaCluster 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 24 with QuotaCluster

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

the class QuotaManager method checkClusterMatchQuota.

// In case this param is a QuotaVdsConsumptionParameter - check that it has a valid
// vds group id which is handled by this quota
private boolean checkClusterMatchQuota(QuotaConsumptionParametersWrapper parameters, QuotaClusterConsumptionParameter param) {
    Quota quota = param.getQuota();
    if (param.getClusterId() == null) {
        parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
        log.error("Quota Vds parameters from command '{}' are missing vds group id", parameters.getAuditLogable().getClass().getName());
        return false;
    }
    boolean clusterInQuota = false;
    if (quota.getGlobalQuotaCluster() != null) {
        clusterInQuota = true;
    } else {
        for (QuotaCluster cluster : quota.getQuotaClusters()) {
            if (cluster.getClusterId().equals(param.getClusterId())) {
                clusterInQuota = true;
                break;
            }
        }
    }
    if (!clusterInQuota) {
        parameters.getValidationMessages().add(EngineMessage.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
        log.error("Quota Vds parameters from command '{}'. Vds group does not match quota", parameters.getAuditLogable().getClass().getName());
        return false;
    }
    return true;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

Example 25 with QuotaCluster

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

the class QuotaManager method rollBackClusterConsumptionParameters.

private void rollBackClusterConsumptionParameters(List<QuotaClusterConsumptionParameter> executed) {
    for (QuotaClusterConsumptionParameter parameter : executed) {
        long requestedMemory = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedMemory() : parameter.getRequestedMemory();
        int requestedCpu = parameter.getQuotaAction() == QuotaConsumptionParameter.QuotaAction.CONSUME ? -parameter.getRequestedCpu() : parameter.getRequestedCpu();
        QuotaCluster quotaCluster = null;
        Quota quota = parameter.getQuota();
        if (quota.getGlobalQuotaCluster() != null) {
            // global cluster quota
            quotaCluster = quota.getGlobalQuotaCluster();
        } else {
            for (QuotaCluster cluster : quota.getQuotaClusters()) {
                if (cluster.getClusterId().equals(parameter.getClusterId())) {
                    quotaCluster = cluster;
                    break;
                }
            }
        }
        if (quotaCluster != null) {
            long newMemory = requestedMemory + quotaCluster.getMemSizeMBUsage();
            int newVcpu = requestedCpu + quotaCluster.getVirtualCpuUsage();
            cacheNewValues(quotaCluster, newMemory, newVcpu);
        }
    }
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster)

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