Skip to content

Commit

Permalink
Add Data timestamps to allow time-ordered insertions. May also help with
Browse files Browse the repository at this point in the history
potential temporal reasoning, correlation, and more robust notification. The
timestamps are supplied by the app sending the Data and will default to
system time.
Also:
- Change XxxConditionEval constructors to pass in the relevant Data objects.
  A little cleaner in the rules, and a bit more flexible.
- update and standardize the model's toString() impls given the new fields
  and variations in the previous impls. Used Eclipse's generator.
- update equals/hashcode impls due to field additions. Used Eclipse generators.
  • Loading branch information
jshaughn committed Feb 4, 2015
1 parent 708175c commit 65f322e
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public int hashCode() {

@Override
public String toString() {
return "Alert{" +
"evals=" + evals +
", triggerId='" + triggerId + '\'' +
", time=" + time +
'}';
return "Alert [triggerId=" + triggerId + ", evals=" + evals + ", time=" + time + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ public int hashCode() {

@Override
public String toString() {
return "AvailabilityCondition{conditionId='" + conditionId + '\'' +
", dataId='" + dataId + '\'' +
", operator=" + operator +
'}';
return "AvailabilityCondition [dataId=" + dataId + ", operator=" + operator + ", toString()="
+ super.toString() + "]";
}

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

import org.hawkular.alerts.api.model.data.Availability;
import org.hawkular.alerts.api.model.data.Availability.AvailabilityType;

/**
Expand All @@ -30,15 +31,15 @@ public class AvailabilityConditionEval extends ConditionEval {
private AvailabilityType value;

public AvailabilityConditionEval() {
super(false);
super(false, 0);
this.condition = null;
this.value = null;
}

public AvailabilityConditionEval(AvailabilityCondition condition, AvailabilityType value) {
super(condition.match(value));
public AvailabilityConditionEval(AvailabilityCondition condition, Availability avail) {
super(condition.match(avail.getValue()), avail.getTimestamp());
this.condition = condition;
this.value = value;
this.value = avail.getValue();
}

public AvailabilityCondition getCondition() {
Expand Down Expand Up @@ -101,9 +102,8 @@ public int hashCode() {

@Override
public String toString() {
return "AvailabilityConditionEval{" +
"condition=" + condition +
", value=" + value +
'}';
return "AvailabilityConditionEval [condition=" + condition + ", value=" + value + ", toString()="
+ super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@ public int hashCode() {

@Override
public String toString() {
return "CompareCondition{conditionId='" + conditionId + '\'' +
"data1Id='" + data1Id + '\'' +
", operator=" + operator +
", data2Id='" + data2Id + '\'' +
", data2Multiplier=" + data2Multiplier +
'}';
return "CompareCondition [data1Id=" + data1Id + ", operator=" + operator + ", data2Id=" + data2Id
+ ", data2Multiplier=" + data2Multiplier + ", toString()=" + super.toString() + "]";
}

}
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.data.NumericData;

/**
* An evaluation state for compare condition.
*
Expand All @@ -29,17 +31,18 @@ public class CompareConditionEval extends ConditionEval {
private Double value2;

public CompareConditionEval() {
super(false);
super(false, 0);
this.condition = null;
this.value1 = null;
this.value2 = null;
}

public CompareConditionEval(CompareCondition condition, Double value1, Double value2) {
super(condition.match(value1, value2));
public CompareConditionEval(CompareCondition condition, NumericData data1, NumericData data2) {
super(condition.match(data1.getValue(), data2.getValue()),
((data1.getTimestamp() > data1.getTimestamp()) ? data1.getTimestamp() : data2.getTimestamp()));
this.condition = condition;
this.value1 = value1;
this.value2 = value2;
this.value1 = data1.getValue();
this.value2 = data2.getValue();
}

public CompareCondition getCondition() {
Expand Down Expand Up @@ -88,15 +91,21 @@ public String getLog() {

@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;

CompareConditionEval that = (CompareConditionEval) o;

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

return true;
}
Expand All @@ -112,10 +121,8 @@ public int hashCode() {

@Override
public String toString() {
return "CompareConditionEval{" +
"condition=" + condition +
", value1=" + value1 +
", value2=" + value2 +
'}';
return "CompareConditionEval [condition=" + condition + ", value1=" + value1 + ", value2=" + value2
+ ", toString()=" + super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ public int hashCode() {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ public abstract class ConditionEval {
// result of the condition evaluation
protected boolean match;
// time of condition evaluation (i.e. creation time)
protected long time;
protected long evalTimestamp;
// time stamped on the data used in the eval
protected long dataTimestamp;
// flag noting whether this condition eval was used in a tested Tuple and already applied to dampening
protected boolean used;

public ConditionEval(boolean match) {
public ConditionEval(boolean match, long dataTimestamp) {
this.match = match;
this.time = System.currentTimeMillis();
this.dataTimestamp = dataTimestamp;
this.evalTimestamp = System.currentTimeMillis();
this.used = false;
}

Expand All @@ -45,12 +48,20 @@ public void setMatch(boolean match) {
this.match = match;
}

public long getTime() {
return time;
public long getEvalTimestamp() {
return evalTimestamp;
}

public void setTime(long time) {
this.time = time;
public void setEvalTimestamp(long evalTimestamp) {
this.evalTimestamp = evalTimestamp;
}

public long getDataTimestamp() {
return dataTimestamp;
}

public void setDataTimestamp(long dataTimestamp) {
this.dataTimestamp = dataTimestamp;
}

public boolean isUsed() {
Expand All @@ -70,32 +81,40 @@ public void setUsed(boolean used) {
public abstract String getLog();

@Override
public boolean equals(Object o) {
if (this == o)
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (dataTimestamp ^ (dataTimestamp >>> 32));
result = prime * result + (int) (evalTimestamp ^ (evalTimestamp >>> 32));
result = prime * result + (match ? 1231 : 1237);
result = prime * result + (used ? 1231 : 1237);
return result;
}

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

ConditionEval that = (ConditionEval) o;

if (match != that.match)
if (getClass() != obj.getClass())
return false;
if (time != that.time)
ConditionEval other = (ConditionEval) obj;
if (dataTimestamp != other.dataTimestamp)
return false;
if (evalTimestamp != other.evalTimestamp)
return false;
if (match != other.match)
return false;
if (used != other.used)
return false;

return true;
}

@Override
public int hashCode() {
int result = (match ? 1 : 0);
result = 31 * result + (int) (time ^ (time >>> 32));
return result;
}

@Override
public String toString() {
return "ConditionEval [match=" + match + ", time=" + time + ", used=" + used + "]";
return "ConditionEval [match=" + match + ", evalTimestamp=" + evalTimestamp + ", dataTimestamp="
+ dataTimestamp + ", used=" + used + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ public int hashCode() {

@Override
public String toString() {
return "StringCondition{conditionId='" + conditionId + '\'' +
"dataId='" + dataId + '\'' +
", operator=" + operator +
", pattern='" + pattern + '\'' +
", ignoreCase=" + ignoreCase +
'}';
return "StringCondition [dataId=" + dataId + ", operator=" + operator + ", pattern=" + pattern
+ ", ignoreCase=" + ignoreCase + ", toString()=" + super.toString() + "]";
}

}
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.data.StringData;

/**
* An evaluation state for string condition.
*
Expand All @@ -28,15 +30,15 @@ public class StringConditionEval extends ConditionEval {
private String value;

public StringConditionEval() {
super(false);
super(false, 0);
this.condition = null;
this.value = null;
}

public StringConditionEval(StringCondition condition, String value) {
super(condition.match(value));
public StringConditionEval(StringCondition condition, StringData data) {
super(condition.match(data.getValue()), data.getTimestamp());
this.condition = condition;
this.value = value;
this.value = data.getValue();
}

public StringCondition getCondition() {
Expand Down Expand Up @@ -99,9 +101,8 @@ public int hashCode() {

@Override
public String toString() {
return "StringConditionEval{" +
"condition=" + condition +
", value='" + value + '\'' +
'}';
return "StringConditionEval [condition=" + condition + ", value=" + value + ", toString()=" + super.toString()
+ "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ public int hashCode() {

@Override
public String toString() {
return "ThresholdCondition{conditionId='" + conditionId + '\'' +
", dataId='" + dataId + '\'' +
", operator=" + operator +
", threshold=" + threshold +
'}';
return "ThresholdCondition [dataId=" + dataId + ", operator=" + operator + ", threshold=" + threshold
+ ", toString()=" + super.toString() + "]";
}

}
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.data.NumericData;

/**
* An evaluation state for threshold condition.
*
Expand All @@ -28,15 +30,15 @@ public class ThresholdConditionEval extends ConditionEval {
private Double value;

public ThresholdConditionEval() {
super(false);
super(false, 0);
this.condition = null;
this.value = null;
}

public ThresholdConditionEval(ThresholdCondition condition, Double value) {
super(condition.match(value));
public ThresholdConditionEval(ThresholdCondition condition, NumericData data) {
super(condition.match(data.getValue()), data.getTimestamp());
this.condition = condition;
this.value = value;
this.value = data.getValue();
}

public ThresholdCondition getCondition() {
Expand Down Expand Up @@ -99,9 +101,8 @@ public int hashCode() {

@Override
public String toString() {
return "ThresholdConditionEval{" +
"condition=" + condition +
", value=" + value +
'}';
return "ThresholdConditionEval [condition=" + condition + ", value=" + value + ", toString()="
+ super.toString() + "]";
}

}

0 comments on commit 65f322e

Please sign in to comment.