Bug 534460 (RHQ-1253) - allow agent to change its preferences node without user having to edit agent-configuration.xml
Summary: allow agent to change its preferences node without user having to edit agent-...
Keywords:
Status: CLOSED NEXTRELEASE
Alias: RHQ-1253
Product: RHQ Project
Classification: Other
Component: Agent
Version: unspecified
Hardware: All
OS: All
low
medium
Target Milestone: ---
: ---
Assignee: John Mazzitelli
QA Contact: Jeff Weiss
URL: http://jira.rhq-project.org/browse/RH...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-12-12 14:24 UTC by John Mazzitelli
Modified: 2014-11-09 22:48 UTC (History)
1 user (show)

Fixed In Version: 1.2
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)

Description John Mazzitelli 2008-12-12 14:24:00 UTC
If the user running the agent has its home directory stored on NFS then running multiple agents will pick up the same Java Preferences across all your machines. The one solution is to have your agents use different Java Preferences names. To do this, edit your agents' agent-configuration.xml files and change their Java preferences node names from "default" to something else that makes them unique across all agents. For example, change:

<node name="default">

to

<node name="another-agent-default">

Now each time that you start your agents, you need to tell them where they can find their preferences (since you overrode its default location). You tell the agent your new preference name via --pref (or its shorthand notation of -p). Since you changed the configuration file, don't forget that the first time you restart the agent you need to pass in -c too):

rhq-agent.sh -p another-agent-default -c agent-configuration.xml

Thereafter, the agent need only be passed in -p every time you restart it (the new configuration will be persisted for you).

However, its annoying to have to change the agent-configuration.xml everytime you start an agent with a custom preference node name.

We need a way to install this .xml into Java Preferences so you don't have to do that.

One idea, be able to use system property substitution in the .xml:

<node name=${rhq.agent.name}>

You can package up your agent with this change and be able to run the agent on any box (even with NFS mounted home) and get it to work.

The problem is - you can't pass the .xml directly to the Java preferences API because it knows nothing about substituting that and will use the string "${rhq.agent.name}" literally.

We would have to take the agent-configuration.xml, process it ourselves (run it through a preprocessor and replace all "${var}" string appropriately) - store the XML in a temporary location and pass that new tmp XML to the Java Preferences API. We could store that tmp .xml file in the data/tmp directory as a place to put it.

Using a temp file would allow the user to stop the agent, restart it with a new --pref option and it would work (assuming you passed in --cleanconfig because otherwise, existing preferences would take effect and config processing would never take place anyway).

Comment 1 John Mazzitelli 2008-12-12 14:25:30 UTC
we might not even need a tmp .xml file - just store the processed XML content in memory and stream it to the Java Preferences API (assuming the API takes a stream - would have to look at it to make sure).

Comment 2 John Mazzitelli 2008-12-12 14:33:21 UTC
Java Prefs API has this:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/Preferences.html#importPreferences(java.io.InputStream)

The more I think about this, the more I think this could be very easy to implement. 

1) load in the .xml like we do today
2) run the xml content through a pre-processor that simply replaces ${} with system prop values
3) pass to preferences API

We already do 1 and 3 - just need to insert 2.

Comment 3 John Mazzitelli 2008-12-12 14:36:29 UTC
DOH! I knew it wasn't this easy. I'm getting flashbacks - this is the same train of thought I was on long ago when I tried fixing this.

The rhq.agent.name isn't set until after the config is loaded (the rhq.agent.name IS in preferences - chicken and egg, can't get prefs until you have a pref value to tell you where the prefs are stored?)

Need to figure out some other key to use - hostname may or may not a good alternative. How would the agent get the hostname (Java API I assume)? Using hostname limits us to running a single agent on a box (in testing environment, we can run 100 or more on the same box)

Comment 4 John Mazzitelli 2008-12-12 14:39:30 UTC
Idea:

rhq-agent-env.sh:

RHQ_AGENT_CMDLINE_OPTS=--daemon -Drhq.agent.preference-node=`hostname`

agent-configuration.xml:

<node name="${rhq.agent.preferences-node}">

The user can use whatever value they want. `hostname` or "helloworld" or whatever.

Comment 5 John Mazzitelli 2008-12-12 14:42:19 UTC
Better yet, why not just use the cmdline option we already have:

rhq-agent.sh --pref=`hostname`

or, in rhq-agent-env.sh:

RHQ_AGENT_CMDLINE_OPTS=--pref=`hostname`

Our code is already looking for this option, we just take it and set an internal system property (call it rhq.agent.preference-node), and replace it in the agent-configuration.xml, assuming the .xml has:

<node name=${rhq.agent.preference-node}>

Yes... I think that might work. We would just have to go through all the agent-configuration.xml files in SVN, and change the name="default" to name="${rhq.agent.preference-node}" and make sure whenever the agent uses this .xml, it pre-processes it first.

Comment 6 John Mazzitelli 2008-12-12 16:25:42 UTC
i think we can fix rhq-11 once this is added

Comment 7 John Mazzitelli 2008-12-12 20:43:08 UTC
--pref now can be specified without editing the config .xml by hand.

the pref node name is replaced with the value of your given pref node, default is still "default".

Comment 8 John Mazzitelli 2009-01-09 15:01:56 UTC
To test:

1) shutdown any agent running
2) delete any perferences location (on windows, purge the registry entries for rhq-agent, on UNIX, delete the $HOME/.java directory) - this starts clean for you
3) Start the agent with the --pref option (--pref=testing)
4) now go into the registry (if windows) or $HOME/.java (if UNIX) and look for the "testing" node - you shoudl see the testing node and NOT the node named "default"

Comment 9 Jeff Weiss 2009-01-09 17:38:38 UTC
Verified that using the "pref" option causes the agent to save and load its prefs from the specified properties.  rev2561, linux

Comment 10 Red Hat Bugzilla 2009-11-10 20:29:07 UTC
This bug was previously known as http://jira.rhq-project.org/browse/RHQ-1253
This bug incorporates RHQ-11



Note You need to log in before you can comment on or make changes to this bug.