public override async Task <Experiment> TryFindExperiment(int id)
        {
            try
            {
                var e = await storage.GetExperiment(id);

                return(ExperimentFromEntity(id, e));
            }
            catch (ArgumentException)
            {
                return(null);
            }
        }
Example #2
0
        public async Task <ExperimentSummary[]> Update(string timelineName, params int[] experiments)
        {
            if (experiments == null)
            {
                throw new ArgumentNullException(nameof(experiments));
            }

            Trace.WriteLine("Downloading experiment results...");
            var all_summaries = await DownloadSummary(timelineName);

            Table        timeline = all_summaries.Item1;
            RecordsTable records  = all_summaries.Item2;
            string       etag     = all_summaries.Item3;

            foreach (var experimentId in experiments)
            {
                var exp = await storage.GetExperiment(experimentId); // fails if not found

                var domain = resolveDomain.GetDomain(exp.DomainName);

                var results = (await storage.GetResults(experimentId)).Benchmarks;

                Trace.WriteLine("Building summary for the experiment " + experimentId);
                var catSummary = ExperimentSummary.Build(results, domain, ExperimentSummary.DuplicateResolution.Ignore);
                var expSummary = new ExperimentSummary(experimentId, DateTimeOffset.Now, catSummary);
                timeline = ExperimentSummaryStorage.AppendOrReplace(timeline, expSummary);

                Trace.WriteLine("Updating records...");
                records.UpdateWith(results, domain);
            }

            await UploadSummary(timelineName, timeline, records, all_summaries.Item3);

            var resultfromTable = ExperimentSummaryStorage.LoadFromTable(timeline);

            Array.Sort(resultfromTable, (el1, el2) => DateTimeOffset.Compare(el2.Date, el1.Date));
            return(resultfromTable);
        }
        public override async Task <bool> TryDelete(IEnumerable <BenchmarkResult> toRemove)
        {
            if (toRemove == null)
            {
                throw new ArgumentNullException(nameof(toRemove));
            }

            var benchmarks = Benchmarks;
            var removeSet  = new HashSet <BenchmarkResult>(toRemove);

            if (removeSet.Count == 0)
            {
                return(true);
            }

            int n = benchmarks.Length;
            List <AzureBenchmarkResult> newAzureResults = new List <AzureBenchmarkResult>(n);
            List <BenchmarkResult>      newResults      = new List <BenchmarkResult>(n);
            List <AzureBenchmarkResult> deleteOuts      = new List <AzureBenchmarkResult>();

            for (int i = 0; i < n; i++)
            {
                var b = benchmarks[i];
                if (!removeSet.Contains(b)) // remains
                {
                    var azureResult = ToAzureResult(b, TryGetExternalOutput(b));
                    newAzureResults.Add(azureResult);
                    newResults.Add(b);
                }
                else // to be removed
                {
                    removeSet.Remove(b);

                    AzureBenchmarkResult ar;
                    if (externalOutputs.TryGetValue(b, out ar))
                    {
                        deleteOuts.Add(ar);
                    }
                }
            }
            if (removeSet.Count != 0)
            {
                throw new ArgumentException("Some of the given results to remove do not belong to the experiment results");
            }

            // Updating blob with results table
            string newEtag = await Upload(newAzureResults.ToArray());

            if (newEtag == null)
            {
                return(false);
            }
            etag = newEtag;

            // Update benchmarks array
            Replace(newResults.ToArray());
            (await storage.GetExperiment(ExperimentId)).CompletedBenchmarks = Benchmarks.Count();

            // Deleting blobs with output
            foreach (var ar in deleteOuts)
            {
                try
                {
                    var _ = storage.DeleteOutputs(ar);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(string.Format("Exception when deleting output: {0}", ex));
                }
            }

            return(true);
        }