modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/ReenableAlertDefinitionAction.java | 80 ++++++++++
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/subsystem/SubsystemAlertDefinitionUIBean.java | 4
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml | 10 -
modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/AlertDefinitionActive.jsp | 10 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java | 13 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java | 19 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java | 8 -
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsBackingBean.java | 12 +
9 files changed, 144 insertions(+), 14 deletions(-)
New commits:
commit 2b28eb953aad5656ce7c7ecf6eaf029e767b27a9
Merge: 40bfa51... 7b5ccc1...
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Feb 24 13:48:36 2010 +0100
Merge branch 'master' into alertPlugin
commit 40bfa515fa1c5dcc785e80597505f43866dd399c
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Feb 24 13:46:00 2010 +0100
Provide an internal cleanup method that is called when the notification is deleted. This way, the backing bean can do some housekeeping if needed.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
index dfa59f3..0896c6e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
@@ -41,7 +41,6 @@ import org.rhq.core.domain.alert.notification.AlertNotification;
import org.rhq.core.domain.alert.notification.NotificationTemplate;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.authz.Role;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.plugin.PluginKey;
@@ -154,6 +153,18 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
}
}
+ // Before we delete the notification, check if has a custom backing bean
+ // and give it the possibility to clean up
+ for (AlertNotification notification : toBeRemoved) {
+ CustomAlertSenderBackingBean bb = getBackingBeanForSender(notification.getSenderName(),notification.getId());
+ try {
+ bb.internalCleanup();
+ }
+ catch (Throwable t ) {
+ LOG.error("removeNotifications, calling backingBean.internalCleanup() resulted in " + t.getMessage());
+ }
+ }
+
alertDefinition.getAlertNotifications().removeAll(toBeRemoved);
postProcessAlertDefinition(alertDefinition);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java
index 5b39eae..e4b2d20 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java
@@ -44,7 +44,7 @@ public class CustomAlertSenderBackingBean {
* This method is called when the alert notification that uses this backing bean
* is removed, so that the backing bean can do some cleanup work
*/
- protected void cleanup() {}
+ public void internalCleanup() {}
/**
* Persist the passed configuration object. This can be a new object or one
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsBackingBean.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsBackingBean.java
index 2a3b635..98fa0e9 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsBackingBean.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsBackingBean.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.server.plugins.alertOperations;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -71,6 +72,17 @@ public class OperationsBackingBean extends CustomAlertSenderBackingBean {
log.info("init");
}
+ @Override
+ public void internalCleanup() {
+ PropertySimple parameterConfigProp = alertParameters.getSimple(OperationsSender.PARAMETERS_CONFIG);
+ if (parameterConfigProp!=null) {
+ Integer paramId = parameterConfigProp.getIntegerValue();
+ if (paramId!=null) {
+ ConfigurationManagerLocal cmgr = LookupUtil.getConfigurationManager();
+ cmgr.deleteConfigurations(Arrays.asList(paramId));
+ }
+ }
+ }
public String selectResource() {
commit 780776f1eaf8067d86fa2ca45354fc5686f9d9c5
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Feb 24 13:33:37 2010 +0100
Add a link to re-enable the definition on the detail page. Alternate solution to BZ 535889
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/ReenableAlertDefinitionAction.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/ReenableAlertDefinitionAction.java
new file mode 100644
index 0000000..265db09
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/ReenableAlertDefinitionAction.java
@@ -0,0 +1,80 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.enterprise.gui.legacy.action.BaseAction;
+import org.rhq.enterprise.gui.legacy.util.RequestUtils;
+import org.rhq.enterprise.server.alert.AlertDefinitionManagerLocal;
+import org.rhq.enterprise.server.alert.AlertManagerLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Struts action to re-enable an alert definition from the
+ * AlertdefinitionActive.jsp tile, that gets included from
+ * ViewAlertProperties.jsp
+ * @author Heiko W. Rupp
+ */
+public class ReenableAlertDefinitionAction extends BaseAction {
+
+ private final Log log = LogFactory.getLog(ReenableAlertDefinitionAction.class);
+
+ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ Subject subject = RequestUtils.getSubject(request);
+ AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
+
+ Map<String,Object> params = new HashMap<String,Object>(4);
+ // pass-through the alertId and resource id
+ Integer alertId = new Integer(request.getParameter("a"));
+ request.setAttribute("a", alertId);
+ params.put("a",alertId);
+
+ Integer alertDefId = new Integer(request.getParameter("ad"));
+ request.setAttribute("ad", alertDefId);
+ params.put("ad",alertDefId);
+
+ Integer resourceId = new Integer(request.getParameter("id"));
+ request.setAttribute("id",resourceId);
+ params.put("id",resourceId);
+
+ String mode = request.getParameter("mode");
+ request.setAttribute("mode",mode);
+ params.put("mode",mode);
+
+ alertDefinitionManager.enableAlertDefinitions(subject, new Integer[]{alertDefId});
+
+ log.debug("Reenabled Alert definition with id " + alertId + " and user " + subject.getName());
+
+ return returnSuccess(request,mapping,params);
+ }
+}
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml
index a4c1b31..76321ce 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml
@@ -2563,9 +2563,13 @@
scope="request"
type="org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts.AckAlertAction">
<set-property property="title" value="View+Alert"/>
- <exception key="exception.AlertNotFoundException"
- type="org.rhq.enterprise.server.legacy.events.AlertNotFoundException"
- path="/common/GenericError.jsp"/>
+ <forward name="success" path="/alerts/Alerts.do" redirect="true" />
+ </action>
+
+ <action path="/alerts/RenableAlertDefinition"
+ scope="request"
+ type="org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts.ReenableAlertDefinitionAction">
+ <set-property property="title" value="View+Alert"/>
<forward name="success" path="/alerts/Alerts.do" redirect="true" />
</action>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/AlertDefinitionActive.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/AlertDefinitionActive.jsp
index 6affcc2..ed6b4fa 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/AlertDefinitionActive.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/AlertDefinitionActive.jsp
@@ -14,10 +14,14 @@
<fmt:message key="alert.config.props.PB.ActiveYes"/>
</td>
</c:when>
- <c:otherwise>
+ <c:otherwise>
<td width="30%" class="BlockContent">
- <html:img page="/images/icon_available_red.gif" width="12" height="12" border="0"/>
- <fmt:message key="alert.config.props.PB.ActiveNo"/>
+ <html:img page="/images/icon_available_red.gif" width="12" height="12" border="0"/>
+ <fmt:message key="alert.config.props.PB.ActiveNo"/>
+
+ <c:if test="${not alertDef.deleted}">
+ <a href="/alerts/RenableAlertDefinition.do?id=${Resource.id}&a=${alert.id}&mode=${param.mode}&ad=${alertDef.id}">click to re-enable</a>
+ </c:if>
</td>
</c:otherwise>
</c:choose>
commit 7b5ccc130607114a539bae8a97e7b097e7edc1ba
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Feb 24 13:27:56 2010 +0100
BZ 567925 - a follow up to my previous commit should finally fix the issue.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
index 54cebf6..b0db81c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
@@ -2204,7 +2204,10 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
for (T r : results) {
MutableDisambiguationReport<T> value = new MutableDisambiguationReport<T>();
value.original = r;
- reportByResourceId.put(extractor.extract(r), value);
+ int resourceId = extractor.extract(r);
+ if (resourceId > 0) {
+ reportByResourceId.put(resourceId, value);
+ }
}
//k, now let's construct the JPQL query to get the parents and type infos...
@@ -2247,10 +2250,18 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
//now we have all the information to create the result.
//first create the immutable reports.
- List<DisambiguationReport<T>> resolution = new ArrayList<DisambiguationReport<T>>(reportByResourceId.size());
+ List<DisambiguationReport<T>> resolution = new ArrayList<DisambiguationReport<T>>(results.size());
- for (Map.Entry<Integer, MutableDisambiguationReport<T>> entry : reportByResourceId.entrySet()) {
- resolution.add(entry.getValue().getReport());
+ for(T result : results) {
+ int resourceId = extractor.extract(result);
+ if (resourceId > 0) {
+ MutableDisambiguationReport<T> report = reportByResourceId.get(resourceId);
+ resolution.add(report.getReport());
+ } else {
+ //this result doesn't correspond to any resource, need to handle it specially
+ DisambiguationReport<T> report = new DisambiguationReport<T>(result, Collections.<ResourceParentFlyweight>emptyList(), null, null);
+ resolution.add(report);
+ }
}
return new ResourceNamesDisambiguationResult<T>(resolution, typeResolutionNeeded, parentResolutionNeeded,
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
index 2c99c9d..6db6155 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
@@ -36,6 +36,7 @@ import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceError;
import org.rhq.core.domain.resource.ResourceErrorType;
import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.domain.resource.composite.DisambiguationReport;
import org.rhq.core.domain.resource.composite.RecentlyAddedResourceComposite;
import org.rhq.core.domain.resource.composite.ResourceAvailabilitySummary;
import org.rhq.core.domain.resource.composite.ResourceComposite;
@@ -449,7 +450,12 @@ public interface ResourceManagerLocal {
* The disambiguation result contains information on what types of information are needed to make the resources
* in the original result unambiguous and contains the decorated original data in the same order as the
* supplied result list.
- *
+ * <p>
+ * The objects in results do not necessarily need to correspond to a resource. In case of such objects,
+ * the resourceIdExtractor should return 0. In the resulting report such objects will still be wrapped
+ * in a {@link DisambiguationReport} but the parent list will be empty and resource type and plugin name will
+ * be null.
+ *
* @see ResourceNamesDisambiguationResult
*
* @param <T> the type of the result elements
commit ee6254859736c4b3447259517988e6ffe57e4cc8
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Feb 24 12:33:52 2010 +0100
Fixing an NPE on alert definitions subsystem page caused by alert defs without an attached resource.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/subsystem/SubsystemAlertDefinitionUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/subsystem/SubsystemAlertDefinitionUIBean.java
index 4d656b5..5831f3e 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/subsystem/SubsystemAlertDefinitionUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/subsystem/SubsystemAlertDefinitionUIBean.java
@@ -34,6 +34,7 @@ import org.rhq.core.domain.alert.AlertCondition;
import org.rhq.core.domain.alert.AlertConditionCategory;
import org.rhq.core.domain.alert.composite.AlertDefinitionComposite;
import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.gui.util.FacesContextUtility;
@@ -74,7 +75,8 @@ public class SubsystemAlertDefinitionUIBean extends SubsystemView {
private IntExtractor<AlertDefinitionComposite> RESOURCE_ID_EXTRACTOR = new IntExtractor<AlertDefinitionComposite>() {
public int extract(AlertDefinitionComposite object) {
- return object.getAlertDefinition().getResource().getId();
+ Resource resource = object.getAlertDefinition().getResource();
+ return resource == null ? 0 : resource.getId();
}
};