Skip to content

Commit 1577f57

Browse files
authored
HADOOP-19228. ShellCommandFencer#setConfAsEnvVars should also replace '-' with '_'. (#6936). Contributed by fuchaohong.
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
1 parent a5eb5e9 commit 1577f57

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public final Map<String, String> getFencingParameters() {
183183
* expose to fencing implementations/scripts. Fencing methods are free
184184
* to use this map as they see fit -- notably, the shell script
185185
* implementation takes each entry, prepends 'target_', substitutes
186-
* '_' for '.', and adds it to the environment of the script.
186+
* '_' for '.' and '-', and adds it to the environment of the script.
187187
*
188188
* Subclass implementations should be sure to delegate to the superclass
189189
* implementation as well as adding their own keys.

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
* (cmd.exe on Windows) and may not include any closing parentheses.<p>
4040
*
4141
* The shell command will be run with an environment set up to contain
42-
* all of the current Hadoop configuration variables, with the '_' character
43-
* replacing any '.' characters in the configuration keys.<p>
42+
* all of the current Hadoop configuration variables, with the '_' character
43+
* replacing any '.' or '-' characters in the configuration keys.<p>
4444
*
4545
* If the shell command returns an exit code of 0, the fencing is
4646
* determined to be successful. If it returns any other exit code, the
@@ -202,11 +202,11 @@ private static String tryGetPid(Process p) {
202202

203203
/**
204204
* Set the environment of the subprocess to be the Configuration,
205-
* with '.'s replaced by '_'s.
205+
* with '.'s and '-'s replaced by '_'s.
206206
*/
207207
private void setConfAsEnvVars(Map<String, String> env) {
208208
for (Map.Entry<String, String> pair : getConf()) {
209-
env.put(pair.getKey().replace('.', '_'), pair.getValue());
209+
env.put(pair.getKey().replaceAll("[.-]", "_"), pair.getValue());
210210
}
211211
}
212212

@@ -237,7 +237,7 @@ private void addTargetInfoAsEnvVars(HAServiceTarget target,
237237
for (Map.Entry<String, String> e :
238238
target.getFencingParameters().entrySet()) {
239239
String key = prefix + e.getKey();
240-
key = key.replace('.', '_');
240+
key = key.replaceAll("[.-]", "_");
241241
environment.put(key, e.getValue());
242242
}
243243
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void resetLogSpy() {
6363

6464
private static ShellCommandFencer createFencer() {
6565
Configuration conf = new Configuration();
66-
conf.set("in.fencing.tests", "yessir");
66+
conf.set("in.fencing-tests", "yessir");
6767
ShellCommandFencer fencer = new ShellCommandFencer();
6868
fencer.setConf(conf);
6969
return fencer;

0 commit comments

Comments
 (0)