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 1AB4D18D99 for ; Tue, 13 Oct 2015 20:49:42 +0000 (UTC) Received: (qmail 38189 invoked by uid 500); 13 Oct 2015 20:49:39 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 38117 invoked by uid 500); 13 Oct 2015 20:49:39 -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 38102 invoked by uid 99); 13 Oct 2015 20:49:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2015 20:49:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EF319DFF13; Tue, 13 Oct 2015 20:49:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stevel@apache.org To: common-commits@hadoop.apache.org Date: Tue, 13 Oct 2015 20:49:38 -0000 Message-Id: <0f90af78c18a4503975e490795afb815@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] hadoop git commit: HADOOP-10775. Shell operations to fail with meaningful errors on windows if winutils.exe not found. (stevel) Repository: hadoop Updated Branches: refs/heads/trunk eb50c4f7a -> c59af2fdf http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java index 987c706..6fc8969 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java @@ -45,13 +45,18 @@ public class TestWinUtils { private static final Log LOG = LogFactory.getLog(TestWinUtils.class); private static File TEST_DIR = new File(System.getProperty("test.build.data", - "/tmp"), TestWinUtils.class.getSimpleName()); + "target"+File.pathSeparator + "tmp"), TestWinUtils.class.getSimpleName()); + + String winutils; @Before - public void setUp() { + public void setUp() throws IOException { // Not supported on non-Windows platforms assumeTrue(Shell.WINDOWS); TEST_DIR.mkdirs(); + assertTrue("Failed to create Test directory " + TEST_DIR, + TEST_DIR.isDirectory() ); + winutils = Shell.getWinutilsPath(); } @After @@ -59,46 +64,55 @@ public class TestWinUtils { FileUtil.fullyDelete(TEST_DIR); } + private void requireWinutils() throws IOException { + Shell.getWinutilsPath(); + } + // Helper routine that writes the given content to the file. private void writeFile(File file, String content) throws IOException { byte[] data = content.getBytes(); - FileOutputStream os = new FileOutputStream(file); - os.write(data); - os.close(); + try (FileOutputStream os = new FileOutputStream(file)) { + os.write(data); + os.close(); + } } // Helper routine that reads the first 100 bytes from the file. private String readFile(File file) throws IOException { - FileInputStream fos = new FileInputStream(file); - byte[] b = new byte[100]; - fos.read(b); - return b.toString(); + byte[] b; + try (FileInputStream fos = new FileInputStream(file)) { + b = new byte[100]; + int count = fos.read(b); + assertEquals(100, count); + } + return new String(b); } @Test (timeout = 30000) public void testLs() throws IOException { + requireWinutils(); final String content = "6bytes"; final int contentSize = content.length(); File testFile = new File(TEST_DIR, "file1"); writeFile(testFile, content); // Verify permissions and file name return tokens + String testPath = testFile.getCanonicalPath(); String output = Shell.execCommand( - Shell.WINUTILS, "ls", testFile.getCanonicalPath()); + winutils, "ls", testPath); String[] outputArgs = output.split("[ \r\n]"); - assertTrue(outputArgs[0].equals("-rwx------")); - assertTrue(outputArgs[outputArgs.length - 1] - .equals(testFile.getCanonicalPath())); + assertEquals("-rwx------", outputArgs[0]); + assertEquals(outputArgs[outputArgs.length - 1], testPath); // Verify most tokens when using a formatted output (other tokens // will be verified with chmod/chown) output = Shell.execCommand( - Shell.WINUTILS, "ls", "-F", testFile.getCanonicalPath()); + winutils, "ls", "-F", testPath); outputArgs = output.split("[|\r\n]"); assertEquals(9, outputArgs.length); - assertTrue(outputArgs[0].equals("-rwx------")); + assertEquals("-rwx------", outputArgs[0]); assertEquals(contentSize, Long.parseLong(outputArgs[4])); - assertTrue(outputArgs[8].equals(testFile.getCanonicalPath())); + assertEquals(outputArgs[8], testPath); testFile.delete(); assertFalse(testFile.exists()); @@ -106,41 +120,42 @@ public class TestWinUtils { @Test (timeout = 30000) public void testGroups() throws IOException { + requireWinutils(); String currentUser = System.getProperty("user.name"); // Verify that groups command returns information about the current user // groups when invoked with no args String outputNoArgs = Shell.execCommand( - Shell.WINUTILS, "groups").trim(); + winutils, "groups").trim(); String output = Shell.execCommand( - Shell.WINUTILS, "groups", currentUser).trim(); + winutils, "groups", currentUser).trim(); assertEquals(output, outputNoArgs); // Verify that groups command with the -F flag returns the same information String outputFormat = Shell.execCommand( - Shell.WINUTILS, "groups", "-F", currentUser).trim(); + winutils, "groups", "-F", currentUser).trim(); outputFormat = outputFormat.replace("|", " "); assertEquals(output, outputFormat); } private void chmod(String mask, File file) throws IOException { Shell.execCommand( - Shell.WINUTILS, "chmod", mask, file.getCanonicalPath()); + winutils, "chmod", mask, file.getCanonicalPath()); } private void chmodR(String mask, File file) throws IOException { Shell.execCommand( - Shell.WINUTILS, "chmod", "-R", mask, file.getCanonicalPath()); + winutils, "chmod", "-R", mask, file.getCanonicalPath()); } private String ls(File file) throws IOException { return Shell.execCommand( - Shell.WINUTILS, "ls", file.getCanonicalPath()); + winutils, "ls", file.getCanonicalPath()); } private String lsF(File file) throws IOException { return Shell.execCommand( - Shell.WINUTILS, "ls", "-F", file.getCanonicalPath()); + winutils, "ls", "-F", file.getCanonicalPath()); } private void assertPermissions(File file, String expected) @@ -151,6 +166,7 @@ public class TestWinUtils { private void testChmodInternal(String mode, String expectedPerm) throws IOException { + requireWinutils(); File a = new File(TEST_DIR, "file1"); assertTrue(a.createNewFile()); @@ -168,6 +184,7 @@ public class TestWinUtils { } private void testNewFileChmodInternal(String expectedPerm) throws IOException { + requireWinutils(); // Create a new directory File dir = new File(TEST_DIR, "dir1"); @@ -190,6 +207,7 @@ public class TestWinUtils { private void testChmodInternalR(String mode, String expectedPerm, String expectedPermx) throws IOException { + requireWinutils(); // Setup test folder hierarchy File a = new File(TEST_DIR, "a"); assertTrue(a.mkdir()); @@ -226,6 +244,7 @@ public class TestWinUtils { @Test (timeout = 30000) public void testBasicChmod() throws IOException { + requireWinutils(); // - Create a file. // - Change mode to 377 so owner does not have read permission. // - Verify the owner truly does not have the permissions to read. @@ -249,7 +268,7 @@ public class TestWinUtils { try { writeFile(a, "test"); - assertFalse("writeFile should have failed!", true); + fail("writeFile should have failed!"); } catch (IOException ex) { LOG.info("Expected: Failed write to a file with permissions 577"); } @@ -261,14 +280,14 @@ public class TestWinUtils { // - Change mode to 677 so owner does not have execute permission. // - Verify the owner truly does not have the permissions to execute the file. - File winutilsFile = new File(Shell.WINUTILS); + File winutilsFile = Shell.getWinutilsFile(); File aExe = new File(TEST_DIR, "a.exe"); FileUtils.copyFile(winutilsFile, aExe); chmod("677", aExe); try { Shell.execCommand(aExe.getCanonicalPath(), "ls"); - assertFalse("executing " + aExe + " should have failed!", true); + fail("executing " + aExe + " should have failed!"); } catch (IOException ex) { LOG.info("Expected: Failed to execute a file with permissions 677"); } @@ -278,6 +297,7 @@ public class TestWinUtils { /** Validate behavior of chmod commands on directories on Windows. */ @Test (timeout = 30000) public void testBasicChmodOnDir() throws IOException { + requireWinutils(); // Validate that listing a directory with no read permission fails File a = new File(TEST_DIR, "a"); File b = new File(a, "b"); @@ -287,8 +307,7 @@ public class TestWinUtils { // Remove read permissions on directory a chmod("300", a); String[] files = a.list(); - assertTrue("Listing a directory without read permission should fail", - null == files); + assertNull("Listing a directory without read permission should fail", files); // restore permissions chmod("700", a); @@ -306,7 +325,7 @@ public class TestWinUtils { // FILE_WRITE_DATA/FILE_ADD_FILE privilege is denied on // the dir. c.createNewFile(); - assertFalse("writeFile should have failed!", true); + fail("writeFile should have failed!"); } catch (IOException ex) { LOG.info("Expected: Failed to create a file when directory " + "permissions are 577"); @@ -356,6 +375,7 @@ public class TestWinUtils { @Test (timeout = 30000) public void testChmod() throws IOException { + requireWinutils(); testChmodInternal("7", "-------rwx"); testChmodInternal("70", "----rwx---"); testChmodInternal("u-x,g+r,o=g", "-rw-r--r--"); @@ -376,7 +396,7 @@ public class TestWinUtils { private void chown(String userGroup, File file) throws IOException { Shell.execCommand( - Shell.WINUTILS, "chown", userGroup, file.getCanonicalPath()); + winutils, "chown", userGroup, file.getCanonicalPath()); } private void assertOwners(File file, String expectedUser, @@ -390,6 +410,7 @@ public class TestWinUtils { @Test (timeout = 30000) public void testChown() throws IOException { + requireWinutils(); File a = new File(TEST_DIR, "a"); assertTrue(a.createNewFile()); String username = System.getProperty("user.name"); @@ -415,12 +436,13 @@ public class TestWinUtils { @Test (timeout = 30000) public void testSymlinkRejectsForwardSlashesInLink() throws IOException { + requireWinutils(); File newFile = new File(TEST_DIR, "file"); assertTrue(newFile.createNewFile()); String target = newFile.getPath(); String link = new File(TEST_DIR, "link").getPath().replaceAll("\\\\", "/"); try { - Shell.execCommand(Shell.WINUTILS, "symlink", link, target); + Shell.execCommand(winutils, "symlink", link, target); fail(String.format("did not receive expected failure creating symlink " + "with forward slashes in link: link = %s, target = %s", link, target)); } catch (IOException e) { @@ -431,12 +453,13 @@ public class TestWinUtils { @Test (timeout = 30000) public void testSymlinkRejectsForwardSlashesInTarget() throws IOException { + requireWinutils(); File newFile = new File(TEST_DIR, "file"); assertTrue(newFile.createNewFile()); String target = newFile.getPath().replaceAll("\\\\", "/"); String link = new File(TEST_DIR, "link").getPath(); try { - Shell.execCommand(Shell.WINUTILS, "symlink", link, target); + Shell.execCommand(winutils, "symlink", link, target); fail(String.format("did not receive expected failure creating symlink " + "with forward slashes in target: link = %s, target = %s", link, target)); } catch (IOException e) { @@ -447,6 +470,7 @@ public class TestWinUtils { @Test (timeout = 30000) public void testReadLink() throws IOException { + requireWinutils(); // Create TEST_DIR\dir1\file1.txt // File dir1 = new File(TEST_DIR, "dir1"); @@ -462,18 +486,18 @@ public class TestWinUtils { // symlink to file1.txt. // Shell.execCommand( - Shell.WINUTILS, "symlink", dirLink.toString(), dir1.toString()); + winutils, "symlink", dirLink.toString(), dir1.toString()); Shell.execCommand( - Shell.WINUTILS, "symlink", fileLink.toString(), file1.toString()); + winutils, "symlink", fileLink.toString(), file1.toString()); // Read back the two links and ensure we get what we expected. // - String readLinkOutput = Shell.execCommand(Shell.WINUTILS, + String readLinkOutput = Shell.execCommand(winutils, "readlink", dirLink.toString()); assertThat(readLinkOutput, equalTo(dir1.toString())); - readLinkOutput = Shell.execCommand(Shell.WINUTILS, + readLinkOutput = Shell.execCommand(winutils, "readlink", fileLink.toString()); assertThat(readLinkOutput, equalTo(file1.toString())); @@ -483,7 +507,7 @@ public class TestWinUtils { try { // No link name specified. // - Shell.execCommand(Shell.WINUTILS, "readlink", ""); + Shell.execCommand(winutils, "readlink", ""); fail("Failed to get Shell.ExitCodeException when reading bad symlink"); } catch (Shell.ExitCodeException ece) { assertThat(ece.getExitCode(), is(1)); @@ -492,7 +516,7 @@ public class TestWinUtils { try { // Bad link name. // - Shell.execCommand(Shell.WINUTILS, "readlink", "ThereIsNoSuchLink"); + Shell.execCommand(winutils, "readlink", "ThereIsNoSuchLink"); fail("Failed to get Shell.ExitCodeException when reading bad symlink"); } catch (Shell.ExitCodeException ece) { assertThat(ece.getExitCode(), is(1)); @@ -501,7 +525,7 @@ public class TestWinUtils { try { // Non-symlink directory target. // - Shell.execCommand(Shell.WINUTILS, "readlink", dir1.toString()); + Shell.execCommand(winutils, "readlink", dir1.toString()); fail("Failed to get Shell.ExitCodeException when reading bad symlink"); } catch (Shell.ExitCodeException ece) { assertThat(ece.getExitCode(), is(1)); @@ -510,7 +534,7 @@ public class TestWinUtils { try { // Non-symlink file target. // - Shell.execCommand(Shell.WINUTILS, "readlink", file1.toString()); + Shell.execCommand(winutils, "readlink", file1.toString()); fail("Failed to get Shell.ExitCodeException when reading bad symlink"); } catch (Shell.ExitCodeException ece) { assertThat(ece.getExitCode(), is(1)); @@ -519,7 +543,7 @@ public class TestWinUtils { try { // Too many parameters. // - Shell.execCommand(Shell.WINUTILS, "readlink", "a", "b"); + Shell.execCommand(winutils, "readlink", "a", "b"); fail("Failed to get Shell.ExitCodeException with bad parameters"); } catch (Shell.ExitCodeException ece) { assertThat(ece.getExitCode(), is(1)); @@ -529,6 +553,7 @@ public class TestWinUtils { @SuppressWarnings("deprecation") @Test(timeout=10000) public void testTaskCreate() throws IOException { + requireWinutils(); File batch = new File(TEST_DIR, "testTaskCreate.cmd"); File proof = new File(TEST_DIR, "testTaskCreate.out"); FileWriter fw = new FileWriter(batch); @@ -538,7 +563,7 @@ public class TestWinUtils { assertFalse(proof.exists()); - Shell.execCommand(Shell.WINUTILS, "task", "create", "testTaskCreate" + testNumber, + Shell.execCommand(winutils, "task", "create", "testTaskCreate" + testNumber, batch.getAbsolutePath()); assertTrue(proof.exists()); @@ -550,30 +575,31 @@ public class TestWinUtils { @Test (timeout = 30000) public void testTaskCreateWithLimits() throws IOException { + requireWinutils(); // Generate a unique job id String jobId = String.format("%f", Math.random()); // Run a task without any options - String out = Shell.execCommand(Shell.WINUTILS, "task", "create", + String out = Shell.execCommand(winutils, "task", "create", "job" + jobId, "cmd /c echo job" + jobId); assertTrue(out.trim().equals("job" + jobId)); // Run a task without any limits jobId = String.format("%f", Math.random()); - out = Shell.execCommand(Shell.WINUTILS, "task", "create", "-c", "-1", "-m", + out = Shell.execCommand(winutils, "task", "create", "-c", "-1", "-m", "-1", "job" + jobId, "cmd /c echo job" + jobId); assertTrue(out.trim().equals("job" + jobId)); // Run a task with limits (128MB should be enough for a cmd) jobId = String.format("%f", Math.random()); - out = Shell.execCommand(Shell.WINUTILS, "task", "create", "-c", "10000", "-m", + out = Shell.execCommand(winutils, "task", "create", "-c", "10000", "-m", "128", "job" + jobId, "cmd /c echo job" + jobId); assertTrue(out.trim().equals("job" + jobId)); // Run a task without enough memory try { jobId = String.format("%f", Math.random()); - out = Shell.execCommand(Shell.WINUTILS, "task", "create", "-m", "128", "job" + out = Shell.execCommand(winutils, "task", "create", "-m", "128", "job" + jobId, "java -Xmx256m -version"); fail("Failed to get Shell.ExitCodeException with insufficient memory"); } catch (Shell.ExitCodeException ece) { @@ -584,7 +610,7 @@ public class TestWinUtils { // try { jobId = String.format("%f", Math.random()); - Shell.execCommand(Shell.WINUTILS, "task", "create", "-c", "-1", "-m", + Shell.execCommand(winutils, "task", "create", "-c", "-1", "-m", "-1", "foo", "job" + jobId, "cmd /c echo job" + jobId); fail("Failed to get Shell.ExitCodeException with bad parameters"); } catch (Shell.ExitCodeException ece) { @@ -593,7 +619,7 @@ public class TestWinUtils { try { jobId = String.format("%f", Math.random()); - Shell.execCommand(Shell.WINUTILS, "task", "create", "-c", "-m", "-1", + Shell.execCommand(winutils, "task", "create", "-c", "-m", "-1", "job" + jobId, "cmd /c echo job" + jobId); fail("Failed to get Shell.ExitCodeException with bad parameters"); } catch (Shell.ExitCodeException ece) { @@ -602,7 +628,7 @@ public class TestWinUtils { try { jobId = String.format("%f", Math.random()); - Shell.execCommand(Shell.WINUTILS, "task", "create", "-c", "foo", + Shell.execCommand(winutils, "task", "create", "-c", "foo", "job" + jobId, "cmd /c echo job" + jobId); fail("Failed to get Shell.ExitCodeException with bad parameters"); } catch (Shell.ExitCodeException ece) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/WindowsBasedProcessTree.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/WindowsBasedProcessTree.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/WindowsBasedProcessTree.java index ebe8df1..41b26f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/WindowsBasedProcessTree.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/WindowsBasedProcessTree.java @@ -51,8 +51,11 @@ public class WindowsBasedProcessTree extends ResourceCalculatorProcessTree { public static boolean isAvailable() { if (Shell.WINDOWS) { + if (!Shell.hasWinutilsPath()) { + return false; + } ShellCommandExecutor shellExecutor = new ShellCommandExecutor( - new String[] { Shell.WINUTILS, "help" }); + new String[] { Shell.getWinutilsPath(), "help" }); try { shellExecutor.execute(); } catch (IOException e) { @@ -75,9 +78,10 @@ public class WindowsBasedProcessTree extends ResourceCalculatorProcessTree { // helper method to override while testing String getAllProcessInfoFromShell() { - ShellCommandExecutor shellExecutor = new ShellCommandExecutor( - new String[] { Shell.WINUTILS, "task", "processList", taskProcessId }); try { + ShellCommandExecutor shellExecutor = new ShellCommandExecutor( + new String[] {Shell.getWinutilsFile().getCanonicalPath(), + "task", "processList", taskProcessId }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java index 68bfbbf..a83ef84 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java @@ -401,7 +401,7 @@ public abstract class ContainerExecutor implements Configurable { cpuRate = Math.min(10000, (int) (containerCpuPercentage * 100)); } } - return new String[] { Shell.WINUTILS, "task", "create", "-m", + return new String[] { Shell.getWinutilsPath(), "task", "create", "-m", String.valueOf(memory), "-c", String.valueOf(cpuRate), groupId, "cmd /c " + command }; } else { http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java index fd2e31b..70fdcda 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java @@ -578,7 +578,8 @@ public class WindowsSecureContainerExecutor extends DefaultContainerExecutor { LOG.debug(String.format("getRunCommand: %s exists:%b", command, f.exists())); } - return new String[] { Shell.WINUTILS, "task", "createAsUser", groupId, + return new String[] { Shell.getWinutilsPath(), "task", + "createAsUser", groupId, userName, pidFile.toString(), "cmd /c " + command }; } http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java index 9718098..4349332 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java @@ -24,7 +24,6 @@ import static org.apache.hadoop.fs.CreateFlag.OVERWRITE; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintStream; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -747,16 +746,9 @@ public class ContainerLaunch implements Callable { File srcFile = new File(src.toUri().getPath()); String srcFileStr = srcFile.getPath(); String dstFileStr = new File(dst.toString()).getPath(); - // If not on Java7+ on Windows, then copy file instead of symlinking. - // See also FileUtil#symLink for full explanation. - if (!Shell.isJava7OrAbove() && srcFile.isFile()) { - lineWithLenCheck(String.format("@copy \"%s\" \"%s\"", srcFileStr, dstFileStr)); - errorCheck(); - } else { - lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.WINUTILS, - dstFileStr, srcFileStr)); - errorCheck(); - } + lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", + Shell.getWinutilsPath(), dstFileStr, srcFileStr)); + errorCheck(); } @Override http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java index 2ebf4ec..bc87b03 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java @@ -34,6 +34,7 @@ import org.junit.Test; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; +@SuppressWarnings("deprecation") public class TestContainerExecutor { private ContainerExecutor containerExecutor = new DefaultContainerExecutor(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/c59af2fd/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java index ea6bb1d..f85b01e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java @@ -978,7 +978,7 @@ public class TestContainerLaunch extends BaseContainerManagerTest { Assume.assumeTrue(Shell.WINDOWS); // The tests are built on assuming 8191 max command line length - assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT); + assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH); ShellScriptBuilder builder = ShellScriptBuilder.create(); @@ -987,11 +987,11 @@ public class TestContainerLaunch extends BaseContainerManagerTest { org.apache.commons.lang.StringUtils.repeat("A", 1024))); builder.command(Arrays.asList( org.apache.commons.lang.StringUtils.repeat( - "E", Shell.WINDOWS_MAX_SHELL_LENGHT - callCmd.length()))); + "E", Shell.WINDOWS_MAX_SHELL_LENGTH - callCmd.length()))); try { builder.command(Arrays.asList( org.apache.commons.lang.StringUtils.repeat( - "X", Shell.WINDOWS_MAX_SHELL_LENGHT -callCmd.length() + 1))); + "X", Shell.WINDOWS_MAX_SHELL_LENGTH -callCmd.length() + 1))); fail("longCommand was expected to throw"); } catch(IOException e) { assertThat(e.getMessage(), containsString(expectedMessage)); @@ -1026,17 +1026,17 @@ public class TestContainerLaunch extends BaseContainerManagerTest { Assume.assumeTrue(Shell.WINDOWS); // The tests are built on assuming 8191 max command line length - assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT); + assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH); ShellScriptBuilder builder = ShellScriptBuilder.create(); // test env builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", 1024)); builder.env("somekey", org.apache.commons.lang.StringUtils.repeat( - "A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length())); + "A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length())); try { builder.env("somekey", org.apache.commons.lang.StringUtils.repeat( - "A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length()) + 1); + "A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length()) + 1); fail("long env was expected to throw"); } catch(IOException e) { assertThat(e.getMessage(), containsString(expectedMessage)); @@ -1051,17 +1051,17 @@ public class TestContainerLaunch extends BaseContainerManagerTest { Assume.assumeTrue(Shell.WINDOWS); // The tests are built on assuming 8191 max command line length - assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT); + assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH); ShellScriptBuilder builder = ShellScriptBuilder.create(); // test mkdir builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat("A", 1024))); builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat( - "E", (Shell.WINDOWS_MAX_SHELL_LENGHT - mkDirCmd.length())/2))); + "E", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length())/2))); try { builder.mkdir(new Path(org.apache.commons.lang.StringUtils.repeat( - "X", (Shell.WINDOWS_MAX_SHELL_LENGHT - mkDirCmd.length())/2 +1))); + "X", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length())/2 +1))); fail("long mkdir was expected to throw"); } catch(IOException e) { assertThat(e.getMessage(), containsString(expectedMessage)); @@ -1072,11 +1072,10 @@ public class TestContainerLaunch extends BaseContainerManagerTest { public void testWindowsShellScriptBuilderLink() throws IOException { // Test is only relevant on Windows Assume.assumeTrue(Shell.WINDOWS); - - String linkCmd = "@" +Shell.WINUTILS + " symlink \"\" \"\""; + String linkCmd = "@" + Shell.getWinutilsPath() + " symlink \"\" \"\""; // The tests are built on assuming 8191 max command line length - assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT); + assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH); ShellScriptBuilder builder = ShellScriptBuilder.create(); @@ -1085,15 +1084,15 @@ public class TestContainerLaunch extends BaseContainerManagerTest { new Path(org.apache.commons.lang.StringUtils.repeat("B", 1024))); builder.link( new Path(org.apache.commons.lang.StringUtils.repeat( - "E", (Shell.WINDOWS_MAX_SHELL_LENGHT - linkCmd.length())/2)), + "E", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2)), new Path(org.apache.commons.lang.StringUtils.repeat( - "F", (Shell.WINDOWS_MAX_SHELL_LENGHT - linkCmd.length())/2))); + "F", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2))); try { builder.link( new Path(org.apache.commons.lang.StringUtils.repeat( - "X", (Shell.WINDOWS_MAX_SHELL_LENGHT - linkCmd.length())/2 + 1)), + "X", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2 + 1)), new Path(org.apache.commons.lang.StringUtils.repeat( - "Y", (Shell.WINDOWS_MAX_SHELL_LENGHT - linkCmd.length())/2) + 1)); + "Y", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2) + 1)); fail("long link was expected to throw"); } catch(IOException e) { assertThat(e.getMessage(), containsString(expectedMessage));