Exemple #1
0
        /// <summary>
        /// Adds new entry to the experiments table
        /// </summary>
        /// <param name="experiment"></param>
        /// <param name="submitted"></param>
        /// <param name="creator"></param>
        /// <param name="note"></param>
        /// <returns>ID of newly created entry</returns>
        public async Task <int> AddExperiment(ExperimentDefinition experiment, DateTime submitted, string creator, string note, string workerInformation)
        {
            TableQuery <NextExperimentIDEntity> idEntityQuery = QueryForNextId();

            bool idChanged;
            int  id = -1;

            do
            {
                idChanged = false;

                var list = (await experimentsTable.ExecuteQuerySegmentedAsync(idEntityQuery, null)).ToList();

                NextExperimentIDEntity nextId = null;

                if (list.Count == 0)
                {
                    nextId    = new NextExperimentIDEntity();
                    id        = 1;
                    nextId.Id = 2;

                    idChanged = !(await TryInsertTableEntity(experimentsTable, nextId));
                }
                else
                {
                    nextId    = list[0];
                    id        = nextId.Id;
                    nextId.Id = id + 1;

                    idChanged = !(await TryUpdateTableEntity(experimentsTable, nextId));
                }
            } while (idChanged);

            var row = new ExperimentEntity(id);

            row.Submitted              = submitted;
            row.Executable             = experiment.Executable;
            row.DomainName             = experiment.DomainName;
            row.Parameters             = experiment.Parameters;
            row.BenchmarkContainerUri  = experiment.BenchmarkContainerUri;
            row.BenchmarkDirectory     = experiment.BenchmarkDirectory;
            row.BenchmarkFileExtension = experiment.BenchmarkFileExtension;
            row.Category          = experiment.Category;
            row.BenchmarkTimeout  = experiment.BenchmarkTimeout.TotalSeconds;
            row.ExperimentTimeout = experiment.ExperimentTimeout.TotalSeconds;
            row.MemoryLimitMB     = experiment.MemoryLimitMB;
            row.GroupName         = experiment.GroupName;
            row.Note                        = note;
            row.Creator                     = creator;
            row.WorkerInformation           = workerInformation;
            row.AdaptiveRunMaxRepetitions   = experiment.AdaptiveRunMaxRepetitions;
            row.AdaptiveRunMaxTimeInSeconds = experiment.AdaptiveRunMaxTimeInSeconds;

            TableOperation insertOperation = TableOperation.Insert(row);
            await experimentsTable.ExecuteAsync(insertOperation);

            return(id);
        }
        /// <summary>
        /// Replaces existing experiments and their results which have same ID.
        /// </summary>
        /// <param name="experiments"></param>
        /// <returns></returns>
        public async Task ImportExperiments(IEnumerable <ExperimentEntity> experiments)
        {
            var nextIdQuery = QueryForNextId();
            var list        = (await experimentsTable.ExecuteQuerySegmentedAsync(nextIdQuery, null)).ToList();
            int nextId      = 0;

            if (list.Count != 0)
            {
                nextId = list[0].Id;
            }

            var upload =
                GroupExperiments(experiments, azureStorageBatchSize)
                .Select(batch =>
            {
                TableBatchOperation opsBatch = new TableBatchOperation();
                int maxID = 0;
                foreach (var item in batch)
                {
                    opsBatch.InsertOrReplace(item);
                    int id = int.Parse(item.RowKey, System.Globalization.CultureInfo.InvariantCulture);
                    if (id > maxID)
                    {
                        maxID = id;
                    }
                }
                return(Tuple.Create(experimentsTable.ExecuteBatchAsync(opsBatch), maxID));
            })
                .ToArray();

            var maxId   = upload.Length > 0 ? upload.Max(t => t.Item2) + 1 : 1;
            var inserts = upload.Select(t => t.Item1);
            await Task.WhenAll(inserts);

            if (maxId > nextId)
            {
                var nextIdEnt = new NextExperimentIDEntity();
                nextIdEnt.Id = maxId;
                await experimentsTable.ExecuteAsync(TableOperation.InsertOrReplace(nextIdEnt));
            }
        }