Search in sources :

Example 26 with AsyncQuery

use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.

the class InstanceTypeManager method updateDefaultDisplayRelatedFields.

protected void updateDefaultDisplayRelatedFields(final VmBase vmBase) {
    // Update display protocol selected item
    final Collection<DisplayType> displayTypes = model.getDisplayType().getItems();
    if (displayTypes == null || displayTypes.isEmpty()) {
        return;
    }
    // graphics
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        deactivate();
        List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
        model.getIsHeadlessModeEnabled().setEntity(vmBase.getDefaultDisplayType() == DisplayType.none);
        // select display protocol
        // first by default
        DisplayType displayProtocol = displayTypes.iterator().next();
        if (displayTypes.contains(vmBase.getDefaultDisplayType())) {
            // if display types contain DT of a vm, pick this one
            displayProtocol = vmBase.getDefaultDisplayType();
        }
        maybeSetSelectedItem(model.getDisplayType(), displayProtocol);
        Set<GraphicsType> graphicsTypes = new HashSet<>();
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            graphicsTypes.add(graphicsDevice.getGraphicsType());
        }
        UnitVmModel.GraphicsTypes selected = UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypes);
        if (selected != null && getModel().getGraphicsType().getItems().contains(selected)) {
            maybeSetSelectedItem(getModel().getGraphicsType(), selected);
        }
        maybeSetSelectedItem(model.getNumOfMonitors(), vmBase.getNumOfMonitors());
        maybeSetSelectedItem(model.getUsbPolicy(), vmBase.getUsbPolicy());
        maybeSetEntity(model.getIsSmartcardEnabled(), vmBase.isSmartcardEnabled());
        maybeSetSingleQxlPci(vmBase);
        activate();
    }));
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) HashSet(java.util.HashSet) Set(java.util.Set) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with AsyncQuery

use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.

the class InstanceTypeManager method updateAll.

/**
 * First updates the list of instance types and selects the one which is supposed to be selected and then
 * updates all the fields which are taken from the instance type (by calling the updateFields()).
 */
public void updateAll() {
    final Guid selectedInstanceTypeId = getSelectedInstanceTypeId();
    Frontend.getInstance().runQuery(QueryType.GetAllInstanceTypes, new QueryParametersBase(), new AsyncQuery<QueryReturnValue>(returnValue -> {
        if (returnValue == null || !returnValue.getSucceeded()) {
            return;
        }
        List<InstanceType> instanceTypes = new ArrayList<>();
        // add this only if the user is allowed to
        if (!getModel().isCreateInstanceOnly()) {
            instanceTypes.add(CustomInstanceType.INSTANCE);
        }
        for (InstanceType instanceType : (Iterable<InstanceType>) returnValue.getReturnValue()) {
            instanceTypes.add(instanceType);
        }
        getModel().getInstanceTypes().setItems(instanceTypes);
        for (InstanceType instanceType : instanceTypes) {
            if ((instanceType instanceof CustomInstanceType) && selectedInstanceTypeId == null) {
                getModel().getInstanceTypes().setSelectedItem(CustomInstanceType.INSTANCE);
                break;
            }
            if (instanceType.getId() == null || selectedInstanceTypeId == null) {
                continue;
            }
            if (instanceType.getId().equals(selectedInstanceTypeId)) {
                getModel().getInstanceTypes().setSelectedItem(instanceType);
                break;
            }
        }
        if (getModel().getInstanceTypes().getSelectedItem() instanceof CustomInstanceType) {
            // detach if the instance type is "custom"
            getModel().getAttachedToInstanceType().setEntity(false);
        }
        updateFields();
    }));
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType)

Example 28 with AsyncQuery

use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.

the class InstanceTypeManager method updateRngDevice.

protected void updateRngDevice(final VmBase vmBase) {
    if (model.getIsRngEnabled().getIsChangable() && model.getIsRngEnabled().getIsAvailable()) {
        if (!isNextRunConfigurationExists()) {
            Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
                deactivate();
                List<VmDevice> rngDevices = returnValue.getReturnValue();
                getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
                if (!rngDevices.isEmpty()) {
                    VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
                    rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion());
                    getModel().setRngDevice(rngDevice);
                }
                activate();
                updateVirtioScsi(vmBase);
            }));
        } else {
            deactivate();
            VmDevice rngDevice = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.RNG);
            getModel().getIsRngEnabled().setEntity(rngDevice != null);
            if (rngDevice != null) {
                getModel().setRngDevice(new VmRngDevice(rngDevice));
            }
            activate();
            updateVirtioScsi(vmBase);
        }
    } else {
        updateVirtioScsi(vmBase);
    }
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) 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) ArrayList(java.util.ArrayList) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 29 with AsyncQuery

use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.

