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; } }
/** * 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; }
/** * 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()); }
mUfsManager.get(mountInfo.getMountId()).acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); info.setUfsType(ufs.getUnderFSType()); try { info.setUfsCapacityBytes(
/** * 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()); }