HADOOP-19228. ShellCommandFencer#setConfAsEnvVars should also replace '-' with '_'. (#6936). Contributed by fuchaohong.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
fuchaohong 2024-07-20 16:13:33 +08:00 committed by GitHub
parent a5eb5e9611
commit 1577f57d4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 7 deletions

View File

@ -183,7 +183,7 @@ public final Map<String, String> getFencingParameters() {
* expose to fencing implementations/scripts. Fencing methods are free * expose to fencing implementations/scripts. Fencing methods are free
* to use this map as they see fit -- notably, the shell script * to use this map as they see fit -- notably, the shell script
* implementation takes each entry, prepends 'target_', substitutes * implementation takes each entry, prepends 'target_', substitutes
* '_' for '.', and adds it to the environment of the script. * '_' for '.' and '-', and adds it to the environment of the script.
* *
* Subclass implementations should be sure to delegate to the superclass * Subclass implementations should be sure to delegate to the superclass
* implementation as well as adding their own keys. * implementation as well as adding their own keys.

View File

@ -40,7 +40,7 @@
* *
* The shell command will be run with an environment set up to contain * The shell command will be run with an environment set up to contain
* all of the current Hadoop configuration variables, with the '_' character * all of the current Hadoop configuration variables, with the '_' character
* replacing any '.' characters in the configuration keys.<p> * replacing any '.' or '-' characters in the configuration keys.<p>
* *
* If the shell command returns an exit code of 0, the fencing is * If the shell command returns an exit code of 0, the fencing is
* determined to be successful. If it returns any other exit code, the * determined to be successful. If it returns any other exit code, the
@ -202,11 +202,11 @@ private static String tryGetPid(Process p) {
/** /**
* Set the environment of the subprocess to be the Configuration, * Set the environment of the subprocess to be the Configuration,
* with '.'s replaced by '_'s. * with '.'s and '-'s replaced by '_'s.
*/ */
private void setConfAsEnvVars(Map<String, String> env) { private void setConfAsEnvVars(Map<String, String> env) {
for (Map.Entry<String, String> pair : getConf()) { for (Map.Entry<String, String> pair : getConf()) {
env.put(pair.getKey().replace('.', '_'), pair.getValue()); env.put(pair.getKey().replaceAll("[.-]", "_"), pair.getValue());
} }
} }
@ -237,7 +237,7 @@ private void addTargetInfoAsEnvVars(HAServiceTarget target,
for (Map.Entry<String, String> e : for (Map.Entry<String, String> e :
target.getFencingParameters().entrySet()) { target.getFencingParameters().entrySet()) {
String key = prefix + e.getKey(); String key = prefix + e.getKey();
key = key.replace('.', '_'); key = key.replaceAll("[.-]", "_");
environment.put(key, e.getValue()); environment.put(key, e.getValue());
} }
} }

View File

@ -63,7 +63,7 @@ public void resetLogSpy() {
private static ShellCommandFencer createFencer() { private static ShellCommandFencer createFencer() {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set("in.fencing.tests", "yessir"); conf.set("in.fencing-tests", "yessir");
ShellCommandFencer fencer = new ShellCommandFencer(); ShellCommandFencer fencer = new ShellCommandFencer();
fencer.setConf(conf); fencer.setConf(conf);
return fencer; return fencer;