On 11/08/2012 12:18 PM, Johannes Renner wrote:
> On 11/05/2012 12:03 PM, Tomas Lestach wrote:
>> ... 
>> If there's a bug in the API call, we of course fix it.
>> But we try to keep the current API interface as is. Spacewalk users have 
>> their 
>> scripts using our API calls and we do not want to break the scripts by 
>> renaming/deleting existing API calls. (Introducing of new sensefull APIs is 
>> always good. :)
>>
>> So, it is important that the API behaves according to its name. It the name 
>> and behavior do not match, we fix the behavior according to the name and can 
>> introduce a new API in case the behavior of the original API was helpfull.
>>
>> However, internal naming has lower priority, because the users do not come 
>> into contact with it, so it cannot be confusing for them. (But we of course 
>> try to keep the naming sensefull as well.)
> 
> Ok, I might come up with a patch these days, fixing the existing API call so
> it behaves like its name is suggesting + maybe add a new call to provide the
> previous behavior in addition to that.
> 
> Thanks for the explanations,
> Johannes

Ok, here we go: The first patch should fix the query for the existing API call
so that actually only the very latest versions of packages will be returned,
as the name of the function suggests. (Note that the query might have been
working for you correctly before, but only in case all of packages and updates
are provided through one single channel, I guess).

Further, the query is internally renamed like this (in Package_queries.xml):

"system_latest_all_available_packages" -> "system_latest_available_packages"

The second patch adds a new API call to list all versions and releases of
packages that can be installed to a given system:

system.list_all_installable_packages(key, sid)

Unfortunately the previous query could not be reused, since it didn't actually
return all of the versions and releases of a package (as noted above). It rather
returned only the max EVR version of each package in every channel the system
is subscribed to. This might have lead to correct behavior for list_latest, but
only in case all packages are provided through _one_ single channel. So the
second patch also contains a new query to handle the list_all_... case.

Regards,
Johannes

-- 
SUSE LINUX Products GmbH, HRB 16746 (AG Nürnberg)
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
>From 84295bbb50bf32bfbec425d3aca516eeb8276d85 Mon Sep 17 00:00:00 2001
From: Johannes Renner <jren...@suse.de>
Date: Wed, 21 Nov 2012 18:21:20 +0100
Subject: [PATCH] Fix query for API call system.listLatestInstallablePackages

---
 .../common/db/datasource/xml/Package_queries.xml   |   33 +++++++++++---------
 .../redhat/rhn/manager/system/SystemManager.java   |    2 +-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
index 44bc39d..38e7f4b 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
@@ -6,20 +6,19 @@
   </query>
 </callable-mode>
 
-<mode name="system_latest_all_available_packages">
+<mode name="system_latest_available_packages">
   <query params="sid">
 SELECT
         pn.name AS name,
-        full_list.id AS id,
+        pkg.id AS id,
         NVL((full_list.evr).version, ' ') AS version,
         NVL((full_list.evr).release, ' ') AS release,
         NVL((full_list.evr).epoch, ' ') AS epoch,
         NVL(full_list.arch_label, ' ') AS arch_label
   FROM  (
          SELECT  p.name_id name_id,
-                 p.id,
-                 p.evr_id,
                  max(pe.evr) evr,
+                 pa.id as arch_id,
                  pa.label as arch_label
            FROM  rhnPackageArch PA, rhnPackageEVR PE, rhnPackage P,
                  rhnChannelNewestPackage CNP, rhnServerChannel SC
@@ -28,17 +27,23 @@ SELECT
             AND  cnp.package_id = p.id
             AND  p.evr_id = pe.id
             AND  p.package_arch_id = pa.id
-       GROUP BY  p.name_id, p.id, p.evr_id, pa.label
+       GROUP BY  p.name_id, pa.label, pa.id
        ) full_list,
-       rhnPackageName pn
- WHERE  full_list.name_id = pn.id
-   AND  NOT EXISTS (SELECT 1
-                      FROM rhnServerPackage SP, rhnPackageEVR PE2
-                     WHERE SP.server_id = :sid
-                       AND SP.name_id = full_list.name_id
-                       AND SP.evr_id = PE2.id
-                       AND PE2.evr &gt;= full_list.evr)
-ORDER BY  UPPER(pn.name), full_list.evr
+       rhnPackage pkg
+       join rhnPackageName pn on pkg.name_id = pn.id
+       join rhnPackageEVR pevr on pkg.evr_id = pevr.id
+       join rhnChannelPackage CP on CP.package_id = pkg.id
+       join rhnServerChannel SC on SC.channel_id = CP.channel_id
+ WHERE full_list.name_id = pkg.name_id
+   AND full_list.evr = pevr.evr
+   AND full_list.arch_id = pkg.package_arch_id
+   AND SC.server_id = :sid
+   AND NOT EXISTS (SELECT 1
+                     FROM rhnServerPackage SP
+                    WHERE SP.server_id = :sid
+                      AND SP.name_id = full_list.name_id
+                      AND (SP.package_arch_id = full_list.arch_id or SP.package_arch_id is null))
+order by upper(pn.name)
   </query>
 </mode>
 
