Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5394


Ignore:
Timestamp:
01/29/11 13:29:21 (13 years ago)
Author:
cneumuel
Message:

#1347

  • jobs are deleted when engine is paused or stopped
  • execution time on hive is computed
Location:
branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HiveEngine.cs

    r5358 r5394  
    3939      set { priority = value; }
    4040    }
     41
     42    [Storable]
     43    private TimeSpan executionTimeOnHive;
     44    public TimeSpan ExecutionTimeOnHive {
     45      get { return executionTimeOnHive; }
     46      set {
     47        if (value != executionTimeOnHive) {
     48          executionTimeOnHive = value;
     49          OnExecutionTimeOnHiveChanged();
     50        }
     51      }
     52    }
    4153   
    4254    #region constructors and cloning
     
    4456      ResourceIds = "HEAL";
    4557    }
     58
    4659    [StorableConstructor]
    4760    protected HiveEngine(bool deserializing) : base(deserializing) { }
     
    5164      this.currentOperator = cloner.Clone(original.currentOperator);
    5265      this.priority = original.priority;
     66      this.executionTimeOnHive = original.executionTimeOnHive;
    5367    }
    5468    public override IDeepCloneable Clone(Cloner cloner) {
    5569      return new HiveEngine(this, cloner);
     70    }
     71    #endregion
     72
     73    #region Events
     74    protected override void OnPrepared() {
     75      base.OnPrepared();
     76      this.ExecutionTimeOnHive = TimeSpan.Zero;
     77    }
     78
     79    public event EventHandler ExecutionTimeOnHiveChanged;
     80    protected virtual void OnExecutionTimeOnHiveChanged() {
     81      var handler = ExecutionTimeOnHiveChanged;
     82      if (handler != null) handler(this, EventArgs.Empty);
    5683    }
    5784    #endregion
     
    158185      IScope[] scopes = new Scope[jobs.Length];
    159186      object locker = new object();
     187      IDictionary<Guid, int> jobIndices = new Dictionary<Guid, int>();
    160188
    161189      try {
    162         IDictionary<Guid, int> jobIndices = new Dictionary<Guid, int>();
    163190        List<Guid> remainingJobIds = new List<Guid>();
    164191        JobResultList results;
     
    203230            }
    204231            jobs[key] = null; // relax memory
    205             LogMessage(string.Format("Submitted job #{0}", key + 1, jobDto.Id));
     232            LogMessage(string.Format("Uploaded job #{0}", key + 1, jobDto.Id));
    206233            uploadTasks.Remove(task);
    207234          }
     
    212239        var downloadTasks = new List<Task<OperationJob>>();
    213240        var executionTimes = new List<TimeSpan>();
     241        var executionTimeOnHiveBefore = executionTimeOnHive;
    214242        while (processUploadedJobsTask.Status != TaskStatus.RanToCompletion || remainingJobIds.Count > 0) {
    215243          cancellationToken.ThrowIfCancellationRequested();
     
    222250            var jobsFinished = results.Where(j => j.State == JobState.Finished || j.State == JobState.Failed || j.State == JobState.Aborted);
    223251            finishedCount += jobsFinished.Count();
    224             var totalExecutionTime = TimeSpan.FromMilliseconds(results.Select(j => j.ExecutionTime).Union(executionTimes).Select(e => e.TotalMilliseconds).Sum());
    225             LogMessage(string.Format("Results polled. Jobs finished: {0}/{1}, TotalExecutionTime: {2}", finishedCount, jobs.Length, totalExecutionTime));
     252            if (jobsFinished.Count() > 0) LogMessage(string.Format("Finished: {0}/{1}", finishedCount, jobs.Length));
     253            ExecutionTimeOnHive = executionTimeOnHiveBefore + executionTimes.Sum() + results.Select(x => x.ExecutionTime).Sum();
     254
    226255            foreach (var result in jobsFinished) {
    227256              if (result.State == JobState.Finished) {
     
    232261                LogMessage(string.Format("Job #{0} aborted (id: {1})", jobIndices[result.Id] + 1, result.Id));
    233262              } else if (result.State == JobState.Failed) {
    234                 LogMessage(string.Format("Job {0} failed (id: {1}): {2}", jobIndices[result.Id] + 1, result.Id, result.Exception));
     263                LogMessage(string.Format("Job #{0} failed (id: {1}): {2}", jobIndices[result.Id] + 1, result.Id, result.Exception));
    235264              }
    236265              remainingJobIds.Remove(result.Id);
     
    259288        }
    260289
    261         LogMessage(string.Format("All jobs finished (TotalExecutionTime: {0}). Deleting jobs on hive.", TimeSpan.FromMilliseconds(executionTimes.Select(e => e.TotalMilliseconds).Sum())));
    262         // delete jobs
     290        LogMessage(string.Format("All jobs finished (TotalExecutionTime: {0}).", executionTimes.Sum()));
     291        DeleteJobs(jobIndices);
     292
     293        return scopes;
     294      }
     295      catch (OperationCanceledException e) {
     296        lock (locker) {
     297          if (jobIndices != null) DeleteJobs(jobIndices);
     298        }
     299        throw e;
     300      }
     301      catch (Exception e) {
     302        lock (locker) {
     303          if (jobIndices != null) DeleteJobs(jobIndices);
     304        }
     305        LogException(e);
     306        throw e;
     307      }
     308    }
     309
     310    private void DeleteJobs(IDictionary<Guid, int> jobIndices) {
     311      if (jobIndices.Count > 0) {
    263312        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
    264313          foreach (Guid jobId in jobIndices.Keys) {
    265314            service.Obj.DeleteJob(jobId);
    266315          }
    267         }
    268 
    269         LogMessage(string.Format("Operations on the hive finished.", jobs.Length));
    270         return scopes;
    271       }
    272       catch (Exception e) {
    273         LogException(e);
    274         throw e;
     316          LogMessage(string.Format("Deleted {0} jobs on hive.", jobIndices.Count));
     317          jobIndices.Clear();
     318        }
    275319      }
    276320    }
     
    395439    }
    396440  }
     441
     442  public static class EnumerableExtensions {
     443    public static TimeSpan Sum(this IEnumerable<TimeSpan> times) {
     444      return TimeSpan.FromMilliseconds(times.Select(e => e.TotalMilliseconds).Sum());
     445    }
     446  }
    397447}
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/Views/HiveEngineView.Designer.cs

    r5282 r5394  
    2828      this.priorityLabel = new System.Windows.Forms.Label();
    2929      this.priorityTextBox = new System.Windows.Forms.TextBox();
     30      this.label1 = new System.Windows.Forms.Label();
     31      this.executionTimeOnHiveTextBox = new System.Windows.Forms.TextBox();
    3032      this.SuspendLayout();
     33      //
     34      // executionTimeTextBox
     35      //
     36      this.executionTimeTextBox.Size = new System.Drawing.Size(623, 20);
    3137      //
    3238      // logView
    3339      //
    34       this.logView.Location = new System.Drawing.Point(0, 81);
    35       this.logView.Size = new System.Drawing.Size(430, 270);
     40      this.logView.Location = new System.Drawing.Point(0, 78);
     41      this.logView.Size = new System.Drawing.Size(715, 469);
    3642      //
    3743      // resourceIdsLabel
    3844      //
    3945      this.resourceIdsLabel.AutoSize = true;
    40       this.resourceIdsLabel.Location = new System.Drawing.Point(3, 26);
     46      this.resourceIdsLabel.Location = new System.Drawing.Point(113, 55);
    4147      this.resourceIdsLabel.Name = "resourceIdsLabel";
    4248      this.resourceIdsLabel.Size = new System.Drawing.Size(70, 13);
     
    4652      // resourceIdsTextBox
    4753      //
    48       this.resourceIdsTextBox.Location = new System.Drawing.Point(73, 23);
     54      this.resourceIdsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     55                  | System.Windows.Forms.AnchorStyles.Left)
     56                  | System.Windows.Forms.AnchorStyles.Right)));
     57      this.resourceIdsTextBox.Location = new System.Drawing.Point(189, 52);
    4958      this.resourceIdsTextBox.Name = "resourceIdsTextBox";
    50       this.resourceIdsTextBox.Size = new System.Drawing.Size(357, 20);
     59      this.resourceIdsTextBox.Size = new System.Drawing.Size(526, 20);
    5160      this.resourceIdsTextBox.TabIndex = 4;
    5261      this.resourceIdsTextBox.Text = "HEAL";
     
    5665      //
    5766      this.priorityLabel.AutoSize = true;
    58       this.priorityLabel.Location = new System.Drawing.Point(3, 49);
     67      this.priorityLabel.Location = new System.Drawing.Point(3, 55);
    5968      this.priorityLabel.Name = "priorityLabel";
    6069      this.priorityLabel.Size = new System.Drawing.Size(41, 13);
     
    6473      // priorityTextBox
    6574      //
    66       this.priorityTextBox.Location = new System.Drawing.Point(73, 46);
     75      this.priorityTextBox.Location = new System.Drawing.Point(50, 52);
    6776      this.priorityTextBox.Name = "priorityTextBox";
    68       this.priorityTextBox.Size = new System.Drawing.Size(357, 20);
     77      this.priorityTextBox.Size = new System.Drawing.Size(57, 20);
    6978      this.priorityTextBox.TabIndex = 6;
     79      this.priorityTextBox.Text = "0";
    7080      this.priorityTextBox.TextChanged += new System.EventHandler(this.priorityTextBox_TextChanged);
     81      //
     82      // label1
     83      //
     84      this.label1.AutoSize = true;
     85      this.label1.Location = new System.Drawing.Point(3, 29);
     86      this.label1.Name = "label1";
     87      this.label1.Size = new System.Drawing.Size(123, 13);
     88      this.label1.TabIndex = 7;
     89      this.label1.Text = "Execution Time on Hive:";
     90      //
     91      // executionTimeOnHiveTextBox
     92      //
     93      this.executionTimeOnHiveTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     94                  | System.Windows.Forms.AnchorStyles.Left)
     95                  | System.Windows.Forms.AnchorStyles.Right)));
     96      this.executionTimeOnHiveTextBox.Location = new System.Drawing.Point(129, 26);
     97      this.executionTimeOnHiveTextBox.Name = "executionTimeOnHiveTextBox";
     98      this.executionTimeOnHiveTextBox.ReadOnly = true;
     99      this.executionTimeOnHiveTextBox.Size = new System.Drawing.Size(586, 20);
     100      this.executionTimeOnHiveTextBox.TabIndex = 8;
    71101      //
    72102      // HiveEngineView
     
    74104      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    75105      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     106      this.Controls.Add(this.label1);
     107      this.Controls.Add(this.executionTimeOnHiveTextBox);
     108      this.Controls.Add(this.priorityTextBox);
     109      this.Controls.Add(this.priorityLabel);
     110      this.Controls.Add(this.resourceIdsLabel);
    76111      this.Controls.Add(this.resourceIdsTextBox);
    77       this.Controls.Add(this.priorityTextBox);
    78       this.Controls.Add(this.resourceIdsLabel);
    79       this.Controls.Add(this.priorityLabel);
    80112      this.Name = "HiveEngineView";
     113      this.Size = new System.Drawing.Size(715, 550);
     114      this.Controls.SetChildIndex(this.resourceIdsTextBox, 0);
     115      this.Controls.SetChildIndex(this.resourceIdsLabel, 0);
    81116      this.Controls.SetChildIndex(this.priorityLabel, 0);
    82       this.Controls.SetChildIndex(this.resourceIdsLabel, 0);
    83117      this.Controls.SetChildIndex(this.priorityTextBox, 0);
    84       this.Controls.SetChildIndex(this.resourceIdsTextBox, 0);
    85118      this.Controls.SetChildIndex(this.logView, 0);
    86119      this.Controls.SetChildIndex(this.executionTimeLabel, 0);
    87120      this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
     121      this.Controls.SetChildIndex(this.executionTimeOnHiveTextBox, 0);
     122      this.Controls.SetChildIndex(this.label1, 0);
    88123      this.ResumeLayout(false);
    89124      this.PerformLayout();
     
    97132    private System.Windows.Forms.Label priorityLabel;
    98133    private System.Windows.Forms.TextBox priorityTextBox;
     134    private System.Windows.Forms.Label label1;
     135    protected System.Windows.Forms.TextBox executionTimeOnHiveTextBox;
    99136  }
    100137}
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/Views/HiveEngineView.cs

    r5282 r5394  
    2424
    2525    protected override void DeregisterContentEvents() {
     26      Content.ExecutionTimeOnHiveChanged -= new EventHandler(Content_ExecutionTimeOnHiveChanged);
    2627      base.DeregisterContentEvents();
    2728    }
     
    2930    protected override void RegisterContentEvents() {
    3031      base.RegisterContentEvents();
     32      Content.ExecutionTimeOnHiveChanged += new EventHandler(Content_ExecutionTimeOnHiveChanged);
    3133    }
    3234
    3335    #region Event Handlers (Content)
    34     // Put event handlers of the content here
     36    private void Content_ExecutionTimeOnHiveChanged(object sender, EventArgs e) {
     37      if (InvokeRequired) {
     38        Invoke(new EventHandler(Content_ExecutionTimeOnHiveChanged), sender, e);
     39      } else {
     40        executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
     41      }
     42    }
    3543    #endregion
    3644
     
    4048        resourceIdsTextBox.Text = string.Empty;
    4149        priorityTextBox.Text = string.Empty;
     50        executionTimeOnHiveTextBox.Text = string.Empty;
    4251      } else {
    4352        resourceIdsTextBox.Text = Content.ResourceIds;
    4453        priorityTextBox.Text = Content.Priority.ToString();
     54        executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
    4555      }
    4656    }
    47 
    4857
    4958    protected override void SetEnabledStateOfControls() {
Note: See TracChangeset for help on using the changeset viewer.