/// <summary> /// Aggregate Data and return UnitInfo List /// </summary> public DataAggregatorResult AggregateData(FahLog fahLog, QueueData queueData, UnitInfoLogData unitInfo) { if (Logger.IsDebugEnabled) { foreach (var s in fahLog.Where(x => x.LineType == LogLineType.Error)) { Logger.DebugFormat(Constants.ClientNameFormat, ClientName, String.Format("Failed to parse log line: {0}", s)); } } var currentClientRun = GetCurrentClientRun(fahLog); if (currentClientRun == null) { return null; } var result = new DataAggregatorResult(); result.StartTime = currentClientRun.Data.StartTime; result.Arguments = currentClientRun.Data.Arguments; result.ClientVersion = currentClientRun.Data.ClientVersion; result.UserID = currentClientRun.Data.UserID; result.MachineID = currentClientRun.Data.MachineID; result.Status = currentClientRun.SlotRuns[0].Data.Status; // Decision Time: If Queue Read fails parse from logs only if (queueData != null) { GenerateUnitInfoDataFromQueue(result, queueData, fahLog, unitInfo); result.Queue = BuildClientQueue(queueData); result.CurrentUnitIndex = result.Queue.CurrentIndex; } else { Logger.WarnFormat(Constants.ClientNameFormat, ClientName, "Queue unavailable or failed read. Parsing logs without queue."); GenerateUnitInfoDataFromLogs(result, fahLog, unitInfo); // default Unit Index if only parsing logs result.CurrentUnitIndex = 1; } if (result.UnitInfos == null || result.UnitInfos[result.CurrentUnitIndex] == null || result.UnitInfos[result.CurrentUnitIndex].LogLines == null) { result.CurrentLogLines = currentClientRun.ToList(); } else { result.CurrentLogLines = result.UnitInfos[result.CurrentUnitIndex].LogLines; } return result; }
/// <summary> /// Aggregate Data and return UnitInfo Dictionary. /// </summary> public DataAggregatorResult AggregateData(ClientRun clientRun, UnitCollection unitCollection, Info info, Options options, SlotOptions slotOptions, UnitInfo currentUnitInfo, int slotId) { if (clientRun == null) throw new ArgumentNullException("clientRun"); if (unitCollection == null) throw new ArgumentNullException("unitCollection"); if (options == null) throw new ArgumentNullException("options"); if (slotOptions == null) throw new ArgumentNullException("slotOptions"); if (currentUnitInfo == null) throw new ArgumentNullException("currentUnitInfo"); var result = new DataAggregatorResult(); result.CurrentUnitIndex = -1; SlotRun slotRun = null; if (clientRun.SlotRuns.ContainsKey(slotId)) { slotRun = clientRun.SlotRuns[slotId]; } result.StartTime = clientRun.Data.StartTime; result.Arguments = clientRun.Data.Arguments; result.ClientVersion = clientRun.Data.ClientVersion; result.UserID = clientRun.Data.UserID; result.MachineID = clientRun.Data.MachineID; result.Status = slotRun != null ? slotRun.Data.Status : SlotStatus.Unknown; if (Logger.IsDebugEnabled) { foreach (var s in clientRun.Where(x => x.LineType == LogLineType.Error)) { Logger.DebugFormat(Constants.ClientNameFormat, ClientName, String.Format("Failed to parse log line: {0}", s)); } } GenerateUnitInfoDataFromQueue(result, slotRun, unitCollection, options, slotOptions, currentUnitInfo, slotId); result.Queue = BuildClientQueue(unitCollection, info, slotOptions, slotId); if (result.UnitInfos.ContainsKey(result.CurrentUnitIndex) && result.UnitInfos[result.CurrentUnitIndex].LogLines != null) { result.CurrentLogLines = result.UnitInfos[result.CurrentUnitIndex].LogLines; } else if (slotRun != null) { result.CurrentLogLines = slotRun.ToList(); } else { result.CurrentLogLines = clientRun.ToList(); } return result; }
private void GenerateUnitInfoDataFromQueue(DataAggregatorResult result, QueueData q, FahLog fahLog, UnitInfoLogData unitInfo) { Debug.Assert(q != null); result.UnitInfos = new Dictionary<int, UnitInfo>(10); for (int i = 0; i < 10; i++) { result.UnitInfos[i] = null; } var clientRun = GetCurrentClientRun(fahLog); for (int queueIndex = 0; queueIndex < result.UnitInfos.Count; queueIndex++) { var unitRun = GetUnitRunForQueueIndex(fahLog, queueIndex); UnitInfoLogData unitInfoLogData = null; // On the Current Queue Index if (queueIndex == q.CurrentIndex) { // Get the UnitInfo Log Data unitInfoLogData = unitInfo; } var queueEntry = q.GetQueueEntry((uint)queueIndex); result.UnitInfos[queueIndex] = BuildUnitInfo(queueEntry, clientRun, unitRun, unitInfoLogData); if (result.UnitInfos[queueIndex] == null) { if (queueIndex == q.CurrentIndex) { string message = String.Format(CultureInfo.CurrentCulture, "Could not verify log section for current queue index {0} {1}.", queueIndex, queueEntry.ToProjectInfo()); Logger.WarnFormat(Constants.ClientNameFormat, ClientName, message); unitRun = GetCurrentUnitRun(fahLog); var slotRun = GetCurrentSlotRun(fahLog); if (slotRun != null && slotRun.Data.Status == SlotStatus.GettingWorkPacket) { unitRun = null; unitInfoLogData = new UnitInfoLogData(); } result.UnitInfos[queueIndex] = BuildUnitInfo(queueEntry, clientRun, unitRun, unitInfoLogData, true); } else if (Logger.IsDebugEnabled) { // Write debug info and skip this unit var projectInfo = queueEntry.ToProjectInfo(); if (!projectInfo.ProjectIsUnknown()) { string message = String.Format(CultureInfo.CurrentCulture, "Could not find log section for queue index {0} {1}.", queueIndex, queueEntry.ToProjectInfo()); Logger.DebugFormat(Constants.ClientNameFormat, ClientName, message); } } } } }
private void GenerateUnitInfoDataFromLogs(DataAggregatorResult result, FahLog fahLog, UnitInfoLogData unitInfo) { result.UnitInfos = new Dictionary<int, UnitInfo>(2); for (int i = 0; i < 2; i++) { result.UnitInfos[i] = null; } var currentClientRun = GetCurrentClientRun(fahLog); var previousUnitRun = GetPreviousUnitRun(fahLog); if (previousUnitRun != null) { result.UnitInfos[0] = BuildUnitInfo(null, currentClientRun, previousUnitRun, null); } var currentUnitRun = GetCurrentUnitRun(fahLog); result.UnitInfos[1] = BuildUnitInfo(null, currentClientRun, currentUnitRun, unitInfo, currentUnitRun == null); }
private void GenerateUnitInfoDataFromQueue(DataAggregatorResult result, SlotRun slotRun, ICollection<Unit> unitCollection, Options options, SlotOptions slotOptions, UnitInfo currentUnitInfo, int slotId) { Debug.Assert(unitCollection != null); Debug.Assert(options != null); Debug.Assert(slotOptions != null); Debug.Assert(currentUnitInfo != null); result.UnitInfos = new Dictionary<int, UnitInfo>(); bool foundCurrentUnitInfo = false; foreach (var unit in unitCollection.Where(x => x.Slot == slotId)) { var projectInfo = unit.ToProjectInfo(); if (projectInfo.EqualsProject(currentUnitInfo) && unit.AssignedDateTime.GetValueOrDefault().Equals(currentUnitInfo.DownloadTime)) { foundCurrentUnitInfo = true; } // Get the Log Lines for this queue position from the reader var unitRun = GetUnitRun(slotRun, unit.Id, projectInfo); if (unitRun == null) { string message = String.Format(CultureInfo.CurrentCulture, "Could not find log section for Slot {0} {1}. Cannot update log data for this unit.", slotId, projectInfo); Logger.WarnFormat(Constants.ClientNameFormat, ClientName, message); } UnitInfo unitInfo = BuildUnitInfo(unit, options, slotOptions, unitRun); if (unitInfo != null) { result.UnitInfos.Add(unit.Id, unitInfo); if (unit.StateEnum == FahUnitStatus.Running) { result.CurrentUnitIndex = unit.Id; } } } // if no running WU found if (result.CurrentUnitIndex == -1) { // look for a WU with Ready state var unit = unitCollection.FirstOrDefault(x => x.Slot == slotId && x.StateEnum == FahUnitStatus.Ready); if (unit != null) { result.CurrentUnitIndex = unit.Id; } } // if the current unit has already left the UnitCollection then find the log section and update here if (!foundCurrentUnitInfo) { // Get the Log Lines for this queue position from the reader var unitRun = GetUnitRun(slotRun, currentUnitInfo.QueueIndex, currentUnitInfo); if (unitRun != null) { // create a clone of the current UnitInfo object so we're not working with an // instance that is referenced by a SlotModel that is bound to the grid - Issue 277 UnitInfo currentClone = currentUnitInfo.DeepClone(); UpdateUnitInfoFromLogData(currentClone, unitRun); result.UnitInfos.Add(currentClone.QueueIndex, currentClone); } } }