From 7594e6ad276587d5b88c9164b31c55834a874cdb Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Thu, 5 Feb 2015 13:51:38 +0200 Subject: [PATCH] [BZ 1187527] If --agent-preference is given, store the modified preferences to agent-configuration.xml and backup the original one with comments --- .../control/command/AbstractInstall.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java index 2e0a755ef0b..46ff0b42a2e 100644 --- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java +++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java @@ -31,6 +31,7 @@ import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -911,7 +912,7 @@ private Properties getAgentServerEndpoint() throws Exception { return endpointData; } - private void overrideAgentPreferences(CommandLine commandLine, Preferences preferencesNode) { + private void overrideAgentPreferences(CommandLine commandLine, Preferences preferencesNode) throws BackingStoreException, IOException { // override the out of box config with user custom agent preference values String[] customPrefs = commandLine.getOptionValues(AGENT_PREFERENCE); if (customPrefs != null && customPrefs.length > 0) { @@ -923,6 +924,32 @@ private void overrideAgentPreferences(CommandLine commandLine, Preferences prefe preferencesNode.put(prefName, prefValue); } } + + // These should be stored in the configuration file also for reload marker + File confDir = new File(getAgentBasedir(), "conf"); + File defaultConfigFile = new File(confDir, "agent-configuration.xml"); + File backupConfigFile = new File(confDir, "agent-configuration.xml.orig"); + + if(!defaultConfigFile.renameTo(backupConfigFile)) { + log.error("Could not rename " + defaultConfigFile.getAbsolutePath() + " to " + backupConfigFile.getAbsolutePath() + " for backup purposes"); + } + + FileOutputStream fos = null; + try { + fos = new FileOutputStream(defaultConfigFile); + preferencesNode.exportSubtree(fos); + } catch (IOException e) { + log.error("Failed to store overridden agent preferences to " + defaultConfigFile.getAbsolutePath() + "."); + throw e; + } catch (BackingStoreException e) { + log.error("Failed to store overridden agent preferences to " + defaultConfigFile.getAbsolutePath() + "."); + throw e; + } finally { + if(fos != null) { + fos.close(); + } + } + return; }