Search in sources :

Example 11 with Quota

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

the class RegisterVmModel method prepareParameters.

private List<ActionParametersBase> prepareParameters() {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (RegisterVmData registerVmData : getEntities().getItems()) {
        VM vm = registerVmData.getEntity();
        Cluster cluster = registerVmData.getCluster().getSelectedItem();
        ImportVmFromConfParameters params = new ImportVmFromConfParameters(cloneExternalVnicProfiles(cluster), registerVmData.getReassignMacs().getEntity());
        params.setContainerId(vm.getId());
        params.setStorageDomainId(getStorageDomainId());
        params.setImagesExistOnTargetStorageDomain(true);
        params.setClusterId(cluster != null ? cluster.getId() : null);
        params.setAllowPartialImport(registerVmData.getAllowPartialImport().getEntity());
        if (isQuotaEnabled()) {
            Quota quota = registerVmData.getClusterQuota().getSelectedItem();
            params.setQuotaId(quota != null ? quota.getId() : null);
            params.setDiskMap(vm.getDiskMap());
            updateDiskQuotas(new ArrayList<>(params.getDiskMap().values()));
        }
        parameters.add(params);
    }
    return parameters;
}
Also used : Quota(org.ovirt.engine.core.common.businessentities.Quota) RegisterVmData(org.ovirt.engine.ui.uicommonweb.models.vms.register.RegisterVmData) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ImportVmFromConfParameters(org.ovirt.engine.core.common.action.ImportVmFromConfParameters) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 12 with Quota

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

the class AbstractDiskModel method updateQuota.

private void updateQuota(StoragePool datacenter) {
    if (datacenter.getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED) || !getDiskStorageType().getEntity().isInternal()) {
        getQuota().setIsAvailable(false);
        return;
    }
    getQuota().setIsAvailable(true);
    StorageDomain storageDomain = getStorageDomain().getSelectedItem();
    if (storageDomain == null) {
        return;
    }
    final Guid diskQuota = getDisk() != null ? ((DiskImage) getDisk()).getQuotaId() : null;
    final Guid vmQuota = getVm() != null ? getVm().getQuotaId() : null;
    final Guid defaultQuota = diskQuota != null ? diskQuota : vmQuota;
    AsyncDataProvider.getInstance().getAllRelevantQuotasForStorageSorted(new AsyncQuery<>(quotaList -> {
        if (quotaList != null && !quotaList.isEmpty()) {
            getQuota().setItems(quotaList);
            // If list contains default quota, return
            if (quotaList.get(0).getId().equals(defaultQuota)) {
                return;
            }
        }
        if (diskQuota != null) {
            Quota quota = new Quota();
            quota.setId(diskQuota);
            quota.setQuotaName(getDiskImage().getQuotaName());
            if (quotaList == null) {
                quotaList = new ArrayList<>();
            }
            quotaList.add(quota);
            getQuota().setItems(quotaList);
            getQuota().setSelectedItem(quota);
        }
    }), storageDomain.getId(), defaultQuota);
}
Also used : Arrays(java.util.Arrays) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) SpecialAsciiI18NOrNoneValidation(org.ovirt.engine.ui.uicommonweb.validation.SpecialAsciiI18NOrNoneValidation) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Event(org.ovirt.engine.ui.uicompat.Event) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) Version(org.ovirt.engine.core.compat.Version) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) I18NNameValidation(org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation) BusinessEntitiesDefinitions(org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) Collectors(java.util.stream.Collectors) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) StorageModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageModel) NotEmptyQuotaValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyQuotaValidation) NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) Frontend(org.ovirt.engine.ui.frontend.Frontend) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) CinderVolumeType(org.ovirt.engine.core.common.businessentities.storage.CinderVolumeType) SanStorageModelBase(org.ovirt.engine.ui.uicommonweb.models.storage.SanStorageModelBase) Linq(org.ovirt.engine.ui.uicommonweb.Linq) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) Quota(org.ovirt.engine.core.common.businessentities.Quota) VM(org.ovirt.engine.core.common.businessentities.VM) ScsiGenericIO(org.ovirt.engine.core.common.businessentities.storage.ScsiGenericIO) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 13 with Quota

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

the class ImportVmFromExportDomainPopupView method addStorageQuotaColumn.

