Search in sources :

Example 41 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class VmPropertiesUtils method init.

public void init() throws InitializationException {
    try {
        predefinedProperties = new HashMap<>();
        userdefinedProperties = new HashMap<>();
        allVmProperties = new HashMap<>();
        Set<Version> versions = getSupportedClusterLevels();
        for (Version version : versions) {
            predefinedProperties.put(version, new HashMap<>());
            userdefinedProperties.put(version, new HashMap<>());
            allVmProperties.put(version, new HashMap<>());
            parsePropertiesRegex(getPredefinedVMProperties(version), predefinedProperties.get(version));
            parsePropertiesRegex(getUserDefinedVMProperties(version), userdefinedProperties.get(version));
            allVmProperties.get(version).putAll(predefinedProperties.get(version));
            allVmProperties.get(version).putAll(userdefinedProperties.get(version));
        }
    } catch (Throwable ex) {
        throw new InitializationException(ex);
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) InitializationException(org.ovirt.engine.core.common.utils.exceptions.InitializationException)

Example 42 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class RpmVersionUtils method isUpdateAvailable.

/**
 * Checks if an update is available for host OS
 *
 * @param isos
 *            an images which may upgrade the given host
 * @param hostOs
 *            the examined host OS
 * @return {@code true} if an update is available, else {@code false}
 */
public static boolean isUpdateAvailable(List<RpmVersion> isos, String hostOs) {
    String[] hostOsParts = hostOs.split("-");
    for (int i = 0; i < hostOsParts.length; i++) {
        hostOsParts[i] = hostOsParts[i].trim();
    }
    // hostOs holds the following components:
    // hostOs[0] holds prefix
    // hostOs[1] holds version
    // hostOs[2] holds release
    final int VERSION_FIELDS_NUMBER = 4;
    // Fix hostOs[1] to be format of major.minor.build.revision
    // Add ".0" for missing parts
    String[] hostOsVersionParts = hostOsParts[1].split("\\.");
    for (int i = 0; i < VERSION_FIELDS_NUMBER - hostOsVersionParts.length; i++) {
        hostOsParts[1] = hostOsParts[1].trim() + ".0";
    }
    Version hostVersion = new Version(hostOsParts[1].trim());
    String releaseHost = hostOsParts[2].trim();
    for (RpmVersion iso : isos) {
        // Major check
        if (hostVersion.getMajor() == iso.getMajor()) {
            // Minor and Buildiso.getRpmName()
            if (iso.getMinor() > hostVersion.getMinor() || iso.getBuild() > hostVersion.getBuild()) {
                return true;
            }
            String rpmFromIso = iso.getRpmName();
            // Removes the ".iso" file extension , and get the release part from it
            int isoIndex = rpmFromIso.indexOf(".iso");
            if (isoIndex != -1) {
                rpmFromIso = iso.getRpmName().substring(0, isoIndex);
            }
            if (RpmVersionUtils.compareRpmParts(RpmVersionUtils.splitRpmToParts(rpmFromIso)[2], releaseHost) > 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : RpmVersion(org.ovirt.engine.core.compat.RpmVersion) Version(org.ovirt.engine.core.compat.Version) RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Example 43 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class DevicePropertiesUtils method init.

/**
 * Loads device custom properties definition
 *
 * @throws InitializationException
 *             if an error occured during device custom properties definition loading
 */
public void init() throws InitializationException {
    try {
        Set<Version> versions = getSupportedClusterLevels();
        String devicePropertiesStr;
        deviceProperties = new HashMap<>();
        for (Version version : versions) {
            // load device properties
            devicePropertiesStr = getCustomDeviceProperties(version);
            deviceProperties.put(version, new EnumMap<>(VmDeviceGeneralType.class));
            Matcher typeMatcher = devicePropSplitPattern.matcher(devicePropertiesStr);
            while (typeMatcher.find()) {
                String dcpStr = typeMatcher.group();
                // device type definition starts with "{type="
                int start = TYPE_PREFIX_LEN;
                int end = dcpStr.length() - 1;
                if (dcpStr.endsWith(PROPERTIES_DELIMETER)) {
                    // remove trailing ;
                    end--;
                }
                dcpStr = dcpStr.substring(start, end);
                int idx = dcpStr.indexOf(PROPERTIES_DELIMETER);
                VmDeviceGeneralType type = VmDeviceGeneralType.forValue(dcpStr.substring(0, idx));
                // properties definition for device starts with ";prop={"
                String propStr = dcpStr.substring(idx + PROP_PREFIX_LEN, dcpStr.length() - 1);
                Map<String, String> props = new HashMap<>();
                parsePropertiesRegex(propStr, props);
                deviceProperties.get(version).put(type, props);
            }
        }
    } catch (Exception ex) {
        throw new InitializationException(ex);
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) InitializationException(org.ovirt.engine.core.common.utils.exceptions.InitializationException) InitializationException(org.ovirt.engine.core.common.utils.exceptions.InitializationException)

Example 44 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class ConfigUtilsBase method getValue.

/**
 * Returns the typed value of the given option. returns default value if option.option_value is null
 */
protected Object getValue(VdcOption option) {
    Object result = option.getOptionValue();
    EnumValue enumValue = parseEnumValue(option.getOptionName());
    if (enumValue != null) {
        final OptionBehaviourAttribute optionBehaviour = enumValue.getOptionBehaviour();
        final Class<?> fieldType = enumValue.getFieldType();
        result = parseValue(option.getOptionValue(), option.getOptionName(), fieldType);
        if (optionBehaviour != null) {
            Map<String, Object> values = null;
            switch(optionBehaviour.behaviour()) {
                // split string by comma for List<string> constructor
                case CommaSeparatedStringArray:
                    result = Arrays.asList(((String) result).split("[,]", -1));
                    break;
                case Password:
                    try {
                        result = EngineEncryptionUtils.decrypt((String) result);
                    } catch (Exception e) {
                        log.error("Failed to decrypt value for property '{}', encrypted value will be used. Error: {} ", option.getOptionName(), e.getMessage());
                        log.debug("Exception", e);
                    }
                    break;
                case ValueDependent:
                    // get the config that this value depends on
                    String prefix = getValue(optionBehaviour.dependentOn(), ConfigCommon.defaultConfigurationVersion);
                    // combine the prefix with the 'real value'
                    if (prefix != null) {
                        String realName = String.format("%1$s%2$s", prefix, optionBehaviour.realValue());
                        result = getValue(ConfigValues.valueOf(realName), ConfigCommon.defaultConfigurationVersion);
                    }
                    break;
                case CommaSeparatedVersionArray:
                    HashSet<Version> versions = new HashSet<>();
                    for (String ver : result.toString().split("[,]", -1)) {
                        try {
                            versions.add(new Version(ver));
                        } catch (Exception e) {
                            log.error("Could not parse version '{}' for config value '{}'", ver, option.getOptionName());
                        }
                    }
                    result = versions;
                    break;
            }
        }
    }
    return result;
}
Also used : Version(org.ovirt.engine.core.compat.Version) OptionBehaviourAttribute(org.ovirt.engine.core.common.config.OptionBehaviourAttribute) HashSet(java.util.HashSet)

Example 45 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class GetProductVersionQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    String rpmVersion = Config.getValue(ConfigValues.ProductRPMVersion);
    Version version = parseRpmVersion(rpmVersion);
    if (version == null) {
        String vdcVersion = Config.getValue(ConfigValues.VdcVersion);
        version = parseVdcVersion(vdcVersion);
    }
    setReturnValue(version);
}
Also used : Version(org.ovirt.engine.core.compat.Version)

Aggregations

Version (org.ovirt.engine.core.compat.Version)102 ArrayList (java.util.ArrayList)24 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)20 Guid (org.ovirt.engine.core.compat.Guid)20 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)17 Map (java.util.Map)16 List (java.util.List)15 HashSet (java.util.HashSet)14 VDS (org.ovirt.engine.core.common.businessentities.VDS)14 HashMap (java.util.HashMap)13 ServerCpu (org.ovirt.engine.core.common.businessentities.ServerCpu)12 VM (org.ovirt.engine.core.common.businessentities.VM)11 ConfigValues (org.ovirt.engine.core.common.config.ConfigValues)11 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)11 Arrays (java.util.Arrays)10 MigrationPolicy (org.ovirt.engine.core.common.migration.MigrationPolicy)10 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)10 Collection (java.util.Collection)9 Collections (java.util.Collections)9 ArchitectureType (org.ovirt.engine.core.common.businessentities.ArchitectureType)9