Red Hat Training

A Red Hat training course is available for Red Hat JBoss Operations Network

10. Example: Managing JBoss ON Server Configuration

Even in different environments, JBoss ON servers can share a lot of the same configuration. For example, different JBoss ON servers may manage a development environment, staging environment, and production environment, yet on all three, the servers use similar metric templates and configuration settings. To simplify managing separate but similar environments, JBoss ON can export the configuration for a server and then import that configuration into another server.
Any user with permissions to manage settings can export the server configuration.

10.1. Simple Export/Import Synchronization

At its simplest, synchronizing server settings exports all metrics and server configuration settings and then imports that information directly, without any adjustment to the data before its imported or filters on what data to import.

Note

This can be automated by including login information for both JBoss ON servers, and then running the script. This could also be broken into two scripts, one run against server1 and the other against server2. Using a wrapper script would allow you to run the export script, then to run a utility like SCP to copy over the archive, and then to run the import script.
The first part of the script exports the data from server1 and creates a zipped XML archive.
//log into the first server
rhq.login('rhqadmin','rhqadmin','server1.example.com','7080');

//export the settings
var ex = SynchronizationManager.exportAllSubsystems();
rhqadmin@localhost:7080$ saveBytesToFile(ex.exportFile, 'export.xml.gz');

// log out of the first server
rhq.logout()
The archive file then needs to be copied over to server2 in some way.
When the archive is copied over, it can then be imported into server2. The null parameter means that the import process uses the default settings in the XML file or, if the defaults are missing from the XML, that it uses the settings defined on the target server.
// log into the second server
rhq.login('rhqadmin','rhqadmin','server2.example.com','7080');

// import the settings
var data = getFileBytes('export.xml.gz');
SynchronizationManager.importAllSubsystems(ex, null);

// log out of the second server
rhq.logout()

10.2. Changing Server Configuration Before Importing

Metrics schedules and server configuration are applied through synchronizers. Synchronizers control what elements are imported into the JBoss ON server and how to apply them to the server. The synchronizer has a default template which applies configuration changes to every import operation.
The synchronizer configuration can be changed to change what settings are imported into the target server.
The first part of the script would export the XML archive, as before.
//log into the first server
rhq.login('rhqadmin','rhqadmin','server1.example.com','7080');

//export the settings
var ex = SynchronizationManager.exportAllSubsystems();
rhqadmin@localhost:7080$ saveBytesToFile(ex.exportFile, 'export.xml.gz');

// log out of the first server
rhq.logout()
The XML file contains the full configuration information, so just checking that file can give you an idea of what settings to change.
On the second server, change the synchronizer settings.
  1. Get the default definition.
    rhqadmin@localhost:7080$ var systemSettingsImportConfigurationDefinition = SynchronizationManager.getImportConfigurationDefinition('org.rhq.enterprise.server.sync.SystemSettingsSynchronizer')
  2. Create a new configuration instance.
    rhqadmin@localhost:7080$ var configurationObject = systemSettingsImportConfigurationDefinition.configurationDefinition.defaultTemplate.createConfiguration()
    
    rhqadmin@localhost:7080$ var systemSettingsImportConfiguration = new ImportConfiguration(systemSettingsImportConfigurationDefinition.synchronizerClassName, configurationObject)
  3. Change the settings.
    For example, this edits the server synchronizer so that it imports only the database settings for storing monitoring data.
    rhqadmin@localhost:7080$ configurationObject.getSimple('propertiesToImport').setValue('CAM_DATA_PURGE_1H, CAM_DATA_PURGE_6H, CAM_DATA_PURGE_1D, CAM_DATA_MAINTENANCE')
    For the metrics template synchronizer, define which metric schedules to import per resource type, based on a properties list or a properties map. For example:
    rhqadmin@localhost:7080$ configurationObject.getSimple('updateAllSchedules').setBooleanValue(true)
    rhqadmin@localhost:7080$ var updateList = new PropertyList('metricUpdateOverrides')
    rhqadmin@localhost:7080$ var update = new PropertyMap('metricUpdateOverride')
    rhqadmin@localhost:7080$ update.put(new PropertySimple('metricName', 'MCBean|ServerInfo|*|freeMemory'))
    rhqadmin@localhost:7080$ update.put(new PropertySimple('resourceTypeName', 'JBossAS Server'))
    rhqadmin@localhost:7080$ update.put(new PropertySimple('resourceTypePlugin', 'JBossAS5'))
    rhqadmin@localhost:7080$ update.put(new PropertySimple('updateSchedules', 'true'))
    
    rhqadmin@localhost:7080$ updateList.add(update)
    
    rhqadmin@localhost:7080$ configurationObject.put(updateList)
After changing the synchronizer settings, then import the configuration.
rhqadmin@localhost:7080$ var configsToImport = new java.util.ArrayList()
rhqadmin@localhost:7080$ configsToImport.add(systemSettingsImportConfiguration);
rhqadmin@localhost:7080$ configsToImport.add(metricTemplatesImportConfiguration);
rhqadmin@localhost:7080$ SynchronizationManager.importAllSubsystems(ex, configToImport);