예제 #1
0
        private static void ValidateStates(string stateQuery, ICollection <string> statesQuery
                                           )
        {
            // stateQuery is deprecated.
            if (stateQuery != null && !stateQuery.IsEmpty())
            {
                statesQuery.AddItem(stateQuery);
            }
            ICollection <string> appStates = ParseQueries(statesQuery, true);

            foreach (string appState in appStates)
            {
                switch (YarnApplicationState.ValueOf(StringUtils.ToUpperCase(appState)))
                {
                case YarnApplicationState.Finished:
                case YarnApplicationState.Failed:
                case YarnApplicationState.Killed:
                {
                    continue;
                }

                default:
                {
                    throw new BadRequestException("Invalid application-state " + appState + " specified. It should be a final state"
                                                  );
                }
                }
            }
        }
예제 #2
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        protected internal virtual void FetchData()
        {
            reqAppStates = EnumSet.NoneOf <YarnApplicationState>();
            string reqStateString = $(YarnWebParams.AppState);

            if (reqStateString != null && !reqStateString.IsEmpty())
            {
                string[] appStateStrings = reqStateString.Split(",");
                foreach (string stateString in appStateStrings)
                {
                    reqAppStates.AddItem(YarnApplicationState.ValueOf(stateString.Trim()));
                }
            }
            callerUGI = GetCallerUGI();
            GetApplicationsRequest request = GetApplicationsRequest.NewInstance(reqAppStates);
            string appsNumStr = $(YarnWebParams.AppsNum);

            if (appsNumStr != null && !appsNumStr.IsEmpty())
            {
                long appsNum = long.Parse(appsNumStr);
                request.SetLimit(appsNum);
            }
            if (callerUGI == null)
            {
                appReports = appBaseProt.GetApplications(request).GetApplicationList();
            }
            else
            {
                appReports = callerUGI.DoAs(new _PrivilegedExceptionAction_87(this, request));
            }
        }
예제 #3
0
        protected internal static ICollection <string> ParseQueries(ICollection <string> queries
                                                                    , bool isState)
        {
            ICollection <string> @params = new HashSet <string>();

            if (!queries.IsEmpty())
            {
                foreach (string query in queries)
                {
                    if (query != null && !query.Trim().IsEmpty())
                    {
                        string[] paramStrs = query.Split(",");
                        foreach (string paramStr in paramStrs)
                        {
                            if (paramStr != null && !paramStr.Trim().IsEmpty())
                            {
                                if (isState)
                                {
                                    try
                                    {
                                        // enum string is in the uppercase
                                        YarnApplicationState.ValueOf(StringUtils.ToUpperCase(paramStr.Trim()));
                                    }
                                    catch (RuntimeException)
                                    {
                                        YarnApplicationState[] stateArray = YarnApplicationState.Values();
                                        string allAppStates = Arrays.ToString(stateArray);
                                        throw new BadRequestException("Invalid application-state " + paramStr.Trim() + " specified. It should be one of "
                                                                      + allAppStates);
                                    }
                                }
                                @params.AddItem(StringUtils.ToLowerCase(paramStr.Trim()));
                            }
                        }
                    }
                }
            }
            return(@params);
        }
