Beispiel #1
0
            /*
             * If this method is called with isTrackingUrl=false, no tracking url
             * will set in the app report. Hence, there will be a connection exception
             * when the prxyCon tries to connect.
             */
            private AppReportFetcher.FetchedAppReport GetDefaultApplicationReport(ApplicationId
                                                                                  appId, bool isTrackingUrl)
            {
                AppReportFetcher.FetchedAppReport fetchedReport;
                ApplicationReport result = new ApplicationReportPBImpl();

                result.SetApplicationId(appId);
                result.SetYarnApplicationState(YarnApplicationState.Running);
                result.SetUser(CommonConfigurationKeys.DefaultHadoopHttpStaticUser);
                if (isTrackingUrl)
                {
                    result.SetOriginalTrackingUrl("localhost:" + TestWebAppProxyServlet.originalPort
                                                  + "/foo/bar");
                }
                if (this._enclosing.configuration.GetBoolean(YarnConfiguration.ApplicationHistoryEnabled
                                                             , false))
                {
                    fetchedReport = new AppReportFetcher.FetchedAppReport(result, AppReportFetcher.AppReportSource
                                                                          .Ahs);
                }
                else
                {
                    fetchedReport = new AppReportFetcher.FetchedAppReport(result, AppReportFetcher.AppReportSource
                                                                          .Rm);
                }
                return(fetchedReport);
            }
Beispiel #2
0
        /// <summary>
        /// Get an application report for the specified application id from the RM and
        /// fall back to the Application History Server if not found in RM.
        /// </summary>
        /// <param name="appId">id of the application to get.</param>
        /// <returns>the ApplicationReport for the appId.</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException">on any error.</exception>
        /// <exception cref="System.IO.IOException"/>
        public virtual AppReportFetcher.FetchedAppReport GetApplicationReport(ApplicationId
                                                                              appId)
        {
            GetApplicationReportRequest request = recordFactory.NewRecordInstance <GetApplicationReportRequest
                                                                                   >();

            request.SetApplicationId(appId);
            ApplicationReport appReport;

            AppReportFetcher.FetchedAppReport fetchedAppReport;
            try
            {
                appReport = applicationsManager.GetApplicationReport(request).GetApplicationReport
                                ();
                fetchedAppReport = new AppReportFetcher.FetchedAppReport(appReport, AppReportFetcher.AppReportSource
                                                                         .Rm);
            }
            catch (ApplicationNotFoundException e)
            {
                if (!isAHSEnabled)
                {
                    // Just throw it as usual if historyService is not enabled.
                    throw;
                }
                //Fetch the application report from AHS
                appReport        = historyManager.GetApplicationReport(request).GetApplicationReport();
                fetchedAppReport = new AppReportFetcher.FetchedAppReport(appReport, AppReportFetcher.AppReportSource
                                                                         .Ahs);
            }
            return(fetchedAppReport);
        }
