Changeset 6178
- Timestamp:
- 05/10/11 17:58:59 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4
- Files:
-
- 4 added
- 2 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
r6175 r6178 47 47 private Dictionary<Guid, Executor> executors = new Dictionary<Guid, Executor>(); 48 48 private Dictionary<Guid, AppDomain> appDomains = new Dictionary<Guid, AppDomain>(); 49 50 // signalizes if the Executor.Start method has properly finished. only then the appdomain may be unloaded 51 private Dictionary<Guid, Semaphore> semaphores = new Dictionary<Guid, Semaphore>(); 49 52 50 53 private WcfService wcfService; … … 484 487 executor.MemoryNeeded = job.MemoryNeeded; 485 488 clientCom.LogMessage("Starting Executor for job " + job.Id); 486 executor.Start(jobData.Data);487 489 lock (executors) { 488 490 executors.Add(job.Id, executor); 489 491 } 492 semaphores[job.Id] = new Semaphore(0, 1); 493 executor.Start(jobData.Data); 494 semaphores[job.Id].Release(); 490 495 } 491 496 catch (Exception exception) { … … 535 540 /// Kill a appdomain with a specific id. 536 541 /// </summary> 537 /// <param name=" id">the GUID of the job</param>538 public void KillAppDomain(Guid id) {542 /// <param name="jobId">the GUID of the job</param> 543 public void KillAppDomain(Guid jobId) { 539 544 if (Thread.CurrentThread.ManagedThreadId != this.coreThreadId) { 540 EnqueueExecutorMessage<Guid>(KillAppDomain, id);545 EnqueueExecutorMessage<Guid>(KillAppDomain, jobId); 541 546 return; 542 547 } 543 548 544 clientCom.LogMessage("Shutting down Appdomain for Job " + id);549 clientCom.LogMessage("Shutting down Appdomain for Job " + jobId); 545 550 lock (executors) { 546 551 try { 547 if (executors.ContainsKey(id)) { 548 executors[id].Dispose(); 549 executors.Remove(id); 550 } 551 552 if (appDomains.ContainsKey(id)) { 553 appDomains[id].UnhandledException -= new UnhandledExceptionEventHandler(AppDomain_UnhandledException); 554 552 if (executors.ContainsKey(jobId)) { 553 executors[jobId].Dispose(); 554 executors.Remove(jobId); 555 } 556 557 if (appDomains.ContainsKey(jobId)) { 558 appDomains[jobId].UnhandledException -= new UnhandledExceptionEventHandler(AppDomain_UnhandledException); 555 559 int repeat = 5; 556 560 while (repeat > 0) { 557 561 try { 558 AppDomain.Unload(appDomains[id]); 562 semaphores[jobId].WaitOne(); 563 AppDomain.Unload(appDomains[jobId]); 564 semaphores[jobId].Dispose(); 565 semaphores.Remove(jobId); 559 566 repeat = 0; 560 567 } … … 569 576 } 570 577 } 571 appDomains.Remove( id);572 } 573 574 PluginCache.Instance.DeletePluginsForJob( id);578 appDomains.Remove(jobId); 579 } 580 581 PluginCache.Instance.DeletePluginsForJob(jobId); 575 582 GC.Collect(); 576 583 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
r6168 r6178 89 89 } else { 90 90 Job.Start(); 91 startJobSem.WaitOne(); 91 if (!startJobSem.WaitOne(TimeSpan.FromSeconds(15))) { 92 throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired."); 93 } 92 94 } 93 95 } 94 96 catch (Exception e) { 95 97 this.currentException = e; 96 Job_JobFailed(this, new HeuristicLab.Common.EventArgs<Exception>(e));98 Job_JobFailed(this, new EventArgs<Exception>(e)); 97 99 } 98 100 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs
r6107 r6178 278 278 internal void DeletePluginsForJob(Guid id) { 279 279 try { 280 SlaveClientCom.Instance.ClientCom.LogMessage(" unloading...");280 SlaveClientCom.Instance.ClientCom.LogMessage("Deleting plugins..."); 281 281 int tries = 5; 282 282 while (tries > 0) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/HiveJobView.cs
r6168 r6178 61 61 base.OnContentChanged(); 62 62 if (Content != null && Content.Job != null) { 63 computeInParallelCheckBox.Checked = Content. JobItem.ComputeInParallel;63 computeInParallelCheckBox.Checked = Content.ItemJob.ComputeInParallel; 64 64 } else { 65 65 computeInParallelCheckBox.Checked = false; … … 72 72 protected virtual void RegisterJobEvents() { 73 73 if (Content != null && Content.Job != null) { 74 Content. JobItem.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);75 Content. JobItem.ItemChanged += new EventHandler(Job_ItemChanged);74 Content.ItemJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged); 75 Content.ItemJob.ItemChanged += new EventHandler(Job_ItemChanged); 76 76 } 77 77 } … … 79 79 protected virtual void DeregisterJobEvents() { 80 80 if (Content != null && Content.Job != null) { 81 Content. JobItem.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);82 Content. JobItem.ItemChanged -= new EventHandler(Job_ItemChanged);81 Content.ItemJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged); 82 Content.ItemJob.ItemChanged -= new EventHandler(Job_ItemChanged); 83 83 } 84 84 } … … 111 111 112 112 protected virtual void Job_ItemChanged(object sender, EventArgs e) { 113 if (Content != null && Content.Job != null && Content. JobItem.Item != null) {114 optimizerItemView.Content = Content. JobItem.Item;113 if (Content != null && Content.Job != null && Content.ItemJob.Item != null) { 114 optimizerItemView.Content = Content.ItemJob.Item; 115 115 } else { 116 116 optimizerItemView.Content = null; … … 129 129 this.exceptionTextBox.Text = Content.Job.CurrentStateLog != null ? Content.Job.CurrentStateLog.Exception : string.Empty; 130 130 this.lastUpdatedTextBox.Text = Content.Job.LastJobDataUpdate.ToString(); 131 if (Content. JobItem.ComputeInParallel) {131 if (Content.ItemJob.ComputeInParallel) { 132 132 this.stateLogViewHost.Content = new StateLogListList( 133 133 this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog) … … 165 165 this.coresNeededTextBox.ReadOnly = this.ReadOnly; 166 166 this.memoryNeededTextBox.ReadOnly = this.ReadOnly; 167 this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content. JobItem != null && this.Content.JobItem.IsParallelizable;168 169 this.modifyItemButton.Enabled = (Content != null && Content. JobItem.Item != null && (Content.Job.State == JobState.Paused || Content.Job.State == JobState.Offline || Content.Job.State == JobState.Finished || Content.Job.State == JobState.Failed || Content.Job.State == JobState.Aborted));167 this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.ItemJob != null && this.Content.ItemJob.IsParallelizable; 168 169 this.modifyItemButton.Enabled = (Content != null && Content.ItemJob.Item != null && (Content.Job.State == JobState.Paused || Content.Job.State == JobState.Offline || Content.Job.State == JobState.Finished || Content.Job.State == JobState.Failed || Content.Job.State == JobState.Aborted)); 170 170 171 171 optimizerItemView.ReadOnly = true; … … 176 176 Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e); 177 177 } else { 178 computeInParallelCheckBox.Checked = Content. JobItem.ComputeInParallel;178 computeInParallelCheckBox.Checked = Content.ItemJob.ComputeInParallel; 179 179 } 180 180 } … … 183 183 #region Child Control Events 184 184 protected virtual void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) { 185 if (Content != null && Content. JobItem!= null) {186 this.Content. JobItem.ComputeInParallel = this.computeInParallelCheckBox.Checked;185 if (Content != null && Content.ItemJob != null) { 186 this.Content.ItemJob.ComputeInParallel = this.computeInParallelCheckBox.Checked; 187 187 } 188 188 } … … 196 196 197 197 protected virtual void modifyItemButton_Click(object sender, EventArgs e) { 198 MainFormManager.MainForm.ShowContent(Content. JobItem.Item);198 MainFormManager.MainForm.ShowContent(Content.ItemJob.Item); 199 199 } 200 200 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/OptimizerHiveJobView.cs
r6168 r6178 43 43 44 44 protected override void Job_ItemChanged(object sender, EventArgs e) { 45 if (Content != null && Content.Job != null && Content. JobItem.Item != null) {46 runCollectionViewHost.Content = Content. JobItem.Item.Runs;45 if (Content != null && Content.Job != null && Content.ItemJob.Item != null) { 46 runCollectionViewHost.Content = Content.ItemJob.Item.Runs; 47 47 } else { 48 48 runCollectionViewHost.Content = null; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/RefreshableHiveExperimentView.cs
r6033 r6178 55 55 } 56 56 57 protected override void DeregisterContentEvents() {58 Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged);59 Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged);60 Content.HiveExperimentChanged -= new EventHandler(Content_HiveExperimentChanged);61 base.DeregisterContentEvents();62 }63 64 57 protected override void RegisterContentEvents() { 65 58 base.RegisterContentEvents(); … … 67 60 Content.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged); 68 61 Content.HiveExperimentChanged += new EventHandler(Content_HiveExperimentChanged); 62 Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged); 63 } 64 protected override void DeregisterContentEvents() { 65 Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged); 66 Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged); 67 Content.HiveExperimentChanged -= new EventHandler(Content_HiveExperimentChanged); 68 Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged); 69 base.DeregisterContentEvents(); 69 70 } 70 71 … … 134 135 bool jobsLoaded = Content.HiveExperiment.HiveJobs != null && Content.HiveExperiment.HiveJobs.All(x => x.Job.Id != Guid.Empty); 135 136 136 this.nameTextBox.ReadOnly = Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded;137 this.resourceNamesTextBox.ReadOnly = Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded;138 this.jobsTreeView.ReadOnly = Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded;139 this.useLocalPluginsCheckBox.Enabled = !(Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded); 140 this. refreshAutomaticallyCheckBox.Enabled = alreadyUploaded && jobsLoaded && Content.HiveExperiment.ExecutionState == ExecutionState.Started;141 this.refresh Button.Enabled = alreadyUploaded;142 143 this.Locked = Content.HiveExperiment.ExecutionState == ExecutionState.Started;137 this.nameTextBox.ReadOnly = !Content.IsControllable || Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded; 138 this.resourceNamesTextBox.ReadOnly = !Content.IsControllable || Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded; 139 this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded; 140 141 this.useLocalPluginsCheckBox.Enabled = Content.IsControllable && !(Content.HiveExperiment.ExecutionState != ExecutionState.Prepared || alreadyUploaded); 142 this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && Content.HiveExperiment.ExecutionState == ExecutionState.Started; 143 this.refreshButton.Enabled = Content.IsControllable && alreadyUploaded; 144 this.Locked = !Content.IsControllable || Content.HiveExperiment.ExecutionState == ExecutionState.Started; 144 145 } 145 146 SetEnabledStateOfExecutableButtons(); … … 246 247 } 247 248 } 249 private void Content_IsControllableChanged(object sender, EventArgs e) { 250 SetEnabledStateOfControls(); 251 } 248 252 #endregion 249 253 … … 302 306 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false; 303 307 } else { 304 startButton.Enabled = Content. HiveExperiment.HiveJobs != null && Content.HiveExperiment.HiveJobs.Count > 0 && Content.HiveExperiment.ExecutionState == ExecutionState.Prepared;305 pauseButton.Enabled = Content. HiveExperiment.ExecutionState == ExecutionState.Started;306 stopButton.Enabled = Content. HiveExperiment.ExecutionState == ExecutionState.Started;308 startButton.Enabled = Content.IsControllable && Content.HiveExperiment.HiveJobs != null && Content.HiveExperiment.HiveJobs.Count > 0 && Content.HiveExperiment.ExecutionState == ExecutionState.Prepared; 309 pauseButton.Enabled = Content.IsControllable && Content.HiveExperiment.ExecutionState == ExecutionState.Started; 310 stopButton.Enabled = Content.IsControllable && Content.HiveExperiment.ExecutionState == ExecutionState.Started; 307 311 resetButton.Enabled = false; 308 312 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/TreeView/DeleteJobTreeNodeAction.cs
r6033 r6178 24 24 hiveJobs.Remove(item); 25 25 } else { 26 var experiment = parentItem. JobItem.Item as Experiment;26 var experiment = parentItem.ItemJob.Item as Experiment; 27 27 if (experiment != null) { 28 experiment.Optimizers.Remove(((OptimizerJob)item. JobItem).Item);28 experiment.Optimizers.Remove(((OptimizerJob)item.ItemJob).Item); 29 29 } 30 30 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/TreeView/HiveJobItemTreeView.cs
r6033 r6178 81 81 Content.Add(new OptimizerHiveJob(optimizer)); 82 82 } else { 83 var experiment = ((HiveJob)treeView.SelectedNode.Tag). JobItem.Item as Experiment;83 var experiment = ((HiveJob)treeView.SelectedNode.Tag).ItemJob.Item as Experiment; 84 84 if (experiment != null) { 85 85 experiment.Optimizers.Add(optimizer); … … 96 96 Content.Remove((HiveJob)treeView.SelectedNode.Tag); 97 97 } else { 98 var experiment = parentItem. JobItem.Item as Experiment;98 var experiment = parentItem.ItemJob.Item as Experiment; 99 99 if (experiment != null) { 100 experiment.Optimizers.Remove(((OptimizerJob)selectedItem. JobItem).Item);100 experiment.Optimizers.Remove(((OptimizerJob)selectedItem.ItemJob).Item); 101 101 } 102 102 } … … 108 108 var actions = base.GetTreeNodeItemActions(selectedItem); 109 109 if (selectedItem != null) { 110 if (selectedItem. JobItem.Item is Experiment) {110 if (selectedItem.ItemJob.Item is Experiment) { 111 111 112 112 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/TreeView/NewExperimentTreeNodeAction.cs
r6033 r6178 43 43 public void Execute(HiveJob item, HiveJob parentItem) { 44 44 if (item != null) { 45 var experiment = item. JobItem.Item as Experiment;45 var experiment = item.ItemJob.Item as Experiment; 46 46 experiment.Optimizers.Add(new Experiment()); 47 47 } else { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/ExperimentManagerClient.cs
r6111 r6178 274 274 List<IPluginDescription> plugins; 275 275 276 if (hiveJob. JobItem.ComputeInParallel &&277 (hiveJob. JobItem.Item is Optimization.Experiment || hiveJob.JobItem.Item is Optimization.BatchRun)) {276 if (hiveJob.ItemJob.ComputeInParallel && 277 (hiveJob.ItemJob.Item is Optimization.Experiment || hiveJob.ItemJob.Item is Optimization.BatchRun)) { 278 278 hiveJob.Job.IsParentJob = true; 279 279 hiveJob.Job.FinishWhenChildJobsFinished = true; 280 hiveJob. JobItem.CollectChildJobs = false; // don't collect child-jobs on slaves280 hiveJob.ItemJob.CollectChildJobs = false; // don't collect child-jobs on slaves 281 281 jobData = hiveJob.GetAsJobData(true, out plugins); 282 282 } else { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJob.cs
r6168 r6178 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.Linq; … … 55 56 } 56 57 58 [Storable] 57 59 protected Job job; 58 60 public Job Job { … … 60 62 set { 61 63 if (job != value) { 64 DeregisterJobEvents(); 62 65 job = value; 66 RegisterJobEvents(); 67 itemJobDownloaded = false; 63 68 OnJobChanged(); 64 69 OnToStringChanged(); 65 70 OnItemImageChanged(); 66 71 } 72 67 73 } 68 74 } 69 75 70 76 [Storable] 71 protected ItemJob jobItem;72 public ItemJob JobItem{73 get { return jobItem; }77 protected ItemJob itemJob; 78 public ItemJob ItemJob { 79 get { return itemJob; } 74 80 internal set { 75 if ( jobItem!= null && syncJobsWithOptimizers) {81 if (itemJob != null && syncJobsWithOptimizers) { 76 82 this.childHiveJobs.Clear(); 77 83 } 78 if ( jobItem!= value) {79 Dergister JobItemsEvents();80 jobItem= value;81 Register JobItemEvents();84 if (itemJob != value) { 85 DergisterItemJobEvents(); 86 itemJob = value; 87 RegisterItemJobEvents(); 82 88 OnJobItemChanged(); 83 } 84 } 89 itemJobDownloaded = true; 90 } 91 } 92 } 93 94 // job downloaded since last status change 95 [Storable] 96 private bool itemJobDownloaded = false; 97 public bool ItemJobDownloaded { 98 get { return itemJobDownloaded; } 85 99 } 86 100 … … 106 120 } 107 121 108 public HiveJob(ItemJob jobItem, bool autoCreateChildHiveJobs)122 public HiveJob(ItemJob itemJob, bool autoCreateChildHiveJobs) 109 123 : this() { 110 124 this.syncJobsWithOptimizers = autoCreateChildHiveJobs; 111 this. JobItem = jobItem;125 this.ItemJob = itemJob; 112 126 this.syncJobsWithOptimizers = true; 113 127 } … … 117 131 this.Job = job; 118 132 try { 119 this. JobItem= PersistenceUtil.Deserialize<ItemJob>(jobData.Data);133 this.ItemJob = PersistenceUtil.Deserialize<ItemJob>(jobData.Data); 120 134 } 121 135 catch { 122 this. JobItem= null;136 this.ItemJob = null; 123 137 } 124 138 this.childHiveJobs = new ItemList<HiveJob>(); … … 130 144 : base(original, cloner) { 131 145 this.Job = cloner.Clone(original.job); 132 this. JobItem = cloner.Clone(original.JobItem);146 this.ItemJob = cloner.Clone(original.ItemJob); 133 147 this.childHiveJobs = cloner.Clone(original.childHiveJobs); 134 148 this.syncJobsWithOptimizers = original.syncJobsWithOptimizers; 149 this.itemJobDownloaded = original.itemJobDownloaded; 135 150 } 136 151 public override IDeepCloneable Clone(Cloner cloner) { … … 141 156 protected virtual void UpdateChildHiveJobs() { } 142 157 143 protected virtual void Register JobItemEvents() {144 if ( JobItem!= null) {145 JobItem.ComputeInParallelChanged += new EventHandler(JobItem_ComputeInParallelChanged);146 JobItem.ToStringChanged += new EventHandler(JobItem_ToStringChanged);147 } 148 } 149 protected virtual void Dergister JobItemsEvents() {150 if ( JobItem!= null) {151 JobItem.ComputeInParallelChanged -= new EventHandler(JobItem_ComputeInParallelChanged);152 JobItem.ToStringChanged -= new EventHandler(JobItem_ToStringChanged);158 protected virtual void RegisterItemJobEvents() { 159 if (ItemJob != null) { 160 ItemJob.ComputeInParallelChanged += new EventHandler(JobItem_ComputeInParallelChanged); 161 ItemJob.ToStringChanged += new EventHandler(JobItem_ToStringChanged); 162 } 163 } 164 protected virtual void DergisterItemJobEvents() { 165 if (ItemJob != null) { 166 ItemJob.ComputeInParallelChanged -= new EventHandler(JobItem_ComputeInParallelChanged); 167 ItemJob.ToStringChanged -= new EventHandler(JobItem_ToStringChanged); 153 168 } 154 169 } … … 168 183 this.OnToStringChanged(); 169 184 } 170 185 171 186 protected virtual void JobItem_ComputeInParallelChanged(object sender, EventArgs e) { 172 if ( JobItem!= null && syncJobsWithOptimizers) {187 if (ItemJob != null && syncJobsWithOptimizers) { 173 188 this.UpdateChildHiveJobs(); 174 189 } … … 180 195 181 196 public override string ToString() { 182 if ( jobItem!= null) {183 return jobItem.ToString();197 if (itemJob != null) { 198 return itemJob.ToString(); 184 199 } else { 185 200 return base.ToString(); … … 196 211 job.Command = lightweightJob.Command; 197 212 job.LastJobDataUpdate = lightweightJob.LastJobDataUpdate; 198 213 199 214 OnJobStateChanged(); 200 215 OnToStringChanged(); … … 210 225 /// </param> 211 226 public virtual JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) { 212 plugins = null; 213 return null; 227 plugins = new List<IPluginDescription>(); 228 if (this.itemJob == null) 229 return null; 230 231 IEnumerable<Type> usedTypes; 232 byte[] jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes); 233 234 JobData jobData = new JobData() { 235 JobId = job.Id, 236 Data = jobByteArray 237 }; 238 239 PluginUtil.CollectDeclaringPlugins(plugins, usedTypes); 240 241 return jobData; 214 242 } 215 243 … … 239 267 if (handler != null) handler(this, EventArgs.Empty); 240 268 } 269 270 private void RegisterJobEvents() { 271 if (job != null) 272 job.PropertyChanged += new PropertyChangedEventHandler(job_PropertyChanged); 273 } 274 275 private void DeregisterJobEvents() { 276 if (job != null) 277 job.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(job_PropertyChanged); 278 } 279 280 private void job_PropertyChanged(object sender, PropertyChangedEventArgs e) { 281 if (e.PropertyName == "State") { 282 itemJobDownloaded = false; 283 } 284 } 241 285 #endregion 242 286 243 287 /// <summary> 244 288 /// Returns a list of HiveJobs including this and all its child-jobs recursively … … 326 370 } else { 327 371 ServiceLocator.Instance.CallHiveService(s => s.PauseJob(this.job.Id)); 328 } 372 } 329 373 } 330 374 … … 343 387 JobData jobData = new JobData(); 344 388 jobData.JobId = this.job.Id; 345 jobData.Data = PersistenceUtil.Serialize(this. jobItem);389 jobData.Data = PersistenceUtil.Serialize(this.itemJob); 346 390 service.UpdateJobData(this.Job, jobData); 347 391 service.RestartJob(this.job.Id); … … 350 394 }); 351 395 } 352 396 353 397 public ICollection<IItemTreeNodeAction<HiveJob>> Actions { 354 398 get { … … 364 408 public class HiveJob<T> : HiveJob where T : ItemJob { 365 409 366 public new T JobItem{367 get { return (T)base. JobItem; }368 internal set { base. JobItem= value; }410 public new T ItemJob { 411 get { return (T)base.ItemJob; } 412 internal set { base.ItemJob = value; } 369 413 } 370 414 371 415 #region Constructors and Cloning 372 416 public HiveJob() : base() { } 417 public HiveJob(T itemJob) : base(itemJob, true) { } 373 418 protected HiveJob(HiveJob original, Cloner cloner) 374 419 : base(original, cloner) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobDownloader.cs
r6168 r6178 30 30 public class HiveJobDownloader { 31 31 private IEnumerable<Guid> jobIds; 32 private JobDownloader<ItemJob> jobDownloader;32 private ConcurrentJobDownloader<ItemJob> jobDownloader; 33 33 private IDictionary<Guid, HiveJob> results; 34 34 35 35 public bool IsFinished { 36 36 get { 37 //return tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion ||38 // t.Status == TaskStatus.Faulted ||39 // t.Status == TaskStatus.Canceled);40 37 return results.Count == jobIds.Count(); 41 38 } … … 44 41 public int FinishedCount { 45 42 get { 46 //var faulted = tasks.Where(t => t.Status == TaskStatus.Faulted);47 //if (faulted.Count() > 0) {48 // abort = true;49 // throw faulted.First().Exception;50 //}51 //return tasks.Count(t => t.Status == TaskStatus.RanToCompletion ||52 // t.Status == TaskStatus.Faulted ||53 // t.Status == TaskStatus.Canceled);54 43 return results.Count; 55 44 } … … 58 47 public IDictionary<Guid, HiveJob> Results { 59 48 get { 60 //var results = new Dictionary<Guid, HiveJob>();61 //foreach (var t in tasks) {62 // if (t.Status == TaskStatus.Faulted) {63 // throw t.Exception;64 // }65 // if (t.Result != null)66 // results.Add(t.Result.Job.Id, t.Result);67 //}68 49 return results; 69 50 } … … 72 53 public HiveJobDownloader(IEnumerable<Guid> jobIds) { 73 54 this.jobIds = jobIds; 74 this.jobDownloader = new JobDownloader<ItemJob>(2, 2);55 this.jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2); 75 56 this.results = new Dictionary<Guid, HiveJob>(); 76 57 } … … 81 62 (id, itemJob, exception) => { 82 63 if (exception != null) { 83 throw new JobDownloaderException("Downloading job failed", exception);64 throw new ConcurrentJobDownloaderException("Downloading job failed", exception); 84 65 } 85 66 Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(id)); … … 95 76 } 96 77 }); 97 } 98 99 //tasks = new List<Task<HiveJob>>(); 100 //TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException); 101 //foreach (Guid jobId in jobIds) { 102 // tasks.Add(Task<JobData>.Factory.StartNew( 103 // (x) => DownloadJob(x), jobId) 104 // .ContinueWith((x) => DeserializeJob(x.Result))); 105 //} 78 } 106 79 } 107 108 //private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) {109 // e.SetObserved(); // avoid crash of process because task crashes. first exception found is handled in Results property110 //}111 112 //// use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory113 //private Semaphore downloadSemaphore = new Semaphore(2, 2);114 //private Semaphore deserializeSemaphore = new Semaphore(2, 2);115 //protected JobData DownloadJob(object jobId) {116 // downloadSemaphore.WaitOne();117 // deserializeSemaphore.WaitOne();118 // JobData result;119 // try {120 // if (abort) return null;121 // result = ServiceLocator.Instance.CallHiveService(s => s.GetJobData((Guid)jobId));122 // }123 // finally {124 // downloadSemaphore.Release();125 // }126 // return result;127 //}128 129 //protected HiveJob DeserializeJob(JobData jobData) {130 // try {131 // Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(jobData.JobId));132 // if (abort || job == null || jobData == null) return null;133 134 // HiveJob hiveJob;135 // var itemJob = PersistenceUtil.Deserialize<ItemJob>(jobData.Data);136 // if (itemJob is OptimizerJob) {137 // hiveJob = new OptimizerHiveJob((OptimizerJob)itemJob);138 // } else {139 // hiveJob = new HiveJob(itemJob, true);140 // }141 // jobData.Data = null; // reduce memory consumption.142 // hiveJob.Job = job;143 // return hiveJob;144 // }145 // finally {146 // deserializeSemaphore.Release();147 // }148 //}149 80 } 150 81 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/OptimizerHiveJob.cs
r6111 r6178 37 37 public OptimizerHiveJob(IOptimizer optimizer) 38 38 : this() { 39 this. JobItem= new OptimizerJob(optimizer);39 this.ItemJob = new OptimizerJob(optimizer); 40 40 } 41 41 public OptimizerHiveJob(OptimizerJob optimizerJob) 42 42 : this() { 43 this. JobItem= optimizerJob;43 this.ItemJob = optimizerJob; 44 44 } 45 45 protected OptimizerHiveJob(OptimizerHiveJob original, Cloner cloner) … … 60 60 base.UpdateChildHiveJobs(); 61 61 if (Job != null && syncJobsWithOptimizers) { 62 if (! JobItem.ComputeInParallel) {62 if (!ItemJob.ComputeInParallel) { 63 63 this.childHiveJobs.Clear(); 64 64 } else { 65 if ( JobItem.Item is Optimization.Experiment) {66 Optimization.Experiment experiment = (Optimization.Experiment) JobItem.Item;65 if (ItemJob.Item is Optimization.Experiment) { 66 Optimization.Experiment experiment = (Optimization.Experiment)ItemJob.Item; 67 67 foreach (IOptimizer childOpt in experiment.Optimizers) { 68 68 this.childHiveJobs.Add(new OptimizerHiveJob(childOpt)); 69 69 } 70 } else if ( JobItem.Item is Optimization.BatchRun) {71 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;70 } else if (ItemJob.Item is Optimization.BatchRun) { 71 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 72 72 if (batchRun.Optimizer != null) { 73 73 while (this.childHiveJobs.Count < batchRun.Repetitions) { … … 83 83 } 84 84 85 protected override void Register JobItemEvents() {86 base.Register JobItemEvents();87 if ( JobItem!= null) {88 if ( JobItem.Item is Optimization.Experiment) {89 Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;85 protected override void RegisterItemJobEvents() { 86 base.RegisterItemJobEvents(); 87 if (ItemJob != null) { 88 if (ItemJob.Item is Optimization.Experiment) { 89 Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment; 90 90 experiment.Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 91 91 experiment.Optimizers.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced); 92 92 experiment.Optimizers.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved); 93 93 experiment.Optimizers.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset); 94 } else if ( JobItem.Item is Optimization.BatchRun) {95 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;94 } else if (ItemJob.Item is Optimization.BatchRun) { 95 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 96 96 batchRun.RepetitionsChanged += new EventHandler(batchRun_RepetitionsChanged); 97 97 batchRun.OptimizerChanged += new EventHandler(batchRun_OptimizerChanged); … … 99 99 } 100 100 } 101 protected override void Dergister JobItemsEvents() {102 base.Dergister JobItemsEvents();103 if ( JobItem!= null) {104 if ( JobItem.Item is Optimization.Experiment) {105 Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;101 protected override void DergisterItemJobEvents() { 102 base.DergisterItemJobEvents(); 103 if (ItemJob != null) { 104 if (ItemJob.Item is Optimization.Experiment) { 105 Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment; 106 106 experiment.Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 107 107 experiment.Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced); 108 108 experiment.Optimizers.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved); 109 109 experiment.Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset); 110 } else if ( JobItem.Item is Optimization.BatchRun) {111 Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;110 } else if (ItemJob.Item is Optimization.BatchRun) { 111 Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun; 112 112 batchRun.RepetitionsChanged -= new EventHandler(batchRun_RepetitionsChanged); 113 113 batchRun.OptimizerChanged -= new EventHandler(batchRun_OptimizerChanged); … … 129 129 130 130 private void Optimizers_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 131 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {131 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 132 132 foreach (var item in e.Items) { 133 133 if (GetChildByOptimizer(item.Value) == null && item.Value.Name != "Placeholder") { … … 138 138 } 139 139 private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 140 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {140 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 141 141 foreach (var item in e.OldItems) { 142 142 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 150 150 } 151 151 private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 152 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {152 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 153 153 foreach (var item in e.Items) { 154 154 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 157 157 } 158 158 private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) { 159 if (syncJobsWithOptimizers && this. JobItem.ComputeInParallel) {159 if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) { 160 160 foreach (var item in e.Items) { 161 161 this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value)); … … 174 174 syncJobsWithOptimizers = false; // don't sync with optimizers during this method 175 175 176 if (this. JobItem != null && this.JobItem.Item != null) {177 if (this. JobItem.Item is Optimization.Experiment) {178 UpdateOptimizerInExperiment(this. JobItem.OptimizerAsExperiment, optimizerJob);179 } else if (this. JobItem.Item is Optimization.BatchRun) {180 UpdateOptimizerInBatchRun(this. JobItem.OptimizerAsBatchRun, optimizerJob);176 if (this.ItemJob != null && this.ItemJob.Item != null) { 177 if (this.ItemJob.Item is Optimization.Experiment) { 178 UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerJob); 179 } else if (this.ItemJob.Item is Optimization.BatchRun) { 180 UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerJob); 181 181 } 182 182 } … … 185 185 if (!optimizerJob.ComputeInParallel) { 186 186 child.syncJobsWithOptimizers = false; 187 child. JobItem= optimizerJob;187 child.ItemJob = optimizerJob; 188 188 child.syncJobsWithOptimizers = true; 189 189 } … … 236 236 internal void SetIndexInParentOptimizerList(OptimizerHiveJob parentHiveJob) { 237 237 if (parentHiveJob != null) { 238 if (parentHiveJob. JobItem.Item is Optimization.Experiment) {239 this. JobItem.IndexInParentOptimizerList = parentHiveJob.JobItem.OptimizerAsExperiment.Optimizers.IndexOf(this.JobItem.Item);240 } else if (parentHiveJob. JobItem.Item is Optimization.BatchRun) {241 this. JobItem.IndexInParentOptimizerList = 0;238 if (parentHiveJob.ItemJob.Item is Optimization.Experiment) { 239 this.ItemJob.IndexInParentOptimizerList = parentHiveJob.ItemJob.OptimizerAsExperiment.Optimizers.IndexOf(this.ItemJob.Item); 240 } else if (parentHiveJob.ItemJob.Item is Optimization.BatchRun) { 241 this.ItemJob.IndexInParentOptimizerList = 0; 242 242 } else { 243 243 throw new NotSupportedException("Only Experiment and BatchRuns are supported"); … … 253 253 var optimizerHiveJob = (OptimizerHiveJob)hiveJob; 254 254 syncJobsWithOptimizers = false; 255 if (this. JobItem != null && optimizerHiveJob.JobItem!= null) {255 if (this.ItemJob != null && optimizerHiveJob.ItemJob != null) { 256 256 // if job is in state Paused, it has to preserve its ResultCollection, which is cleared when a optimizer is added to an experiment 257 257 OptimizerJob optimizerJobClone = null; 258 258 if (optimizerHiveJob.Job.State == JobState.Paused) { 259 optimizerJobClone = (OptimizerJob)optimizerHiveJob. JobItem.Clone();260 } 261 262 if (this. JobItem.Item is Optimization.Experiment) {263 if (!this. JobItem.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.JobItem.Item)) {264 UpdateOptimizerInExperiment(this. JobItem.OptimizerAsExperiment, optimizerHiveJob.JobItem);259 optimizerJobClone = (OptimizerJob)optimizerHiveJob.ItemJob.Clone(); 260 } 261 262 if (this.ItemJob.Item is Optimization.Experiment) { 263 if (!this.ItemJob.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.ItemJob.Item)) { 264 UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerHiveJob.ItemJob); 265 265 } 266 } else if (this. JobItem.Item is Optimization.BatchRun) {267 UpdateOptimizerInBatchRun(this. JobItem.OptimizerAsBatchRun, optimizerHiveJob.JobItem);266 } else if (this.ItemJob.Item is Optimization.BatchRun) { 267 UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerHiveJob.ItemJob); 268 268 } 269 269 270 270 if (optimizerHiveJob.Job.State == JobState.Paused) { 271 optimizerHiveJob. JobItem= optimizerJobClone;271 optimizerHiveJob.ItemJob = optimizerJobClone; 272 272 } 273 273 } … … 283 283 public override JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) { 284 284 plugins = new List<IPluginDescription>(); 285 if (this. jobItem== null) // || this.jobItem.Optimizer == null285 if (this.itemJob == null) // || this.jobItem.Optimizer == null 286 286 return null; 287 287 288 288 IEnumerable<Type> usedTypes; 289 289 byte[] jobByteArray; 290 if (withoutChildOptimizers && this. JobItem.Item is Optimization.Experiment) {291 OptimizerJob clonedJob = (OptimizerJob)this. JobItem.Clone(); // use a cloned job, so that the childHiveJob don't get confused290 if (withoutChildOptimizers && this.ItemJob.Item is Optimization.Experiment) { 291 OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone(); // use a cloned job, so that the childHiveJob don't get confused 292 292 clonedJob.OptimizerAsExperiment.Optimizers.Clear(); 293 293 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 294 } else if (withoutChildOptimizers && this. JobItem.Item is Optimization.BatchRun) {295 OptimizerJob clonedJob = (OptimizerJob)this. JobItem.Clone();294 } else if (withoutChildOptimizers && this.ItemJob.Item is Optimization.BatchRun) { 295 OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone(); 296 296 clonedJob.OptimizerAsBatchRun.Optimizer = null; 297 297 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 298 } else if (this. JobItem.Item is IAlgorithm) {299 ((IAlgorithm)this. JobItem.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size300 jobByteArray = PersistenceUtil.Serialize(this. JobItem, out usedTypes);298 } else if (this.ItemJob.Item is IAlgorithm) { 299 ((IAlgorithm)this.ItemJob.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size 300 jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes); 301 301 } else { 302 jobByteArray = PersistenceUtil.Serialize(this. JobItem, out usedTypes);302 jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes); 303 303 } 304 304 … … 315 315 public OptimizerHiveJob GetChildByOptimizerJob(OptimizerJob optimizerJob) { 316 316 foreach (OptimizerHiveJob child in ChildHiveJobs) { 317 if (child. JobItem== optimizerJob)317 if (child.ItemJob == optimizerJob) 318 318 return child; 319 319 } … … 323 323 public HiveJob<OptimizerJob> GetChildByOptimizer(IOptimizer optimizer) { 324 324 foreach (OptimizerHiveJob child in ChildHiveJobs) { 325 if (child. JobItem.Item == optimizer)325 if (child.ItemJob.Item == optimizer) 326 326 return child; 327 327 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/RefreshableHiveExperiment.cs
r6168 r6178 34 34 public class RefreshableHiveExperiment : IHiveItem, IDeepCloneable, IContent, IProgressReporter { 35 35 private JobResultPoller jobResultPoller; 36 private JobDownloader<ItemJob> jobDownloader = newJobDownloader<ItemJob>(2, 2);36 private ConcurrentJobDownloader<ItemJob> jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2); 37 37 private static object locker = new object(); 38 38 … … 83 83 } 84 84 85 [Storable] 86 private bool isControllable = true; 87 public bool IsControllable { 88 get { return isControllable; } 89 set { 90 if (value != isControllable) { 91 isControllable = value; 92 OnIsControllableChanged(); 93 } 94 } 95 } 96 85 97 #region Constructors and Cloning 86 98 public RefreshableHiveExperiment() { … … 99 111 this.RefreshAutomatically = original.RefreshAutomatically; 100 112 this.IncludeJobs = original.IncludeJobs; 113 this.IsControllable = original.IsControllable; 101 114 } 102 115 public IDeepCloneable Clone(Cloner cloner) { … … 163 176 jobDownloader.DownloadJob(hj.Job.Id, (id, itemJob, exception) => { 164 177 if (exception != null) { 165 throw new JobDownloaderException("Downloading job failed.", exception);178 throw new ConcurrentJobDownloaderException("Downloading job failed.", exception); 166 179 } 167 180 … … 171 184 // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare) 172 185 if (hj.Job.State == JobState.Paused) { 173 hj. JobItem= itemJob;186 hj.ItemJob = itemJob; 174 187 } else { 175 188 if (lightweightJob.ParentJobId.HasValue) { … … 177 190 parentHiveJob.IntegrateChild(itemJob, hj.Job.Id); 178 191 } else { 179 hj. JobItem= itemJob;192 hj.ItemJob = itemJob; 180 193 } 181 194 } … … 211 224 212 225 public bool AllJobsFinished() { 213 return hiveExperiment.GetAllHiveJobs().All(j => j.Job.State == JobState.Finished 214 || j.Job.State == JobState.Aborted 215 || j.Job.State == JobState.Failed); 226 return hiveExperiment.GetAllHiveJobs().All(j => (j.Job.State == JobState.Finished 227 || j.Job.State == JobState.Aborted 228 || j.Job.State == JobState.Failed) 229 && j.ItemJobDownloaded); 216 230 } 217 231 … … 299 313 if (handler != null) handler(sender, e); 300 314 } 315 316 public event EventHandler IsControllableChanged; 317 private void OnIsControllableChanged() { 318 var handler = IsControllableChanged; 319 if (handler != null) handler(this, EventArgs.Empty); 320 } 301 321 #endregion 302 322 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj
r6168 r6178 120 120 <Compile Include="Exceptions\JobResultPollingException.cs" /> 121 121 <Compile Include="Exceptions\OptimizerNotFoundException.cs" /> 122 <Compile Include="ExperimentManager\JobDownloader.cs" /> 122 <Compile Include="ExperimentManager\ConcurrentJobDownloader.cs" /> 123 <Compile Include="ExperimentManager\EngineHiveJob.cs" /> 123 124 <Compile Include="ExperimentManager\ExperimentManagerClient.cs" /> 124 125 <Compile Include="ExperimentManager\HiveJobDownloader.cs" /> 125 <Compile Include="ExperimentManager\ JobDownloaderException.cs" />126 <Compile Include="ExperimentManager\ConcurrentJobDownloaderException.cs" /> 126 127 <Compile Include="ExperimentManager\TreeView\IItemTree.cs" /> 127 128 <Compile Include="ExperimentManager\TreeView\IItemTreeAction.cs" /> … … 145 146 <None Include="Properties\AssemblyInfo.cs.frame" /> 146 147 <Compile Include="Exceptions\ServiceClientFactoryException.cs" /> 148 <Compile Include="ScopeExtensions.cs" /> 147 149 <Compile Include="ServiceClients\Appointment.cs" /> 148 150 <Compile Include="ServiceClients\HiveItemCollection.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs
r6111 r6178 72 72 73 73 protected override void RegisterItemEvents() { 74 base.RegisterItemEvents(); 74 75 Item.Stopped += new EventHandler(engine_Stopped); 76 Item.Paused += new EventHandler(Item_Paused); 77 Item.Started += new EventHandler(Item_Started); 75 78 Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred); 79 Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged); 80 Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged); 76 81 } 77 82 78 83 protected override void DeregisterItemEvents() { 79 84 Item.Stopped -= new EventHandler(engine_Stopped); 85 Item.Paused -= new EventHandler(Item_Paused); 86 Item.Started -= new EventHandler(Item_Started); 80 87 Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred); 88 Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged); 89 Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged); 90 base.DeregisterItemEvents(); 81 91 } 82 92 … … 87 97 private void engine_Stopped(object sender, EventArgs e) { 88 98 OnJobStopped(); 99 } 100 101 private void Item_Paused(object sender, EventArgs e) { 102 OnJobPaused(); 103 } 104 105 private void Item_ExecutionTimeChanged(object sender, EventArgs e) { 106 OnExecutionTimeChanged(); 107 } 108 109 private void Item_ExecutionStateChanged(object sender, EventArgs e) { 110 OnExecutionStateChanged(); 111 } 112 113 private void Item_Started(object sender, EventArgs e) { 114 OnJobStarted(); 89 115 } 90 116 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/Program.cs
r6110 r6178 48 48 GeneticAlgorithm ga = new GeneticAlgorithm(); 49 49 ga.Problem = new SingleObjectiveTestFunctionProblem(); 50 ga.Engine = new HiveEngine(); 51 ga.PopulationSize.Value = 3; 50 ga.Engine = new HiveEngine(); 51 ga.Elites.Value = 0; 52 ga.PopulationSize.Value = 4; 52 53 ga.MaximumGenerations.Value = 3; 53 54 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.4/HiveEngine.cs
r6111 r6178 7 7 using HeuristicLab.Common; 8 8 using HeuristicLab.Core; 9 using HeuristicLab.Hive; 9 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 11 using HeuristicLab.PluginInfrastructure; … … 140 141 141 142 IScope[] scopes = ExecuteOnHive(jobs, parentScopeClone, cancellationToken); 142 143 //IScope[] scopes = ExecuteLocally(jobs, parentScopeClone, cancellationToken); 144 143 145 for (int i = 0; i < coll.Count; i++) { 144 146 if (coll[i] is IAtomicOperation) { … … 203 205 204 206 // testfunction: 205 //private IScope[] ExecuteLocally(EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) { 206 // IScope[] scopes = new Scope[jobs.Length]; 207 // for (int i = 0; i < jobs.Length; i++) { 208 // var job = (EngineJob)jobs[i].Clone(); 209 // job.Start(); 210 // while (job.ExecutionState != ExecutionState.Stopped) { 211 // Thread.Sleep(100); 212 // } 213 // scopes[i] = ((IAtomicOperation)job.InitialOperation).Scope; 214 // } 215 // return scopes; 216 //} 207 private IScope[] ExecuteLocally(EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) { 208 IScope[] scopes = new Scope[jobs.Length]; 209 for (int i = 0; i < jobs.Length; i++) { 210 var serialized = PersistenceUtil.Serialize(jobs[i]); 211 var deserialized = PersistenceUtil.Deserialize<IJob>(serialized); 212 deserialized.Start(); 213 while (deserialized.ExecutionState != ExecutionState.Stopped) { 214 Thread.Sleep(100); 215 } 216 var serialized2 = PersistenceUtil.Serialize(deserialized); 217 var deserialized2 = PersistenceUtil.Deserialize<EngineJob>(serialized2); 218 var newScope = ((IAtomicOperation)deserialized2.InitialOperation).Scope; 219 scopes[i] = newScope; 220 } 221 return scopes; 222 } 217 223 218 224 /// <summary> … … 230 236 try { 231 237 List<Guid> remainingJobIds = new List<Guid>(); 232 List<LightweightJob> lightweightJobs;233 234 int finishedCount = 0;235 int uploadCount = 0;236 238 237 239 // create hive experiment 238 240 hiveExperiment.Name = "HiveEngine Run " + hiveExperiments.Count; 241 hiveExperiment.DateCreated = DateTime.Now; 239 242 hiveExperiment.UseLocalPlugins = this.UseLocalPlugins; 240 243 hiveExperiment.ResourceNames = this.ResourceNames; 241 hiveExperiment.Id = ServiceLocator.Instance.CallHiveService(s => s.AddHiveExperiment(hiveExperiment));242 244 var refreshableHiveExperiment = new RefreshableHiveExperiment(hiveExperiment); 245 refreshableHiveExperiment.IsControllable = false; 243 246 hiveExperiments.Add(refreshableHiveExperiment); 244 247 … … 246 249 var uploadTasks = new List<Task<Job>>(); 247 250 for (int i = 0; i < jobs.Length; i++) { 248 var job = jobs[i];251 hiveExperiment.HiveJobs.Add(new EngineHiveJob(jobs[i], parentScopeClone)); 249 252 250 253 // shuffle random variable to avoid the same random sequence in each operation; todo: does not yet work (it cannot find the random variable) 251 IRandom random = FindRandomParameter(job .InitialOperation as IExecutionContext);254 IRandom random = FindRandomParameter(jobs[i].InitialOperation as IExecutionContext); 252 255 if (random != null) 253 256 random.Reset(random.Next()); 254 255 uploadTasks.Add(Task.Factory.StartNew<Job>((keyValuePairObj) => { 256 return UploadJob(keyValuePairObj, parentScopeClone, cancellationToken, GetResourceIds(), hiveExperiment.Id); 257 }, new KeyValuePair<int, EngineJob>(i, job), cancellationToken)); 258 } 259 260 Task processUploadedJobsTask = new Task(() => { 261 // process finished upload-tasks 262 int uploadTasksCount = uploadTasks.Count; 263 for (int i = 0; i < uploadTasksCount; i++) { 264 cancellationToken.ThrowIfCancellationRequested(); 265 266 var uploadTasksArray = uploadTasks.ToArray(); 267 var task = uploadTasksArray[Task.WaitAny(uploadTasksArray)]; 268 if (task.Status == TaskStatus.Faulted) { 269 LogException(task.Exception); 270 throw task.Exception; 271 } 272 273 int key = ((KeyValuePair<int, EngineJob>)task.AsyncState).Key; 274 Job job = task.Result; 275 lock (locker) { 276 uploadCount++; 277 jobIndices.Add(job.Id, key); 278 remainingJobIds.Add(job.Id); 279 } 280 jobs[key] = null; // relax memory 281 LogMessage(string.Format("Uploaded job #{0}", key + 1, job.Id)); 282 uploadTasks.Remove(task); 283 } 284 }, cancellationToken, TaskCreationOptions.PreferFairness); 285 processUploadedJobsTask.Start(); 286 287 refreshableHiveExperiment.RefreshAutomatically = true; 288 257 } 258 ExperimentManagerClient.StartExperiment((e) => { throw e; }, refreshableHiveExperiment); 259 // do polling until experiment is finished and all jobs are downloaded 289 260 while (!refreshableHiveExperiment.AllJobsFinished()) { 290 Thread.Sleep(1000); 291 // update time 292 // handle cancellation 293 } 294 295 296 297 // poll job-statuses and create tasks for those which are finished 298 var downloadTasks = new List<Task<EngineJob>>(); 299 var executionTimes = new List<TimeSpan>(); 300 var executionTimeOnHiveBefore = executionTimeOnHive; 301 while (processUploadedJobsTask.Status != TaskStatus.RanToCompletion || remainingJobIds.Count > 0) { 302 cancellationToken.ThrowIfCancellationRequested(); 303 304 Thread.Sleep(10000); 305 try { 306 lightweightJobs = ServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobs(remainingJobIds)); 307 308 var jobsFinished = lightweightJobs.Where(j => j.State == JobState.Finished || j.State == JobState.Failed || j.State == JobState.Aborted); 309 finishedCount += jobsFinished.Count(); 310 if (jobsFinished.Count() > 0) LogMessage(string.Format("Finished: {0}/{1}", finishedCount, jobs.Length)); 311 ExecutionTimeOnHive = executionTimeOnHiveBefore + executionTimes.Sum() + lightweightJobs.Select(x => x.ExecutionTime.HasValue ? x.ExecutionTime.Value : TimeSpan.Zero).Sum(); 312 313 foreach (var result in jobsFinished) { 314 if (result.State == JobState.Finished) { 315 downloadTasks.Add(Task.Factory.StartNew<EngineJob>((jobIdObj) => { 316 return DownloadJob(jobIndices, jobIdObj, cancellationToken); 317 }, result.Id, cancellationToken)); 318 } else if (result.State == JobState.Aborted) { 319 LogMessage(string.Format("Job #{0} aborted (id: {1})", jobIndices[result.Id] + 1, result.Id)); 320 } else if (result.State == JobState.Failed) { 321 LogMessage(string.Format("Job #{0} failed (id: {1}): {2}", jobIndices[result.Id] + 1, result.Id, result.CurrentStateLog != null ? result.CurrentStateLog.Exception : string.Empty)); 322 } 323 remainingJobIds.Remove(result.Id); 324 executionTimes.Add(result.ExecutionTime.HasValue ? result.ExecutionTime.Value : TimeSpan.Zero); 325 } 326 } 327 catch (Exception e) { 328 LogException(e); 329 } 330 } 331 332 // process finished download-tasks 333 int downloadTasksCount = downloadTasks.Count; 334 for (int i = 0; i < downloadTasksCount; i++) { 335 cancellationToken.ThrowIfCancellationRequested(); 336 337 var downloadTasksArray = downloadTasks.ToArray(); 338 var task = downloadTasksArray[Task.WaitAny(downloadTasksArray)]; 339 var jobId = (Guid)task.AsyncState; 340 if (task.Status == TaskStatus.Faulted) { 341 LogException(task.Exception); 342 throw task.Exception; 343 } 344 scopes[jobIndices[(Guid)task.AsyncState]] = ((IAtomicOperation)task.Result.InitialOperation).Scope; 345 downloadTasks.Remove(task); 346 } 347 348 LogMessage(string.Format("All jobs finished (TotalExecutionTime: {0}).", executionTimes.Sum())); 261 Thread.Sleep(500); 262 this.ExecutionTimeOnHive = TimeSpan.FromMilliseconds(hiveExperiments.Sum(x => x.HiveExperiment.ExecutionTime.TotalMilliseconds)); 263 } 264 LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableHiveExperiment.ToString(), refreshableHiveExperiment.HiveExperiment.ExecutionTime)); 265 266 // get scopes 267 int j = 0; 268 foreach (var hiveJob in hiveExperiment.HiveJobs) { 269 var scope = ((IAtomicOperation) ((EngineJob)hiveJob.ItemJob).InitialOperation).Scope; 270 scopes[j++] = scope; 271 } 272 refreshableHiveExperiment.RefreshAutomatically = false; 349 273 DeleteHiveExperiment(hiveExperiment.Id); 350 351 274 return scopes; 352 275 } … … 505 428 } 506 429 507 public static class ScopeExtensions {508 public static void ClearParentScopes(this IScope scope) {509 scope.ClearParentScopes(null);510 }511 512 public static void ClearParentScopes(this IScope scope, IScope childScope) {513 if (childScope != null) {514 scope.SubScopes.Clear();515 scope.SubScopes.Add(childScope);516 }517 if (scope.Parent != null)518 scope.Parent.ClearParentScopes(scope);519 }520 }521 522 430 public static class EnumerableExtensions { 523 431 public static TimeSpan Sum(this IEnumerable<TimeSpan> times) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/Web.config
r6168 r6178 21 21 </roleManager> 22 22 <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> 23 <httpRuntime maxRequestLength="1048576" /> 23 24 </system.web> 24 25 … … 79 80 </modules>--> 80 81 <directoryBrowse enabled="true"/> 82 81 83 </system.webServer> 82 84
Note: See TracChangeset
for help on using the changeset viewer.