Search in sources :

Example 16 with CpuProfile

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

the class TemplateBackupModel method executeImport.

protected void executeImport() {
    ImportTemplateModel model = (ImportTemplateModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (!model.validate()) {
        return;
    }
    List<ActionParametersBase> prms = new ArrayList<>();
    for (Object object : importModel.getItems()) {
        ImportTemplateData importData = (ImportTemplateData) object;
        VmTemplate template = importData.getTemplate();
        ImportVmTemplateParameters importVmTemplateParameters = new ImportVmTemplateParameters(model.getStoragePool().getId(), getEntity().getId(), Guid.Empty, model.getCluster().getSelectedItem().getId(), template);
        if (importModel.getClusterQuota().getSelectedItem() != null && importModel.getClusterQuota().getIsAvailable()) {
            importVmTemplateParameters.setQuotaId(importModel.getClusterQuota().getSelectedItem().getId());
        }
        CpuProfile cpuProfile = importModel.getCpuProfiles().getSelectedItem();
        if (cpuProfile != null) {
            importVmTemplateParameters.setCpuProfileId(cpuProfile.getId());
        }
        Map<Guid, Guid> map = new HashMap<>();
        for (DiskImage disk : template.getDiskList()) {
            map.put(disk.getId(), importModel.getDiskImportData(disk.getId()).getSelectedStorageDomain().getId());
            if (importModel.getDiskImportData(disk.getId()).getSelectedQuota() != null) {
                disk.setQuotaId(importModel.getDiskImportData(disk.getId()).getSelectedQuota().getId());
            }
        }
        importVmTemplateParameters.setImageToDestinationDomainMap(map);
        if (importData.isExistsInSystem() || importData.getClone().getEntity()) {
            if (!cloneObjectMap.containsKey(template.getId())) {
                continue;
            }
            importVmTemplateParameters.setImportAsNewEntity(true);
            importVmTemplateParameters.getVmTemplate().setName(((ImportTemplateData) cloneObjectMap.get(template.getId())).getTemplate().getName());
        }
        prms.add(importVmTemplateParameters);
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.ImportVmTemplate, prms, result -> {
        TemplateBackupModel templateBackupModel = (TemplateBackupModel) result.getState();
        templateBackupModel.getWindow().stopProgress();
        templateBackupModel.cancel();
        List<ActionReturnValue> retVals = result.getReturnValue();
        if (retVals != null && templateBackupModel.getSelectedItems().size() == retVals.size()) {
            StringBuilder importedTemplates = new StringBuilder();
            int counter = 0;
            boolean toShowConfirmWindow = false;
            for (VmTemplate template : templateBackupModel.getSelectedItems()) {
                if (retVals.get(counter) != null && retVals.get(counter).isValid()) {
                    // $NON-NLS-1$
                    importedTemplates.append(template.getName()).append(", ");
                    toShowConfirmWindow = true;
                }
                counter++;
            }
            if (toShowConfirmWindow) {
                ConfirmationModel confirmModel = new ConfirmationModel();
                templateBackupModel.setConfirmWindow(confirmModel);
                confirmModel.setTitle(constants.importTemplatesTitle());
                confirmModel.setHelpTag(HelpTag.import_template);
                // $NON-NLS-1$
                confirmModel.setHashName("import_template");
                confirmModel.setMessage(messages.importProcessHasBegunForTemplates(StringHelper.trimEnd(importedTemplates.toString().trim(), ',')));
                confirmModel.getCommands().add(// $NON-NLS-1$
                new UICommand(CANCEL_CONFIRMATION_COMMAND, templateBackupModel).setTitle(constants.close()).setIsDefault(true).setIsCancel(true));
            }
        }
    }, this);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImportTemplateModel(org.ovirt.engine.ui.uicommonweb.models.templates.ImportTemplateModel) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 17 with CpuProfile

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

the class ImportVmFromExternalProviderPopupView method initListBoxEditors.

private void initListBoxEditors() {
    destClusterEditor = new ListModelListBoxEditor<>(new NullSafeRenderer<Cluster>() {

        @Override
        public String renderNullSafe(Cluster object) {
            return object.getName();
        }
    });
    destClusterQuotaEditor = new ListModelListBoxEditor<>(new NullSafeRenderer<Quota>() {

        @Override
        public String renderNullSafe(Quota object) {
            return object.getQuotaName();
        }
    });
    destStorageEditor = new ListModelListBoxEditor<>(new StorageDomainFreeSpaceRenderer());
    cpuProfileEditor = new ListModelListBoxEditor<>(new NullSafeRenderer<CpuProfile>() {

        @Override
        protected String renderNullSafe(CpuProfile object) {
            return object.getName();
        }
    });
    disksAllocationEditor = new ListModelListBoxEditor<>(new NullSafeRenderer<VolumeType>() {

        @Override
        protected String renderNullSafe(VolumeType object) {
            return new EnumRenderer<VolumeType>().render(object);
        }
    });
    attachDriversEditor = new EntityModelCheckBoxEditor(Align.LEFT);
    cdImageEditor = new ListModelListBoxOnlyEditor<>(new NullSafeRenderer<RepoImage>() {

        @Override
        protected String renderNullSafe(RepoImage object) {
            return object.getRepoImageId();
        }
    });
}
Also used : VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) Quota(org.ovirt.engine.core.common.businessentities.Quota) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) NullSafeRenderer(org.ovirt.engine.ui.common.widget.renderer.NullSafeRenderer) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) EntityModelCheckBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor) StorageDomainFreeSpaceRenderer(org.ovirt.engine.ui.common.widget.renderer.StorageDomainFreeSpaceRenderer)

