Example #1
0
        /// <summary>Create a redirection URL</summary>
        /// <exception cref="System.IO.IOException"/>
        private Uri CreateRedirectURL(string path, string encodedPath, HdfsFileStatus status
                                      , UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request,
                                      string dt)
        {
            string        scheme = request.GetScheme();
            LocatedBlocks blks   = nnproxy.GetBlockLocations(status.GetFullPath(new Path(path))
                                                             .ToUri().GetPath(), 0, 1);
            Configuration conf = NameNodeHttpServer.GetConfFromContext(GetServletContext());
            DatanodeID    host = PickSrcDatanode(blks, status, conf);
            string        hostname;

            if (host is DatanodeInfo)
            {
                hostname = host.GetHostName();
            }
            else
            {
                hostname = host.GetIpAddr();
            }
            int    port    = "https".Equals(scheme) ? host.GetInfoSecurePort() : host.GetInfoPort();
            string dtParam = string.Empty;

            if (dt != null)
            {
                dtParam = JspHelper.GetDelegationTokenUrlParam(dt);
            }
            // Add namenode address to the url params
            NameNode nn        = NameNodeHttpServer.GetNameNodeFromContext(GetServletContext());
            string   addr      = nn.GetNameNodeAddressHostPortString();
            string   addrParam = JspHelper.GetUrlParam(JspHelper.NamenodeAddress, addr);

            return(new Uri(scheme, hostname, port, "/streamFile" + encodedPath + '?' + "ugi="
                           + ServletUtil.EncodeQueryValue(ugi.GetShortUserName()) + dtParam + addrParam));
        }
Example #2
0
            /// <summary>Create a redirection URL</summary>
            /// <exception cref="System.IO.IOException"/>
            private Uri CreateRedirectURL(UserGroupInformation ugi, DatanodeID host, HttpServletRequest
                                          request, NameNode nn)
            {
                string hostname = host is DatanodeInfo?host.GetHostName() : host.GetIpAddr();

                string scheme = request.GetScheme();
                int    port   = host.GetInfoPort();

                if ("https".Equals(scheme))
                {
                    int portObject = (int)GetServletContext().GetAttribute(DFSConfigKeys.DfsDatanodeHttpsPortKey
                                                                           );
                    if (portObject != null)
                    {
                        port = portObject;
                    }
                }
                string encodedPath = ServletUtil.GetRawPath(request, "/fileChecksum");
                string dtParam     = string.Empty;

                if (UserGroupInformation.IsSecurityEnabled())
                {
                    string tokenString = ugi.GetTokens().GetEnumerator().Next().EncodeToUrlString();
                    dtParam = JspHelper.GetDelegationTokenUrlParam(tokenString);
                }
                string addr      = nn.GetNameNodeAddressHostPortString();
                string addrParam = JspHelper.GetUrlParam(JspHelper.NamenodeAddress, addr);

                return(new Uri(scheme, hostname, port, "/getFileChecksum" + encodedPath + '?' + "ugi="
                               + ServletUtil.EncodeQueryValue(ugi.GetShortUserName()) + dtParam + addrParam));
            }
Example #3
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual string AddDelegationTokenParam(string query)
        {
            string tokenString = null;

            if (UserGroupInformation.IsSecurityEnabled())
            {
                lock (this)
                {
                    tokenAspect.EnsureTokenInitialized();
                    if (delegationToken != null)
                    {
                        tokenString = delegationToken.EncodeToUrlString();
                        return(query + JspHelper.GetDelegationTokenUrlParam(tokenString));
                    }
                }
            }
            return(query);
        }