Wednesday, August 26, 2009

Jopr plugins: Autodiscovery vs. manual add


One thing that I have neglected so far in the plugin development articles for Jopr that I wrote is the possibility to just manually add a resource instead of having it auto discovered.

Why would you want to manually add a resource?

Some resources are virtual like e.g. Twitter feeds in the twitter plugin. If you have 100 agents, it makes no sense to either take the twitter feeds into inventory on all 100 of them or to have to ignore them all in the auto discovery portlet.

When to use auto discovery then?

Auto discovery is best used for more concrete resources like e.g. processes that can exist on a system (a JBossAS for example) or file systems etc. Those are items you usually want to monitor on each system.

Ok, show me the code

Well, actually the code is not that different from what you already know. Within ResourceDiscoveryComponent.discoverResources() the change is to check for passed resource configurations and use those to create the concrete discovered resource:

for (Configuration config :
(Iterable)
discoveryContext.getPluginConfigurations()) {
DiscoveredResourceDetails detail =
new DiscoveredResourceDetails(
discoveryContext.getResourceType(), // ResourceType
url + "_"+ user, // ResourceKey
url + " feed for " +user,
null,
"One " + url + " user",
config,
null );

return Collections.singleton(detail);
}
return null;

As the plugin container will only pass us one configuration at a time (even if the call to getPluginConfigurations() is returning a List), we can safely return the constructed detail. And this is already all :-)


One thing you need to change though is in the plugin descriptor:

<server
name="Twitter"
discovery="TwitterDiscovery"
class="TwitterComponent"
description="Twitter monitoring subsystem"
supportsManualAdd="true"

This supportsManualAdd is what lets the resource type show up in its parent (usually platform for a standalone server) "Manually Add" dialog:

Bild 11.png


For more resources related to plugin development have a look at this post.

No comments: