示例#1
0
        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);
                        }
                    }
                }
            }
        }
示例#2
0
        /// <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            = BuildQueueDictionary(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);
        }
示例#3
0
        private void PopulateRunLevelData(DataAggregatorResult result, SlotModel slotModel)
        {
            slotModel.Arguments     = result.Arguments;
            slotModel.ClientVersion = result.ClientVersion;

            slotModel.UserId    = result.UserID;
            slotModel.MachineId = result.MachineID;

            //slotModel.TotalRunCompletedUnits = run.CompletedUnits;
            //slotModel.TotalRunFailedUnits = run.FailedUnits;
            //slotModel.TotalCompletedUnits = run.TotalCompletedUnits;
            if (UnitInfoDatabase.Connected)
            {
                slotModel.TotalRunCompletedUnits = (int)UnitInfoDatabase.Count(slotModel.Name, CountType.Completed, result.StartTime);
                slotModel.TotalCompletedUnits    = (int)UnitInfoDatabase.Count(slotModel.Name, CountType.Completed);
                slotModel.TotalRunFailedUnits    = (int)UnitInfoDatabase.Count(slotModel.Name, CountType.Failed, result.StartTime);
                slotModel.TotalFailedUnits       = (int)UnitInfoDatabase.Count(slotModel.Name, CountType.Failed);
            }
        }
示例#4
0
        private static 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 PopulateRunLevelData(DataAggregatorResult result, Info info, SlotModel slotModel)
        {
            Debug.Assert(slotModel != null);

            if (info != null)
            {
                slotModel.ClientVersion = info.Build.Version;
            }
            //if (run != null)
            //{
            //   slotModel.TotalRunCompletedUnits = run.CompletedUnits;
            //   slotModel.TotalRunFailedUnits = run.FailedUnits;
            //}
            if (UnitInfoDatabase.Connected)
            {
                slotModel.TotalRunCompletedUnits = (int)UnitInfoDatabase.CountCompleted(slotModel.Name, result.StartTime);
                slotModel.TotalCompletedUnits    = (int)UnitInfoDatabase.CountCompleted(slotModel.Name, null);
                slotModel.TotalRunFailedUnits    = (int)UnitInfoDatabase.CountFailed(slotModel.Name, result.StartTime);
                slotModel.TotalFailedUnits       = (int)UnitInfoDatabase.CountFailed(slotModel.Name, null);
            }
        }
示例#6
0
        /// <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(nameof(clientRun));
            }
            if (unitCollection == null)
            {
                throw new ArgumentNullException(nameof(unitCollection));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (slotOptions == null)
            {
                throw new ArgumentNullException(nameof(slotOptions));
            }
            if (currentUnitInfo == null)
            {
                throw new ArgumentNullException(nameof(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;

            if (Logger.IsDebugEnabled)
            {
                foreach (var s in LogLineEnumerable.Create(clientRun).Where(x => x.Data is LogLineDataParserError))
                {
                    Logger.DebugFormat(Constants.ClientNameFormat, ClientName, String.Format("Failed to parse log line: {0}", s));
                }
            }

            GenerateUnitInfoDataFromQueue(result, slotRun, unitCollection, options, slotOptions, currentUnitInfo, slotId);
            result.Queue = BuildQueueDictionary(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 = LogLineEnumerable.Create(slotRun).ToList();
            }
            else
            {
                result.CurrentLogLines = LogLineEnumerable.Create(clientRun).ToList();
            }

            return(result);
        }
示例#7
0
        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 == UnitState.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 == UnitState.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);
                }
            }
        }
        /// <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 = BuildQueueDictionary(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 Process()
        {
            var sw = Stopwatch.StartNew();

            // Set successful Last Retrieval Time
            LastRetrievalTime = DateTime.Now;

            var options = _messages.Options;
            var info    = _messages.Info;

            _slotsLock.EnterReadLock();
            try
            {
                foreach (var slotModel in _slots)
                {
                    // Re-Init Slot Level Members Before Processing
                    slotModel.Initialize();

                    // Run the Aggregator
                    var dataAggregator = new FahClientDataAggregator {
                        Logger = Logger
                    };
                    dataAggregator.ClientName = slotModel.Name;
                    DataAggregatorResult result = dataAggregator.AggregateData(_fahLog.ClientRuns.LastOrDefault(),
                                                                               _messages.UnitCollection,
                                                                               info,
                                                                               options,
                                                                               slotModel.SlotOptions,
                                                                               slotModel.UnitInfo,
                                                                               slotModel.SlotId);
                    PopulateRunLevelData(result, info, slotModel);

                    slotModel.Queue           = result.Queue;
                    slotModel.CurrentLogLines = result.CurrentLogLines;
                    //slotModel.UnitLogLines = result.UnitLogLines;

                    var parsedUnits = new Dictionary <int, UnitInfoModel>(result.UnitInfos.Count);
                    foreach (int key in result.UnitInfos.Keys)
                    {
                        if (result.UnitInfos[key] != null)
                        {
                            parsedUnits[key] = BuildUnitInfoLogic(slotModel, result.UnitInfos[key]);
                        }
                    }

                    // *** THIS HAS TO BE DONE BEFORE UPDATING SlotModel.UnitInfoLogic ***
                    UpdateBenchmarkData(slotModel.UnitInfoModel, parsedUnits.Values, result.CurrentUnitIndex);

                    // Update the UnitInfoLogic if we have a current unit index
                    if (result.CurrentUnitIndex != -1 && parsedUnits.ContainsKey(result.CurrentUnitIndex))
                    {
                        slotModel.UnitInfoModel = parsedUnits[result.CurrentUnitIndex];
                    }

                    SetSlotStatus(slotModel);

                    slotModel.UnitInfoModel.ShowProductionTrace(Logger, slotModel.Name, slotModel.Status,
                                                                Prefs.Get <PpdCalculationType>(Preference.PpdCalculation),
                                                                Prefs.Get <BonusCalculationType>(Preference.BonusCalculation));

                    string statusMessage = String.Format(CultureInfo.CurrentCulture, "Slot Status: {0}", slotModel.Status);
                    Logger.InfoFormat(Constants.ClientNameFormat, slotModel.Name, statusMessage);
                }
            }
            finally
            {
                _slotsLock.ExitReadLock();
            }

            string message = String.Format(CultureInfo.CurrentCulture, "Retrieval finished: {0}", sw.GetExecTime());

            Logger.InfoFormat(Constants.ClientNameFormat, Settings.Name, message);
        }