/** * 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 a proto type to a wire type. * * @param mountPointPInfo the proto type to convert * @return the converted wire type */ public static MountPointInfo fromProto(alluxio.grpc.MountPointInfo mountPointPInfo) { return new MountPointInfo().setUfsUri(mountPointPInfo.getUfsUri()) .setUfsType(mountPointPInfo.getUfsType()) .setUfsCapacityBytes(mountPointPInfo.getUfsCapacityBytes()) .setUfsUsedBytes(mountPointPInfo.getUfsUsedBytes()) .setReadOnly(mountPointPInfo.getReadOnly()) .setProperties(mountPointPInfo.getPropertiesMap()).setShared(mountPointPInfo.getShared()); }
/** * @return the {@link MountPointInfo} for the mount point */ public MountPointInfo toMountPointInfo() { MountPointInfo info = new MountPointInfo(); info.setUfsUri(mUfsUri.toString()); info.setReadOnly(mOptions.getReadOnly()); info.setProperties(mOptions.getProperties()); info.setShared(mOptions.getShared()); return info; }
/** * 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; }
private Capacity getUfsCapacityInternal() { MountPointInfo mountInfo = mFileSystemMaster.getMountTable().get(MountTable.ROOT); if (mountInfo == null) { return new Capacity().setTotal(-1).setUsed(-1); } long capacityBytes = mountInfo.getUfsCapacityBytes(); long usedBytes = mountInfo.getUfsUsedBytes(); return new Capacity().setTotal(capacityBytes).setUsed(usedBytes); }
/** * 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; } }
@Override public void check(Clients clients) throws Exception { FileSystemMasterClient masterClient = clients.getFileSystemMasterClient(); assertFalse(masterClient.getMountTable().get("/").getReadOnly()); } }
/** * @return the {@link MountPointInfo} for the mount point */ public MountPointInfo toMountPointInfo() { MountPointInfo info = new MountPointInfo(); info.setUfsUri(mUfsUri.toString()); info.setReadOnly(mOptions.isReadOnly()); info.setProperties(mOptions.getProperties()); info.setShared(mOptions.isShared()); return info; }
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) { info.setUfsUsedBytes( ufs.getSpace(info.getUfsUri(), UnderFileSystem.SpaceType.SPACE_USED)); } catch (IOException e) {
mountInfo = mFileSystemMaster.getMountPointInfo(new AlluxioURI(MountTable.ROOT)); long capacityBytes = mountInfo.getUfsCapacityBytes(); long usedBytes = mountInfo.getUfsUsedBytes(); long freeBytes = -1; if (capacityBytes >= 0 && usedBytes >= 0 && capacityBytes >= usedBytes) {
/** * 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 static MountPointInfo createRandom() { Random random = new Random(); String ufsUri = CommonUtils.randomAlphaNumString(random.nextInt(10)); String ufsType = CommonUtils.randomAlphaNumString(random.nextInt(10)); long ufsCapacityBytes = random.nextLong(); long ufsUsedBytes = random.nextLong(); boolean readOnly = random.nextBoolean(); Map<String, String> properties = new HashMap<>(); for (int i = 0, n = random.nextInt(10) + 1; i < n; i++) { properties.put(CommonUtils.randomAlphaNumString(random.nextInt(5)), CommonUtils.randomAlphaNumString(random.nextInt(5))); } MountPointInfo result = new MountPointInfo(); result.setUfsUri(ufsUri); result.setUfsType(ufsType); result.setUfsCapacityBytes(ufsCapacityBytes); result.setUfsUsedBytes(ufsUsedBytes); result.setReadOnly(readOnly); result.setProperties(properties); return result; } }
private Capacity getUfsCapacityInternal() { MountPointInfo mountInfo = mFileSystemMaster.getMountTable().get(MountTable.ROOT); if (mountInfo == null) { return new Capacity().setTotal(-1).setUsed(-1); } long capacityBytes = mountInfo.getUfsCapacityBytes(); long usedBytes = mountInfo.getUfsUsedBytes(); return new Capacity().setTotal(capacityBytes).setUsed(usedBytes); }
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); }
/** * Creates a new instance of {@link MountPointInfo} from thrift representation. * * @param info the thrift representation of a mount point information * @return the instance */ public static MountPointInfo fromThrift(alluxio.thrift.MountPointInfo info) { return new MountPointInfo() .setUfsUri(info.getUfsUri()) .setUfsType(info.getUfsType()) .setUfsCapacityBytes(info.getUfsCapacityBytes()) .setUfsUsedBytes(info.getUfsUsedBytes()) .setReadOnly(info.isReadOnly()) .setProperties(info.getProperties()) .setShared(info.isShared()); }
long capacityBytes = mountInfo.getUfsCapacityBytes(); long usedBytes = mountInfo.getUfsUsedBytes(); long freeBytes = -1; if (capacityBytes >= 0 && usedBytes >= 0 && capacityBytes >= usedBytes) {