diff --git a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
index 182a22c..2ae0178 100644
--- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
@@ -289,7 +289,7 @@ public class SystemManager extends BaseManager {
      */
     public static DataResult latestInstallablePackages(Long sid) {
         SelectMode m = ModeFactory.getMode("Package_queries",
-                "system_latest_all_available_packages",
+                "system_latest_available_packages",
                 Map.class);
         Map params = new HashMap();
         params.put("sid", sid);
-- 
1.7.10.4

>From 03a77e91bd774d3c798fa876abb4708e047a9859 Mon Sep 17 00:00:00 2001
From: Johannes Renner <jren...@suse.de>
Date: Thu, 22 Nov 2012 14:50:57 +0100
Subject: [PATCH] Implement new API call system.listAllInstallablePackages

---
 .../common/db/datasource/xml/Package_queries.xml   |   24 ++++++++++++++++
 .../rhn/frontend/xmlrpc/system/SystemHandler.java  |   29 ++++++++++++++++++++
 .../redhat/rhn/manager/system/SystemManager.java   |   14 ++++++++++
 3 files changed, 67 insertions(+)

diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
index 38e7f4b..48c11cc 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
@@ -6,6 +6,30 @@
   </query>
 </callable-mode>
 
+<mode name="system_all_available_packages">
+  <query params="sid">
+SELECT PKG.id AS id,
+       PN.name AS name,
+       NVL((PEVR.evr).version, ' ') AS version,
+       NVL((PEVR.evr).release, ' ') AS release,
+       NVL((PEVR.evr).epoch, ' ') AS epoch,
+       NVL(PA.label, ' ') AS arch_label
+  FROM rhnPackage PKG
+       join rhnPackageName PN on PKG.name_id = PN.id
+       join rhnPackageEVR PEVR on PKG.evr_id = PEVR.id
+       join rhnPackageArch PA on PKG.package_arch_id = PA.id
+       join rhnChannelPackage CP on CP.package_id = PKG.id
+       join rhnServerChannel SC on SC.channel_id = CP.channel_id
+ WHERE SC.server_id = :sid
+   AND NOT EXISTS (SELECT 1
+                     FROM rhnServerPackage SP
+                    WHERE SP.server_id = :sid
+                      AND SP.name_id = PN.id
+                      AND (SP.package_arch_id = PA.id or SP.package_arch_id is null))
+ORDER BY UPPER(PN.name), PEVR.evr
+  </query>
+</mode>
+
 <mode name="system_latest_available_packages">
   <query params="sid">
 SELECT
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
index b8a33ab..156254f 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
@@ -1015,6 +1015,35 @@ public class SystemHandler extends BaseHandler {
     }
 
     /**
+     * Get the list of all installable packages for a given system.
+     * @param sessionKey The sessionKey containing the logged in user
+     * @param sid The id for the system in question
+     * @return Returns an array of maps representing the latest installable packages
+     * @throws FaultException A FaultException is thrown if the server corresponding to
+     * sid cannot be found.
+     *
+     * @xmlrpc.doc Get the list of all installable packages for a given system.
+     * @xmlrpc.param #param("string", "sessionKey")
+     * @xmlrpc.param #param("int", "serverId")
+     * @xmlrpc.returntype
+     *      #struct("package")
+     *          #prop("string", "name")
+     *          #prop("string", "version")
+     *          #prop("string", "release")
+     *          #prop("string", "epoch")
+     *          #prop("int", "id")
+     *          #prop("string", "arch_label")
+     *      #struct_end()
+     */
+    public Object[] listAllInstallablePackages(String sessionKey, Integer sid)
+            throws FaultException {
+        User loggedInUser = getLoggedInUser(sessionKey);
+        Server server = lookupServer(loggedInUser, sid);
+        DataResult dr = SystemManager.allInstallablePackages(server.getId());
+        return dr.toArray();
+    }
+
+    /**
      * Get the list of latest installable packages for a given system.
      * @param sessionKey The sessionKey containing the logged in user
      * @param sid The id for the system in question
diff --git a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
index 2ae0178..a7a5de7 100644
--- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
@@ -283,6 +283,20 @@ public class SystemManager extends BaseManager {
     }
 
     /**
+     * Get all installable packages for a given system.
+     * @param sid The id for the system we want packages for
+     * @return Return a list of all installable packages for a system.
+     */
+    public static DataResult allInstallablePackages(Long sid) {
+        SelectMode m = ModeFactory.getMode("Package_queries",
+                "system_all_available_packages",
+                Map.class);
+        Map params = new HashMap();
+        params.put("sid", sid);
+        return m.execute(params);
+    }
+
+    /**
      * Gets the latest installable packages for a system
      * @param sid The id for the system we want packages for
      * @return Returns a list of latest installable packages for a system.
-- 
1.7.10.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to