the class VmInstanceTypeManager method updateNetworkInterfaces.

private void updateNetworkInterfaces(final ProfileBehavior behavior, final List<VmNetworkInterface> argNics) {
    AsyncQuery<List<VnicProfileView>> query = new AsyncQuery<>(profiles -> {
        List<VnicInstanceType> vnicInstanceTypes = new ArrayList<>();
        List<VmNetworkInterface> nics = (argNics == null) ? new ArrayList<VmNetworkInterface>() : argNics;
        for (VmNetworkInterface nic : nics) {
            final VnicInstanceType vnicInstanceType = new VnicInstanceType(nic);
            vnicInstanceType.setItems(profiles);
            behavior.initSelectedProfile(vnicInstanceType, vnicInstanceType.getNetworkInterface());
            vnicInstanceTypes.add(vnicInstanceType);
        }
        getModel().getNicsWithLogicalNetworks().getVnicProfiles().setItems(profiles);
        getModel().getNicsWithLogicalNetworks().setItems(vnicInstanceTypes);
        getModel().getNicsWithLogicalNetworks().setSelectedItem(Linq.firstOrNull(vnicInstanceTypes));
    });
    behavior.initProfiles(getModel().getSelectedCluster().getId(), getModel().getSelectedDataCenter().getId(), query);
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) VnicInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.VnicInstanceType)

Example 30 with AsyncQuery

use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.

the class ExistingVmModelBehavior method initialize.

@Override
public void initialize() {
    super.initialize();
    toggleAutoSetVmHostname();
    getModel().getVmInitEnabled().setEntity(getVm().getVmInit() != null);
    getModel().getVmInitModel().init(getVm().getStaticData());
    getModel().getVmType().setIsChangeable(true);
    getModel().getIsSoundcardEnabled().setIsChangeable(true);
    getModel().getInstanceTypes().setIsChangeable(!vm.isRunning());
    getModel().getLabelList().setIsAvailable(true);
    getModel().getVmId().setIsAvailable(true);
    getModel().getVmId().setIsChangeable(false);
    loadDataCenter();
    instanceTypeManager = new ExistingVmInstanceTypeManager(getModel(), vm);
    if (vm.getVmPoolId() != null) {
        instanceTypeManager.setAlwaysEnabledFieldUpdate(true);
    }
    Frontend.getInstance().runQuery(QueryType.GetVmNumaNodesByVmId, new IdQueryParameters(vm.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        List<VmNumaNode> nodes = returnValue.getReturnValue();
        getModel().setVmNumaNodes(nodes);
        getModel().updateNodeCount(nodes.size());
    }));
    // load dedicated host names into host names list
    if (getVm().getDedicatedVmForVdsList().size() > 0) {
        Frontend.getInstance().runQuery(QueryType.GetAllHostNamesPinnedToVmById, new IdQueryParameters(vm.getId()), asyncQuery((QueryReturnValue returnValue) -> setDedicatedHostsNames((List<String>) returnValue.getReturnValue())));
    }
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) Arrays(java.util.Arrays) Guid(org.ovirt.engine.core.compat.Guid) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) CommentVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommentVmBaseToUnitBuilder) Map(java.util.Map) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) Version(org.ovirt.engine.core.compat.Version) InstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.InstanceTypeManager) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) EnumSet(java.util.EnumSet) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmActionByVmOriginTypeValidator(org.ovirt.engine.core.common.validation.VmActionByVmOriginTypeValidator) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Linq(org.ovirt.engine.ui.uicommonweb.Linq) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) NameAndDescriptionVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.NameAndDescriptionVmBaseToUnitBuilder) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) StringHelper(org.ovirt.engine.core.compat.StringHelper) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) CommonCompatibilityVersionUtils(org.ovirt.engine.core.common.utils.CommonCompatibilityVersionUtils) ExistingVmInstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.ExistingVmInstanceTypeManager) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) CommonVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommonVmBaseToUnitBuilder) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ExistingVmInstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.ExistingVmInstanceTypeManager) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AsyncQuery (org.ovirt.engine.ui.frontend.AsyncQuery)35 List (java.util.List)25 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)24 Guid (org.ovirt.engine.core.compat.Guid)24 Frontend (org.ovirt.engine.ui.frontend.Frontend)24 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)24 ArrayList (java.util.ArrayList)22 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)21 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)21 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)20 QueryType (org.ovirt.engine.core.common.queries.QueryType)20 Collection (java.util.Collection)19 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)19 Linq (org.ovirt.engine.ui.uicommonweb.Linq)19 BuilderExecutor (org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor)18 Arrays (java.util.Arrays)17 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)17 StringHelper (org.ovirt.engine.core.compat.StringHelper)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)16 Collections (java.util.Collections)15