Skip to content

Commit

Permalink
HWKALERTS-123 Introduce time constraints on actions
Browse files Browse the repository at this point in the history
HWKALERTS-79 Define actions per state
  • Loading branch information
lucasponce committed Feb 3, 2016
1 parent 7a1c0df commit ecb4b4c
Show file tree
Hide file tree
Showing 24 changed files with 1,125 additions and 194 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* Copyright 2015-2016 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");
Expand Down Expand Up @@ -69,6 +69,7 @@ public enum Status {
public Alert() {
// for json assembly
this.eventType = EventType.ALERT.name();
this.status = Status.OPEN;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public class Trigger implements Serializable {
@JsonInclude(Include.NON_EMPTY)
protected Map<String, String> tags;

/** A map with key based on actionPlugin and value a set of action's ids */
/** A list of links to actions represented by TriggerAction*/
@JsonInclude(Include.NON_EMPTY)
private Map<String, Set<String>> actions;
private Set<TriggerAction> actions;

/** Disable automatically after firing */
@JsonInclude
Expand Down Expand Up @@ -167,7 +167,7 @@ public Trigger(String tenantId, String id, String name, Map<String, String> cont
this.context = context;
this.tags = tags;

this.actions = new HashMap<>();
this.actions = new HashSet<>();
this.autoDisable = false;
this.autoEnable = false;
this.autoResolve = false;
Expand Down Expand Up @@ -335,50 +335,19 @@ public Match getAutoResolveMatch() {
return autoResolveMatch;
}

public Map<String, Set<String>> getActions() {
public Set<TriggerAction> getActions() {
if (actions == null) {
actions = new HashSet<>();
}
return actions;
}

public void setActions(Map<String, Set<String>> actions) {
public void setActions(Set<TriggerAction> actions) {
this.actions = actions;
}

public void addAction(String actionPlugin, String actionId) {
if (actionPlugin == null || actionPlugin.isEmpty()) {
throw new IllegalArgumentException("ActionPlugin must be non-empty.");
}
if (actionId == null || actionId.isEmpty()) {
throw new IllegalArgumentException("ActionId must be non-empty.");
}
if (actions.get(actionPlugin) == null) {
actions.put(actionPlugin, new HashSet<>());
}
actions.get(actionPlugin).add(actionId);
}

public void addActions(String actionPlugin, Set<String> actionIds) {
if (actionPlugin == null || actionPlugin.isEmpty()) {
throw new IllegalArgumentException("ActionPlugin must be non-empty.");
}
if (actionIds == null) {
throw new IllegalArgumentException("ActionIds must be non null");
}
if (actions.get(actionPlugin) == null) {
actions.put(actionPlugin, new HashSet<>());
}
actions.get(actionPlugin).addAll(actionIds);
}

public void removeAction(String actionPlugin, String actionId) {
if (actionPlugin == null || actionPlugin.isEmpty()) {
throw new IllegalArgumentException("actionPlugin must be non-empty.");
}
if (actionId == null || actionId.isEmpty()) {
throw new IllegalArgumentException("ActionId must be non-empty.");
}
if (actions.get(actionPlugin) != null) {
actions.get(actionPlugin).remove(actionId);
}
public void addAction(TriggerAction triggerAction) {
getActions().add(triggerAction);
}

public String getMemberOf() {
Expand Down
Loading

0 comments on commit ecb4b4c

Please sign in to comment.