Skip to content

Commit

Permalink
HADOOP-12478. Shell.getWinUtilsPath() has been renamed Shell.getWinut…
Browse files Browse the repository at this point in the history
…ilsPath(). (stevel)
  • Loading branch information
steveloughran committed Oct 14, 2015
1 parent ab13aa3 commit dfa7848
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Expand Up @@ -1225,6 +1225,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-11515. Upgrade jsch lib to jsch-0.1.51 to avoid problems running HADOOP-11515. Upgrade jsch lib to jsch-0.1.51 to avoid problems running
on java7. (stevel and ozawa) on java7. (stevel and ozawa)


HADOOP-12478. Shell.getWinUtilsPath() has been renamed
Shell.getWinutilsPath(). (stevel)

OPTIMIZATIONS OPTIMIZATIONS


HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()
Expand Down
Expand Up @@ -137,7 +137,7 @@ static class HardLinkCGWin extends HardLinkCommandGetter {
@Override @Override
String[] linkCount(File file) throws IOException { String[] linkCount(File file) throws IOException {
// trigger the check for winutils // trigger the check for winutils
Shell.getWinutilsFile(); Shell.getWinUtilsFile();
String[] buf = new String[getLinkCountCommand.length]; String[] buf = new String[getLinkCountCommand.length];
System.arraycopy(getLinkCountCommand, 0, buf, 0, System.arraycopy(getLinkCountCommand, 0, buf, 0,
getLinkCountCommand.length); getLinkCountCommand.length);
Expand Down
Expand Up @@ -108,7 +108,7 @@ public static void main(String[] args) {
if (Shell.WINDOWS) { if (Shell.WINDOWS) {
// winutils.exe is required on Windows // winutils.exe is required on Windows
try { try {
winutilsPath = Shell.getWinutilsFile().getCanonicalPath(); winutilsPath = Shell.getWinUtilsFile().getCanonicalPath();
winutilsExists = true; winutilsExists = true;
} catch (IOException e) { } catch (IOException e) {
LOG.debug("No Winutils: ", e); LOG.debug("No Winutils: ", e);
Expand Down
Expand Up @@ -185,7 +185,7 @@ public static String[] getGroupsForUserCommand(final String user) {
//'groups username' command return is inconsistent across different unixes //'groups username' command return is inconsistent across different unixes
return WINDOWS ? return WINDOWS ?
new String[] new String[]
{ getWinutilsPath(), "groups", "-F", "\"" + user + "\"" } { getWinUtilsPath(), "groups", "-F", "\"" + user + "\"" }
: new String [] {"bash", "-c", "id -gn " + user + "&& id -Gn " + user}; : new String [] {"bash", "-c", "id -gn " + user + "&& id -Gn " + user};
} }


Expand All @@ -198,19 +198,19 @@ public static String[] getUsersForNetgroupCommand(final String netgroup) {


/** Return a command to get permission information. */ /** Return a command to get permission information. */
public static String[] getGetPermissionCommand() { public static String[] getGetPermissionCommand() {
return (WINDOWS) ? new String[] { getWinutilsPath(), "ls", "-F" } return (WINDOWS) ? new String[] { getWinUtilsPath(), "ls", "-F" }
: new String[] { "/bin/ls", "-ld" }; : new String[] { "/bin/ls", "-ld" };
} }


/** Return a command to set permission. */ /** Return a command to set permission. */
public static String[] getSetPermissionCommand(String perm, boolean recursive) { public static String[] getSetPermissionCommand(String perm, boolean recursive) {
if (recursive) { if (recursive) {
return (WINDOWS) ? return (WINDOWS) ?
new String[] { getWinutilsPath(), "chmod", "-R", perm } new String[] { getWinUtilsPath(), "chmod", "-R", perm }
: new String[] { "chmod", "-R", perm }; : new String[] { "chmod", "-R", perm };
} else { } else {
return (WINDOWS) ? return (WINDOWS) ?
new String[] { getWinutilsPath(), "chmod", perm } new String[] { getWinUtilsPath(), "chmod", perm }
: new String[] { "chmod", perm }; : new String[] { "chmod", perm };
} }
} }
Expand All @@ -234,21 +234,21 @@ public static String[] getSetPermissionCommand(String perm,
/** Return a command to set owner. */ /** Return a command to set owner. */
public static String[] getSetOwnerCommand(String owner) { public static String[] getSetOwnerCommand(String owner) {
return (WINDOWS) ? return (WINDOWS) ?
new String[] { getWinutilsPath(), "chown", "\"" + owner + "\"" } new String[] { getWinUtilsPath(), "chown", "\"" + owner + "\"" }
: new String[] { "chown", owner }; : new String[] { "chown", owner };
} }


/** Return a command to create symbolic links. */ /** Return a command to create symbolic links. */
public static String[] getSymlinkCommand(String target, String link) { public static String[] getSymlinkCommand(String target, String link) {
return WINDOWS ? return WINDOWS ?
new String[] { getWinutilsPath(), "symlink", link, target } new String[] { getWinUtilsPath(), "symlink", link, target }
: new String[] { "ln", "-s", target, link }; : new String[] { "ln", "-s", target, link };
} }


/** Return a command to read the target of the a symbolic link. */ /** Return a command to read the target of the a symbolic link. */
public static String[] getReadlinkCommand(String link) { public static String[] getReadlinkCommand(String link) {
return WINDOWS ? return WINDOWS ?
new String[] { getWinutilsPath(), "readlink", link } new String[] { getWinUtilsPath(), "readlink", link }
: new String[] { "readlink", link }; : new String[] { "readlink", link };
} }


Expand All @@ -266,9 +266,9 @@ public static String[] getSignalKillCommand(int code, String pid) {
// Code == 0 means check alive // Code == 0 means check alive
if (Shell.WINDOWS) { if (Shell.WINDOWS) {
if (0 == code) { if (0 == code) {
return new String[] {Shell.getWinutilsPath(), "task", "isAlive", pid }; return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid };
} else { } else {
return new String[] {Shell.getWinutilsPath(), "task", "kill", pid }; return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid };
} }
} }


Expand Down Expand Up @@ -590,7 +590,7 @@ public static String getQualifiedBinPath(String executable)
* The lack of such checks has led to many support issues being raised. * The lack of such checks has led to many support issues being raised.
* <p> * <p>
* @deprecated use one of the exception-raising getter methods, * @deprecated use one of the exception-raising getter methods,
* specifically {@link #getWinutilsPath()} or {@link #getWinutilsFile()} * specifically {@link #getWinUtilsPath()} or {@link #getWinUtilsFile()}
*/ */
@Deprecated @Deprecated
public static final String WINUTILS; public static final String WINUTILS;
Expand Down Expand Up @@ -646,7 +646,7 @@ public static String getQualifiedBinPath(String executable)
* Predicate to indicate whether or not the path to winutils is known. * Predicate to indicate whether or not the path to winutils is known.
* *
* If true, then {@link #WINUTILS} is non-null, and both * If true, then {@link #WINUTILS} is non-null, and both
* {@link #getWinutilsPath()} and {@link #getWinutilsFile()} * {@link #getWinUtilsPath()} and {@link #getWinUtilsFile()}
* will successfully return this value. Always false on non-windows systems. * will successfully return this value. Always false on non-windows systems.
* @return true if there is a valid path to the binary * @return true if there is a valid path to the binary
*/ */
Expand All @@ -662,7 +662,7 @@ public static boolean hasWinutilsPath() {
* @return the path to {@link #WINUTILS_EXE} * @return the path to {@link #WINUTILS_EXE}
* @throws RuntimeException if the path is not resolvable * @throws RuntimeException if the path is not resolvable
*/ */
public static String getWinutilsPath() { public static String getWinUtilsPath() {
if (WINUTILS_FAILURE == null) { if (WINUTILS_FAILURE == null) {
return WINUTILS_PATH; return WINUTILS_PATH;
} else { } else {
Expand All @@ -677,7 +677,7 @@ public static String getWinutilsPath() {
* @return the file instance referring to the winutils bin. * @return the file instance referring to the winutils bin.
* @throws FileNotFoundException on any failure to locate that file. * @throws FileNotFoundException on any failure to locate that file.
*/ */
public static File getWinutilsFile() throws FileNotFoundException { public static File getWinUtilsFile() throws FileNotFoundException {
if (WINUTILS_FAILURE == null) { if (WINUTILS_FAILURE == null) {
return WINUTILS_FILE; return WINUTILS_FILE;
} else { } else {
Expand Down
Expand Up @@ -72,7 +72,7 @@ void reset() {
String getSystemInfoInfoFromShell() { String getSystemInfoInfoFromShell() {
try { try {
ShellCommandExecutor shellExecutor = new ShellCommandExecutor( ShellCommandExecutor shellExecutor = new ShellCommandExecutor(
new String[] {Shell.getWinutilsFile().getCanonicalPath(), new String[] {Shell.getWinUtilsFile().getCanonicalPath(),
"systeminfo" }); "systeminfo" });
shellExecutor.execute(); shellExecutor.execute();
return shellExecutor.getOutput(); return shellExecutor.getOutput();
Expand Down
Expand Up @@ -218,7 +218,7 @@ public void testGetServerSideGroups() throws IOException,
} }
// get the groups // get the groups
pp = Runtime.getRuntime().exec(Shell.WINDOWS ? pp = Runtime.getRuntime().exec(Shell.WINDOWS ?
Shell.getWinutilsPath() + " groups -F" Shell.getWinUtilsPath() + " groups -F"
: "id -Gn"); : "id -Gn");
br = new BufferedReader(new InputStreamReader(pp.getInputStream())); br = new BufferedReader(new InputStreamReader(pp.getInputStream()));
String line = br.readLine(); String line = br.readLine();
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void testGetCheckProcessIsAliveCommand() throws Exception {


if (Shell.WINDOWS) { if (Shell.WINDOWS) {
expectedCommand = expectedCommand =
new String[]{getWinutilsPath(), "task", "isAlive", anyPid }; new String[]{getWinUtilsPath(), "task", "isAlive", anyPid };
} else if (Shell.isSetsidAvailable) { } else if (Shell.isSetsidAvailable) {
expectedCommand = new String[] { "bash", "-c", "kill -0 -- -" + anyPid }; expectedCommand = new String[] { "bash", "-c", "kill -0 -- -" + anyPid };
} else { } else {
Expand All @@ -214,7 +214,7 @@ public void testGetSignalKillCommand() throws Exception {


if (Shell.WINDOWS) { if (Shell.WINDOWS) {
expectedCommand = expectedCommand =
new String[]{getWinutilsPath(), "task", "kill", anyPid }; new String[]{getWinUtilsPath(), "task", "kill", anyPid };
} else if (Shell.isSetsidAvailable) { } else if (Shell.isSetsidAvailable) {
expectedCommand = new String[] { "bash", "-c", "kill -9 -- -" + anyPid }; expectedCommand = new String[] { "bash", "-c", "kill -9 -- -" + anyPid };
} else { } else {
Expand Down Expand Up @@ -342,12 +342,12 @@ public void testBinWinUtilsNotAFile() throws Throwable {
public void testNoWinutilsOnUnix() throws Throwable { public void testNoWinutilsOnUnix() throws Throwable {
Assume.assumeFalse(WINDOWS); Assume.assumeFalse(WINDOWS);
try { try {
getWinutilsFile(); getWinUtilsFile();
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
assertExContains(ex, E_NOT_A_WINDOWS_SYSTEM); assertExContains(ex, E_NOT_A_WINDOWS_SYSTEM);
} }
try { try {
getWinutilsPath(); getWinUtilsPath();
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
assertExContains(ex, E_NOT_A_WINDOWS_SYSTEM); assertExContains(ex, E_NOT_A_WINDOWS_SYSTEM);
if ( ex.getCause() == null if ( ex.getCause() == null
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void setUp() throws IOException {
TEST_DIR.mkdirs(); TEST_DIR.mkdirs();
assertTrue("Failed to create Test directory " + TEST_DIR, assertTrue("Failed to create Test directory " + TEST_DIR,
TEST_DIR.isDirectory() ); TEST_DIR.isDirectory() );
winutils = Shell.getWinutilsPath(); winutils = Shell.getWinUtilsPath();
} }


@After @After
Expand All @@ -65,7 +65,7 @@ public void tearDown() throws IOException {
} }


private void requireWinutils() throws IOException { private void requireWinutils() throws IOException {
Shell.getWinutilsPath(); Shell.getWinUtilsPath();
} }


// Helper routine that writes the given content to the file. // Helper routine that writes the given content to the file.
Expand Down Expand Up @@ -280,7 +280,7 @@ public void testBasicChmod() throws IOException {
// - Change mode to 677 so owner does not have execute permission. // - Change mode to 677 so owner does not have execute permission.
// - Verify the owner truly does not have the permissions to execute the file. // - Verify the owner truly does not have the permissions to execute the file.


File winutilsFile = Shell.getWinutilsFile(); File winutilsFile = Shell.getWinUtilsFile();
File aExe = new File(TEST_DIR, "a.exe"); File aExe = new File(TEST_DIR, "a.exe");
FileUtils.copyFile(winutilsFile, aExe); FileUtils.copyFile(winutilsFile, aExe);
chmod("677", aExe); chmod("677", aExe);
Expand Down
Expand Up @@ -55,7 +55,7 @@ public static boolean isAvailable() {
return false; return false;
} }
ShellCommandExecutor shellExecutor = new ShellCommandExecutor( ShellCommandExecutor shellExecutor = new ShellCommandExecutor(
new String[] { Shell.getWinutilsPath(), "help" }); new String[] { Shell.getWinUtilsPath(), "help" });
try { try {
shellExecutor.execute(); shellExecutor.execute();
} catch (IOException e) { } catch (IOException e) {
Expand All @@ -80,7 +80,7 @@ public WindowsBasedProcessTree(String pid) {
String getAllProcessInfoFromShell() { String getAllProcessInfoFromShell() {
try { try {
ShellCommandExecutor shellExecutor = new ShellCommandExecutor( ShellCommandExecutor shellExecutor = new ShellCommandExecutor(
new String[] {Shell.getWinutilsFile().getCanonicalPath(), new String[] {Shell.getWinUtilsFile().getCanonicalPath(),
"task", "processList", taskProcessId }); "task", "processList", taskProcessId });
shellExecutor.execute(); shellExecutor.execute();
return shellExecutor.getOutput(); return shellExecutor.getOutput();
Expand Down
Expand Up @@ -401,7 +401,7 @@ protected String[] getRunCommand(String command, String groupId,
cpuRate = Math.min(10000, (int) (containerCpuPercentage * 100)); cpuRate = Math.min(10000, (int) (containerCpuPercentage * 100));
} }
} }
return new String[] { Shell.getWinutilsPath(), "task", "create", "-m", return new String[] { Shell.getWinUtilsPath(), "task", "create", "-m",
String.valueOf(memory), "-c", String.valueOf(cpuRate), groupId, String.valueOf(memory), "-c", String.valueOf(cpuRate), groupId,
"cmd /c " + command }; "cmd /c " + command };
} else { } else {
Expand Down
Expand Up @@ -578,7 +578,7 @@ protected String[] getRunCommand(String command, String groupId,
LOG.debug(String.format("getRunCommand: %s exists:%b", LOG.debug(String.format("getRunCommand: %s exists:%b",
command, f.exists())); command, f.exists()));
} }
return new String[] { Shell.getWinutilsPath(), "task", return new String[] { Shell.getWinUtilsPath(), "task",
"createAsUser", groupId, "createAsUser", groupId,
userName, pidFile.toString(), "cmd /c " + command }; userName, pidFile.toString(), "cmd /c " + command };
} }
Expand Down
Expand Up @@ -747,7 +747,7 @@ protected void link(Path src, Path dst) throws IOException {
String srcFileStr = srcFile.getPath(); String srcFileStr = srcFile.getPath();
String dstFileStr = new File(dst.toString()).getPath(); String dstFileStr = new File(dst.toString()).getPath();
lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"",
Shell.getWinutilsPath(), dstFileStr, srcFileStr)); Shell.getWinUtilsPath(), dstFileStr, srcFileStr));
errorCheck(); errorCheck();
} }


Expand Down
Expand Up @@ -1072,7 +1072,7 @@ public void testWindowsShellScriptBuilderMkdir() throws IOException {
public void testWindowsShellScriptBuilderLink() throws IOException { public void testWindowsShellScriptBuilderLink() throws IOException {
// Test is only relevant on Windows // Test is only relevant on Windows
Assume.assumeTrue(Shell.WINDOWS); Assume.assumeTrue(Shell.WINDOWS);
String linkCmd = "@" + Shell.getWinutilsPath() + " symlink \"\" \"\""; String linkCmd = "@" + Shell.getWinUtilsPath() + " symlink \"\" \"\"";


// The tests are built on assuming 8191 max command line length // The tests are built on assuming 8191 max command line length
assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH); assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGTH);
Expand Down

0 comments on commit dfa7848

Please sign in to comment.