Thursday, September 24, 2009

New api for manual discovery on RHQ and Jopr

The other day I was writing about manual discovery/addition of resources. Now that Jopr 2.3 (and its JBoss ON counterpart is out), we have updated the API for manual discovery to provide its own interface so that you don't need to fiddle around with finding the passed configuration.

The new API lives in the ManualAddFacet, which has one method
DiscoveredResourceDetails discoverResource(Configuration pluginConfiguration, ResourceDiscoveryContext<T> context)
throws InvalidPluginConfigurationException;
that you need to implement. This Facet is implemented in addition to the ResourceDiscoveryComponent within the discovery component. Ips has already converted all existing plugins to the new api, so you can have a look at many examples there, so I'll only show a short one here, which is an excerpt from the Twitter plugin:


public class TwitterDiscovery
implements ResourceDiscoveryComponent,ManualAddFacet {
 
// Auto-discovery not supported, so return an empty set
public Set discoverResources
(ResourceDiscoveryContext discoveryContext)
throws Exception {
 
// We don't support auto-discovery.
return Collections.emptySet();
}
 
// perform the manual add
public DiscoveredResourceDetails discoverResource(
Configuration pluginConfig,
ResourceDiscoveryContext discoveryContext)
throws InvalidPluginConfigurationException {
 
DiscoveredResourceDetails detail =
new DiscoveredResourceDetails(
discoveryContext.getResourceType(), //ResourceType
url + "_"+ user, // ResourceKey
url + " feed for " +user, // ResourceName
null, // Version
"One " + url + " user", // Description
pluginConfig, // Passed plugin config
null ); // Process scans
return detail;
}
}

I have also updated the plugin skeleton generator code in svn to support this new API and have uploaded the new version to jopr.org

2 comments:

ARUN RAJ ( NO BODY CAN CATCH ME ) said...

Hi Heiko,

I am new to java and RHQ. But I am interested to know things. Please help me to understand RHQ.

In the discoverResources method, you are returning Collections.emptySet(). There is nothing like that, I am right. Then How it will return any discovered value.
Again, You are manually adding resources in the another discoverResources method. I understand the code. In that Block, I want to list out my Server(Resource Type- multiple which has been discovered) as a parent in this method. How to make it out. Please help me .

Heiko Rupp said...

Arun,

before said change we had one method to be called for auto-discovery and for manual add.

This change breaks them apart into two methods.

Now in my post, I only want to manually add the resource and not auto-discover it. As I have to implement discoverResources(), I need to return something there, so I return just an empty set.

In discoverResource() I return the manually added one.

If you want to allow for auto-discover and manual add, you need to implement both methods with actual code.