On 04/16/2012 11:25 AM, Tomas Lestach wrote:
On Friday 13 of April 2012 17:28:05 Duncan Mac-Vicar P. wrote:
On 04/13/2012 02:30 PM, Tomas Lestach wrote:
A separate query for a single system would definitelly be more efficient.
Looking at what you pointed out in IRC: what happens if the errata is
applied on the client side. So I modified them to look at the package
install time instead:

For the system list:

    SELECT DISTINCT S.id, S.NAME,
         (SELECT 1
            FROM rhnServerFeaturesView SFV
           WHERE SFV.server_id = S.id
             AND SFV.label = 'ftr_system_grouping') AS selectable
    FROM rhnServer S,
         rhnErrata E,
         rhnServerInfo SI,
         rhnServerPackage SP,
         rhnPackage P,
         rhnActionErrataUpdate EA,
         rhnServerAction SA,
         rhnErrataPackage EP,
         rhnPackageName PN
   WHERE S.org_id = :org_id
     AND EXISTS (SELECT 1 FROM rhnUserServerPerms USP WHERE
USP.user_id=:user_id AND USP.server_id = S.id)
     AND SI.server_id = S.id
     AND SP.server_id = S.id
     AND P.evr_id = SP.evr_id
     AND P.name_id = SP.name_id
     AND EA.errata_id = E.id
     AND SA.action_id = EA.action_id AND SA.server_id = S.id
     AND EP.errata_id = E.id AND EP.package_id = P.id
     AND (to_timestamp(S.last_boot)<  SP.installtime)
     AND E.id IN (SELECT EK.errata_id FROM rhnErrataKeyword EK WHERE
EK.keyword = :keyword)
     AND PN.id = P.name_id
Duncan,
if an erratum package is installed on the client side using yum, you
definitelly won't have any entry in the
rhnServerAction/rhnAction/rhnActionErrataUpdate tables. I would omit them from
the select.
Basicly you need only (user) servers having any errata packages installed
after the latest reboot, where the appropriate erratum has the need_reboot
flag. (no 'Actions' in the sentence)

I'm not sure, why you join also the rhnPackageName, if you do not really use
it.
Sorry for wasting your time. I pasted directly from the pgadmin3 console.

Attached patch, rebased against master. It contains all suggestions and fixed some formatting issues not relevant to the patch. Additionally changed to_timestamp() to something that works in both databases.

Duncan


>From 34b8bea2ad8e64a4b9c5359d21ad6d0d480f054f Mon Sep 17 00:00:00 2001
From: Duncan Mac-Vicar P <dmacvi...@suse.de>
Date: Tue, 17 Apr 2012 15:31:06 +0200
Subject: [PATCH] Show systems that need reboot because of an errata.

---
 .../common/db/datasource/xml/System_queries.xml    |   55 ++++++++++++++++++++
 .../action/systems/RequiringRebootSetupAction.java |   37 +++++++++++++
 .../action/systems/sdc/SystemOverviewAction.java   |    5 ++
 .../frontend/strings/jsp/StringResource_en_US.xml  |   14 +++++
 .../frontend/strings/nav/StringResource_en_US.xml  |    6 ++
 .../redhat/rhn/manager/system/SystemManager.java   |   40 ++++++++++++++
 .../webapp/WEB-INF/nav/sitenav-authenticated.xml   |    1 +
 .../WEB-INF/pages/systems/requiringrebootlist.jsp  |   25 +++++++++
 .../webapp/WEB-INF/pages/systems/sdc/overview.jsp  |    5 ++-
 java/code/webapp/WEB-INF/struts-config.xml         |   10 ++++
 10 files changed, 197 insertions(+), 1 deletions(-)
 create mode 100644 java/code/src/com/redhat/rhn/frontend/action/systems/RequiringRebootSetupAction.java
 create mode 100644 java/code/webapp/WEB-INF/pages/systems/requiringrebootlist.jsp

diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
index cdb0cc5..64560e0 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
@@ -757,6 +757,61 @@ ORDER BY  UPPER(COALESCE(S.NAME, '(none)')), S.ID
   <elaborator name="is_virtual_host" />
 </mode>
 
