Search in sources :

Example 11 with AsyncCallback

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

the class VmGeneralModel method updateProperties.

private void updateProperties() {
    VM vm = getEntity();
    super.updateProperties(vm.getId());
    setName(vm.getName());
    setDescription(vm.getVmDescription());
    // $NON-NLS-1$
    setQuotaName(vm.getQuotaName() != null ? vm.getQuotaName() : "");
    setQuotaAvailable(vm.getQuotaEnforcementType() != null && !vm.getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED));
    setTemplate(vmTemplateNameRenderer.render(vm));
    // $NON-NLS-1$
    setDefinedMemory(vm.getVmMemSizeMb() + " MB");
    // $NON-NLS-1$
    setMinAllocatedMemory(vm.getMinAllocatedMem() + " MB");
    if (vm.isRunningOrPaused() && vm.getGuestMemoryBuffered() != null && vm.getGuestMemoryCached() != null && vm.getGuestMemoryFree() != null) {
        setGuestFreeCachedBufferedMemInfo(// $NON-NLS-1$
        (vm.getGuestMemoryFree() / 1024L) + " / " + (vm.getGuestMemoryBuffered() / 1024L) + // $NON-NLS-1$
        " / " + (vm.getGuestMemoryCached() / 1024L) + // $NON-NLS-1$
        " MB");
    } else {
        // Handled in form
        setGuestFreeCachedBufferedMemInfo(null);
    }
    setOS(AsyncDataProvider.getInstance().getOsName(vm.getVmOsId()));
    EnumTranslator translator = EnumTranslator.getInstance();
    setDefaultDisplayType(translator.translate(vm.getDefaultDisplayType()));
    setOrigin(translator.translate(vm.getOrigin()));
    setIsHighlyAvailable(vm.isAutoStartup());
    setPriority(AsyncDataProvider.getInstance().priorityToString(vm.getPriority()));
    setOptimizedForSystemProfile(translator.translate(vm.getVmType()));
    setMonitorCount(vm.getNumOfMonitors());
    setUsbPolicy(translator.translate(vm.getUsbPolicy()));
    setCpuInfo(ConstantsManager.getInstance().getMessages().cpuInfoLabel(vm.getNumOfCpus(), vm.getNumOfSockets(), vm.getCpuPerSocket(), vm.getThreadsPerCpu()));
    setGuestCpuCount(vm.getGuestCpuCount());
    setHasDomain(AsyncDataProvider.getInstance().isWindowsOsType(vm.getVmOsId()));
    if (vm.getVmInit() != null) {
        setDomain(vm.getVmInit().getDomain());
    }
    setHasTimeZone(!StringHelper.isNullOrEmpty(vm.getTimeZone()));
    setTimeZone(vm.getTimeZone());
    setHasCustomProperties(!StringHelper.isNullOrEmpty(vm.getCustomProperties()));
    setCustomProperties(getHasCustomProperties() ? constants.configured() : constants.notConfigured());
    setCompatibilityVersion(vm.getCompatibilityVersion() != null ? vm.getCompatibilityVersion().toString() : // $NON-NLS-1$
    "");
    setVmId(vm.getId().toString());
    setFqdn(vm.getFqdn());
    setHasAlert(vm.getVmPauseStatus() != VmPauseStatus.NONE && vm.getVmPauseStatus() != VmPauseStatus.NOERR);
    if (getHasAlert()) {
        setAlert(translator.translate(vm.getVmPauseStatus()));
    } else {
        setAlert(null);
    }
    setHasCreatedByUser(vm.getCreatedByUserId() != null);
    if (getHasCreatedByUser()) {
        Frontend.getInstance().runQuery(QueryType.GetDbUserByUserId, new IdQueryParameters(vm.getCreatedByUserId()), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

            @Override
            public void onSuccess(QueryReturnValue result) {
                DbUser dbUser = result.getReturnValue();
                if (dbUser != null) {
                    setCreatedByUser(getUserName(dbUser));
                }
            }

            private String getUserName(DbUser dbUser) {
                if (StringHelper.isNotNullOrEmpty(dbUser.getFirstName()) || StringHelper.isNotNullOrEmpty(dbUser.getLastName())) {
                    return messages.userName(nullToEmpty(dbUser.getFirstName()), nullToEmpty(dbUser.getLastName()));
                }
                return dbUser.getLoginName();
            }

            private String nullToEmpty(String val) {
                return val == null ? "" : val;
            }
        }));
    }
    setHasDefaultHost(vm.getDedicatedVmForVdsList().size() > 0);
    if (getHasDefaultHost()) {
        Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(// $NON-NLS-1$
        "Host: cluster = " + vm.getClusterName() + " sortby name", SearchType.VDS).withoutRefresh(), new AsyncQuery<QueryReturnValue>(returnValue -> {
            // $NON-NLS-1$
            VM localVm = getEntity();
            if (localVm == null) {
                return;
            }
            ArrayList<VDS> hosts = returnValue.getReturnValue();
            if (localVm.getDedicatedVmForVdsList().size() > 0) {
                String defaultHost = "";
                for (VDS host : hosts) {
                    if (localVm.getDedicatedVmForVdsList().contains(host.getId())) {
                        if (defaultHost.isEmpty()) {
                            defaultHost = host.getName();
                        } else {
                            // $NON-NLS-1$
                            defaultHost += ", " + host.getName();
                        }
                    }
                }
                setDefaultHost(defaultHost);
            }
        }));
    } else {
        setDefaultHost(ConstantsManager.getInstance().getConstants().anyHostInCluster());
    }
    final String guestCpuType = vm.getCpuName() != null ? vm.getCpuName() : (vm.getCustomCpuName() != null ? vm.getCustomCpuName() : vm.getClusterCpuName());
    setGuestCpuType(guestCpuType);
}
Also used : SearchType(org.ovirt.engine.core.common.interfaces.SearchType) QueryType(org.ovirt.engine.core.common.queries.QueryType) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) Event(org.ovirt.engine.ui.uicompat.Event) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Frontend(org.ovirt.engine.ui.frontend.Frontend) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) VmPauseStatus(org.ovirt.engine.core.common.businessentities.VmPauseStatus) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StringHelper(org.ovirt.engine.core.compat.StringHelper) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) Objects(java.util.Objects) VM(org.ovirt.engine.core.common.businessentities.VM) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) EventDefinition(org.ovirt.engine.ui.uicompat.EventDefinition) VDS(org.ovirt.engine.core.common.businessentities.VDS) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) VDS(org.ovirt.engine.core.common.businessentities.VDS) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) ArrayList(java.util.ArrayList) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 12 with AsyncCallback

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

