/** Return a command to read the target of the a symbolic link. */ public static String[] getReadlinkCommand(String link) { return WINDOWS ? new String[] { getWinUtilsPath(), "readlink", link } : new String[] { "readlink", link }; }
/** Return a command to get permission information. */ public static String[] getGetPermissionCommand() { return (WINDOWS) ? new String[] { getWinUtilsPath(), "ls", "-F" } : new String[] { "ls", "-ld" }; }
/** Return a command to set owner. */ public static String[] getSetOwnerCommand(String owner) { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chown", "\"" + owner + "\"" } : new String[] { "chown", owner }; }
/** Return a command to create symbolic links. */ public static String[] getSymlinkCommand(String target, String link) { return WINDOWS ? new String[] { getWinUtilsPath(), "symlink", link, target } : new String[] { "ln", "-s", target, link }; }
/** Return a command to set permission. */ public static String[] getSetPermissionCommand(String perm, boolean recursive) { if (recursive) { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chmod", "-R", perm } : new String[] { "chmod", "-R", perm }; } else { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chmod", perm } : new String[] { "chmod", perm }; } }
/** Return a command to send a signal to a given pid. */ public static String[] getSignalKillCommand(int code, String pid) { // Code == 0 means check alive if (Shell.WINDOWS) { if (0 == code) { return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid }; } else { return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid }; } } // Use the bash-builtin instead of the Unix kill command (usually // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported // OSes. final String quotedPid = bashQuote(pid); if (isSetsidAvailable) { return new String[] { "bash", "-c", "kill -" + code + " -- -" + quotedPid }; } else { return new String[] { "bash", "-c", "kill -" + code + " " + quotedPid }; } }
/** * A command to get a given user's group id list. * The command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. * This command does not support Windows and will only return group names. */ public static String[] getGroupsIDForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[]{getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -g " + quotedUser + "; id -G " + quotedUser}; } }
/** * A command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** Return a command to create symbolic links. */ public static String[] getSymlinkCommand(String target, String link) { return WINDOWS ? new String[] { getWinUtilsPath(), "symlink", link, target } : new String[] { "ln", "-s", target, link }; }
/** Return a command to read the target of the a symbolic link. */ public static String[] getReadlinkCommand(String link) { return WINDOWS ? new String[] { getWinUtilsPath(), "readlink", link } : new String[] { "readlink", link }; }
/** Return a command to get permission information. */ public static String[] getGetPermissionCommand() { return (WINDOWS) ? new String[] { getWinUtilsPath(), "ls", "-F" } : new String[] { "ls", "-ld" }; }
/** Return a command to set permission. */ public static String[] getSetPermissionCommand(String perm, boolean recursive) { if (recursive) { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chmod", "-R", perm } : new String[] { "chmod", "-R", perm }; } else { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chmod", perm } : new String[] { "chmod", perm }; } }
/** Return a command to set owner. */ public static String[] getSetOwnerCommand(String owner) { return (WINDOWS) ? new String[] { getWinUtilsPath(), "chown", "\"" + owner + "\"" } : new String[] { "chown", owner }; }
@Override protected String[] getRunCommand(String command, String groupId, String userName, Path pidFile, Configuration conf) { File f = new File(command); if (LOG.isDebugEnabled()) { LOG.debug(String.format("getRunCommand: %s exists:%b", command, f.exists())); } return new String[] { Shell.getWinUtilsPath(), "task", "createAsUser", groupId, userName, pidFile.toString(), "cmd /c " + command }; }
@Override protected String[] getRunCommand(String command, String groupId, String userName, Path pidFile, Configuration conf) { File f = new File(command); if (LOG.isDebugEnabled()) { LOG.debug(String.format("getRunCommand: %s exists:%b", command, f.exists())); } return new String[] { Shell.getWinUtilsPath(), "task", "createAsUser", groupId, userName, pidFile.toString(), "cmd /c " + command }; }
@Override protected void link(Path src, Path dst) throws IOException { File srcFile = new File(src.toUri().getPath()); String srcFileStr = srcFile.getPath(); String dstFileStr = new File(dst.toString()).getPath(); lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.getWinUtilsPath(), dstFileStr, srcFileStr)); errorCheck(); }
@Override protected void link(Path src, Path dst) throws IOException { File srcFile = new File(src.toUri().getPath()); String srcFileStr = srcFile.getPath(); String dstFileStr = new File(dst.toString()).getPath(); lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.getWinUtilsPath(), dstFileStr, srcFileStr)); errorCheck(); }
/** * A command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** * a Unix command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }
/** * a Unix command to get a given user's groups list. * If the OS is not WINDOWS, the command will get the user's primary group * first and finally get the groups list which includes the primary group. * i.e. the user's primary group will be included twice. */ public static String[] getGroupsForUserCommand(final String user) { //'groups username' command return is inconsistent across different unixes if (WINDOWS) { return new String[] {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""}; } else { String quotedUser = bashQuote(user); return new String[] {"bash", "-c", "id -gn " + quotedUser + "; id -Gn " + quotedUser}; } }