private void btnNewJob_Click(object sender, RoutedEventArgs args)
 {
     try
     {
         string creator = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
         var    vm      = new NewExperimentViewModel(managerVm, uiService, recentValues, creator, domainResolver);
         SubmitNewJob(vm);
     }
     catch (Exception e)
     {
         uiService.ShowError(e, "New experiment");
     }
 }
        private void Restart(object target, ExecutedRoutedEventArgs e)
        {
            var handle = uiService.StartIndicateLongOperation("Restarting selected experiments...");

            try
            {
                string creator     = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                int    n           = dataGrid.SelectedItems.Count;
                var    experiments = new ExperimentStatusViewModel[n];
                for (int i = 0; i < n; i++)
                {
                    experiments[i] = (ExperimentStatusViewModel)dataGrid.SelectedItems[i];
                }

                for (int i = 0; i < n; i++)
                {
                    var experiment = experiments[i];
                    var vm         = new NewExperimentViewModel(managerVm, uiService, recentValues, creator, domainResolver);
                    vm.Note = experiment.Note;
                    if (experiment.Definition.BenchmarkContainerUri != ExperimentDefinition.DefaultContainerUri)
                    {
                        vm.BenchmarkContainerUriNotDefault = experiment.Definition.BenchmarkContainerUri;
                        vm.IsDefaultBenchmarkContainerUri  = false;
                    }
                    vm.BenchmarkContainerUri  = experiment.Definition.BenchmarkContainerUri;
                    vm.BenchmarkDirectory     = experiment.Definition.BenchmarkDirectory;
                    vm.Categories             = experiment.Category;
                    vm.Extension              = experiment.Definition.BenchmarkFileExtension;
                    vm.BenchmarkTimeoutSec    = experiment.Definition.BenchmarkTimeout.TotalSeconds;
                    vm.ExperimentTimeoutSec   = experiment.Definition.ExperimentTimeout.TotalSeconds;
                    vm.BenchmarkMemoryLimitMb = experiment.Definition.MemoryLimitMB;
                    vm.Domain                 = experiment.Definition.DomainName;
                    vm.Parameters             = experiment.Definition.Parameters;
                    vm.MaxRepetitions         = experiment.Definition.AdaptiveRunMaxRepetitions;
                    vm.MaxTimeForAdaptiveRuns = experiment.Definition.AdaptiveRunMaxTimeInSeconds;
                    vm.AllowAdaptiveRuns      = experiment.Definition.AdaptiveRunMaxRepetitions != 1 || experiment.Definition.AdaptiveRunMaxTimeInSeconds != 0;
                    vm.Executable             = experiment.Definition.Executable;

                    SubmitNewJob(vm);
                }
            }
            catch (Exception ex)
            {
                uiService.ShowError(ex, "Failed to restart experiments");
            }
            finally
            {
                uiService.StopIndicateLongOperation(handle);
            }
        }
