/** * Gets the align format according to the longest mount point/under storage path. * @param mountTable the mount table to get information from * @return the align format for printing mounted info */ private static String getAlignFormat(Map<String, MountPointInfo> mountTable) { int mountPointLength = mountTable.entrySet().stream().map(w -> w.getKey().length()) .max(Comparator.comparing(Integer::intValue)).get(); int usfLength = mountTable.entrySet().stream().map(w -> w.getValue().getUfsUri().length()) .max(Comparator.comparing(Integer::intValue)).get(); String leftAlignFormat = "%-" + usfLength + "s on %-" + mountPointLength + "s (%s, capacity=%s, used=%s, %sread-only, %sshared, "; return leftAlignFormat; } }
/** * Gets the mount point information from a mount information. * * @param mountInfo the mount information to transform * @return the mount point information */ private MountPointInfo getMountPointInfo(MountInfo mountInfo) { MountPointInfo info = mountInfo.toMountPointInfo(); try (CloseableResource<UnderFileSystem> ufsResource = mUfsManager.get(mountInfo.getMountId()).acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); info.setUfsType(ufs.getUnderFSType()); try { info.setUfsCapacityBytes( ufs.getSpace(info.getUfsUri(), UnderFileSystem.SpaceType.SPACE_TOTAL)); } catch (IOException e) { LOG.warn("Cannot get total capacity of {}", info.getUfsUri(), e); } try { info.setUfsUsedBytes( ufs.getSpace(info.getUfsUri(), UnderFileSystem.SpaceType.SPACE_USED)); } catch (IOException e) { LOG.warn("Cannot get used capacity of {}", info.getUfsUri(), e); } } catch (UnavailableException | NotFoundException e) { // We should never reach here LOG.error("No UFS cached for {}", info, e); } return info; }
/** * Prints mount information for a mount table. * * @param mountTable the mount table to get information from */ public static void printMountInfo(Map<String, MountPointInfo> mountTable) { for (Map.Entry<String, MountPointInfo> entry : mountTable.entrySet()) { String mMountPoint = entry.getKey(); MountPointInfo mountPointInfo = entry.getValue(); long capacityBytes = mountPointInfo.getUfsCapacityBytes(); long usedBytes = mountPointInfo.getUfsUsedBytes(); String usedPercentageInfo = ""; if (capacityBytes > 0) { int usedPercentage = (int) (100L * usedBytes / capacityBytes); usedPercentageInfo = String.format("(%s%%)", usedPercentage); } String leftAlignFormat = getAlignFormat(mountTable); System.out.format(leftAlignFormat, mountPointInfo.getUfsUri(), mMountPoint, mountPointInfo.getUfsType(), FormatUtils.getSizeFromBytes(capacityBytes), FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo, mountPointInfo.getReadOnly() ? "" : "not ", mountPointInfo.getShared() ? "" : "not "); System.out.println("properties=" + mountPointInfo.getProperties() + ")"); } }
/** * Converts wire type to proto type. * * @param info the wire representation to convert * @return converted proto representation */ public static alluxio.grpc.MountPointInfo toProto(MountPointInfo info) { return alluxio.grpc.MountPointInfo.newBuilder().setUfsUri(info.getUfsUri()) .setUfsType(info.getUfsType()).setUfsCapacityBytes(info.getUfsCapacityBytes()) .setReadOnly(info.getReadOnly()).putAllProperties(info.getProperties()) .setShared(info.getShared()).build(); }
public void checkEquality(MountPointInfo a, MountPointInfo b) { Assert.assertEquals(a.getUfsUri(), b.getUfsUri()); Assert.assertEquals(a.getUfsType(), b.getUfsType()); Assert.assertEquals(a.getUfsCapacityBytes(), b.getUfsCapacityBytes()); Assert.assertEquals(a.getUfsUsedBytes(), b.getUfsUsedBytes()); Assert.assertEquals(a.getReadOnly(), b.getReadOnly()); Assert.assertEquals(a.getProperties(), b.getProperties()); Assert.assertEquals(a, b); }