Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1187527] If --agent-preference is given, store the modified prefe…
Browse files Browse the repository at this point in the history
…rences to agent-configuration.xml and backup the original one with comments
  • Loading branch information
Michael Burman authored and Simeon Pinder committed May 26, 2015
1 parent 93c081b commit 7594e6a
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 7594e6a

Please sign in to comment.