Esempio n. 1
0
        public virtual void TestGetApplicationsRequest()
        {
            GetApplicationsRequest         request   = GetApplicationsRequest.NewInstance();
            EnumSet <YarnApplicationState> appStates = EnumSet.Of(YarnApplicationState.Accepted
                                                                  );

            request.SetApplicationStates(appStates);
            ICollection <string> tags = new HashSet <string>();

            tags.AddItem("tag1");
            request.SetApplicationTags(tags);
            ICollection <string> types = new HashSet <string>();

            types.AddItem("type1");
            request.SetApplicationTypes(types);
            long startBegin = Runtime.CurrentTimeMillis();
            long startEnd   = Runtime.CurrentTimeMillis() + 1;

            request.SetStartRange(startBegin, startEnd);
            long finishBegin = Runtime.CurrentTimeMillis() + 2;
            long finishEnd   = Runtime.CurrentTimeMillis() + 3;

            request.SetFinishRange(finishBegin, finishEnd);
            long limit = 100L;

            request.SetLimit(limit);
            ICollection <string> queues = new HashSet <string>();

            queues.AddItem("queue1");
            request.SetQueues(queues);
            ICollection <string> users = new HashSet <string>();

            users.AddItem("user1");
            request.SetUsers(users);
            ApplicationsRequestScope scope = ApplicationsRequestScope.All;

            request.SetScope(scope);
            GetApplicationsRequest requestFromProto = new GetApplicationsRequestPBImpl(((GetApplicationsRequestPBImpl
                                                                                         )request).GetProto());

            // verify the whole record equals with original record
            NUnit.Framework.Assert.AreEqual(requestFromProto, request);
            // verify all properties are the same as original request
            NUnit.Framework.Assert.AreEqual("ApplicationStates from proto is not the same with original request"
                                            , requestFromProto.GetApplicationStates(), appStates);
            NUnit.Framework.Assert.AreEqual("ApplicationTags from proto is not the same with original request"
                                            , requestFromProto.GetApplicationTags(), tags);
            NUnit.Framework.Assert.AreEqual("ApplicationTypes from proto is not the same with original request"
                                            , requestFromProto.GetApplicationTypes(), types);
            NUnit.Framework.Assert.AreEqual("StartRange from proto is not the same with original request"
                                            , requestFromProto.GetStartRange(), new LongRange(startBegin, startEnd));
            NUnit.Framework.Assert.AreEqual("FinishRange from proto is not the same with original request"
                                            , requestFromProto.GetFinishRange(), new LongRange(finishBegin, finishEnd));
            NUnit.Framework.Assert.AreEqual("Limit from proto is not the same with original request"
                                            , requestFromProto.GetLimit(), limit);
            NUnit.Framework.Assert.AreEqual("Queues from proto is not the same with original request"
                                            , requestFromProto.GetQueues(), queues);
            NUnit.Framework.Assert.AreEqual("Users from proto is not the same with original request"
                                            , requestFromProto.GetUsers(), users);
        }
Esempio n. 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));
            }
        }
