Changeset 11083


Ignore:
Timestamp:
07/03/14 16:36:10 (5 years ago)
Author:
ascheibe
Message:

#2117 merged r10130, r10150, r10154, r10170, r11079 into stable

Location:
stable
Files:
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Clients.Hive.JobManager/3.3/HeuristicLab.Clients.Hive.JobManager-3.3.csproj

    r8718 r11083  
    9898    <Compile Include="ExtensionMethods\TreeNodeExtensions.cs" />
    9999    <Compile Include="ListViewItemDateComparer.cs" />
     100    <Compile Include="MenuItems\CreateHiveJobMenuItem.cs" />
     101    <Compile Include="MenuItems\RunInHiveMenuItem.cs" />
    100102    <Compile Include="Plugin.cs" />
    101103    <Compile Include="Views\HiveJobManagerView.cs">
  • stable/HeuristicLab.Clients.Hive.JobManager/3.3/MenuItems/CreateHiveJobMenuItem.cs

    r10150 r11083  
    2222using System;
    2323using System.Collections.Generic;
    24 using HeuristicLab.Clients.Hive;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.MainForm;
    2726using HeuristicLab.Optimization;
     27using HeuristicLab.Optimizer;
    2828
    29 namespace HeuristicLab.Optimizer.MenuItems {
     29namespace HeuristicLab.Clients.Hive.JobManager {
    3030  public class CreateHiveJobMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
    3131    public override string Name {
     
    4848          Type contentType = content.GetType();
    4949          ToolStripItem.Enabled = ItemTask.IsTypeSupported(contentType);
    50         } else {
    51           ToolStripItem.Enabled = false;
     50          return;
    5251        }
    5352      }
     53      ToolStripItem.Enabled = false;
    5454    }
    5555
     
    7474      HiveTask task = hiveTask.CreateHiveTask();
    7575      RefreshableJob rJob = new RefreshableJob();
    76       rJob.Job.Name = content.ItemName;
     76      rJob.Job.Name = content.ToString();
    7777      rJob.HiveTasks.Add(task);
    7878      task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun;
  • stable/HeuristicLab.Clients.Hive.JobManager/3.3/MenuItems/JobManagerMenuItem.cs

    r9456 r11083  
    2222using System.Collections.Generic;
    2323using System.Windows.Forms;
    24 using HeuristicLab.Clients.Hive;
    2524using HeuristicLab.MainForm;
     25using HeuristicLab.Optimizer;
    2626
    27 namespace HeuristicLab.Optimizer.MenuItems {
     27namespace HeuristicLab.Clients.Hive.JobManager {
    2828  public class JobManagerMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
    2929    public override string Name {
  • stable/HeuristicLab.Clients.Hive.JobManager/3.3/MenuItems/RunInHiveMenuItem.cs

    r10150 r11083  
    2323using System.Collections.Generic;
    2424using System.Threading;
    25 using HeuristicLab.Clients.Hive;
    2625using HeuristicLab.Core;
    2726using HeuristicLab.MainForm;
    2827using HeuristicLab.Optimization;
     28using HeuristicLab.Optimizer;
    2929using HeuristicLab.PluginInfrastructure;
    3030
    31 namespace HeuristicLab.Optimizer.MenuItems {
     31namespace HeuristicLab.Clients.Hive.JobManager {
    3232  public class RunInHiveMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
    3333    public override string Name {
     
    5050          Type contentType = content.GetType();
    5151          ToolStripItem.Enabled = ItemTask.IsTypeSupported(contentType);
    52         } else {
    53           ToolStripItem.Enabled = false;
     52          return;
    5453        }
    5554      }
     55      ToolStripItem.Enabled = false;
    5656    }
    5757
     
    7878      HiveTask task = hiveTask.CreateHiveTask();
    7979      RefreshableJob rJob = new RefreshableJob();
    80       rJob.Job.Name = content.ItemName;
     80      rJob.Job.Name = content.ToString();
    8181      rJob.HiveTasks.Add(task);
    8282      task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun;
  • stable/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r9933 r11083  
    468468    private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
    469469      e.Effect = DragDropEffects.None;
    470       var obj = e.Data.GetData(Constants.DragDropDataFormat);
    471       if (obj is IOptimizer) {
     470      var obj = (IDeepCloneable)e.Data.GetData(Constants.DragDropDataFormat);
     471
     472      Type objType = obj.GetType();
     473      if (ItemTask.IsTypeSupported(objType)) {
    472474        if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
    473475        else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
     
    478480    private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
    479481      if (e.Effect != DragDropEffects.None) {
    480         var obj = e.Data.GetData(Constants.DragDropDataFormat);
    481 
    482         var optimizer = obj as IOptimizer;
    483         if (optimizer != null) {
    484           IOptimizer newOptimizer = null;
    485           if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    486             newOptimizer = (IOptimizer)optimizer.Clone();
    487             newOptimizer.Runs.Clear();
    488           } else {
    489             newOptimizer = optimizer;
     482        var obj = (IItem)e.Data.GetData(Constants.DragDropDataFormat);
     483
     484        IItem newObj = null;
     485        if (e.Effect.HasFlag(DragDropEffects.Copy)) {
     486          newObj = (IItem)obj.Clone();
     487        } else {
     488          newObj = obj;
     489        }
     490
     491        //IOptimizer and IExecutables need some special care
     492        if (newObj is IOptimizer) {
     493          ((IOptimizer)newObj).Runs.Clear();
     494        }
     495        if (newObj is IExecutable) {
     496          IExecutable exec = (IExecutable)newObj;
     497          if (exec.ExecutionState != ExecutionState.Prepared) {
     498            exec.Prepare();
    490499          }
    491           if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
    492             newOptimizer.Prepare();
    493           }
    494 
    495           Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
    496         }
     500        }
     501
     502        ItemTask hiveTask = ItemTask.GetItemTaskForItem(newObj);
     503        Content.HiveTasks.Add(hiveTask.CreateHiveTask());
    497504      }
    498505    }
  • stable/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r9933 r11083  
    351351    /// </summary>
    352352    /// <param name="parentHiveTask">shall be null if its the root task</param>
    353     private void UploadTaskWithChildren(Progress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, bool isPrivileged, CancellationToken cancellationToken) {
     353    private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, bool isPrivileged, CancellationToken cancellationToken) {
    354354      taskUploadSemaphore.WaitOne();
    355355      bool semaphoreReleased = false;
     
    362362        List<IPluginDescription> plugins;
    363363
    364         if (hiveTask.ItemTask.ComputeInParallel && (hiveTask.ItemTask.Item is Optimization.Experiment || hiveTask.ItemTask.Item is Optimization.BatchRun)) {
     364        if (hiveTask.ItemTask.ComputeInParallel) {
    365365          hiveTask.Task.IsParentTask = true;
    366366          hiveTask.Task.FinishWhenChildJobsFinished = true;
  • stable/HeuristicLab.Clients.Hive/3.3/HiveTasks/EngineHiveTask.cs

    r9456 r11083  
    3232    #region Constructors and cloning
    3333    public EngineHiveTask() { }
    34     public EngineHiveTask(EngineTask engineJob, IScope parentScopeClone)
    35       : base(engineJob) {
     34    public EngineHiveTask(EngineTask engineTask, IScope parentScopeClone)
     35      : base(engineTask) {
    3636      this.parentScopeClone = parentScopeClone;
    3737    }
  • stable/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs

    r9886 r11083  
    182182    }
    183183
    184     public HiveTask(ItemTask itemJob, bool autoCreateChildHiveJobs)
     184    public HiveTask(ItemTask itemTask, bool autoCreateChildHiveTasks)
    185185      : this() {
    186       this.syncTasksWithOptimizers = autoCreateChildHiveJobs;
    187       this.ItemTask = itemJob;
     186      this.syncTasksWithOptimizers = autoCreateChildHiveTasks;
     187      this.ItemTask = itemTask;
    188188      this.syncTasksWithOptimizers = true;
    189189    }
    190190
    191     public HiveTask(Task job, TaskData taskData, bool autoCreateChildHiveTasks) {
     191    public HiveTask(Task task, TaskData taskData, bool autoCreateChildHiveTasks) {
    192192      this.syncTasksWithOptimizers = autoCreateChildHiveTasks;
    193       this.Task = job;
     193      this.Task = task;
    194194      try {
    195195        this.ItemTask = PersistenceUtil.Deserialize<ItemTask>(taskData.Data);
     
    545545    public new T ItemTask {
    546546      get { return (T)base.ItemTask; }
    547       internal set { base.ItemTask = value; }
     547      set { base.ItemTask = value; }
    548548    }
    549549
     
    552552    [StorableConstructor]
    553553    protected HiveTask(bool deserializing) { }
    554     public HiveTask(T itemJob) : base(itemJob, true) { }
     554    public HiveTask(T itemTask) : base(itemTask, true) { }
    555555    protected HiveTask(HiveTask<T> original, Cloner cloner)
    556556      : base(original, cloner) {
  • stable/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs

    r9933 r11083  
    157157    }
    158158
    159     private Progress progress;
    160     public Progress Progress {
     159    private IProgress progress;
     160    public IProgress Progress {
    161161      get { return progress; }
    162162      set {
  • stable/HeuristicLab.Clients.Hive/3.3/TaskDownloader.cs

    r9456 r11083  
    2424using System.Linq;
    2525using System.Threading;
    26 using HeuristicLab.Clients.Hive.Jobs;
    2726using HeuristicLab.Common;
    2827
     
    7978
    8079    public TaskDownloader(IEnumerable<Guid> jobIds) {
    81       this.taskIds = jobIds;
    82       this.taskDownloader = new ConcurrentTaskDownloader<ItemTask>(Settings.Default.MaxParallelDownloads, Settings.Default.MaxParallelDownloads);
    83       this.taskDownloader.ExceptionOccured += new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);
    84       this.results = new Dictionary<Guid, HiveTask>();
     80      taskIds = jobIds;
     81      taskDownloader = new ConcurrentTaskDownloader<ItemTask>(Settings.Default.MaxParallelDownloads, Settings.Default.MaxParallelDownloads);
     82      taskDownloader.ExceptionOccured += new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);
     83      results = new Dictionary<Guid, HiveTask>();
    8584    }
    8685
     
    8887      foreach (Guid taskId in taskIds) {
    8988        taskDownloader.DownloadTaskDataAndTask(taskId,
    90           (localJob, itemJob) => {
    91             if (localJob != null && itemJob != null) {
    92               HiveTask hiveTask;
    93               if (itemJob is OptimizerTask) {
    94                 hiveTask = new OptimizerHiveTask((OptimizerTask)itemJob);
    95               } else {
    96                 hiveTask = new HiveTask(itemJob, true);
    97               }
    98               hiveTask.Task = localJob;
     89          (localTask, itemTask) => {
     90            if (localTask != null && itemTask != null) {
     91              HiveTask hiveTask = itemTask.CreateHiveTask();
     92              hiveTask.Task = localTask;
    9993              try {
    10094                resultsLock.EnterWriteLock();
    101                 this.results.Add(localJob.Id, hiveTask);
     95                results.Add(localTask.Id, hiveTask);
    10296              }
    10397              finally { resultsLock.ExitWriteLock(); }
     
    113107    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
    114108    private void OnExceptionOccured(Exception exception) {
    115       this.exceptionOccured = true;
    116       this.currentException = exception;
     109      exceptionOccured = true;
     110      currentException = exception;
    117111      var handler = ExceptionOccured;
    118112      if (handler != null) handler(this, new EventArgs<Exception>(exception));
  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs

    r9886 r11083  
    2929  [StorableClass]
    3030  public class EngineTask : ItemTask {
     31    public override HiveTask CreateHiveTask() {
     32      //only used when deserializing, so no problem with parentscope
     33      return new EngineHiveTask(this, null);
     34    }
     35
    3136    [Storable]
    3237    protected IOperation initialOperation;
     
    5459      this.Item = engine;
    5560    }
     61
     62    public EngineTask(IEngine engine) : base(engine) { }
    5663
    5764    [StorableConstructor]
  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/ItemTask.cs

    r9456 r11083  
    2222using System;
    2323using System.Drawing;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Hive;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2830
    2931namespace HeuristicLab.Clients.Hive {
     
    3133  [StorableClass]
    3234  public abstract class ItemTask : NamedItem, ITask {
     35    public virtual HiveTask CreateHiveTask() {
     36      return new HiveTask(this, true);
     37    }
     38
    3339    public virtual bool IsParallelizable {
    3440      get { return true; }
     41      set { }
    3542    }
    3643
     
    7178      this.Item = cloner.Clone(original.Item);
    7279    }
     80    public ItemTask(IItem item) {
     81      Item = item;
     82    }
    7383
    7484    [StorableHook(HookType.AfterDeserialization)]
     
    211221      return Name;
    212222    }
     223
     224    #region Helpers
     225    public static bool IsTypeSupported(Type itemType) {
     226      var supportedHiveTaskTypes = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     227          .Select(t => t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)).PropertyType);
     228      return supportedHiveTaskTypes.Any(x => x.IsAssignableFrom(itemType));
     229    }
     230
     231    public static Type GetHiveTaskType(Type itemType) {
     232      if (!IsTypeSupported(itemType)) throw new Exception("Item " + itemType + " is not supported for Hive.");
     233
     234      var typeHiveTaskMap = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     235          .Select(t => new Tuple<Type, Type>(t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)).PropertyType, t));
     236
     237      return typeHiveTaskMap.Single(x => x.Item1.IsAssignableFrom(itemType)).Item2;
     238    }
     239
     240    public static ItemTask GetItemTaskForItem(IItem item) {
     241      Type itemType = item.GetType();
     242      Type hiveTaskType = GetHiveTaskType(itemType);
     243      return Activator.CreateInstance(hiveTaskType, new object[] { item }) as ItemTask;
     244    }
     245    #endregion
    213246  }
    214247}
  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/OptimizerTask.cs

    r9886 r11083  
    3030  [StorableClass]
    3131  public class OptimizerTask : ItemTask {
     32    public override HiveTask CreateHiveTask() {
     33      return new OptimizerHiveTask(this);
     34    }
     35
    3236    public override bool IsParallelizable {
    3337      get { return this.Item is Experiment || this.Item is BatchRun; }
     
    4650    }
    4751
    48     public OptimizerTask(IOptimizer optimizer) {
    49       this.Item = optimizer;
    50 
    51       if (optimizer is Experiment) {
     52    public OptimizerTask(IOptimizer optimizer)
     53      : base(optimizer) {
     54
     55      if (optimizer is Experiment || optimizer is BatchRun) {
    5256        this.ComputeInParallel = true;
    53       } else if (optimizer is BatchRun) {
    54         this.ComputeInParallel = false;
    5557      } else {
    5658        this.ComputeInParallel = false;
  • stable/HeuristicLab.Hive/3.3/ITask.cs

    r9456 r11083  
    3333    /// indicates wether it is possible to create childjobs from this job
    3434    /// </summary>
    35     bool IsParallelizable { get; }
     35    bool IsParallelizable { get; set; }
    3636
    3737    /// <summary>
Note: See TracChangeset for help on using the changeset viewer.