Search in sources :

Example 66 with Quota

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

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

the class QuotaListModel method onRemove.

public void onRemove() {
    ConfirmationModel model = (ConfirmationModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    ArrayList<ActionParametersBase> prms = new ArrayList<>();
    for (Quota a : getSelectedItems()) {
        IdParameters idParameters = new IdParameters(a.getId());
        prms.add(idParameters);
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.RemoveQuota, prms, result -> {
        ConfirmationModel localModel = (ConfirmationModel) result.getState();
        localModel.stopProgress();
        cancel();
    }, model);
}
Also used : IdParameters(org.ovirt.engine.core.common.action.IdParameters) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 68 with Quota

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

the class ImportExportRepoImageBaseModel method updateQuotas.

private void updateQuotas() {
    StorageDomain storageDomain = getStorageDomain().getSelectedItem();
    if (getDataCenterQuotaEnforcementType() == QuotaEnforcementTypeEnum.DISABLED || storageDomain == null) {
        getQuota().setItems(null);
        getQuota().setIsEmpty(true);
        updateControlsAvailability();
        return;
    }
    startProgress();
    AsyncDataProvider.getInstance().getAllRelevantQuotasForStorageSorted(new AsyncQuery<>(quotas -> {
        quotas = (quotas != null) ? quotas : new ArrayList<Quota>();
        getQuota().setItems(quotas);
        getQuota().setIsEmpty(quotas.isEmpty());
        updateControlsAvailability();
        stopProgress();
    }), storageDomain.getId(), null);
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Guid(org.ovirt.engine.core.compat.Guid) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Event(org.ovirt.engine.ui.uicompat.Event) Quota(org.ovirt.engine.core.common.businessentities.Quota) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) EventDefinition(org.ovirt.engine.ui.uicompat.EventDefinition) ICommandTarget(org.ovirt.engine.ui.uicommonweb.ICommandTarget) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) Collections(java.util.Collections) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Quota(org.ovirt.engine.core.common.businessentities.Quota)

Example 69 with Quota

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

the class ImportRepoImageModel method executeCommand.

@Override
public void executeCommand(UICommand command) {
    if (!validate()) {
        return;
    }
    super.executeCommand(command);
    startProgress();
    ArrayList<ActionParametersBase> actionParameters = new ArrayList<>();
    final StringBuilder imageNames = new StringBuilder();
    for (EntityModel entity : getEntities()) {
        RepoImage repoImage = (RepoImage) entity.getEntity();
        // $NON-NLS-1$
        imageNames.append("\n -");
        imageNames.append(repoImage.getRepoImageName());
        ImportRepoImageParameters importParameters = new ImportRepoImageParameters();
        // source
        importParameters.setSourceRepoImageId(repoImage.getRepoImageId());
        importParameters.setSourceStorageDomainId(sourceStorageDomain.getId());
        // destination
        importParameters.setDiskAlias(((RepoImageModel) entity).getDiskImageAlias());
        importParameters.setStoragePoolId(getDataCenter().getSelectedItem().getId());
        importParameters.setStorageDomainId(getStorageDomain().getSelectedItem().getId());
        importParameters.setClusterId(getStorageDomain().getSelectedItem().getId());
        Quota selectedQuota = getQuota().getSelectedItem();
        if (selectedQuota != null) {
            importParameters.setQuotaId(selectedQuota.getId());
        }
        Boolean importAsTemplate = getImportAsTemplate().getEntity();
        importParameters.setImportAsTemplate(importAsTemplate);
        if (importAsTemplate) {
            importParameters.setClusterId(getCluster().getSelectedItem().getId());
            String templateName = getTemplateName().getEntity();
            if (StringHelper.isNotNullOrEmpty(templateName)) {
                importParameters.setTemplateName(templateName);
            }
        }
        actionParameters.add(importParameters);
    }
    Frontend.getInstance().runMultipleAction(ActionType.ImportRepoImage, actionParameters, result -> {
        ImportExportRepoImageBaseModel model = (ImportExportRepoImageBaseModel) result.getState();
        model.stopProgress();
        model.cancel();
        ConfirmationModel confirmModel = new ConfirmationModel();
        storageIsoListModel.setConfirmWindow(confirmModel);
        confirmModel.setTitle(ConstantsManager.getInstance().getConstants().importImagesTitle());
        confirmModel.setHelpTag(HelpTag.import_images);
        // $NON-NLS-1$
        confirmModel.setHashName("import_images");
        confirmModel.setMessage(ConstantsManager.getInstance().getMessages().importProcessHasBegunForImages(imageNames.toString()));
        confirmModel.getCommands().add(// $NON-NLS-1$
        new UICommand("CancelConfirm", storageIsoListModel).setTitle(ConstantsManager.getInstance().getConstants().close()).setIsDefault(true).setIsCancel(true));
    }, this);
}
Also used : ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ImportRepoImageParameters(org.ovirt.engine.core.common.action.ImportRepoImageParameters) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Quota(org.ovirt.engine.core.common.businessentities.Quota) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 70 with Quota

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

the class QuotaManager method updateQuotaCacheImpl.

private synchronized void updateQuotaCacheImpl() {
    if (!isCacheUpdateNeeded()) {
        return;
    }
    log.debug("Updating Quota Cache...");
    long timeStart = System.currentTimeMillis();
    List<Quota> allQuotaIncludingConsumption = getQuotaDao().getAllQuotaIncludingConsumption();
    if (allQuotaIncludingConsumption.isEmpty()) {
        return;
    }
    HashMap<Guid, Map<Guid, Quota>> newStoragePoolQuotaMap = new HashMap<>();
    HashMap<Guid, Guid> newDefaultQuotaIdMap = new HashMap<>();
    for (Quota quota : allQuotaIncludingConsumption) {
        if (!newStoragePoolQuotaMap.containsKey(quota.getStoragePoolId())) {
            newStoragePoolQuotaMap.put(quota.getStoragePoolId(), new HashMap<>());
        }
        newStoragePoolQuotaMap.get(quota.getStoragePoolId()).put(quota.getId(), quota);
        if (quota.isDefault()) {
            newDefaultQuotaIdMap.put(quota.getStoragePoolId(), quota.getId());
        }
    }
    lock.writeLock().lock();
    try {
        storagePoolQuotaMap = newStoragePoolQuotaMap;
        storagePoolDefaultQuotaIdMap = newDefaultQuotaIdMap;
    } finally {
        lock.writeLock().unlock();
    }
    long timeEnd = System.currentTimeMillis();
    log.info("Quota Cache updated. ({} msec)", timeEnd - timeStart);
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Quota (org.ovirt.engine.core.common.businessentities.Quota)101 ArrayList (java.util.ArrayList)23 Guid (org.ovirt.engine.core.compat.Guid)22 Test (org.junit.Test)17 QuotaCluster (org.ovirt.engine.core.common.businessentities.QuotaCluster)17 QuotaStorage (org.ovirt.engine.core.common.businessentities.QuotaStorage)16 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)12 HashMap (java.util.HashMap)9 List (java.util.List)9 QueryType (org.ovirt.engine.core.common.queries.QueryType)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)8 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)6 QuotaCRUDParameters (org.ovirt.engine.core.common.action.QuotaCRUDParameters)6 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)6 Map (java.util.Map)5 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)5 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)5 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)5