/// <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)); } }
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); }