Search in sources :

Example 1 with ImportTemplateData

use of org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData in project ovirt-engine by oVirt.

the class TemplateBackupModel method onRestore.

public void onRestore() {
    importModel = (ImportTemplateModel) getWindow();
    if (importModel.getProgress() != null) {
        return;
    }
    if (!importModel.validate()) {
        return;
    }
    cloneObjectMap = new HashMap<>();
    objectsToClone = new ArrayList<>();
    for (Object object : importModel.getItems()) {
        ImportTemplateData item = (ImportTemplateData) object;
        if (item.getClone().getEntity()) {
            objectsToClone.add(item);
        }
    }
    executeImportClone();
}
Also used : ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData)

Example 2 with ImportTemplateData

use of org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData in project ovirt-engine by oVirt.

the class ImportTemplateModel method init.

public void init(final Collection<VmTemplate> externalTemplates, final Guid storageDomainId) {
    Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(createSearchPattern(externalTemplates), SearchType.VmTemplate), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

        @Override
        public void onSuccess(QueryReturnValue returnValue) {
            UIConstants constants = ConstantsManager.getInstance().getConstants();
            List<VmTemplate> vmtList = returnValue.getReturnValue();
            List<ImportTemplateData> templateDataList = new ArrayList<>();
            for (VmTemplate template : externalTemplates) {
                ImportTemplateData templateData = new ImportTemplateData(template);
                boolean templateExistsInSystem = vmtList.contains(template);
                templateData.setExistsInSystem(templateExistsInSystem);
                if (templateExistsInSystem) {
                    templateData.enforceClone(constants.importTemplateThatExistsInSystemMustClone());
                } else if (!template.isBaseTemplate() && findAnyVmTemplateById(vmtList, template.getBaseTemplateId()) == null) {
                    templateData.enforceClone(constants.importTemplateWithoutBaseMustClone());
                }
                templateDataList.add(templateData);
            }
            setItems(templateDataList);
            withDataCenterLoaded(storageDomainId, r -> doInit());
        }

        private VmTemplate findAnyVmTemplateById(List<VmTemplate> vmtList, Guid templateId) {
            for (VmTemplate vmt : vmtList) {
                if (templateId.equals(vmt.getId())) {
                    return vmt;
                }
            }
            return null;
        }
    }));
}
Also used : AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Example 3 with ImportTemplateData

use of org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData in project ovirt-engine by oVirt.

the class ImportTemplatePopupView method initMainTable.

@Override
protected void initMainTable() {
    this.table = new ListModelObjectCellTable<>();
    AbstractCheckboxColumn<Object> cloneTemplateColumn = new AbstractCheckboxColumn<Object>((index, model, value) -> {
        ((ImportTemplateData) model).getClone().setEntity(value);
        table.asEditor().edit(importModel);
    }) {

        @Override
        public Boolean getValue(Object model) {
            return ((ImportTemplateData) model).getClone().getEntity();
        }

        @Override
        protected boolean canEdit(Object model) {
            return ((ImportTemplateData) model).getClone().getIsChangable();
        }
    };
    // $NON-NLS-1$
    table.addColumn(cloneTemplateColumn, constants.cloneVM(), "50px");
    AbstractTextColumn<Object> nameColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return ((ImportTemplateData) object).getTemplate().getName();
        }
    };
    // $NON-NLS-1$
    table.addColumn(nameColumn, constants.nameTemplate(), "150px");
    AbstractTextColumn<Object> versionNameColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            VmTemplate template = ((ImportTemplateData) object).getTemplate();
            if (template.isBaseTemplate()) {
                // $NON-NLS-1$
                return "";
            }
            return // $NON-NLS-1$
            StringFormat.format(// $NON-NLS-1$
            "%s (%s)", // $NON-NLS-1$
            template.getTemplateVersionName() != null ? template.getTemplateVersionName() : "", template.getTemplateVersionNumber());
        }
    };
    // $NON-NLS-1$
    table.addColumn(versionNameColumn, constants.versionTemplate(), "150px");
    AbstractTextColumn<Object> originColumn = new AbstractEnumColumn<Object, OriginType>() {

        @Override
        protected OriginType getRawValue(Object object) {
            return ((ImportTemplateData) object).getTemplate().getOrigin();
        }
    };
    // $NON-NLS-1$
    table.addColumn(originColumn, constants.originTemplate(), "100px");
    AbstractTextColumn<Object> memoryColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return messages.megabytes(String.valueOf(((ImportTemplateData) object).getTemplate().getMemSizeMb()));
        }
    };
    // $NON-NLS-1$
    table.addColumn(memoryColumn, constants.memoryTemplate(), "100px");
    AbstractTextColumn<Object> cpuColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportTemplateData) object).getTemplate().getNumOfCpus());
        }
    };
    // $NON-NLS-1$
    table.addColumn(cpuColumn, constants.cpusTemplate(), "50px");
    AbstractTextColumn<Object> archColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportTemplateData) object).getTemplate().getClusterArch());
        }
    };
    // $NON-NLS-1$
    table.addColumn(archColumn, constants.architectureTemplate(), "50px");
    AbstractTextColumn<Object> diskColumn = new AbstractTextColumn<Object>() {

        @Override
        public String getValue(Object object) {
            return String.valueOf(((ImportTemplateData) object).getTemplate().getDiskList().size());
        }
    };
    // $NON-NLS-1$
    table.addColumn(diskColumn, constants.disksTemplate(), "50px");
    isObjectInSystemColumn = new AbstractImageResourceColumn<Object>() {

        @Override
        public ImageResource getValue(Object object) {
            return ((ImportTemplateData) object).isExistsInSystem() ? resources.logNormalImage() : null;
        }
    };
    // $NON-NLS-1$
    table.addColumn(isObjectInSystemColumn, constants.templateInSetup(), "60px");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    splitLayoutPanel.add(sp);
    table.getElement().getStyle().setPosition(Position.RELATIVE);
}
Also used : AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn) AbstractEnumColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractEnumColumn) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) ImageResource(com.google.gwt.resources.client.ImageResource) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 4 with ImportTemplateData

