Search in sources :

Example 11 with VM

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

the class VmListModel method cancelMigration.

private void cancelMigration() {
    ArrayList<ActionParametersBase> list = new ArrayList<>();
    for (Object item : getSelectedItems()) {
        VM a = (VM) item;
        list.add(new VmOperationParameterBase(a.getId()));
    }
    Frontend.getInstance().runMultipleAction(ActionType.CancelMigrateVm, list, result -> {
    }, null);
}
Also used : VmOperationParameterBase(org.ovirt.engine.core.common.action.VmOperationParameterBase) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 12 with VM

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

the class VmListModel method powerAction.

private void powerAction(String actionName, String title, String message, boolean reasonVisible) {
    ConfirmationModel model = new ConfirmationModel();
    setWindow(model);
    model.setTitle(title);
    model.setReasonVisible(reasonVisible);
    if (actionName.equals(SHUTDOWN)) {
        model.setHelpTag(HelpTag.shutdown_virtual_machine);
        // $NON-NLS-1$
        model.setHashName("shutdown_virtual_machine");
    } else if (actionName.equals(STOP)) {
        model.setHelpTag(HelpTag.stop_virtual_machine);
        // $NON-NLS-1$
        model.setHashName("stop_virtual_machine");
    } else if (actionName.equals(REBOOT)) {
        model.setHelpTag(HelpTag.reboot_virtual_machine);
        // $NON-NLS-1$
        model.setHashName("reboot_virtual_machine");
    }
    model.setMessage(message);
    ArrayList<String> items = new ArrayList<>();
    boolean stoppingSingleVM = getSelectedItems().size() == 1 && (actionName.equals(SHUTDOWN) || actionName.equals(STOP));
    for (Object item : getSelectedItems()) {
        VM vm = (VM) item;
        items.add(vm.getName());
        // is populated with the current reason so the user can edit it.
        if (stoppingSingleVM && reasonVisible && VMStatus.PoweringDown.equals(vm.getStatus())) {
            model.getReason().setEntity(vm.getStopReason());
        }
    }
    model.setItems(items);
    // $NON-NLS-1$
    UICommand tempVar = new UICommand("On" + actionName, this);
    tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok());
    tempVar.setIsDefault(true);
    model.getCommands().add(tempVar);
    // $NON-NLS-1$
    UICommand tempVar2 = UICommand.createCancelUiCommand("Cancel", this);
    model.getCommands().add(tempVar2);
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)

Example 13 with VM

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

the class VmListModel method updateVM.

