Search in sources :

Example 1 with OS

use of org.ovirt.engine.core.utils.OS in project ovirt-engine by oVirt.

the class InClusterUpgradeValidator method isUpgradePossible.

public ValidationResult isUpgradePossible(Collection<VDS> hosts, Collection<VM> vms) {
    requireNonNull(hosts);
    requireNonNull(vms);
    final List<String> errors = new ArrayList<>();
    for (final VDS host : hosts) {
        final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
        if (!hostOs.isValid()) {
            errors.addAll(toHostEngineMessage(host, EngineMessage.CLUSTER_UPGRADE_DETAIL_HOST_INVALID_OS));
        }
    }
    for (final VM vm : vms) {
        errors.addAll(checkVmReadyForUpgrade(vm));
    }
    if (errors.isEmpty()) {
        return ValidationResult.VALID;
    } else {
        return new ValidationResult(EngineMessage.CLUSTER_UPGRADE_CAN_NOT_BE_STARTED, errors);
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) OS(org.ovirt.engine.core.utils.OS) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 2 with OS

use of org.ovirt.engine.core.utils.OS in project ovirt-engine by oVirt.

the class InClusterUpgradeFilterPolicyUnit method filter.

@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
    final VdsDynamic sourceHost = getLastHost(vm);
    if (sourceHost == null) {
        return hosts;
    }
    final OS lastHostOs = OS.fromPackageVersionString(sourceHost.getHostOs());
    if (!lastHostOs.isValid()) {
        log.debug("Source host {} does not provide a valid and complete OS identifier. Found {}.", sourceHost.getId(), sourceHost.getHostOs());
        return hosts;
    }
    final List<VDS> notOlderHosts = new ArrayList();
    for (VDS host : hosts) {
        final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
        if (!hostOs.isValid()) {
            log.debug("Host {} does not provide a valid OS identifier. Found {}.", host.getId(), host.getHostOs());
            messages.addMessage(host.getId(), EngineMessage.VAR__DETAIL__INVALID_OS.name());
            messages.addMessage(host.getId(), String.format("$os %1$s", host.getHostOs()));
        } else if (!hostOs.isSameOsFamily(lastHostOs)) {
            log.debug("Host {} does not run the same operating system. Expected {}, found {}", host.getId(), lastHostOs.getName(), hostOs.getName());
            messages.addMessage(host.getId(), EngineMessage.VAR__DETAIL__WRONG_OS.name());
            messages.addMessage(host.getId(), String.format("$expected %1$s", lastHostOs.getName()));
            messages.addMessage(host.getId(), String.format("$found %1$s", hostOs.getName()));
        } else if (hostOs.isOlderThan(lastHostOs) && !hostOs.isSameMajorVersion(lastHostOs)) {
            log.debug("Host {} runs a too old OS version. Found {}", host.getId(), host.getHostOs());
            messages.addMessage(host.getId(), EngineMessage.VAR__DETAIL__OLD_OS.name());
            messages.addMessage(host.getId(), String.format("$found %1$s", hostOs.getName()));
        } else {
            notOlderHosts.add(host);
        }
    }
    return notOlderHosts;
}
Also used : OS(org.ovirt.engine.core.utils.OS) VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsDynamic(org.ovirt.engine.core.common.businessentities.VdsDynamic) ArrayList(java.util.ArrayList)

Example 3 with OS

use of org.ovirt.engine.core.utils.OS in project ovirt-engine by oVirt.

the class InClusterUpgradeWeightPolicyUnit method score.

