Search in sources :

Example 1 with HdfsFileStatusProto

use of org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto in project hadoop by apache.

the class PBHelperClient method convert.

public static HdfsFileStatusProto convert(HdfsFileStatus fs) {
    if (fs == null)
        return null;
    FileType fType = FileType.IS_FILE;
    if (fs.isDir()) {
        fType = FileType.IS_DIR;
    } else if (fs.isSymlink()) {
        fType = FileType.IS_SYMLINK;
    }
    HdfsFileStatusProto.Builder builder = HdfsFileStatusProto.newBuilder().setLength(fs.getLen()).setFileType(fType).setBlockReplication(fs.getReplication()).setBlocksize(fs.getBlockSize()).setModificationTime(fs.getModificationTime()).setAccessTime(fs.getAccessTime()).setPermission(convert(fs.getPermission())).setOwner(fs.getOwner()).setGroup(fs.getGroup()).setFileId(fs.getFileId()).setChildrenNum(fs.getChildrenNum()).setPath(getByteString(fs.getLocalNameInBytes())).setStoragePolicy(fs.getStoragePolicy());
    if (fs.isSymlink()) {
        builder.setSymlink(getByteString(fs.getSymlinkInBytes()));
    }
    if (fs.getFileEncryptionInfo() != null) {
        builder.setFileEncryptionInfo(convert(fs.getFileEncryptionInfo()));
    }
    if (fs instanceof HdfsLocatedFileStatus) {
        final HdfsLocatedFileStatus lfs = (HdfsLocatedFileStatus) fs;
        LocatedBlocks locations = lfs.getBlockLocations();
        if (locations != null) {
            builder.setLocations(convert(locations));
        }
    }
    if (fs.getErasureCodingPolicy() != null) {
        builder.setEcPolicy(convertErasureCodingPolicy(fs.getErasureCodingPolicy()));
    }
    return builder.build();
}
Also used : FileType(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto.FileType) HdfsFileStatusProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto) HdfsLocatedFileStatus(org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus) LocatedBlocks(org.apache.hadoop.hdfs.protocol.LocatedBlocks)

Example 2 with HdfsFileStatusProto

use of org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto in project hadoop by apache.

the class PBHelperClient method convert.

public static SnapshottableDirectoryStatusProto convert(SnapshottableDirectoryStatus status) {
    if (status == null) {
        return null;
    }
    int snapshotNumber = status.getSnapshotNumber();
    int snapshotQuota = status.getSnapshotQuota();
    byte[] parentFullPath = status.getParentFullPath();
    ByteString parentFullPathBytes = getByteString(parentFullPath == null ? DFSUtilClient.EMPTY_BYTES : parentFullPath);
    HdfsFileStatusProto fs = convert(status.getDirStatus());
    SnapshottableDirectoryStatusProto.Builder builder = SnapshottableDirectoryStatusProto.newBuilder().setSnapshotNumber(snapshotNumber).setSnapshotQuota(snapshotQuota).setParentFullpath(parentFullPathBytes).setDirStatus(fs);
    return builder.build();
}
Also used : ByteString(com.google.protobuf.ByteString) HdfsFileStatusProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto) SnapshottableDirectoryStatusProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.SnapshottableDirectoryStatusProto)

Aggregations

HdfsFileStatusProto (org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto)2 ByteString (com.google.protobuf.ByteString)1 HdfsLocatedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus)1 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)1 FileType (org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.HdfsFileStatusProto.FileType)1 SnapshottableDirectoryStatusProto (org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.SnapshottableDirectoryStatusProto)1