Пример #1
0
        public virtual void TestDeprecatedKeys()
        {
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetInt("nfs3.server.port", 998);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsServerPortKey, 0) ==
                                          998);
            conf.SetInt("nfs3.mountd.port", 999);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsMountdPortKey, 0) ==
                                          999);
            conf.Set("dfs.nfs.exports.allowed.hosts", "host1");
            NUnit.Framework.Assert.IsTrue(conf.Get(CommonConfigurationKeys.NfsExportsAllowedHostsKey
                                                   ).Equals("host1"));
            conf.SetInt("dfs.nfs.exports.cache.expirytime.millis", 1000);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(Nfs3Constant.NfsExportsCacheExpirytimeMillisKey
                                                      , 0) == 1000);
            conf.SetInt("hadoop.nfs.userupdate.milly", 10);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(IdMappingConstant.UsergroupidUpdateMillisKey
                                                      , 0) == 10);
            conf.Set("dfs.nfs3.dump.dir", "/nfs/tmp");
            NUnit.Framework.Assert.IsTrue(conf.Get(NfsConfigKeys.DfsNfsFileDumpDirKey).Equals
                                              ("/nfs/tmp"));
            conf.SetBoolean("dfs.nfs3.enableDump", false);
            NUnit.Framework.Assert.IsTrue(conf.GetBoolean(NfsConfigKeys.DfsNfsFileDumpKey, true
                                                          ) == false);
            conf.SetInt("dfs.nfs3.max.open.files", 500);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsMaxOpenFilesKey, 0)
                                          == 500);
            conf.SetInt("dfs.nfs3.stream.timeout", 6000);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsStreamTimeoutKey, 0
                                                      ) == 6000);
            conf.Set("dfs.nfs3.export.point", "/dir1");
            NUnit.Framework.Assert.IsTrue(conf.Get(NfsConfigKeys.DfsNfsExportPointKey).Equals
                                              ("/dir1"));
        }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 public RpcProgramMountd(NfsConfiguration config, DatagramSocket registrationSocket
                         , bool allowInsecurePorts)
     : base("mountd", "localhost", config.GetInt(NfsConfigKeys.DfsNfsMountdPortKey, NfsConfigKeys
                                                 .DfsNfsMountdPortDefault), Program, Version1, Version3, registrationSocket, allowInsecurePorts
            )
 {
     // Note that RPC cache is not enabled
     exports = new AList <string>();
     exports.AddItem(config.Get(NfsConfigKeys.DfsNfsExportPointKey, NfsConfigKeys.DfsNfsExportPointDefault
                                ));
     this.hostsMatcher = NfsExports.GetInstance(config);
     this.mounts       = Sharpen.Collections.SynchronizedList(new AList <MountEntry>());
     UserGroupInformation.SetConfiguration(config);
     SecurityUtil.Login(config, NfsConfigKeys.DfsNfsKeytabFileKey, NfsConfigKeys.DfsNfsKerberosPrincipalKey
                        );
     this.dfsClient = new DFSClient(NameNode.GetAddress(config), config);
 }
Пример #3
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual void Start()
        {
            IPEndPoint httpAddr        = GetHttpAddress(conf);
            string     httpsAddrString = conf.Get(NfsConfigKeys.NfsHttpsAddressKey, NfsConfigKeys
                                                  .NfsHttpsAddressDefault);
            IPEndPoint httpsAddr = NetUtils.CreateSocketAddr(httpsAddrString);

            HttpServer2.Builder builder = DFSUtil.HttpServerTemplateForNNAndJN(conf, httpAddr
                                                                               , httpsAddr, "nfs3", NfsConfigKeys.DfsNfsKerberosPrincipalKey, NfsConfigKeys.DfsNfsKeytabFileKey
                                                                               );
            this.httpServer = builder.Build();
            this.httpServer.Start();
            HttpConfig.Policy policy = DFSUtil.GetHttpPolicy(conf);
            int connIdx = 0;

            if (policy.IsHttpEnabled())
            {
                infoPort = httpServer.GetConnectorAddress(connIdx++).Port;
            }
            if (policy.IsHttpsEnabled())
            {
                infoSecurePort = httpServer.GetConnectorAddress(connIdx).Port;
            }
        }