private void addStorageQuotaColumn() {
    if (!importModel.isQuotaEnabled()) {
        return;
    }
    if (quotaColumn != null) {
        return;
    }
    CustomSelectionCell customSelectionCellQuota = new CustomSelectionCell(new ArrayList<String>());
    customSelectionCellQuota.setStyle(EMPTY_STYLE);
    quotaColumn = new Column<DiskImage, String>(customSelectionCellQuota) {

        @Override
        public String getValue(DiskImage disk) {
            ImportDiskData importData = importModel.getDiskImportData(disk.getId());
            ArrayList<String> storageQuotaList = new ArrayList<>();
            Quota selectedQuota = null;
            if (importData != null && importData.getQuotaList() != null) {
                for (Quota quota : importData.getQuotaList()) {
                    storageQuotaList.add(quota.getQuotaName());
                    if (importData.getSelectedQuota() != null) {
                        if (quota.getId().equals(importData.getSelectedQuota().getId())) {
                            selectedQuota = quota;
                        }
                    }
                }
            }
            ((CustomSelectionCell) getCell()).setOptions(storageQuotaList);
            if (!storageQuotaList.isEmpty()) {
                if (selectedQuota != null) {
                    return selectedQuota.getQuotaName();
                } else {
                    return storageQuotaList.get(0);
                }
            }
            return "";
        }
    };
    quotaColumn.setFieldUpdater((index, disk, value) -> importModel.getDiskImportData(disk.getId()).setSelectedQuotaString(value));
    // $NON-NLS-1$
    diskTable.addColumn(quotaColumn, constants.quota(), "100px");
}
Also used : CustomSelectionCell(org.ovirt.engine.ui.webadmin.widget.table.cell.CustomSelectionCell) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) ImportDiskData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportDiskData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 14 with Quota

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

the class RegisterEntityInfoPanel method getDiskQuotaColumn.

private Column<Disk, String> getDiskQuotaColumn() {
    CustomSelectionCell customSelectionCell = new CustomSelectionCell(new ArrayList<String>());
    // $NON-NLS-1$
    customSelectionCell.setStyle("input-group col-xs-11");
    AbstractColumn<Disk, String> column = new AbstractColumn<Disk, String>(customSelectionCell) {

        @Override
        public String getValue(Disk disk) {
            if (disk.getDiskStorageType() == DiskStorageType.LUN) {
                return null;
            }
            List<Quota> quotas = (List<Quota>) registerEntityModel.getStorageQuota().getItems();
            if (quotas == null || quotas.isEmpty()) {
                return constants.empty();
            }
            Map<Guid, Quota> diskQuotaMap = registerEntityModel.getDiskQuotaMap().getEntity();
            if (diskQuotaMap.get(disk.getId()) == null) {
                diskQuotaMap.put(disk.getId(), quotas.get(0));
                ((CustomSelectionCell) getCell()).setOptions(registerEntityModel.getQuotaNames(quotas));
            }
            return diskQuotaMap.get(disk.getId()).getQuotaName();
        }
    };
    column.setFieldUpdater((index, disk, value) -> {
        Quota quota = registerEntityModel.getQuotaByName(value, (List<Quota>) registerEntityModel.getStorageQuota().getItems());
        registerEntityModel.getDiskQuotaMap().getEntity().put(disk.getId(), quota);
    });
    return column;
}
Also used : CustomSelectionCell(org.ovirt.engine.ui.webadmin.widget.table.cell.CustomSelectionCell) Quota(org.ovirt.engine.core.common.businessentities.Quota) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) AbstractColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractColumn) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 15 with Quota

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

the class RegisterEntityPopupView method getClusterQuotaColumn.

protected Column<D, String> getClusterQuotaColumn() {
    CustomSelectionCell customSelectionCell = new CustomSelectionCell(new ArrayList<String>());
    // $NON-NLS-1$
    customSelectionCell.setStyle("input-group col-xs-11 gwt-ListBox");
    Column<D, String> column = new Column<D, String>(customSelectionCell) {

        @Override
        public String getValue(D object) {
            Guid clusterId = object.getCluster().getSelectedItem() != null ? object.getCluster().getSelectedItem().getId() : null;
            List<Quota> quotas = registerEntityModel.getClusterQuotasMap().getEntity().get(clusterId);
            object.getClusterQuota().setItems(quotas);
            ((CustomSelectionCell) getCell()).setOptions(registerEntityModel.getQuotaNames(quotas));
            return object.getClusterQuota().getSelectedItem() != null ? object.getClusterQuota().getSelectedItem().getQuotaName() : constants.empty();
        }
    };
    column.setFieldUpdater((index, object, value) -> registerEntityModel.selectQuotaByName(value, object.getClusterQuota()));
    return column;
}
Also used : CustomSelectionCell(org.ovirt.engine.ui.webadmin.widget.table.cell.CustomSelectionCell) Quota(org.ovirt.engine.core.common.businessentities.Quota) Column(com.google.gwt.user.cellview.client.Column) Guid(org.ovirt.engine.core.compat.Guid)

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