int scheduleId = changesComposite.getScheduleId();
MeasurementDataNumeric numeric = measurementDataManager.getCurrentNumericForSchedule(scheduleId);
try {
MeasurementNumericCacheElement cacheElement = new MeasurementNumericCacheElement(
alertConditionOperator, (numeric == null) ? null : numeric.getValue(), alertConditionId);
addTo("measurementDataCache", measurementDataCache, scheduleId, cacheElement, alertConditionId, stats);
} catch (InvalidCacheElementException icee) {
log.info("Failed to create MeasurementNumericCacheElement with parameters: "
+ AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
null, numeric, icee));
}
} else if (alertConditionCategory == AlertConditionCategory.TRAIT) {
AlertConditionTraitCategoryComposite traitsComposite = (AlertConditionTraitCategoryComposite) composite;
String value = null;
switch (alertConditionOperator) {
case CHANGES:
value = traitsComposite.getValue();
break;
case REGEX:
value = traitsComposite.getCondition().getOption();
break;
default:
log.error("Invalid operator for Trait condition: " + alertConditionOperator);
}
try {
/*
* don't forget special defensive handling to allow for null trait calculation;
* this might happen if a newly committed resource has some alert template applied to
* it for some trait that it has not yet gotten from the agent
*/
MeasurementTraitCacheElement cacheElement = new MeasurementTraitCacheElement(alertConditionOperator,
value, alertConditionId);
addTo("measurementTraitCache", measurementTraitCache, traitsComposite.getScheduleId(), cacheElement,
alertConditionId, stats);
} catch (InvalidCacheElementException icee) {
log.info("Failed to create MeasurementTraitCacheElement with parameters: "
+ AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
null, value, icee));
}
} else if (alertConditionCategory == AlertConditionCategory.THRESHOLD) {
AlertConditionScheduleCategoryComposite thresholdComposite = (AlertConditionScheduleCategoryComposite) composite;
Double thresholdValue = alertCondition.getThreshold();
MeasurementNumericCacheElement cacheElement = null;
try {
cacheElement = new MeasurementNumericCacheElement(alertConditionOperator, thresholdValue,
alertConditionId);
} catch (InvalidCacheElementException icee) {
log.info("Failed to create MeasurementNumericCacheElement with parameters: "
+ AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
null, thresholdValue, icee));
}
if (cacheElement != null) {
addTo("measurementDataCache", measurementDataCache, thresholdComposite.getScheduleId(), cacheElement,
alertConditionId, stats);
}
} else if (alertConditionCategory == AlertConditionCategory.EVENT) {
AlertConditionEventCategoryComposite eventComposite = (AlertConditionEventCategoryComposite) composite;
EventSeverity eventSeverity = EventSeverity.valueOf(alertCondition.getName());
String eventDetails = alertCondition.getOption();
EventCacheElement cacheElement = null;
try {
if (eventDetails == null) {
cacheElement = new EventCacheElement(alertConditionOperator, eventSeverity, alertConditionId);
} else {
String regexEventDetails = "", regexSourceLocation = "";
if (eventDetails.contains(AlertCondition.ADHOC_SEPARATOR)) {
String[] regexes = eventDetails.split(AlertCondition.ADHOC_SEPARATOR);
if (regexes.length > 0) {
regexEventDetails = regexes[0];
if (regexes.length > 1) {
regexSourceLocation = regexes[1];
}
}
} else {
regexEventDetails = eventDetails; // let's keep backward compatibility here, because there may be REST
// clients using the old approach
}
cacheElement = new EventCacheElement(alertConditionOperator, eventDetails, regexEventDetails,
regexSourceLocation, eventSeverity, alertConditionId);
}
} catch (InvalidCacheElementException icee) {
log.info("Failed to create EventCacheElement with parameters: "
+ AlertConditionCacheUtils.getCacheElementErrorString(alertConditionId, alertConditionOperator,
eventDetails, eventSeverity, icee));
}
addTo("eventsCache", eventsCache, eventComposite.getResourceId(), cacheElement, alertConditionId, stats);
} else if (alertConditionCategory == AlertConditionCategory.DRIFT) {
AlertConditionDriftCategoryComposite driftComposite = (AlertConditionDriftCategoryComposite) composite;
String driftDefNameRegexStr = driftComposite.getCondition().getName();
String driftPathNameRegexStr = driftComposite.getCondition().getOption();
DriftCacheElement cacheElement = null;
try {
cacheElement = new DriftCacheElement(alertConditionOperator, driftDefNameRegexStr,
driftPathNameRegexStr, alertConditionId);
} catch (InvalidCacheElementException icee) {
log.info("Failed to create DriftCacheElement: id=" + alertConditionId + ", operator="
+ alertConditionOperator + ", driftDefNameRegex=" + driftDefNameRegexStr + ", driftPathNameRegex="
+ driftPathNameRegexStr);
}
addTo("driftCache", driftCache, driftComposite.getResourceId(), cacheElement, alertConditionId, stats);
} else if (alertConditionCategory == AlertConditionCategory.RANGE) {
AlertConditionRangeCategoryComposite rangeComposite = (AlertConditionRangeCategoryComposite) composite;
Double loValue = alertCondition.getThreshold();
String hiValueStr = alertCondition.getOption();
MeasurementNumericCacheElement cacheElement = null;
try {
if (hiValueStr == null) {
throw new NumberFormatException("The range alert condition is missing the high value");
}
Double hiValue = Double.valueOf(hiValueStr);