예제 #4
0
        /// <exception cref="System.Exception"/>
        public override int Run(string[] args)
        {
            Options opts  = new Options();
            string  title = null;

            if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], Application))
            {
                title = Application;
                opts.AddOption(StatusCmd, true, "Prints the status of the application.");
                opts.AddOption(ListCmd, false, "List applications. " + "Supports optional use of -appTypes to filter applications "
                               + "based on application type, " + "and -appStates to filter applications based on application state."
                               );
                opts.AddOption(KillCmd, true, "Kills the application.");
                opts.AddOption(MoveToQueueCmd, true, "Moves the application to a " + "different queue."
                               );
                opts.AddOption(QueueCmd, true, "Works with the movetoqueue command to" + " specify which queue to move an application to."
                               );
                opts.AddOption(HelpCmd, false, "Displays help for all commands.");
                Option appTypeOpt = new Option(AppTypeCmd, true, "Works with -list to " + "filter applications based on "
                                               + "input comma-separated list of application types.");
                appTypeOpt.SetValueSeparator(',');
                appTypeOpt.SetArgs(Option.UnlimitedValues);
                appTypeOpt.SetArgName("Types");
                opts.AddOption(appTypeOpt);
                Option appStateOpt = new Option(AppStateCmd, true, "Works with -list " + "to filter applications based on input comma-separated list of "
                                                + "application states. " + GetAllValidApplicationStates());
                appStateOpt.SetValueSeparator(',');
                appStateOpt.SetArgs(Option.UnlimitedValues);
                appStateOpt.SetArgName("States");
                opts.AddOption(appStateOpt);
                opts.GetOption(KillCmd).SetArgName("Application ID");
                opts.GetOption(MoveToQueueCmd).SetArgName("Application ID");
                opts.GetOption(QueueCmd).SetArgName("Queue Name");
                opts.GetOption(StatusCmd).SetArgName("Application ID");
            }
            else
            {
                if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt
                                                                        ))
                {
                    title = ApplicationAttempt;
                    opts.AddOption(StatusCmd, true, "Prints the status of the application attempt.");
                    opts.AddOption(ListCmd, true, "List application attempts for aplication.");
                    opts.AddOption(HelpCmd, false, "Displays help for all commands.");
                    opts.GetOption(StatusCmd).SetArgName("Application Attempt ID");
                    opts.GetOption(ListCmd).SetArgName("Application ID");
                }
                else
                {
                    if (args.Length > 0 && Sharpen.Runtime.EqualsIgnoreCase(args[0], Container))
                    {
                        title = Container;
                        opts.AddOption(StatusCmd, true, "Prints the status of the container.");
                        opts.AddOption(ListCmd, true, "List containers for application attempt.");
                        opts.AddOption(HelpCmd, false, "Displays help for all commands.");
                        opts.GetOption(StatusCmd).SetArgName("Container ID");
                        opts.GetOption(ListCmd).SetArgName("Application Attempt ID");
                    }
                }
            }
            int         exitCode  = -1;
            CommandLine cliParser = null;

            try
            {
                cliParser = new GnuParser().Parse(opts, args);
            }
            catch (MissingArgumentException)
            {
                sysout.WriteLine("Missing argument for options");
                PrintUsage(title, opts);
                return(exitCode);
            }
            if (cliParser.HasOption(StatusCmd))
            {
                if (args.Length != 3)
                {
                    PrintUsage(title, opts);
                    return(exitCode);
                }
                if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Application))
                {
                    exitCode = PrintApplicationReport(cliParser.GetOptionValue(StatusCmd));
                }
                else
                {
                    if (Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt))
                    {
                        exitCode = PrintApplicationAttemptReport(cliParser.GetOptionValue(StatusCmd));
                    }
                    else
                    {
                        if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Container))
                        {
                            exitCode = PrintContainerReport(cliParser.GetOptionValue(StatusCmd));
                        }
                    }
                }
                return(exitCode);
            }
            else
            {
                if (cliParser.HasOption(ListCmd))
                {
                    if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Application))
                    {
                        allAppStates = false;
                        ICollection <string> appTypes = new HashSet <string>();
                        if (cliParser.HasOption(AppTypeCmd))
                        {
                            string[] types = cliParser.GetOptionValues(AppTypeCmd);
                            if (types != null)
                            {
                                foreach (string type in types)
                                {
                                    if (!type.Trim().IsEmpty())
                                    {
                                        appTypes.AddItem(StringUtils.ToUpperCase(type).Trim());
                                    }
                                }
                            }
                        }
                        EnumSet <YarnApplicationState> appStates = EnumSet.NoneOf <YarnApplicationState>();
                        if (cliParser.HasOption(AppStateCmd))
                        {
                            string[] states = cliParser.GetOptionValues(AppStateCmd);
                            if (states != null)
                            {
                                foreach (string state in states)
                                {
                                    if (!state.Trim().IsEmpty())
                                    {
                                        if (Sharpen.Runtime.EqualsIgnoreCase(state.Trim(), AllstatesOption))
                                        {
                                            allAppStates = true;
                                            break;
                                        }
                                        try
                                        {
                                            appStates.AddItem(YarnApplicationState.ValueOf(StringUtils.ToUpperCase(state).Trim
                                                                                               ()));
                                        }
                                        catch (ArgumentException)
                                        {
                                            sysout.WriteLine("The application state " + state + " is invalid.");
                                            sysout.WriteLine(GetAllValidApplicationStates());
                                            return(exitCode);
                                        }
                                    }
                                }
                            }
                        }
                        ListApplications(appTypes, appStates);
                    }
                    else
                    {
                        if (Sharpen.Runtime.EqualsIgnoreCase(args[0], ApplicationAttempt))
                        {
                            if (args.Length != 3)
                            {
                                PrintUsage(title, opts);
                                return(exitCode);
                            }
                            ListApplicationAttempts(cliParser.GetOptionValue(ListCmd));
                        }
                        else
                        {
                            if (Sharpen.Runtime.EqualsIgnoreCase(args[0], Container))
                            {
                                if (args.Length != 3)
                                {
                                    PrintUsage(title, opts);
                                    return(exitCode);
                                }
                                ListContainers(cliParser.GetOptionValue(ListCmd));
                            }
                        }
                    }
                }
                else
                {
                    if (cliParser.HasOption(KillCmd))
                    {
                        if (args.Length != 3)
                        {
                            PrintUsage(title, opts);
                            return(exitCode);
                        }
                        try
                        {
                            KillApplication(cliParser.GetOptionValue(KillCmd));
                        }
                        catch (ApplicationNotFoundException)
                        {
                            return(exitCode);
                        }
                    }
                    else
                    {
                        if (cliParser.HasOption(MoveToQueueCmd))
                        {
                            if (!cliParser.HasOption(QueueCmd))
                            {
                                PrintUsage(title, opts);
                                return(exitCode);
                            }
                            MoveApplicationAcrossQueues(cliParser.GetOptionValue(MoveToQueueCmd), cliParser.GetOptionValue
                                                            (QueueCmd));
                        }
                        else
                        {
                            if (cliParser.HasOption(HelpCmd))
                            {
                                PrintUsage(title, opts);
                                return(0);
                            }
                            else
                            {
                                syserr.WriteLine("Invalid Command Usage : ");
                                PrintUsage(title, opts);
                            }
                        }
                    }
                }
            }
            return(0);
        }
예제 #5
0
 public static YarnApplicationState ConvertFromProtoFormat(YarnProtos.YarnApplicationStateProto
                                                           e)
 {
     return(YarnApplicationState.ValueOf(e.ToString()));
 }
        private static ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt ConvertToApplicationReport
            (TimelineEntity entity, ApplicationHistoryManagerOnTimelineStore.ApplicationReportField
            field)
        {
            string user         = null;
            string queue        = null;
            string name         = null;
            string type         = null;
            long   createdTime  = 0;
            long   finishedTime = 0;
            ApplicationAttemptId latestApplicationAttemptId = null;
            string diagnosticsInfo = null;
            FinalApplicationStatus         finalStatus              = FinalApplicationStatus.Undefined;
            YarnApplicationState           state                    = null;
            ApplicationResourceUsageReport appResources             = null;
            IDictionary <ApplicationAccessType, string> appViewACLs = new Dictionary <ApplicationAccessType
                                                                                      , string>();
            IDictionary <string, object> entityInfo = entity.GetOtherInfo();

            if (entityInfo != null)
            {
                if (entityInfo.Contains(ApplicationMetricsConstants.UserEntityInfo))
                {
                    user = entityInfo[ApplicationMetricsConstants.UserEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.AppViewAclsEntityInfo))
                {
                    string appViewACLsStr = entityInfo[ApplicationMetricsConstants.AppViewAclsEntityInfo
                                            ].ToString();
                    if (appViewACLsStr.Length > 0)
                    {
                        appViewACLs[ApplicationAccessType.ViewApp] = appViewACLsStr;
                    }
                }
                if (field == ApplicationHistoryManagerOnTimelineStore.ApplicationReportField.UserAndAcls)
                {
                    return(new ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt(ApplicationReport
                                                                                             .NewInstance(ConverterUtils.ToApplicationId(entity.GetEntityId()), latestApplicationAttemptId
                                                                                                          , user, queue, name, null, -1, null, state, diagnosticsInfo, null, createdTime,
                                                                                                          finishedTime, finalStatus, null, null, 1.0F, type, null), appViewACLs));
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.QueueEntityInfo))
                {
                    queue = entityInfo[ApplicationMetricsConstants.QueueEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.NameEntityInfo))
                {
                    name = entityInfo[ApplicationMetricsConstants.NameEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.TypeEntityInfo))
                {
                    type = entityInfo[ApplicationMetricsConstants.TypeEntityInfo].ToString();
                }
                if (entityInfo.Contains(ApplicationMetricsConstants.AppCpuMetrics))
                {
                    long vcoreSeconds = long.Parse(entityInfo[ApplicationMetricsConstants.AppCpuMetrics
                                                   ].ToString());
                    long memorySeconds = long.Parse(entityInfo[ApplicationMetricsConstants.AppMemMetrics
                                                    ].ToString());
                    appResources = ApplicationResourceUsageReport.NewInstance(0, 0, null, null, null,
                                                                              memorySeconds, vcoreSeconds);
                }
            }
            IList <TimelineEvent> events = entity.GetEvents();

            if (events != null)
            {
                foreach (TimelineEvent @event in events)
                {
                    if (@event.GetEventType().Equals(ApplicationMetricsConstants.CreatedEventType))
                    {
                        createdTime = @event.GetTimestamp();
                    }
                    else
                    {
                        if (@event.GetEventType().Equals(ApplicationMetricsConstants.FinishedEventType))
                        {
                            finishedTime = @event.GetTimestamp();
                            IDictionary <string, object> eventInfo = @event.GetEventInfo();
                            if (eventInfo == null)
                            {
                                continue;
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.LatestAppAttemptEventInfo))
                            {
                                latestApplicationAttemptId = ConverterUtils.ToApplicationAttemptId(eventInfo[ApplicationMetricsConstants
                                                                                                             .LatestAppAttemptEventInfo].ToString());
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.DiagnosticsInfoEventInfo))
                            {
                                diagnosticsInfo = eventInfo[ApplicationMetricsConstants.DiagnosticsInfoEventInfo]
                                                  .ToString();
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.FinalStatusEventInfo))
                            {
                                finalStatus = FinalApplicationStatus.ValueOf(eventInfo[ApplicationMetricsConstants
                                                                                       .FinalStatusEventInfo].ToString());
                            }
                            if (eventInfo.Contains(ApplicationMetricsConstants.StateEventInfo))
                            {
                                state = YarnApplicationState.ValueOf(eventInfo[ApplicationMetricsConstants.StateEventInfo
                                                                     ].ToString());
                            }
                        }
                    }
                }
            }
            return(new ApplicationHistoryManagerOnTimelineStore.ApplicationReportExt(ApplicationReport
                                                                                     .NewInstance(ConverterUtils.ToApplicationId(entity.GetEntityId()), latestApplicationAttemptId
                                                                                                  , user, queue, name, null, -1, null, state, diagnosticsInfo, null, createdTime,
                                                                                                  finishedTime, finalStatus, appResources, null, 1.0F, type, null), appViewACLs));
        }
