Skip to content

Commit

Permalink
Potential model, API revisions for review (branched off trigger safet…
Browse files Browse the repository at this point in the history
…y PR)

** work in progress, compiling only **

- fix up some equals/hashcode logic
  - use Trigger.triggerId as unique key
    - make TriggerTemplate abstract and set match fields as transient
  - give Dampening a unique key: dampeningId

- Introduce trigger-granular reload so that changes to a trigger don't
  force a global reload but just a reload of the affected trigger.
  - add support in RulesEngine for get/removeFacts

- Various changes to definitions service
  - move torwards a more trigger-centric model
    - support full conditionSet replacement
  - introduce triggerMode into the api
  - use dampening's unique key
  - add jdoc

- DB table changes
  - introduce dampeningId into the tables
  - introduce triggerMode into the tables

- remove MemDefinitionsServiceImpl
  • Loading branch information
jshaughn committed Feb 25, 2015
1 parent 104e158 commit 3669fb4
Show file tree
Hide file tree
Showing 19 changed files with 796 additions and 990 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public enum Type {
private int evalTrueSetting;
private int evalTotalSetting;
private long evalTimeSetting;
/**
* A composed key for the dampening
*/
protected String dampeningId;

// The following fields are only relevant while the engine is executing.
private transient int numTrueEvals;
Expand Down Expand Up @@ -117,6 +121,7 @@ public Dampening(String triggerId, Mode triggerMode, Type type, int evalTrueSett
this.evalTotalSetting = evalTotalSetting;
this.evalTimeSetting = evalTimeSetting;
this.triggerMode = triggerMode;
updateId();

reset();
}
Expand All @@ -127,6 +132,16 @@ public String getTriggerId() {

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

public Mode getTriggerMode() {
return triggerMode;
}

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

public void setEvalTimeSetting(long evalTimeSetting) {
Expand Down Expand Up @@ -193,14 +208,6 @@ public long getEvalTimeSetting() {
return evalTimeSetting;
}

public Mode getTriggerMode() {
return triggerMode;
}

public void setTriggerMode(Mode triggerMode) {
this.triggerMode = triggerMode;
}

public boolean isSatisfied() {
return satisfied;
}
Expand Down Expand Up @@ -316,16 +323,21 @@ public String log() {
return sb.toString();
}

public String getDampeningId() {
return dampeningId;
}

private void updateId() {
StringBuilder sb = new StringBuilder(triggerId);
sb.append("-").append(triggerMode.name());
this.dampeningId = sb.toString();
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (evalTimeSetting ^ (evalTimeSetting >>> 32));
result = prime * result + evalTotalSetting;
result = prime * result + evalTrueSetting;
result = prime * result + ((triggerId == null) ? 0 : triggerId.hashCode());
result = prime * result + ((triggerMode == null) ? 0 : triggerMode.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((dampeningId == null) ? 0 : dampeningId.hashCode());
return result;
}

Expand All @@ -338,20 +350,10 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Dampening other = (Dampening) obj;
if (evalTimeSetting != other.evalTimeSetting)
return false;
if (evalTotalSetting != other.evalTotalSetting)
return false;
if (evalTrueSetting != other.evalTrueSetting)
return false;
if (triggerId == null) {
if (other.triggerId != null)
if (dampeningId == null) {
if (other.dampeningId != null)
return false;
} else if (!triggerId.equals(other.triggerId))
return false;
if (triggerMode != other.triggerMode)
return false;
if (type != other.type)
} else if (!dampeningId.equals(other.dampeningId))
return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public void setMatch(Match match) {
this.match = match;
}


@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (enabled ? 1231 : 1237);
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
Expand All @@ -121,13 +121,11 @@ public int hashCode() {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Trigger other = (Trigger) obj;
if (enabled != other.enabled)
return false;
if (id == null) {
if (other.id != null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@
* @author Jay Shaughnessy
* @author Lucas Ponce
*/
public class TriggerTemplate {
public abstract class TriggerTemplate {

public enum Match {
ALL, ANY
};

private String name;
private String description;
private Match firingMatch;
private Match safetyMatch;

/** A group of notifier's ids. */
private Set<String> notifiers;

private transient Match firingMatch;
private transient Match safetyMatch;

public TriggerTemplate(String name) {
this.name = name;

this.firingMatch = Match.ALL;
this.safetyMatch = Match.ALL;
this.notifiers = new HashSet();
Expand Down Expand Up @@ -109,43 +112,6 @@ public void removeNotifier(String id) {
notifiers.remove(id);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((firingMatch == null) ? 0 : firingMatch.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((safetyMatch == null) ? 0 : safetyMatch.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;
TriggerTemplate other = (TriggerTemplate) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (firingMatch != other.firingMatch)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (safetyMatch != other.safetyMatch)
return false;
return true;
}

@Override
public String toString() {
return "TriggerTemplate [name=" + name + ", description=" + description + ", firingMatch=" + firingMatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package org.hawkular.alerts.api.services;

import java.util.Collection;

import org.hawkular.alerts.api.model.condition.Alert;
import org.hawkular.alerts.api.model.data.Data;

import java.util.Collection;

/**
* Interface that allows to send data to the alerts engine and check resulting state.
*
Expand All @@ -30,18 +30,25 @@
public interface AlertsService {

void sendData(Data data);

void sendData(Collection<Data> data);

Collection<Alert> checkAlerts();

/**
* Reload all alerts definitions.
* Reset session state.
*/
void reload();
void clear();

/**
* Reset session state.
* Reload all Triggers.
*/
void clear();
void reload();

/**
* Reload the specified Trigger. Removes any existing definition from the engine. If enabled then loads the firing
* condition set and dampening. If safetyEnabled then also loads the safety condition set and dampening.
* @param triggerId
*/
void reloadTrigger(String triggerId);
}

0 comments on commit 3669fb4

Please sign in to comment.