Search in sources :

Example 66 with FileHandle

use of org.apache.hadoop.nfs.nfs3.FileHandle in project hadoop by apache.

the class TestWrites method testWriteStableHow.

@Test
public void testWriteStableHow() throws IOException, InterruptedException {
    NfsConfiguration config = new NfsConfiguration();
    DFSClient client = null;
    MiniDFSCluster cluster = null;
    RpcProgramNfs3 nfsd;
    SecurityHandler securityHandler = Mockito.mock(SecurityHandler.class);
    Mockito.when(securityHandler.getUser()).thenReturn(System.getProperty("user.name"));
    String currentUser = System.getProperty("user.name");
    config.set(DefaultImpersonationProvider.getTestProvider().getProxySuperuserGroupConfKey(currentUser), "*");
    config.set(DefaultImpersonationProvider.getTestProvider().getProxySuperuserIpConfKey(currentUser), "*");
    ProxyUsers.refreshSuperUserGroupsConfiguration(config);
    try {
        cluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
        cluster.waitActive();
        client = new DFSClient(DFSUtilClient.getNNAddress(config), config);
        // Use emphral port in case tests are running in parallel
        config.setInt("nfs3.mountd.port", 0);
        config.setInt("nfs3.server.port", 0);
        // Start nfs
        Nfs3 nfs3 = new Nfs3(config);
        nfs3.startServiceInternal(false);
        nfsd = (RpcProgramNfs3) nfs3.getRpcProgram();
        HdfsFileStatus status = client.getFileInfo("/");
        FileHandle rootHandle = new FileHandle(status.getFileId());
        // Create file1
        CREATE3Request createReq = new CREATE3Request(rootHandle, "file1", Nfs3Constant.CREATE_UNCHECKED, new SetAttr3(), 0);
        XDR createXdr = new XDR();
        createReq.serialize(createXdr);
        CREATE3Response createRsp = nfsd.create(createXdr.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
        FileHandle handle = createRsp.getObjHandle();
        // Test DATA_SYNC
        byte[] buffer = new byte[10];
        for (int i = 0; i < 10; i++) {
            buffer[i] = (byte) i;
        }
        WRITE3Request writeReq = new WRITE3Request(handle, 0, 10, WriteStableHow.DATA_SYNC, ByteBuffer.wrap(buffer));
        XDR writeXdr = new XDR();
        writeReq.serialize(writeXdr);
        nfsd.write(writeXdr.asReadOnlyWrap(), null, 1, securityHandler, new InetSocketAddress("localhost", 1234));
        waitWrite(nfsd, handle, 60000);
        // Readback
        READ3Request readReq = new READ3Request(handle, 0, 10);
        XDR readXdr = new XDR();
        readReq.serialize(readXdr);
        READ3Response readRsp = nfsd.read(readXdr.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
        assertTrue(Arrays.equals(buffer, readRsp.getData().array()));
        // Test FILE_SYNC
        // Create file2
        CREATE3Request createReq2 = new CREATE3Request(rootHandle, "file2", Nfs3Constant.CREATE_UNCHECKED, new SetAttr3(), 0);
        XDR createXdr2 = new XDR();
        createReq2.serialize(createXdr2);
        CREATE3Response createRsp2 = nfsd.create(createXdr2.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
        FileHandle handle2 = createRsp2.getObjHandle();
        WRITE3Request writeReq2 = new WRITE3Request(handle2, 0, 10, WriteStableHow.FILE_SYNC, ByteBuffer.wrap(buffer));
        XDR writeXdr2 = new XDR();
        writeReq2.serialize(writeXdr2);
        nfsd.write(writeXdr2.asReadOnlyWrap(), null, 1, securityHandler, new InetSocketAddress("localhost", 1234));
        waitWrite(nfsd, handle2, 60000);
        // Readback
        READ3Request readReq2 = new READ3Request(handle2, 0, 10);
        XDR readXdr2 = new XDR();
        readReq2.serialize(readXdr2);
        READ3Response readRsp2 = nfsd.read(readXdr2.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
        assertTrue(Arrays.equals(buffer, readRsp2.getData().array()));
        // FILE_SYNC should sync the file size
        status = client.getFileInfo("/file2");
        assertTrue(status.getLen() == 10);
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) SecurityHandler(org.apache.hadoop.oncrpc.security.SecurityHandler) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) XDR(org.apache.hadoop.oncrpc.XDR) WRITE3Request(org.apache.hadoop.nfs.nfs3.request.WRITE3Request) NfsConfiguration(org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration) SetAttr3(org.apache.hadoop.nfs.nfs3.request.SetAttr3) READ3Request(org.apache.hadoop.nfs.nfs3.request.READ3Request) CREATE3Response(org.apache.hadoop.nfs.nfs3.response.CREATE3Response) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) CREATE3Request(org.apache.hadoop.nfs.nfs3.request.CREATE3Request) READ3Response(org.apache.hadoop.nfs.nfs3.response.READ3Response) Test(org.junit.Test)

Example 67 with FileHandle

use of org.apache.hadoop.nfs.nfs3.FileHandle in project hadoop by apache.

the class TestRpcProgramNfs3 method testRemove.

@Test(timeout = 60000)
public void testRemove() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    REMOVE3Request req = new REMOVE3Request(handle, "bar");
    req.serialize(xdr_req);
    // Attempt by an unpriviledged user should fail.
    REMOVE3Response response1 = nfsd.remove(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a priviledged user should pass.
    REMOVE3Response response2 = nfsd.remove(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) REMOVE3Response(org.apache.hadoop.nfs.nfs3.response.REMOVE3Response) REMOVE3Request(org.apache.hadoop.nfs.nfs3.request.REMOVE3Request) Test(org.junit.Test)

Example 68 with FileHandle

use of org.apache.hadoop.nfs.nfs3.FileHandle in project hadoop by apache.

the class TestRpcProgramNfs3 method testRmdir.

@Test(timeout = 60000)
public void testRmdir() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    RMDIR3Request req = new RMDIR3Request(handle, "foo");
    req.serialize(xdr_req);
    // Attempt by an unprivileged user should fail.
    RMDIR3Response response1 = nfsd.rmdir(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a privileged user should pass.
    RMDIR3Response response2 = nfsd.rmdir(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) RMDIR3Response(org.apache.hadoop.nfs.nfs3.response.RMDIR3Response) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) RMDIR3Request(org.apache.hadoop.nfs.nfs3.request.RMDIR3Request) Test(org.junit.Test)

Example 69 with FileHandle

use of org.apache.hadoop.nfs.nfs3.FileHandle in project hadoop by apache.

the class TestRpcProgramNfs3 method testRename.

@Test(timeout = 60000)
public void testRename() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    RENAME3Request req = new RENAME3Request(handle, "bar", handle, "fubar");
    req.serialize(xdr_req);
    // Attempt by an unprivileged user should fail.
    RENAME3Response response1 = nfsd.rename(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a privileged user should pass.
    RENAME3Response response2 = nfsd.rename(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : RENAME3Request(org.apache.hadoop.nfs.nfs3.request.RENAME3Request) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) RENAME3Response(org.apache.hadoop.nfs.nfs3.response.RENAME3Response) Test(org.junit.Test)

Example 70 with FileHandle

use of org.apache.hadoop.nfs.nfs3.FileHandle in project hadoop by apache.

the class TestRpcProgramNfs3 method testSymlink.

@Test(timeout = 60000)
public void testSymlink() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    SYMLINK3Request req = new SYMLINK3Request(handle, "fubar", new SetAttr3(), "bar");
    req.serialize(xdr_req);
    // Attempt by an unprivileged user should fail.
    SYMLINK3Response response1 = nfsd.symlink(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a privileged user should pass.
    SYMLINK3Response response2 = nfsd.symlink(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : SYMLINK3Request(org.apache.hadoop.nfs.nfs3.request.SYMLINK3Request) SetAttr3(org.apache.hadoop.nfs.nfs3.request.SetAttr3) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) SYMLINK3Response(org.apache.hadoop.nfs.nfs3.response.SYMLINK3Response) Test(org.junit.Test)

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)79 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)34 XDR (org.apache.hadoop.oncrpc.XDR)34 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)31 Test (org.junit.Test)31 InetSocketAddress (java.net.InetSocketAddress)28 DFSClient (org.apache.hadoop.hdfs.DFSClient)26 IOException (java.io.IOException)24 VisibleForTesting (com.google.common.annotations.VisibleForTesting)19 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)12 SetAttr3 (org.apache.hadoop.nfs.nfs3.request.SetAttr3)11 WRITE3Request (org.apache.hadoop.nfs.nfs3.request.WRITE3Request)8 NfsConfiguration (org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration)7 HdfsDataOutputStream (org.apache.hadoop.hdfs.client.HdfsDataOutputStream)6 CREATE3Request (org.apache.hadoop.nfs.nfs3.request.CREATE3Request)6 READ3Request (org.apache.hadoop.nfs.nfs3.request.READ3Request)5 CREATE3Response (org.apache.hadoop.nfs.nfs3.response.CREATE3Response)5 READ3Response (org.apache.hadoop.nfs.nfs3.response.READ3Response)5 WRITE3Response (org.apache.hadoop.nfs.nfs3.response.WRITE3Response)5 VerifierNone (org.apache.hadoop.oncrpc.security.VerifierNone)5