+<query name="having_errata_with_keyword_applied_since_last_reboot_list" params="org_id, user_id, keyword">
+SELECT DISTINCT S.id, S.NAME,
+       (SELECT 1
+          FROM rhnServerFeaturesView SFV
+         WHERE SFV.server_id = S.id
+           AND SFV.label = 'ftr_system_grouping') AS selectable
+  FROM rhnServer S,
+       rhnErrata E,
+       rhnServerInfo SI,
+       rhnServerPackage SP,
+       rhnPackage P,
+       rhnErrataPackage EP
+ WHERE S.org_id = :org_id
+   AND EXISTS (SELECT 1 FROM rhnUserServerPerms USP WHERE USP.user_id=:user_id AND USP.server_id = S.id)
+   AND SI.server_id = S.id
+   AND SP.server_id = S.id
+   AND P.evr_id = SP.evr_id
+   AND P.name_id = SP.name_id
+   AND EP.errata_id = E.id AND EP.package_id = P.id
+   AND (to_date('1970-01-01', 'YYYY-MM-DD') + numtodsinterval(S.last_boot, 'second')) &lt; SP.installtime
+   AND E.id IN (SELECT EK.errata_id FROM rhnErrataKeyword EK WHERE EK.keyword = :keyword)
+</query>
+
+<mode name="having_errata_with_keyword_applied_since_last_reboot" class="com.redhat.rhn.frontend.dto.SystemOverview">
+  <query name="having_errata_with_keyword_applied_since_last_reboot_list"/>
+  <elaborator name="system_overview" />
+  <elaborator name="entitlements" />
+  <elaborator name="is_virtual_guest" />
+  <elaborator name="is_virtual_host" />
+</mode>
+
+<mode name="has_errata_with_keyword_applied_since_last_reboot">
+  <query params="org_id, user_id, keyword, sid">
+  SELECT EXISTS (
+	SELECT 1
+	FROM rhnServer S,
+	  rhnErrata E,
+	  rhnServerInfo SI,
+	  rhnServerPackage SP,
+	  rhnPackage P,
+	  rhnErrataPackage EP
+	WHERE S.org_id = :org_id
+	  AND S.id = :sid
+	  AND EXISTS (SELECT 1 FROM rhnUserServerPerms USP WHERE USP.user_id=:user_id AND USP.server_id = S.id)
+	  AND SI.server_id = S.id
+	  AND SP.server_id = S.id
+	  AND P.evr_id = SP.evr_id
+	  AND P.name_id = SP.name_id
+	  AND EP.errata_id = E.id AND EP.package_id = P.id
+	  AND (to_date('1970-01-01', 'YYYY-MM-DD') + numtodsinterval(S.last_boot, 'second')) &lt; SP.installtime
+	  AND E.id IN (SELECT EK.errata_id FROM rhnErrataKeyword EK WHERE EK.keyword = :keyword)
+    )
+    </query>
+</mode>
+
 <mode name="inactive" class="com.redhat.rhn.frontend.dto.SystemOverview">
   <query params="org_id, user_id, checkin_threshold">
 SELECT S.id, S.NAME,
diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/RequiringRebootSetupAction.java b/java/code/src/com/redhat/rhn/frontend/action/systems/RequiringRebootSetupAction.java
new file mode 100644
index 0000000..e33dce7
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/action/systems/RequiringRebootSetupAction.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2012 Novell
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.frontend.action.systems;
+
+import org.apache.struts.action.ActionForm;
+
+import com.redhat.rhn.common.db.datasource.DataResult;
+import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.frontend.dto.SystemOverview;
+import com.redhat.rhn.frontend.listview.PageControl;
+import com.redhat.rhn.manager.system.SystemManager;
+
+/**
+ * InactiveSetupAction
+ * @version $Rev$
+ */
+public class RequiringRebootSetupAction extends BaseSystemsAction {
+
+    @Override
+    protected DataResult<SystemOverview> getDataResult(User user,
+            PageControl pc, ActionForm formIn) {
+        return SystemManager.requiringRebootList(user, null);
+    }
+
+}
diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemOverviewAction.java b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemOverviewAction.java
index fc6ce5b..f82ab20 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemOverviewAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemOverviewAction.java
@@ -59,6 +59,7 @@ public class SystemOverviewAction extends RhnAction {
                                                        .RECEIVE_NOTIFICATIONS};
 
     /** {@inheritDoc} */
