Esempio n. 1
0
 public AppInfo(ApplicationReport app)
 {
     // JAXB needs this
     appId = app.GetApplicationId().ToString();
     if (app.GetCurrentApplicationAttemptId() != null)
     {
         currentAppAttemptId = app.GetCurrentApplicationAttemptId().ToString();
     }
     user                = app.GetUser();
     queue               = app.GetQueue();
     name                = app.GetName();
     type                = app.GetApplicationType();
     host                = app.GetHost();
     rpcPort             = app.GetRpcPort();
     appState            = app.GetYarnApplicationState();
     diagnosticsInfo     = app.GetDiagnostics();
     trackingUrl         = app.GetTrackingUrl();
     originalTrackingUrl = app.GetOriginalTrackingUrl();
     submittedTime       = app.GetStartTime();
     startedTime         = app.GetStartTime();
     finishedTime        = app.GetFinishTime();
     elapsedTime         = Times.Elapsed(startedTime, finishedTime);
     finalAppStatus      = app.GetFinalApplicationStatus();
     progress            = app.GetProgress() * 100;
     // in percent
     if (app.GetApplicationTags() != null && !app.GetApplicationTags().IsEmpty())
     {
         this.applicationTags = StringHelper.CsvJoiner.Join(app.GetApplicationTags());
     }
 }
Esempio n. 2
0
        private void VerifyEnemyAppReport(ApplicationReport appReport)
        {
            NUnit.Framework.Assert.AreEqual("Enemy should not see app host!", Unavailable, appReport
                                            .GetHost());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app rpc port!", -1, appReport
                                            .GetRpcPort());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app client token!", null, appReport
                                            .GetClientToAMToken());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app diagnostics!", Unavailable
                                            , appReport.GetDiagnostics());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app tracking url!", Unavailable
                                            , appReport.GetTrackingUrl());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app original tracking url!"
                                            , Unavailable, appReport.GetOriginalTrackingUrl());
            ApplicationResourceUsageReport usageReport = appReport.GetApplicationResourceUsageReport
                                                             ();

            NUnit.Framework.Assert.AreEqual("Enemy should not see app used containers", -1, usageReport
                                            .GetNumUsedContainers());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app reserved containers", -
                                            1, usageReport.GetNumReservedContainers());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app used resources", -1, usageReport
                                            .GetUsedResources().GetMemory());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app reserved resources", -1
                                            , usageReport.GetReservedResources().GetMemory());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app needed resources", -1,
                                            usageReport.GetNeededResources().GetMemory());
        }
Esempio n. 3
0
        /// <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);
            }
        }
Esempio n. 4
0
        /// <summary>Prints the application report for an application id.</summary>
        /// <param name="applicationId"/>
        /// <returns>exitCode</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private int PrintApplicationReport(string applicationId)
        {
            ApplicationReport appReport = null;

            try
            {
                appReport = client.GetApplicationReport(ConverterUtils.ToApplicationId(applicationId
                                                                                       ));
            }
            catch (ApplicationNotFoundException)
            {
                sysout.WriteLine("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server."
                                 );
                return(-1);
            }
            // Use PrintWriter.println, which uses correct platform line ending.
            ByteArrayOutputStream baos         = new ByteArrayOutputStream();
            PrintWriter           appReportStr = new PrintWriter(new OutputStreamWriter(baos, Sharpen.Extensions.GetEncoding
                                                                                            ("UTF-8")));

            if (appReport != null)
            {
                appReportStr.WriteLine("Application Report : ");
                appReportStr.Write("\tApplication-Id : ");
                appReportStr.WriteLine(appReport.GetApplicationId());
                appReportStr.Write("\tApplication-Name : ");
                appReportStr.WriteLine(appReport.GetName());
                appReportStr.Write("\tApplication-Type : ");
                appReportStr.WriteLine(appReport.GetApplicationType());
                appReportStr.Write("\tUser : "******"\tQueue : ");
                appReportStr.WriteLine(appReport.GetQueue());
                appReportStr.Write("\tStart-Time : ");
                appReportStr.WriteLine(appReport.GetStartTime());
                appReportStr.Write("\tFinish-Time : ");
                appReportStr.WriteLine(appReport.GetFinishTime());
                appReportStr.Write("\tProgress : ");
                DecimalFormat formatter = new DecimalFormat("###.##%");
                string        progress  = formatter.Format(appReport.GetProgress());
                appReportStr.WriteLine(progress);
                appReportStr.Write("\tState : ");
                appReportStr.WriteLine(appReport.GetYarnApplicationState());
                appReportStr.Write("\tFinal-State : ");
                appReportStr.WriteLine(appReport.GetFinalApplicationStatus());
                appReportStr.Write("\tTracking-URL : ");
                appReportStr.WriteLine(appReport.GetOriginalTrackingUrl());
                appReportStr.Write("\tRPC Port : ");
                appReportStr.WriteLine(appReport.GetRpcPort());
                appReportStr.Write("\tAM Host : ");
                appReportStr.WriteLine(appReport.GetHost());
                appReportStr.Write("\tAggregate Resource Allocation : ");
                ApplicationResourceUsageReport usageReport = appReport.GetApplicationResourceUsageReport
                                                                 ();
                if (usageReport != null)
                {
                    //completed app report in the timeline server doesn't have usage report
                    appReportStr.Write(usageReport.GetMemorySeconds() + " MB-seconds, ");
                    appReportStr.WriteLine(usageReport.GetVcoreSeconds() + " vcore-seconds");
                }
                else
                {
                    appReportStr.WriteLine("N/A");
                }
                appReportStr.Write("\tDiagnostics : ");
                appReportStr.Write(appReport.GetDiagnostics());
            }
            else
            {
                appReportStr.Write("Application with id '" + applicationId + "' doesn't exist in RM."
                                   );
                appReportStr.Close();
                sysout.WriteLine(baos.ToString("UTF-8"));
                return(-1);
            }
            appReportStr.Close();
            sysout.WriteLine(baos.ToString("UTF-8"));
            return(0);
        }