コード例 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestReadlink()
        {
            // Create a symlink first.
            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);
            SYMLINK3Response response = nfsd.Symlink(xdr_req.AsReadOnlyWrap(), securityHandler
                                                     , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response
                                            .GetStatus());
            // Now perform readlink operations.
            FileHandle       handle2  = response.GetObjFileHandle();
            XDR              xdr_req2 = new XDR();
            READLINK3Request req2     = new READLINK3Request(handle2);

            req2.Serialize(xdr_req2);
            // Attempt by an unpriviledged user should fail.
            READLINK3Response response1 = nfsd.Readlink(xdr_req2.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            READLINK3Response response2 = nfsd.Readlink(xdr_req2.AsReadOnlyWrap(), securityHandler
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
コード例 #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestWrite()
        {
            HdfsFileStatus status = nn.GetRpcServer().GetFileInfo("/tmp/bar");
            long           dirId  = status.GetFileId();
            FileHandle     handle = new FileHandle(dirId);

            byte[] buffer = new byte[10];
            for (int i = 0; i < 10; i++)
            {
                buffer[i] = unchecked ((byte)i);
            }
            WRITE3Request writeReq = new WRITE3Request(handle, 0, 10, Nfs3Constant.WriteStableHow
                                                       .DataSync, ByteBuffer.Wrap(buffer));
            XDR xdr_req = new XDR();

            writeReq.Serialize(xdr_req);
            // Attempt by an unpriviledged user should fail.
            WRITE3Response response1 = nfsd.Write(xdr_req.AsReadOnlyWrap(), null, 1, securityHandlerUnpriviledged
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            WRITE3Response response2 = nfsd.Write(xdr_req.AsReadOnlyWrap(), null, 1, securityHandler
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect response:", null, response2);
        }
コード例 #3
0
        public virtual void TestReaddirPlus()
        {
            // Test readdirplus
            // 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);
            xdr_req.WriteLongAsHyper(0);
            // cookie
            xdr_req.WriteLongAsHyper(0);
            // verifier
            xdr_req.WriteInt(100);
            // dirCount
            xdr_req.WriteInt(1000);
            // maxCount
            READDIRPLUS3Response responsePlus = nfsd.Readdirplus(xdr_req.AsReadOnlyWrap(), securityHandler
                                                                 , new IPEndPoint("localhost", 1234));
            IList <READDIRPLUS3Response.EntryPlus3> direntPlus = responsePlus.GetDirListPlus()
                                                                 .GetEntries();

            NUnit.Framework.Assert.IsTrue(direntPlus.Count == 5);
            // including dot, dotdot
            // 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);
            xdr_req.WriteLongAsHyper(f2Id);
            // cookie
            xdr_req.WriteLongAsHyper(0);
            // verifier
            xdr_req.WriteInt(100);
            // dirCount
            xdr_req.WriteInt(1000);
            // maxCount
            responsePlus = nfsd.Readdirplus(xdr_req.AsReadOnlyWrap(), securityHandler, new IPEndPoint
                                                ("localhost", 1234));
            direntPlus = responsePlus.GetDirListPlus().GetEntries();
            NUnit.Framework.Assert.IsTrue(direntPlus.Count == 1);
            READDIRPLUS3Response.EntryPlus3 entryPlus = direntPlus[0];
            NUnit.Framework.Assert.IsTrue(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 IPEndPoint
                                                ("localhost", 1234));
            direntPlus = responsePlus.GetDirListPlus().GetEntries();
            NUnit.Framework.Assert.IsTrue(direntPlus.Count == 2);
        }
コード例 #4
0
        /// <exception cref="System.Exception"/>
        public virtual void TestMkdir()
        {
            //FixME
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);
            MKDIR3Request  req     = new MKDIR3Request(handle, "fubar1", new SetAttr3());

            req.Serialize(xdr_req);
            // Attempt to mkdir by an unprivileged user should fail.
            MKDIR3Response response1 = nfsd.Mkdir(xdr_req.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            XDR           xdr_req2 = new XDR();
            MKDIR3Request req2     = new MKDIR3Request(handle, "fubar2", new SetAttr3());

            req2.Serialize(xdr_req2);
            // Attempt to mkdir by a privileged user should pass.
            MKDIR3Response response2 = nfsd.Mkdir(xdr_req2.AsReadOnlyWrap(), securityHandler,
                                                  new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
コード例 #5
0
        /// <exception cref="System.Exception"/>
        public virtual void TestClientAccessPrivilegeForRemove()
        {
            // Configure ro access for nfs1 service
            config.Set("dfs.nfs.exports.allowed.hosts", "* ro");
            // Start nfs
            Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3 nfs = new Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3
                                                           (config);
            nfs.StartServiceInternal(false);
            RpcProgramNfs3 nfsd = (RpcProgramNfs3)nfs.GetRpcProgram();
            // Create a remove request
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);

            handle.Serialize(xdr_req);
            xdr_req.WriteString("f1");
            // Remove operation
            REMOVE3Response response = nfsd.Remove(xdr_req.AsReadOnlyWrap(), securityHandler,
                                                   new IPEndPoint("localhost", 1234));

            // Assert on return code
            NUnit.Framework.Assert.AreEqual("Incorrect return code", Nfs3Status.Nfs3errAcces,
                                            response.GetStatus());
        }
コード例 #6
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPathconf()
        {
            HdfsFileStatus   status  = nn.GetRpcServer().GetFileInfo("/tmp/bar");
            long             dirId   = status.GetFileId();
            FileHandle       handle  = new FileHandle(dirId);
            XDR              xdr_req = new XDR();
            PATHCONF3Request req     = new PATHCONF3Request(handle);

            req.Serialize(xdr_req);
            // Attempt by an unpriviledged user should fail.
            PATHCONF3Response response1 = nfsd.Pathconf(xdr_req.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            PATHCONF3Response response2 = nfsd.Pathconf(xdr_req.AsReadOnlyWrap(), securityHandler
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
コード例 #7
0
        public virtual void TestSerializeDeserialize()
        {
            // Serialize NfsTime
            NfsTime t1  = new NfsTime(1001);
            XDR     xdr = new XDR();

            t1.Serialize(xdr);
            // Deserialize it back
            NfsTime t2 = NfsTime.Deserialize(xdr.AsReadOnlyWrap());

            // Ensure the NfsTimes are equal
            Assert.Equal(t1, t2);
        }
コード例 #8
0
        /// <exception cref="System.Exception"/>
        public virtual void TestCreate()
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);
            CREATE3Request req     = new CREATE3Request(handle, "fubar", Nfs3Constant.CreateUnchecked
                                                        , new SetAttr3(), 0);

            req.Serialize(xdr_req);
            // Attempt by an unpriviledged user should fail.
            CREATE3Response response1 = nfsd.Create(xdr_req.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            CREATE3Response response2 = nfsd.Create(xdr_req.AsReadOnlyWrap(), securityHandler
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
コード例 #9
0
        /// <exception cref="System.Exception"/>
        public virtual void TestCommit()
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo("/tmp/bar");
            long           dirId   = status.GetFileId();
            FileHandle     handle  = new FileHandle(dirId);
            XDR            xdr_req = new XDR();
            COMMIT3Request req     = new COMMIT3Request(handle, 0, 5);

            req.Serialize(xdr_req);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            // Attempt by an unpriviledged user should fail.
            COMMIT3Response response1 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandlerUnpriviledged
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            COMMIT3Response response2 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandler
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect COMMIT3Response:", null, response2);
        }
コード例 #10
0
ファイル: TestFileHandle.cs プロジェクト: orf53975/hadoop.net
        public virtual void TestConstructor()
        {
            FileHandle handle = new FileHandle(1024);
            XDR        xdr    = new XDR();

            handle.Serialize(xdr);
            Assert.Equal(handle.GetFileId(), 1024);
            // Deserialize it back
            FileHandle handle2 = new FileHandle();

            handle2.Deserialize(xdr.AsReadOnlyWrap());
            Assert.Equal("Failed: Assert 1024 is id ", 1024, handle.GetFileId
                             ());
        }
コード例 #11
0
        /// <exception cref="System.Exception"/>
        public virtual void TestSetattr()
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);
            SetAttr3       symAttr = new SetAttr3(0, 1, 0, 0, null, null, EnumSet.Of(SetAttr3.SetAttrField
                                                                                     .Uid));
            SETATTR3Request req = new SETATTR3Request(handle, symAttr, false, null);

            req.Serialize(xdr_req);
            // Attempt by an unprivileged user should fail.
            SETATTR3Response response1 = nfsd.Setattr(xdr_req.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                      , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code", Nfs3Status.Nfs3errAcces,
                                            response1.GetStatus());
            // Attempt by a priviledged user should pass.
            SETATTR3Response response2 = nfsd.Setattr(xdr_req.AsReadOnlyWrap(), securityHandler
                                                      , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
コード例 #12
0
        public virtual void TestReadWrite()
        {
            CredentialsSys credential = new CredentialsSys();

            credential.SetUID(0);
            credential.SetGID(1);
            XDR xdr = new XDR();

            credential.Write(xdr);
            CredentialsSys newCredential = new CredentialsSys();

            newCredential.Read(xdr.AsReadOnlyWrap());
            Assert.Equal(0, newCredential.GetUID());
            Assert.Equal(1, newCredential.GetGID());
        }
コード例 #13
0
        /// <exception cref="System.Exception"/>
        private void CreateFileUsingNfs(string fileName, byte[] buffer)
        {
            DFSTestUtil.CreateFile(hdfs, new Path(fileName), 0, (short)1, 0);
            HdfsFileStatus status   = nn.GetRpcServer().GetFileInfo(fileName);
            long           dirId    = status.GetFileId();
            FileHandle     handle   = new FileHandle(dirId);
            WRITE3Request  writeReq = new WRITE3Request(handle, 0, buffer.Length, Nfs3Constant.WriteStableHow
                                                        .DataSync, ByteBuffer.Wrap(buffer));
            XDR xdr_req = new XDR();

            writeReq.Serialize(xdr_req);
            WRITE3Response response = nfsd.Write(xdr_req.AsReadOnlyWrap(), null, 1, securityHandler
                                                 , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect response: ", null, response);
        }
コード例 #14
0
        /// <exception cref="System.Exception"/>
        private void Commit(string fileName, int len)
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(fileName);
            long           dirId   = status.GetFileId();
            FileHandle     handle  = new FileHandle(dirId);
            XDR            xdr_req = new XDR();
            COMMIT3Request req     = new COMMIT3Request(handle, 0, len);

            req.Serialize(xdr_req);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            COMMIT3Response response2 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandler
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect COMMIT3Response:", null, response2);
        }
コード例 #15
0
        /// <exception cref="System.Exception"/>
        private byte[] GetFileContentsUsingNfs(string fileName, int len)
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(fileName);
            long           dirId   = status.GetFileId();
            FileHandle     handle  = new FileHandle(dirId);
            READ3Request   readReq = new READ3Request(handle, 0, len);
            XDR            xdr_req = new XDR();

            readReq.Serialize(xdr_req);
            READ3Response response = nfsd.Read(xdr_req.AsReadOnlyWrap(), securityHandler, new
                                               IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code: ", Nfs3Status.Nfs3Ok, response
                                            .GetStatus());
            NUnit.Framework.Assert.IsTrue("expected full read", response.IsEof());
            return((byte[])response.GetData().Array());
        }
コード例 #16
0
ファイル: TestWrites.cs プロジェクト: orf53975/hadoop.net
        public virtual void TestOOOWrites()
        {
            NfsConfiguration config  = new NfsConfiguration();
            MiniDFSCluster   cluster = null;
            RpcProgramNfs3   nfsd;
            int             bufSize         = 32;
            int             numOOO          = 3;
            SecurityHandler securityHandler = Org.Mockito.Mockito.Mock <SecurityHandler>();

            Org.Mockito.Mockito.When(securityHandler.GetUser()).ThenReturn(Runtime.GetProperty
                                                                               ("user.name"));
            string currentUser = Runtime.GetProperty("user.name");

            config.Set(DefaultImpersonationProvider.GetTestProvider().GetProxySuperuserGroupConfKey
                           (currentUser), "*");
            config.Set(DefaultImpersonationProvider.GetTestProvider().GetProxySuperuserIpConfKey
                           (currentUser), "*");
            ProxyUsers.RefreshSuperUserGroupsConfiguration(config);
            // Use emphral port in case tests are running in parallel
            config.SetInt("nfs3.mountd.port", 0);
            config.SetInt("nfs3.server.port", 0);
            try
            {
                cluster = new MiniDFSCluster.Builder(config).NumDataNodes(1).Build();
                cluster.WaitActive();
                Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3 nfs3 = new Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3
                                                                (config);
                nfs3.StartServiceInternal(false);
                nfsd = (RpcProgramNfs3)nfs3.GetRpcProgram();
                DFSClient      dfsClient  = new DFSClient(NameNode.GetAddress(config), config);
                HdfsFileStatus status     = dfsClient.GetFileInfo("/");
                FileHandle     rootHandle = new FileHandle(status.GetFileId());
                CREATE3Request createReq  = new CREATE3Request(rootHandle, "out-of-order-write" +
                                                               Runtime.CurrentTimeMillis(), Nfs3Constant.CreateUnchecked, new SetAttr3(), 0);
                XDR createXdr = new XDR();
                createReq.Serialize(createXdr);
                CREATE3Response createRsp = nfsd.Create(createXdr.AsReadOnlyWrap(), securityHandler
                                                        , new IPEndPoint("localhost", 1234));
                FileHandle handle = createRsp.GetObjHandle();
                byte[][]   oooBuf = new byte[][] { new byte[bufSize], new byte[bufSize], new byte[bufSize
                                                   ] };
                for (int i = 0; i < numOOO; i++)
                {
                    Arrays.Fill(oooBuf[i], unchecked ((byte)i));
                }
                for (int i_1 = 0; i_1 < numOOO; i_1++)
                {
                    long          offset   = (numOOO - 1 - i_1) * bufSize;
                    WRITE3Request writeReq = new WRITE3Request(handle, offset, bufSize, Nfs3Constant.WriteStableHow
                                                               .Unstable, ByteBuffer.Wrap(oooBuf[i_1]));
                    XDR writeXdr = new XDR();
                    writeReq.Serialize(writeXdr);
                    nfsd.Write(writeXdr.AsReadOnlyWrap(), null, 1, securityHandler, new IPEndPoint("localhost"
                                                                                                   , 1234));
                }
                WaitWrite(nfsd, handle, 60000);
                READ3Request readReq = new READ3Request(handle, bufSize, bufSize);
                XDR          readXdr = new XDR();
                readReq.Serialize(readXdr);
                READ3Response readRsp = nfsd.Read(readXdr.AsReadOnlyWrap(), securityHandler, new
                                                  IPEndPoint("localhost", config.GetInt(NfsConfigKeys.DfsNfsServerPortKey, NfsConfigKeys
                                                                                        .DfsNfsServerPortDefault)));
                NUnit.Framework.Assert.IsTrue(Arrays.Equals(oooBuf[1], ((byte[])readRsp.GetData()
                                                                        .Array())));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
コード例 #17
0
        protected override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info)
        {
            RpcCall rpcCall = (RpcCall)info.Header();

            MountInterface.MNTPROC mntproc = MountInterface.MNTPROC.FromValue(rpcCall.GetProcedure
                                                                                  ());
            int xid = rpcCall.GetXid();

            byte[] data = new byte[info.Data().ReadableBytes()];
            info.Data().ReadBytes(data);
            XDR       xdr    = new XDR(data);
            XDR       @out   = new XDR();
            IPAddress client = ((IPEndPoint)info.RemoteAddress()).Address;

            if (mntproc == MountInterface.MNTPROC.Null)
            {
                @out = NullOp(@out, xid, client);
            }
            else
            {
                if (mntproc == MountInterface.MNTPROC.Mnt)
                {
                    // Only do port monitoring for MNT
                    if (!DoPortMonitoring(info.RemoteAddress()))
                    {
                        @out = MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null);
                    }
                    else
                    {
                        @out = Mnt(xdr, @out, xid, client);
                    }
                }
                else
                {
                    if (mntproc == MountInterface.MNTPROC.Dump)
                    {
                        @out = Dump(@out, xid, client);
                    }
                    else
                    {
                        if (mntproc == MountInterface.MNTPROC.Umnt)
                        {
                            @out = Umnt(xdr, @out, xid, client);
                        }
                        else
                        {
                            if (mntproc == MountInterface.MNTPROC.Umntall)
                            {
                                Umntall(@out, xid, client);
                            }
                            else
                            {
                                if (mntproc == MountInterface.MNTPROC.Export)
                                {
                                    // Currently only support one NFS export
                                    IList <NfsExports> hostsMatchers = new AList <NfsExports>();
                                    if (hostsMatcher != null)
                                    {
                                        hostsMatchers.AddItem(hostsMatcher);
                                        @out = MountResponse.WriteExportList(@out, xid, exports, hostsMatchers);
                                    }
                                    else
                                    {
                                        // This means there are no valid exports provided.
                                        RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                         ()).Write(@out);
                                    }
                                }
                                else
                                {
                                    // Invalid procedure
                                    RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                     ()).Write(@out);
                                }
                            }
                        }
                    }
                }
            }
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, info.RemoteAddress());

            RpcUtil.SendRpcResponse(ctx, rsp);
        }
コード例 #18
0
        /// <exception cref="System.Exception"/>
        public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
        {
            RpcInfo info        = (RpcInfo)e.GetMessage();
            RpcCall rpcCall     = (RpcCall)info.Header();
            int     portmapProc = rpcCall.GetProcedure();
            int     xid         = rpcCall.GetXid();
            XDR     @in         = new XDR(info.Data().ToByteBuffer().AsReadOnlyBuffer(), XDR.State.Reading
                                          );
            XDR @out = new XDR();

            if (portmapProc == PmapprocNull)
            {
                @out = NullOp(xid, @in, @out);
            }
            else
            {
                if (portmapProc == PmapprocSet)
                {
                    @out = Set(xid, @in, @out);
                }
                else
                {
                    if (portmapProc == PmapprocUnset)
                    {
                        @out = Unset(xid, @in, @out);
                    }
                    else
                    {
                        if (portmapProc == PmapprocDump)
                        {
                            @out = Dump(xid, @in, @out);
                        }
                        else
                        {
                            if (portmapProc == PmapprocGetport)
                            {
                                @out = Getport(xid, @in, @out);
                            }
                            else
                            {
                                if (portmapProc == PmapprocGetversaddr)
                                {
                                    @out = Getport(xid, @in, @out);
                                }
                                else
                                {
                                    Log.Info("PortmapHandler unknown rpc procedure=" + portmapProc);
                                    RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState
                                                                                          .ProcUnavail, new VerifierNone());
                                    reply.Write(@out);
                                }
                            }
                        }
                    }
                }
            }
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, info.RemoteAddress());

            RpcUtil.SendRpcResponse(ctx, rsp);
        }
コード例 #19
0
ファイル: TestWrites.cs プロジェクト: orf53975/hadoop.net
        public virtual void TestWriteStableHow()
        {
            NfsConfiguration config  = new NfsConfiguration();
            DFSClient        client  = null;
            MiniDFSCluster   cluster = null;
            RpcProgramNfs3   nfsd;
            SecurityHandler  securityHandler = Org.Mockito.Mockito.Mock <SecurityHandler>();

            Org.Mockito.Mockito.When(securityHandler.GetUser()).ThenReturn(Runtime.GetProperty
                                                                               ("user.name"));
            string currentUser = Runtime.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(NameNode.GetAddress(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
                Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3 nfs3 = new Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.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.CreateUnchecked
                                                              , new SetAttr3(), 0);
                XDR createXdr = new XDR();
                createReq.Serialize(createXdr);
                CREATE3Response createRsp = nfsd.Create(createXdr.AsReadOnlyWrap(), securityHandler
                                                        , new IPEndPoint("localhost", 1234));
                FileHandle handle = createRsp.GetObjHandle();
                // Test DATA_SYNC
                byte[] buffer = new byte[10];
                for (int i = 0; i < 10; i++)
                {
                    buffer[i] = unchecked ((byte)i);
                }
                WRITE3Request writeReq = new WRITE3Request(handle, 0, 10, Nfs3Constant.WriteStableHow
                                                           .DataSync, ByteBuffer.Wrap(buffer));
                XDR writeXdr = new XDR();
                writeReq.Serialize(writeXdr);
                nfsd.Write(writeXdr.AsReadOnlyWrap(), null, 1, securityHandler, new IPEndPoint("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
                                                  IPEndPoint("localhost", 1234));
                NUnit.Framework.Assert.IsTrue(Arrays.Equals(buffer, ((byte[])readRsp.GetData().Array
                                                                         ())));
                // Test FILE_SYNC
                // Create file2
                CREATE3Request createReq2 = new CREATE3Request(rootHandle, "file2", Nfs3Constant.
                                                               CreateUnchecked, new SetAttr3(), 0);
                XDR createXdr2 = new XDR();
                createReq2.Serialize(createXdr2);
                CREATE3Response createRsp2 = nfsd.Create(createXdr2.AsReadOnlyWrap(), securityHandler
                                                         , new IPEndPoint("localhost", 1234));
                FileHandle    handle2   = createRsp2.GetObjHandle();
                WRITE3Request writeReq2 = new WRITE3Request(handle2, 0, 10, Nfs3Constant.WriteStableHow
                                                            .FileSync, ByteBuffer.Wrap(buffer));
                XDR writeXdr2 = new XDR();
                writeReq2.Serialize(writeXdr2);
                nfsd.Write(writeXdr2.AsReadOnlyWrap(), null, 1, securityHandler, new IPEndPoint("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
                                                   IPEndPoint("localhost", 1234));
                NUnit.Framework.Assert.IsTrue(Arrays.Equals(buffer, ((byte[])readRsp2.GetData().Array
                                                                         ())));
                // FILE_SYNC should sync the file size
                status = client.GetFileInfo("/file2");
                NUnit.Framework.Assert.IsTrue(status.GetLen() == 10);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }