Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 32C80F3C2 for ; Sun, 28 Apr 2013 23:17:13 +0000 (UTC) Received: (qmail 66483 invoked by uid 500); 28 Apr 2013 23:17:13 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 66293 invoked by uid 500); 28 Apr 2013 23:17:12 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 66278 invoked by uid 99); 28 Apr 2013 23:17:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Apr 2013 23:17:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Apr 2013 23:17:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 97AFA23888E3; Sun, 28 Apr 2013 23:16:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1476856 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java src/test/java/org/apache/hadoop/ha/TestNodeFencer.java Date: Sun, 28 Apr 2013 23:16:48 -0000 To: common-commits@hadoop.apache.org From: suresh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130428231648.97AFA23888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: suresh Date: Sun Apr 28 23:16:47 2013 New Revision: 1476856 URL: http://svn.apache.org/r1476856 Log: HADOOP-9524. Fix ShellCommandFencer to work on Windows. Contributed by Arpit Agarwal. Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestNodeFencer.java Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1476856&r1=1476855&r2=1476856&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Sun Apr 28 23:16:47 2013 @@ -528,6 +528,9 @@ Trunk (Unreleased) HADOOP-9490. LocalFileSystem#reportChecksumFailure not closing the checksum file handle before rename. (Ivan Mitic via suresh) + + HADOOP-9524. Fix ShellCommandFencer to work on Windows. + (Arpit Agarwal via suresh) Release 2.0.5-beta - UNRELEASED Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java?rev=1476856&r1=1476855&r2=1476856&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java Sun Apr 28 23:16:47 2013 @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFac import org.apache.hadoop.conf.Configured; import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.util.Shell; /** * Fencing method that runs a shell command. It should be specified @@ -33,8 +34,8 @@ import com.google.common.annotations.Vis * * shell(/path/to/my/script.sh arg1 arg2 ...) *
- * The string between '(' and ')' is passed directly to a bash shell and - * may not include any closing parentheses.

+ * The string between '(' and ')' is passed directly to a bash shell + * (cmd.exe on Windows) and may not include any closing parentheses.

* * The shell command will be run with an environment set up to contain * all of the current Hadoop configuration variables, with the '_' character @@ -58,11 +59,11 @@ public class ShellCommandFencer /** Prefix for target parameters added to the environment */ private static final String TARGET_PREFIX = "target_"; - + @VisibleForTesting static Log LOG = LogFactory.getLog( ShellCommandFencer.class); - + @Override public void checkArgs(String args) throws BadFencingConfigurationException { if (args == null || args.isEmpty()) { @@ -74,8 +75,14 @@ public class ShellCommandFencer @Override public boolean tryFence(HAServiceTarget target, String cmd) { - ProcessBuilder builder = new ProcessBuilder( - "bash", "-e", "-c", cmd); + ProcessBuilder builder; + + if (!Shell.WINDOWS) { + builder = new ProcessBuilder("bash", "-e", "-c", cmd); + } else { + builder = new ProcessBuilder("cmd.exe", "/c", cmd); + } + setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestNodeFencer.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestNodeFencer.java?rev=1476856&r1=1476855&r2=1476856&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestNodeFencer.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestNodeFencer.java Sun Apr 28 23:16:47 2013 @@ -24,6 +24,7 @@ import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.util.Shell; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -33,7 +34,12 @@ import com.google.common.collect.Lists; public class TestNodeFencer { private HAServiceTarget MOCK_TARGET; - + + // Fencer shell commands that always return true on Unix and Windows + // respectively. Lacking the POSIX 'true' command on Windows, we use + // the batch command 'rem'. + private static String FENCER_TRUE_COMMAND_UNIX = "shell(true)"; + private static String FENCER_TRUE_COMMAND_WINDOWS = "shell(rem)"; @Before public void clearMockState() { @@ -48,6 +54,11 @@ public class TestNodeFencer { .when(MOCK_TARGET).getAddress(); } + private static String getFencerTrueCommand() { + return Shell.WINDOWS ? + FENCER_TRUE_COMMAND_WINDOWS : FENCER_TRUE_COMMAND_UNIX; + } + @Test public void testSingleFencer() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer( @@ -100,7 +111,7 @@ public class TestNodeFencer { @Test public void testShortNameShell() throws BadFencingConfigurationException { - NodeFencer fencer = setupFencer("shell(true)"); + NodeFencer fencer = setupFencer(getFencerTrueCommand()); assertTrue(fencer.fence(MOCK_TARGET)); }