Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: backend: GetoVirtISOsQuery use VersionUtils
......................................................................

backend: GetoVirtISOsQuery use VersionUtils

- Replace parseIsoFileVersion() by direct RpmVersion calls
- Use VersionUtils for isIsoVersionSupported()

Change-Id: I17cae0eed9e6109fa0c7efb460e02ab7073fe21d
Signed-off-by: Douglas Schilling Landgraf <dougsl...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetoVirtISOsQuery.java
1 file changed, 9 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/18435/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetoVirtISOsQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetoVirtISOsQuery.java
index cf6cdbd..440a5ed 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetoVirtISOsQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetoVirtISOsQuery.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSType;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.common.utils.VersionUtils;
 import org.ovirt.engine.core.common.queries.VdsIdParametersBase;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.RpmVersion;
@@ -84,10 +85,13 @@
                             continue;
                         }
 
-                        RpmVersion isoVersion = 
parseIsoFileVersion(isoFileName, majorVersionStr);
+                        RpmVersion isoVersion = new RpmVersion(isoFileName, 
getOvirtIsoPrefix(), true);
+                        isoVersion.setRpmName(isoFileName);
+
                         boolean shouldAdd = false;
 
-                        if (isoVersion != null && 
isIsoVersionSupported(isoVersion)) {
+                        String rpmParts [] = 
VersionUtils.splitRpmToParts(isoFileName);
+                        if (isoVersion != null && 
isIsoVersionSupported(rpmParts[1]) != -1) {
                             if (isoData.getVdsmCompatibilityVersion() != null) 
{
                                 shouldAdd = 
isIsoCompatibleForUpgradeByClusterVersion(isoData);
                             } else if (vdsOsVersion != null) {
@@ -140,21 +144,6 @@
             vdsOsVersion = VdsHandler.getOvirtHostOsVersion(vds);
         }
         return vdsOsVersion;
-    }
-
-    private RpmVersion parseIsoFileVersion(String isoFileName, String 
majorVersionStr) {
-        RpmVersion isoVersion = null;
-        try {
-            String rpmLike = isoFileName.replaceFirst(majorVersionStr + "-", 
majorVersionStr + ".");
-            isoVersion = new RpmVersion(rpmLike, getOvirtIsoPrefix(), true);
-            isoVersion.setRpmName(isoFileName);
-        } catch (RuntimeException e) {
-            log.errorFormat("Failed to extract RpmVersion for iso file {0} 
with major version {1} due to {2}",
-                    isoFileName,
-                    majorVersionStr,
-                    ExceptionUtils.getMessage(e));
-        }
-        return isoVersion;
     }
 
     private static String getIsoFileNameByVersion(List<String> listOfIsoFiles, 
String majorVersionStr, String releaseStr) {
@@ -244,9 +233,9 @@
         });
     }
 
-    private static boolean isIsoVersionSupported(Version isoVersion) {
-        Version supported = new Version(Config.<String> 
GetValue(ConfigValues.OvirtInitialSupportedIsoVersion));
-        return isoVersion.compareTo(supported) >= 0;
+    private static int isIsoVersionSupported(String isoVersion) {
+        String supported = Config.<String> 
GetValue(ConfigValues.OvirtInitialSupportedIsoVersion);
+        return VersionUtils.compareRpmPart(isoVersion, supported);
     }
 
     public VDS getVdsByVdsId(Guid vdsId) {


-- 
To view, visit http://gerrit.ovirt.org/18435
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I17cae0eed9e6109fa0c7efb460e02ab7073fe21d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsl...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to