use of org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData in project ovirt-engine by oVirt.

the class RegisterTemplateModel method prepareActionParameters.

private List<ActionParametersBase> prepareActionParameters() {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (ImportTemplateData entityData : getEntities().getItems()) {
        VmTemplate vmTemplate = entityData.getEntity();
        Cluster cluster = entityData.getCluster().getSelectedItem();
        ImportVmTemplateFromConfParameters params = new ImportVmTemplateFromConfParameters();
        params.setExternalVnicProfileMappings(cloneExternalVnicProfiles(cluster));
        params.setContainerId(vmTemplate.getId());
        params.setStorageDomainId(getStorageDomainId());
        params.setImagesExistOnTargetStorageDomain(true);
        params.setClusterId(cluster != null ? cluster.getId() : null);
        if (isQuotaEnabled()) {
            Quota quota = entityData.getClusterQuota().getSelectedItem();
            params.setQuotaId(quota != null ? quota.getId() : null);
            params.setDiskTemplateMap(vmTemplate.getDiskTemplateMap());
            updateDiskQuotas(new ArrayList<Disk>(params.getDiskTemplateMap().values()));
        }
        parameters.add(params);
    }
    return parameters;
}
Also used : ImportVmTemplateFromConfParameters(org.ovirt.engine.core.common.action.ImportVmTemplateFromConfParameters) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 5 with ImportTemplateData

use of org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData in project ovirt-engine by oVirt.

the class TemplateBackupModel method onClone.

private void onClone() {
    ImportCloneModel cloneModel = (ImportCloneModel) getConfirmWindow();
    if (cloneModel.getApplyToAll().getEntity()) {
        if (!cloneModel.getNoClone().getEntity()) {
            String suffix = cloneModel.getSuffix().getEntity();
            if (!validateSuffix(suffix, cloneModel.getSuffix())) {
                return;
            }
            for (ImportTemplateData object : objectsToClone) {
                setObjectName(object, suffix, true);
                cloneObjectMap.put((Guid) object.getEntity().getQueryableId(), object);
            }
        }
        objectsToClone.clear();
    } else {
        ImportTemplateData object = (ImportTemplateData) cloneModel.getEntity();
        if (!cloneModel.getNoClone().getEntity()) {
            String vmName = cloneModel.getName().getEntity();
            if (!validateName(vmName, cloneModel.getName(), getClonedNameValidators())) {
                return;
            }
            setObjectName(object, vmName, false);
            cloneObjectMap.put((Guid) object.getEntity().getQueryableId(), object);
        }
        objectsToClone.remove(object);
    }
    setConfirmWindow(null);
    executeImportClone();
}
Also used : ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData)

Aggregations

ImportTemplateData (org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData)8 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)6 ArrayList (java.util.ArrayList)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 Guid (org.ovirt.engine.core.compat.Guid)2 ImageResource (com.google.gwt.resources.client.ImageResource)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ImportVmTemplateFromConfParameters (org.ovirt.engine.core.common.action.ImportVmTemplateFromConfParameters)1 ImportVmTemplateParameters (org.ovirt.engine.core.common.action.ImportVmTemplateParameters)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 Quota (org.ovirt.engine.core.common.businessentities.Quota)1 CpuProfile (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)1 AbstractCheckboxColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)1