Esempio n. 3
0
        public virtual AppsInfo GetApps(HttpServletRequest req, HttpServletResponse res,
                                        string stateQuery, ICollection <string> statesQuery, string finalStatusQuery, string
                                        userQuery, string queueQuery, string count, string startedBegin, string startedEnd
                                        , string finishBegin, string finishEnd, ICollection <string> applicationTypes)
        {
            UserGroupInformation callerUGI = GetUser(req);
            bool checkStart     = false;
            bool checkEnd       = false;
            bool checkAppTypes  = false;
            bool checkAppStates = false;
            long countNum       = long.MaxValue;
            // set values suitable in case both of begin/end not specified
            long sBegin = 0;
            long sEnd   = long.MaxValue;
            long fBegin = 0;
            long fEnd   = long.MaxValue;

            if (count != null && !count.IsEmpty())
            {
                countNum = long.Parse(count);
                if (countNum <= 0)
                {
                    throw new BadRequestException("limit value must be greater then 0");
                }
            }
            if (startedBegin != null && !startedBegin.IsEmpty())
            {
                checkStart = true;
                sBegin     = long.Parse(startedBegin);
                if (sBegin < 0)
                {
                    throw new BadRequestException("startedTimeBegin must be greater than 0");
                }
            }
            if (startedEnd != null && !startedEnd.IsEmpty())
            {
                checkStart = true;
                sEnd       = long.Parse(startedEnd);
                if (sEnd < 0)
                {
                    throw new BadRequestException("startedTimeEnd must be greater than 0");
                }
            }
            if (sBegin > sEnd)
            {
                throw new BadRequestException("startedTimeEnd must be greater than startTimeBegin"
                                              );
            }
            if (finishBegin != null && !finishBegin.IsEmpty())
            {
                checkEnd = true;
                fBegin   = long.Parse(finishBegin);
                if (fBegin < 0)
                {
                    throw new BadRequestException("finishTimeBegin must be greater than 0");
                }
            }
            if (finishEnd != null && !finishEnd.IsEmpty())
            {
                checkEnd = true;
                fEnd     = long.Parse(finishEnd);
                if (fEnd < 0)
                {
                    throw new BadRequestException("finishTimeEnd must be greater than 0");
                }
            }
            if (fBegin > fEnd)
            {
                throw new BadRequestException("finishTimeEnd must be greater than finishTimeBegin"
                                              );
            }
            ICollection <string> appTypes = ParseQueries(applicationTypes, false);

            if (!appTypes.IsEmpty())
            {
                checkAppTypes = true;
            }
            // stateQuery is deprecated.
            if (stateQuery != null && !stateQuery.IsEmpty())
            {
                statesQuery.AddItem(stateQuery);
            }
            ICollection <string> appStates = ParseQueries(statesQuery, true);

            if (!appStates.IsEmpty())
            {
                checkAppStates = true;
            }
            AppsInfo allApps = new AppsInfo();
            ICollection <ApplicationReport> appReports = null;
            GetApplicationsRequest          request    = GetApplicationsRequest.NewInstance();

            request.SetLimit(countNum);
            try
            {
                if (callerUGI == null)
                {
                    // TODO: the request should take the params like what RMWebServices does
                    // in YARN-1819.
                    appReports = appBaseProt.GetApplications(request).GetApplicationList();
                }
                else
                {
                    appReports = callerUGI.DoAs(new _PrivilegedExceptionAction_161(this, request));
                }
            }
            catch (Exception e)
            {
                RewrapAndThrowException(e);
            }
            foreach (ApplicationReport appReport in appReports)
            {
                if (checkAppStates && !appStates.Contains(StringUtils.ToLowerCase(appReport.GetYarnApplicationState
                                                                                      ().ToString())))
                {
                    continue;
                }
                if (finalStatusQuery != null && !finalStatusQuery.IsEmpty())
                {
                    FinalApplicationStatus.ValueOf(finalStatusQuery);
                    if (!Sharpen.Runtime.EqualsIgnoreCase(appReport.GetFinalApplicationStatus().ToString
                                                              (), finalStatusQuery))
                    {
                        continue;
                    }
                }
                if (userQuery != null && !userQuery.IsEmpty())
                {
                    if (!appReport.GetUser().Equals(userQuery))
                    {
                        continue;
                    }
                }
                if (queueQuery != null && !queueQuery.IsEmpty())
                {
                    if (!appReport.GetQueue().Equals(queueQuery))
                    {
                        continue;
                    }
                }
                if (checkAppTypes && !appTypes.Contains(StringUtils.ToLowerCase(appReport.GetApplicationType
                                                                                    ().Trim())))
                {
                    continue;
                }
                if (checkStart && (appReport.GetStartTime() < sBegin || appReport.GetStartTime()
                                   > sEnd))
                {
                    continue;
                }
                if (checkEnd && (appReport.GetFinishTime() < fBegin || appReport.GetFinishTime()
                                 > fEnd))
                {
                    continue;
                }
                AppInfo app = new AppInfo(appReport);
                allApps.Add(app);
            }
            return(allApps);
        }