private static final Log log = LogFactory.getLog(AlertConditionCacheCoordinator.class);
public static AlertConditionOperator getAlertConditionOperator(AlertCondition alertCondition) {
AlertConditionCategory category = alertCondition.getCategory();
String name = alertCondition.getName();
String comparator = alertCondition.getComparator();
switch (category) {
case CONTROL:
// the UI currently only supports one operator for control
return AlertConditionOperator.EQUALS;
case EVENT:
// the UI currently only supports one operator for events
return AlertConditionOperator.GREATER_THAN_OR_EQUAL_TO;
case DRIFT:
// any drift that is detected infers a change to its previous state
return AlertConditionOperator.CHANGES;
case RESOURCE_CONFIG:
case CHANGE:
// the model currently supports CHANGE as a category type instead of a comparator
return AlertConditionOperator.CHANGES;
case TRAIT:
String regex = alertCondition.getOption();
return (null == regex || regex.isEmpty()) ? AlertConditionOperator.CHANGES : AlertConditionOperator.REGEX;
case AVAILABILITY: {
AlertConditionOperator operator = AlertConditionOperator.valueOf(name.toUpperCase());
switch (operator) {
case AVAIL_GOES_DISABLED:
case AVAIL_GOES_DOWN:
case AVAIL_GOES_UNKNOWN:
case AVAIL_GOES_UP:
case AVAIL_GOES_NOT_UP:
return operator;
default:
throw new UnsupportedAlertConditionOperatorException(
"Invalid alertConditionValue for AVAILABILITY category:" + operator);
}
}
case AVAIL_DURATION: {
AlertConditionOperator operator = AlertConditionOperator.valueOf(name.toUpperCase());
switch (operator) {
case AVAIL_DURATION_DOWN:
case AVAIL_DURATION_NOT_UP:
return operator;
default:
throw new UnsupportedAlertConditionOperatorException(
"Invalid alertConditionValue for AVAILABILITY_DURATION category:" + operator);
}
}
case RANGE:
// range can support <= and >=, which we look for here. It can also support < and >, which is checked down below further.
// note that RANGE does not support =, so we throw an exception if caller tries that
if (comparator.equals("<=")) {
return AlertConditionOperator.LESS_THAN_OR_EQUAL_TO;
} else if (comparator.equals(">=")) {
return AlertConditionOperator.GREATER_THAN_OR_EQUAL_TO;
} else if (comparator.equals("=")) {
throw new UnsupportedAlertConditionOperatorException("Comparator [" + comparator + "] "
+ "is not supported for category: " + category.name());
}
default:
if (comparator.equals("<")) {
return AlertConditionOperator.LESS_THAN;
} else if (comparator.equals(">")) {
return AlertConditionOperator.GREATER_THAN;
} else if (comparator.equals("=")) {
return AlertConditionOperator.EQUALS;
} else {
throw new UnsupportedAlertConditionOperatorException("Comparator [" + comparator + "] "
+ "is not supported for category: " + category.name());
}
}
}