Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Javax.Servlet.ServletException"/>
        public override void DoFilter(HttpServletRequest request, HttpServletResponse response
                                      , FilterChain chain)
        {
            response.SetCharacterEncoding("UTF-8");
            string uri = HtmlQuoting.QuoteHtmlChars(request.GetRequestURI());

            if (uri == null)
            {
                uri = "/";
            }
            RMWebApp rmWebApp = injector.GetInstance <RMWebApp>();

            rmWebApp.CheckIfStandbyRM();
            if (rmWebApp.IsStandby() && ShouldRedirect(rmWebApp, uri))
            {
                string redirectPath = rmWebApp.GetRedirectPath();
                if (redirectPath != null && !redirectPath.IsEmpty())
                {
                    redirectPath += uri;
                    string      redirectMsg = "This is standby RM. The redirect url is: " + redirectPath;
                    PrintWriter @out        = response.GetWriter();
                    @out.WriteLine(redirectMsg);
                    response.SetHeader("Location", redirectPath);
                    response.SetStatus(HttpServletResponse.ScTemporaryRedirect);
                    return;
                }
                else
                {
                    bool   doRetry          = true;
                    string retryIntervalStr = request.GetParameter(YarnWebParams.NextRefreshInterval);
                    int    retryInterval    = 0;
                    if (retryIntervalStr != null)
                    {
                        try
                        {
                            retryInterval = System.Convert.ToInt32(retryIntervalStr.Trim());
                        }
                        catch (FormatException)
                        {
                            doRetry = false;
                        }
                    }
                    int    next        = CalculateExponentialTime(retryInterval);
                    string redirectUrl = AppendOrReplaceParamter(path + uri, YarnWebParams.NextRefreshInterval
                                                                 + "=" + (retryInterval + 1));
                    if (redirectUrl == null || next > MaxSleepTime)
                    {
                        doRetry = false;
                    }
                    string redirectMsg = doRetry ? "Can not find any active RM. Will retry in next "
                                         + next + " seconds." : "There is no active RM right now.";
                    redirectMsg += "\nHA Zookeeper Connection State: " + rmWebApp.GetHAZookeeperConnectionState
                                       ();
                    PrintWriter @out = response.GetWriter();
                    @out.WriteLine(redirectMsg);
                    if (doRetry)
                    {
                        response.SetHeader("Refresh", next + ";url=" + redirectUrl);
                        response.SetStatus(HttpServletResponse.ScTemporaryRedirect);
                    }
                }
                return;
            }
            base.DoFilter(request, response, chain);
        }
Beispiel #2
0
 private bool ShouldRedirect(RMWebApp rmWebApp, string uri)
 {
     return(!uri.Equals("/" + rmWebApp.WsName() + "/v1/cluster/info") && !uri.Equals("/"
                                                                                     + rmWebApp.Name() + "/cluster") && !uri.StartsWith(ProxyUriUtils.ProxyBase) &&
            !NonRedirectedUris.Contains(uri));
 }