+    @Override
     public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response) {
         RequestContext rctx = new RequestContext(request);
@@ -106,6 +107,9 @@ public class SystemOverviewAction extends RhnAction {
         boolean hasUpdates =
             criticalErrataCount + nonCriticalErrataCount + upgradablePackagesCount > 0;
 
+        // Reboot needed after certain types of updates
+        boolean rebootRequired = SystemManager.requiresReboot(user, sid);
+
         // Monitoring
         processRequestForMonitoring(user, s, request);
 
@@ -118,6 +122,7 @@ public class SystemOverviewAction extends RhnAction {
 
         SdcHelper.ssmCheck(request, sid, user);
 
+        request.setAttribute("rebootRequired", Boolean.valueOf(rebootRequired));
         request.setAttribute("unentitled", Boolean.valueOf(s.getEntitlements().isEmpty()));
         request.setAttribute("systemInactive", Boolean.valueOf(s.isInactive()));
         request.setAttribute("documentation", ConfigDefaults.get().isDocAvailable());
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
index afe8387..6ed1aac 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
@@ -5058,6 +5058,13 @@ value for this entitlement, excluding the default organization's consumption.</s
         </context-group>
       </trans-unit>
 
+      <trans-unit id="requiringrebootlist.jsp.header">
+        <source>Systems requiring reboot</source>
+        <context-group name="ctx">
+          <context context-type="sourcefile">/rhn/systems/RequiringReboot</context>
+          <context context-type="sourcefile">/rhn/systems/YourRhn.do</context>
+        </context-group>
+      </trans-unit>
 
       <trans-unit id="inactivelist.jsp.header">
 <source>Inactive Systems</source>
@@ -17559,6 +17566,13 @@ The Tree Path, Kickstart RPM, Base Channel, and Installer Generation should alwa
         	</context-group>
 	     </trans-unit>
 
+	     <trans-unit id="sdc.details.overview.requires_reboot">
+	        <source>The system requires a reboot</source>
+		<context-group name="ctx">
+                  <context context-type="sourcefile">/systems/details/Overview.do</context>
+                </context-group>
+             </trans-unit>
+
 	     <trans-unit id="sdc.details.overview.inactive1">
 		<source>&lt;strong&gt;System not checking in with @@PRODUCT_NAME@@&lt;/strong&gt;</source>
 		<context-group name="ctx">
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/nav/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/nav/StringResource_en_US.xml
index 97b6522..5400455 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/nav/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/nav/StringResource_en_US.xml
@@ -111,6 +111,12 @@ http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd";
           <context context-type="sourcefile">Systems Navigation Menu</context>
         </context-group>
       </trans-unit>
+      <trans-unit id="Requiring Reboot">
+        <source>Requiring Reboot</source>
+        <context-group name="ctx">
+          <context context-type="sourcefile">Systems Navigation Menu</context>
+        </context-group>
+      </trans-unit>
 
       <trans-unit id="duplicate.systems.nav.ips">
 <source>Duplicate IP Address</source>
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 23be330..78240dc 100644
--- a/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/SystemManager.java
@@ -196,6 +196,46 @@ public class SystemManager extends BaseManager {
         return m.execute(params);
     }
 
+    /**
+     * @param user
+     *            Currently logged in user.
+     * @param sid
+     *            System id
+     * @return true if the system requires a reboot i.e: because kernel updates.
+     */
+    public static boolean requiresReboot(User user, Long sid) {
+        SelectMode m = ModeFactory.getMode("System_queries",
+                "has_errata_with_keyword_applied_since_last_reboot");
+        Map params = new HashMap();
+        params.put("user_id", user.getId());
+        params.put("org_id", user.getOrg().getId());
+        params.put("sid", sid);
+        params.put("keyword", "reboot_suggested");
+        DataResult dr = m.execute(params);
+        return !dr.isEmpty();
+    }
+
+    /**
+     * Returns list of systems requiring a reboot i.e: because kernel updates,
+     * visible to user, sorted by name.
+     *
+     * @param user
+     *            Currently logged in user.
+     * @param pc
+     *            PageControl
+     * @return list of SystemOverviews.
+     */
+    public static DataResult<SystemOverview> requiringRebootList(User user,
+            PageControl pc) {
+        SelectMode m = ModeFactory.getMode("System_queries",
+                "having_errata_with_keyword_applied_since_last_reboot");
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("org_id", user.getOrg().getId());
+        params.put("user_id", user.getId());
+        params.put("keyword", "reboot_suggested");
+        Map<String, Object> elabParams = new HashMap<String, Object>();
+        return makeDataResult(params, elabParams, pc, m);
+    }
 
     /**
      * Gets the latest upgradable packages for a system
diff --git a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
index a79d842..c153626 100644
--- a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
+++ b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
@@ -37,6 +37,7 @@
       <rhn-tab name="All" url="/rhn/systems/SystemList.do"/>
       <rhn-tab name="Virtual Systems" url="/rhn/systems/VirtualSystemsList.do"/>
       <rhn-tab name="Out of Date" url="/rhn/systems/OutOfDate.do"/>
+      <rhn-tab name="Requiring Reboot" url="/rhn/systems/RequiringReboot.do"/>
       <rhn-tab name="Unentitled" url="/rhn/systems/Unentitled.do"/>
       <rhn-tab name="Ungrouped" url="/rhn/systems/Ungrouped.do" acl="org_entitlement(sw_mgr_enterprise); user_role(org_admin)"/>
       <rhn-tab name="Inactive" url="/rhn/systems/Inactive.do"/>
diff --git a/java/code/webapp/WEB-INF/pages/systems/requiringrebootlist.jsp b/java/code/webapp/WEB-INF/pages/systems/requiringrebootlist.jsp
new file mode 100644
index 0000000..d5cb310
--- /dev/null
+++ b/java/code/webapp/WEB-INF/pages/systems/requiringrebootlist.jsp
@@ -0,0 +1,25 @@
+<%@ taglib uri="http://rhn.redhat.com/rhn"; prefix="rhn" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
+<%@ taglib uri="http://struts.apache.org/tags-html"; prefix="html" %>
+<%@ taglib uri="http://struts.apache.org/tags-bean"; prefix="bean" %>
+<%@ taglib uri="http://rhn.redhat.com/tags/list"; prefix="rl" %>
+
+<html:xhtml/>
+<html>
+<head>
+    <meta name="page-decorator" content="none" />
+</head>
+<body>
+<rhn:toolbar base="h1" img="/img/rhn-icon-system.gif" imgAlt="system.common.systemAlt"
+ helpUrl="/rhn/help/reference/en-US/s1-sm-systems.jsp#s3-sm-system-list-inact">
+  <bean:message key="requiringrebootlist.jsp.header"/>
+</rhn:toolbar>
+
+<rl:listset name="systemListSet" legend="system">
+    <rhn:csrf />
+    <rhn:submitted />
+    <%@ include file="/WEB-INF/pages/common/fragments/systems/system_listdisplay.jspf" %>
+</rl:listset>
+
+</body>
+</html>
diff --git a/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp b/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
index 40d220b..d69645b 100644
--- a/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
+++ b/java/code/webapp/WEB-INF/pages/systems/sdc/overview.jsp
@@ -22,7 +22,10 @@
             <bean:message key="sdc.details.overview.inactive2" arg0="/rhn/help/reference/en-US/s1-sm-systems.jsp#s2-sm-system-list"/>
           </c:if>
         </c:when>
-
+        <c:when test="${rebootRequired}">
+          <img src="/img/restart.png"/><bean:message key="sdc.details.overview.requires_reboot"/>
+          <bean:message key="sdc.details.overview.schedulereboot" arg0="/network/systems/details/reboot_confirm.pxt?sid=${system.id}"/>
+        </c:when>
         <c:when test="${hasUpdates}">
             <c:choose>
                 <c:when test="${criticalErrataCount > 0}">
diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml
index 591c766..88dc052 100644
--- a/java/code/webapp/WEB-INF/struts-config.xml
+++ b/java/code/webapp/WEB-INF/struts-config.xml
@@ -2707,6 +2707,16 @@
                  path="/WEB-INF/pages/systems/inactivelist.jsp"/>
     </action>
 
+    <action path="/systems/RequiringReboot"
+        scope="request"
+        input="/WEB-INF/pages/systems/requiringreboot.jsp"
+        type="com.redhat.rhn.frontend.action.systems.RequiringRebootSetupAction"
+        className="com.redhat.rhn.frontend.struts.RhnActionMapping">
+        <set-property property="postRequiredIfSubmitted" value="true" />
+        <forward name="default"
+                 path="/WEB-INF/pages/systems/requiringrebootlist.jsp"/>
+    </action>
+
     <action path="/systems/Registered"
         scope="request"
         name="recentlyRegisteredSystemsForm"
-- 
1.7.7

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

Reply via email to