- Timestamp:
- 05/16/11 00:18:48 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 1 added
- 1 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/HiveJobView.cs
r6178 r6200 46 46 protected override void RegisterContentEvents() { 47 47 base.RegisterContentEvents(); 48 Content. JobItemChanged += new EventHandler(Content_JobItemChanged);48 Content.ItemJobChanged += new EventHandler(Content_JobItemChanged); 49 49 Content.JobChanged += new EventHandler(Content_JobChanged); 50 50 Content.JobStateChanged += new EventHandler(Content_JobStateChanged); … … 52 52 53 53 protected override void DeregisterContentEvents() { 54 Content. JobItemChanged -= new EventHandler(Content_JobItemChanged);54 Content.ItemJobChanged -= new EventHandler(Content_JobItemChanged); 55 55 Content.JobChanged -= new EventHandler(Content_JobChanged); 56 56 Content.JobStateChanged -= new EventHandler(Content_JobStateChanged); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/RefreshableHiveExperimentView.cs
r6198 r6200 21 21 22 22 using System; 23 using System.ComponentModel;24 23 using System.Linq; 25 24 using System.Threading; … … 58 57 base.RegisterContentEvents(); 59 58 Content.RefreshAutomaticallyChanged += new EventHandler(Content_RefreshAutomaticallyChanged); 60 Content.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged);61 59 Content.HiveExperimentChanged += new EventHandler(Content_HiveExperimentChanged); 62 60 Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged); 63 } 61 Content.JobStatisticsChanged += new EventHandler(Content_JobStatisticsChanged); 62 } 63 64 64 protected override void DeregisterContentEvents() { 65 65 Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged); 66 Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged);67 66 Content.HiveExperimentChanged -= new EventHandler(Content_HiveExperimentChanged); 68 67 Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged); 68 Content.JobStatisticsChanged -= new EventHandler(Content_JobStatisticsChanged); 69 69 base.DeregisterContentEvents(); 70 70 } … … 104 104 //includeJobsCheckBox.Checked = false; 105 105 refreshAutomaticallyCheckBox.Checked = false; 106 jobsTextBox.Text = "0";107 calculatingTextBox.Text = "0";108 finishedTextBox.Text = "0";109 106 logView.Content = null; 110 107 } else { … … 115 112 //includeJobsCheckBox.Checked = Content.IncludeJobs; 116 113 refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically; 117 jobsTextBox.Text = Content.HiveExperiment.JobCount.ToString();118 calculatingTextBox.Text = Content.HiveExperiment.CalculatingCount.ToString();119 finishedTextBox.Text = Content.HiveExperiment.FinishedCount.ToString();120 114 logView.Content = Content.Log; 121 115 } 116 Content_JobStatisticsChanged(this, EventArgs.Empty); 122 117 Content_HiveExperimentChanged(this, EventArgs.Empty); 123 118 Content_HiveJobChanged(this, EventArgs.Empty); … … 233 228 } 234 229 235 private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {236 if (InvokeRequired)237 Invoke(new PropertyChangedEventHandler(Content_PropertyChanged), sender, e);238 else {239 jobsTextBox.Text = Content.HiveExperiment.JobCount.ToString();240 calculatingTextBox.Text = Content.HiveExperiment.CalculatingCount.ToString();241 finishedTextBox.Text = Content.HiveExperiment.FinishedCount.ToString();242 }243 }244 245 230 private void Content_HiveExperimentChanged(object sender, EventArgs e) { 246 231 if (Content.HiveExperiment != null) { … … 252 237 SetEnabledStateOfControls(); 253 238 } 239 private void Content_JobStatisticsChanged(object sender, EventArgs e) { 240 if (InvokeRequired) 241 Invoke(new EventHandler(Content_JobStatisticsChanged), sender, e); 242 else { 243 if (Content != null) { 244 jobsTextBox.Text = Content.HiveExperiment.JobCount.ToString(); 245 calculatingTextBox.Text = Content.HiveExperiment.CalculatingCount.ToString(); 246 finishedTextBox.Text = Content.HiveExperiment.FinishedCount.ToString(); 247 } else { 248 jobsTextBox.Text = "0"; 249 calculatingTextBox.Text = "0"; 250 finishedTextBox.Text = "0"; 251 } 252 } 253 } 254 254 #endregion 255 255 256 256 #region Control events 257 257 private void startButton_Click(object sender, EventArgs e) { 258 ExperimentManagerClient.StartExperiment( new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex)), Content);258 ExperimentManagerClient.StartExperiment((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content); 259 259 } 260 260 private void pauseButton_Click(object sender, EventArgs e) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/ConcurrentJobDownloader.cs
r6198 r6200 21 21 22 22 public void DownloadJob(Job job, Action<Job, T, Exception> onFinishedAction) { 23 Task<JobData>.Factory.StartNew((x) => DownloadJob(x), job.Id) 24 .ContinueWith((x) => DeserializeJob(x.Result)) 25 .ContinueWith((x) => OnJobFinished(job, x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously); 23 Task<T> task = Task<JobData>.Factory.StartNew((x) => DownloadJob(x), job.Id) 24 .ContinueWith((x) => DeserializeJob(x.Result)); 25 task.ContinueWith((x) => OnJobFinished(job, x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion); 26 task.ContinueWith((x) => OnJobFailed(job, x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted); 26 27 } 27 28 28 29 private void OnJobFinished(Job job, Task<T> task, Action<Job, T, Exception> onFinishedAction) { 29 onFinishedAction(job, task.Result, task.Exception); 30 onFinishedAction(job, task.Result, null); 31 } 32 private void OnJobFailed(Job job, Task<T> task, Action<Job, T, Exception> onFinishedAction) { 33 onFinishedAction(job, task.Result, task.Exception.Flatten()); 30 34 } 31 35 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/ExperimentManagerClient.cs
r6178 r6200 239 239 } 240 240 } 241 241 242 242 /// <summary> 243 243 /// Uploads the local configuration file as plugin … … 286 286 } 287 287 288 hiveJob.Job.PluginsNeededIds = PluginUtil.GetPluginDependencies(service, this.onlinePlugins, this.alreadyUploadedPlugins, plugins, useLocalPlugins); 288 TryAndRepeat(() => { 289 hiveJob.Job.PluginsNeededIds = PluginUtil.GetPluginDependencies(service, this.onlinePlugins, this.alreadyUploadedPlugins, plugins, useLocalPlugins); 290 }, -1, "Failed to upload plugins"); 289 291 hiveJob.Job.PluginsNeededIds.Add(configPluginId); 290 292 hiveJob.Job.HiveExperimentId = hiveExperimentId; … … 293 295 progress.ProgressValue = (double)jobCount / totalJobCount; 294 296 295 if (parentHiveJob != null) { 296 hiveJob.Job.Id = service.AddChildJob(parentHiveJob.Job.Id, hiveJob.Job, jobData); 297 } else { 298 hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, groups.ToList()); 299 } 297 298 TryAndRepeat(() => { 299 if (parentHiveJob != null) { 300 hiveJob.Job.Id = service.AddChildJob(parentHiveJob.Job.Id, hiveJob.Job, jobData); 301 } else { 302 hiveJob.Job.Id = service.AddJob(hiveJob.Job, jobData, groups.ToList()); 303 } 304 }, -1, "Failed to add job"); 300 305 301 306 foreach (HiveJob child in hiveJob.ChildHiveJobs) { … … 382 387 } 383 388 } 389 390 /// <summary> 391 /// Executes the action. If it throws an exception it is repeated until repetition-count is reached. 392 /// If repetitions is -1, it is repeated infinitely. 393 /// </summary> 394 public static void TryAndRepeat(Action action, int repetitions, string errorMessage) { 395 try { action(); } 396 catch (Exception e) { 397 repetitions--; 398 if (repetitions == 0) 399 throw new HiveException(errorMessage, e); 400 TryAndRepeat(action, repetitions, errorMessage); 401 } 402 } 384 403 } 385 404 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJob.cs
r6198 r6200 86 86 itemJob = value; 87 87 RegisterItemJobEvents(); 88 On JobItemChanged();88 OnItemJobChanged(); 89 89 IsFinishedJobDownloaded = true; 90 90 } … … 166 166 protected virtual void RegisterItemJobEvents() { 167 167 if (ItemJob != null) { 168 ItemJob.ComputeInParallelChanged += new EventHandler( JobItem_ComputeInParallelChanged);169 ItemJob.ToStringChanged += new EventHandler( JobItem_ToStringChanged);168 ItemJob.ComputeInParallelChanged += new EventHandler(ItemJob_ComputeInParallelChanged); 169 ItemJob.ToStringChanged += new EventHandler(ItemJob_ToStringChanged); 170 170 } 171 171 } 172 172 protected virtual void DergisterItemJobEvents() { 173 173 if (ItemJob != null) { 174 ItemJob.ComputeInParallelChanged -= new EventHandler( JobItem_ComputeInParallelChanged);175 ItemJob.ToStringChanged -= new EventHandler( JobItem_ToStringChanged);174 ItemJob.ComputeInParallelChanged -= new EventHandler(ItemJob_ComputeInParallelChanged); 175 ItemJob.ToStringChanged -= new EventHandler(ItemJob_ToStringChanged); 176 176 } 177 177 } … … 188 188 } 189 189 190 protected virtual void JobItem_ToStringChanged(object sender, EventArgs e) {190 protected virtual void ItemJob_ToStringChanged(object sender, EventArgs e) { 191 191 this.OnToStringChanged(); 192 192 } 193 193 194 protected virtual void JobItem_ComputeInParallelChanged(object sender, EventArgs e) {194 protected virtual void ItemJob_ComputeInParallelChanged(object sender, EventArgs e) { 195 195 if (ItemJob != null && syncJobsWithOptimizers) { 196 196 this.UpdateChildHiveJobs(); … … 203 203 204 204 public override string ToString() { 205 if (itemJob != null ) {205 if (itemJob != null && itemJob.Item != null) { 206 206 return itemJob.ToString(); 207 207 } else { 208 return base.ToString();208 return Job.Id.ToString(); 209 209 } 210 210 } … … 262 262 } 263 263 264 public event EventHandler JobItemChanged;265 private void On JobItemChanged() {266 JobItem_ComputeInParallelChanged(this, EventArgs.Empty);267 var handler = JobItemChanged;264 public event EventHandler ItemJobChanged; 265 private void OnItemJobChanged() { 266 ItemJob_ComputeInParallelChanged(this, EventArgs.Empty); 267 var handler = ItemJobChanged; 268 268 if (handler != null) handler(this, EventArgs.Empty); 269 269 } … … 410 410 public virtual void IntegrateChild(ItemJob job, Guid childJobId) { } 411 411 412 /// <summary> 413 /// Delete ItemJob 414 /// </summary> 415 public void ClearData() { 416 this.ItemJob.Item = null; 417 } 412 418 } 413 419 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/RefreshableHiveExperiment.cs
r6199 r6200 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Hive; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;31 30 32 31 namespace HeuristicLab.Clients.Hive { 33 [StorableClass]34 32 public class RefreshableHiveExperiment : IHiveItem, IDeepCloneable, IContent, IProgressReporter { 35 33 private JobResultPoller jobResultPoller; … … 37 35 private static object locker = new object(); 38 36 39 [Storable]40 37 private HiveExperiment hiveExperiment; 41 38 public HiveExperiment HiveExperiment { … … 55 52 56 53 /** include jobs when refreshing **/ 57 [Storable]58 54 private bool includeJobs; 59 55 public bool IncludeJobs { … … 62 58 } 63 59 64 [Storable]65 60 private bool refreshAutomatically; 66 61 public bool RefreshAutomatically { … … 83 78 } 84 79 85 [Storable]86 80 private bool isControllable = true; 87 81 public bool IsControllable { … … 95 89 } 96 90 97 [Storable]98 91 private ILog log; 99 92 public ILog Log { … … 120 113 cloner.RegisterClonedObject(original, this); 121 114 this.HiveExperiment = original.HiveExperiment; 122 this.RefreshAutomatically = original.RefreshAutomatically;123 115 this.IncludeJobs = original.IncludeJobs; 124 116 this.IsControllable = original.IsControllable; 125 117 this.Log = cloner.Clone(original.Log); 118 this.RefreshAutomatically = false; // do not start results polling automatically 126 119 } 127 120 public IDeepCloneable Clone(Cloner cloner) { … … 196 189 197 190 if (exception != null) { 198 var ex = new ConcurrentJobDownloaderException("Downloading job failed .", exception);191 var ex = new ConcurrentJobDownloaderException("Downloading job failed", exception); 199 192 LogException(ex); 200 193 localHiveJob.IsDownloading = false; … … 206 199 } else { 207 200 // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare) 208 209 201 210 202 if (localJob.State == JobState.Paused) { … … 231 223 } 232 224 UpdateTotalExecutionTime(); 233 UpdateStat s();225 UpdateStatistics(); 234 226 } 235 227 … … 237 229 private void LogException(Exception exception) { 238 230 lock (logLocker) { 239 log.LogException(exception);231 this.log.LogException(exception); 240 232 } 241 233 } … … 243 235 private void LogMessage(string message) { 244 236 lock (logLocker) { 245 log.LogMessage(message);237 this.log.LogMessage(message); 246 238 } 247 239 } … … 256 248 } 257 249 258 private void UpdateStat s() {250 private void UpdateStatistics() { 259 251 var jobs = hiveExperiment.GetAllHiveJobs(); 260 252 hiveExperiment.JobCount = jobs.Count(); 261 253 hiveExperiment.CalculatingCount = jobs.Count(j => j.Job.State == JobState.Calculating); 262 254 hiveExperiment.FinishedCount = jobs.Count(j => j.Job.State == JobState.Finished); 255 OnJobStatisticsChanged(); 263 256 } 264 257 … … 269 262 && j.IsFinishedJobDownloaded); 270 263 } 271 272 //public bool AllJobsFinishedAndDownloaded() {273 // return this.AllJobsFinished() && hiveExperiment.GetAllHiveJobs().All(j => j.JobItem.;274 //}275 264 276 265 private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) { … … 359 348 if (handler != null) handler(this, EventArgs.Empty); 360 349 } 350 351 public event EventHandler JobStatisticsChanged; 352 private void OnJobStatisticsChanged() { 353 var handler = JobStatisticsChanged; 354 if (handler != null) handler(this, EventArgs.Empty); 355 } 361 356 #endregion 362 357 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj
r6178 r6200 123 123 <Compile Include="ExperimentManager\EngineHiveJob.cs" /> 124 124 <Compile Include="ExperimentManager\ExperimentManagerClient.cs" /> 125 <Compile Include="Exceptions\HiveException.cs" /> 125 126 <Compile Include="ExperimentManager\HiveJobDownloader.cs" /> 126 127 <Compile Include="ExperimentManager\ConcurrentJobDownloaderException.cs" /> … … 155 156 <Compile Include="ServiceClients\HiveItem.cs" /> 156 157 <Compile Include="ServiceClients\JobData.cs" /> 157 <Compile Include="ServiceClients\OperationJob.cs" />158 158 <Compile Include="ExperimentManager\RefreshableHiveExperiment.cs" /> 159 159 <Compile Include="ServiceClients\Plugin.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs
r6178 r6200 129 129 130 130 public override string Name { 131 get { return Item .ToString(); }131 get { return Item != null ? Item.ToString() : null; } 132 132 set { throw new NotSupportedException(); } 133 133 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Progress/Progress.cs
r4629 r6200 64 64 private void OnFinished() { 65 65 var handler = Finished; 66 if (handler != null) handler(this, EventArgs.Empty); 66 try { 67 if (handler != null) handler(this, EventArgs.Empty); 68 } 69 catch (Exception) { } 67 70 } 68 71 … … 70 73 private void OnStatusChanged() { 71 74 var handler = StatusChanged; 72 if (handler != null) handler(this, EventArgs.Empty); 75 try { 76 if (handler != null) handler(this, EventArgs.Empty); 77 } 78 catch (Exception) { } 73 79 } 74 80 … … 76 82 private void OnProgressChanged() { 77 83 var handler = ProgressValueChanged; 78 if (handler != null) handler(this, EventArgs.Empty); 84 try { 85 if (handler != null) handler(this, EventArgs.Empty); 86 } 87 catch (Exception) { } 79 88 } 80 89 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs
r6168 r6200 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;29 28 30 29 namespace HeuristicLab.Clients.Hive { 31 [StorableClass]32 30 public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter { 33 [Storable]34 31 private bool useLocalPlugins; 35 32 public bool UseLocalPlugins { … … 38 35 } 39 36 40 [Storable]41 37 private ExecutionState executionState; 42 38 public ExecutionState ExecutionState { … … 50 46 } 51 47 52 [Storable]53 48 private TimeSpan executionTime; 54 49 public TimeSpan ExecutionTime { … … 62 57 } 63 58 64 [Storable]65 59 private ItemCollection<HiveJob> hiveJobs; 66 60 public ItemCollection<HiveJob> HiveJobs { … … 74 68 } 75 69 76 [Storable]77 70 private bool isProgressing; 78 71 public bool IsProgressing { … … 86 79 } 87 80 88 [Storable]89 81 private IProgress progress; 90 82 public IProgress Progress { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItem.cs
r5955 r6200 28 28 29 29 namespace HeuristicLab.Clients.Hive { 30 31 30 public partial class HiveItem : IHiveItem { 32 31 public string ItemName { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItemCollection.cs
r5955 r6200 6 6 7 7 namespace HeuristicLab.Clients.Hive { 8 [Item("HiveItem Collection", "Represents a collection of OKBitems.")]8 [Item("HiveItem Collection", "Represents a collection of Hive items.")] 9 9 public class HiveItemCollection<T> : ItemCollection<T> where T : class, IHiveItem { 10 10 protected HiveItemCollection(HiveItemCollection<T> original, Cloner cloner) : base(original, cloner) { } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Job.cs
r6006 r6200 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;26 25 27 26 namespace HeuristicLab.Clients.Hive { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/JobData.cs
r5779 r6200 24 24 25 25 namespace HeuristicLab.Clients.Hive { 26 27 26 public partial class JobData : IDeepCloneable, IContent { 28 27 public JobData() { } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/MessageContainer.cs
r5614 r6200 22 22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;25 24 26 25 namespace HeuristicLab.Clients.Hive { 27 [StorableClass]28 26 public partial class MessageContainer : IDeepCloneable, IContent { 29 27 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive 3.4.sln
r6116 r6200 276 276 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Debug|x86.ActiveCfg = Debug|x86 277 277 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Debug|x86.Build.0 = Debug|x86 278 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Release|Any CPU.ActiveCfg = Release|x86 278 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Release|Any CPU.ActiveCfg = Release|Any CPU 279 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Release|Any CPU.Build.0 = Release|Any CPU 279 280 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Release|Mixed Platforms.ActiveCfg = Release|x86 280 281 {BA8001DE-E83C-4B1F-8B2E-2695C4222491}.Release|Mixed Platforms.Build.0 = Release|x86 … … 290 291 {28711372-0255-4883-9BED-81E150D73880}.Debug|x86.Build.0 = Debug 291 292 {28711372-0255-4883-9BED-81E150D73880}.Release|Any CPU.ActiveCfg = Release 293 {28711372-0255-4883-9BED-81E150D73880}.Release|Any CPU.Build.0 = Release 292 294 {28711372-0255-4883-9BED-81E150D73880}.Release|Mixed Platforms.ActiveCfg = Release 293 295 {28711372-0255-4883-9BED-81E150D73880}.Release|x64.ActiveCfg = Release … … 301 303 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Debug|x86.ActiveCfg = Debug|x86 302 304 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Debug|x86.Build.0 = Debug|x86 303 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|Any CPU.ActiveCfg = Release|x86 305 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|Any CPU.ActiveCfg = Release|Any CPU 306 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|Any CPU.Build.0 = Release|Any CPU 304 307 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|Mixed Platforms.ActiveCfg = Release|x86 305 308 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|Mixed Platforms.Build.0 = Release|x86 … … 397 400 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Debug|x86.ActiveCfg = Debug|x86 398 401 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Debug|x86.Build.0 = Debug|x86 399 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Release|Any CPU.ActiveCfg = Release|x86 402 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Release|Any CPU.ActiveCfg = Release|Any CPU 403 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Release|Any CPU.Build.0 = Release|Any CPU 400 404 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Release|Mixed Platforms.ActiveCfg = Release|x86 401 405 {87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}.Release|Mixed Platforms.Build.0 = Release|x86 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.4/HiveEngine.cs
r6198 r6200 7 7 using HeuristicLab.Common; 8 8 using HeuristicLab.Core; 9 using HeuristicLab.Hive;10 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 11 using HeuristicLab.PluginInfrastructure;12 10 13 11 namespace HeuristicLab.HiveEngine { … … 18 16 [Item("Hive Engine", "Engine for parallel execution on the hive. You need enable `Parallel` for at least one operator in your operator graph to have all childoperations parallelized. Also those childoperations must not have sideeffects on a higher scope.")] 19 17 public class HiveEngine : Engine { 20 private Semaphore maxConcurrentConnections = new Semaphore(4, 4); // avoid too many connections 21 private Semaphore maxSerializedJobsInMemory = new Semaphore(4, 4); // avoid memory problems 18 private static object logLocker = new object(); 22 19 private CancellationToken cancellationToken; 23 20 24 21 [Storable] 25 22 private IOperator currentOperator; … … 54 51 } 55 52 56 [Storable]57 private ItemCollection<RefreshableHiveExperiment> hiveExperiments ;53 // [Storable] -> HiveExperiment can't be storable, so RefreshableHiveExperiment can't be stored 54 private ItemCollection<RefreshableHiveExperiment> hiveExperiments = new ItemCollection<RefreshableHiveExperiment>(); 58 55 public ItemCollection<RefreshableHiveExperiment> HiveExperiments { 59 56 get { return hiveExperiments; } … … 76 73 public HiveEngine() { 77 74 ResourceNames = "HEAL"; 78 HiveExperiments = new ItemCollection<RefreshableHiveExperiment>();79 75 Priority = 0; 80 76 } … … 89 85 this.executionTimeOnHive = original.executionTimeOnHive; 90 86 this.useLocalPlugins = original.useLocalPlugins; 87 this.hiveExperiments = cloner.Clone(original.hiveExperiments); 91 88 } 92 89 public override IDeepCloneable Clone(Cloner cloner) { … … 202 199 target.SubScopes.AddRange(source.SubScopes); 203 200 // TODO: validate if parent scopes match - otherwise source is invalid 204 }205 206 // testfunction: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 201 } 223 202 … … 256 235 random.Reset(random.Next()); 257 236 } 258 ExperimentManagerClient.StartExperiment((e) => { throw e; }, refreshableHiveExperiment); 237 ExperimentManagerClient.StartExperiment((e) => { 238 LogException(e); 239 }, refreshableHiveExperiment); 240 259 241 // do polling until experiment is finished and all jobs are downloaded 260 242 while (!refreshableHiveExperiment.AllJobsFinished()) { … … 273 255 refreshableHiveExperiment.RefreshAutomatically = false; 274 256 DeleteHiveExperiment(hiveExperiment.Id); 257 ClearData(refreshableHiveExperiment); 275 258 return scopes; 276 259 } … … 290 273 } 291 274 275 private void ClearData(RefreshableHiveExperiment refreshableHiveExperiment) { 276 var jobs = refreshableHiveExperiment.HiveExperiment.GetAllHiveJobs(); 277 foreach (var job in jobs) { 278 job.ClearData(); 279 } 280 } 281 292 282 private void DeleteHiveExperiment(Guid hiveExperimentId) { 293 TryAndRepeat(() => {283 ExperimentManagerClient.TryAndRepeat(() => { 294 284 ServiceLocator.Instance.CallHiveService(s => s.DeleteHiveExperiment(hiveExperimentId)); 295 285 }, 5, string.Format("Could not delete jobs")); 296 286 } 297 298 private static object locker = new object(); 299 private Job UploadJob(object keyValuePairObj, IScope parentScopeClone, CancellationToken cancellationToken, List<Guid> resourceIds, Guid hiveExperimentId) { 300 var keyValuePair = (KeyValuePair<int, EngineJob>)keyValuePairObj; 301 Job job = new Job(); 302 303 try { 304 maxSerializedJobsInMemory.WaitOne(); 305 JobData jobData = new JobData(); 306 IEnumerable<Type> usedTypes; 307 308 // clone operation and remove unnecessary scopes; don't do this earlier to avoid memory problems 309 lock (locker) { 310 ((IAtomicOperation)keyValuePair.Value.InitialOperation).Scope.Parent = parentScopeClone; 311 keyValuePair.Value.InitialOperation = (IOperation)keyValuePair.Value.InitialOperation.Clone(); 312 if (keyValuePair.Value.InitialOperation is IAtomicOperation) 313 ((IAtomicOperation)keyValuePair.Value.InitialOperation).Scope.ClearParentScopes(); 314 jobData.Data = PersistenceUtil.Serialize(keyValuePair.Value, out usedTypes); 315 } 316 var neededPlugins = new List<IPluginDescription>(); 317 318 bool useAllLocalPlugins = true; 319 if (useAllLocalPlugins) { 320 // use all plugins 321 neededPlugins.AddRange(ApplicationManager.Manager.Plugins); 322 } else { 323 // use only 324 PluginUtil.CollectDeclaringPlugins(neededPlugins, usedTypes); 325 } 326 327 job.CoresNeeded = 1; 328 job.PluginsNeededIds = ServiceLocator.Instance.CallHiveService(s => PluginUtil.GetPluginDependencies(s, this.OnlinePlugins, this.AlreadyUploadedPlugins, neededPlugins, useLocalPlugins)); 329 job.Priority = priority; 330 job.HiveExperimentId = hiveExperimentId; 331 332 try { 333 maxConcurrentConnections.WaitOne(); 334 while (job.Id == Guid.Empty) { // repeat until success 335 cancellationToken.ThrowIfCancellationRequested(); 336 try { 337 job.Id = ServiceLocator.Instance.CallHiveService(s => s.AddJob(job, jobData, resourceIds)); 338 } 339 catch (Exception e) { 340 LogException(e); 341 LogMessage("Repeating upload"); 342 } 343 } 344 } 345 finally { 346 maxConcurrentConnections.Release(); 347 } 348 } 349 finally { 350 maxSerializedJobsInMemory.Release(); 351 } 352 return job; 353 } 354 287 355 288 private List<Guid> GetResourceIds() { 356 289 return ServiceLocator.Instance.CallHiveService(service => { … … 368 301 } 369 302 370 private EngineJob DownloadJob(IDictionary<Guid, int> jobIndices, object jobIdObj, CancellationToken cancellationToken) {371 Guid jobId = (Guid)jobIdObj;372 JobData jobData = null;373 EngineJob engineJob = null;374 try {375 maxSerializedJobsInMemory.WaitOne();376 maxConcurrentConnections.WaitOne();377 while (jobData == null) { // repeat until success378 cancellationToken.ThrowIfCancellationRequested();379 try {380 jobData = ServiceLocator.Instance.CallHiveService(s => s.GetJobData(jobId));381 }382 catch (Exception e) {383 LogException(e);384 LogMessage("Repeating download");385 }386 }387 engineJob = PersistenceUtil.Deserialize<EngineJob>(jobData.Data);388 jobData = null;389 LogMessage(string.Format("Downloaded job #{0}", jobIndices[jobId] + 1, jobId));390 }391 finally {392 maxConcurrentConnections.Release();393 maxSerializedJobsInMemory.Release();394 }395 return engineJob;396 }397 398 303 /// <summary> 399 304 /// Threadsafe message logging 400 305 /// </summary> 401 306 private void LogMessage(string message) { 402 lock ( Log) {307 lock (logLocker) { 403 308 Log.LogMessage(message); 404 309 } … … 409 314 /// </summary> 410 315 private void LogException(Exception exception) { 411 lock ( Log) {316 lock (logLocker) { 412 317 Log.LogException(exception); 413 318 } 414 319 } 415 320 416 /// <summary> 417 /// Executes the action. If it throws an exception it is repeated until repetition-count is reached. 418 /// If repetitions is -1, it is repeated infinitely. 419 /// </summary> 420 private static void TryAndRepeat(Action action, int repetitions, string errorMessage) { 421 try { action(); } 422 catch (Exception e) { 423 repetitions--; 424 if (repetitions <= 0) 425 throw new HiveEngineException(errorMessage, e); 426 TryAndRepeat(action, repetitions, errorMessage); 427 } 428 } 429 } 430 431 public static class EnumerableExtensions { 432 public static TimeSpan Sum(this IEnumerable<TimeSpan> times) { 433 return TimeSpan.FromMilliseconds(times.Select(e => e.TotalMilliseconds).Sum()); 434 } 321 // testfunction: 322 //private IScope[] ExecuteLocally(EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) { 323 // IScope[] scopes = new Scope[jobs.Length]; 324 // for (int i = 0; i < jobs.Length; i++) { 325 // var serialized = PersistenceUtil.Serialize(jobs[i]); 326 // var deserialized = PersistenceUtil.Deserialize<IJob>(serialized); 327 // deserialized.Start(); 328 // while (deserialized.ExecutionState != ExecutionState.Stopped) { 329 // Thread.Sleep(100); 330 // } 331 // var serialized2 = PersistenceUtil.Serialize(deserialized); 332 // var deserialized2 = PersistenceUtil.Deserialize<EngineJob>(serialized2); 333 // var newScope = ((IAtomicOperation)deserialized2.InitialOperation).Scope; 334 // scopes[i] = newScope; 335 // } 336 // return scopes; 337 //} 435 338 } 436 339 }
Note: See TracChangeset
for help on using the changeset viewer.