the class TemplateVmModelBehavior method initialize.

@Override
public void initialize() {
    super.initialize();
    getModel().getTemplateWithVersion().setIsChangeable(false);
    getModel().getBaseTemplate().setIsChangeable(false);
    getModel().getTemplateWithVersion().setIsChangeable(false);
    getModel().getProvisioning().setIsChangeable(false);
    getModel().getStorageDomain().setIsChangeable(false);
    getModel().getIsSoundcardEnabled().setIsChangeable(true);
    getModel().getVmType().setIsChangeable(true);
    getModel().getTemplateVersionName().setIsChangeable(!template.isBaseTemplate());
    getModel().getName().setIsChangeable(template.isBaseTemplate());
    if (template.getStoragePoolId() != null && !template.getStoragePoolId().equals(Guid.Empty)) {
        AsyncDataProvider.getInstance().getDataCenterById(new AsyncQuery<>(dataCenter -> AsyncDataProvider.getInstance().getClusterListByService(new AsyncQuery<>(clusters -> {
            ArrayList<Cluster> clustersSupportingVirt = new ArrayList<>();
            // filter clusters supporting virt service only
            for (Cluster cluster : clusters) {
                if (cluster.supportsVirtService()) {
                    clustersSupportingVirt.add(cluster);
                }
            }
            List<Cluster> filteredClusters = AsyncDataProvider.getInstance().filterByArchitecture(clustersSupportingVirt, template.getClusterArch());
            getModel().setDataCentersAndClusters(getModel(), new ArrayList<>(Arrays.asList(new StoragePool[] { dataCenter })), filteredClusters, template.getClusterId());
            updateRngDevice(template.getId());
            AsyncDataProvider.getInstance().isSoundcardEnabled(new AsyncQuery<>(returnValue -> {
                getModel().getIsSoundcardEnabled().setEntity(returnValue);
                initTemplate();
                initCdImage();
            }), template.getId());
            Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(template.getId()), new AsyncQuery<>((QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
            AsyncDataProvider.getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), template.getId());
        }), true, false)), template.getStoragePoolId());
    }
    AsyncDataProvider.getInstance().getWatchdogByVmId(new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
        UnitVmModel model = getModel();
        @SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
        for (VmWatchdog watchdog : watchdogs) {
            model.getWatchdogAction().setSelectedItem(watchdog.getAction());
            model.getWatchdogModel().setSelectedItem(watchdog.getModel());
        }
    }), template.getId());
    getModel().getMigrationMode().setSelectedItem(template.getMigrationSupport());
    setupBaseTemplate(template.getBaseTemplateId());
}
Also used : DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) Arrays(java.util.Arrays) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) 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) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) CommentVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommentVmBaseToUnitBuilder) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) Collections(java.util.Collections) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) CommonVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommonVmBaseToUnitBuilder) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with AsyncCallback

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

