Search in sources :

Example 1 with EnumTranslator

use of org.ovirt.engine.ui.uicompat.EnumTranslator 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 2 with EnumTranslator

use of org.ovirt.engine.ui.uicompat.EnumTranslator in project ovirt-engine by oVirt.

the class StorageGeneralModel method onEntityChanged.

@Override
protected void onEntityChanged() {
    super.onEntityChanged();
    if (getEntity() != null) {
        StorageDomain storageDomain = getEntity();
        setIsNfs(storageDomain.getStorageType() == StorageType.NFS);
        setIsLocalS(storageDomain.getStorageType() == StorageType.LOCALFS);
        setIsPosix(storageDomain.getStorageType() == StorageType.POSIXFS);
        setIsGlusterfs(storageDomain.getStorageType() == StorageType.GLUSTERFS);
        if (getIsNfs() || getIsLocalS() || getIsPosix() || getIsGlusterfs()) {
            AsyncDataProvider.getInstance().getStorageConnectionById(new AsyncQuery<>(connection -> {
                if (connection != null) {
                    setPath(connection.getConnection());
                    if (isNfs) {
                        EnumTranslator translator = EnumTranslator.getInstance();
                        setNfsVersion(translator.translate(connection.getNfsVersion()));
                        setRetransmissions(connection.getNfsRetrans());
                        setTimeout(connection.getNfsTimeo());
                    }
                    if (isPosix || isGlusterfs) {
                        setVfsType(connection.getVfsType());
                        setMountOptions(connection.getMountOptions());
                    }
                } else {
                    setPath(null);
                }
            }), storageDomain.getStorage(), false);
        } else {
            setPath(null);
        }
    }
}
Also used : Objects(java.util.Objects) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator)

Example 3 with EnumTranslator

use of org.ovirt.engine.ui.uicompat.EnumTranslator in project ovirt-engine by oVirt.

the class VmStatusColumn method getTooltip.

@Override
public SafeHtml getTooltip(T object) {
    String tooltip;
    EnumTranslator translator = EnumTranslator.getInstance();
    VM vm = getValue(object);
    if (vm == null) {
        return null;
    }
    // the tooltip always has at least the vm status
    tooltip = getStatusTooltipText(vm.getStatus());
    // optionally, the vm status icon gets an alert exclamation. Indicate why.
    if (needsAlert(vm)) {
        if (isUpdateNeeded(vm)) {
            // $NON-NLS-1$
            tooltip += "<br/><br/>" + constants.newtools();
        }
        if (hasPauseError(vm)) {
            // $NON-NLS-1$
            tooltip += "<br/><br/>" + translator.translate(vm.getVmPauseStatus());
        }
        if (hasIllegalImages(vm)) {
            if (vm.getStatus() == VMStatus.Up) {
                // $NON-NLS-1$
                tooltip += "<br/><br/>" + constants.runningVmHasIllegalImages();
            } else {
                // $NON-NLS-1$
                tooltip += "<br/><br/>" + constants.shutdownVmHasIllegalImages();
            }
        }
        if (vm.getStatus() == VMStatus.Up) {
            if (hasGuestAgent(vm)) {
                if (hasDifferentTimezone(vm)) {
                    // $NON-NLS-1$
                    tooltip += "<br/><br/>" + constants.guestTimezoneDiffers();
                }
                if (hasDifferentOSType(vm)) {
                    // $NON-NLS-1$
                    tooltip += "<br/><br/>" + constants.guestOSDiffers();
                }
            } else {
                // $NON-NLS-1$
                tooltip += "<br/><br/>" + constants.guestAgentNotAvailable();
            }
        }
    }
    if (tooltip != null) {
        return SafeHtmlUtils.fromSafeConstant(tooltip);
    }
    return null;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator)

Example 4 with EnumTranslator

use of org.ovirt.engine.ui.uicompat.EnumTranslator in project ovirt-engine by oVirt.

the class SubTabVolumeGeneralView method translateVolumeType.

private void translateVolumeType(GlusterVolumeEntity volumeEntity) {
    EnumTranslator translator = EnumTranslator.getInstance();
    if (translator.containsKey(volumeEntity.getVolumeType())) {
        String volumeType = translator.translate(volumeEntity.getVolumeType());
        if (volumeEntity.getIsArbiter()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            volumeType += " (" + ConstantsManager.getInstance().getConstants().arbiter() + ")";
        }
        getDetailModel().setVolumeTypeSilently(volumeType);
    }
}
Also used : EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator)

Aggregations

EnumTranslator (org.ovirt.engine.ui.uicompat.EnumTranslator)4 Objects (java.util.Objects)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)2 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)2 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)2 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)2 ArrayList (java.util.ArrayList)1 QuotaEnforcementTypeEnum (org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 VmPauseStatus (org.ovirt.engine.core.common.businessentities.VmPauseStatus)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)1 SearchType (org.ovirt.engine.core.common.interfaces.SearchType)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 QueryType (org.ovirt.engine.core.common.queries.QueryType)1 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)1 StringHelper (org.ovirt.engine.core.compat.StringHelper)1