summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java6
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java2
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GroupAlertDefinitionsView.java6
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java6
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SingleAlertDefinitionView.java12
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/TemplateAlertDefinitionsView.java6
-rw-r--r--modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertDefinitionGWTServiceImpl.java2
-rw-r--r--modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/config/NewDefinitionAction.java2
-rw-r--r--modules/enterprise/server/itests/pom.xml34
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginService.java148
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginServiceMBean.java (renamed from modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginServiceMBean.java)12
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java716
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSender.java107
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSenderPluginService.java67
-rw-r--r--modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginService.java103
-rw-r--r--modules/enterprise/server/itests/src/test/resources/log4j.xml4
-rw-r--r--modules/enterprise/server/itests/src/test/resources/test-alert-sender-serverplugin.xml23
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java76
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerLocal.java42
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java18
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java6
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertTemplateManagerBean.java18
-rw-r--r--modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/GroupAlertDefinitionManagerBean.java16
-rw-r--r--modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertConditionTest.java10
-rw-r--r--modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java2
25 files changed, 1297 insertions, 147 deletions
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
index e75263d..a11b88e 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
@@ -56,6 +56,7 @@ public class AlertDefinitionCriteria extends Criteria {
private String filterAlertTemplateResourceTypeName; // requires overrides
private List<Integer> filterResourceIds; // requires overrides
private List<Integer> filterResourceGroupIds; // requires overrides
+ private Integer filterGroupAlertDefinitionId;
private Boolean filterEnabled;
private Boolean filterDeleted = false; // find enabled definitions by default
private NonBindingOverrideFilter filterResourceOnly; // requires overrides - finds only those associated with a resource
@@ -80,6 +81,7 @@ public class AlertDefinitionCriteria extends Criteria {
filterOverrides.put("alertTemplateResourceTypeName", "resourceType.name like ?");
filterOverrides.put("resourceIds", "resource.id IN ( ? )");
filterOverrides.put("resourceGroupIds", "resourceGroup.id IN ( ? )");
+ filterOverrides.put("groupAlertDefinitionId", "groupAlertDefinition.id = ?");
filterOverrides.put("resourceOnly", "resource IS NOT NULL");
filterOverrides.put("notificationSenderNames", "id IN ("
+ "SELECT notif.alertDefinition.id FROM AlertNotification notif " + "WHERE notif.senderName IN ( ? ))");
@@ -158,6 +160,10 @@ public class AlertDefinitionCriteria extends Criteria {
this.filterNotificationSenderNames = Arrays.asList(notificationNames);
}
+ public void addFilterGroupAlertDefinitionId(Integer groupAlertDefinitionId) {
+ this.filterGroupAlertDefinitionId = groupAlertDefinitionId;
+ }
+
public void fetchAlerts(boolean fetchAlerts) {
this.fetchAlerts = fetchAlerts;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
index 6a2fbf5..ae46936 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
@@ -199,5 +199,5 @@ public abstract class AbstractAlertDefinitionsView extends TableSection<Abstract
protected abstract void disableButtonPressed(ListGridRecord[] selection);
- protected abstract void commitAlertDefinition(AlertDefinition alertDefinition, boolean isPurgeInternals);
+ protected abstract void commitAlertDefinition(AlertDefinition alertDefinition, boolean isPurgeInternals, AsyncCallback<AlertDefinition> resultReceiver);
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GroupAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GroupAlertDefinitionsView.java
index b277077..4b8e072 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GroupAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GroupAlertDefinitionsView.java
@@ -198,7 +198,7 @@ public class GroupAlertDefinitionsView extends AbstractAlertDefinitionsView {
}
@Override
- protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals) {
+ protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals, final AsyncCallback<AlertDefinition> resultReceiver) {
if (alertDefinition.getId() == 0) {
GWTServiceLookup.getGroupAlertDefinitionService().createGroupAlertDefinitions(alertDefinition,
Integer.valueOf(this.group.getId()), new AsyncCallback<Integer>() {
@@ -208,11 +208,13 @@ public class GroupAlertDefinitionsView extends AbstractAlertDefinitionsView {
new Message(MSG.view_alert_definitions_create_success(), Severity.Info));
alertDefinition.setId(result.intValue());
GroupAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(alertDefinition);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_create_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
} else {
@@ -224,11 +226,13 @@ public class GroupAlertDefinitionsView extends AbstractAlertDefinitionsView {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_alert_definitions_update_success(), Severity.Info));
GroupAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(result);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_update_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
index 00aa951..5dfacc8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
@@ -194,7 +194,7 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
}
@Override
- protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals) {
+ protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals, final AsyncCallback<AlertDefinition> resultReceiver) {
if (alertDefinition.getId() == 0) {
GWTServiceLookup.getAlertDefinitionService().createAlertDefinition(alertDefinition,
Integer.valueOf(resource.getId()), new AsyncCallback<Integer>() {
@@ -204,11 +204,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
new Message(MSG.view_alert_definitions_create_success(), Severity.Info));
alertDefinition.setId(result.intValue());
ResourceAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(alertDefinition);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_create_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
} else {
@@ -219,11 +221,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_alert_definitions_update_success(), Severity.Info));
ResourceAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(result);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_update_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SingleAlertDefinitionView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SingleAlertDefinitionView.java
index f2007ce..a5d15e9 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SingleAlertDefinitionView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SingleAlertDefinitionView.java
@@ -23,6 +23,7 @@
package org.rhq.enterprise.gui.coregui.client.alert.definitions;
+import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
@@ -139,7 +140,16 @@ public class SingleAlertDefinitionView extends LocatableVLayout {
setAlertDefinition(getAlertDefinition()); // loads data into static fields
makeViewOnly();
- alertDefView.commitAlertDefinition(getAlertDefinition(), resetMatching);
+ alertDefView.commitAlertDefinition(getAlertDefinition(), resetMatching, new AsyncCallback<AlertDefinition>() {
+ @Override
+ public void onSuccess(AlertDefinition result) {
+ setAlertDefinition(result);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ }
+ });
} else {
tabSet.selectTab(generalPropertiesTab);
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/TemplateAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/TemplateAlertDefinitionsView.java
index 0c710b4..1218c3a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/TemplateAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/TemplateAlertDefinitionsView.java
@@ -206,7 +206,7 @@ public class TemplateAlertDefinitionsView extends AbstractAlertDefinitionsView {
}
@Override
- protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean resetMatching) {
+ protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean resetMatching, final AsyncCallback<AlertDefinition> resultReceiver) {
if (alertDefinition.getId() == 0) {
GWTServiceLookup.getAlertTemplateService().createAlertTemplate(alertDefinition,
Integer.valueOf(this.resourceType.getId()), new AsyncCallback<Integer>() {
@@ -216,11 +216,13 @@ public class TemplateAlertDefinitionsView extends AbstractAlertDefinitionsView {
new Message(MSG.view_alert_definitions_create_success(), Severity.Info));
alertDefinition.setId(result.intValue());
TemplateAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(alertDefinition);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_create_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
} else {
@@ -231,11 +233,13 @@ public class TemplateAlertDefinitionsView extends AbstractAlertDefinitionsView {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_alert_definitions_update_success(), Severity.Info));
TemplateAlertDefinitionsView.this.refresh();
+ resultReceiver.onSuccess(result);
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_alert_definitions_update_failure(), caught);
+ resultReceiver.onFailure(caught);
}
});
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertDefinitionGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertDefinitionGWTServiceImpl.java
index 01ba237..07d6132 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertDefinitionGWTServiceImpl.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertDefinitionGWTServiceImpl.java
@@ -65,7 +65,7 @@ public class AlertDefinitionGWTServiceImpl extends AbstractGWTServiceImpl implem
@Override
public int createAlertDefinition(AlertDefinition alertDefinition, Integer resourceId) throws RuntimeException {
try {
- int results = alertDefManager.createAlertDefinition(getSessionSubject(), alertDefinition, resourceId);
+ int results = alertDefManager.createAlertDefinition(getSessionSubject(), alertDefinition, resourceId, true);
return results;
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/config/NewDefinitionAction.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/config/NewDefinitionAction.java
index e4c25f8..1db7d05 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/config/NewDefinitionAction.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/config/NewDefinitionAction.java
@@ -92,7 +92,7 @@ public class NewDefinitionAction extends BaseAction {
alertDefinitionId = alertTemplateManager.createAlertTemplate(subject, alertDef, defForm.getType());
} else if (context == FormContext.Resource) {
AlertDefinitionManagerLocal alertDefinitionManager = LookupUtil.getAlertDefinitionManager();
- alertDefinitionId = alertDefinitionManager.createAlertDefinition(subject, alertDef, defForm.getId());
+ alertDefinitionId = alertDefinitionManager.createAlertDefinition(subject, alertDef, defForm.getId(), true);
} else if (context == FormContext.Group) {
GroupAlertDefinitionManagerLocal groupAlertDefinitionManager = LookupUtil
.getGroupAlertDefinitionManager();
diff --git a/modules/enterprise/server/itests/pom.xml b/modules/enterprise/server/itests/pom.xml
index 43a14c8..d16253a 100644
--- a/modules/enterprise/server/itests/pom.xml
+++ b/modules/enterprise/server/itests/pom.xml
@@ -141,6 +141,18 @@
<scope>test</scope>
</dependency>
+ <!-- Shrinkwrap to build up test plugins etc. -->
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
<!-- NOTE: The remaining test deps correspond to the classes contained in hibernate-all.jar and thirdparty-all.jar. -->
<dependency>
@@ -274,8 +286,30 @@
<version>${resteasy.version}</version>
</dependency>
+ <!-- Dependencies for RHQ components needed for integration tests -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>rhq-serverplugin-drift</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-testng</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
<build>
<testResources>
<testResource>
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginService.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginService.java
new file mode 100644
index 0000000..be9b752
--- /dev/null
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginService.java
@@ -0,0 +1,148 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.server;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
+import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
+import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public abstract class TestServerPluginService extends ServerPluginService implements TestServerPluginServiceMBean {
+ public TestMasterServerPluginContainer master;
+ public MasterServerPluginContainerConfiguration masterConfig;
+
+ protected TestServerPluginService() {
+ // build the config at constructor time so tests have it even before the PC is initialized
+ File dir = new File(System.getProperty("java.io.tmpdir"), "test-server-plugins");
+ this.masterConfig = new MasterServerPluginContainerConfiguration(dir, dir, dir, null);
+ }
+
+ @Override
+ public MasterServerPluginContainer createMasterPluginContainer() {
+ this.master = new TestMasterServerPluginContainer();
+ this.master.initialize(this.masterConfig);
+ return this.master;
+ }
+
+ protected abstract List<AbstractTypeServerPluginContainer> createPluginContainers(MasterServerPluginContainer master);
+
+ public static ServerPlugin getPlugin(ServerPluginEnvironment env) {
+ return getPlugin(env.getPluginUrl(), env.getPluginDescriptor());
+ }
+
+ public static ServerPlugin getPlugin(URL pluginUrl, ServerPluginDescriptorType pluginDescriptor) {
+ try {
+ Configuration pluginConfig = null;
+ Configuration scheduledJobsConfig = null;
+ ConfigurationDefinition configDef;
+
+ configDef = ServerPluginDescriptorMetadataParser.getPluginConfigurationDefinition(pluginDescriptor);
+ if (configDef != null) {
+ pluginConfig = configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ configDef = ServerPluginDescriptorMetadataParser.getScheduledJobsDefinition(pluginDescriptor);
+ if (configDef != null) {
+ scheduledJobsConfig = configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ File pluginFile = new File(pluginUrl.toURI());
+ PluginKey pluginKey = PluginKey.createServerPluginKey(new ServerPluginType(pluginDescriptor).stringify(), pluginDescriptor.getName());
+ ServerPlugin plugin =
+ new ServerPlugin(0, pluginKey.getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED,
+ pluginDescriptor.getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile),
+ pluginDescriptor.getVersion(), pluginDescriptor.getVersion(), pluginConfig,
+ scheduledJobsConfig, new ServerPluginType(pluginDescriptor).stringify(),
+ System.currentTimeMillis(), System.currentTimeMillis());
+ return plugin;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static ServerPlugin getPlugin(URL pluginUrl) throws Exception {
+ ServerPluginDescriptorType type = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
+
+ return getPlugin(pluginUrl, type);
+ }
+
+ protected Map<URL, ? extends ServerPluginDescriptorType> preloadAllPlugins() throws Exception {
+ return null;
+ }
+
+ private class TestMasterServerPluginContainer extends MasterServerPluginContainer {
+
+ @Override
+ protected ClassLoader createRootServerPluginClassLoader() {
+ return getClass().getClassLoader();
+ }
+
+ @Override
+ protected Map<URL, ? extends ServerPluginDescriptorType> preloadAllPlugins() throws Exception {
+ Map<URL, ? extends ServerPluginDescriptorType> plugins = TestServerPluginService.this.preloadAllPlugins();
+ if (plugins != null) {
+ return plugins;
+ }
+
+ // if our test never setup any plugins, ignore it and just return an empty map
+ File pluginDir = getConfiguration().getPluginDirectory();
+ if (pluginDir == null || pluginDir.listFiles() == null || pluginDir.listFiles().length == 0) {
+ return new HashMap<URL, ServerPluginDescriptorType>();
+ } else {
+ return super.preloadAllPlugins();
+ }
+ }
+
+ @Override
+ protected List<PluginKey> getDisabledPluginKeys() {
+ // in the real world, the db is checked for enable flag, here we say all plugins are enabled
+ return new ArrayList<PluginKey>();
+ }
+
+ @Override
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers() {
+ return TestServerPluginService.this.createPluginContainers(this);
+ }
+ }
+}
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginServiceMBean.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginServiceMBean.java
index d38374e..3cd24a4 100644
--- a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginServiceMBean.java
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/TestServerPluginServiceMBean.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2012 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -17,9 +17,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-package org.rhq.enterprise.server.drift;
+package org.rhq.enterprise.server;
import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
-public interface DriftServerPluginServiceMBean extends ServerPluginServiceManagement {
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public interface TestServerPluginServiceMBean extends ServerPluginServiceManagement {
+
}
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
new file mode 100644
index 0000000..d89855e
--- /dev/null
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
@@ -0,0 +1,716 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.server.alert;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+import org.rhq.core.domain.alert.AlertDampening;
+import org.rhq.core.domain.alert.AlertDefinition;
+import org.rhq.core.domain.alert.AlertPriority;
+import org.rhq.core.domain.alert.BooleanExpression;
+import org.rhq.core.domain.alert.notification.AlertNotification;
+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.cloud.Server;
+import org.rhq.core.domain.cloud.Server.OperationMode;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.criteria.AlertDefinitionCriteria;
+import org.rhq.core.domain.criteria.ResourceCriteria;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.domain.resource.Agent;
+import org.rhq.core.domain.resource.InventoryStatus;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.domain.resource.group.ResourceGroup;
+import org.rhq.core.domain.shared.ResourceBuilder;
+import org.rhq.core.domain.shared.ResourceTypeBuilder;
+import org.rhq.enterprise.server.TestServerPluginService;
+import org.rhq.enterprise.server.auth.SessionManager;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+import org.rhq.enterprise.server.test.TestServerCommunicationsService;
+import org.rhq.enterprise.server.util.LookupUtil;
+import org.rhq.enterprise.server.util.ResourceTreeHelper;
+import org.rhq.test.JPAUtils;
+import org.rhq.test.TransactionCallback;
+import org.rhq.test.TransactionCallbackWithContext;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+@Test(groups = "alert")
+public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Test {
+
+ private static final Log LOG = LogFactory.getLog(AlertDefinitionWithComplexNotificationsTest.class);
+
+ private enum ParentType {
+ GROUP, TEMPLATE
+ }
+
+ private String universalName;
+
+ private Server server;
+ private Agent agent;
+ private Subject subject;
+ private Role role;
+ private ResourceType resourceType;
+ private ResourceGroup resourceGroup;
+ private Set<Resource> resources;
+ private AlertDefinition templateAlertDefinition;
+ private AlertDefinition groupAlertDefinition;
+ private AlertDefinition resourceAlertDefinition;
+ private ServerPlugin serverPlugin;
+ private Set<Object> junk = new LinkedHashSet<Object>();
+
+ private int resourceLevelAlertDefinitionId;
+ private int groupLevelAlertDefinitionId;
+ private int templateLevelAlertDefinitionId;
+ private Resource copyTestsResource;
+
+ private TestAlertSenderPluginService alertSenderService;
+ private TestServerCommunicationsService agentService;
+
+ @BeforeClass
+ public void prepareDB() {
+ executeInTransaction(new TransactionCallback() {
+ @Override
+ public void execute() throws Exception {
+ EntityManager em = getEntityManager();
+
+ universalName = getClass().getName();
+
+ agent = new Agent("localhost", "localhost", 0, "foo", "bar");
+
+ server = new Server();
+ server.setAddress("localhost");
+ server.setName("localhost");
+ server.setOperationMode(OperationMode.NORMAL);
+
+ server.setAgents(Collections.singletonList(agent));
+
+ role = new Role(universalName);
+ role.addPermission(Permission.MANAGE_INVENTORY);
+ role.addPermission(Permission.MANAGE_SETTINGS);
+
+ subject = new Subject(universalName, true, false);
+ subject.addRole(role);
+
+ resourceType =
+ new ResourceTypeBuilder().createPlatformResourceType().withId(0).withName(universalName)
+ .withPlugin(universalName).build();
+
+ resourceGroup = new ResourceGroup(universalName, resourceType);
+
+ resources = new LinkedHashSet<Resource>();
+ for (int i = 0; i < 10; ++i) {
+ Resource res = createResourceForTest(universalName + i);
+
+ resources.add(res);
+
+ resourceGroup.addExplicitResource(res);
+ }
+
+ templateAlertDefinition = createDefinitionForTest(universalName + " template", true);
+ templateAlertDefinition.setResourceType(resourceType);
+
+ groupAlertDefinition = createDefinitionForTest(universalName + " group", true);
+ groupAlertDefinition.setResourceGroup(resourceGroup);
+
+ resourceAlertDefinition = createDefinitionForTest(universalName + " resource", true);
+ resourceAlertDefinition.setResource(resources.iterator().next());
+
+ em.persist(agent);
+ em.persist(server);
+ em.persist(role);
+ em.persist(subject);
+ em.persist(resourceType);
+ em.persist(resourceGroup);
+ for (Resource r : resources) {
+ em.persist(r);
+ }
+ em.persist(templateAlertDefinition);
+ em.persist(groupAlertDefinition);
+ em.persist(resourceAlertDefinition);
+
+ //only need this for a short time now, so that we can precreate the plugin structure
+ alertSenderService = new TestAlertSenderPluginService();
+ prepareCustomServerPluginService(alertSenderService);
+ alertSenderService.masterConfig.getPluginDirectory().mkdirs();
+ unprepareServerPluginService();
+
+ JavaArchive archive =
+ ShrinkWrap.create(JavaArchive.class).addClass(TestAlertSender.class)
+ .addAsResource("test-alert-sender-serverplugin.xml", "META-INF/rhq-serverplugin.xml");
+
+ File pluginFile =
+ new File(alertSenderService.masterConfig.getPluginDirectory(), "test-aler-plugin.jar");
+
+ archive.as(ZipExporter.class).exportTo(pluginFile, true);
+
+ //the alert sender plugin manager needs the plugins in the database...
+ serverPlugin = TestServerPluginService.getPlugin(pluginFile.toURI().toURL());
+ em.persist(serverPlugin);
+ }
+ });
+ }
+
+ @BeforeMethod
+ public void containerSetup() {
+ alertSenderService = new TestAlertSenderPluginService();
+ prepareCustomServerPluginService(alertSenderService);
+ alertSenderService.masterConfig.getPluginDirectory().mkdirs();
+
+ alertSenderService.startMasterPluginContainer();
+
+ agentService = prepareForTestAgents();
+ }
+
+ @AfterMethod
+ public void containerTearDown() throws Exception {
+ unprepareServerPluginService();
+ unprepareForTestAgents();
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void cleanDB() throws Exception {
+ for (Object o : junk) {
+ removeNoExceptions(o);
+ }
+
+ removeNoExceptions(resourceAlertDefinition);
+ removeNoExceptions(groupAlertDefinition);
+ removeNoExceptions(templateAlertDefinition);
+ removeNoExceptions(resourceGroup);
+ for (Resource r : resources) {
+ r.removeExplicitGroup(resourceGroup);
+ r.getAlertDefinitions().clear();
+ removeNoExceptions(r);
+ }
+ removeNoExceptions(resourceType);
+ removeNoExceptions(subject);
+ removeNoExceptions(role);
+ removeNoExceptions(server);
+ removeNoExceptions(agent);
+
+ removeNoExceptions(serverPlugin);
+ }
+
+ @BeforeMethod
+ public void login() throws Exception {
+ //the embedded server cannot do a full-blown login
+ //so we hack our way in
+ subject = SessionManager.getInstance().put(subject);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void logout() throws Exception {
+ SessionManager.getInstance().invalidate(subject.getSessionId());
+ }
+
+ private Resource getCopyTestsResource() throws Exception {
+ if (copyTestsResource == null) {
+ final String keyAndName = universalName + "-copyTests";
+
+ LookupUtil.getResourceManager().createResource(subject, createResourceForTest(keyAndName), Resource.ROOT_ID);
+
+ //ok, now the new resource should contain the alert definition defined by the template
+ ResourceCriteria crit = new ResourceCriteria();
+ crit.addFilterResourceKey(keyAndName);
+ crit.fetchExplicitGroups(true); //so that cleanup works
+ crit.fetchAlertDefinitions(true); //so that cleanup works
+
+ List<Resource> foundResources = LookupUtil.getResourceManager().findResourcesByCriteria(subject, crit);
+
+ assertEquals("A new resource should have been created", 1, foundResources.size());
+
+ Resource res = foundResources.get(0);
+ resources.add(res);
+
+ copyTestsResource = res;
+ }
+
+ return copyTestsResource;
+ }
+
+ public void testNotificationsCopiedOnAlertTemplateApplication() throws Exception {
+ TestAlertSender.setExpectedSubject(null);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ Resource res = getCopyTestsResource();
+
+ //apply the template manually - this is done in server-agent back-and-forth that we
+ //don't test here and which is complex to mock out.
+ //this method has to be called using the overlord subject
+ LookupUtil.getAlertTemplateManager().updateAlertDefinitionsForResource(LookupUtil.getSubjectManager().getOverlord(), res.getId());
+
+ assertEquals("No validation should occur on the copied notifications", 0, TestAlertSender.getValidateMethodCallCount());
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+ AlertDefinitionCriteria adCrit = new AlertDefinitionCriteria();
+ adCrit.addFilterResourceIds(res.getId());
+ adCrit.fetchAlertNotifications(true);
+
+ List<AlertDefinition> foundAlertDefs = adm.findAlertDefinitionsByCriteria(subject, adCrit);
+ junk.addAll(foundAlertDefs);
+
+ assertEquals("The new resource should have an alert definition obtained from the template.", 1, foundAlertDefs.size());
+
+ AlertDefinition defWithNotifications = foundAlertDefs.get(0);
+
+ testSingleDependentAlertDefinition(defWithNotifications, ParentType.TEMPLATE, defWithNotifications.getParentId());
+ }
+
+ @Test(dependsOnMethods = "testNotificationsCopiedOnAlertTemplateApplication")
+ public void testNotificationsCopiedOnGroupMemberAddition() throws Exception {
+ TestAlertSender.setExpectedSubject(null);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ Resource res = getCopyTestsResource();
+
+ LookupUtil.getResourceGroupManager().addResourcesToGroup(subject, resourceGroup.getId(), new int[] { res.getId() });
+
+ assertEquals("No validation should occur on the copied notifications", 0, TestAlertSender.getValidateMethodCallCount());
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+ AlertDefinitionCriteria adCrit = new AlertDefinitionCriteria();
+ adCrit.addFilterResourceIds(res.getId());
+ adCrit.fetchAlertNotifications(true);
+
+ List<AlertDefinition> foundAlertDefs = adm.findAlertDefinitionsByCriteria(subject, adCrit);
+ junk.addAll(foundAlertDefs);
+
+ //1 from the group, 1 from the template
+ assertEquals("The new resource should have an alert definition obtained from the group.", 2, foundAlertDefs.size());
+
+ AlertDefinition groupOriginatingDef = null;
+ for(AlertDefinition d : foundAlertDefs) {
+ if ((universalName + " group").equals(d.getName())) {
+ groupOriginatingDef = d;
+ break;
+ }
+ }
+
+ assertNotNull("The alert definition originating from the group not present on the resource.", groupOriginatingDef);
+
+ testSingleDependentAlertDefinition(groupOriginatingDef, ParentType.GROUP, groupOriginatingDef.getGroupAlertDefinition().getId());
+ }
+
+ public void testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ Resource res = resources.iterator().next();
+
+ AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation", false);
+ def.setResource(resources.iterator().next());
+
+ int id = adm.createAlertDefinition(subject, def, res.getId(), true);
+ def.setId(id);
+
+ resourceLevelAlertDefinitionId = id;
+
+ junk.add(def);
+
+ testMainAlertDefinition(id);
+ }
+
+ @Test(dependsOnMethods = { "testNotificationsCopiedOnAlertTemplateApplication", "testNotificationsCopiedOnGroupMemberAddition" })
+ public void testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+
+ GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager();
+
+ AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation", false);
+ def.setResourceGroup(resourceGroup);
+
+ int id = gadm.createGroupAlertDefinitions(subject, def, resourceGroup.getId());
+ def.setId(id);
+
+ groupLevelAlertDefinitionId = id;
+
+ junk.add(def);
+
+ testMainAlertDefinition(id);
+ List<AlertDefinition> deps = testDependentAlertDefinitions(id, ParentType.GROUP);
+
+ junk.addAll(deps);
+ }
+
+ @Test(dependsOnMethods = { "testNotificationsCopiedOnAlertTemplateApplication", "testNotificationsCopiedOnGroupMemberAddition" })
+ public void testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+
+ AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager();
+
+ AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation", false);
+ def.setResourceGroup(resourceGroup);
+
+ int id = atm.createAlertTemplate(subject, def, resourceType.getId());
+ def.setId(id);
+
+ templateLevelAlertDefinitionId = id;
+
+ junk.add(def);
+
+ testMainAlertDefinition(id);
+ List<AlertDefinition> deps = testDependentAlertDefinitions(id, ParentType.TEMPLATE);
+
+ junk.addAll(deps);
+ }
+
+ @Test(dependsOnMethods = "testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation")
+ public void testNoValidationWhenNoNotificationUpdateOnResourceLevel() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(resourceLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ foundDef.setEnabled(true);
+
+ adm.updateAlertDefinition(subject, resourceLevelAlertDefinitionId, foundDef, false);
+
+ assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ @Test(dependsOnMethods = "testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation")
+ public void testNoValidationWhenNoNotificationUpdateOnGroupLevel() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(groupLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created group level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ foundDef.setEnabled(true);
+
+ GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager();
+ gadm.updateGroupAlertDefinitions(subject, foundDef, true);
+
+ assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ @Test(dependsOnMethods = "testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation")
+ public void testNoValidationWhenNoNotificationUpdateOnTemplateLevel() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(templateLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ foundDef.setEnabled(true);
+
+ AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager();
+
+ atm.updateAlertTemplate(subject, foundDef, true);
+
+ assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ @Test(dependsOnMethods = "testNoValidationWhenNoNotificationUpdateOnResourceLevel")
+ public void testCorrectSubjectPassedOnResourceLevelAlertDefinitionUpdate() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(resourceLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ AlertNotification newNotif = createAlertNotificationForTest(foundDef, false);
+ //just add some dummy config property so that the 2 notifs are distinguishable from each other
+ //and are saved separately
+ newNotif.getConfiguration().put(new PropertySimple("foo-resource", "bar"));
+
+ adm.updateAlertDefinition(subject, resourceLevelAlertDefinitionId, foundDef, false);
+
+ assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ @Test(dependsOnMethods = "testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation")
+ public void testCorrectSubjectPassedOnGroupLevelAlertDefinitionUpdate() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(groupLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created group level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ AlertNotification newNotif = createAlertNotificationForTest(foundDef, false);
+ //just add some dummy config property so that the 2 notifs are distinguishable from each other
+ //and are saved separately
+ newNotif.getConfiguration().put(new PropertySimple("foo-group", "bar"));
+
+ GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager();
+ gadm.updateGroupAlertDefinitions(subject, foundDef, true);
+
+ //notice that the validation should be called just once, even though in effect we're creating 11 notifs
+ //1 for group and 10 for its members.
+ assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ @Test(dependsOnMethods = "testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation")
+ public void testCorrectSubjectPassedOnTemplateLevelAlertDefinitionUpdate() throws Exception {
+ TestAlertSender.setExpectedSubject(subject);
+ TestAlertSender.resetValidateMethodCallCount();
+
+ AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
+
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(templateLevelAlertDefinitionId);
+ crit.fetchAlertNotifications(true);
+ crit.fetchConditions(true);
+
+ List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit);
+
+ assertEquals("Failed to find the previously created template level alert definition.", 1, foundDefs.size());
+
+ AlertDefinition foundDef = foundDefs.get(0);
+
+ AlertNotification newNotif = createAlertNotificationForTest(foundDef, false);
+ //just add some dummy config property so that the 2 notifs are distinguishable from each other
+ //and are saved separately
+ newNotif.getConfiguration().put(new PropertySimple("foo-template", "bar"));
+
+ AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager();
+ atm.updateAlertTemplate(subject, foundDef, true);
+
+ //notice that the validation should be called just once, even though in effect we're creating 11 notifs
+ //1 for template and 10 for its members.
+ assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount());
+ }
+
+ private void removeNoExceptions(final Object o) {
+ try {
+ JPAUtils.executeInTransaction(new TransactionCallbackWithContext<Void>() {
+ @Override
+ public Void execute(TransactionManager tm, EntityManager em) {
+ Object o2 = em.merge(o);
+
+ if (o2 instanceof Resource) {
+ ResourceTreeHelper.deleteResource(em, (Resource) o2);
+ } else {
+ em.remove(o2);
+ }
+ return null;
+ }
+ });
+ } catch (Exception e) {
+ LOG.error("Failed to DELETE an object from database: " + o, e);
+ }
+ }
+
+ private AlertDefinition createDefinition(String name) {
+ AlertDefinition ret = new AlertDefinition();
+ ret.setName(name);
+ ret.setPriority(AlertPriority.MEDIUM);
+ ret.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
+ ret.setConditionExpression(BooleanExpression.ANY);
+ ret.setRecoveryId(0);
+
+ return ret;
+ }
+
+ private AlertDefinition createDefinitionForTest(String name, boolean precanned) {
+ AlertDefinition def = createDefinition(name);
+ createAlertNotificationForTest(def, precanned);
+
+ return def;
+ }
+
+ private AlertNotification createAlertNotificationForTest(AlertDefinition alertDefinition, boolean precanned) {
+ AlertNotification notif = new AlertNotification("Test Alert Sender");
+
+ Configuration alertConfig = new Configuration();
+
+ if (precanned) {
+ alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE));
+ } else {
+ alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent"));
+ alertConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral"));
+ }
+
+ Configuration extraConfig = new Configuration();
+
+ if (precanned) {
+ extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE));
+ } else {
+ extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent"));
+ extraConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral"));
+ }
+
+ notif.setConfiguration(alertConfig);
+ notif.setExtraConfiguration(extraConfig);
+
+ alertDefinition.addAlertNotification(notif);
+ notif.setAlertDefinition(alertDefinition);
+
+ return notif;
+ }
+
+ private void testMainAlertDefinition(int id) {
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+ crit.addFilterId(id);
+ crit.fetchAlertNotifications(true);
+
+ List<AlertDefinition> checkList =
+ LookupUtil.getAlertDefinitionManager().findAlertDefinitionsByCriteria(subject, crit);
+
+ assertNotNull("Failed to retrieve the save alert definition", checkList);
+ assertEquals("The alert definition should have been saved.", 1, checkList.size());
+
+ AlertDefinition check = checkList.get(0);
+
+ assertEquals("There should be exactly 1 notification on the definition", 1, check.getAlertNotifications()
+ .size());
+
+ Configuration config = check.getAlertNotifications().get(0).getConfiguration();
+ assertEquals("Unexpected persistent value in notif config", TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE,
+ config.getSimpleValue(TestAlertSender.PERSISTENT_PROPERTY_NAME, null));
+ assertNull("Ephemeral property seems to have been saved",
+ config.getSimpleValue(TestAlertSender.EPHEMERAL_PROPERTY_NAME, null));
+ }
+
+ private List<AlertDefinition> testDependentAlertDefinitions(int expectedParentId, ParentType parentType) {
+ AlertDefinitionCriteria crit = new AlertDefinitionCriteria();
+
+ Set<Integer> resourceIds = new HashSet<Integer>(resources.size());
+ for (Resource r : resources) {
+ resourceIds.add(r.getId());
+ }
+
+ if (parentType == ParentType.TEMPLATE) {
+ crit.addFilterAlertTemplateParentId(expectedParentId);
+ } else if (parentType == ParentType.GROUP) {
+ crit.addFilterGroupAlertDefinitionId(expectedParentId);
+ }
+
+ crit.fetchAlertNotifications(true);
+
+ List<AlertDefinition> checkList =
+ LookupUtil.getAlertDefinitionManager().findAlertDefinitionsByCriteria(subject, crit);
+
+ assertNotNull("Failed to retrieve the save alert definition", checkList);
+ assertEquals("The dependent alert definitions should have been saved.", resources.size(), checkList.size());
+
+ for (AlertDefinition check : checkList) {
+ testSingleDependentAlertDefinition(check, parentType, expectedParentId);
+ }
+
+ return checkList;
+ }
+
+ private void testSingleDependentAlertDefinition(AlertDefinition alertDef, ParentType parentType, int expectedParentId) {
+ assertEquals("There should be exactly 1 notification on the definition " + alertDef, 1, alertDef
+ .getAlertNotifications().size());
+
+ Configuration config = alertDef.getAlertNotifications().get(0).getConfiguration();
+ assertEquals("Unexpected persistent value in notif config " + alertDef,
+ TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE,
+ config.getSimpleValue(TestAlertSender.PERSISTENT_PROPERTY_NAME, null));
+ assertNull("Ephemeral property seems to have been saved " + alertDef,
+ config.getSimpleValue(TestAlertSender.EPHEMERAL_PROPERTY_NAME, null));
+
+ if (parentType == ParentType.GROUP) {
+ assertEquals("The group parent id has unexpected value", expectedParentId, alertDef.getGroupAlertDefinition().getId());
+ } else if (parentType == ParentType.TEMPLATE) {
+ assertEquals("The parent id has unexpected value", Integer.valueOf(expectedParentId), alertDef.getParentId());
+ }
+ }
+
+ private Resource createResourceForTest(String resourceKey) {
+ Resource res = new ResourceBuilder().createPlatform().withRandomUuid().withResourceKey(resourceKey)
+ .withResourceType(resourceType).withName(resourceKey)
+ .withInventoryStatus(InventoryStatus.COMMITTED).build();
+ res.setAgent(agent);
+
+ return res;
+ }
+}
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSender.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSender.java
new file mode 100644
index 0000000..900d74c
--- /dev/null
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSender.java
@@ -0,0 +1,107 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.server.alert;
+
+import org.testng.Assert;
+
+import org.rhq.core.domain.alert.Alert;
+import org.rhq.core.domain.alert.notification.SenderResult;
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderValidationResults;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class TestAlertSender extends AlertSender<ServerPluginComponent> {
+
+ public static final String NAME = "Test Alert Sender";
+
+ public static final String PERSISTENT_PROPERTY_NAME = "persistent";
+ public static final String PERSISTEN_PROPERTY_EXPECTED_VALUE = "persistentephemeral";
+ public static final String EPHEMERAL_PROPERTY_NAME = "ephemeral";
+
+ private static Subject EXPECTED_SUBJECT;
+ private static volatile int VALIDATE_METHOD_CALL_COUNT;
+ private static Runnable VALIDATION_CHECKER;
+
+ public static void setExpectedSubject(Subject subject) {
+ EXPECTED_SUBJECT = subject;
+ }
+
+ public static void setValidationChecker(Runnable validationChecker) {
+ VALIDATION_CHECKER = validationChecker;
+ }
+
+ public static int getValidateMethodCallCount() {
+ return VALIDATE_METHOD_CALL_COUNT;
+ }
+
+ public static void resetValidateMethodCallCount() {
+ VALIDATE_METHOD_CALL_COUNT = 0;
+ }
+
+ @Override
+ public SenderResult send(Alert alert) {
+ SenderResult ret = new SenderResult();
+ ret.addSuccessMessage("kachny");
+
+ return ret;
+ }
+
+ @Override
+ public AlertSenderValidationResults validateAndFinalizeConfiguration(Subject subject) {
+ ++VALIDATE_METHOD_CALL_COUNT;
+
+ if (EXPECTED_SUBJECT != null && !subject.equals(EXPECTED_SUBJECT)) {
+ throw new AssertionError("Unexpected subject. Expected " + EXPECTED_SUBJECT + " but was " + subject);
+ }
+
+ if (VALIDATION_CHECKER != null) {
+ VALIDATION_CHECKER.run();
+ }
+
+ if (alertParameters.getSimple(EPHEMERAL_PROPERTY_NAME) == null) {
+ Assert.fail("Ephemeral property not present in alert parameters during validation. This should never happen.");
+ }
+
+ if (extraParameters.getSimple(EPHEMERAL_PROPERTY_NAME) == null) {
+ Assert.fail("Ephemeral property not present in extra parameters during validation. This should never happen.");
+ }
+
+ updateConfig(alertParameters);
+ updateConfig(extraParameters);
+
+ return new AlertSenderValidationResults(alertParameters, extraParameters);
+ }
+
+ private void updateConfig(Configuration configuration) {
+ String persistentValue = configuration.getSimpleValue(PERSISTENT_PROPERTY_NAME, "");
+ String ephemeralValue = configuration.getSimpleValue(EPHEMERAL_PROPERTY_NAME, "");
+
+ configuration.put(new PropertySimple(PERSISTENT_PROPERTY_NAME, persistentValue + ephemeralValue));
+ configuration.remove(EPHEMERAL_PROPERTY_NAME);
+ }
+}
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSenderPluginService.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSenderPluginService.java
new file mode 100644
index 0000000..9aae985
--- /dev/null
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/alert/TestAlertSenderPluginService.java
@@ -0,0 +1,67 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.server.alert;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.enterprise.server.TestServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderPluginManager;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertServerPluginContainer;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class TestAlertSenderPluginService extends TestServerPluginService {
+
+ @Override
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers(MasterServerPluginContainer master) {
+ return Collections.<AbstractTypeServerPluginContainer>singletonList(new TestAlertServerPluginContainer(master));
+ }
+
+ class TestAlertServerPluginContainer extends AlertServerPluginContainer {
+ public TestAlertServerPluginContainer(MasterServerPluginContainer master) {
+ super(master);
+ }
+
+ @Override
+ protected ServerPluginManager createPluginManager() {
+ return new TestAlertServerPluginManager(this);
+ }
+ }
+
+ class TestAlertServerPluginManager extends AlertSenderPluginManager {
+ public TestAlertServerPluginManager(AlertServerPluginContainer pc) {
+ super(pc);
+ }
+
+ @Override
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
+ return TestServerPluginService.getPlugin(env);
+ }
+ }
+}
diff --git a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginService.java b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginService.java
index 64c6537..46d725f 100644
--- a/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginService.java
+++ b/modules/enterprise/server/itests/src/test/java/org/rhq/enterprise/server/drift/DriftServerPluginService.java
@@ -19,81 +19,25 @@
package org.rhq.enterprise.server.drift;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.PluginKey;
-import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.domain.plugin.ServerPlugin;
-import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.enterprise.server.TestServerPluginService;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
-import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.plugin.pc.drift.DriftServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.drift.DriftServerPluginManager;
-import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
-import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
-public class DriftServerPluginService extends ServerPluginService implements DriftServerPluginServiceMBean {
-
- public TestMasterServerPluginContainer master;
- public MasterServerPluginContainerConfiguration masterConfig;
-
- public DriftServerPluginService() {
- // build the config at constructor time so tests have it even before the PC is initialized
- File dir = new File(System.getProperty("java.io.tmpdir"), "test-server-plugins");
- this.masterConfig = new MasterServerPluginContainerConfiguration(dir, dir, dir, null);
- }
+public class DriftServerPluginService extends TestServerPluginService {
@Override
- public MasterServerPluginContainer createMasterPluginContainer() {
- this.master = new TestMasterServerPluginContainer();
- this.master.initialize(this.masterConfig);
- return this.master;
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers(MasterServerPluginContainer master) {
+ return Collections.<AbstractTypeServerPluginContainer>singletonList(new TestDriftServerPluginContainer(master));
}
- class TestMasterServerPluginContainer extends MasterServerPluginContainer {
- @Override
- protected ClassLoader createRootServerPluginClassLoader() {
- return getClass().getClassLoader();
- }
-
- @Override
- protected Map<URL, ? extends ServerPluginDescriptorType> preloadAllPlugins() throws Exception {
- // if our test never setup any plugins, ignore it and just return an empty map
- File pluginDir = getConfiguration().getPluginDirectory();
- if (pluginDir == null || pluginDir.listFiles() == null || pluginDir.listFiles().length == 0) {
- return new HashMap<URL, ServerPluginDescriptorType>();
- } else {
- return super.preloadAllPlugins();
- }
- }
-
- @Override
- protected List<PluginKey> getDisabledPluginKeys() {
- // in the real world, the db is checked for enable flag, here we say all plugins are enabled
- return new ArrayList<PluginKey>();
- }
-
- @Override
- protected List<AbstractTypeServerPluginContainer> createPluginContainers() {
- ArrayList<AbstractTypeServerPluginContainer> pcs = new ArrayList<AbstractTypeServerPluginContainer>(1);
- DriftServerPluginContainer driftPC = new TestDriftServerPluginContainer(this);
- pcs.add(driftPC);
-
- return pcs;
- }
- }
class TestDriftServerPluginContainer extends DriftServerPluginContainer {
public TestDriftServerPluginContainer(MasterServerPluginContainer master) {
@@ -101,9 +45,9 @@ public class DriftServerPluginService extends ServerPluginService implements Dri
}
@Override
- protected ServerPluginManager createPluginManager() {
- return new TestDriftServerPluginManager(this);
- }
+ protected ServerPluginManager createPluginManager() {
+ return new TestDriftServerPluginManager(this);
+ }
}
class TestDriftServerPluginManager extends DriftServerPluginManager {
@@ -113,34 +57,7 @@ public class DriftServerPluginService extends ServerPluginService implements Dri
@Override
protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
- try {
- Configuration pluginConfig = null;
- Configuration scheduledJobsConfig = null;
- ConfigurationDefinition configDef;
-
- ServerPluginDescriptorType pluginDescriptor = env.getPluginDescriptor();
-
- configDef = ServerPluginDescriptorMetadataParser.getPluginConfigurationDefinition(pluginDescriptor);
- if (configDef != null) {
- pluginConfig = configDef.getDefaultTemplate().createConfiguration();
- }
-
- configDef = ServerPluginDescriptorMetadataParser.getScheduledJobsDefinition(pluginDescriptor);
- if (configDef != null) {
- scheduledJobsConfig = configDef.getDefaultTemplate().createConfiguration();
- }
-
- File pluginFile = new File(env.getPluginUrl().toURI());
- ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
- pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
- .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
- .getVersion(), pluginDescriptor.getVersion(), pluginConfig, scheduledJobsConfig,
- new ServerPluginType(pluginDescriptor).stringify(), System.currentTimeMillis(), System
- .currentTimeMillis());
- return plugin;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ return TestServerPluginService.getPlugin(env);
}
- }
+ }
}
diff --git a/modules/enterprise/server/itests/src/test/resources/log4j.xml b/modules/enterprise/server/itests/src/test/resources/log4j.xml
index bc65329..ca0936f 100644
--- a/modules/enterprise/server/itests/src/test/resources/log4j.xml
+++ b/modules/enterprise/server/itests/src/test/resources/log4j.xml
@@ -17,7 +17,7 @@
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
- <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+ <!-- <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
<param name="Target" value="System.out"/>
<param name="Threshold" value="WARN"/>
@@ -64,7 +64,7 @@
<category name="org.hibernate.SQL">
<priority value="DEBUG"/>
</category>
- -->
+ -->
<root>
<appender-ref ref="CONSOLE"/>
diff --git a/modules/enterprise/server/itests/src/test/resources/test-alert-sender-serverplugin.xml b/modules/enterprise/server/itests/src/test/resources/test-alert-sender-serverplugin.xml
new file mode 100644
index 0000000..f6bf879
--- /dev/null
+++ b/modules/enterprise/server/itests/src/test/resources/test-alert-sender-serverplugin.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<alert-plugin
+ name="alert-complex-test"
+ displayName="Alert:ComplexTest"
+ xmlns="urn:xmlns:rhq-serverplugin.alert"
+ xmlns:c="urn:xmlns:rhq-configuration"
+ xmlns:serverplugin="urn:xmlns:rhq-serverplugin"
+ package="org.rhq.enterprise.server.alert"
+ description="Alert sender plugin for testing the complex validation behavior."
+ >
+
+ <!-- How does this sender show up in drop downs etc -->
+ <short-name>Test Alert Sender</short-name>
+
+ <!-- Class that does the actual sending -->
+ <plugin-class>TestAlertSender</plugin-class>
+
+ <alert-configuration>
+ <c:simple-property name="persistent" type="string" required="true" description="The property that is persisted into the database."/>
+ <c:simple-property name="ephemeral" type="string" required="true" description="The property used only at creation/update time. It is not stored into the datbase because the plugin actually removes it from the configuration." />
+ </alert-configuration>
+</alert-plugin> \ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java
index 927ae74..0b3ff87 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java
@@ -18,6 +18,9 @@
*/
package org.rhq.enterprise.server.alert;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
@@ -201,19 +204,19 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
public int createDependentAlertDefinition(Subject subject, AlertDefinition alertDefinition, int resourceId)
throws InvalidAlertDefinitionException {
- return createAlertDefinitionInternal(subject, alertDefinition, resourceId, false);
+ return createAlertDefinitionInternal(subject, alertDefinition, resourceId, false, false);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public int createAlertDefinition(Subject subject, AlertDefinition alertDefinition, Integer resourceId)
+ public int createAlertDefinition(Subject subject, AlertDefinition alertDefinition, Integer resourceId, boolean validateNotificationConfiguration)
throws InvalidAlertDefinitionException {
- return createAlertDefinitionInternal(subject, alertDefinition, resourceId, true);
+ return createAlertDefinitionInternal(subject, alertDefinition, resourceId, true, validateNotificationConfiguration);
}
- private int createAlertDefinitionInternal(Subject subject, AlertDefinition alertDefinition, Integer resourceId, boolean checkPerms) throws InvalidAlertDefinitionException {
- checkAlertDefinition(subject, alertDefinition, resourceId);
+ private int createAlertDefinitionInternal(Subject subject, AlertDefinition alertDefinition, Integer resourceId, boolean checkPerms, boolean validateNotificationConfiguration) throws InvalidAlertDefinitionException {
+ checkAlertDefinition(subject, null, alertDefinition, resourceId, validateNotificationConfiguration);
// if this is an alert definition, set up the link to a resource
if (resourceId != null) {
@@ -463,21 +466,34 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
return list;
}
+ @Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public AlertDefinition updateAlertDefinition(Subject subject, int alertDefinitionId,
AlertDefinition alertDefinition, boolean resetMatching) throws InvalidAlertDefinitionException,
AlertDefinitionUpdateException {
+ return updateAlertDefinitionInternal(subject, alertDefinitionId, alertDefinition, resetMatching, true, true);
+ }
+
+ @Override
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public AlertDefinition updateDependentAlertDefinition(Subject subject, int alertDefinitionId, AlertDefinition alertDefinition, boolean resetMatching) throws InvalidAlertDefinitionException, AlertDefinitionUpdateException {
+ return updateAlertDefinitionInternal(subject, alertDefinitionId, alertDefinition, resetMatching, false, false);
+ }
+
+ private AlertDefinition updateAlertDefinitionInternal(Subject subject, int alertDefinitionId,
+ AlertDefinition alertDefinition, boolean resetMatching, boolean checkPerms, boolean finalizeNotifications) throws InvalidAlertDefinitionException,
+ AlertDefinitionUpdateException {
if (resetMatching) {
alertDefinitionManager.purgeInternals(alertDefinitionId);
}
-
+
/*
* Method for catching ENABLE / DISABLE changes will use switch logic off of the delta instead of calling out to
* the enable/disable functions
*/
AlertDefinition oldAlertDefinition = entityManager.find(AlertDefinition.class, alertDefinitionId);
- if (checkPermission(subject, oldAlertDefinition) == false) {
+ if (checkPerms && checkPermission(subject, oldAlertDefinition) == false) {
if (oldAlertDefinition.getResourceType() != null) {
throw new PermissionException("User [" + subject.getName()
+ "] does not have permission to modify alert templates for type ["
@@ -498,8 +514,9 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
* is not currently deleted
*/
boolean isResourceLevel = (oldAlertDefinition.getResource() != null);
- checkAlertDefinition(subject, alertDefinition, isResourceLevel ? oldAlertDefinition.getResource().getId()
- : null);
+
+ checkAlertDefinition(subject, oldAlertDefinition, alertDefinition, isResourceLevel ? oldAlertDefinition.getResource().getId()
+ : null, finalizeNotifications);
/*
* Should not be able to update an alert definition if the old alert definition is in an invalid state
@@ -590,6 +607,11 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
* begin with, and nothing needs to be added to the cache as a result
*/
+ //we've been touching both conditions and notifications of the updated alert definition, so we should
+ //return an object with the same... let's force lazy load before we leave the persistence context
+ new ArrayList<AlertCondition>(newAlertDefinition.getConditions());
+ new ArrayList<AlertNotification>(newAlertDefinition.getAlertNotifications());
+
return newAlertDefinition;
}
@@ -612,7 +634,7 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
}
}
- private void checkAlertDefinition(Subject subject, AlertDefinition alertDefinition, Integer resourceId)
+ private void checkAlertDefinition(Subject subject, AlertDefinition persistedAlertDefinition, AlertDefinition alertDefinition, Integer resourceId, boolean finalizeNotifications)
throws InvalidAlertDefinitionException {
// if someone enters a really long description, we need to truncate it - the column is only 250 chars
if (alertDefinition.getDescription() != null && alertDefinition.getDescription().length() > 250) {
@@ -640,8 +662,38 @@ public class AlertDefinitionManagerBean implements AlertDefinitionManagerLocal,
}
}
- if (!alertNotificationManager.finalizeNotifications(subject, alertDefinition.getAlertNotifications())) {
- throw new InvalidAlertDefinitionException("Some of the notifications failed to validate.");
+ if (finalizeNotifications) {
+ List<AlertNotification> notifications = new ArrayList<AlertNotification>(alertDefinition.getAlertNotifications());
+
+ //now remove the notifications that have not changed
+ if (persistedAlertDefinition != null) {
+ List<AlertNotification> persistedNotifications = persistedAlertDefinition.getAlertNotifications() == null ? Collections.<AlertNotification>emptyList() : persistedAlertDefinition.getAlertNotifications();
+
+ if (persistedNotifications.size() > 0) {
+ Iterator<AlertNotification> it = notifications.iterator();
+ while (it.hasNext()) {
+ AlertNotification newNotification = it.next();
+
+ if (newNotification.getId() == 0) {
+ //this is a fresh, not persisted notif. These guys have to be always finalized.
+ continue;
+ }
+
+ for(AlertNotification persistedNotification : persistedNotifications) {
+ //ignore the ids on the notifications as they may vary if we are comparing parent alert def with its children
+ //it's enough for us they they are semantically the same.
+ if (newNotification.getSenderName().equals(persistedNotification.getSenderName()) && newNotification.equalsData(persistedNotification)) {
+ it.remove();
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (!alertNotificationManager.finalizeNotifications(subject, notifications)) {
+ throw new InvalidAlertDefinitionException("Some of the notifications failed to validate.");
+ }
}
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerLocal.java
index 81f0ac0..95dd3a7 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerLocal.java
@@ -45,11 +45,29 @@ public interface AlertDefinitionManagerLocal {
List<IntegerOptionItem> findAlertDefinitionOptionItemsForGroup(Subject subject, int groupId);
- int createAlertDefinition(Subject subject, AlertDefinition alertDefinition, Integer resourceId)
+ /**
+ * Creates a new alert definition. Note that the suject is checked to have necessary authz, which might not
+ * be what you want in all use cases. See {@link #createDependentAlertDefinition(Subject, AlertDefinition, int)}
+ * for further discussion of this.
+ *
+ * @param subject the user creating the alert definition
+ * @param alertDefinition the new alert definition to persist
+ * @param resourceId the resource id for which the def is being created
+ * @param finalizeNotificationConfiguration if true, the configuration of the def's notifications is validated.
+ * This is NOT what you want if, for example, you are merely creating a copy of an existing definition.
+ * Some notifications might require more input when creating the notification than is then persisted in their configs
+ * (prominent example being the CLI alert sender).
+ * This would then cause the validation to fail every time you created a copy of a definition and tried
+ * to persist it. Note that passing false AND having new, unpersisted notifications in the alert definition can
+ * lead to invalid configuration being stored for the notifications.
+ * @return the id of the newly persisted alert definition
+ * @throws InvalidAlertDefinitionException
+ */
+ int createAlertDefinition(Subject subject, AlertDefinition alertDefinition, Integer resourceId, boolean finalizeNotificationConfiguration)
throws InvalidAlertDefinitionException;
-
+
/**
- * This is exactly the same as {@link #createAlertDefinition(Subject, AlertDefinition, Integer)} but
+ * This is exactly the same as {@link #createAlertDefinition(Subject, AlertDefinition, Integer, boolean)} but
* assumes the resource is part of a group (or has given resource type for templates) for which
* a group or template alert definition is being created.
* <p>
@@ -93,6 +111,24 @@ public interface AlertDefinitionManagerLocal {
AlertDefinition updateAlertDefinition(Subject subject, int alertDefinitionId, AlertDefinition alertDefinition,
boolean resetMatching) throws InvalidAlertDefinitionException, AlertDefinitionUpdateException;
+ /**
+ * This method is similar in use-case to {@link #createDependentAlertDefinition(Subject, AlertDefinition, int)}.
+ * It assumes that the the update is part of some more complex operation (like updating alert definition on a group
+ * or a template) and that authz checks have already been performed.
+ * <p>
+ * This method is therefore identical to {@link #updateAlertDefinition(Subject, int, AlertDefinition, boolean)} but
+ * does not perform any authorization checks.
+ *
+ * @param subject the user that is updating the alert definition
+ * @param alertDefinitionId
+ * @param alertDefinition
+ * @param resetMatching
+ * @return
+ * @throws InvalidAlertDefinitionException
+ * @throws AlertDefinitionUpdateException
+ */
+ AlertDefinition updateDependentAlertDefinition(Subject subject, int alertDefinitionId, AlertDefinition alertDefinition, boolean resetMatching) throws InvalidAlertDefinitionException, AlertDefinitionUpdateException;
+
int purgeUnusedAlertDefinitions();
void purgeInternals(int alertDefinitionId);
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 14b1dfb..0e38bb8 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
@@ -109,6 +109,7 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
/**
* @throws AlertDefinitionUpdateException if the {@link AlertNotification} is not associated with a known sender
*/
+ @Deprecated
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public AlertNotification addAlertNotification(Subject user, int alertDefinitionId, AlertNotification notification)
throws AlertDefinitionUpdateException {
@@ -123,11 +124,12 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
List<AlertNotification> notifications = definition.getAlertNotifications();
notifications.add(notification);
- postProcessAlertDefinition(definition);
+ postProcessAlertDefinition(user, definition);
return notification;
}
+ @Deprecated
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void updateAlertNotification(Subject subject, int alertDefinitionId, AlertNotification notification) {
AlertDefinition alertDefinition = getDetachedAlertDefinition(alertDefinitionId); // permissions check first
@@ -144,9 +146,10 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
notifications.add(notification);
}
- postProcessAlertDefinition(alertDefinition);
+ postProcessAlertDefinition(subject, alertDefinition);
}
+ @Deprecated
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public int removeNotifications(Subject subject, Integer alertDefinitionId, Integer[] notificationIds) {
AlertDefinition alertDefinition = getDetachedAlertDefinition(alertDefinitionId); // permissions check first
@@ -168,7 +171,7 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
alertDefinition.getAlertNotifications().removeAll(toBeRemoved);
- postProcessAlertDefinition(alertDefinition);
+ postProcessAlertDefinition(subject, alertDefinition);
return removed;
}
@@ -178,16 +181,15 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
return purgeQuery.executeUpdate();
}
- private AlertDefinition postProcessAlertDefinition(AlertDefinition definition) {
+ private AlertDefinition postProcessAlertDefinition(Subject subject, AlertDefinition definition) {
AlertDefinition updated = null;
AlertDefinitionContext context = definition.getContext();
- Subject overlord = subjectManager.getOverlord();
if (context == AlertDefinitionContext.Type) {
- updated = alertTemplateManager.updateAlertTemplate(overlord, definition, true);
+ updated = alertTemplateManager.updateAlertTemplate(subject, definition, true);
} else if (context == AlertDefinitionContext.Group) {
- updated = groupAlertDefintionManager.updateGroupAlertDefinitions(overlord, definition, true);
+ updated = groupAlertDefintionManager.updateGroupAlertDefinitions(subject, definition, true);
} else if (context == AlertDefinitionContext.Resource) {
- updated = alertDefinitionManager.updateAlertDefinition(overlord, definition.getId(), definition, false);
+ updated = alertDefinitionManager.updateAlertDefinition(subject, definition.getId(), definition, false);
} else {
throw new IllegalStateException("No support for updating alert notifications for AlertDefinitionContext: "
+ definition.getContext());
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
index 56f8eab..3aa21cf 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
@@ -44,7 +44,9 @@ public interface AlertNotificationManagerLocal {
* @param senderName shortName of the {@link AlertSender}
* @param configuration Properties for this alert sender.
* @throws AlertNotificationValidationException if the alert sender of the notification failed to finalize and validate the provided notification's configuration
+ * @deprecated this is used only by the legacy JSF UI and no longer works correctly
*/
+ @Deprecated
AlertNotification addAlertNotification(Subject user, int alertDefinitionId, AlertNotification notification) throws AlertDefinitionUpdateException, AlertNotificationValidationException;
/**
@@ -52,7 +54,9 @@ public interface AlertNotificationManagerLocal {
*
* @param notification
* @throws AlertNotificationValidationException if the alert sender of the notification failed to finalize and validate the notification's configuration
+ * @deprecated this is used only by the legacy JSF UI and no longer works correctly
*/
+ @Deprecated
void updateAlertNotification(Subject subject, int alertDefinitionId, AlertNotification notification) throws AlertDefinitionUpdateException, AlertNotificationValidationException;
/**
@@ -61,7 +65,9 @@ public interface AlertNotificationManagerLocal {
* @param alertDefinitionId alert definition to modify
* @param notificationIds Notifications to remove
* @return number of notifications removed
+ * @deprecated this is used only by the legacy JSF UI and no longer works correctly
*/
+ @Deprecated
int removeNotifications(Subject subject, Integer alertDefinitionId, Integer[] notificationIds);
/**
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertTemplateManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertTemplateManagerBean.java
index cda1e0f..5b5c2ef 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertTemplateManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertTemplateManagerBean.java
@@ -118,16 +118,20 @@ public class AlertTemplateManagerBean implements AlertTemplateManagerLocal {
}
ResourceType type = resourceTypeManager.getResourceTypeById(user, resourceTypeId);
-
+
alertTemplate.setResourceType(type); // mark this as an alert "template" definition
+
int alertTemplateId = 0;
try {
- alertTemplateId = alertDefinitionManager.createAlertDefinition(user, alertTemplate, null);
+ alertTemplateId = alertDefinitionManager.createAlertDefinition(user, alertTemplate, null, true);
} catch (Throwable t) {
throw new AlertDefinitionCreationException("Could not create alertTemplate for " + type + " with data "
+ alertTemplate.toSimpleString(), t);
}
+ //get the alert definition we just created.. this is so that we can create copies of it
+ AlertDefinition persistedAlertTemplate = alertDefinitionManager.getAlertDefinition(user, alertTemplateId);
+
Throwable firstThrowable = null;
List<Integer> resourceIdsForType = getCommittedResourceIdsNeedingTemplateApplication(user, alertTemplateId,
@@ -136,7 +140,7 @@ public class AlertTemplateManagerBean implements AlertTemplateManagerLocal {
for (Integer resourceId : resourceIdsForType) {
try {
// construct the child
- AlertDefinition childAlertDefinition = new AlertDefinition(alertTemplate);
+ AlertDefinition childAlertDefinition = new AlertDefinition(persistedAlertTemplate);
childAlertDefinition.setParentId(alertTemplate.getId());
// persist the child as a dependent alert definition
@@ -187,7 +191,7 @@ public class AlertTemplateManagerBean implements AlertTemplateManagerLocal {
// persist the child, user is known to be overlord at this point for this system side-effect
try {
- alertDefinitionManager.createAlertDefinition(user, childAlertDefinition, resourceId);
+ alertDefinitionManager.createAlertDefinition(user, childAlertDefinition, resourceId, false);
} catch (Throwable t) {
throw new AlertDefinitionCreationException("Failed to create child AlertDefinition for Resource[id="
+ resourceId + "] with template " + template.toSimpleString());
@@ -259,7 +263,7 @@ public class AlertTemplateManagerBean implements AlertTemplateManagerLocal {
for (Integer alertDefinitionId : alertDefinitions) {
try {
alertDefinitionManager
- .updateAlertDefinition(overlord, alertDefinitionId, alertTemplate, resetMatching);
+ .updateDependentAlertDefinition(user, alertDefinitionId, updated, resetMatching);
} catch (Throwable t) {
// continue on error, update as many as possible
if (firstThrowable == null) {
@@ -279,11 +283,11 @@ public class AlertTemplateManagerBean implements AlertTemplateManagerLocal {
for (Integer resourceId : resourceIds) {
try {
// construct the child
- AlertDefinition childAlertDefinition = new AlertDefinition(alertTemplate);
+ AlertDefinition childAlertDefinition = new AlertDefinition(updated);
childAlertDefinition.setParentId(alertTemplate.getId());
// persist the child
- alertDefinitionManager.createAlertDefinition(overlord, childAlertDefinition, resourceId);
+ alertDefinitionManager.createAlertDefinition(overlord, childAlertDefinition, resourceId, false);
} catch (Throwable t) {
// continue on error, update as many as possible
if (firstThrowable == null) {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/GroupAlertDefinitionManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/GroupAlertDefinitionManagerBean.java
index 6df9ae0..8cac89c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/GroupAlertDefinitionManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/GroupAlertDefinitionManagerBean.java
@@ -146,12 +146,15 @@ public class GroupAlertDefinitionManagerBean implements GroupAlertDefinitionMana
int groupAlertDefinitionId = 0;
try {
- groupAlertDefinitionId = alertDefinitionManager.createAlertDefinition(subject, groupAlertDefinition, null);
+ groupAlertDefinitionId = alertDefinitionManager.createAlertDefinition(subject, groupAlertDefinition, null, true);
} catch (Throwable t) {
throw new AlertDefinitionCreationException("Could not create groupAlertDefinitions for " + group
+ " with data " + groupAlertDefinition.toSimpleString(), t);
}
+ //get the alert definition we just created.. this is so that we can create copies of it
+ AlertDefinition persistedDefinition = alertDefinitionManager.getAlertDefinition(subject, groupAlertDefinitionId);
+
Throwable firstThrowable = null;
List<Integer> resourceIdsForGroup = getCommittedResourceIdsNeedingGroupAlertDefinitionApplication(subject,
@@ -160,7 +163,7 @@ public class GroupAlertDefinitionManagerBean implements GroupAlertDefinitionMana
for (Integer resourceId : resourceIdsForGroup) {
try {
// construct the child
- AlertDefinition childAlertDefinition = new AlertDefinition(groupAlertDefinition);
+ AlertDefinition childAlertDefinition = new AlertDefinition(persistedDefinition);
childAlertDefinition.setGroupAlertDefinition(groupAlertDefinition);
// persist the child
@@ -241,9 +244,10 @@ public class GroupAlertDefinitionManagerBean implements GroupAlertDefinitionMana
LOG.debug("Need to update the following children alert definition ids: " + alertDefinitions);
}
List<Integer> alertDefinitionIdsInError = new ArrayList<Integer>();
+
for (Integer alertDefinitionId : alertDefinitions) {
try {
- alertDefinitionManager.updateAlertDefinition(overlord, alertDefinitionId, groupAlertDefinition,
+ alertDefinitionManager.updateDependentAlertDefinition(subject, alertDefinitionId, updated,
resetMatching);
} catch (Throwable t) {
// continue on error, update as many as possible
@@ -261,11 +265,11 @@ public class GroupAlertDefinitionManagerBean implements GroupAlertDefinitionMana
for (Integer resourceId : resourceIds) {
try {
// construct the child
- AlertDefinition childAlertDefinition = new AlertDefinition(groupAlertDefinition);
+ AlertDefinition childAlertDefinition = new AlertDefinition(updated);
childAlertDefinition.setGroupAlertDefinition(groupAlertDefinition);
// persist the child
- alertDefinitionManager.createAlertDefinition(overlord, childAlertDefinition, resourceId);
+ alertDefinitionManager.createAlertDefinition(subject, childAlertDefinition, resourceId, false);
} catch (Throwable t) {
// continue on error, update as many as possible
if (firstThrowable == null) {
@@ -308,7 +312,7 @@ public class GroupAlertDefinitionManagerBean implements GroupAlertDefinitionMana
childAlertDefinition.setGroupAlertDefinition(groupAlertDefinition);
// persist the child
- alertDefinitionManager.createAlertDefinition(overlord, childAlertDefinition, resourceId);
+ alertDefinitionManager.createAlertDefinition(overlord, childAlertDefinition, resourceId, false);
} catch (Throwable t) {
// continue on error, create as many as possible
if (firstThrowable == null) {
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertConditionTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertConditionTest.java
index 47ba274..5116a90 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertConditionTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertConditionTest.java
@@ -479,7 +479,7 @@ public class AlertConditionTest extends UpdatePluginMetadataTestBase {
alertDefinition.setConditions(conditions);
AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
- int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId);
+ int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId, true);
alertDefinition = alertDefManager.getAlertDefinition(getOverlord(), defId); // load it back so we get its ID and all condition IDs
assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
+ alertDefinition;
@@ -513,7 +513,7 @@ public class AlertConditionTest extends UpdatePluginMetadataTestBase {
alertDefinition.setConditions(conditions);
AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
- int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId);
+ int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId, true);
alertDefinition = alertDefManager.getAlertDefinition(getOverlord(), defId); // load it back so we get its ID and all condition IDs
assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
+ alertDefinition;
@@ -546,7 +546,7 @@ public class AlertConditionTest extends UpdatePluginMetadataTestBase {
alertDefinition.setConditions(conditions);
AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
- int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId);
+ int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId, true);
alertDefinition = alertDefManager.getAlertDefinition(getOverlord(), defId); // load it back so we get its ID and all condition IDs
assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
+ alertDefinition;
@@ -579,7 +579,7 @@ public class AlertConditionTest extends UpdatePluginMetadataTestBase {
alertDefinition.setConditions(conditions);
AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
- int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId);
+ int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId, true);
alertDefinition = alertDefManager.getAlertDefinition(getOverlord(), defId); // load it back so we get its ID and all condition IDs
assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
+ alertDefinition;
@@ -613,7 +613,7 @@ public class AlertConditionTest extends UpdatePluginMetadataTestBase {
alertDefinition.setConditions(conditions);
AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
- int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId);
+ int defId = alertDefManager.createAlertDefinition(getOverlord(), alertDefinition, resourceId, true);
alertDefinition = alertDefManager.getAlertDefinition(getOverlord(), defId); // load it back so we get its ID and all condition IDs
assert alertDefinition != null && alertDefinition.getId() > 0 : "did not persist alert def properly: "
+ alertDefinition;
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
index 825fdee..4b9dea2 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
@@ -355,7 +355,7 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest {
def.setPriority(AlertPriority.MEDIUM);
def.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
def.setRecoveryId(0);
- alertDefinitionManager.createAlertDefinition(overlord, def, res.getId());
+ alertDefinitionManager.createAlertDefinition(overlord, def, res.getId(), true);
for (int MULTI : ROUNDS) {
String round = String.format(ROUND__FORMAT, MULTI);