Beispiel #3
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 public override AppReportFetcher.FetchedAppReport GetApplicationReport(ApplicationId
                                                                        appId)
 {
     if (this.answer == 0)
     {
         return(this.GetDefaultApplicationReport(appId));
     }
     else
     {
         if (this.answer == 1)
         {
             return(null);
         }
         else
         {
             if (this.answer == 2)
             {
                 AppReportFetcher.FetchedAppReport result = this.GetDefaultApplicationReport(appId
                                                                                             );
                 result.GetApplicationReport().SetUser("user");
                 return(result);
             }
             else
             {
                 if (this.answer == 3)
                 {
                     AppReportFetcher.FetchedAppReport result = this.GetDefaultApplicationReport(appId
                                                                                                 );
                     result.GetApplicationReport().SetYarnApplicationState(YarnApplicationState.Killed
                                                                           );
                     return(result);
                 }
                 else
                 {
                     if (this.answer == 4)
                     {
                         throw new ApplicationNotFoundException("Application is not found");
                     }
                     else
                     {
                         if (this.answer == 5)
                         {
                             // test user-provided path and query parameter can be appended to the
                             // original tracking url
                             AppReportFetcher.FetchedAppReport result = this.GetDefaultApplicationReport(appId
                                                                                                         );
                             result.GetApplicationReport().SetOriginalTrackingUrl("localhost:" + TestWebAppProxyServlet
                                                                                  .originalPort + "/foo/bar?a=b#main");
                             result.GetApplicationReport().SetYarnApplicationState(YarnApplicationState.Finished
                                                                                   );
                             return(result);
                         }
                         else
                         {
                             if (this.answer == 6)
                             {
                                 return(this.GetDefaultApplicationReport(appId, false));
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                string   userApprovedParamS = req.GetParameter(ProxyUriUtils.ProxyApprovalParam);
                bool     userWasWarned      = false;
                bool     userApproved       = Sharpen.Extensions.ValueOf(userApprovedParamS);
                bool     securityEnabled    = IsSecurityEnabled();
                string   remoteUser         = req.GetRemoteUser();
                string   pathInfo           = req.GetPathInfo();
                string[] parts = pathInfo.Split("/", 3);
                if (parts.Length < 2)
                {
                    Log.Warn("{} gave an invalid proxy path {}", remoteUser, pathInfo);
                    NotFound(resp, "Your path appears to be formatted incorrectly.");
                    return;
                }
                //parts[0] is empty because path info always starts with a /
                string        appId = parts[1];
                string        rest  = parts.Length > 2 ? parts[2] : string.Empty;
                ApplicationId id    = Apps.ToAppID(appId);
                if (id == null)
                {
                    Log.Warn("{} attempting to access {} that is invalid", remoteUser, appId);
                    NotFound(resp, appId + " appears to be formatted incorrectly.");
                    return;
                }
                if (securityEnabled)
                {
                    string   cookieName = GetCheckCookieName(id);
                    Cookie[] cookies    = req.GetCookies();
                    if (cookies != null)
                    {
                        foreach (Cookie c in cookies)
                        {
                            if (cookieName.Equals(c.GetName()))
                            {
                                userWasWarned = true;
                                userApproved  = userApproved || Sharpen.Extensions.ValueOf(c.GetValue());
                                break;
                            }
                        }
                    }
                }
                bool checkUser = securityEnabled && (!userWasWarned || !userApproved);
                AppReportFetcher.FetchedAppReport fetchedAppReport = null;
                ApplicationReport applicationReport = null;
                try
                {
                    fetchedAppReport = GetApplicationReport(id);
                    if (fetchedAppReport != null)
                    {
                        if (fetchedAppReport.GetAppReportSource() != AppReportFetcher.AppReportSource.Rm &&
                            fetchedAppReport.GetAppReportSource() != AppReportFetcher.AppReportSource.Ahs)
                        {
                            throw new NotSupportedException("Application report not " + "fetched from RM or history server."
                                                            );
                        }
                        applicationReport = fetchedAppReport.GetApplicationReport();
                    }
                }
                catch (ApplicationNotFoundException)
                {
                    applicationReport = null;
                }
                if (applicationReport == null)
                {
                    Log.Warn("{} attempting to access {} that was not found", remoteUser, id);
                    URI toFetch = ProxyUriUtils.GetUriFromTrackingPlugins(id, this.trackingUriPlugins
                                                                          );
                    if (toFetch != null)
                    {
                        ProxyUtils.SendRedirect(req, resp, toFetch.ToString());
                        return;
                    }
                    NotFound(resp, "Application " + appId + " could not be found " + "in RM or history server"
                             );
                    return;
                }
                string original = applicationReport.GetOriginalTrackingUrl();
                URI    trackingUri;
                if (original == null || original.Equals("N/A") || original.Equals(string.Empty))
                {
                    if (fetchedAppReport.GetAppReportSource() == AppReportFetcher.AppReportSource.Rm)
                    {
                        // fallback to ResourceManager's app page if no tracking URI provided
                        // and Application Report was fetched from RM
                        Log.Debug("Original tracking url is '{}'. Redirecting to RM app page", original ==
                                  null ? "NULL" : original);
                        ProxyUtils.SendRedirect(req, resp, StringHelper.Pjoin(rmAppPageUrlBase, id.ToString
                                                                                  ()));
                    }
                    else
                    {
                        if (fetchedAppReport.GetAppReportSource() == AppReportFetcher.AppReportSource.Ahs)
                        {
                            // fallback to Application History Server app page if the application
                            // report was fetched from AHS
                            Log.Debug("Original tracking url is '{}'. Redirecting to AHS app page", original
                                      == null ? "NULL" : original);
                            ProxyUtils.SendRedirect(req, resp, StringHelper.Pjoin(ahsAppPageUrlBase, id.ToString
                                                                                      ()));
                        }
                    }
                    return;
                }
                else
                {
                    if (ProxyUriUtils.GetSchemeFromUrl(original).IsEmpty())
                    {
                        trackingUri = ProxyUriUtils.GetUriFromAMUrl(WebAppUtils.GetHttpSchemePrefix(conf)
                                                                    , original);
                    }
                    else
                    {
                        trackingUri = new URI(original);
                    }
                }
                string runningUser = applicationReport.GetUser();
                if (checkUser && !runningUser.Equals(remoteUser))
                {
                    Log.Info("Asking {} if they want to connect to the " + "app master GUI of {} owned by {}"
                             , remoteUser, appId, runningUser);
                    WarnUserPage(resp, ProxyUriUtils.GetPathAndQuery(id, rest, req.GetQueryString(),
                                                                     true), runningUser, id);
                    return;
                }
                // Append the user-provided path and query parameter to the original
                // tracking url.
                IList <NameValuePair> queryPairs = URLEncodedUtils.Parse(req.GetQueryString(), null
                                                                         );
                UriBuilder builder = UriBuilder.FromUri(trackingUri);
                foreach (NameValuePair pair in queryPairs)
                {
                    builder.QueryParam(pair.GetName(), pair.GetValue());
                }
                URI toFetch_1 = builder.Path(rest).Build();
                Log.Info("{} is accessing unchecked {}" + " which is the app master GUI of {} owned by {}"
                         , remoteUser, toFetch_1, appId, runningUser);
                switch (applicationReport.GetYarnApplicationState())
                {
                case YarnApplicationState.Killed:
                case YarnApplicationState.Finished:
                case YarnApplicationState.Failed:
                {
                    ProxyUtils.SendRedirect(req, resp, toFetch_1.ToString());
                    return;
                }

                default:
                {
                    break;
                }
                }
                // fall out of the switch
                Cookie c_1 = null;
                if (userWasWarned && userApproved)
                {
                    c_1 = MakeCheckCookie(id, true);
                }
                ProxyLink(req, resp, toFetch_1, c_1, GetProxyHost());
            }
            catch (Exception e)
            {
                throw new IOException(e);
            }
        }