/** * Gets system mount information. This method should only be attempted on Unix systems. * * @return system mount information */ public static List<UnixMountInfo> getUnixMountInfo() throws IOException { Preconditions.checkState(OSUtils.isLinux() || OSUtils.isMacOS()); String output = execCommand(MOUNT_COMMAND); List<UnixMountInfo> mountInfo = new ArrayList<>(); for (String line : output.split("\n")) { mountInfo.add(parseMountInfo(line)); } return mountInfo; }
/** * @return the OS login module class name */ private static String getOSLoginModuleName() { if (OSUtils.IBM_JAVA) { if (OSUtils.isWindows()) { return OSUtils.is64Bit() ? "com.ibm.security.auth.module.Win64LoginModule" : "com.ibm.security.auth.module.NTLoginModule"; } else if (OSUtils.isAIX()) { return OSUtils.is64Bit() ? "com.ibm.security.auth.module.AIX64LoginModule" : "com.ibm.security.auth.module.AIXLoginModule"; } else { return "com.ibm.security.auth.module.LinuxLoginModule"; } } else { return OSUtils.isWindows() ? "com.sun.security.auth.module.NTLoginModule" : "com.sun.security.auth.module.UnixLoginModule"; } }
if (!OSUtils.isLinux()) { System.out.println("OS is not Linux, skip validation."); return TaskResult.SKIPPED;
/** * Checks if the given path is properly formed. * * @param path The path to check * @throws InvalidPathException If the path is not properly formed */ public static void validatePath(String path) throws InvalidPathException { boolean invalid = (path == null || path.isEmpty()); if (!OSUtils.isWindows()) { invalid = (invalid || !path.startsWith(AlluxioURI.SEPARATOR)); } if (invalid) { throw new InvalidPathException(ExceptionMessage.PATH_INVALID.getMessage(path)); } }
if (!OSUtils.isLinux()) { return;
/** * Checks if the given path is properly formed. * * @param path The path to check * @throws InvalidPathException If the path is not properly formed */ public static void validatePath(String path) throws InvalidPathException { boolean invalid = (path == null || path.isEmpty()); if (!OSUtils.isWindows()) { invalid = (invalid || !path.startsWith(AlluxioURI.SEPARATOR)); } if (invalid) { throw new InvalidPathException(ExceptionMessage.PATH_INVALID.getMessage(path)); } }
/** * Gets the group name from the group id. * * @param gid the group id * @return group name */ public static String getGroupName(long gid) throws IOException { if (OSUtils.isLinux()) { String script = "getent group " + gid + " | cut -d: -f1"; return ShellUtils.execCommand("bash", "-c", script).trim(); } else if (OSUtils.isMacOS()) { String script = "dscl . list /Groups PrimaryGroupID | awk '($2 == \"" + gid + "\") { print $1 }'"; return ShellUtils.execCommand("bash", "-c", script).trim(); } return ""; }
if (!OSUtils.isLinux()) { System.out.println("OS is not Linux, skip validation."); return TaskResult.SKIPPED;
/** * @return the OS principal class name */ private static String getOSPrincipalClassName() { String principalClassName; if (OSUtils.IBM_JAVA) { if (OSUtils.is64Bit()) { principalClassName = "com.ibm.security.auth.UsernamePrincipal"; } else { if (OSUtils.isWindows()) { principalClassName = "com.ibm.security.auth.NTUserPrincipal"; } else if (OSUtils.isAIX()) { principalClassName = "com.ibm.security.auth.AIXPrincipal"; } else { principalClassName = "com.ibm.security.auth.LinuxPrincipal"; } } } else { principalClassName = OSUtils.isWindows() ? "com.sun.security.auth.NTUserPrincipal" : "com.sun.security.auth.UnixPrincipal"; } return principalClassName; } }
/** * Checks whether fuse is installed in local file system. * Alluxio-Fuse only support mac and linux. * * @return true if fuse is installed, false otherwise */ public static boolean isFuseInstalled() { try { if (OSUtils.isLinux()) { String result = ShellUtils.execCommand("fusermount", "-V"); return !result.isEmpty(); } else if (OSUtils.isMacOS()) { String result = ShellUtils.execCommand("bash", "-c", "mount | grep FUSE"); return !result.isEmpty(); } } catch (Exception e) { return false; } return false; }
/** * @return the OS login module class name */ private static String getOSLoginModuleName() { if (OSUtils.IBM_JAVA) { if (OSUtils.isWindows()) { return OSUtils.is64Bit() ? "com.ibm.security.auth.module.Win64LoginModule" : "com.ibm.security.auth.module.NTLoginModule"; } else if (OSUtils.isAIX()) { return OSUtils.is64Bit() ? "com.ibm.security.auth.module.AIX64LoginModule" : "com.ibm.security.auth.module.AIXLoginModule"; } else { return "com.ibm.security.auth.module.LinuxLoginModule"; } } else { return OSUtils.isWindows() ? "com.sun.security.auth.module.NTLoginModule" : "com.sun.security.auth.module.UnixLoginModule"; } }
/** * Retrieves the gid of the given group. * * @param groupName the group name * @return gid */ public static long getGidFromGroupName(String groupName) throws IOException { String result = ""; if (OSUtils.isLinux()) { String script = "getent group " + groupName + " | cut -d: -f3"; result = ShellUtils.execCommand("bash", "-c", script).trim(); } else if (OSUtils.isMacOS()) { String script = "dscl . -read /Groups/" + groupName + " | awk '($1 == \"PrimaryGroupID:\") { print $2 }'"; result = ShellUtils.execCommand("bash", "-c", script).trim(); } try { return Long.parseLong(result); } catch (NumberFormatException e) { LOG.error("Failed to get gid from group name {}.", groupName); return -1; } }
/** * @return the OS principal class name */ private static String getOSPrincipalClassName() { String principalClassName; if (OSUtils.IBM_JAVA) { if (OSUtils.is64Bit()) { principalClassName = "com.ibm.security.auth.UsernamePrincipal"; } else { if (OSUtils.isWindows()) { principalClassName = "com.ibm.security.auth.NTUserPrincipal"; } else if (OSUtils.isAIX()) { principalClassName = "com.ibm.security.auth.AIXPrincipal"; } else { principalClassName = "com.ibm.security.auth.LinuxPrincipal"; } } } else { principalClassName = OSUtils.isWindows() ? "com.sun.security.auth.NTUserPrincipal" : "com.sun.security.auth.UnixPrincipal"; } return principalClassName; } }
/** * Gets system mount information. This method should only be attempted on Unix systems. * * @return system mount information */ public static List<UnixMountInfo> getUnixMountInfo() throws IOException { Preconditions.checkState(OSUtils.isLinux() || OSUtils.isMacOS()); String output = execCommand(MOUNT_COMMAND); List<UnixMountInfo> mountInfo = new ArrayList<>(); for (String line : output.split("\n")) { mountInfo.add(parseMountInfo(line)); } return mountInfo; }