@Override
public List<Pair<Guid, Integer>> score(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters) {
    VdsDynamic referenceHost = getLastHost(vm);
    boolean isVmStartup = false;
    // Check if the VM is starting
    if (referenceHost == null) {
        isVmStartup = true;
        final Map<String, Version> highestVersions = new HashMap<>();
        for (VDS host : hosts) {
            OS os = OS.fromPackageVersionString(host.getHostOs());
            if (!os.isValid()) {
                continue;
            }
            Version version = highestVersions.get(os.getOsFamily());
            if (version == null || version.getMajor() < os.getVersion().getMajor()) {
                highestVersions.put(os.getOsFamily(), os.getVersion());
                referenceHost = host.getDynamicData();
            }
        }
        if (highestVersions.isEmpty()) {
            log.debug("No valid OS descriptors detected. Will not weight hosts on VM startup.");
            return noWeights(hosts);
        } else if (highestVersions.size() > 1) {
            log.debug("More than one OS family detected. Will not weight hosts on VM startup.");
            return noWeights(hosts);
        }
    }
    final OS lastHostOs = OS.fromPackageVersionString(referenceHost.getHostOs());
    if (!lastHostOs.isValid()) {
        log.debug("Reference host {} provides an invalid or incomplete OS identifier. Found {}.", referenceHost.getId(), referenceHost.getHostOs());
        return noWeights(hosts);
    }
    final List<Pair<Guid, Integer>> weights = new ArrayList<>();
    for (final VDS host : hosts) {
        final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
        if (!hostOs.isValid()) {
            log.debug("Host {} does not provide an valid OS identifier. Found {}.", host.getId(), host.getHostOs());
            weights.add(toWeight(host, BAD_WEIGHT));
        } else if (!hostOs.isSameOsFamily(lastHostOs)) {
            log.debug("Host {} does not run the same operating system. Expected {}, found {}", host.getId(), lastHostOs.getName(), hostOs.getName());
            weights.add(toWeight(host, BAD_WEIGHT));
        } else if (hostOs.isOlderThan(lastHostOs) && !hostOs.isSameMajorVersion(lastHostOs)) {
            weights.add(toWeight(host, BAD_WEIGHT));
        } else if (hostOs.isSameMajorVersion(lastHostOs) && !isVmStartup) {
            weights.add(toWeight(host, BETTER_WEIGHT));
        } else {
            weights.add(toWeight(host, BEST_WEIGHT));
        }
    }
    return weights;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) OS(org.ovirt.engine.core.utils.OS) Version(org.ovirt.engine.core.compat.Version) HashMap(java.util.HashMap) VdsDynamic(org.ovirt.engine.core.common.businessentities.VdsDynamic) ArrayList(java.util.ArrayList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 4 with OS

use of org.ovirt.engine.core.utils.OS in project ovirt-engine by oVirt.

the class HostMapper method mapOperatingSystem.

private static OperatingSystem mapOperatingSystem(VDS entity) {
    final OperatingSystem model = new OperatingSystem();
    if (StringUtils.isNotBlank(entity.getHostOs())) {
        OS hostOs = OS.fromPackageVersionString(entity.getHostOs());
        Version version = new Version();
        if (hostOs.getVersion().getMajor() != VERSION_NOT_SET) {
            version.setMajor(hostOs.getVersion().getMajor());
        }
        if (hostOs.getVersion().getMinor() != VERSION_NOT_SET) {
            version.setMinor(hostOs.getVersion().getMinor());
        }
        if (hostOs.getVersion().getBuild() != VERSION_NOT_SET) {
            version.setBuild(hostOs.getVersion().getBuild());
        }
        version.setFullVersion(hostOs.getFullVersion());
        model.setVersion(version);
        model.setType(hostOs.getName());
    }
    model.setCustomKernelCmdline(Objects.toString(entity.getCurrentKernelCmdline(), ""));
    model.setReportedKernelCmdline(entity.getKernelArgs());
    return model;
}
Also used : OperatingSystem(org.ovirt.engine.api.model.OperatingSystem) OS(org.ovirt.engine.core.utils.OS) Version(org.ovirt.engine.api.model.Version)

Example 5 with OS

use of org.ovirt.engine.core.utils.OS in project ovirt-engine by oVirt.

the class InClusterUpgradeValidator method isUpgradeDone.

public ValidationResult isUpgradeDone(Collection<VDS> hosts) {
    requireNonNull(hosts);
    final List<String> errors = new ArrayList<>();
    final Map<String, Set<Integer>> majorVersions = new LinkedHashMap<>();
    final Map<String, Set<VDS>> osToHostIdMap = new HashMap<>();
    for (final VDS host : hosts) {
        final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
        if (!hostOs.isValid()) {
            errors.addAll(toHostEngineMessage(host, EngineMessage.CLUSTER_UPGRADE_DETAIL_HOST_INVALID_OS));
        } else {
            putMajorVersion(majorVersions, hostOs);
            putHost(osToHostIdMap, host, hostOs);
        }
    }
    for (Map.Entry<String, Set<Integer>> entry : majorVersions.entrySet()) {
        if (entry.getValue().size() > 1) {
            final int newestMajorVersion = Collections.max(entry.getValue());
            for (VDS host : osToHostIdMap.get(entry.getKey())) {
                final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
                if (hostOs.getVersion().getMajor() < newestMajorVersion) {
                    errors.addAll(toHostEngineMessage(host, EngineMessage.CLUSTER_UPGRADE_DETAIL_HOST_RUNS_TOO_OLD_OS));
                }
            }
        }
    }
    if (errors.isEmpty()) {
        return ValidationResult.VALID;
    } else {
        return new ValidationResult(EngineMessage.CLUSTER_UPGRADE_NOT_FINISHED, errors);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) VDS(org.ovirt.engine.core.common.businessentities.VDS) OS(org.ovirt.engine.core.utils.OS) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

OS (org.ovirt.engine.core.utils.OS)5 ArrayList (java.util.ArrayList)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)4 HashMap (java.util.HashMap)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 VdsDynamic (org.ovirt.engine.core.common.businessentities.VdsDynamic)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 OperatingSystem (org.ovirt.engine.api.model.OperatingSystem)1 Version (org.ovirt.engine.api.model.Version)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 Version (org.ovirt.engine.core.compat.Version)1