How to make the changes of inventory connection effective in discovery component?

Lukas Krejci lkrejci at redhat.com
Mon Jan 3 10:39:05 UTC 2011


Hi,

The name of the resource cannot be changed programatically in RHQ <= 3 in the 
plugin code. The only option you have is either to change the name manually 
using the UI or use the RHQ CLI and have a script that would periodically scan 
for changes in the plugin configs and rename the resources accordingly.

In RHQ 4 however, this is going to be possible from within your plugin code  
with the resource upgrade functionality, but you're still going to have to do 
a bit of manual setup to get it working.

You can read about the resource upgrade on our wiki:
http://www.rhq-project.org/display/RHQ/Design+-+Resource+Upgrade

Using the resource upgrade functionality, you are currently able to upgrade 
the resource's key, name and description. But the RHQ server is by default 
configured to ignore the name and description changes (so that we don't 
override the custom values users might have assigned to their resources). 
Currently there is no way of changing that configuration from the UI.

To enable the upgrade of resource name and description, you have to change the 
RHQ server system configuration using this SQL (for Postgres):

INSERT INTO RHQ_SYSTEM_CONFIG (ID, PROPERTY_KEY, PROPERTY_VALUE) VALUES 
(nextval('rhq_system_config_id_seq'), 'RESOURCE_GENERIC_PROPERTIES_UPGRADE', 
'true');

and restart the server.

In your plugin code, you'll have to make your discovery class implement the 
ResourceUpgradeFacet interface and implement the upgrade() method along the 
lines of:

public ResourceUpgradeReport 
upgrade(ResourceUpgradeContext<HttpHostResourceComponent> context) {

Configuration pluginConfig = context.getPluginConfiguration();

//TODO extract the values from plugin config
String hostname = null;
String port = null;

//TODO implement
String newResourceName = generateResourceName(hostname, port);

ResourceUpgradeReport report = new ResourceUpgradeReport();
report.setNewResourceName(newResourceName);

return report;
}

Lukas

On Tuesday, December 28, 2010 07:04:51 Lin Gao wrote:
> Hi:
> 
>    If the value of one inventory connection is part of the resource
> component name, how to make the resource component name reflecting the
> changes of the inventory connection value.
> 
>   below is an example:
> 
>   rhq-plugin.xml:
> 
> <server name="HttpServer-Host" description="Http server host and port"
>              discovery="HttpHostDiscoveryComponent"
> class="HttpHostResourceComponent"
>              supportsManualAdd="true">
> 
> <plugin-configuration>
> <c:simple-property name="host" description="host of target http server" />
> <c:simple-property name="port"  description="port of target http server" />
> </plugin-configuration>
> </server>
> 
> HttpHostDiscoveryComponent.java:
> 
> public Set<DiscoveredResourceDetails> discoverResources(
>              ResourceDiscoveryContext<HttpHostResourceComponent> context)
>              throws InvalidPluginConfigurationException, Exception {
>          Set<DiscoveredResourceDetails> result = new
> HashSet<DiscoveredResourceDetails>();
>          for(Configuration config: context.getPluginConfigurations()){
>              String host = config.getSimpleValue(PLUGIN_CONFIG_HOST_KEY,
> null);
>              Integer port =
> Integer.valueOf(config.getSimpleValue(PLUGIN_CONFIG_PORT_KEY, "80"));
> 
>              String resourceKey = "HTTP_CHECK_" + host + ":" + port;
>              String resourceName = "Http Checker on: " + host + ":" + port;
>              String resourceVersion = "1.0.0";
>              String resourceDescription = "Http Checker on server: " +
> host + ":" + port + ".";
>              DiscoveredResourceDetails resource = new
> DiscoveredResourceDetails(context.getResourceType(), resourceKey,
> resourceName, resourceVersion, resourceDescription, config, null);
>              result.add(resource);
>          }
>          return result;
>      }
> 
> 
> If the host is defined to: 127.0.0.1 and port to: 80 when the server is
> added manually, the name of this resource component in the navigate tree
> is: "Http Checker on: 127.0.0.1:80", after that, if the host is
> changed(inventory->connection->edit...), the name of the resource
> component in the navigate tree is not changed, even re load the tree, so
> how to make it changed also?


More information about the rhq-devel mailing list