Changeset 10130


Ignore:
Timestamp:
11/12/13 20:35:30 (6 years ago)
Author:
ascheibe
Message:

#2117

  • fixed drag and drop check in the RefreshableHiveJobView to be more generic
  • fixed TaskDownloader to generate the correct HiveTasks when downloading tasks
  • fixed some variable names (job => task) which were forgotten
  • the IsParallelizable property of a task can now be set (e.g. if a task gets parallelized, the generated child tasks should sometimes not be able to get further parallelized)
Location:
trunk/sources
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r9894 r10130  
    2323using System.ComponentModel;
    2424using System.Linq;
     25using System.Reflection;
    2526using System.Text;
    2627using System.Threading;
     
    468469    private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
    469470      e.Effect = DragDropEffects.None;
    470       var obj = e.Data.GetData(Constants.DragDropDataFormat);
    471       if (obj is IOptimizer) {
     471      var obj = e.Data.GetData(Constants.DragDropDataFormat) as IDeepCloneable;
     472      Type objType = obj.GetType();
     473
     474      var typeHiveTaskMap = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     475          .Select(t => new Tuple<PropertyInfo, Type>(t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)), t));
     476
     477      var hiveTaskFound = typeHiveTaskMap.Any(x => x.Item1.PropertyType.IsAssignableFrom(objType));
     478
     479      if (hiveTaskFound) {
    472480        if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
    473481        else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
     
    478486    private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
    479487      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;
     488        var obj = e.Data.GetData(Constants.DragDropDataFormat) as IDeepCloneable;
     489        Type objType = obj.GetType();
     490
     491        var typeHiveTaskMap = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     492            .Select(t => new Tuple<PropertyInfo, Type>(t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)), t));
     493
     494        var hiveTaskType = typeHiveTaskMap.Single(x => x.Item1.PropertyType.IsAssignableFrom(objType)).Item2;
     495
     496        IDeepCloneable newObj = null;
     497        if (e.Effect.HasFlag(DragDropEffects.Copy)) {
     498          newObj = obj.Clone(new Cloner());
     499        } else {
     500          newObj = obj;
     501        }
     502
     503        //IOptimizer and IExecutables need some special care
     504        if (newObj is IOptimizer) {
     505          ((IOptimizer)newObj).Runs.Clear();
     506        }
     507        if (newObj is IExecutable) {
     508          IExecutable exec = newObj as IExecutable;
     509          if (exec.ExecutionState != ExecutionState.Prepared) {
     510            exec.Prepare();
    490511          }
    491           if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
    492             newOptimizer.Prepare();
    493           }
    494 
    495           Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
    496         }
     512        }
     513
     514        ItemTask hiveTask = Activator.CreateInstance(hiveTaskType, new object[] { newObj }) as ItemTask;
     515        Content.HiveTasks.Add(hiveTask.CreateHiveTask());
    497516      }
    498517    }
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r9893 r10130  
    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;
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveTasks/EngineHiveTask.cs

    r9456 r10130  
    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    }
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs

    r9819 r10130  
    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) {
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/TaskDownloader.cs

    r9456 r10130  
    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));
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs

    r9819 r10130  
    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;
     
    5257    public EngineTask(IOperation initialOperation, IEngine engine) {
    5358      this.initialOperation = initialOperation;
     59      this.Item = engine;
     60    }
     61
     62    public EngineTask(IEngine engine) {
    5463      this.Item = engine;
    5564    }
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/ItemTask.cs

    r9456 r10130  
    3131  [StorableClass]
    3232  public abstract class ItemTask : NamedItem, ITask {
     33    public virtual HiveTask CreateHiveTask() {
     34      return new HiveTask(this, true);
     35    }
     36
    3337    public virtual bool IsParallelizable {
    3438      get { return true; }
     39      set { }
    3540    }
    3641
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/OptimizerTask.cs

    r9819 r10130  
    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; }
  • trunk/sources/HeuristicLab.Hive/3.3/ITask.cs

    r9456 r10130  
    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.