You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by he...@apache.org on 2024/07/20 08:13:43 UTC
(hadoop) branch trunk updated: HADOOP-19228. ShellCommandFencer#setConfAsEnvVars should also replace '-' with '_'. (#6936). Contributed by fuchaohong.
This is an automated email from the ASF dual-hosted git repository.
hexiaoqiao pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 1577f57d4c8 HADOOP-19228. ShellCommandFencer#setConfAsEnvVars should also replace '-' with '_'. (#6936). Contributed by fuchaohong.
1577f57d4c8 is described below
commit 1577f57d4c8bc9a0ef200a9e308e1c0f2c21c18f
Author: fuchaohong <17...@qq.com>
AuthorDate: Sat Jul 20 16:13:33 2024 +0800
HADOOP-19228. ShellCommandFencer#setConfAsEnvVars should also replace '-' with '_'. (#6936). Contributed by fuchaohong.
Signed-off-by: He Xiaoqiao <he...@apache.org>
---
.../src/main/java/org/apache/hadoop/ha/HAServiceTarget.java | 2 +-
.../src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java | 10 +++++-----
.../test/java/org/apache/hadoop/ha/TestShellCommandFencer.java | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceTarget.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceTarget.java
index 288a9dcbe0e..701862a0f07 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceTarget.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceTarget.java
@@ -183,7 +183,7 @@ public abstract class HAServiceTarget {
* expose to fencing implementations/scripts. Fencing methods are free
* to use this map as they see fit -- notably, the shell script
* 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
* implementation as well as adding their own keys.
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
index 1ffcc3009ea..059c87c0d31 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
@@ -39,8 +39,8 @@ import org.slf4j.LoggerFactory;
* (cmd.exe on Windows) and may not include any closing parentheses.<p>
*
* The shell command will be run with an environment set up to contain
- * all of the current Hadoop configuration variables, with the '_' character
- * replacing any '.' characters in the configuration keys.<p>
+ * all of the current Hadoop configuration variables, with the '_' character
+ * replacing any '.' or '-' characters in the configuration keys.<p>
*
* 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
@@ -202,11 +202,11 @@ public class ShellCommandFencer
/**
* 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) {
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 @@ public class ShellCommandFencer
for (Map.Entry<String, String> e :
target.getFencingParameters().entrySet()) {
String key = prefix + e.getKey();
- key = key.replace('.', '_');
+ key = key.replaceAll("[.-]", "_");
environment.put(key, e.getValue());
}
}
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
index 88afb35a8dd..3eb6f42e467 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
@@ -63,7 +63,7 @@ public class TestShellCommandFencer {
private static ShellCommandFencer createFencer() {
Configuration conf = new Configuration();
- conf.set("in.fencing.tests", "yessir");
+ conf.set("in.fencing-tests", "yessir");
ShellCommandFencer fencer = new ShellCommandFencer();
fencer.setConf(conf);
return fencer;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org