@Override
protected void updateVM(final UnitVmModel model) {
    final VM selectedItem = getSelectedItem();
    // explicitly pass non-editable field from the original VM
    getcurrentVm().setCreatedByUserId(selectedItem.getCreatedByUserId());
    getcurrentVm().setUseLatestVersion(model.getTemplateWithVersion().getSelectedItem().isLatest());
    if (selectedItem.isRunningOrPaused() && !selectedItem.isHostedEngine()) {
        AsyncDataProvider.getInstance().getVmChangedFieldsForNextRun(editedVm, getcurrentVm(), getUpdateVmParameters(false), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

            @Override
            public void onSuccess(QueryReturnValue returnValue) {
                List<String> changedFields = returnValue.getReturnValue();
                final boolean cpuHotPluggable = VmCommonUtils.isCpusToBeHotpluggedOrUnplugged(selectedItem, getcurrentVm());
                final boolean isHeadlessModeChanged = isHeadlessModeChanged(editedVm, getUpdateVmParameters(false));
                final boolean memoryHotPluggable = VmCommonUtils.isMemoryToBeHotplugged(selectedItem, getcurrentVm());
                final boolean minAllocatedMemoryChanged = selectedItem.getMinAllocatedMem() != getcurrentVm().getMinAllocatedMem();
                final boolean vmLeaseUpdated = VmCommonUtils.isVmLeaseToBeHotPluggedOrUnplugged(selectedItem, getcurrentVm());
                if (isHeadlessModeChanged) {
                    changedFields.add(constants.headlessMode());
                }
                // provide warnings if isVmUnpinned()
                if (!changedFields.isEmpty() || isVmUnpinned() || memoryHotPluggable || cpuHotPluggable || vmLeaseUpdated) {
                    VmNextRunConfigurationModel confirmModel = new VmNextRunConfigurationModel();
                    if (isVmUnpinned()) {
                        confirmModel.setVmUnpinned();
                    }
                    confirmModel.setTitle(ConstantsManager.getInstance().getConstants().editNextRunConfigurationTitle());
                    confirmModel.setHelpTag(HelpTag.edit_next_run_configuration);
                    // $NON-NLS-1$
                    confirmModel.setHashName("edit_next_run_configuration");
                    confirmModel.setChangedFields(changedFields);
                    confirmModel.setCpuPluggable(cpuHotPluggable);
                    confirmModel.setMemoryPluggable(memoryHotPluggable);
                    // it can be plugged only together with the memory, never alone
                    confirmModel.setMinAllocatedMemoryPluggable(memoryHotPluggable && minAllocatedMemoryChanged);
                    confirmModel.setVmLeaseUpdated(vmLeaseUpdated);
                    confirmModel.getCommands().add(// $NON-NLS-1$
                    new UICommand("updateExistingVm", VmListModel.this).setTitle(ConstantsManager.getInstance().getConstants().ok()).setIsDefault(true));
                    // $NON-NLS-1$
                    confirmModel.getCommands().add(UICommand.createCancelUiCommand("CancelConfirmation", VmListModel.this));
                    setConfirmWindow(confirmModel);
                } else {
                    updateExistingVm(false);
                }
            }

            private boolean isVmUnpinned() {
                if (selectedItem.isRunning()) {
                    if (selectedItem.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST && getcurrentVm().getMigrationSupport() != MigrationSupport.PINNED_TO_HOST) {
                        return true;
                    }
                }
                return false;
            }
        }));
    } else {
        updateExistingVm(false);
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 14 with VM

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

the class VmListModel method cancelConversion.

private void cancelConversion() {
    List<ActionParametersBase> parameters = new ArrayList<>();
    for (VM vm : getSelectedItems()) {
        parameters.add(new VmOperationParameterBase(vm.getId()));
    }
    Frontend.getInstance().runMultipleAction(ActionType.CancelConvertVm, parameters);
}
Also used : VmOperationParameterBase(org.ovirt.engine.core.common.action.VmOperationParameterBase) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 15 with VM

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

the class VmListModel method initImportModelForVmsToImportNamesOnly.

private void initImportModelForVmsToImportNamesOnly(final ImportVmsModel importVmsModel, final ImportVmModel importVmModel) {
    final UIMessages messages = ConstantsManager.getInstance().getMessages();
    final UIConstants constants = ConstantsManager.getInstance().getConstants();
    final List<String> vmsToImport = new ArrayList<>();
    OriginType originType = convertImportSourceToOriginType(importVmsModel.getImportSources().getSelectedItem());
    final List<VM> externalVms = importVmsModel.getVmsToImport();
    for (VM vm : externalVms) {
        vmsToImport.add(vm.getName());
    }
    importVmsModel.clearProblem();
    importVmsModel.startProgress();
    importVmModel.setMessage("");
    AsyncQuery query = new AsyncQuery(returnValue -> {
        if (returnValue instanceof QueryReturnValue) {
            importVmsModel.setError(messages.providerFailure());
            importVmsModel.stopProgress();
        } else {
            List<VM> remoteVms = (List<VM>) returnValue;
            List<VM> remoteDownVms = new ArrayList<>();
            List<VM> nonRetrievedVms = new ArrayList<>();
            // find vms with status=down
            for (VM vm : remoteVms) {
                if (vm.isDown()) {
                    remoteDownVms.add(vm);
                }
            }
            // i.e. they were retrieved with their names only but not with their full info
            if (remoteVms.size() != externalVms.size()) {
                for (VM vm : externalVms) {
                    if (!remoteVms.contains(vm)) {
                        nonRetrievedVms.add(vm);
                    }
                }
            }
            importVmsModel.stopProgress();
            // prepare error message to be displayed in one of the models
            String messageForImportVm = null;
            String messageForImportVms = null;
            if (remoteVms.size() != remoteDownVms.size()) {
                if (!nonRetrievedVms.isEmpty()) {
                    messageForImportVm = constants.nonRetrievedAndRunningVmsWereFilteredOnImportVm();
                    messageForImportVms = constants.nonRetrievedAndRunningVmsWereAllFilteredOnImportVm();
                } else {
                    messageForImportVm = constants.runningVmsWereFilteredOnImportVm();
                    messageForImportVms = constants.runningVmsWereAllFilteredOnImportVm();
                }
            } else if (!nonRetrievedVms.isEmpty()) {
                messageForImportVm = constants.nonRetrievedVmsWereFilteredOnImportVm();
                messageForImportVms = constants.nonRetrievedVmsWereAllFilteredOnImportVm();
            }
            if (remoteDownVms.isEmpty() && messageForImportVms != null) {
                importVmsModel.setError(messageForImportVms);
            }
            if (!importVmsModel.validateArchitectures(remoteDownVms)) {
                return;
            }
            // init and display next dialog - the importVmsModel model
            importVmModel.init(remoteDownVms, importVmsModel.getDataCenters().getSelectedItem().getId());
            setWindow(null);
            setWindow(importVmModel);
            if (messageForImportVm != null) {
                importVmModel.setMessage(messageForImportVm);
            }
        }
    });
    if (!(importVmModel instanceof ImportVmFromExternalSourceModel)) {
        importVmsModel.setError(messages.providerImportFailure());
        importVmsModel.stopProgress();
        return;
    }
    ImportVmFromExternalSourceModel importVmsFromExternalSource = (ImportVmFromExternalSourceModel) importVmModel;
    query.setHandleFailure(true);
    AsyncDataProvider.getInstance().getVmsFromExternalServer(query, importVmsModel.getDataCenters().getSelectedItem().getId(), importVmsFromExternalSource.getProxyHostId(), importVmsFromExternalSource.getUrl(), importVmsFromExternalSource.getUsername(), importVmsFromExternalSource.getPassword(), originType, vmsToImport);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) OriginType(org.ovirt.engine.core.common.businessentities.OriginType) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Aggregations

VM (org.ovirt.engine.core.common.businessentities.VM)591 Test (org.junit.Test)178 Guid (org.ovirt.engine.core.compat.Guid)150 ArrayList (java.util.ArrayList)130 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)82 HashMap (java.util.HashMap)69 List (java.util.List)65 VDS (org.ovirt.engine.core.common.businessentities.VDS)63 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)56 Map (java.util.Map)53 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)53 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)41 QueryType (org.ovirt.engine.core.common.queries.QueryType)36 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)34 Frontend (org.ovirt.engine.ui.frontend.Frontend)34 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)33 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)32 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)32 Collectors (java.util.stream.Collectors)31 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)31