Search in sources :

Example 1 with EntryPlus3

use of org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response.EntryPlus3 in project hadoop by apache.

the class READDIRPLUS3Response method serialize.

@Override
public XDR serialize(XDR out, int xid, Verifier verifier) {
    super.serialize(out, xid, verifier);
    // attributes follow
    out.writeBoolean(true);
    if (postOpDirAttr == null) {
        postOpDirAttr = new Nfs3FileAttributes();
    }
    postOpDirAttr.serialize(out);
    if (getStatus() == Nfs3Status.NFS3_OK) {
        out.writeLongAsHyper(cookieVerf);
        for (EntryPlus3 f : dirListPlus.getEntries()) {
            // next
            out.writeBoolean(true);
            f.seralize(out);
        }
        out.writeBoolean(false);
        out.writeBoolean(dirListPlus.getEof());
    }
    return out;
}
Also used : Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)

Example 2 with EntryPlus3

use of org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response.EntryPlus3 in project hadoop by apache.

the class READDIRPLUS3Response method deserialize.

public static READDIRPLUS3Response deserialize(XDR xdr) {
    int status = xdr.readInt();
    xdr.readBoolean();
    Nfs3FileAttributes postOpDirAttr = Nfs3FileAttributes.deserialize(xdr);
    long cookieVerf = 0;
    ArrayList<EntryPlus3> entries = new ArrayList<EntryPlus3>();
    DirListPlus3 dirList = null;
    if (status == Nfs3Status.NFS3_OK) {
        cookieVerf = xdr.readHyper();
        while (xdr.readBoolean()) {
            EntryPlus3 e = EntryPlus3.deseralize(xdr);
            entries.add(e);
        }
        boolean eof = xdr.readBoolean();
        EntryPlus3[] allEntries = new EntryPlus3[entries.size()];
        entries.toArray(allEntries);
        dirList = new DirListPlus3(allEntries, eof);
    }
    return new READDIRPLUS3Response(status, postOpDirAttr, cookieVerf, dirList);
}
Also used : Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) ArrayList(java.util.ArrayList)

Example 3 with EntryPlus3

use of org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response.EntryPlus3 in project hadoop by apache.

the class TestReaddir method testReaddirPlus.

@Test
public // Test readdirplus
void testReaddirPlus() throws IOException {
    // Get inodeId of /tmp
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    // Create related part of the XDR request
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    handle.serialize(xdr_req);
    // cookie
    xdr_req.writeLongAsHyper(0);
    // verifier
    xdr_req.writeLongAsHyper(0);
    // dirCount
    xdr_req.writeInt(100);
    // maxCount
    xdr_req.writeInt(1000);
    READDIRPLUS3Response responsePlus = nfsd.readdirplus(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    List<EntryPlus3> direntPlus = responsePlus.getDirListPlus().getEntries();
    // including dot, dotdot
    assertTrue(direntPlus.size() == 5);
    // Test start listing from f2
    status = nn.getRpcServer().getFileInfo(testdir + "/f2");
    long f2Id = status.getFileId();
    // Create related part of the XDR request
    xdr_req = new XDR();
    handle = new FileHandle(dirId);
    handle.serialize(xdr_req);
    // cookie
    xdr_req.writeLongAsHyper(f2Id);
    // verifier
    xdr_req.writeLongAsHyper(0);
    // dirCount
    xdr_req.writeInt(100);
    // maxCount
    xdr_req.writeInt(1000);
    responsePlus = nfsd.readdirplus(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    direntPlus = responsePlus.getDirListPlus().getEntries();
    assertTrue(direntPlus.size() == 1);
    EntryPlus3 entryPlus = direntPlus.get(0);
    assertTrue(entryPlus.getName().equals("f3"));
    // When the cookie is deleted, list starts over no including dot, dotdot
    hdfs.delete(new Path(testdir + "/f2"), false);
    responsePlus = nfsd.readdirplus(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    direntPlus = responsePlus.getDirListPlus().getEntries();
    // No dot, dotdot
    assertTrue(direntPlus.size() == 2);
}
Also used : Path(org.apache.hadoop.fs.Path) EntryPlus3(org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response.EntryPlus3) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) READDIRPLUS3Response(org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response) Test(org.junit.Test)

Aggregations

Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Path (org.apache.hadoop.fs.Path)1 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)1 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)1 READDIRPLUS3Response (org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response)1 EntryPlus3 (org.apache.hadoop.nfs.nfs3.response.READDIRPLUS3Response.EntryPlus3)1 XDR (org.apache.hadoop.oncrpc.XDR)1 Test (org.junit.Test)1