Skip to content

Commit

Permalink
HWKALERTS-91 Change Tag impl to Map of name-value pairs and store on …
Browse files Browse the repository at this point in the history
…Trigger

- This initial impl still uses Trigger's Tags for Alerts fetch.  That
  will change as the Events work is completed.
- Simplify Tag persistence into single table and improve distribution
  • Loading branch information
jshaughn committed Sep 28, 2015
1 parent 5805afa commit 3084b91
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 1,007 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.api.model;

/**
* The type of Tag being stored or fethed.
*
* @author jay shaughnessy
* @author lucas ponce
*/
public enum TagType {
TRIGGER, ALERT, EVENT
}

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 tname, String tvalue) {
if (null == tags) {
tags = new HashMap<>();
}
tags.put(tname, tvalue);
}

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 3084b91

Please sign in to comment.