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)); }
public static FinalApplicationStatus ConvertFromProtoFormat(YarnProtos.FinalApplicationStatusProto e) { return(FinalApplicationStatus.ValueOf(e.ToString().Replace(FinalApplicationStatusPrefix , string.Empty))); }
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); }