the class WebClientConsoleInvoker method invokeClient.

public void invokeClient() {
    Frontend.getInstance().runQuery(QueryType.SignString, new SignStringParameters(createConnectionString(host, port, useSsl)), new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
        String signedTicket = returnValue.getReturnValue();
        invokeClientNative(signedTicket);
    }));
}
Also used : AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) SignStringParameters(org.ovirt.engine.core.common.queries.SignStringParameters)

Example 14 with AsyncCallback

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

the class PoolGeneralModel method updateProperties.

private void updateProperties() {
    final VmPool pool = getEntity();
    setName(pool.getName());
    setDescription(pool.getVmPoolDescription());
    Frontend.getInstance().runQuery(QueryType.GetVmDataByPoolId, new IdQueryParameters(pool.getVmPoolId()), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

        @Override
        public void onSuccess(QueryReturnValue result) {
            // refactor to "switch ... case...".
            if (result != null) {
                setvm((VM) result.getReturnValue());
            }
            if (getvm() != null) {
                setTemplate(vmTemplateNameRenderer.render(getvm()));
                setCpuInfo(ConstantsManager.getInstance().getMessages().cpuInfoLabel(getvm().getNumOfCpus(), getvm().getNumOfSockets(), getvm().getCpuPerSocket(), getvm().getThreadsPerCpu()));
                setMonitorCount(getvm().getNumOfMonitors());
                setOS(getvm().getVmOsId());
                // $NON-NLS-1$
                setDefinedMemory(getvm().getVmMemSizeMb() + " MB");
                // $NON-NLS-1$
                setMinAllocatedMemory(getvm().getMinAllocatedMem() + " MB");
                Translator translator = EnumTranslator.getInstance();
                setDefaultDisplayType(translator.translate(getvm().getDefaultDisplayType()));
                setOrigin(translator.translate(getvm().getOrigin()));
                setUsbPolicy(translator.translate(getvm().getUsbPolicy()));
                setHasDomain(AsyncDataProvider.getInstance().isWindowsOsType(getvm().getVmOsId()));
                setOptimizedForSystemProfile(translator.translate(getvm().getVmType()));
                setHasTimeZone(AsyncDataProvider.getInstance().isWindowsOsType(getvm().getVmOsId()));
                setTimeZone(getvm().getTimeZone());
                setIsStateless(!pool.isStateful());
                setQuotaName(getvm().getQuotaName());
                setHasDefaultHost(getvm().getDedicatedVmForVdsList().size() > 0);
                if (getHasDefaultHost()) {
                    Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(// $NON-NLS-1$
                    "Host: cluster = " + getvm().getClusterName() + " sortby name", SearchType.VDS), new AsyncQuery<QueryReturnValue>(returnValue1 -> {
                        // $NON-NLS-1$
                        String defaultHost1 = "";
                        ArrayList<VDS> hosts = returnValue1.getReturnValue();
                        for (VDS host : hosts) {
                            if (getvm().getDedicatedVmForVdsList().contains(host.getId())) {
                                if (defaultHost1.isEmpty()) {
                                    defaultHost1 = host.getName();
                                } else {
                                    // $NON-NLS-1$
                                    defaultHost1 += ", " + host.getName();
                                }
                            }
                        }
                        setDefaultHost(defaultHost1);
                    }));
                } else {
                    setDefaultHost(ConstantsManager.getInstance().getConstants().anyHostInCluster());
                }
                if (getvm() != null) {
                    PoolGeneralModel.super.updateProperties(getvm().getId());
                }
            } else {
                setTemplate(null);
                setCpuCount(0);
                setMonitorCount(0);
                setOS(0);
                setDefinedMemory(null);
                setMinAllocatedMemory(null);
                setDefaultDisplayType(null);
                setHasDomain(false);
                setDomain(null);
                setHasTimeZone(false);
                setTimeZone(null);
                setUsbPolicy(null);
                setDefaultHost(null);
                setIsStateless(!pool.isStateful());
                // $NON-NLS-1$
                setGraphicsType("");
                // $NON-NLS-1$
                setOptimizedForSystemProfile("");
                getUpdateCompleteEvent().raise(this, EventArgs.EMPTY);
            }
        }
    }));
}
Also used : VmPool(org.ovirt.engine.core.common.businessentities.VmPool) SearchType(org.ovirt.engine.core.common.interfaces.SearchType) QueryType(org.ovirt.engine.core.common.queries.QueryType) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) Event(org.ovirt.engine.ui.uicompat.Event) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Objects(java.util.Objects) Frontend(org.ovirt.engine.ui.frontend.Frontend) VM(org.ovirt.engine.core.common.businessentities.VM) Translator(org.ovirt.engine.ui.uicompat.Translator) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) EventDefinition(org.ovirt.engine.ui.uicompat.EventDefinition) AbstractGeneralModel(org.ovirt.engine.ui.uicommonweb.models.vms.AbstractGeneralModel) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VDS(org.ovirt.engine.core.common.businessentities.VDS) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) VmTemplateNameRenderer(org.ovirt.engine.ui.uicommonweb.models.vms.VmTemplateNameRenderer) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) VmPool(org.ovirt.engine.core.common.businessentities.VmPool) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) Translator(org.ovirt.engine.ui.uicompat.Translator) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList)

