use of org.ovirt.engine.core.compat.RpmVersion in project ovirt-engine by oVirt.
the class GetoVirtISOsQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
List<RpmVersion> availableISOsList = new ArrayList<>();
VDS vds = getVdsByVdsId(getParameters().getId());
if (vds == null) {
getQueryReturnValue().setReturnValue(availableISOsList);
return;
}
RpmVersion vdsOsVersion = VdsHandler.getOvirtHostOsVersion(vds);
String nodeOS = vds.getHostOs();
if (nodeOS == null) {
getQueryReturnValue().setReturnValue(new ArrayList<RpmVersion>());
return;
}
for (OVirtNodeInfo.Entry info : OVirtNodeInfo.getInstance().get()) {
log.debug("nodeOS [{}] | osPattern [{}] | minimumVersion [{}]", nodeOS, info.osPattern, info.minimumVersion);
Matcher matcher = info.osPattern.matcher(nodeOS);
if (matcher.matches() && info.path.isDirectory()) {
log.debug("Looking for list of ISOs in [{}], regex [{}]", info.path, info.isoPattern);
File[] files = info.path.listFiles();
if (files != null) {
for (File file : files) {
matcher = info.isoPattern.matcher(file.getName());
if (matcher.matches()) {
log.debug("ISO Found [{}]", file);
String version = matcher.group(1);
log.debug("ISO Version [{}]", version);
File versionFile = new File(info.path, String.format("version-%s.txt", version));
log.debug("versionFile [{}]", versionFile);
// Setting IsoData Class to get further [version] and [vdsm compatibility version] data
IsoData isoData = new IsoData();
isoData.setVersion(readIsoVersion(versionFile));
String isoVersionText = isoData.getVersion();
isoData.setVdsmCompitibilityVersion(readVdsmCompatibiltyVersion(versionFile.getAbsolutePath().replace(OVIRT_ISO_VERSION_PREFIX, OVIRT_ISO_VDSM_COMPATIBILITY_PREFIX)));
if (StringUtils.isEmpty(isoVersionText)) {
log.debug("Iso version file '{}' is empty.", versionFile.getAbsolutePath());
continue;
}
String[] versionParts = isoVersionText.split(",");
if (versionParts.length < 2) {
log.debug("Iso version file '{}' contains invalid content. Expected: <major-version>,<release> format.", versionFile.getAbsolutePath());
continue;
}
RpmVersion isoVersion = new RpmVersion(file.getName());
if (isoData.getVdsmCompatibilityVersion() != null && isIsoCompatibleForUpgradeByClusterVersion(isoData) || vdsOsVersion != null && VdsHandler.isIsoVersionCompatibleForUpgrade(vdsOsVersion, isoVersion)) {
availableISOsList.add(isoVersion);
}
}
}
}
}
}
Collections.sort(availableISOsList);
getQueryReturnValue().setReturnValue(availableISOsList);
updateUpdatesAvailableForHost(availableISOsList, vds);
}
use of org.ovirt.engine.core.compat.RpmVersion in project ovirt-engine by oVirt.
the class OvirtNodeUpgradeManager method checkForUpdates.
@Override
public HostUpgradeManagerResult checkForUpdates(VDS host) {
QueryReturnValue returnValue = backendInternal.runInternalQuery(QueryType.GetoVirtISOs, new IdQueryParameters(host.getId()));
List<RpmVersion> isos = returnValue.getReturnValue();
boolean updateAvailable = RpmVersionUtils.isUpdateAvailable(isos, host.getHostOs());
HostUpgradeManagerResult hostUpgradeManagerResult = new HostUpgradeManagerResult();
hostUpgradeManagerResult.setUpdatesAvailable(updateAvailable);
if (updateAvailable) {
AuditLogable auditLog = new AuditLogableImpl();
auditLog.setVdsName(host.getName());
auditLog.setVdsId(host.getId());
auditLog.setClusterName(host.getClusterName());
auditLog.setClusterId(host.getClusterId());
auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE);
}
return hostUpgradeManagerResult;
}
use of org.ovirt.engine.core.compat.RpmVersion 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;
}
use of org.ovirt.engine.core.compat.RpmVersion in project ovirt-engine by oVirt.
the class UpgradeOvirtNodeInternalCommand method validate.
@Override
protected boolean validate() {
if (getVdsId() == null || getVdsId().equals(Guid.Empty)) {
return failValidation(EngineMessage.VDS_INVALID_SERVER_ID);
}
if (getVds() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_HOST_NOT_EXIST);
}
if (isOvirtReInstallOrUpgrade()) {
// Block re-install on non-operational Host
if (getVds().getStatus() == VDSStatus.NonOperational) {
return failValidation(EngineMessage.VDS_CANNOT_INSTALL_STATUS_ILLEGAL);
}
File iso = resolveISO(getParameters().getoVirtIsoFile());
if (iso == null) {
return failValidation(EngineMessage.VDS_CANNOT_INSTALL_MISSING_IMAGE_FILE);
}
RpmVersion ovirtHostOsVersion = VdsHandler.getOvirtHostOsVersion(getVds());
if (!isISOCompatible(iso, ovirtHostOsVersion)) {
addValidationMessage(EngineMessage.VDS_CANNOT_UPGRADE_BETWEEN_MAJOR_VERSION);
addValidationMessageVariable("IsoVersion", ovirtHostOsVersion.getMajor());
return false;
}
_iso = iso;
} else {
return failValidation(EngineMessage.VDS_CANNOT_INSTALL_STATUS_ILLEGAL);
}
return true;
}
use of org.ovirt.engine.core.compat.RpmVersion in project ovirt-engine by oVirt.
the class VdsDynamicDaoTest method updateExistingEntity.
@Override
protected void updateExistingEntity() {
existingEntity.setGlusterVersion(new RpmVersion("glusterfs-3.4.0.34.1u2rhs-1.el6rhs"));
existingEntity.setLibrbdVersion(new RpmVersion("librbd1-0.80.9-1.fc21.x86_64_updated"));
}
Aggregations