Skip to content

Commit

Permalink
Merge pull request #102 from jshaughn/jay-tags
Browse files Browse the repository at this point in the history
HWKALERTS-91 Change Tag impl to Map of name-value pairs and store on …
  • Loading branch information
lucasponce committed Sep 28, 2015
2 parents 41123d8 + e895128 commit 095b9d7
Show file tree
Hide file tree
Showing 19 changed files with 387 additions and 1,008 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class Trigger {
@JsonInclude(Include.NON_EMPTY)
protected Map<String, String> context;

@JsonInclude(Include.NON_EMPTY)
protected Map<String, String> tags;

/** A map with key based on actionPlugin and value a set of action's ids */
@JsonInclude(Include.NON_EMPTY)
private Map<String, Set<String>> actions;
Expand Down Expand Up @@ -129,17 +132,22 @@ public Trigger(String triggerId, String name, Map<String, String> context) {
}

public Trigger(String tenantId, String id, String name) {
this(tenantId, id, name, null);
this(tenantId, id, name, null, null);
}

public Trigger(String tenantId, String id, String name, Map<String, String> context) {
this(tenantId, id, name, context, null);
}

public Trigger(String tenantId, String id, String name, Map<String, String> context, Map<String, String> tags) {
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("Trigger id must be non-empty");
}
this.tenantId = tenantId;
this.id = id;
this.name = name;
this.context = context;
this.tags = tags;

this.actions = new HashMap<>();
this.autoDisable = false;
Expand Down Expand Up @@ -209,19 +217,29 @@ public void setContext(Map<String, String> context) {
this.context = context;
}

/**
* Add context information.
* @param name context key.
* @param value context value.
*/
public void addProperty(String name, String value) {
public void addContext(String name, String value) {
if (null == name || null == value) {
throw new IllegalArgumentException("Propety must have non-null name and value");
throw new IllegalArgumentException("Context must have non-null name and value");
}
if (null == context) {
context = new HashMap<>();
getContext().put(name, value);
}

public Map<String, String> getTags() {
if (null == tags) {
tags = new HashMap<>();
}
return tags;
}

public void setTags(Map<String, String> tags) {
this.tags = tags;
}

public void addTag(String name, String value) {
if (null == name || null == value) {
throw new IllegalArgumentException("Tag must have non-null name and value");
}
context.put(name, value);
getTags().put(name, value);
}

public boolean isAutoDisable() {
Expand Down Expand Up @@ -437,7 +455,7 @@ public String toString() {
+ ", autoResolveAlerts=" + autoResolveAlerts + ", severity=" + severity + ", actions=" + actions
+ ", firingMatch=" + firingMatch + ", autoResolveMatch=" + autoResolveMatch + ", context=" + context
+ ", group=" + group + ", memberOf=" + memberOf + ", orphan=" + orphan + ", enabled=" + enabled
+ ", mode=" + mode + "]";
+ ", mode=" + mode + ", tags=" + tags + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package org.hawkular.alerts.api.services;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.hawkular.alerts.api.model.Severity;
import org.hawkular.alerts.api.model.condition.Alert;
import org.hawkular.alerts.api.model.trigger.Tag;

/**
* Query criteria for fetching Alerts.
Expand All @@ -38,8 +39,7 @@ public class AlertsCriteria {
Collection<Severity> severities = null;
String triggerId = null;
Collection<String> triggerIds = null;
Tag tag = null;
Collection<Tag> tags = null;
Map<String, String> tags = null;
boolean thin = false;

public AlertsCriteria() {
Expand Down Expand Up @@ -122,28 +122,21 @@ public void setTriggerIds(Collection<String> triggerIds) {
this.triggerIds = triggerIds;
}

public Tag getTag() {
return tag;
}

/**
* @param tag fetched Alerts must be for triggers with the specified Tag. Ignored if Tags filter is set.
*/
public void setTag(Tag tag) {
this.tag = tag;
}

public Collection<Tag> getTags() {
public Map<String, String> getTags() {
return tags;
}

/**
* @param tags fetched Alerts must be for trigger with any of the specified Tags.
*/
public void setTags(Collection<Tag> tags) {
public void setTags(Map<String, String> tags) {
this.tags = tags;
}

public void addTag(String name, String value) {
if (null == tags) {
tags = new HashMap<>();
}
tags.put(name, value);
}

public Severity getSeverity() {
return severity;
}
Expand Down Expand Up @@ -175,7 +168,6 @@ public boolean hasCriteria() {
|| null != severity
|| null != triggerId
|| null != alertId
|| null != tag
|| (null != statusSet && !statusSet.isEmpty())
|| (null != severities && !severities.isEmpty())
|| (null != triggerIds && !triggerIds.isEmpty())
Expand All @@ -188,6 +180,6 @@ public String toString() {
return "AlertsCriteria [startTime=" + startTime + ", endTime=" + endTime + ", alertId=" + alertId
+ ", alertIds=" + alertIds + ", status=" + status + ", statusSet=" + statusSet + ", severity="
+ severity + ", severities=" + severities + ", triggerId=" + triggerId + ", triggerIds=" + triggerIds
+ ", tag=" + tag + ", tags=" + tags + ", thin=" + thin + "]";
+ ", tags=" + tags + ", thin=" + thin + "]";
}
}

0 comments on commit 095b9d7

Please sign in to comment.