Skip to content

Commit

Permalink
Merge pull request #10 from hawkular/jshaughn/data-insert
Browse files Browse the repository at this point in the history
Jshaughn/data insert
  • Loading branch information
jshaughn committed Feb 10, 2015
2 parents 79211a6 + eba5627 commit 2e41d0c
Show file tree
Hide file tree
Showing 15 changed files with 1,350 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
public class Alert {

private String triggerId;
private List<Set<ConditionEval>> evals;
private List<Set<ConditionEval>> evalSets;
private long time;

public Alert(String triggerId, List<Set<ConditionEval>> evals) {
public Alert(String triggerId, List<Set<ConditionEval>> evalSets) {
this.triggerId = triggerId;
this.evals = evals;
this.evalSets = evalSets;
this.time = System.currentTimeMillis();
}

public List<Set<ConditionEval>> getEvals() {
return evals;
public List<Set<ConditionEval>> getEvalSets() {
return evalSets;
}

public void setEvals(List<Set<ConditionEval>> evals) {
this.evals = evals;
public void setEvalSets(List<Set<ConditionEval>> evalSets) {
this.evalSets = evalSets;
}

public long getTime() {
Expand All @@ -69,7 +69,7 @@ public boolean equals(Object o) {
Alert alert = (Alert) o;

if (time != alert.time) return false;
if (evals != null ? !evals.equals(alert.evals) : alert.evals != null) return false;
if (evalSets != null ? !evalSets.equals(alert.evalSets) : alert.evalSets != null) return false;
if (triggerId != null ? !triggerId.equals(alert.triggerId) : alert.triggerId != null) return false;

return true;
Expand All @@ -78,14 +78,14 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = triggerId != null ? triggerId.hashCode() : 0;
result = 31 * result + (evals != null ? evals.hashCode() : 0);
result = 31 * result + (evalSets != null ? evalSets.hashCode() : 0);
result = 31 * result + (int) (time ^ (time >>> 32));
return result;
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public boolean match(String value) {
case CONTAINS:
return value.contains(pattern);
case MATCH:
return value.matches(pattern);
return value.matches(ignoreCase ? ("(?i)" + pattern) : pattern);
default:
msgLog.warnUnknowOperatorOnCondition(operator.name(), this.getClass().getName());
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public boolean match(double value) {
return false;
}

if (!aboveLow && inRange) {
return false;
if (!aboveLow) {
return inRange ? false : true;
}

switch (operatorHigh) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.hawkular.alerts.api.model.dampening;

import org.hawkular.alerts.api.model.condition.ConditionEval;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hawkular.alerts.api.model.condition.ConditionEval;

/**
* A representation of dampening status.
*
Expand Down Expand Up @@ -51,6 +51,40 @@ public Dampening() {
this("Default", Type.RELAXED_COUNT, 0, 0, 0);
}

/**
* Fire if we have <code>numTrueEvals</code> consecutive true evaluations of the condition set.
* @param triggerId
* @param numConsecutiveTrueEvals
* @return
*/
static public Dampening forStrict(String triggerId, int numConsecutiveTrueEvals) {
return new Dampening(triggerId, Type.STRICT, numConsecutiveTrueEvals, numConsecutiveTrueEvals, 0);
}

/**
* Fire if we have <code>numTrueEvals</code> of the condition set out of <code>numTotalEvals</code>.
* @param triggerId
* @param numTrueEvals
* @param numTotalEvals
* @return
*/
static public Dampening forRelaxedCount(String triggerId, int numTrueEvals, int numTotalEvals) {
return new Dampening(triggerId, Type.RELAXED_COUNT, numTrueEvals, numTotalEvals, 0);
}

/**
* Fire if we have <code>numTrueEvals</code> of the condition set within <code>evalTimeSetting</code>.
* @param triggerId
* @param numTrueEvals
* @param evalPeriod Elapsed real time, in milliseconds. In other words, this is not measured against
* collectionTimes (i.e. the timestamp on the data) but rather the evaluation times.
* evaluation times.
* @return
*/
static public Dampening forRelaxedTime(String triggerId, int numTrueEvals, long evalPeriod) {
return new Dampening(triggerId, Type.RELAXED_TIME, numTrueEvals, 0, evalPeriod);
}

public Dampening(String triggerId, Type type, int evalTrueSetting, int evalTotalSetting, long evalTimeSetting) {
super();
this.triggerId = triggerId;
Expand Down Expand Up @@ -138,8 +172,11 @@ public boolean isSatisfied() {
return satisfied;
}

/**
* @return a safe, but not deep, copy of the satisfying evals List
*/
public List<Set<ConditionEval>> getSatisfyingEvals() {
return satisfyingEvals;
return new ArrayList<Set<ConditionEval>>(satisfyingEvals);
}

public void addSatisfyingEvals(Set<ConditionEval> satisfyingEvals) {
Expand Down Expand Up @@ -240,7 +277,8 @@ public String log() {
@Override
public String toString() {
return "Dampening [triggerId=" + triggerId + ", type=" + type + ", evalTrueSetting=" + evalTrueSetting
+ ", evalTotalSetting=" + evalTotalSetting + ", evalTimeSetting=" + evalTimeSetting + ", numTrueEvals="
+ ", evalTotalSetting=" + evalTotalSetting + ", evalTimeSetting=" + evalTimeSetting
+ ", numTrueEvals="
+ numTrueEvals + ", numEvals=" + numEvals + ", trueEvalsStartTime=" + trueEvalsStartTime
+ ", satisfied=" + satisfied + ", satisfyingEvals=" + satisfyingEvals + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,31 @@ public enum AvailabilityType {
UP, DOWN, UNAVAILABLE
}

private AvailabilityType value;

public Availability() {
this(null, 0, null);
this(null, 0, AvailabilityType.UP);
}

public Availability(String id, long timestamp, AvailabilityType value) {
super(id, timestamp);
this.value = value;
super(id, timestamp, (null == value) ? AvailabilityType.UP : value);
}

public AvailabilityType getValue() {
return value;
return (AvailabilityType) value;
}

public void setValue(AvailabilityType value) {
this.value = 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;

Availability that = (Availability) o;

if (value != that.value)
return false;

return true;
this.value = (null == value) ? AvailabilityType.UP : value;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
public String toString() {
return "Availability [id=" + id + ", timestamp=" + timestamp + ", value=" + value + "]";
}

@Override
public String toString() {
return "Availability [value=" + value + ", getId()=" + getId() + ", getTimestamp()=" + getTimestamp() + "]";
int compareValue(Object value1, Object value2) {
AvailabilityType v1 = (AvailabilityType) value1;
AvailabilityType v2 = (AvailabilityType) value2;
return v1.compareTo(v2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
* A base class for incoming data into alerts subsystem. All {@link Data} has an Id and a timestamp. The
* timestamp is used to ensure that data is time-ordered when being sent into the alerting engine. If
* not assigned the timestamp will be assigned to current time.
* <br/><br/>
* This provides a default implementation of {@link #compareTo(Data)}. Subclasses must Override this if
* they are unhappy with the Natural Ordering provided:
* Id asc, Timestamp asc, Value asc
*
* @author Jay Shaughnessy
* @author Lucas Ponce
*/
public class Data {

private String id;
private long timestamp;
public abstract class Data implements Comparable<Data> {
protected String id;
protected long timestamp;
protected Object value;

public Data() {
/*
Expand All @@ -40,9 +44,10 @@ public Data() {
* @param id not null.
* @param timestamp if <=0 assigned currentTime.
*/
public Data(String id, long timestamp) {
public Data(String id, long timestamp, Object value) {
this.id = id;
this.timestamp = (timestamp <= 0) ? System.currentTimeMillis() : timestamp;
this.value = value;
}

public String getId() {
Expand All @@ -64,6 +69,24 @@ public void setTimestamp(long timestamp) {
this.timestamp = (timestamp <= 0) ? System.currentTimeMillis() : timestamp;
}

public Object getValue() {
return value;
}

public void setValue(Object value) {
this.value = value;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand All @@ -80,21 +103,39 @@ public boolean equals(Object obj) {
return false;
if (timestamp != other.timestamp)
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
return result;
public String toString() {
return "Data [id=" + id + ", timestamp=" + timestamp + ", value=" + value + "]";
}

@Override
public String toString() {
return "Data [id=" + id + ", timestamp=" + timestamp + "]";
public int compareTo(Data o) {
int c = this.id.compareTo(o.id);
if (0 != c)
return c;

c = Long.compare(this.timestamp, o.timestamp);
if (0 != c)
return c;

return compareValue(this.value, o.value);
}

/**
* Subclasses must provide the natural comparison of their value type. Or, override {@link #compare(Data, Data)}
* completely.
* @param value1
* @param value2
* @return standard -1, 0, 1 compare value
*/
abstract int compareValue(Object value1, Object value2);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,35 @@
*/
public class NumericData extends Data {

private Double value;

public NumericData() {
/*
Default constructor is needed for JSON libraries in JAX-RS context.
*/
this(null, 0, null);
this(null, 0, Double.NaN);
}

public NumericData(String id, long timestamp, Double value) {
super(id, timestamp);
this.value = value;
super(id, timestamp, (null == value) ? Double.NaN : value);
}

public Double getValue() {
return value;
return (Double) value;
}

public void setValue(Double value) {
this.value = value;
super.setValue(null == value ? Double.NaN : 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;

NumericData that = (NumericData) o;

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

return true;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
public String toString() {
return "NumericData [id=" + id + ", timestamp=" + timestamp + ", value=" + value + "]";
}

@Override
public String toString() {
return "NumericData [value=" + value + ", getId()=" + getId() + ", getTimestamp()=" + getTimestamp() + "]";
int compareValue(Object value1, Object value2) {
Double v1 = (Double) value1;
Double v2 = (Double) value2;
return v1.compareTo(v2);
}

}
Loading

0 comments on commit 2e41d0c

Please sign in to comment.