/** * 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; }
/** * 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; } }
/** * 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 ""; }
/** * 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; }
if (!OSUtils.isLinux()) { System.out.println("OS is not Linux, skip validation."); return TaskResult.SKIPPED;
if (!OSUtils.isLinux()) { return;
@Test public void getMountInfo() throws Exception { assumeTrue(OSUtils.isMacOS() || OSUtils.isLinux()); List<UnixMountInfo> info = ShellUtils.getUnixMountInfo(); assertTrue(info.size() > 0); } }
/** * 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; }
if (!OSUtils.isLinux()) { System.out.println("OS is not Linux, skip validation."); return TaskResult.SKIPPED;