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);
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations