public virtual AppsInfo GetNodeApps(string stateQuery, string userQuery) { Init(); AppsInfo allApps = new AppsInfo(); foreach (KeyValuePair <ApplicationId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application > entry in this.nmContext.GetApplications()) { AppInfo appInfo = new AppInfo(entry.Value); if (stateQuery != null && !stateQuery.IsEmpty()) { ApplicationState.ValueOf(stateQuery); if (!Sharpen.Runtime.EqualsIgnoreCase(appInfo.GetState(), stateQuery)) { continue; } } if (userQuery != null) { if (userQuery.IsEmpty()) { string msg = "Error: You must specify a non-empty string for the user"; throw new BadRequestException(msg); } if (!appInfo.GetUser().ToString().Equals(userQuery)) { continue; } } allApps.Add(appInfo); } return(allApps); }
public virtual void TestAppsRace() { // mock up an RM that returns app reports for apps that don't exist // in the RMApps list ApplicationId appId = ApplicationId.NewInstance(1, 1); ApplicationReport mockReport = Org.Mockito.Mockito.Mock <ApplicationReport>(); Org.Mockito.Mockito.When(mockReport.GetApplicationId()).ThenReturn(appId); GetApplicationsResponse mockAppsResponse = Org.Mockito.Mockito.Mock <GetApplicationsResponse >(); Org.Mockito.Mockito.When(mockAppsResponse.GetApplicationList()).ThenReturn(Arrays .AsList(new ApplicationReport[] { mockReport })); ClientRMService mockClientSvc = Org.Mockito.Mockito.Mock <ClientRMService>(); Org.Mockito.Mockito.When(mockClientSvc.GetApplications(Matchers.IsA <GetApplicationsRequest >(), Matchers.AnyBoolean())).ThenReturn(mockAppsResponse); ResourceManager mockRM = Org.Mockito.Mockito.Mock <ResourceManager>(); RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, null, null , null, null, null); Org.Mockito.Mockito.When(mockRM.GetRMContext()).ThenReturn(rmContext); Org.Mockito.Mockito.When(mockRM.GetClientRMService()).ThenReturn(mockClientSvc); RMWebServices webSvc = new RMWebServices(mockRM, new Configuration(), Org.Mockito.Mockito.Mock <HttpServletResponse>()); ICollection <string> emptySet = Collections.UnmodifiableSet(Collections.EmptySet <string >()); // verify we don't get any apps when querying HttpServletRequest mockHsr = Org.Mockito.Mockito.Mock <HttpServletRequest>(); AppsInfo appsInfo = webSvc.GetApps(mockHsr, null, emptySet, null, null, null, null , null, null, null, null, emptySet, emptySet); NUnit.Framework.Assert.IsTrue(appsInfo.GetApps().IsEmpty()); // verify we don't get an NPE when specifying a final status query appsInfo = webSvc.GetApps(mockHsr, null, emptySet, "FAILED", null, null, null, null , null, null, null, emptySet, emptySet); NUnit.Framework.Assert.IsTrue(appsInfo.GetApps().IsEmpty()); }
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); }