Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/20/18 15:26:57 (5 years ago)
Author:
pfleck
Message:

#2845 Merged trunk changes into branch (15406-15681, 15683-16308)

Location:
branches/2845_EnhancedProgress
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2845_EnhancedProgress

  • branches/2845_EnhancedProgress/HeuristicLab.Clients.Hive.JobManager

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManagermergedeligible
      /stable/HeuristicLab.Clients.Hive.JobManagermergedeligible
      /trunk/HeuristicLab.Clients.Hive.JobManagermergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Clients.Hive.JobManager10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Clients.Hive.JobManager5516-5520
      /branches/Async/HeuristicLab.Clients.Hive.JobManager13329-15286
      /branches/Benchmarking/sources/HeuristicLab.Clients.Hive.JobManager6917-7005
      /branches/CloningRefactoring/HeuristicLab.Clients.Hive.JobManager4656-4721
      /branches/CodeEditor/HeuristicLab.Clients.Hive.JobManager11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Clients.Hive.JobManager5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Clients.Hive.JobManager5815-6180
      /branches/DataAnalysis/HeuristicLab.Clients.Hive.JobManager4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Clients.Hive.JobManager10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Clients.Hive.JobManager6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Clients.Hive.JobManager5060
      /branches/HLScript/HeuristicLab.Clients.Hive.JobManager10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Clients.Hive.JobManager11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Clients.Hive.JobManager6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Clients.Hive.JobManager11130-12721
      /branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager15377-15760
      /branches/HiveStatistics/sources/HeuristicLab.Clients.Hive.JobManager12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.Clients.Hive.JobManager10202-10483
      /branches/NET40/sources/HeuristicLab.Clients.Hive.JobManager5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Clients.Hive.JobManager12033-12122
      /branches/ParallelEngine/HeuristicLab.Clients.Hive.JobManager5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Clients.Hive.JobManager7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Clients.Hive.JobManager6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Clients.Hive.JobManager6828
      /branches/RuntimeOptimizer/HeuristicLab.Clients.Hive.JobManager8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Clients.Hive.JobManager7787-8333
      /branches/SlaveShutdown/HeuristicLab.Clients.Hive.JobManager8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Clients.Hive.JobManager10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Clients.Hive.JobManager5370-5682
      /branches/Trunk/HeuristicLab.Clients.Hive.JobManager6829-6865
      /branches/UnloadJobs/HeuristicLab.Clients.Hive.JobManager9168-9215
      /branches/VNS/HeuristicLab.Clients.Hive.JobManager5594-5752
      /branches/crossvalidation-2434/HeuristicLab.Clients.Hive.JobManager12948-12950
      /branches/histogram/HeuristicLab.Clients.Hive.JobManager5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Clients.Hive.JobManager14232-14825
  • branches/2845_EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r16308 r16311  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.ComponentModel;
    2424using System.Linq;
    25 using System.Text;
    2625using System.Threading;
    2726using System.Threading.Tasks;
     
    3433using HeuristicLab.Optimization;
    3534using HeuristicLab.PluginInfrastructure;
     35using System.Collections.Generic;
    3636
    3737namespace HeuristicLab.Clients.Hive.JobManager.Views {
     
    4545    private bool SuppressEvents { get; set; }
    4646    private object runCollectionViewLocker = new object();
     47    private Project selectedProject;
     48    private Dictionary<Guid, Guid> originalJobProjectAssignment = new Dictionary<Guid, Guid>();
    4749
    4850    public new RefreshableJob Content {
    4951      get { return (RefreshableJob)base.Content; }
    50       set { base.Content = value; }
     52      set {
     53        base.Content = value;
     54      }
    5155    }
    5256
     
    117121        if (Content == null) {
    118122          nameTextBox.Text = string.Empty;
     123          descriptionTextBox.Text = string.Empty;
    119124          executionTimeTextBox.Text = string.Empty;
    120           resourceNamesTextBox.Text = string.Empty;
     125          projectNameTextBox.Text = string.Empty;
    121126          refreshAutomaticallyCheckBox.Checked = false;
    122127          lock (runCollectionViewLocker) {
     
    128133          stateLogViewHost.Content = null;
    129134        } else {
     135          if(Content.Job != null
     136            && Content.Job.Id != Guid.Empty
     137            && !originalJobProjectAssignment.ContainsKey(Content.Job.Id)) {
     138            originalJobProjectAssignment.Add(Content.Job.Id, Content.Job.ProjectId);
     139          }
     140
     141          // project look up
     142          if (Content.Job != null && Content.Job.ProjectId == Guid.Empty) {
     143            projectNameTextBox.Text = string.Empty;
     144            if (HiveClient.Instance != null && HiveClient.Instance.Projects != null && HiveClient.Instance.Projects.Count == 1) {
     145              var p = HiveClient.Instance.Projects.FirstOrDefault();
     146              if (p != null && p.Id != Guid.Empty) {
     147                hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId);
     148                Content.Job.ProjectId = p.Id;
     149                var resources = HiveClient.Instance.GetAvailableResourcesForProject(p.Id).ToList();
     150                Content.Job.ResourceIds = resources.Select(x => x.Id).ToList();
     151                hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId;
     152                hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
     153
     154                var cores = resources.Union(resources.SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id)))
     155                  .OfType<Slave>()
     156                  .Distinct()
     157                  .Sum(x => x.Cores);
     158
     159                projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(Content.Job.ProjectId);
     160                projectNameTextBox.Text += "   (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)";
     161              }               
     162            }
     163          } else if (Content.Job != null && Content.Job.ProjectId != Guid.Empty) {
     164            if (selectedProject == null || selectedProject.Id != Content.Job.ProjectId) {
     165              selectedProject = GetProject(Content.Job.ProjectId);
     166              hiveResourceSelectorDialog = null;
     167            }
     168
     169            if(hiveResourceSelectorDialog == null)
     170              hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId);
     171
     172            if (selectedProject != null) {
     173              projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(selectedProject.Id);
     174            } else {
     175              projectNameTextBox.Text = string.Empty;
     176            }
     177
     178            List<Resource> resources = null;
     179            if (Content.Job.ResourceIds == null)
     180              resources = HiveClient.Instance.GetAssignedResourcesForJob(Content.Job.Id).ToList();
     181            else
     182              resources = HiveClient.Instance.Resources.Where(x => Content.Job.ResourceIds.Contains(x.Id)).ToList();
     183
     184            Content.Job.ResourceIds = resources.Select(x => x.Id).ToList();
     185            hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
     186
     187            var cores = resources.Union(resources.SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id)))
     188              .OfType<Slave>()
     189              .Distinct()
     190              .Sum(x => x.Cores);
     191
     192            projectNameTextBox.Text += "   (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)";
     193
     194          } else {
     195            selectedProject = null;
     196            projectNameTextBox.Text = string.Empty;
     197            Content.Job.ResourceIds = null;
     198          }
     199
     200
    130201          nameTextBox.Text = Content.Job.Name;
     202          descriptionTextBox.Text = Content.Job.Description;
    131203          executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    132           resourceNamesTextBox.Text = Content.Job.ResourceNames;
    133204          refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
     205         
    134206          logView.Content = Content.Log;
    135207          lock (runCollectionViewLocker) {
     
    140212        SuppressEvents = false;
    141213      }
    142       hiveExperimentPermissionListView.Content = null; // has to be filled by refresh button
     214      hiveExperimentPermissionListView.Content = null; // has to be filled by refresh
    143215      Content_JobStatisticsChanged(this, EventArgs.Empty);
    144216      Content_HiveExperimentChanged(this, EventArgs.Empty);
     
    157229      tabControl.Enabled = !Locked;
    158230      nameTextBox.Enabled = !Locked;
    159       resourceNamesTextBox.Enabled = !Locked;
     231      descriptionTextBox.Enabled = !Locked;
     232      projectNameTextBox.Enabled = !Locked;
    160233      searchButton.Enabled = !Locked;
    161234      jobsTreeView.Enabled = !Locked;
     
    181254          tabControl.Enabled = !Content.IsProgressing;
    182255
    183           this.nameTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
    184           this.resourceNamesTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
    185           this.searchButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Prepared && !alreadyUploaded && !Content.IsProgressing;
     256          this.nameTextBox.ReadOnly = Content.IsProgressing;
     257          this.descriptionTextBox.ReadOnly = Content.IsProgressing;
     258          this.searchButton.Enabled = !Content.IsProgressing && Content.ExecutionState != ExecutionState.Stopped;
    186259          this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
    187260
    188261          this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
    189262          this.refreshButton.Enabled = Content.IsDownloadable && alreadyUploaded && !Content.IsProgressing;
     263          this.updateButton.Enabled = Content.ExecutionState != ExecutionState.Prepared && Content.ExecutionState != ExecutionState.Stopped && !Content.IsProgressing;
    190264
    191265          this.UnloadButton.Enabled = Content.HiveTasks != null && Content.HiveTasks.Count > 0 && alreadyUploaded && !Content.IsProgressing;
     
    332406    #region Control events
    333407    private void searchButton_Click(object sender, EventArgs e) {
    334       if (hiveResourceSelectorDialog == null)
    335         hiveResourceSelectorDialog = new HiveResourceSelectorDialog();
     408      if (hiveResourceSelectorDialog == null) {
     409        hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId);
     410      } else if(hiveResourceSelectorDialog.JobId != Content.Job.Id) {
     411        hiveResourceSelectorDialog.JobId = Content.Job.Id;
     412        hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId;
     413        hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
     414
     415        if (originalJobProjectAssignment.ContainsKey(Content.Job.Id)) {
     416          hiveResourceSelectorDialog.ProjectId = originalJobProjectAssignment[Content.Job.Id];
     417        } else {
     418          hiveResourceSelectorDialog.ProjectId = Guid.Empty;
     419        }
     420      } else if(hiveResourceSelectorDialog.JobId == Guid.Empty && Content.Job.Id == Guid.Empty) {
     421        hiveResourceSelectorDialog.JobId = Content.Job.Id;
     422        hiveResourceSelectorDialog.ProjectId = Guid.Empty;
     423        hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId;
     424        hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
     425      } else {
     426        hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId;
     427        hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
     428      }
     429
    336430      if (hiveResourceSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    337         StringBuilder sb = new StringBuilder();
    338         foreach (Resource resource in hiveResourceSelectorDialog.GetSelectedResources()) {
    339           sb.Append(resource.Name);
    340           sb.Append(";");
    341         }
    342         resourceNamesTextBox.Text = sb.ToString();
    343         if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
    344           Content.Job.ResourceNames = resourceNamesTextBox.Text;
     431        selectedProject = hiveResourceSelectorDialog.SelectedProject;
     432        if(selectedProject != null) {       
     433          Content.Job.ProjectId = selectedProject.Id;
     434          Content.Job.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList();
     435
     436          var cores = hiveResourceSelectorDialog.SelectedResources
     437            .Union(hiveResourceSelectorDialog.SelectedResources
     438              .SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id)))
     439            .OfType<Slave>()
     440            .Distinct()
     441            .Sum(x => x.Cores);
     442
     443          projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(selectedProject.Id) + "";
     444          projectNameTextBox.Text += "   (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)";
     445
     446        } else {
     447          selectedProject = null;
     448          projectNameTextBox.Text = string.Empty;
     449          Content.Job.ProjectId = Guid.Empty;
     450          Content.Job.ResourceIds = null;
     451        }
     452        SetEnabledStateOfExecutableButtons();
    345453      }
    346454    }
     
    349457      if (nameTextBox.Text.Trim() == string.Empty) {
    350458        MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
     459      } else if (Content.Job.ProjectId == null || Content.Job.ProjectId == Guid.Empty) {
     460        MessageBox.Show("Please select a project before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
     461      } else if (Content.Job.ResourceIds == null || !Content.Job.ResourceIds.Any()) {
     462        MessageBox.Show("Please select resources before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
    351463      } else if (Content.ExecutionState == ExecutionState.Paused) {
    352464        var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
     
    358470      } else {
    359471        HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
     472        UpdateSelectorDialog();
    360473      }
    361474    }
     
    402515    }
    403516
     517    private void descriptionTextBox_Validated(object sender, EventArgs e) {
     518      if (!SuppressEvents && Content.Job != null && Content.Job.Description != descriptionTextBox.Text)
     519        Content.Job.Description = descriptionTextBox.Text;
     520    }
     521
    404522    private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
    405       if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)
    406         Content.Job.ResourceNames = resourceNamesTextBox.Text;
     523      //if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)
     524      //  Content.Job.ResourceNames = resourceNamesTextBox.Text;
    407525    }
    408526
     
    420538        }
    421539      }, null);
     540      UpdateSelectorDialog();
     541    }
     542
     543    private void updateButton_Click(object sender, EventArgs e) {
     544      if (Content.ExecutionState == ExecutionState.Stopped) {
     545        MessageBox.Show("Job cannot be updated once it stopped.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
     546        return;
     547      }
     548
     549      var invoker = new Action<RefreshableJob>(HiveClient.UpdateJob);
     550      invoker.BeginInvoke(Content, (ar) => {
     551        try {
     552          invoker.EndInvoke(ar);
     553        } catch (Exception ex) {
     554          ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
     555        }
     556      }, null);
     557      UpdateSelectorDialog();
     558    }
     559
     560    private void UnloadButton_Click(object sender, EventArgs e) {
     561      Content.Unload();
     562      runCollectionViewHost.Content = null;
     563      stateLogViewHost.Content = null;
     564      hiveExperimentPermissionListView.Content = null;
     565      jobsTreeView.Content = null;
     566
     567      SetEnabledStateOfControls();
    422568    }
    423569
     
    436582        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = false;
    437583      } else {
    438         startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
     584        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0
     585          && Content.Job.ProjectId != Guid.Empty && Content.Job.ResourceIds != null  && Content.Job.ResourceIds.Any()
     586          && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
    439587        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
    440588        stopButton.Enabled = Content.IsControllable && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
     589      }
     590    }
     591   
     592    private Project GetProject(Guid projectId) {
     593      return HiveServiceLocator.Instance.CallHiveService(s => s.GetProject(projectId));
     594    }
     595
     596    private void UpdateSelectorDialog() {
     597      if(hiveResourceSelectorDialog != null) {
     598        hiveResourceSelectorDialog = null;
     599        //hiveResourceSelectorDialog.JobId = Content.Job.Id;
     600        //hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId;
     601        //hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds;
    441602      }
    442603    }
     
    515676    }
    516677
    517     private void UnloadButton_Click(object sender, EventArgs e) {
    518       Content.Unload();
    519       runCollectionViewHost.Content = null;
    520       stateLogViewHost.Content = null;
    521       hiveExperimentPermissionListView.Content = null;
    522       jobsTreeView.Content = null;
    523 
    524       SetEnabledStateOfControls();
    525     }
    526678  }
    527679}
Note: See TracChangeset for help on using the changeset viewer.