Search in sources :

Example 1 with RpmVersion

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);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) RpmVersion(org.ovirt.engine.core.compat.RpmVersion) File(java.io.File)

Example 2 with RpmVersion

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;
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Example 3 with RpmVersion

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;
}
Also used : RpmVersion(org.ovirt.engine.core.compat.RpmVersion) Version(org.ovirt.engine.core.compat.Version) RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Example 4 with RpmVersion

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;
}
Also used : File(java.io.File) RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Example 5 with RpmVersion

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"));
}
Also used : RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Aggregations

RpmVersion (org.ovirt.engine.core.compat.RpmVersion)10 VDS (org.ovirt.engine.core.common.businessentities.VDS)4 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 Test (org.junit.Test)2 Host (org.ovirt.engine.api.model.Host)2 Version (org.ovirt.engine.core.compat.Version)2 RadioButton (com.google.gwt.user.client.ui.RadioButton)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 HostUpgradeManagerResult (org.ovirt.engine.core.common.HostUpgradeManagerResult)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)1 AuditLogableImpl (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)1 EntityModelCheckBoxEditor (org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor)1 StringEntityModelTextAreaLabelEditor (org.ovirt.engine.ui.common.widget.editor.generic.StringEntityModelTextAreaLabelEditor)1 NullSafeRenderer (org.ovirt.engine.ui.common.widget.renderer.NullSafeRenderer)1