Skip to content

Commit

Permalink
[HWKALERTS-2] Initial support for Trigger Safety Mode
Browse files Browse the repository at this point in the history
A Trigger can now be in FIRE mode or SAFETY mode. A Condition set and
Dampening can be defined for both modes on the same Trigger. Based on the
Trigger's current mode the relevant conditions and dampening will be used
for evaluations.
- introduce trigger mode across the various constructor/hashcode/equals/toStrings
- add safetyEnabled to indicate that safety conditions are set and enabled
- make ConditionEval.getLog() impls more verbose w/ timestamp info
- update the DB and File def service impls as needed
- add test code

ToDo: Currently satisfying the safety dampening only toggles the Trigger
      back to fire mode.  We need to discuss whether we should be generating
      an alert and/or performing actions.
  • Loading branch information
jshaughn committed Feb 17, 2015
1 parent 81f15f8 commit c4eafd3
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/
package org.hawkular.alerts.api.model.condition;

import static org.hawkular.alerts.api.model.trigger.Trigger.Mode.FIRE;

import org.hawkular.alerts.api.log.MsgLogger;
import org.hawkular.alerts.api.model.data.Availability.AvailabilityType;
import org.hawkular.alerts.api.model.trigger.Trigger.Mode;

/**
* An availability condition definition.
Expand All @@ -43,8 +46,13 @@ public AvailabilityCondition() {
}

public AvailabilityCondition(String triggerId, int conditionSetSize, int conditionSetIndex,
String dataId, Operator operator) {
super(triggerId, conditionSetSize, conditionSetIndex);
String dataId, Operator operator) {
this(triggerId, FIRE, conditionSetSize, conditionSetIndex, dataId, operator);
}

public AvailabilityCondition(String triggerId, Mode triggerMode, int conditionSetSize, int conditionSetIndex,
String dataId, Operator operator) {
super(triggerId, triggerMode, conditionSetSize, conditionSetIndex);
this.dataId = dataId;
this.operator = operator;
}
Expand Down Expand Up @@ -85,14 +93,19 @@ public boolean match(AvailabilityType value) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;

AvailabilityCondition that = (AvailabilityCondition) o;

if (dataId != null ? !dataId.equals(that.dataId) : that.dataId != null) return false;
if (operator != that.operator) return false;
if (dataId != null ? !dataId.equals(that.dataId) : that.dataId != null)
return false;
if (operator != that.operator)
return false;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,24 @@ public int getConditionSetIndex() {

@Override
public String getLog() {
return condition.getLog(value);
return condition.getLog(value) + ", evalTimestamp=" + evalTimestamp + ", dataTimestamp=" + dataTimestamp;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;

AvailabilityConditionEval that = (AvailabilityConditionEval) o;

if (condition != null ? !condition.equals(that.condition) : that.condition != null) return false;
if (value != that.value) return false;
if (condition != null ? !condition.equals(that.condition) : that.condition != null)
return false;
if (value != that.value)
return false;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.hawkular.alerts.api.model.condition;

import static org.hawkular.alerts.api.model.trigger.Trigger.Mode.FIRE;

import org.hawkular.alerts.api.log.MsgLogger;
import org.hawkular.alerts.api.model.trigger.Trigger.Mode;

/**
* A numeric comparison condition.
Expand Down Expand Up @@ -45,8 +48,13 @@ public CompareCondition() {
}

public CompareCondition(String triggerId, int conditionSetSize, int conditionSetIndex,
String data1Id, Operator operator, Double data2Multiplier, String data2Id) {
super(triggerId, conditionSetSize, conditionSetIndex);
String data1Id, Operator operator, Double data2Multiplier, String data2Id) {
this(triggerId, FIRE, conditionSetSize, conditionSetIndex, data1Id, operator, data2Multiplier, data2Id);
}

public CompareCondition(String triggerId, Mode triggerMode, int conditionSetSize, int conditionSetIndex,
String data1Id, Operator operator, Double data2Multiplier, String data2Id) {
super(triggerId, triggerMode, conditionSetSize, conditionSetIndex);
this.data1Id = data1Id;
this.operator = operator;
this.data2Id = data2Id;
Expand Down Expand Up @@ -110,17 +118,23 @@ public boolean match(double data1Value, double data2Value) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;

CompareCondition that = (CompareCondition) o;

if (data1Id != null ? !data1Id.equals(that.data1Id) : that.data1Id != null) return false;
if (data2Id != null ? !data2Id.equals(that.data2Id) : that.data2Id != null) return false;
if (data1Id != null ? !data1Id.equals(that.data1Id) : that.data1Id != null)
return false;
if (data2Id != null ? !data2Id.equals(that.data2Id) : that.data2Id != null)
return false;
if (data2Multiplier != null ? !data2Multiplier.equals(that.data2Multiplier) : that.data2Multiplier != null)
return false;
if (operator != that.operator) return false;
if (operator != that.operator)
return false;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public int getConditionSetIndex() {

@Override
public String getLog() {
return condition.getLog(value1, value2);
return condition.getLog(value1, value2) + ", evalTimestamp=" + evalTimestamp + ", dataTimestamp="
+ dataTimestamp;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.hawkular.alerts.api.model.trigger.Trigger.Mode;

/**
* A base class for condition definition.
*
Expand All @@ -29,6 +31,11 @@ public abstract class Condition {
*/
protected String triggerId;

