Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
 /// <summary>Select a datanode to service this request.</summary>
 /// <remarks>
 /// Select a datanode to service this request.
 /// Currently, this looks at no more than the first five blocks of a file,
 /// selecting a datanode randomly from the most represented.
 /// </remarks>
 /// <param name="conf"></param>
 /// <exception cref="System.IO.IOException"/>
 private DatanodeID PickSrcDatanode(LocatedBlocks blks, HdfsFileStatus i, Configuration
                                    conf)
 {
     if (i.GetLen() == 0 || blks.GetLocatedBlocks().Count <= 0)
     {
         // pick a random datanode
         NameNode nn = NameNodeHttpServer.GetNameNodeFromContext(GetServletContext());
         return(NamenodeJspHelper.GetRandomDatanode(nn));
     }
     return(JspHelper.BestNode(blks, conf));
 }
Ejemplo n.º 3
0
            /// <exception cref="System.Exception"/>
            public object Run()
            {
                NameNode     nn             = NameNodeHttpServer.GetNameNodeFromContext(context);
                FSNamesystem namesystem     = nn.GetNamesystem();
                BlockManager bm             = namesystem.GetBlockManager();
                int          totalDatanodes = namesystem.GetNumberOfDatanodes(HdfsConstants.DatanodeReportType
                                                                              .Live);

                new NamenodeFsck(conf, nn, bm.GetDatanodeManager().GetNetworkTopology(), pmap, @out
                                 , totalDatanodes, remoteAddress).Fsck();
                return(null);
            }
