Download Red Hat JBoss Operations Network 3.3 Writing JBoss ON Command
Transcript
Chapt er 1 3. Example: Script s t o Manage Invent ory (All Resource T ypes)
Uncommitted (new) resources can be identified through a R eso urceC ri teri a search by
adding a search parameter based on the inventory status.
/ / returns a java.util.List of Resource objects
/ / that have not yet been committed into inventory
f uncti o n findUncommittedResources() {
var criteria = ResourceCriteria();
criteria.addFilterInventoryStatus(InventoryStatus.NEW);
return ResourceManager.findResourcesByCriteria(criteria);
}
The second function checks that the inventory search actually returned resources and, if so,
gets the ID for each resource in the array.
/ / returns an array of ids for a given list
/ / of Resource objects. Note the resources argument
/ / can actually be any Collection that contains
/ / elements having an id property.
f uncti o n getIds(resources) {
var ids = [];
i f (resources.size() > 0) {
println("Found resources to import: ");
fo r (i = 0; i < resources.size(); i++) {
resource = resources.get(i);
ids[i] = resource.id;
println(" " + resource.name);
}
} el se {
println("No resources found awaiting import...");
}
return ids;
}
Report a bug
2. Simple Invent ory Count : invent oryCount .js
Searches are performed using *C ri teri a classes; for resources, this is
R eso urceC ri teri a. A search can be very specific, passing criteria so that it returns only
one resource or a small subset of resource. It is also possible to return everything in
inventory.
This script runs a search with no specific criteria (R eso urceC ri teri a()), so that every
resource matches the search. It then takes the size of the results to produce a simple
inventory count.
/ / inventory.js
r hq.login('rhqadmin', 'rhqadmin');
v ar resources =
109