Example 18 with CpuProfile

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

the class CpuProfileHelper method createCpuProfile.

public static CpuProfile createCpuProfile(Guid clusterId, String name) {
    CpuProfile cpuProfile = new CpuProfile();
    cpuProfile.setId(Guid.newGuid());
    cpuProfile.setName(name);
    cpuProfile.setClusterId(clusterId);
    return cpuProfile;
}
Also used : CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)

Example 19 with CpuProfile

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

the class AddCpuProfileCommandTest method createParameters.

private static CpuProfileParameters createParameters() {
    CpuProfile cpuProfile = CpuProfileHelper.createCpuProfile(CLUSTER_ID, PROFILE_NAME);
    CpuProfileParameters parameters = new CpuProfileParameters(cpuProfile);
    parameters.setCorrelationId(CORRELATION_ID);
    parameters.setAddPermissions(true);
    parameters.setSessionId(SESSION_ID);
    return parameters;
}
Also used : CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) CpuProfileParameters(org.ovirt.engine.core.common.action.CpuProfileParameters)

Example 20 with CpuProfile

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

the class CpuProfileHelperTest method createCpuProfileTest.

@Test
public void createCpuProfileTest() {
    CpuProfile cpuProfile = CpuProfileHelper.createCpuProfile(CLUSTER_ID, CLUSTER_NAME);
    assertEquals(CLUSTER_NAME, cpuProfile.getName());
    assertEquals(CLUSTER_ID, cpuProfile.getClusterId());
    assertNotNull(cpuProfile.getId());
    assertEquals(ProfileType.CPU, cpuProfile.getProfileType());
}
Also used : CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Test(org.junit.Test)

Aggregations

CpuProfile (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)20 Guid (org.ovirt.engine.core.compat.Guid)5 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Test (org.junit.Test)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)3 HashMap (java.util.HashMap)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 CpuProfileParameters (org.ovirt.engine.core.common.action.CpuProfileParameters)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 Quota (org.ovirt.engine.core.common.businessentities.Quota)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 CpuQos (org.ovirt.engine.core.common.businessentities.qos.CpuQos)2 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 ImportVmFromExternalProviderParameters (org.ovirt.engine.core.common.action.ImportVmFromExternalProviderParameters)1 ImportVmFromOvaParameters (org.ovirt.engine.core.common.action.ImportVmFromOvaParameters)1