Search in sources :

Example 31 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue 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)

Example 32 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class VmModelBehaviorBase method updateGraphics.

protected void updateGraphics(Guid id) {
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(id), new AsyncQuery<QueryReturnValue>(returnValue -> {
        List<VmDevice> graphicsVmDevs = returnValue.getReturnValue();
        List<GraphicsType> graphicsTypes = new ArrayList<>();
        for (VmDevice graphicsVmDev : graphicsVmDevs) {
            graphicsTypes.add(GraphicsType.fromString(graphicsVmDev.getDevice()));
        }
        boolean hasSpiceAndVnc = graphicsTypes.size() == 2 && graphicsTypes.containsAll(Arrays.asList(GraphicsType.SPICE, GraphicsType.VNC));
        boolean canBeSelected = getModel().getGraphicsType().getItems().contains(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
        if (hasSpiceAndVnc && canBeSelected) {
            getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
        } else if (graphicsVmDevs.size() == 1) {
            GraphicsType type = GraphicsType.fromString(graphicsVmDevs.get(0).getDevice());
            getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsType(type));
        }
    }));
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) Arrays(java.util.Arrays) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) Event(org.ovirt.engine.ui.uicompat.Event) ImagesDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.ImagesDataProvider) VmNumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.VmNumaSupportModel) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) 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) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) I18NNameValidation(org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation) StringHelper(org.ovirt.engine.core.compat.StringHelper) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Guid(org.ovirt.engine.core.compat.Guid) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) HashMap(java.util.HashMap) 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) ExistingBlankTemplateModelBehavior(org.ovirt.engine.ui.uicommonweb.models.templates.ExistingBlankTemplateModelBehavior) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) HashSet(java.util.HashSet) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Frontend(org.ovirt.engine.ui.frontend.Frontend) NumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.NumaSupportModel) InstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.InstanceTypeManager) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) Linq(org.ovirt.engine.ui.uicommonweb.Linq) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmCommonUtils(org.ovirt.engine.core.common.utils.VmCommonUtils) VM(org.ovirt.engine.core.common.businessentities.VM) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) List(java.util.List) ArrayList(java.util.ArrayList)

Example 33 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class ExistingNonClusterModelBehavior method doBuild.

public void doBuild() {
    buildModel(entity, (source, destination) -> {
        Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(entity.getId()), new AsyncQuery<>((QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
        getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), entity.getId());
        getInstance().getWatchdogByVmId(new AsyncQuery<QueryReturnValue>(returnValue -> {
            @SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
            for (VmWatchdog watchdog : watchdogs) {
                getModel().getWatchdogAction().setSelectedItem(watchdog.getAction());
                getModel().getWatchdogModel().setSelectedItem(watchdog.getModel());
            }
        }), entity.getId());
        Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
            List<VmDevice> rngDevices = returnValue.getReturnValue();
            getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
            if (!rngDevices.isEmpty()) {
                VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
                getModel().setRngDevice(rngDevice);
            }
        }));
        getModel().getEmulatedMachine().setSelectedItem(entity.getCustomEmulatedMachine());
        getModel().getCustomCpu().setSelectedItem(entity.getCustomCpuName());
        getModel().getMigrationMode().setSelectedItem(entity.getMigrationSupport());
        postBuild();
    });
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) QueryType(org.ovirt.engine.core.common.queries.QueryType) AsyncDataProvider.getInstance(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider.getInstance) Arrays(java.util.Arrays) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) NameAndDescriptionVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.NameAndDescriptionVmBaseToUnitBuilder) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Set(java.util.Set) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) HashSet(java.util.HashSet) HwOnlyVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.HwOnlyVmBaseToUnitBuilder) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Collection(java.util.Collection) List(java.util.List) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 34 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class VmInstanceTypeManager method updateNetworkInterfacesByTemplate.

public void updateNetworkInterfacesByTemplate(VmBase vmBase) {
    QueryType queryType = (vmBase instanceof VmTemplate) ? QueryType.GetTemplateInterfacesByTemplateId : QueryType.GetVmInterfacesByVmId;
    AsyncQuery<QueryReturnValue> query = new AsyncQuery<>(returnValue -> {
        if (returnValue == null) {
            return;
        }
        List<VmNetworkInterface> nics = returnValue.getReturnValue();
        updateNetworkInterfaces(getNetworkProfileBehavior(), nics);
    });
    Frontend.getInstance().runQuery(queryType, new IdQueryParameters(vmBase.getId()), query);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Example 35 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class VncConsoleModel method invokeConsole.

private void invokeConsole() {
    final GraphicsInfo vncInfo = getEntity().getGraphicsInfos().get(GraphicsType.VNC);
    if (vncInfo == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("Trying to invoke VNC console but VM GraphicsInfo is null.");
    }
    vncImpl.getOptions().setVmId(getEntity().getId());
    ConfigureConsoleOptionsParams parameters = new ConfigureConsoleOptionsParams(vncImpl.getOptions(), true);
    parameters.setEngineBaseUrl(FrontendUrlUtils.getRootURL());
    parameters.setConsoleClientResourcesUrl(dynamicMessages.consoleClientResourcesUrl());
    Frontend.getInstance().runQuery(QueryType.ConfigureConsoleOptions, parameters, new ShowErrorAsyncQuery(returnValue -> {
        ConsoleOptions configuredOptions = ((QueryReturnValue) returnValue).getReturnValue();
        // overriding global server settings by frontend settings
        configuredOptions.setRemapCtrlAltDelete(vncImpl.getOptions().isRemapCtrlAltDelete());
        vncImpl.setOptions(configuredOptions);
        vncImpl.getOptions().setTitle(getClientTitle());
        vncImpl.getOptions().setVmName(getEntity().getName());
        vncImpl.invokeClient();
    }));
}
Also used : DynamicMessages(org.ovirt.engine.ui.uicommonweb.DynamicMessages) QueryType(org.ovirt.engine.core.common.queries.QueryType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ConsoleUtils(org.ovirt.engine.ui.uicommonweb.ConsoleUtils) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) ConfigureConsoleOptionsParams(org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams) FrontendUrlUtils(org.ovirt.engine.ui.frontend.utils.FrontendUrlUtils) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) ConsoleOptions(org.ovirt.engine.core.common.console.ConsoleOptions) Frontend(org.ovirt.engine.ui.frontend.Frontend) VM(org.ovirt.engine.core.common.businessentities.VM) ShowErrorAsyncQuery(org.ovirt.engine.ui.uicommonweb.ShowErrorAsyncQuery) BaseCommandTarget(org.ovirt.engine.ui.uicommonweb.BaseCommandTarget) TypeResolver(org.ovirt.engine.ui.uicommonweb.TypeResolver) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) ConfigureConsoleOptionsParams(org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams) ShowErrorAsyncQuery(org.ovirt.engine.ui.uicommonweb.ShowErrorAsyncQuery) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) ConsoleOptions(org.ovirt.engine.core.common.console.ConsoleOptions)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31