Example #1
0
        public static void Run([QueueTrigger("aggregation")] string guidAndTaskID, TraceWriter log)
        {
            bool logging = false;

            string[] fields = guidAndTaskID.Split('_');
            string   guid   = fields[0];
            int      taskID = Convert.ToInt32(fields[1]);

            SatyamResultsTableAccess       resultsDB        = new SatyamResultsTableAccess();
            List <SatyamResultsTableEntry> collectedResults = resultsDB.getEntriesByGUIDAndTaskID(guid, taskID);

            resultsDB.close();

            if (collectedResults.Count == 0)
            {
                return;
            }

            if (logging)
            {
                log.Info($"Task Type: {collectedResults[0].JobTemplateType}({guid}), Task ID: {taskID}, # of Results: {collectedResults.Count}");
            }

            //SatyamAggregatedResultsTableAccess aggDB = new SatyamAggregatedResultsTableAccess();
            //int LatestResultsAggregated = aggDB.getLatestNoResultsAggregatedByTaskID(taskID);
            //aggDB.close();

            //if (collectedResults.Count != LatestResultsAggregated)
            //{
            SatyamAggregatedResultsTableEntry aggEntry = ResultsTableAggregator.GetAggregatedResultString(taskID, collectedResults);

            if (aggEntry != null)
            {
                //aggEntries.Add(aggEntry);
                SatyamAggregatedResultsTableAccess aggDB = new SatyamAggregatedResultsTableAccess();
                aggDB.AddEntry(aggEntry, collectedResults.Count);
                aggDB.close();
                if (logging)
                {
                    log.Info($"Aggregated");
                }
            }
            //}
        }
Example #2
0
        //go through all the inconclusive results and aggregate them if they are not aggregated already
        public static void AggregateResults()
        {
            //first get all the results that are not aggregated
            SatyamResultsTableAccess       resultsDB = new SatyamResultsTableAccess();
            List <SatyamResultsTableEntry> results   = resultsDB.getEntriesByStatus(ResultStatus.inconclusive);

            if (results.Count == 0) //there is nothing to do
            {
                resultsDB.close();
                return;
            }

            //first group all the results by the tasks since wach task may have multiple entries
            Dictionary <int, List <SatyamResultsTableEntry> > collectedResults = new Dictionary <int, List <SatyamResultsTableEntry> >();
            List <string> pendingGUID = new List <string>();

            foreach (SatyamResultsTableEntry entry in results)
            {
                int taskID = entry.SatyamTaskTableEntryID;
                if (!collectedResults.ContainsKey(taskID))
                {
                    collectedResults.Add(taskID, new List <SatyamResultsTableEntry>());
                }
                collectedResults[taskID].Add(entry);

                if (!pendingGUID.Contains(entry.JobGUID))
                {
                    pendingGUID.Add(entry.JobGUID);
                }
            }
            List <int> taskIDList = collectedResults.Keys.ToList();

            taskIDList.Sort();
            //check if guid is still pending
            SatyamJobSubmissionsTableAccess jobDB = new SatyamJobSubmissionsTableAccess();
            List <string> completedGUIDs          = jobDB.getAllJobGUIDSByStatus(JobStatus.completed);

            jobDB.close();

            //check if this taskID has already been aggregated and exists int he aggregationDB
            Dictionary <string, Dictionary <int, SatyamAggregatedResultsTableEntry> > ExistingAggEntriesPerTaskPerGUID = SatyamAggregatedResultManagement.getAggregatedEntriesPerTaskByGuidList(pendingGUID);

            Console.WriteLine("Aggregating {0} Tasks", taskIDList.Count);
            List <SatyamAggregatedResultsTableEntry> aggEntries = new List <SatyamAggregatedResultsTableEntry>();

            //foreach (int taskId in taskIDList)
            for (int i = 0; i < taskIDList.Count; i++)
            {
                //int taskId = taskIDList[taskIDList.Count - i - 1];
                int    taskId = taskIDList[i];
                string guid   = collectedResults[taskId][0].JobGUID;
                if (completedGUIDs.Contains(guid))
                {
                    // Hit Completed, mark results outdated.
                    resultsDB.UpdateStatusByTaskID(taskId, ResultStatus.outdated);
                    continue;
                }

                //SatyamAggregatedResultsTableAccess aggDB = new SatyamAggregatedResultsTableAccess();
                //int LatestResultsAggregated = aggDB.getLatestNoResultsAggregatedByTaskID(taskId);
                //aggDB.close();

                if (ExistingAggEntriesPerTaskPerGUID.ContainsKey(guid) && ExistingAggEntriesPerTaskPerGUID[guid].ContainsKey(taskId))
                {
                    continue;
                    //int MinResults = TaskConstants.getMinResultsByTemplate(ExistingAggEntriesPerTaskPerGUID[guid][taskId].JobTemplateType);
                    //if (LatestResultsAggregated >= MinResults)
                    //{
                    //    continue;
                    //}
                    // already aggregated to MinResult Request, but leftover results will be judged. So do nothing
                }

                //if it does not exist only then aggregate
                Console.WriteLine("Task Type: {2}({3}), Task ID: {0}, # of Results: {1}", taskId, collectedResults[taskId].Count, collectedResults[taskId][0].JobTemplateType, collectedResults[taskId][0].JobGUID);


                //if (collectedResults[taskId].Count != LatestResultsAggregated)
                //{
                SatyamAggregatedResultsTableEntry aggEntry = ResultsTableAggregator.GetAggregatedResultString(taskId, collectedResults[taskId]);
                if (aggEntry != null)
                {
                    //aggEntries.Add(aggEntry);
                    SatyamAggregatedResultsTableAccess aggDB = new SatyamAggregatedResultsTableAccess();
                    aggDB.AddEntry(aggEntry, collectedResults[taskId].Count);
                    aggDB.close();
                }
                //}
                //else
                //{
                //    Console.WriteLine("No New Results");
                //}
            }


            resultsDB.close();
        }