Skip to content

Commit

Permalink
[HWKALERTS-2] rebase on master, fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jshaughn committed Feb 23, 2015
1 parent 86e78ed commit 0494d8d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class Condition {
/**
* A composed key for the condition
*/
protected String id;
protected String conditionId;

public Condition(String triggerId, Mode triggerMode, int conditionSetSize, int conditionSetIndex) {
this.triggerId = triggerId;
Expand Down Expand Up @@ -98,22 +98,22 @@ public void setTriggerMode(Mode triggerMode) {
}

public String getConditionId() {
return id;
return conditionId;
}

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();
this.conditionId = sb.toString();
}

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

Expand All @@ -126,10 +126,10 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Condition other = (Condition) obj;
if (id == null) {
if (other.id != null)
if (conditionId == null) {
if (other.conditionId != null)
return false;
} else if (!id.equals(other.id))
} else if (!conditionId.equals(other.conditionId))
return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public enum Type {
private int evalTotalSetting;
private long evalTimeSetting;

private int numTrueEvals;
private int numEvals;
private long trueEvalsStartTime;
private boolean satisfied;
private List<Set<ConditionEval>> satisfyingEvals = new ArrayList<Set<ConditionEval>>();
// The following fields are only relevant while the engine is executing.
private transient int numTrueEvals;
private transient int numEvals;
private transient long trueEvalsStartTime;
private transient boolean satisfied;
private transient List<Set<ConditionEval>> satisfyingEvals = new ArrayList<Set<ConditionEval>>();

public Dampening() {
this("Default", Mode.FIRE, Type.STRICT, 1, 1, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public enum Mode {
private boolean safetyEnabled;
private Mode mode;

private transient Match match;

public Trigger() {
/*
Default constructor is needed for JSON libraries in JAX-RS context.
Expand All @@ -51,6 +53,7 @@ public Trigger(String id, String name) {
this.enabled = false;
this.safetyEnabled = false;
this.mode = Mode.FIRE;
this.match = getFiringMatch();
}

public boolean isEnabled() {
Expand All @@ -75,6 +78,7 @@ public Mode getMode() {

public void setMode(Mode mode) {
this.mode = mode;
setMatch(this.mode == Mode.FIRE ? getFiringMatch() : getSafetyMatch());
}

/**
Expand All @@ -97,7 +101,11 @@ public void setSafetyEnabled(boolean safetyEnabled) {
}

public Match getMatch() {
return this.mode == Mode.FIRE ? getFiringMatch() : getSafetyMatch();
return match;
}

public void setMatch(Match match) {
this.match = match;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ private void initFiles(String folder) {
initNotifiers(initFolder);
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
e.printStackTrace();
}
msgLog.errorDatabaseException("Error initializing files. Msg: " + e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
# triggerId,conditionSetSize,conditionSetIndex,<type>
# <triggerId>,<triggerMode>,<conditionSetSize>,<conditionSetIndex>,<type>
# <type> == threshold
# ..., dataId,operator,value
#
trigger-1,1,1,threshold,NumericData-01,LT,10.0
trigger-2,2,1,threshold,NumericData-01,GTE,15.0
trigger-2,2,2,threshold,NumericData-02,GTE,15.0
trigger-1,FIRE,1,1,threshold,NumericData-01,LT,10.0
trigger-2,FIRE,2,1,threshold,NumericData-01,GTE,15.0
trigger-2,FIRE,2,2,threshold,NumericData-02,GTE,15.0
#
# <type> == range
# ...,dataId,operatorLow,operatorHigh,thresholdLow,thresholdHigh,inRange
#
trigger-3,1,1,range,NumericData-03,INCLUSIVE,INCLUSIVE,10.0,15.0,true
trigger-3,FIRE,1,1,range,NumericData-03,INCLUSIVE,INCLUSIVE,10.0,15.0,true
#
# <type> == compare
# ...,data1Id,operator,data2Multiplier,data2Id
#
trigger-4,1,1,compare,NumericData-01,LT,0.5,NumericData-02
trigger-4,FIRE,1,1,compare,NumericData-01,LT,0.5,NumericData-02
#
# <type> == string
# ...,dataId,operator,pattern,ignoreCase
#
trigger-5,1,1,string,StringData-01,STARTS_WITH,Fred,false
trigger-5,FIRE,1,1,string,StringData-01,STARTS_WITH,Fred,false
#
# <type> == availability
# ...,dataId,operator
#
trigger-6,1,1,availability,Availability-01,NOT_UP


trigger-6,FIRE,1,1,availability,Availability-01,NOT_UP
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# triggerId,type,evalTrueSetting,evalTotalSetting,evalTimeSetting
trigger-1,STRICT,2,2,0
# <triggerId>,<triggerMode>,<type>,<evalTrueSetting>,<evalTotalSetting>,<evalTimeSetting>
trigger-1,FIRE,STRICT,2,2,0
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# <triggerId>,<active>,<name>,<description>,<match>,<notifierId1>|<notifierId2>|<notifierId3>|...
trigger-1,true,NumericData-01-low,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-2,true,NumericData-01-02-high,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-3,true,NumericData-03-range,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-4,true,CompareData-01-d1-lthalf-d2,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-5,true,StringData-01-starts,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-6,true,Availability-01-NOT-UP,description,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
# <triggerId>,<enabled>,<safetyEnabled>,<name>,<description>,<firingMatch>,<safetyMatch>,<notifierId1>|<notifierId2>|<notifierId3>|...
trigger-1,true,false,NumericData-01-low,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-2,true,false,NumericData-01-02-high,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-3,true,false,NumericData-03-range,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-4,true,false,CompareData-01-d1-lthalf-d2,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-5,true,false,StringData-01-starts,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
trigger-6,true,false,Availability-01-NOT-UP,description,ALL,ALL,SNMP-Trap-1|SNMP-Trap-2|admin@email.com
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jboss.logging.Logger
import org.junit.Test

import org.hawkular.alerts.api.model.dampening.Dampening.Type
import org.hawkular.alerts.api.model.trigger.Trigger.Mode
import static org.junit.Assert.assertEquals

/**
Expand All @@ -45,7 +46,7 @@ class DampeningTest extends AbstractTestBase {

@Test
void createDampening() {
Dampening d = new Dampening("test-trigger-6", Type.RELAXED_COUNT, 1, 1, 1);
Dampening d = new Dampening("test-trigger-6", Mode.FIRE, Type.RELAXED_COUNT, 1, 1, 1);

def resp = client.post(path: "trigger/dampening", body: d)
assertEquals(200, resp.status)
Expand Down

0 comments on commit 0494d8d

Please sign in to comment.