Exemplo n.º 3
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            NewExperimentViewModel vm = DataContext as NewExperimentViewModel;

            if (vm != null)
            {
                if (vm.Validate())
                {
                    DialogResult = true;
                }
            }
            else
            {
                DialogResult = true;
            }
        }
        public async Task <Tuple <string, int?, Exception>[]> SubmitExperiments(NewExperimentViewModel newExperiment)
        {
            // Uploading package with binaries
            string creator = newExperiment.Creator;
            string packageName;

            if (newExperiment.UseMostRecentExecutable)
            {
                packageName = await newExperiment.GetRecentExecutable();

                if (String.IsNullOrEmpty(packageName))
                {
                    throw new InvalidOperationException("Executable package is not available");
                }
            }
            else if (newExperiment.UseOriginalExecutable)
            {
                packageName = newExperiment.Executable;
            }
            else // upload new executable
            {
                if (newExperiment.ExecutableFileNames == null || newExperiment.ExecutableFileNames.Length == 0)
                {
                    throw new InvalidOperationException("New executable should be uploaded but no files selected");
                }

                if (newExperiment.ExecutableFileNames.Length == 1) // single file will be uploaded as is
                {
                    string fileName = Path.GetFileName(newExperiment.ExecutableFileNames[0]);
                    using (Stream stream = File.Open(newExperiment.ExecutableFileNames[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        packageName = await manager.Storage.UploadNewExecutable(stream, fileName, creator);
                    }
                }
                else // multiple files are packed into zip
                {
                    if (String.IsNullOrEmpty(newExperiment.MainExecutable))
                    {
                        throw new InvalidOperationException("There is no main executable selected");
                    }

                    string fileName = Path.GetFileNameWithoutExtension(newExperiment.MainExecutable) + ".zip";
                    using (MemoryStream stream = new MemoryStream(20 << 20))
                    {
                        Measurement.ExecutablePackage.PackToStream(newExperiment.ExecutableFileNames, newExperiment.MainExecutable, stream);
                        packageName = await manager.Storage.UploadNewExecutable(stream, fileName, creator);
                    }
                }
            }

            int    maxRepetitions = 1;
            double maxTime        = 0;

            if (newExperiment.AllowAdaptiveRuns)
            {
                maxRepetitions = newExperiment.MaxRepetitions;
                maxTime        = newExperiment.MaxTimeForAdaptiveRuns;
            }

            // Submitting experiments
            string[] cats = newExperiment.Categories.Split('|');
            var      res  = new Tuple <string, int?, Exception> [cats.Length];

            for (int i = 0; i < cats.Length; i++)
            {
                string category          = cats[i].Trim();
                ExperimentDefinition def =
                    ExperimentDefinition.Create(
                        packageName, newExperiment.BenchmarkContainerUri, newExperiment.BenchmarkDirectory, newExperiment.Extension, newExperiment.Parameters,
                        TimeSpan.FromSeconds(newExperiment.BenchmarkTimeoutSec), TimeSpan.FromSeconds(newExperiment.ExperimentTimeoutSec), newExperiment.Domain,
                        category, newExperiment.BenchmarkMemoryLimitMb, maxRepetitions, maxTime);

                try
                {
                    // Starts the experiment job
                    manager.BatchPoolID = newExperiment.Pool;
                    int id = await manager.StartExperiment(def, creator, newExperiment.Note);

                    res[i] = Tuple.Create <string, int?, Exception>(category, id, null);
                }
                catch (Exception ex)
                {
                    res[i] = Tuple.Create <string, int?, Exception>(category, null, ex);
                }
            }
            return(res);
        }
        private async void SubmitNewJob(NewExperimentViewModel vm)
        {
            NewJobDialog dlg = new NewJobDialog();

            dlg.DataContext = vm;
            dlg.Owner       = this;
            if (dlg.ShowDialog() == true)
            {
                var handle = uiService.StartIndicateLongOperation("Submitting new experiment...");
                try
                {
                    vm.SaveRecentSettings();
                }
                catch (Exception ex)
                {
                    uiService.ShowWarning(ex.Message, "Failed to save recent settings");
                }

                Tuple <string, int?, Exception>[] result;
                try
                {
                    if (!vm.Parameters.Contains("{0}"))
                    {
                        var domain = domainResolver.GetDomain(vm.Domain);
                        vm.Parameters = domain.AddFileNameArgument(vm.Parameters, "{0}");
                    }

                    // Submitting the new experiment
                    result = await managerVm.SubmitExperiments(vm);
                }
                catch (Exception ex)
                {
                    uiService.ShowError(ex, "Failed to submit an experiment");
                    return;
                }
                finally
                {
                    uiService.StopIndicateLongOperation(handle);
                }

                experimentsVm.Refresh();

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    if (i > 0)
                    {
                        sb.AppendLine();
                    }

                    var r = result[i];
                    if (r.Item2.HasValue)
                    {
                        sb.AppendFormat("Experiment for category {0} successfully submitted with id {1}.", r.Item1, r.Item2.Value);
                    }
                    if (r.Item3 != null)
                    {
                        sb.AppendFormat("Experiment for category {0} could not be submitted: {1}.", r.Item1, r.Item3.Message);
                    }
                }
                uiService.ShowInfo(sb.ToString(), "New experiments");
            }
        }