Example JON CLI script to purge resource operation history older then a specified time

Solution Verified - Updated -

Environment

  • Red Hat JBoss Operations Network (ON) 3.0, 3.1, 3.2, 3.3
    • JBoss ON Command Line Interface (CLI) script
    • Need to delete or purge resource operation history older then a certain date or time

Issue

  • We need a way to purge operations history in bulk
  • Example script that will delete all old operation history

Resolution

JON 3.3

It is now possible to purge operation history to provide better database performance and reduce table space issues. This feature adds an operation history purge to the data purge job.
A new system setting called Delete Operation History Older Than is added to Administration > Configuration > System Settings >> Data Manager Configuration Properties. The default for this system setting is 0 days, which means disabled. The db-upgrade adds the new system setting (also set to disabled) to prevent upgrades from automatically forcing an unexpected purge of operation history. See the release notes

Pre JON 3.3

Resource operation history can be deleted from the JBoss ON system using the JBoss ON remote API's OperationManager.deleteOperationHistory method. Because the method expects exactly one operationHistoryId, you will need to use OperationManager.findResourceOperationHistoriesByCriteria to compile a list of operationHistoryIds that you intend to delete. For example:

// calculate today minus number of days to keep for operation end date
var cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.DATE, (365 * -1));
var endTime = cal.getTime();

var opHistCrit = new ResourceOperationHistoryCriteria();
opHistCrit.addFilterEndTime(endTime.getTime());
var opHistList = OperationManager.findResourceOperationHistoriesByCriteria(opHistCrit);

opHistList will contain all the operation history reports that finished executing more then 365 days ago. You can now iterate through the list and perform the actual deletion:

var itr = opHistList.iterator();
while (itr.hasNext()) {
    opHistory = itr.next();
    OperationManager.deleteOperationHistory(opHistory.getId(), false);
}

A complete example script is contained in rhq-cli-892903_0.zip attached to this solution. After extracting the archive you can execute the script by passing the -f argument to rhq-cli. The help argument can be passed to the script for usage information. For example:

./rhq-cli.sh -u rhqadmin -p rhqadmin -h jboss-on.example.com -t 7080 -f ${HOME}/samples/purgeResourceOperationHistory.js help

Root Cause

Operation history does not get automatically deleted from the JBoss ON system. Although a user can easily delete the old history by using the JBoss ON user-interface (UI) for individual resources or resource groups, it might be easier to delete this type of data in bulk using the JBoss ON CLI.

Red Hat is looking at adding a purge feature, for the operations history, in a future release of JON.

Attachments

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.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.