Пример #4
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual void HandleWrite(DFSClient dfsClient, WRITE3Request request, Org.Jboss.Netty.Channel.Channel
                                          channel, int xid, Nfs3FileAttributes preOpAttr)
        {
            int count = request.GetCount();

            byte[] data = ((byte[])request.GetData().Array());
            if (data.Length < count)
            {
                WRITE3Response response = new WRITE3Response(Nfs3Status.Nfs3errInval);
                Nfs3Utils.WriteChannel(channel, response.Serialize(new XDR(), xid, new VerifierNone
                                                                       ()), xid);
                return;
            }
            FileHandle handle = request.GetHandle();

            if (Log.IsDebugEnabled())
            {
                Log.Debug("handleWrite " + request);
            }
            // Check if there is a stream to write
            FileHandle  fileHandle  = request.GetHandle();
            OpenFileCtx openFileCtx = fileContextCache.Get(fileHandle);

            if (openFileCtx == null)
            {
                Log.Info("No opened stream for fileId: " + fileHandle.GetFileId());
                string fileIdPath               = Nfs3Utils.GetFileIdPath(fileHandle.GetFileId());
                HdfsDataOutputStream fos        = null;
                Nfs3FileAttributes   latestAttr = null;
                try
                {
                    int bufferSize = config.GetInt(CommonConfigurationKeysPublic.IoFileBufferSizeKey,
                                                   CommonConfigurationKeysPublic.IoFileBufferSizeDefault);
                    fos = dfsClient.Append(fileIdPath, bufferSize, EnumSet.Of(CreateFlag.Append), null
                                           , null);
                    latestAttr = Nfs3Utils.GetFileAttr(dfsClient, fileIdPath, iug);
                }
                catch (RemoteException e)
                {
                    IOException io = e.UnwrapRemoteException();
                    if (io is AlreadyBeingCreatedException)
                    {
                        Log.Warn("Can't append file: " + fileIdPath + ". Possibly the file is being closed. Drop the request: "
                                 + request + ", wait for the client to retry...");
                        return;
                    }
                    throw;
                }
                catch (IOException e)
                {
                    Log.Error("Can't append to file: " + fileIdPath, e);
                    if (fos != null)
                    {
                        fos.Close();
                    }
                    WccData        fileWcc  = new WccData(Nfs3Utils.GetWccAttr(preOpAttr), preOpAttr);
                    WRITE3Response response = new WRITE3Response(Nfs3Status.Nfs3errIo, fileWcc, count
                                                                 , request.GetStableHow(), Nfs3Constant.WriteCommitVerf);
                    Nfs3Utils.WriteChannel(channel, response.Serialize(new XDR(), xid, new VerifierNone
                                                                           ()), xid);
                    return;
                }
                // Add open stream
                string writeDumpDir = config.Get(NfsConfigKeys.DfsNfsFileDumpDirKey, NfsConfigKeys
                                                 .DfsNfsFileDumpDirDefault);
                openFileCtx = new OpenFileCtx(fos, latestAttr, writeDumpDir + "/" + fileHandle.GetFileId
                                                  (), dfsClient, iug, aixCompatMode, config);
                if (!AddOpenFileStream(fileHandle, openFileCtx))
                {
                    Log.Info("Can't add new stream. Close it. Tell client to retry.");
                    try
                    {
                        fos.Close();
                    }
                    catch (IOException e)
                    {
                        Log.Error("Can't close stream for fileId: " + handle.GetFileId(), e);
                    }
                    // Notify client to retry
                    WccData        fileWcc  = new WccData(latestAttr.GetWccAttr(), latestAttr);
                    WRITE3Response response = new WRITE3Response(Nfs3Status.Nfs3errJukebox, fileWcc,
                                                                 0, request.GetStableHow(), Nfs3Constant.WriteCommitVerf);
                    Nfs3Utils.WriteChannel(channel, response.Serialize(new XDR(), xid, new VerifierNone
                                                                           ()), xid);
                    return;
                }
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Opened stream for appending file: " + fileHandle.GetFileId());
                }
            }
            // Add write into the async job queue
            openFileCtx.ReceivedNewWrite(dfsClient, request, channel, xid, asyncDataService,
                                         iug);
            return;
        }