Create JON dynamic group based on resource location value
Environment
- Red Hat JBoss Operations Network (ON) 3.2
- JBoss ON dynamic group definition expression to limit group membership to resource location
Issue
- Is it possible to create dynagroup definitions based on resource location?
-
When trying to use groupby resource.location the following error is thrown in the Message Center:
java.lang.RuntimeException:[1398851481575] org.rhq.enterprise.server.resource.group.definition.exception.GroupDefinitionUpdateException:Cannot parse the expression: Invalid 'resource' subexpression: location -
Unable to use resource location property in dynamic group expression
Resolution
The dynamic group definition expression does not support the use of a resource's location property value.
To limit group members to the value defined in their location property, you could create or update a resource group using the JBoss ON remote client API or command-line interface (CLI) script. The script could then be executed periodically or scheduled using your operating system's task scheduler such as cron. The script could locate resources using location criteria and then explicitly add them as group members to a new or existing resource group. For example, the following CLI script demonstrates how to create a new resource group containing all resources of a specific type that have a location value that matches a specified value.
/*
* To the extent possible under law, Red Hat, Inc. has dedicated all
* copyright to this software to the public domain worldwide, pursuant
* to the CC0 Public Domain Dedication. This software is distributed
* without any warranty.
*
* See <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
if (args.length < 2) {
println("Not enough arguments! Please re-run the script with resource name, plugin and location value!");
println("Usage:");
println(" rhq-cli.sh -u <username> -p <password> -s <jon-server-ip-address> -t <jon-server-port> -f <full/path/to/createGroupScript.js> <name> <plugin> <location>");
} else {
var name = args[0];
var plugin = args[1];
var location = args[2];
// search for the resource type to use for the compatible group
var resType = ResourceTypeManager.getResourceTypeByNameAndPlugin(name,plugin);
var rg = new ResourceGroup(resType);
rg.setRecursive(false);
rg.setName(name + ' Group - ' + java.util.Date());
// create resource group
rg = ResourceGroupManager.createResourceGroup(rg);
//find resources to add to the group based on their resource type and their location
criteria = new ResourceCriteria();
criteria.addFilterResourceTypeId(resType.id);
var resources = ResourceManager.findResourcesByCriteria(criteria);
var resource;
if(resources != null) {
for(i=0; i<resources.size(); ++i){
resource=resources.get(i);
var selectedLocation = resource.getLocation();
if (selectedLocation.toString().equals(location)){
ResourceGroupManager.addResourcesToGroup(rg.id, [resource.id])
}
}
}
}
A request for feature enhancement (RFE) has been submitted asking that the location field be made available in the dynamic group expression. This request will be reviewed and considered in a future release of JBoss ON. If you require additional information on the RFE or would also like to request this feature, please contact Red Hat Global Support Services.
Root Cause
The expression resource.location=<value> is not supported by the dynamic group definition language.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
