Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/16/11 00:18:48 (13 years ago)
Author:
cneumuel
Message:

#1233

  • stability improvements for HiveEngine
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4
Files:
1 added
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/ConcurrentJobDownloader.cs

    r6198 r6200  
    2121
    2222    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);
    2627    }
    2728
    2829    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());
    3034    }
    3135
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/ExperimentManagerClient.cs

    r6178 r6200  
    239239      }
    240240    }
    241 
     241   
    242242    /// <summary>
    243243    /// Uploads the local configuration file as plugin
     
    286286      }
    287287
    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");
    289291      hiveJob.Job.PluginsNeededIds.Add(configPluginId);
    290292      hiveJob.Job.HiveExperimentId = hiveExperimentId;
     
    293295      progress.ProgressValue = (double)jobCount / totalJobCount;
    294296
    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");
    300305
    301306      foreach (HiveJob child in hiveJob.ChildHiveJobs) {
     
    382387      }
    383388    }
     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    }
    384403  }
    385404}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJob.cs

    r6198 r6200  
    8686          itemJob = value;
    8787          RegisterItemJobEvents();
    88           OnJobItemChanged();
     88          OnItemJobChanged();
    8989          IsFinishedJobDownloaded = true;
    9090        }
     
    166166    protected virtual void RegisterItemJobEvents() {
    167167      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);
    170170      }
    171171    }
    172172    protected virtual void DergisterItemJobEvents() {
    173173      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);
    176176      }
    177177    }
     
    188188    }
    189189
    190     protected virtual void JobItem_ToStringChanged(object sender, EventArgs e) {
     190    protected virtual void ItemJob_ToStringChanged(object sender, EventArgs e) {
    191191      this.OnToStringChanged();
    192192    }
    193193
    194     protected virtual void JobItem_ComputeInParallelChanged(object sender, EventArgs e) {
     194    protected virtual void ItemJob_ComputeInParallelChanged(object sender, EventArgs e) {
    195195      if (ItemJob != null && syncJobsWithOptimizers) {
    196196        this.UpdateChildHiveJobs();
     
    203203
    204204    public override string ToString() {
    205       if (itemJob != null) {
     205      if (itemJob != null && itemJob.Item != null) {
    206206        return itemJob.ToString();
    207207      } else {
    208         return base.ToString();
     208        return Job.Id.ToString();
    209209      }
    210210    }
     
    262262    }
    263263
    264     public event EventHandler JobItemChanged;
    265     private void OnJobItemChanged() {
    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;
    268268      if (handler != null) handler(this, EventArgs.Empty);
    269269    }
     
    410410    public virtual void IntegrateChild(ItemJob job, Guid childJobId) { }
    411411
     412    /// <summary>
     413    /// Delete ItemJob
     414    /// </summary>
     415    public void ClearData() {
     416      this.ItemJob.Item = null;
     417    }
    412418  }
    413419
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/RefreshableHiveExperiment.cs

    r6199 r6200  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Hive;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130
    3231namespace HeuristicLab.Clients.Hive {
    33   [StorableClass]
    3432  public class RefreshableHiveExperiment : IHiveItem, IDeepCloneable, IContent, IProgressReporter {
    3533    private JobResultPoller jobResultPoller;
     
    3735    private static object locker = new object();
    3836
    39     [Storable]
    4037    private HiveExperiment hiveExperiment;
    4138    public HiveExperiment HiveExperiment {
     
    5552
    5653    /** include jobs when refreshing **/
    57     [Storable]
    5854    private bool includeJobs;
    5955    public bool IncludeJobs {
     
    6258    }
    6359
    64     [Storable]
    6560    private bool refreshAutomatically;
    6661    public bool RefreshAutomatically {
     
    8378    }
    8479
    85     [Storable]
    8680    private bool isControllable = true;
    8781    public bool IsControllable {
     
    9589    }
    9690
    97     [Storable]
    9891    private ILog log;
    9992    public ILog Log {
     
    120113      cloner.RegisterClonedObject(original, this);
    121114      this.HiveExperiment = original.HiveExperiment;
    122       this.RefreshAutomatically = original.RefreshAutomatically;
    123115      this.IncludeJobs = original.IncludeJobs;
    124116      this.IsControllable = original.IsControllable;
    125117      this.Log = cloner.Clone(original.Log);
     118      this.RefreshAutomatically = false; // do not start results polling automatically
    126119    }
    127120    public IDeepCloneable Clone(Cloner cloner) {
     
    196189
    197190              if (exception != null) {
    198                 var ex = new ConcurrentJobDownloaderException("Downloading job failed.", exception);
     191                var ex = new ConcurrentJobDownloaderException("Downloading job failed", exception);
    199192                LogException(ex);
    200193                localHiveJob.IsDownloading = false;
     
    206199              } else {
    207200                // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare)
    208 
    209201
    210202                if (localJob.State == JobState.Paused) {
     
    231223      }
    232224      UpdateTotalExecutionTime();
    233       UpdateStats();
     225      UpdateStatistics();
    234226    }
    235227
     
    237229    private void LogException(Exception exception) {
    238230      lock (logLocker) {
    239         log.LogException(exception);
     231        this.log.LogException(exception);
    240232      }
    241233    }
     
    243235    private void LogMessage(string message) {
    244236      lock (logLocker) {
    245         log.LogMessage(message);
     237        this.log.LogMessage(message);
    246238      }
    247239    }
     
    256248    }
    257249
    258     private void UpdateStats() {
     250    private void UpdateStatistics() {
    259251      var jobs = hiveExperiment.GetAllHiveJobs();
    260252      hiveExperiment.JobCount = jobs.Count();
    261253      hiveExperiment.CalculatingCount = jobs.Count(j => j.Job.State == JobState.Calculating);
    262254      hiveExperiment.FinishedCount = jobs.Count(j => j.Job.State == JobState.Finished);
     255      OnJobStatisticsChanged();
    263256    }
    264257
     
    269262                                                   && j.IsFinishedJobDownloaded);
    270263    }
    271 
    272     //public bool AllJobsFinishedAndDownloaded() {
    273     //  return this.AllJobsFinished() && hiveExperiment.GetAllHiveJobs().All(j => j.JobItem.;
    274     //}
    275264
    276265    private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) {
     
    359348      if (handler != null) handler(this, EventArgs.Empty);
    360349    }
     350
     351    public event EventHandler JobStatisticsChanged;
     352    private void OnJobStatisticsChanged() {
     353      var handler = JobStatisticsChanged;
     354      if (handler != null) handler(this, EventArgs.Empty);
     355    }
    361356    #endregion
    362357
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj

    r6178 r6200  
    123123    <Compile Include="ExperimentManager\EngineHiveJob.cs" />
    124124    <Compile Include="ExperimentManager\ExperimentManagerClient.cs" />
     125    <Compile Include="Exceptions\HiveException.cs" />
    125126    <Compile Include="ExperimentManager\HiveJobDownloader.cs" />
    126127    <Compile Include="ExperimentManager\ConcurrentJobDownloaderException.cs" />
     
    155156    <Compile Include="ServiceClients\HiveItem.cs" />
    156157    <Compile Include="ServiceClients\JobData.cs" />
    157     <Compile Include="ServiceClients\OperationJob.cs" />
    158158    <Compile Include="ExperimentManager\RefreshableHiveExperiment.cs" />
    159159    <Compile Include="ServiceClients\Plugin.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs

    r6178 r6200  
    129129
    130130    public override string Name {
    131       get { return Item.ToString(); }
     131      get { return Item != null ? Item.ToString() : null; }
    132132      set { throw new NotSupportedException(); }
    133133    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Progress/Progress.cs

    r4629 r6200  
    6464    private void OnFinished() {
    6565      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) { }
    6770    }
    6871
     
    7073    private void OnStatusChanged() {
    7174      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) { }
    7379    }
    7480
     
    7682    private void OnProgressChanged() {
    7783      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) { }
    7988    }
    8089    #endregion
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs

    r6168 r6200  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    3029namespace HeuristicLab.Clients.Hive {
    31   [StorableClass]
    3230  public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
    33     [Storable]
    3431    private bool useLocalPlugins;
    3532    public bool UseLocalPlugins {
     
    3835    }
    3936
    40     [Storable]
    4137    private ExecutionState executionState;
    4238    public ExecutionState ExecutionState {
     
    5046    }
    5147
    52     [Storable]
    5348    private TimeSpan executionTime;
    5449    public TimeSpan ExecutionTime {
     
    6257    }
    6358
    64     [Storable]
    6559    private ItemCollection<HiveJob> hiveJobs;
    6660    public ItemCollection<HiveJob> HiveJobs {
     
    7468    }
    7569
    76     [Storable]
    7770    private bool isProgressing;
    7871    public bool IsProgressing {
     
    8679    }
    8780
    88     [Storable]
    8981    private IProgress progress;
    9082    public IProgress Progress {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItem.cs

    r5955 r6200  
    2828
    2929namespace HeuristicLab.Clients.Hive {
    30 
    3130  public partial class HiveItem : IHiveItem {
    3231    public string ItemName {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItemCollection.cs

    r5955 r6200  
    66
    77namespace HeuristicLab.Clients.Hive {
    8   [Item("HiveItem Collection", "Represents a collection of OKB items.")]
     8  [Item("HiveItem Collection", "Represents a collection of Hive items.")]
    99  public class HiveItemCollection<T> : ItemCollection<T> where T : class, IHiveItem {
    1010    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  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Common;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625
    2726namespace HeuristicLab.Clients.Hive {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/JobData.cs

    r5779 r6200  
    2424
    2525namespace HeuristicLab.Clients.Hive {
    26 
    2726  public partial class JobData : IDeepCloneable, IContent {
    2827    public JobData() { }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/MessageContainer.cs

    r5614 r6200  
    2222using System;
    2323using HeuristicLab.Common;
    24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2524
    2625namespace HeuristicLab.Clients.Hive {
    27   [StorableClass]
    2826  public partial class MessageContainer : IDeepCloneable, IContent {
    2927
Note: See TracChangeset for help on using the changeset viewer.