예제 #7
0
        protected override void Render(HtmlBlock.Block html)
        {
            Hamlet.TBODY <Hamlet.TABLE <Org.Apache.Hadoop.Yarn.Webapp.Hamlet.Hamlet> > tbody = html
                                                                                               .Table("#apps").Thead().Tr().Th(".id", "ID").Th(".user", "User").Th(".name", "Name"
                                                                                                                                                                   ).Th(".type", "Application Type").Th(".queue", "Queue").Th(".fairshare", "Fair Share"
                                                                                                                                                                                                                              ).Th(".starttime", "StartTime").Th(".finishtime", "FinishTime").Th(".state", "State"
                                                                                                                                                                                                                                                                                                 ).Th(".finalstatus", "FinalStatus").Th(".progress", "Progress").Th(".ui", "Tracking UI"
                                                                                                                                                                                                                                                                                                                                                                    ).().().Tbody();
            ICollection <YarnApplicationState> reqAppStates = null;
            string reqStateString = $(YarnWebParams.AppState);

            if (reqStateString != null && !reqStateString.IsEmpty())
            {
                string[] appStateStrings = reqStateString.Split(",");
                reqAppStates = new HashSet <YarnApplicationState>(appStateStrings.Length);
                foreach (string stateString in appStateStrings)
                {
                    reqAppStates.AddItem(YarnApplicationState.ValueOf(stateString));
                }
            }
            StringBuilder appsTableData = new StringBuilder("[\n");

            foreach (RMApp app in apps.Values)
            {
                if (reqAppStates != null && !reqAppStates.Contains(app.CreateApplicationState()))
                {
                    continue;
                }
                AppInfo appInfo = new AppInfo(rm, app, true, WebAppUtils.GetHttpSchemePrefix(conf
                                                                                             ));
                string percent = string.Format("%.1f", appInfo.GetProgress());
                ApplicationAttemptId attemptId = app.GetCurrentAppAttempt().GetAppAttemptId();
                int fairShare = fsinfo.GetAppFairShare(attemptId);
                if (fairShare == FairSchedulerInfo.InvalidFairShare)
                {
                    // FairScheduler#applications don't have the entry. Skip it.
                    continue;
                }
                appsTableData.Append("[\"<a href='").Append(Url("app", appInfo.GetAppId())).Append
                    ("'>").Append(appInfo.GetAppId()).Append("</a>\",\"").Append(StringEscapeUtils.EscapeJavaScript
                                                                                     (StringEscapeUtils.EscapeHtml(appInfo.GetUser()))).Append("\",\"").Append(StringEscapeUtils
                                                                                                                                                               .EscapeJavaScript(StringEscapeUtils.EscapeHtml(appInfo.GetName()))).Append("\",\""
                                                                                                                                                                                                                                          ).Append(StringEscapeUtils.EscapeJavaScript(StringEscapeUtils.EscapeHtml(appInfo
                                                                                                                                                                                                                                                                                                                   .GetApplicationType()))).Append("\",\"").Append(StringEscapeUtils.EscapeJavaScript
                                                                                                                                                                                                                                                                                                                                                                       (StringEscapeUtils.EscapeHtml(appInfo.GetQueue()))).Append("\",\"").Append(fairShare
                                                                                                                                                                                                                                                                                                                                                                                                                                                  ).Append("\",\"").Append(appInfo.GetStartTime()).Append("\",\"").Append(appInfo.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          GetFinishTime()).Append("\",\"").Append(appInfo.GetState()).Append("\",\"").Append
                    (appInfo.GetFinalStatus()).Append("\",\"").Append("<br title='").Append(percent)
                .Append("'> <div class='").Append(JQueryUI.CProgressbar).Append("' title='").Append
                    (StringHelper.Join(percent, '%')).Append("'> ").Append("<div class='").Append(JQueryUI
                                                                                                  .CProgressbarValue).Append("' style='").Append(StringHelper.Join("width:", percent
                                                                                                                                                                   , '%')).Append("'> </div> </div>").Append("\",\"<a href='");
                // Progress bar
                string trackingURL = !appInfo.IsTrackingUrlReady() ? "#" : appInfo.GetTrackingUrlPretty
                                         ();
                appsTableData.Append(trackingURL).Append("'>").Append(appInfo.GetTrackingUI()).Append
                    ("</a>\"],\n");
            }
            if (appsTableData[appsTableData.Length - 2] == ',')
            {
                appsTableData.Delete(appsTableData.Length - 2, appsTableData.Length - 1);
            }
            appsTableData.Append("]");
            html.Script().$type("text/javascript").("var appsTableData=" + appsTableData).();
            tbody.().();
        }