/**
* The owning trigger's mode when this condition is active
*/
protected Mode triggerMode;

/**
* Number of conditions associated with a particular trigger.
* i.e. 2 [ conditions ]
Expand All @@ -42,15 +49,16 @@ public abstract class Condition {
protected int conditionSetIndex;

/**
* A composed key for conditionId
* A composed key for the condition
*/
protected String conditionId;
protected String id;

public Condition(String triggerId, int conditionSetSize, int conditionSetIndex) {
public Condition(String triggerId, Mode triggerMode, int conditionSetSize, int conditionSetIndex) {
this.triggerId = triggerId;
this.triggerMode = triggerMode;
this.conditionSetSize = conditionSetSize;
this.conditionSetIndex = conditionSetIndex;
this.conditionId = triggerId + "-" + conditionSetSize + "-" + conditionSetIndex;
updateId();
}

public int getConditionSetIndex() {
Expand All @@ -59,6 +67,7 @@ public int getConditionSetIndex() {

public void setConditionSetIndex(int conditionSetIndex) {
this.conditionSetIndex = conditionSetIndex;
updateId();
}

public int getConditionSetSize() {
Expand All @@ -67,6 +76,7 @@ public int getConditionSetSize() {

public void setConditionSetSize(int conditionSetSize) {
this.conditionSetSize = conditionSetSize;
updateId();
}

public String getTriggerId() {
Expand All @@ -75,43 +85,59 @@ public String getTriggerId() {

public void setTriggerId(String triggerId) {
this.triggerId = triggerId;
updateId();
}

public String getConditionId() {
conditionId = triggerId + "-" + conditionSetSize + "-" + conditionSetIndex;
return conditionId;
public Mode getTriggerMode() {
return triggerMode;
}

public void setConditionId(String conditionId) {
this.conditionId = conditionId;
public void setTriggerMode(Mode triggerMode) {
this.triggerMode = triggerMode;
updateId();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Condition condition = (Condition) o;

if (conditionSetIndex != condition.conditionSetIndex) return false;
if (conditionSetSize != condition.conditionSetSize) return false;
if (triggerId != null ? !triggerId.equals(condition.triggerId) : condition.triggerId != null) return false;
public String getConditionId() {
return id;
}

return true;
private void updateId() {
StringBuilder sb = new StringBuilder(triggerId);
sb.append("-").append(triggerMode.ordinal());
sb.append("-").append(conditionSetSize);
sb.append("-").append(conditionSetIndex);
this.id = sb.toString();
}

@Override
public int hashCode() {
int result = triggerId != null ? triggerId.hashCode() : 0;
result = 31 * result + conditionSetSize;
result = 31 * result + conditionSetIndex;
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Condition other = (Condition) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}

@Override
public String toString() {
return "Condition [triggerId=" + triggerId + ", conditionSetSize=" + conditionSetSize + ", conditionSetIndex="
+ conditionSetIndex + ", conditionId=" + conditionId + "]";
return "Condition [triggerId=" + triggerId + ", triggerMode=" + triggerMode + ", conditionSetSize="
+ conditionSetSize + ", conditionSetIndex=" + conditionSetIndex + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.hawkular.alerts.api.model.condition;

import org.hawkular.alerts.api.log.MsgLogger;
import org.hawkular.alerts.api.model.trigger.Trigger.Mode;

/**
* A string comparison condition.
Expand Down Expand Up @@ -44,8 +45,13 @@ public StringCondition() {
}

public StringCondition(String triggerId, int conditionSetSize, int conditionSetIndex,
String dataId, Operator operator, String pattern, boolean ignoreCase) {
super(triggerId, conditionSetSize, conditionSetIndex);
String dataId, Operator operator, String pattern, boolean ignoreCase) {
this(triggerId, Mode.FIRE, conditionSetSize, conditionSetIndex, dataId, operator, pattern, ignoreCase);
}

public StringCondition(String triggerId, Mode triggerMode, int conditionSetSize, int conditionSetIndex,
String dataId, Operator operator, String pattern, boolean ignoreCase) {
super(triggerId, triggerMode, conditionSetSize, conditionSetIndex);
this.dataId = dataId;
this.operator = operator;
this.pattern = pattern;
Expand Down Expand Up @@ -116,16 +122,23 @@ public boolean match(String value) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;

StringCondition that = (StringCondition) o;

if (ignoreCase != that.ignoreCase) return false;
if (dataId != null ? !dataId.equals(that.dataId) : that.dataId != null) return false;
if (operator != that.operator) return false;
if (pattern != null ? !pattern.equals(that.pattern) : that.pattern != null) return false;
if (ignoreCase != that.ignoreCase)
return false;
if (dataId != null ? !dataId.equals(that.dataId) : that.dataId != null)
return false;
if (operator != that.operator)
return false;
if (pattern != null ? !pattern.equals(that.pattern) : that.pattern != null)
return false;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public int getConditionSetIndex() {

@Override
public String getLog() {
return condition.getLog(value);
return condition.getLog(value) + ", evalTimestamp=" + evalTimestamp + ", dataTimestamp=" + dataTimestamp;
}

@Override
Expand Down

0 comments on commit c4eafd3

Please sign in to comment.