modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
| 377 +++++--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/i18n/AlertI18NResourceKeys.java
| 199 +++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java
| 26
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
| 487 +++++++---
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/DeleteAlertsTest.java
| 123 ++
5 files changed, 925 insertions(+), 287 deletions(-)
New commits:
commit eb50b72dad1558e042bfee3d7e4211e40d39cf91
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Sep 15 22:57:51 2011 -0400
[BZ 738614] fix condition pretty printing - this is for email alert messages and other
notifications
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
index 5bffb48..1275e26 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
@@ -60,7 +60,6 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.AlertCriteria;
-import org.rhq.core.domain.measurement.MeasurementSchedule;
import org.rhq.core.domain.measurement.MeasurementUnits;
import org.rhq.core.domain.operation.OperationDefinition;
import org.rhq.core.domain.resource.Resource;
@@ -79,7 +78,6 @@ import org.rhq.enterprise.server.authz.PermissionException;
import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.core.EmailManagerLocal;
import org.rhq.enterprise.server.measurement.instrumentation.MeasurementMonitor;
-import org.rhq.enterprise.server.measurement.util.MeasurementFormatter;
import org.rhq.enterprise.server.operation.OperationManagerLocal;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
@@ -814,94 +812,269 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
private String prettyPrintAlertCondition(AlertCondition condition, boolean
shortVersion) {
- StringBuilder builder = new StringBuilder();
+ StringBuilder str = new StringBuilder();
AlertConditionCategory category = condition.getCategory();
+ switch (category) {
+ case AVAILABILITY: {
+ if ("up".equalsIgnoreCase(condition.getOption())) {
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_AVAILABILITY_UP_SHORT));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_AVAILABILITY_UP));
+ }
+ } else {
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_AVAILABILITY_DOWN_SHORT));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_AVAILABILITY_DOWN));
+ }
+ }
- // first format the LHS of the operator
- if (category == AlertConditionCategory.CONTROL) {
+ break;
+ }
+ case THRESHOLD: {
+ double value = condition.getThreshold();
+ MeasurementUnits units = condition.getMeasurementDefinition().getUnits();
+ String formatted = MeasurementConverter.format(value, units, true);
+
+ if (condition.getOption() == null) {
+ String metricName = condition.getName();
+ String comparator = condition.getComparator();
+ str.append(metricName).append('
').append(comparator).append(' ').append(formatted);
+ } else {
+ // this is a calltime threshold condition
+ String metricName = "";
+ if (condition.getMeasurementDefinition() != null) {
+ metricName = condition.getMeasurementDefinition().getDisplayName();
+ }
+
+ String limit = condition.getOption(); // MIN, MAX, AVG (never null)
+ String comparator = condition.getComparator(); // <, >, =
+
+ if (condition.getName() != null && condition.getName().length()
> 0) {
+ String regex = condition.getName();
+ if (shortVersion) {
+ str.append(AlertI18NFactory.getMessage(
+
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR_SHORT, metricName, limit,
+ comparator, formatted, regex));
+ } else {
+ str.append(AlertI18NFactory.getMessage(
+
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR, metricName, limit,
+ comparator, formatted, regex));
+ }
+ } else {
+ if (shortVersion) {
+ str.append(AlertI18NFactory.getMessage(
+ AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_SHORT,
metricName, limit, comparator,
+ formatted));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD,
+ metricName, limit, comparator, formatted));
+ }
+ }
+ }
+ break;
+ }
+ case BASELINE: {
+ String metricName = condition.getName();
+ String comparator = condition.getComparator();
+ double value = condition.getThreshold();
+ MeasurementUnits units = MeasurementUnits.PERCENTAGE;
+ String percentage = MeasurementConverter.format(value, units, true);
+ String baselineThreshold = condition.getOption(); // mean, min, max
+
+ if (shortVersion) {
+ if (baselineThreshold.equalsIgnoreCase("min")) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MIN_SHORT,
metricName,
+ comparator, percentage));
+ } else if (baselineThreshold.equalsIgnoreCase("max")) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MAX_SHORT,
metricName,
+ comparator, percentage));
+ } else { // mean
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MEAN_SHORT,
metricName,
+ comparator, percentage));
+ }
+ } else {
+ if (baselineThreshold.equalsIgnoreCase("min")) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MIN,
metricName,
+ comparator, percentage));
+ } else if (baselineThreshold.equalsIgnoreCase("max")) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MAX,
metricName,
+ comparator, percentage));
+ } else { // mean
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MEAN,
metricName,
+ comparator, percentage));
+ }
+ }
+ break;
+ }
+ case CHANGE: {
+ if (condition.getOption() == null) {
+ String metricName = condition.getName();
+ if (shortVersion) {
+ str.append(AlertI18NFactory
+ .getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_SHORT,
metricName));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED,
metricName));
+ }
+ } else {
+ // this is a calltime change condition
+ double value = condition.getThreshold();
+ MeasurementUnits units = MeasurementUnits.PERCENTAGE;
+ String formatted = MeasurementConverter.format(value, units, true);
+
+ String comparator;
+ if ("HI".equalsIgnoreCase(condition.getComparator())) {
+ comparator =
AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_GROWS);
+ } else if ("LO".equalsIgnoreCase(condition.getComparator())) {
+ comparator = AlertI18NFactory
+
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_SHRINKS);
+ } else { // CH
+ comparator = AlertI18NFactory
+
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_CHANGES);
+ }
+
+ String metricName = "";
+ if (condition.getMeasurementDefinition() != null) {
+ metricName = condition.getMeasurementDefinition().getDisplayName();
+ }
+
+ String limit = condition.getOption(); // MIN, MAX, AVG (never null)
+
+ if (condition.getName() != null && condition.getName().length()
> 0) {
+ String regex = condition.getName();
+ if (shortVersion) {
+ str.append(AlertI18NFactory.getMessage(
+
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR_SHORT, metricName, limit,
+ comparator, formatted, regex));
+ } else {
+ str.append(AlertI18NFactory.getMessage(
+ AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR,
metricName, limit,
+ comparator, formatted, regex));
+ }
+ } else {
+ if (shortVersion) {
+ str.append(AlertI18NFactory.getMessage(
+ AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_SHORT,
metricName, limit, comparator,
+ formatted));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE,
+ metricName, limit, comparator, formatted));
+ }
+ }
+ }
+ break;
+ }
+ case TRAIT: {
+ String metricName = condition.getName();
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_SHORT,
metricName));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED,
metricName));
+ }
+ break;
+ }
+ case CONTROL: {
+ String opName;
try {
Integer resourceTypeId =
condition.getAlertDefinition().getResource().getResourceType().getId();
String operationName = condition.getName();
OperationDefinition definition =
operationManager.getOperationDefinitionByResourceTypeAndName(
resourceTypeId, operationName, false);
- builder.append(definition.getDisplayName()).append(' ');
+ opName = definition.getDisplayName();
} catch (Exception e) {
- builder.append(condition.getName()).append(' ');
+ opName = condition.getName(); // can't look up the op display name
(are we in a test?), just use the op name
}
- } else {
- if (category.getName() != null) // this is null for e.g. availability
- builder.append(condition.getName()).append(' ');
- }
-
- // next format the RHS
- if (category == AlertConditionCategory.CONTROL) {
- builder.append(condition.getOption());
- } else if ((category == AlertConditionCategory.THRESHOLD) || (category ==
AlertConditionCategory.BASELINE)) {
- builder.append(condition.getComparator());
- builder.append(' ');
-
- MeasurementSchedule schedule = null;
- MeasurementUnits units;
- double value = condition.getThreshold();
- if (category == AlertConditionCategory.THRESHOLD) {
- units = condition.getMeasurementDefinition().getUnits();
- } else // ( category == AlertConditionCategory.BASELINE )
- {
- units = MeasurementUnits.PERCENTAGE;
+ String status = condition.getOption();
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_OPERATION_SHORT,
opName, status));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_OPERATION, opName,
status));
}
- String formatted = MeasurementConverter.format(value, units, true);
- builder.append(formatted);
-
- if (category == AlertConditionCategory.BASELINE) {
- builder.append(" of ");
-
builder.append(MeasurementFormatter.getBaselineText(condition.getOption(), schedule));
+ break;
+ }
+ case RESOURCE_CONFIG: {
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RESOURCECONFIGCHANGE_SHORT));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RESOURCECONFIGCHANGE));
}
- } else if ((category == AlertConditionCategory.RESOURCE_CONFIG) || (category ==
AlertConditionCategory.CHANGE)
- || (category == AlertConditionCategory.TRAIT)) {
-
- if (shortVersion)
- builder.append(AlertI18NFactory
-
.getMessage(AlertI18NResourceKeys.ALERT_CURRENT_LIST_VALUE_CHANGED_SHORT));
- else
-
builder.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_CURRENT_LIST_VALUE_CHANGED));
-
- } else if (category == AlertConditionCategory.EVENT) {
- if ((condition.getOption() != null) &&
(condition.getOption().length() > 0)) {
- String propsCbEventSeverityRegexMatch;
- if (shortVersion)
- propsCbEventSeverityRegexMatch =
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_REGEX_MATCH_SHORT;
- else
- propsCbEventSeverityRegexMatch =
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_REGEX_MATCH;
-
-
builder.append(AlertI18NFactory.getMessage(propsCbEventSeverityRegexMatch,
condition.getName(),
- condition.getOption()));
+ break;
+ }
+ case EVENT: {
+ String severity = condition.getName();
+ if (condition.getOption() != null && condition.getOption().length()
> 0) {
+ String expression = condition.getOption();
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR_SHORT,
severity,
+ expression));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR,
severity,
+ expression));
+ }
} else {
- if (shortVersion)
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_SHORT,
condition.getName()));
- else
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY,
condition.getName()));
+ if (shortVersion) {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_SHORT,
severity));
+ } else {
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT, severity));
+ }
}
- } else if (category == AlertConditionCategory.AVAILABILITY) {
- if (shortVersion)
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_AVAILABILITY_SHORT,
condition.getOption()));
- else
-
builder.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_AVAILABILITY,
- condition.getOption()));
- } else if (category == AlertConditionCategory.DRIFT) {
- if (shortVersion)
-
builder.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_DRIFT_SHORT,
- condition.getOption()));
- else
-
builder.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_DRIFT,
condition
- .getOption()));
- } else if (category == AlertConditionCategory.RANGE) {
+ break;
+ }
+ case DRIFT: {
+ String configNameRegex = condition.getName();
+ String pathNameRegex = condition.getOption();
+ if (shortVersion) {
+ if (configNameRegex == null || configNameRegex.length() == 0) {
+ if (pathNameRegex == null || pathNameRegex.length() == 0) {
+ // neither a config name regex nor path regex was specified
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_SHORT));
+ } else {
+ // a path name regex was specified, but not a config name regex
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYPATHS_SHORT,
+ pathNameRegex));
+ }
+ } else {
+ if (pathNameRegex == null || pathNameRegex.length() == 0) {
+ // a config name regex was specified, but not a path name regex
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYCONFIG_SHORT,
+ configNameRegex));
+ } else {
+ // both a config name regex and a path regex was specified
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_CONFIGPATHS_SHORT,
+ pathNameRegex, configNameRegex));
+ }
+ }
+ } else {
+ if (configNameRegex == null || configNameRegex.length() == 0) {
+ if (pathNameRegex == null || pathNameRegex.length() == 0) {
+ // neither a config name regex nor path regex was specified
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT));
+ } else {
+ // a path name regex was specified, but not a config name regex
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYPATHS,
+ pathNameRegex));
+ }
+ } else {
+ if (pathNameRegex == null || pathNameRegex.length() == 0) {
+ // a config name regex was specified, but not a path name regex
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYCONFIG,
+ configNameRegex));
+ } else {
+ // both a config name regex and a path regex was specified
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_CONFIGPATHS,
+ pathNameRegex, configNameRegex));
+ }
+ }
+ }
+ break;
+ }
+ case RANGE: {
+ String metricName = condition.getName();
Double loValue = condition.getThreshold();
String hiValueStr = condition.getOption();
@@ -920,55 +1093,55 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
}
+ // < means "inside the range", > means "outside the
range" - exclusive
+ // <= means "inside the range", >= means "outside the
range" - inclusive
+
if ("<".equals(condition.getComparator())) {
if (shortVersion) {
- builder.append(AlertI18NFactory.getMessage(
-
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_INSIDE_EXCL_RANGE_SHORT, loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_INSIDE_EXCL_SHORT,
+ metricName, loValueFormatted, hiValueFormatted));
} else {
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_INSIDE_EXCL_RANGE,
loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_INSIDE_EXCL,
metricName,
+ loValueFormatted, hiValueFormatted));
}
} else if (">".equals(condition.getComparator())) {
if (shortVersion) {
- builder.append(AlertI18NFactory.getMessage(
-
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_OUTSIDE_EXCL_RANGE_SHORT, loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_OUTSIDE_EXCL_SHORT,
+ metricName, loValueFormatted, hiValueFormatted));
} else {
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_OUTSIDE_EXCL_RANGE,
loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_OUTSIDE_EXCL,
metricName,
+ loValueFormatted, hiValueFormatted));
}
} else if ("<=".equals(condition.getComparator())) {
if (shortVersion) {
- builder.append(AlertI18NFactory.getMessage(
-
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_INSIDE_INCL_RANGE_SHORT, loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_INSIDE_INCL_SHORT,
+ metricName, loValueFormatted, hiValueFormatted));
} else {
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_INSIDE_INCL_RANGE,
loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_INSIDE_INCL,
metricName,
+ loValueFormatted, hiValueFormatted));
}
} else if (">=".equals(condition.getComparator())) {
if (shortVersion) {
- builder.append(AlertI18NFactory.getMessage(
-
AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_OUTSIDE_INCL_RANGE_SHORT, loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_OUTSIDE_INCL_SHORT,
+ metricName, loValueFormatted, hiValueFormatted));
} else {
- builder.append(AlertI18NFactory.getMessage(
- AlertI18NResourceKeys.ALERT_CONFIG_PROPS_CB_OUTSIDE_INCL_RANGE,
loValueFormatted,
- hiValueFormatted));
+
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RANGE_OUTSIDE_INCL,
metricName,
+ loValueFormatted, hiValueFormatted));
}
} else {
- builder.append("invalid range comparator [" +
condition.getComparator() + "] (" + loValueFormatted
- + "," + hiValueFormatted + ")");
+ str.append("invalid range comparator [" +
condition.getComparator() + "] (" + loValueFormatted + ","
+ + hiValueFormatted + ")");
}
- } else {
- // do nothing
+
+ break;
+ }
+ default: {
+ str.append("unknown category [" + category.name() +
"]");
+ break;
+ }
}
- return builder.toString();
+ return str.toString();
}
public String prettyPrintAlertURL(Alert alert) {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/i18n/AlertI18NResourceKeys.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/i18n/AlertI18NResourceKeys.java
index d48f93a..f3ab9a6 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/i18n/AlertI18NResourceKeys.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/i18n/AlertI18NResourceKeys.java
@@ -22,77 +22,172 @@ import mazz.i18n.annotation.I18NMessage;
import mazz.i18n.annotation.I18NMessages;
import mazz.i18n.annotation.I18NResourceBundle;
-/**
- * @author Joseph Marques
- */
-
@I18NResourceBundle(baseName = "alert-messages", defaultLocale =
"en")
public interface AlertI18NResourceKeys {
- @I18NMessages( { @I18NMessage("value is between {0} and {1}, inclusive"),
- @I18NMessage(locale = "de", value = "Der Wert zwischen {0} und
{1}, pauschal") })
- String ALERT_CONFIG_PROPS_CB_INSIDE_INCL_RANGE =
"alert.config.props.CB.InsideRange.incl.";
+ @I18NMessages( { @I18NMessage("Availability goes UP"),
+ @I18NMessage(locale = "de", value = "Verf�gbarkeit wird AUF")
})
+ String ALERT_AVAILABILITY_UP = "alert.condition.availability.up";
+
+ @I18NMessages( { @I18NMessage("Avail goes UP"), @I18NMessage(locale =
"de", value = "Verf. wird AUF") })
+ String ALERT_AVAILABILITY_UP_SHORT =
"alert.condition.availability.up.short";
+
+ @I18NMessages( { @I18NMessage("Availability goes DOWN"),
+ @I18NMessage(locale = "de", value = "Verf�gbarkeit wird NACH
UNTEN") })
+ String ALERT_AVAILABILITY_DOWN = "alert.condition.availability.down";
+
+ @I18NMessages( { @I18NMessage("Avail goes DOWN"), @I18NMessage(locale =
"de", value = "Verf. wird NACH UNTEN") })
+ String ALERT_AVAILABILITY_DOWN_SHORT =
"alert.condition.availability.down.short";
+
+ // Foo Prop > 10.0% of Baseline Mean Value
+ @I18NMessages( { @I18NMessage("{0} {1} {2} of Baseline Mean Value") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_BASELINE_MEAN = "alert.condition.baseline.mean";
+
+ // Foo Prop > 10.0% bl mean
+ @I18NMessages( { @I18NMessage("{0} {1} {2} bl mean") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_BASELINE_MEAN_SHORT = "alert.condition.baseline.mean.short";
+
+ @I18NMessages( { @I18NMessage("{0} {1} {2} of Baseline Minimum Value") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_BASELINE_MIN = "alert.condition.baseline.min";
+
+ @I18NMessages( { @I18NMessage("{0} {1} {2} bl min") /*, @I18NMessage(locale
= "de", value = "") */})
+ String ALERT_BASELINE_MIN_SHORT = "alert.condition.baseline.min.short";
+
+ @I18NMessages( { @I18NMessage("{0} {1} {2} of Baseline Maximum Value") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_BASELINE_MAX = "alert.condition.baseline.max";
+
+ @I18NMessages( { @I18NMessage("{0} {1} {2} bl max") /*, @I18NMessage(locale
= "de", value = "") */})
+ String ALERT_BASELINE_MAX_SHORT = "alert.condition.baseline.max.short";
+
+ // Calltime Metric Foo MAX > 1.0 with calltime destination matching
"*.txt"
+ @I18NMessages( { @I18NMessage("Calltime Metric {0} {1} {2} {3} with calltime
destination matching \"{4}\"") /*, @I18NMessage(locale = "de",
value = "") */})
+ String ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR =
"alert.condition.calltime-threshold-with-expr";
+
+ // Foo MAX > 1.0 matching "*.txt"
+ @I18NMessages( { @I18NMessage("{0} {1} {2} {3} matching \"{4}\"")
/*, @I18NMessage(locale = "de", value = "") */})
+ String ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR_SHORT =
"alert.condition.calltime-threshold-with-expr.short";
+
+ // Calltime Metric Foo MAX > 1.0
+ @I18NMessages( { @I18NMessage("Calltime Metric {0} {1} {2} {3}") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_METRIC_CALLTIME_THRESHOLD =
"alert.condition.calltime-threshold";
+
+ // Foo MAX > 1.0
+ @I18NMessages( { @I18NMessage("{0} {1} {2} {3}") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_METRIC_CALLTIME_THRESHOLD_SHORT =
"alert.condition.calltime-threshold.short";
+
+ @I18NMessages( { @I18NMessage("grows") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE_GROWS =
"alert.condition.calltime-change.grows";
+
+ @I18NMessages( { @I18NMessage("shrinks") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE_SHRINKS =
"alert.condition.calltime-change.shrinks";
+
+ @I18NMessages( { @I18NMessage("changes") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE_CHANGES =
"alert.condition.calltime-change.changes";
+
+ // Calltime Metric Foo MAX (grows/shrinks/changes) by at least 1% with calltime
destination matching "*.txt"
+ @I18NMessages( { @I18NMessage("Calltime Metric {0} {1} {2} by at least {3} with
calltime destination matching \"{4}\"") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR =
"alert.condition.calltime-change-with-expr";
+
+ // Foo MAX (grows/shrinks/changes) by 1% matching "*.txt"
+ @I18NMessages( { @I18NMessage("{0} {1} {2} by {3} matching
\"{4}\"") /*, @I18NMessage(locale = "de", value = "")
*/})
+ String ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR_SHORT =
"alert.condition.calltime-change-with-expr.short";
+
+ // Calltime Metric Foo MAX (grows/shrinks/changes) by at least 1%
+ @I18NMessages( { @I18NMessage("Calltime Metric {0} {1} {2} by at least
{3}") /*, @I18NMessage(locale = "de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE = "alert.condition.calltime-change";
+
+ // Foo MAX (grows/shrinks/changes) by 1%
+ @I18NMessages( { @I18NMessage("{0} {1} {2} by {3}") /*, @I18NMessage(locale
= "de", value = "") */})
+ String ALERT_METRIC_CALLTIME_CHANGE_SHORT =
"alert.condition.calltime-change.short";
+
+ // Foo Value Changed
+ @I18NMessages( { @I18NMessage("{0} Value Changed"),
+ @I18NMessage(locale = "de", value = "{0} Der Wert hat sich
ge�ndert") })
+ String ALERT_METRIC_CHANGED = "alert.condition.metric.changed";
+
+ @I18NMessages( { @I18NMessage("{0} Val Chg"), @I18NMessage(locale =
"de", value = "{0} Wert�nd.") })
+ String ALERT_METRIC_CHANGED_SHORT =
"alert.condition.metric.changed.short";
+
+ @I18NMessages( { @I18NMessage("Operation [{0}] has status=[{1}]") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_OPERATION = "alert.condition.op";
+
+ @I18NMessages( { @I18NMessage("Op [{0}]={1}") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_OPERATION_SHORT = "alert.condition.op.short";
+
+ @I18NMessages( { @I18NMessage("Resource Configuration Changed") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_RESOURCECONFIGCHANGE = "alert.condition.resconfigchange";
+
+ @I18NMessages( { @I18NMessage("Res Config Chg") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_RESOURCECONFIGCHANGE_SHORT =
"alert.condition.resconfigchange.short";
+
+ @I18NMessages( { @I18NMessage("Event With Severity [{0}]") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_EVENT = "alert.condition.event";
+
+ // [WARN] Event
+ @I18NMessages( { @I18NMessage("[{0}] Event") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_EVENT_SHORT = "alert.condition.event.short";
+
+ @I18NMessages( { @I18NMessage("Event With Severity [{0}] Matching Expression
\"{1}\"") /*, @I18NMessage(locale = "de", value = "")
*/})
+ String ALERT_EVENT_WITH_EXPR = "alert.condition.event-with-expr";
- @I18NMessages( { @I18NMessage("between {0} and {1}, incl"),
- @I18NMessage(locale = "de", value = "zwischen {0} und {1},
paus") })
- String ALERT_CONFIG_PROPS_CB_INSIDE_INCL_RANGE_SHORT =
"alert.config.props.CB.InsideRange.incl.short";
+ @I18NMessages( { @I18NMessage("[{0}] Event Matching \"{1}\"") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_EVENT_WITH_EXPR_SHORT =
"alert.condition.event-with-expr.short";
- @I18NMessages( { @I18NMessage("value is between {0} and {1}, exclusive"),
- @I18NMessage(locale = "de", value = "Der Wert zwischen {0} und
{1}, exklusiv") })
- String ALERT_CONFIG_PROPS_CB_INSIDE_EXCL_RANGE =
"alert.config.props.CB.InsideRange.excl";
+ @I18NMessages( { @I18NMessage("Drift Detected") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_DRIFT = "alert.condition.drift";
- @I18NMessages( { @I18NMessage("between {0} and {1}, excl"),
- @I18NMessage(locale = "de", value = "zwischen {0} und {1},
exkl.") })
- String ALERT_CONFIG_PROPS_CB_INSIDE_EXCL_RANGE_SHORT =
"alert.config.props.CB.InsideRange.excl.short";
+ @I18NMessages( { @I18NMessage("Drift!") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_DRIFT_SHORT = "alert.condition.drift.short";
- @I18NMessages( { @I18NMessage("value is outside {0} and {1}, inclusive"),
- @I18NMessage(locale = "de", value = "Der Wert außerhalb {0} und
{1}, pauschal") })
- String ALERT_CONFIG_PROPS_CB_OUTSIDE_INCL_RANGE =
"alert.config.props.CB.OutsideRange.incl";
+ @I18NMessages( { @I18NMessage("Drift detected for files that match
\"{0}\" and for drift configuration [{1}]") /*, @I18NMessage(locale =
"de", value = "") */})
+ String ALERT_DRIFT_CONFIGPATHS = "alert.condition.drift.configpaths";
- @I18NMessages( { @I18NMessage("outside {0} and {1}, incl"),
- @I18NMessage(locale = "de", value = "außerhalb {0} und {1},
paus") })
- String ALERT_CONFIG_PROPS_CB_OUTSIDE_INCL_RANGE_SHORT =
"alert.config.props.CB.OutsideRange.incl.short";
+ @I18NMessages( { @I18NMessage("Drift matching \"{0}\",
config=[{1}]") /*, @I18NMessage(locale = "de", value = "") */})
+ String ALERT_DRIFT_CONFIGPATHS_SHORT =
"alert.condition.drift.configpaths.short";
- @I18NMessages( { @I18NMessage("value is outside {0} and {1}, exclusive"),
- @I18NMessage(locale = "de", value = "Der Wert außerhalb {0} und
{1}, exklusiv") })
- String ALERT_CONFIG_PROPS_CB_OUTSIDE_EXCL_RANGE =
"alert.config.props.CB.OutsideRange.excl";
+ @I18NMessages( { @I18NMessage("Drift detected for drift configuration
[{0}]") /*, @I18NMessage(locale = "de", value = "") */})
+ String ALERT_DRIFT_ONLYCONFIG = "alert.condition.drift.onlyconfig";
- @I18NMessages( { @I18NMessage("outside {0} and {1}, excl"),
- @I18NMessage(locale = "de", value = "außerhalb {0} und {1},
exkl") })
- String ALERT_CONFIG_PROPS_CB_OUTSIDE_EXCL_RANGE_SHORT =
"alert.config.props.CB.OutsideRange.excl.short";
+ @I18NMessages( { @I18NMessage("Drift! config=[{0}]") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_DRIFT_ONLYCONFIG_SHORT =
"alert.condition.drift.onlyconfig.short";
- @I18NMessages( { @I18NMessage("Drift detected"), @I18NMessage(locale =
"de", value = "Änderung erkannt") })
- String ALERT_CONFIG_PROPS_CB_DRIFT = "alert.config.props.CB.Drift";
+ @I18NMessages( { @I18NMessage("Drift detected for files that match
\"{0}\"") /*, @I18NMessage(locale = "de", value = "")
*/})
+ String ALERT_DRIFT_ONLYPATHS = "alert.condition.drift.onlypaths";
- @I18NMessages( { @I18NMessage("Drift detected"), @I18NMessage(locale =
"de", value = "Änderung erkannt") })
- String ALERT_CONFIG_PROPS_CB_DRIFT_SHORT =
"alert.config.props.CB.Drift.short";
+ @I18NMessages( { @I18NMessage("Drift matching \"{0}\"") /*,
@I18NMessage(locale = "de", value = "") */})
+ String ALERT_DRIFT_ONLYPATHS_SHORT =
"alert.condition.drift.onlypaths.short";
- @I18NMessages( { @I18NMessage("Availability goes {0}"),
- @I18NMessage(locale = "de", value = "Verf�gbarkeit wird {0}")
})
- String ALERT_CONFIG_PROPS_CB_AVAILABILITY =
"alert.config.props.CB.Availability";
+ // Foo Value is Between 1.0B and 2.0B, Inclusive
+ @I18NMessages( { @I18NMessage("{0} Value is Between {1} and {2},
Inclusive"),
+ @I18NMessage(locale = "de", value = "{0} Der Wert zwischen {1} und
{2}, pauschal") })
+ String ALERT_RANGE_INSIDE_INCL = "alert.condition.range.in.incl";
- @I18NMessages( { @I18NMessage("Avail goes {0}"), @I18NMessage(locale =
"de", value = "Verf. wird {0}") })
- String ALERT_CONFIG_PROPS_CB_AVAILABILITY_SHORT =
"alert.config.props.CB.Availability.short";
+ @I18NMessages( { @I18NMessage("{0} Between {1} - {2}, incl"),
+ @I18NMessage(locale = "de", value = "{0} zwischen {1} und {2},
paus") })
+ String ALERT_RANGE_INSIDE_INCL_SHORT =
"alert.condition.range.in.incl.short";
- @I18NMessages( { @I18NMessage("Event Severity: {0}"),
- @I18NMessage(locale = "de", value = "Schwere des Ereignesses:
{0}") })
- String ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY =
"alert.config.props.CB.EventSeverity";
+ @I18NMessages( { @I18NMessage("{0} Value is Between {1} and {2},
Exclusive"),
+ @I18NMessage(locale = "de", value = "{0} Der Wert zwischen {1} und
{2}, exklusiv") })
+ String ALERT_RANGE_INSIDE_EXCL = "alert.condition.range.in.excl";
- @I18NMessages( { @I18NMessage("Sev: {0}"), @I18NMessage(locale =
"de", value = "Schwere: {0}") })
- String ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_SHORT =
"alert.config.props.CB.EventSeverity.short";
+ @I18NMessages( { @I18NMessage("{0} Between {1} - {2}, excl"),
+ @I18NMessage(locale = "de", value = "{0} zwischen {1} - {2},
exkl.") })
+ String ALERT_RANGE_INSIDE_EXCL_SHORT =
"alert.condition.range.in.excl.short";
- @I18NMessages( { @I18NMessage("Event Severity: {0} and matching expression
\"{1}\""),
- @I18NMessage(locale = "de", value = "Schwere des Ereignesses: {0}
und zugeh�riger Ausdruck \"{1}\"") })
- String ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_REGEX_MATCH =
"alert.config.props.CB.EventSeverity.RegexMatch";
+ @I18NMessages( { @I18NMessage("{0} Value is Outside {1} and {2},
Inclusive"),
+ @I18NMessage(locale = "de", value = "{0} Der Wert außerhalb {1}
und {2}, pauschal") })
+ String ALERT_RANGE_OUTSIDE_INCL = "alert.condition.range.out.incl";
- @I18NMessages( { @I18NMessage("Sev: {0} & exp \"{1}\""),
- @I18NMessage(locale = "de", value = "Schwere: {0} & Ausdruck
\"{1}\"") })
- String ALERT_CONFIG_PROPS_CB_EVENT_SEVERITY_REGEX_MATCH_SHORT =
"alert.config.props.CB.EventSeverity.RegexMatch.short";
+ @I18NMessages( { @I18NMessage("{0} Outside {1} - {2}, incl"),
+ @I18NMessage(locale = "de", value = "{0} außerhalb {1} und {2},
paus") })
+ String ALERT_RANGE_OUTSIDE_INCL_SHORT =
"alert.condition.range.out.incl.short";
- @I18NMessages( { @I18NMessage("value changed"), @I18NMessage(locale =
"de", value = "Der Wert hat sich ge�ndert") })
- String ALERT_CURRENT_LIST_VALUE_CHANGED =
"alert.current.list.ValueChanged";
+ @I18NMessages( { @I18NMessage("{0} Value is Outside {1} and {2},
Exclusive"),
+ @I18NMessage(locale = "de", value = "{0} Der Wert außerhalb {1}
und {2}, exklusiv") })
+ String ALERT_RANGE_OUTSIDE_EXCL = "alert.condition.range.out.excl";
- @I18NMessages( { @I18NMessage("val chg"), @I18NMessage(locale =
"de", value = "Wert�nd.") })
- String ALERT_CURRENT_LIST_VALUE_CHANGED_SHORT =
"alert.current.list.ValueChanged.short";
+ @I18NMessages( { @I18NMessage("{0} Outside {1} - {2}, excl"),
+ @I18NMessage(locale = "de", value = "{0} außerhalb {1} und {2},
exkl") })
+ String ALERT_RANGE_OUTSIDE_EXCL_SHORT =
"alert.condition.range.out.excl.short";
@I18NMessages( {
@I18NMessage("\\ - Condition {0}: {1}\\n\\\n" + "\\ - Date/Time:
{2}\\n\\\n" + "\\ - Details: {3}\\n\\\n"),
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
new file mode 100644
index 0000000..7f502f5
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
@@ -0,0 +1,370 @@
+package org.rhq.enterprise.server.alert.test;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.alert.Alert;
+import org.rhq.core.domain.alert.AlertCondition;
+import org.rhq.core.domain.alert.AlertConditionCategory;
+import org.rhq.core.domain.alert.AlertConditionLog;
+import org.rhq.core.domain.event.EventSeverity;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.measurement.MeasurementUnits;
+import org.rhq.core.domain.measurement.NumericType;
+import org.rhq.core.domain.operation.OperationRequestStatus;
+import org.rhq.core.domain.resource.ResourceCategory;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.enterprise.server.alert.AlertManagerBean;
+
+@Test
+public class AlertManagerBeanTest {
+
+ private String pretty;
+
+ public void testPrettyPrintAVAILABILITY() {
+ AlertCondition condition = createCondition(AlertConditionCategory.AVAILABILITY,
null, null, null,
+ AvailabilityType.UP.name(), null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability goes UP".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail goes UP".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.AVAILABILITY, null, null,
null,
+ AvailabilityType.DOWN.name(), null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Availability goes DOWN".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Avail goes DOWN".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintTHRESHOLD() {
+ MeasurementDefinition md = createDynamicMeasurementDefinition();
+ AlertCondition condition = createCondition(AlertConditionCategory.THRESHOLD,
md.getDisplayName(), ">", 12.5d,
+ null, md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop > 12.5B".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop > 12.5B".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintTHRESHOLD_Calltime() {
+ MeasurementDefinition md = createCalltimeMeasurementDefinition();
+ String regex = "some.*(reg)?ex$"; // this is the "name" of
the condition
+
+ AlertCondition condition = createCondition(AlertConditionCategory.THRESHOLD,
regex, ">", 12.5d, "MAX", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MAX > 12.5B with calltime destination
matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MAX > 12.5B matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ // no regex
+ condition = createCondition(AlertConditionCategory.THRESHOLD, null,
">", 12.5d, "MAX", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MAX > 12.5B".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MAX > 12.5B".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintBASELINE() {
+ MeasurementDefinition md = createDynamicMeasurementDefinition();
+ AlertCondition condition = createCondition(AlertConditionCategory.BASELINE,
md.getDisplayName(), ">", 0.10d,
+ "mean", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% of Baseline Mean Value".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% bl mean".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.BASELINE, md.getDisplayName(),
">", 0.10d, "min", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% of Baseline Minimum Value".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% bl min".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.BASELINE, md.getDisplayName(),
">", 0.10d, "max", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% of Baseline Maximum Value".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop > 10.0% bl max".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintCHANGE() {
+ MeasurementDefinition md = createDynamicMeasurementDefinition();
+ AlertCondition condition = createCondition(AlertConditionCategory.CHANGE,
md.getDisplayName(), null, null,
+ null, md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop Value Changed".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop Val Chg".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintCHANGE_Calltime() {
+ MeasurementDefinition md = createCalltimeMeasurementDefinition();
+ String regex = "some.*(reg)?ex$"; // this is the "name" of
the condition
+
+ AlertCondition condition = createCondition(AlertConditionCategory.CHANGE, regex,
"LO", 0.10d, "MIN", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MIN shrinks by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MIN shrinks by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "CH",
0.10d, "MIN", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MIN changes by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MIN changes by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "HI",
0.10d, "MIN", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MIN grows by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MIN grows by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "LO",
0.10d, "MAX", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MAX shrinks by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MAX shrinks by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "CH",
0.10d, "MAX", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MAX changes by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MAX changes by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "HI",
0.10d, "MAX", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop MAX grows by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop MAX grows by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "LO",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG shrinks by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG shrinks by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "CH",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG changes by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG changes by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, regex, "HI",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG grows by at least 10.0% with calltime
destination matching \"some.*(reg)?ex$\""
+ .equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG grows by 10.0% matching
\"some.*(reg)?ex$\"".equals(pretty) : pretty;
+
+ // no regex
+ condition = createCondition(AlertConditionCategory.CHANGE, null, "LO",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG shrinks by at least
10.0%".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG shrinks by 10.0%".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, null, "CH",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG changes by at least
10.0%".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG changes by 10.0%".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CHANGE, null, "HI",
0.10d, "AVG", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Calltime Metric CT Prop AVG grows by at least
10.0%".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "CT Prop AVG grows by 10.0%".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintTRAIT() {
+ MeasurementDefinition md = createTraitMeasurementDefinition();
+ AlertCondition condition = createCondition(AlertConditionCategory.TRAIT,
md.getDisplayName(), null, null, null,
+ md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Blah Trait Value Changed".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Blah Trait Val Chg".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintCONTROL() {
+ AlertCondition condition = createCondition(AlertConditionCategory.CONTROL,
"opNameHere", null, null,
+ OperationRequestStatus.FAILURE.name(), null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Operation [opNameHere] has status=[FAILURE]".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Op [opNameHere]=FAILURE".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.CONTROL,
"opNameHere", null, null,
+ OperationRequestStatus.SUCCESS.name(), null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Operation [opNameHere] has status=[SUCCESS]".equals(pretty) :
pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Op [opNameHere]=SUCCESS".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintEVENT() {
+ String regex = "some.*(reg)?ex$";
+
+ AlertCondition condition = createCondition(AlertConditionCategory.EVENT,
EventSeverity.WARN.name(), null, null,
+ regex, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert ("Event With Severity [WARN] Matching Expression \"" +
regex + "\"").equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert ("[WARN] Event Matching \"" + regex +
"\"").equals(pretty) : pretty;
+
+ // no regex
+ condition = createCondition(AlertConditionCategory.EVENT,
EventSeverity.WARN.name(), null, null, null, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Event With Severity [WARN]".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "[WARN] Event".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintRESOURCECONFIG() {
+ AlertCondition condition =
createCondition(AlertConditionCategory.RESOURCE_CONFIG, null, null, null, null, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Resource Configuration Changed".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Res Config Chg".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintDRIFT() {
+ AlertCondition condition = createCondition(AlertConditionCategory.DRIFT,
"?riftName", null, null, "fil.*", null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Drift detected for files that match \"fil.*\" and for
drift configuration [?riftName]".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Drift matching \"fil.*\",
config=[?riftName]".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.DRIFT, null, null, null,
"fil.*", null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Drift detected for files that match
\"fil.*\"".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Drift matching \"fil.*\"".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.DRIFT, "?riftName",
null, null, null, null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Drift detected for drift configuration
[?riftName]".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Drift! config=[?riftName]".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.DRIFT, null, null, null, null,
null);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Drift Detected".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Drift!".equals(pretty) : pretty;
+ }
+
+ public void testPrettyPrintRANGE() {
+ MeasurementDefinition md = createDynamicMeasurementDefinition();
+ AlertCondition condition = createCondition(AlertConditionCategory.RANGE,
md.getDisplayName(), "<=", 1.0,
+ "22.2", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop Value is Between 1.0B and 22.2B,
Inclusive".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop Between 1.0B - 22.2B, incl".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.RANGE, md.getDisplayName(),
">=", 1.0, "22.2", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop Value is Outside 1.0B and 22.2B,
Inclusive".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop Outside 1.0B - 22.2B, incl".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.RANGE, md.getDisplayName(),
"<", 1.0, "22.2", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop Value is Between 1.0B and 22.2B,
Exclusive".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop Between 1.0B - 22.2B, excl".equals(pretty) : pretty;
+
+ condition = createCondition(AlertConditionCategory.RANGE, md.getDisplayName(),
">", 1.0, "22.2", md);
+ pretty = getPrettyAlertConditionString(condition);
+ assert "Foo Prop Value is Outside 1.0B and 22.2B,
Exclusive".equals(pretty) : pretty;
+ pretty = getShortPrettyAlertConditionString(condition);
+ assert "Foo Prop Outside 1.0B - 22.2B, excl".equals(pretty) : pretty;
+ }
+
+ private String getPrettyAlertConditionString(AlertCondition condition) {
+ AlertManagerBean pojo = new AlertManagerBean();
+ String s =
extractCondition(pojo.prettyPrintAlertConditions(createAlert(condition), false));
+ System.out.println("long===>" + s);
+ return s;
+ }
+
+ private String getShortPrettyAlertConditionString(AlertCondition condition) {
+ AlertManagerBean pojo = new AlertManagerBean();
+ String s =
extractCondition(pojo.prettyPrintAlertConditions(createAlert(condition), true));
+ System.out.println("short-->" + s);
+ return s;
+ }
+
+ private MeasurementDefinition createDynamicMeasurementDefinition() {
+ ResourceType resourceType = new ResourceType("testType",
"testPlugin", ResourceCategory.PLATFORM, null);
+ MeasurementDefinition md = new MeasurementDefinition(resourceType,
"fooMetric");
+ md.setDataType(DataType.MEASUREMENT);
+ md.setDisplayName("Foo Prop");
+ md.setMeasurementType(NumericType.DYNAMIC);
+ md.setRawNumericType(NumericType.DYNAMIC);
+ md.setUnits(MeasurementUnits.BYTES);
+ return md;
+ }
+
+ private MeasurementDefinition createCalltimeMeasurementDefinition() {
+ ResourceType resourceType = new ResourceType("testType",
"testPlugin", ResourceCategory.PLATFORM, null);
+ MeasurementDefinition md = new MeasurementDefinition(resourceType,
"ctMetric");
+ md.setDataType(DataType.CALLTIME);
+ md.setDisplayName("CT Prop");
+ md.setMeasurementType(NumericType.DYNAMIC);
+ md.setRawNumericType(NumericType.DYNAMIC);
+ md.setUnits(MeasurementUnits.BYTES);
+ md.setDestinationType("/wot gorilla");
+ return md;
+ }
+
+ private MeasurementDefinition createTraitMeasurementDefinition() {
+ ResourceType resourceType = new ResourceType("testType",
"testPlugin", ResourceCategory.PLATFORM, null);
+ MeasurementDefinition md = new MeasurementDefinition(resourceType,
"traitMetric");
+ md.setDataType(DataType.TRAIT);
+ md.setDisplayName("Blah Trait");
+ md.setUnits(MeasurementUnits.BYTES);
+ return md;
+ }
+
+ private Alert createAlert(AlertCondition condition) {
+ Alert alert = new Alert();
+ AlertConditionLog conditionLog = new AlertConditionLog(condition,
System.currentTimeMillis());
+ alert.addConditionLog(conditionLog);
+ return alert;
+ }
+
+ private AlertCondition createCondition(AlertConditionCategory category, String name,
String comparator,
+ Double threshold, String option, MeasurementDefinition measDef) {
+ AlertCondition condition = new AlertCondition();
+ condition.setCategory(category);
+ condition.setName(name);
+ condition.setComparator(comparator);
+ condition.setThreshold(threshold);
+ condition.setOption(option);
+ condition.setMeasurementDefinition(measDef);
+ return condition;
+ }
+
+ private String extractCondition(String prettyString) {
+ //System.out.println(prettyString);
+ Pattern pattern = Pattern.compile(" - Cond(?:ition)? 1: (.*)\n"); //
short form has " - Cond 1: ...", long form has " - Condition 1: ..."
+ Matcher matcher = pattern.matcher(prettyString);
+ assert matcher.find() : "could not find the condition string";
+ return matcher.group(1);
+ }
+}
commit 96f48b1cf1887376bb546cb120968f3696ed3a25
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Sep 15 12:49:13 2011 -0400
rename AlertManagerBeanTest to DeleteAlertsTest - it is still disabled, some other
test isn't cleaning up properly and causing bad data to be sitting in the DB that this
test fails on
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
deleted file mode 100644
index 41b902c..0000000
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/AlertManagerBeanTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 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.test;
-
-import java.sql.Connection;
-import java.util.List;
-
-import org.dbunit.database.DatabaseConnection;
-import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.dbunit.dataset.xml.FlatXmlProducer;
-import org.dbunit.operation.DatabaseOperation;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.xml.sax.InputSource;
-
-import org.rhq.core.domain.alert.AlertConditionLog;
-import org.rhq.core.domain.alert.notification.AlertNotificationLog;
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.enterprise.server.alert.AlertManagerLocal;
-import org.rhq.enterprise.server.test.AbstractEJB3Test;
-import org.rhq.enterprise.server.util.LookupUtil;
-
-/**
- * Test for {@link AlertManagerLocal} SLSB.
- */
-@Test(enabled = false)
-public class AlertManagerBeanTest extends AbstractEJB3Test {
- private AlertManagerLocal alertManager;
- private Subject superuser;
- private Resource newResource;
-
- @BeforeMethod
- public void beforeMethod() throws Exception {
- alertManager = LookupUtil.getAlertManager();
- superuser = LookupUtil.getSubjectManager().getOverlord();
-
- Connection connection = null;
-
- try {
- connection = getConnection();
- IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
- DatabaseOperation.CLEAN_INSERT.execute(dbUnitConnection, getDataSet());
- } finally {
- if (connection != null) {
- connection.close();
- }
- }
-
- newResource = getEntityManager().find(Resource.class, 1);
- }
-
- @AfterClass
- public void cleanupDB() throws Exception {
- if ("true".equals(System.getProperty("clean.db"))) {
- Connection connection = null;
-
- try {
- connection = getConnection();
- IDatabaseConnection dbUnitConnection = new
DatabaseConnection(connection);
- DatabaseOperation.DELETE_ALL.execute(dbUnitConnection, getDataSet());
- } finally {
- if (connection != null) {
- connection.close();
- }
- }
- }
- }
-
- IDataSet getDataSet() throws Exception {
- FlatXmlProducer xmlProducer = new FlatXmlProducer(new InputSource(getClass()
- .getResourceAsStream("AlertManagerBeanTest.xml")));
- xmlProducer.setColumnSensing(true);
- return new FlatXmlDataSet(xmlProducer);
- }
-
- public void deleteAlertsForResource() {
- assert 1 == alertManager.deleteAlertsByContext(superuser,
EntityContext.forResource(newResource.getId()));
- }
-
- @SuppressWarnings("unchecked")
- public void deleteAlertsForResourceTemplate() {
- int resourceTypeId = 1;
- int deletedCount = alertManager.deleteAlertsByContext(superuser,
EntityContext.forTemplate(resourceTypeId));
-
- List<AlertConditionLog> alertConditionLogs =
getEntityManager().createQuery(
- "from AlertConditionLog log where log.id = :id")
- .setParameter("id", 2)
- .getResultList();
-
- List<AlertNotificationLog> notificationLogs =
getEntityManager().createQuery(
- "from AlertNotificationLog log where log.id = :id")
- .setParameter("id", 2)
- .getResultList();
-
- assertEquals("Failed to delete alerts by template", 1, deletedCount);
- assertEquals("Failed to delete alert condition logs when deleting alerts by
template", 0,
- alertConditionLogs.size());
- assertEquals("Failed to delete alert notification logs when deleting alerts
by template", 0,
- notificationLogs.size());
- }
-
- public void testAlertDeleteInRange() {
- assert 2 == alertManager.deleteAlerts(0L, System.currentTimeMillis() + 600000L);
// go out into the future to make sure we get our alert
- }
-
-}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/DeleteAlertsTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/DeleteAlertsTest.java
new file mode 100644
index 0000000..f0ae1b5
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/alert/test/DeleteAlertsTest.java
@@ -0,0 +1,123 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 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.test;
+
+import java.sql.Connection;
+import java.util.List;
+
+import org.dbunit.database.DatabaseConnection;
+import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.dbunit.dataset.xml.FlatXmlProducer;
+import org.dbunit.operation.DatabaseOperation;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.xml.sax.InputSource;
+
+import org.rhq.core.domain.alert.AlertConditionLog;
+import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.enterprise.server.alert.AlertManagerLocal;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Test for {@link AlertManagerLocal} SLSB.
+ */
+@Test(enabled = false)
+public class DeleteAlertsTest extends AbstractEJB3Test {
+ private AlertManagerLocal alertManager;
+ private Subject superuser;
+ private Resource newResource;
+
+ @BeforeMethod
+ public void beforeMethod() throws Exception {
+ alertManager = LookupUtil.getAlertManager();
+ superuser = LookupUtil.getSubjectManager().getOverlord();
+
+ Connection connection = null;
+
+ try {
+ connection = getConnection();
+ IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
+ DatabaseOperation.CLEAN_INSERT.execute(dbUnitConnection, getDataSet());
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ newResource = getEntityManager().find(Resource.class, 1);
+ }
+
+ @AfterClass
+ public void cleanupDB() throws Exception {
+ if ("true".equals(System.getProperty("clean.db"))) {
+ Connection connection = null;
+
+ try {
+ connection = getConnection();
+ IDatabaseConnection dbUnitConnection = new
DatabaseConnection(connection);
+ DatabaseOperation.DELETE_ALL.execute(dbUnitConnection, getDataSet());
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+ }
+
+ IDataSet getDataSet() throws Exception {
+ FlatXmlProducer xmlProducer = new FlatXmlProducer(new
InputSource(getClass().getResourceAsStream(
+ "AlertManagerBeanTest.xml")));
+ xmlProducer.setColumnSensing(true);
+ return new FlatXmlDataSet(xmlProducer);
+ }
+
+ public void deleteAlertsForResource() {
+ assert 1 == alertManager.deleteAlertsByContext(superuser,
EntityContext.forResource(newResource.getId()));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void deleteAlertsForResourceTemplate() {
+ int resourceTypeId = 1;
+ int deletedCount = alertManager.deleteAlertsByContext(superuser,
EntityContext.forTemplate(resourceTypeId));
+
+ List<AlertConditionLog> alertConditionLogs =
getEntityManager().createQuery(
+ "from AlertConditionLog log where log.id =
:id").setParameter("id", 2).getResultList();
+
+ List<AlertNotificationLog> notificationLogs =
getEntityManager().createQuery(
+ "from AlertNotificationLog log where log.id =
:id").setParameter("id", 2).getResultList();
+
+ assertEquals("Failed to delete alerts by template", 1, deletedCount);
+ assertEquals("Failed to delete alert condition logs when deleting alerts by
template", 0, alertConditionLogs
+ .size());
+ assertEquals("Failed to delete alert notification logs when deleting alerts
by template", 0, notificationLogs
+ .size());
+ }
+
+ public void testAlertDeleteInRange() {
+ assert 2 == alertManager.deleteAlerts(0L, System.currentTimeMillis() + 600000L);
// go out into the future to make sure we get our alert
+ }
+
+}
\ No newline at end of file
commit ffd9aa174c13d42799d0002b73dfb8b90d178463
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Sep 15 12:48:26 2011 -0400
don't throw exception if a bad jobID is given, just log a message. this also fixes
an error in our unit tests that couldn't clean up
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java
index 9dbe236..4c007ae 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java
@@ -407,11 +407,15 @@ public class OperationManagerBean implements OperationManagerLocal,
OperationMan
}
public void deleteOperationScheduleEntity(ScheduleJobId jobId) {
- OperationScheduleEntity doomed = findOperationScheduleEntity(jobId);
- if (doomed != null) {
- LOG.debug("Deleting schedule entity: " + jobId);
- entityManager.remove(doomed);
- } else {
+ try {
+ OperationScheduleEntity doomed = findOperationScheduleEntity(jobId);
+ if (doomed != null) {
+ LOG.debug("Deleting schedule entity: " + jobId);
+ entityManager.remove(doomed);
+ } else {
+ LOG.info("Asked to delete unknown schedule - ignoring: " +
jobId);
+ }
+ } catch (NoResultException nre) {
LOG.info("Asked to delete unknown schedule - ignoring: " + jobId);
}
@@ -2106,7 +2110,7 @@ public class OperationManagerBean implements OperationManagerLocal,
OperationMan
}
private static void validateOperationNameAndParameters(ResourceType resourceType,
String operationName,
- Configuration parameters) {
+ Configuration parameters) {
Set<OperationDefinition> operationDefinitions =
resourceType.getOperationDefinitions();
OperationDefinition matchingOperationDefinition = null;
for (OperationDefinition operationDefinition : operationDefinitions) {
@@ -2117,14 +2121,14 @@ public class OperationManagerBean implements
OperationManagerLocal, OperationMan
}
if (matchingOperationDefinition == null) {
throw new IllegalArgumentException("[" + operationName
- + "] is not a valid operation name for Resources of type ["
+ resourceType.getName() + "]." );
+ + "] is not a valid operation name for Resources of type [" +
resourceType.getName() + "].");
}
- ConfigurationDefinition parametersDefinition =
- matchingOperationDefinition.getParametersConfigurationDefinition();
+ ConfigurationDefinition parametersDefinition = matchingOperationDefinition
+ .getParametersConfigurationDefinition();
List<String> errors =
ConfigurationUtility.validateConfiguration(parameters, parametersDefinition);
if (!errors.isEmpty()) {
- throw new IllegalArgumentException("Parameters for [" +
operationName
- + "] on Resource of type [" + resourceType.getName() +
"] are not valid: " + errors );
+ throw new IllegalArgumentException("Parameters for [" +
operationName + "] on Resource of type ["
+ + resourceType.getName() + "] are not valid: " + errors);
}
}