Ejemplo n.º 4
0
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest req, HttpServletResponse resp)
        {
            UserGroupInformation ugi;
            ServletContext       context = GetServletContext();
            Configuration        conf    = NameNodeHttpServer.GetConfFromContext(context);

            try
            {
                ugi = GetUGI(req, conf);
            }
            catch (IOException ioe)
            {
                Log.Info("Request for token received with no authentication from " + req.GetRemoteAddr
                             (), ioe);
                resp.SendError(HttpServletResponse.ScForbidden, "Unable to identify or authenticate user"
                               );
                return;
            }
            NameNode nn          = NameNodeHttpServer.GetNameNodeFromContext(context);
            string   tokenString = req.GetParameter(Token);

            if (tokenString == null)
            {
                resp.SendError(HttpServletResponse.ScMultipleChoices, "Token to renew not specified"
                               );
            }
            Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = new Org.Apache.Hadoop.Security.Token.Token
                                                                                       <DelegationTokenIdentifier>();
            token.DecodeFromUrlString(tokenString);
            try
            {
                long        result = ugi.DoAs(new _PrivilegedExceptionAction_73(nn, token));
                PrintWriter os     = new PrintWriter(new OutputStreamWriter(resp.GetOutputStream(), Charsets
                                                                            .Utf8));
                os.WriteLine(result);
                os.Close();
            }
            catch (Exception e)
            {
                // transfer exception over the http
                string exceptionClass = e.GetType().FullName;
                string exceptionMsg   = e.GetLocalizedMessage();
                string strException   = exceptionClass + ";" + exceptionMsg;
                Log.Info("Exception while renewing token. Re-throwing. s=" + strException, e);
                resp.SendError(HttpServletResponse.ScInternalServerError, strException);
            }
        }
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest req, HttpServletResponse resp)
        {
            UserGroupInformation ugi;
            ServletContext       context = GetServletContext();
            Configuration        conf    = NameNodeHttpServer.GetConfFromContext(context);

            try
            {
                ugi = GetUGI(req, conf);
            }
            catch (IOException ioe)
            {
                Log.Info("Request for token received with no authentication from " + req.GetRemoteAddr
                             (), ioe);
                resp.SendError(HttpServletResponse.ScForbidden, "Unable to identify or authenticate user"
                               );
                return;
            }
            Log.Info("Sending token: {" + ugi.GetUserName() + "," + req.GetRemoteAddr() + "}"
                     );
            NameNode         nn           = NameNodeHttpServer.GetNameNodeFromContext(context);
            string           renewer      = req.GetParameter(Renewer);
            string           renewerFinal = (renewer == null) ? req.GetUserPrincipal().GetName() : renewer;
            DataOutputStream dos          = null;

            try
            {
                dos = new DataOutputStream(resp.GetOutputStream());
                DataOutputStream dosFinal = dos;
                // for doAs block
                ugi.DoAs(new _PrivilegedExceptionAction_69(nn, ugi, renewerFinal, dosFinal));
            }
            catch (Exception e)
            {
                Log.Info("Exception while sending token. Re-throwing ", e);
                resp.SendError(HttpServletResponse.ScInternalServerError);
            }
            finally
            {
                if (dos != null)
                {
                    dos.Close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a
        /// <see cref="NameNode"/>
        /// proxy from the current
        /// <see cref="Javax.Servlet.ServletContext"/>
        /// .
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual ClientProtocol CreateNameNodeProxy()
        {
            ServletContext context = GetServletContext();
            // if we are running in the Name Node, use it directly rather than via
            // rpc
            NameNode nn = NameNodeHttpServer.GetNameNodeFromContext(context);

            if (nn != null)
            {
                return(nn.GetRpcServer());
            }
            IPEndPoint    nnAddr = NameNodeHttpServer.GetNameNodeAddressFromContext(context);
            Configuration conf   = new HdfsConfiguration(NameNodeHttpServer.GetConfFromContext(
                                                             context));

            return(NameNodeProxies.CreateProxy <ClientProtocol>(conf, NameNode.GetUri(nnAddr))
                   .GetProxy());
        }
Ejemplo n.º 7
0
            /// <exception cref="Javax.Servlet.ServletException"/>
            /// <exception cref="System.IO.IOException"/>
            protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                          )
            {
                ServletContext       context  = GetServletContext();
                Configuration        conf     = NameNodeHttpServer.GetConfFromContext(context);
                UserGroupInformation ugi      = GetUGI(request, conf);
                NameNode             namenode = NameNodeHttpServer.GetNameNodeFromContext(context);
                DatanodeID           datanode = NamenodeJspHelper.GetRandomDatanode(namenode);

                try
                {
                    response.SendRedirect(CreateRedirectURL(ugi, datanode, request, namenode).ToString
                                              ());
                }
                catch (IOException e)
                {
                    response.SendError(400, e.Message);
                }
            }
Ejemplo n.º 8
0
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest req, HttpServletResponse resp)
        {
            UserGroupInformation ugi;
            ServletContext       context = GetServletContext();
            Configuration        conf    = NameNodeHttpServer.GetConfFromContext(context);

            try
            {
                ugi = GetUGI(req, conf);
            }
            catch (IOException ioe)
            {
                Log.Info("Request for token received with no authentication from " + req.GetRemoteAddr
                             (), ioe);
                resp.SendError(HttpServletResponse.ScForbidden, "Unable to identify or authenticate user"
                               );
                return;
            }
            NameNode nn          = NameNodeHttpServer.GetNameNodeFromContext(context);
            string   tokenString = req.GetParameter(Token);

            if (tokenString == null)
            {
                resp.SendError(HttpServletResponse.ScMultipleChoices, "Token to renew not specified"
                               );
            }
            Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = new Org.Apache.Hadoop.Security.Token.Token
                                                                                       <DelegationTokenIdentifier>();
            token.DecodeFromUrlString(tokenString);
            try
            {
                ugi.DoAs(new _PrivilegedExceptionAction_70(nn, token));
            }
            catch (Exception e)
            {
                Log.Info("Exception while cancelling token. Re-throwing. ", e);
                resp.SendError(HttpServletResponse.ScInternalServerError, e.Message);
            }
        }