Skip to content

Commit

Permalink
HWKALERTS-206 Improve global plugins (#268)
Browse files Browse the repository at this point in the history
- Remove Global annotations for plugins API
- Any plugin can send single or global actions
- Global actions can be defined at tenant level
- Cache global actions to minimize access into backend
  • Loading branch information
lucasponce authored and jshaughn committed Nov 29, 2016
1 parent 520b344 commit 33a8b41
Show file tree
Hide file tree
Showing 38 changed files with 537 additions and 1,064 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.hawkular.alerts.actions.api.ActionPluginListener;
import org.hawkular.alerts.actions.api.ActionPluginSender;
import org.hawkular.alerts.actions.api.Global;
import org.hawkular.alerts.actions.api.Plugin;
import org.hawkular.alerts.actions.api.Sender;
import org.hawkular.alerts.api.services.ActionsService;
Expand All @@ -52,7 +49,6 @@ public class ActionPlugins {
private ActionsService actions;
private static ActionPlugins instance;
private Map<String, ActionPluginListener> plugins;
private Set<String> globals;
private Map<String, ActionPluginSender> senders;

public static synchronized Map<String, ActionPluginListener> getPlugins() {
Expand All @@ -62,13 +58,6 @@ public static synchronized Map<String, ActionPluginListener> getPlugins() {
return Collections.unmodifiableMap(instance.plugins);
}

public static synchronized Set<String> getGlobals() {
if (instance == null) {
instance = new ActionPlugins();
}
return Collections.unmodifiableSet(instance.globals);
}

public static synchronized Map<String, ActionPluginSender> getSenders() {
if (instance == null) {
instance = new ActionPlugins();
Expand All @@ -79,7 +68,6 @@ public static synchronized Map<String, ActionPluginSender> getSenders() {
private ActionPlugins() {
try {
plugins = new HashMap<>();
globals = new HashSet<>();
senders = new HashMap<>();
init();
List<URL> webInfUrls = getWebInfUrls();
Expand All @@ -94,9 +82,6 @@ private ActionPlugins() {
ActionPluginListener pluginInstance = (ActionPluginListener)newInstance;
injectActionPluginSender(name, pluginInstance);
plugins.put(name, pluginInstance);
if (pluginClass.isAnnotationPresent(Global.class)) {
globals.add(name);
}
} else {
throw new IllegalStateException("Plugin [" + name + "] is not instance of " +
"ActionPluginListener");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.hawkular.alerts.actions.standalone.ServiceNames.Service.DEFINITIONS_SERVICE;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -70,8 +69,7 @@ public void process(Action action) {
}
String actionPlugin = action.getActionPlugin();
final ActionPluginListener plugin = plugins.get(actionPlugin);
Set<String> globals = ActionPlugins.getGlobals();
if (plugin == null && ActionPlugins.getGlobals().isEmpty()) {
if (plugin == null) {
if (log.isDebugEnabled()) {
log.debug("Received action [" + actionPlugin +
"] but no ActionPluginListener found on this deployment");
Expand All @@ -90,23 +88,6 @@ public void process(Action action) {
}
});
}
// Check if the plugin is executed twice
if (!globals.contains(actionPlugin)) {
for (String global : globals) {
ActionPluginListener globalPlugin = ActionPlugins.getPlugins().get(global);
if (globalPlugin != null) {
executorService.execute(() -> {
try {
globalPlugin.process(pluginMessage);
} catch (Exception e) {
log.debug("Error processing action: " + action.getActionPlugin(), e);
msgLog.errorProcessingAction(e.getMessage());
}
});
}
}
}

} catch (Exception e) {
log.debug("Error processing action: " + action.getActionPlugin(), e);
msgLog.errorProcessingAction(e.getMessage());
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 33a8b41

Please sign in to comment.