Example 15 with AsyncCallback

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

the class ClusterListModel method checkForActiveVms.

private void checkForActiveVms(ClusterModel model, final ConfirmationModel confirmModel) {
    Guid clusterId = model.getEntity().getId();
    Frontend.getInstance().runQuery(QueryType.GetNumberOfActiveVmsInClusterByClusterId, new IdQueryParameters(clusterId), new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
        Integer numOfActiveVms = returnValue.getReturnValue();
        if (numOfActiveVms != 0) {
            confirmModel.setMessage(messages.thereAreActiveVMsRequiringRestart(numOfActiveVms));
        }
        checkForNonResponsiveHosts(confirmModel);
    }));
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

AsyncCallback (org.ovirt.engine.ui.frontend.AsyncCallback)16 ArrayList (java.util.ArrayList)11 Guid (org.ovirt.engine.core.compat.Guid)8 List (java.util.List)7 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)6 Frontend (org.ovirt.engine.ui.frontend.Frontend)6 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)6 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)5 Collections (java.util.Collections)4 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 VM (org.ovirt.engine.core.common.businessentities.VM)4 QueryType (org.ovirt.engine.core.common.queries.QueryType)4 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)4 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)4 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)4 UIConstants (org.ovirt.engine.ui.uicompat.UIConstants)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Objects (java.util.Objects)3