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

Commit

Permalink
BZ 1158228 - to support install on Windows, allow for agent to be tol…
Browse files Browse the repository at this point in the history
…d to reload its agent config xml via marker file
  • Loading branch information
jmazzitelli committed Oct 29, 2014
1 parent 79a063c commit 438e10b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Expand Up @@ -30,6 +30,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -3389,13 +3390,20 @@ private void processArguments(String[] args) throws Exception {
prefsNode.flush();
}

if (config_file_name == null) {
// -c was not specified, but let's see if we were told to do a one-time reload of a config file
config_file_name = findAgentConfigurationFileReloadMarker();
}

if (config_file_name != null) {
try {
loadConfigurationFile(config_file_name);
} catch (Exception e) {
throw new IllegalArgumentException(MSG.getMsg(AgentI18NResourceKeys.LOAD_CONFIG_FILE_FAILURE,
config_file_name, e));
}
// now that we know we loaded the config file, make sure we purge any marker file that might have triggered the reload
purgeAgentConfigurationFileReloadMarker();
}

checkInitialConfiguration();
Expand All @@ -3413,6 +3421,57 @@ private void processArguments(String[] args) throws Exception {
return;
}

/**
* If a user puts a marker file in the conf/ directory named "foo.xml.reload", this tells the agent
* it should reload the agent configuration file named "foo.xml" - this will act just as if the user
* passed in "-c foo.xml" on the command line.
*
* @return the agent config file whose reload marker was found; null if no marker file was found
*/
private String findAgentConfigurationFileReloadMarker() {
String agentConfigFileToReload = null;

File confDir = new File("conf");
if (confDir.exists()) {
File[] reload = confDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.endsWith(".xml.reload"));
}
});
if (reload != null && reload.length > 0) {
// just take the first one, should only ever have one anyway (unless we have zero)
File markerFile = reload[0];
int filenameLength = markerFile.getName().length();
agentConfigFileToReload = markerFile.getName().substring(0, filenameLength - ".reload".length());
LOG.info(AgentI18NResourceKeys.AGENT_CONFIG_FILE_RELOAD_MARKER_FILE_FOUND, agentConfigFileToReload);
}
}

return agentConfigFileToReload;
}

/**
* Purges any and all agent configuration file reload marker files found.
*/
private void purgeAgentConfigurationFileReloadMarker() {
File confDir = new File("conf");
if (confDir.exists()) {
File[] reloads = confDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.endsWith(".xml.reload"));
}
});
if (reloads != null && reloads.length > 0) {
for (File doomed : reloads) {
doomed.delete();
}
}
}
return;
}

/**
* This sets the name of the preferences node. This identifies the node where the agent's configuration should be.
* This node name must match the node as defined in the agent's configuration file. See the <i>Java Preferences
Expand Down
Expand Up @@ -660,6 +660,9 @@ public interface AgentI18NResourceKeys {
@I18NMessage("Failed to load configuration file [{0}]. Cause: {1}")
String LOAD_CONFIG_FILE_FAILURE = "AgentMain.load-config-file-failure";

@I18NMessage("Agent told to reload agent config file [{0}] due to marker file existence.")
String AGENT_CONFIG_FILE_RELOAD_MARKER_FILE_FOUND = "AgentMain.agent-config-file-reload-marker-file-found";

@I18NMessage("Agent container has processed its command line arguments: {0}")
String ARGS_PROCESSED = "AgentMain.args-processed";

Expand Down
Expand Up @@ -769,6 +769,10 @@ private void configureAgent(File agentBasedir, CommandLine commandLine) throws E
File agentConfDir = new File(agentBasedir, "conf");
File agentConfigFile = new File(agentConfDir, "agent-configuration.xml");

// BZ 1158228 - to support install on Windows, make sure the first time we reload the agent config xml always
File agentConfigReloadMarkerFile = new File(agentConfigFile.getAbsolutePath() + ".reload");
agentConfigReloadMarkerFile.createNewFile();

if (commandLine.hasOption(AGENT_CONFIG_OPTION)) {
log.info("Configuring the RHQ agent with custom configuration file: "
+ commandLine.getOptionValue(AGENT_CONFIG_OPTION));
Expand Down

0 comments on commit 438e10b

Please sign in to comment.