Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/05/11 15:37:04 (13 years ago)
Author:
cneumuel
Message:

#1233

  • seperated ExperimentMangerClient (OKB-Style, contains business logic) and HiveExperiment (mainly only contains information)
  • fixed redundant cloning methods in dtos
  • added simple statistics in HiveExperiment which the user can see before downloading an experiment
  • added db-delete cascade for slaves and statelogs - now slaves can be safely deleted
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4
Files:
3 added
2 deleted
12 edited

Legend:

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

    r5599 r5955  
    8989        OnExceptionOccured(e);
    9090      }
     91      finally {
     92        IsPolling = false;
     93      }
    9194    }
    9295
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj

    r5852 r5955  
    120120    <Compile Include="Exceptions\JobResultPollingException.cs" />
    121121    <Compile Include="Exceptions\OptimizerNotFoundException.cs" />
     122    <Compile Include="ExperimentManager\ExperimentManagerClient.cs" />
    122123    <Compile Include="ExperimentManager\HiveJobDownloader.cs" />
    123124    <Compile Include="ExperimentManager\IItemTree.cs" />
     
    127128    <Compile Include="Jobs\OptimizerJob.cs" />
    128129    <Compile Include="HeuristicLabClientsHivePlugin.cs" />
    129     <Compile Include="ExperimentManager\HiveExperimentManagerClient.cs" />
    130130    <Compile Include="ExperimentManager\HiveJobClient.cs" />
    131     <Compile Include="ExperimentManager\HiveExperimentClient.cs" />
    132131    <Compile Include="ExperimentManager\JobResultPoller.cs" />
    133132    <Compile Include="Progress\IProgress.cs" />
     
    139138    <Compile Include="Exceptions\ServiceClientFactoryException.cs" />
    140139    <Compile Include="ServiceClients\Appointment.cs" />
     140    <Compile Include="ServiceClients\HiveItemCollection.cs" />
     141    <Compile Include="ServiceClients\IHiveItem.cs" />
    141142    <Compile Include="ServiceClients\NamedHiveItem.cs" />
    142143    <Compile Include="ServiceClients\Heartbeat.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Appointment.cs

    r5779 r5955  
    3737    }
    3838
    39     public IDeepCloneable Clone(Cloner cloner) {
     39    public override IDeepCloneable Clone(Cloner cloner) {
    4040      return new Appointment(this, cloner);
    41     }
    42 
    43     public object Clone() {
    44       return Clone(new Cloner());
    4541    }
    4642  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs

    r5779 r5955  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.ComponentModel;
     25using System.Linq;
     26using HeuristicLab.Clients.Hive.Jobs;
    2227using HeuristicLab.Common;
     28using HeuristicLab.Core;
     29using HeuristicLab.Optimization;
    2330
    2431namespace HeuristicLab.Clients.Hive {
    2532
    26   public partial class HiveExperiment : IDeepCloneable, IContent {
    27 
    28     public HiveExperiment() { }
     33  public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
     34    private JobResultPoller jobResultPoller;
     35
     36    private bool useLocalPlugins;
     37    public bool UseLocalPlugins {
     38      get { return useLocalPlugins; }
     39      set { useLocalPlugins = value; }
     40    }
     41
     42    private ExecutionState executionState;
     43    public ExecutionState ExecutionState {
     44      get { return executionState; }
     45      internal set {
     46        if (executionState != value) {
     47          executionState = value;
     48          OnExecutionStateChanged();
     49        }
     50      }
     51    }
     52
     53    private TimeSpan executionTime;
     54    public TimeSpan ExecutionTime {
     55      get { return executionTime; }
     56      internal set {
     57        if (executionTime != value) {
     58          executionTime = value;
     59          OnExecutionTimeChanged();
     60        }
     61      }
     62    }
     63
     64    private HiveJob hiveJob;
     65    public HiveJob HiveJob {
     66      get { return hiveJob; }
     67      set {
     68        DeregisterHiveJobEvents();
     69        if (hiveJob != value) {
     70          hiveJob = value;
     71          RegisterHiveJobEvents();
     72          OnHiveJobChanged();
     73        }
     74      }
     75    }
     76
     77    private bool isProgressing;
     78    public bool IsProgressing {
     79      get { return isProgressing; }
     80      set {
     81        if (isProgressing != value) {
     82          isProgressing = value;
     83          OnIsProgressingChanged();
     84        }
     85      }
     86    }
     87
     88    /** include jobs when refreshing **/
     89    private bool includeJobs;
     90    public bool IncludeJobs {
     91      get { return includeJobs; }
     92      set { includeJobs = value; }
     93    }
     94
     95    private bool refreshAutomatically;
     96    public bool RefreshAutomatically {
     97      get { return refreshAutomatically; }
     98      set {
     99        if (refreshAutomatically != value) {
     100          refreshAutomatically = value;
     101          OnRefreshAutomaticallyChanged();
     102          if (RefreshAutomatically) {
     103            StartResultPolling();
     104          } else {
     105            StopResultPolling();
     106          }
     107        }
     108      }
     109    }
     110
     111    private IProgress progress;
     112    public IProgress Progress {
     113      get { return progress; }
     114      set { this.progress = value; }
     115    }
     116
     117    #region Constructors and Cloning
     118    public HiveExperiment() {
     119      this.ResourceNames = "HEAL";
     120      this.includeJobs = true;
     121      this.refreshAutomatically = true;
     122    }
    29123
    30124    protected HiveExperiment(HiveExperiment original, Cloner cloner) {
     
    38132      this.Description = original.Description;
    39133      this.Id = original.Id;
    40     }
    41     public IDeepCloneable Clone(Cloner cloner) {
     134
     135      this.UseLocalPlugins = original.UseLocalPlugins;
     136      this.ExecutionTime = original.ExecutionTime;
     137    }
     138    public override IDeepCloneable Clone(Cloner cloner) {
    42139      return new HiveExperiment(this, cloner);
    43140    }
     141    #endregion
    44142
    45143    public override string ToString() {
    46       return base.ToString() + "Name: " + Name + ", Description: " + Description;
    47     }
    48 
    49     public object Clone() {
    50       return Clone(new Cloner());
     144      return Name;
     145    }
     146
     147    #region Events
     148    public event EventHandler ExecutionTimeChanged;
     149    private void OnExecutionTimeChanged() {
     150      EventHandler handler = ExecutionTimeChanged;
     151      if (handler != null) handler(this, EventArgs.Empty);
     152    }
     153
     154    public event EventHandler ExecutionStateChanged;
     155    private void OnExecutionStateChanged() {
     156      EventHandler handler = ExecutionStateChanged;
     157      if (handler != null) handler(this, EventArgs.Empty);
     158    }
     159
     160    public event EventHandler HiveJobChanged;
     161    private void OnHiveJobChanged() {
     162      if (jobResultPoller != null && jobResultPoller.IsPolling) {
     163        jobResultPoller.Stop();
     164        DeregisterResultPollingEvents();
     165      }
     166      if (HiveJob != null && HiveJob.Job.Id != Guid.Empty) {
     167        if (this.RefreshAutomatically)
     168          StartResultPolling();
     169      }
     170      EventHandler handler = HiveJobChanged;
     171      if (handler != null) handler(this, EventArgs.Empty);
     172    }
     173
     174    public event EventHandler IsProgressingChanged;
     175    private void OnIsProgressingChanged() {
     176      EventHandler handler = IsProgressingChanged;
     177      if (handler != null) handler(this, EventArgs.Empty);
     178    }
     179
     180    public event EventHandler RefreshAutomaticallyChanged;
     181    private void OnRefreshAutomaticallyChanged() {
     182      EventHandler handler = RefreshAutomaticallyChanged;
     183      if (handler != null) handler(this, EventArgs.Empty);
     184    }
     185    #endregion
     186
     187    private void RegisterHiveJobEvents() {
     188      if (HiveJob != null) {
     189        HiveJob.JobStateChanged += new EventHandler(HiveJob_JobStateChanged);
     190      }
     191    }
     192
     193    private void DeregisterHiveJobEvents() {
     194      if (HiveJob != null) {
     195        HiveJob.JobStateChanged -= new EventHandler(HiveJob_JobStateChanged);
     196      }
     197    }
     198
     199    private void HiveJob_JobStateChanged(object sender, EventArgs e) {
     200      if (this.HiveJob != null) {
     201        this.RootJobId = HiveJob.Job.Id;
     202      }
     203    }
     204
     205    public Experiment GetExperiment() {
     206      if (this.HiveJob != null) {
     207        return HiveJob.OptimizerJob.OptimizerAsExperiment;
     208      }
     209      return null;
     210    }
     211
     212    public void SetExperiment(Experiment experiment) {
     213      this.HiveJob = new HiveJob(experiment);
     214    }
     215
     216    protected override void OnPropertyChanged(PropertyChangedEventArgs e) {
     217      base.OnPropertyChanged(e);
     218      if (e.PropertyName == "Name") {
     219        OnToStringChanged();
     220      }
     221    }
     222
     223    #region JobResultPoller Events
     224
     225    public void StartResultPolling() {
     226      if (jobResultPoller == null) {
     227        jobResultPoller = new JobResultPoller(HiveJob, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants
     228        RegisterResultPollingEvents();
     229      }
     230
     231      if (!jobResultPoller.IsPolling) {
     232        jobResultPoller.Start();
     233      }
     234    }
     235
     236    public void StopResultPolling() {
     237      if (jobResultPoller.IsPolling) {
     238        jobResultPoller.Stop();
     239      }
     240    }
     241
     242    private void RegisterResultPollingEvents() {
     243      jobResultPoller.ExceptionOccured += new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured);
     244      jobResultPoller.JobResultsReceived += new EventHandler<EventArgs<IEnumerable<LightweightJob>>>(jobResultPoller_JobResultReceived);
     245      jobResultPoller.IsPollingChanged += new EventHandler(jobResultPoller_IsPollingChanged);
     246    }
     247    private void DeregisterResultPollingEvents() {
     248      jobResultPoller.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured);
     249      jobResultPoller.JobResultsReceived -= new EventHandler<EventArgs<IEnumerable<LightweightJob>>>(jobResultPoller_JobResultReceived);
     250      jobResultPoller.IsPollingChanged -= new EventHandler(jobResultPoller_IsPollingChanged);
     251    }
     252    private void jobResultPoller_IsPollingChanged(object sender, EventArgs e) {
     253      this.refreshAutomatically = jobResultPoller.IsPolling;
     254      OnRefreshAutomaticallyChanged();
     255    }
     256    private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) {
     257      foreach (LightweightJob lightweightJob in e.Value) {
     258        HiveJob hj = hiveJob.GetHiveJobByJobId(lightweightJob.Id);
     259        if (hj != null) {
     260          DateTime lastJobDataUpdate = hj.Job.LastJobDataUpdate;
     261          hj.UpdateFromLightweightJob(lightweightJob);
     262
     263          // lastJobDataUpdate equals DateTime.MinValue right after it was uploaded. When the first results are polled, this value is updated
     264          if (lastJobDataUpdate != DateTime.MinValue && lastJobDataUpdate < hj.Job.LastJobDataUpdate) {
     265            OptimizerJob optimizerJob = ExperimentManagerClient.LoadOptimizerJob(hj.Job.Id);
     266            if (optimizerJob == null) {
     267              // something bad happened to this job. bad job, BAAAD job!
     268            } else {
     269              // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare)
     270              if (hj.Job.State == JobState.Paused) {
     271                hj.OptimizerJob = optimizerJob;
     272              } else {
     273                if (lightweightJob.ParentJobId.HasValue) {
     274                  HiveJob parentHiveJob = HiveJob.GetHiveJobByJobId(lightweightJob.ParentJobId.Value);
     275                  parentHiveJob.UpdateChildOptimizer(optimizerJob, hj.Job.Id);
     276                }
     277              }
     278            }
     279          }
     280        }
     281      }
     282      GC.Collect(); // force GC, because .NET is too lazy here (deserialization takes a lot of memory)
     283      if (AllJobsFinished()) {
     284        this.ExecutionState = Core.ExecutionState.Stopped;
     285        StopResultPolling();
     286        //OnStopped();
     287      }
     288      UpdateTotalExecutionTime();
     289      UpdateStats();
     290    }
     291
     292    private void UpdateStats() {
     293      var jobs = HiveJob.GetAllHiveJobs();
     294      this.JobCount = jobs.Count();
     295      this.CalculatingCount = jobs.Count(j => j.Job.State == JobState.Calculating);
     296      this.FinishedCount = jobs.Count(j => j.Job.State == JobState.Finished);
     297    }
     298
     299    private bool AllJobsFinished() {
     300      return HiveJob.GetAllHiveJobs().All(j => j.Job.State == JobState.Finished
     301                                            || j.Job.State == JobState.Aborted
     302                                            || j.Job.State == JobState.Failed);
     303    }
     304
     305    private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) {
     306      //OnExceptionOccured(e.Value);
     307    }
     308
     309    public void UpdateTotalExecutionTime() {
     310      this.ExecutionTime = TimeSpan.FromMilliseconds(HiveJob.GetAllHiveJobs().Sum(x => x.Job.ExecutionTime.HasValue ? x.Job.ExecutionTime.Value.TotalMilliseconds : 0));
     311    }
     312    #endregion
     313
     314    protected override void RaisePropertyChanged(string propertyName) {
     315      if (!(propertyName == "ExecutionTime")
     316        && !(propertyName == "JobCount")
     317        && !(propertyName == "CalculatingCount")
     318        && !(propertyName == "FinishedCount")) {
     319        base.RaisePropertyChanged(propertyName);
     320      }
    51321    }
    52322  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItem.cs

    r5718 r5955  
    2323using System.ComponentModel;
    2424using System.Drawing;
     25using System.Runtime.Serialization;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2829namespace HeuristicLab.Clients.Hive {
    2930
    30   public partial class HiveItem : IItem {
     31  public partial class HiveItem : IHiveItem {
     32    public string ItemName {
     33      get { return ItemAttribute.GetName(this.GetType()); }
     34    }
     35    public string ItemDescription {
     36      get { return ItemAttribute.GetDescription(this.GetType()); }
     37    }
     38    public Version ItemVersion {
     39      get { return ItemAttribute.GetVersion(this.GetType()); }
     40    }
     41    public virtual Image ItemImage {
     42      get {
     43        if (Modified)
     44          return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
     45        else
     46          return HeuristicLab.Common.Resources.VSImageLibrary.Database;
     47      }
     48    }
    3149
    32     public HiveItem() { }
     50    private bool modified;
     51    public bool Modified {
     52      get { return modified; }
     53      private set {
     54        if (value != modified) {
     55          modified = value;
     56          OnModifiedChanged();
     57          RaisePropertyChanged("Modified");
     58          OnItemImageChanged();
     59          RaisePropertyChanged("ItemImage");
     60        }
     61      }
     62    }
     63
     64    #region Constructor and Cloning
     65    public HiveItem() {
     66      modified = true;
     67    }
     68
     69    [OnDeserialized]
     70    private void OnDeserialized(StreamingContext context) {
     71      modified = false;
     72    }
    3373
    3474    protected HiveItem(HiveItem original, Cloner cloner) {
    3575      cloner.RegisterClonedObject(original, this);
    3676      this.Id = original.Id;
     77      modified = true;
    3778    }
    38 
    3979    public virtual IDeepCloneable Clone(Cloner cloner) {
    4080      return new HiveItem(this, cloner);
     
    4484      return Clone(new Cloner());
    4585    }
     86    #endregion
    4687
    47     protected void RaisePropertyChanged(string propertyName) {
     88    public void Store() {
     89      ExperimentManagerClient.Store(this);
     90      Modified = false;
     91    }
     92
     93    protected virtual void RaisePropertyChanged(string propertyName) {
    4894      OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
    4995      if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) {
     
    56102    }
    57103
    58     #region IItem Members
    59     public string ItemName {
    60       get { return ItemAttribute.GetName(this.GetType()); }
    61     }
    62     public string ItemDescription {
    63       get { return ItemAttribute.GetDescription(this.GetType()); }
    64     }
    65     public Version ItemVersion {
    66       get { return ItemAttribute.GetVersion(this.GetType()); }
    67     }
    68     public Image ItemImage {
    69       get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
    70     }
    71 
    72     private bool modified;
    73     public bool Modified {
    74       get { return modified; }
    75       private set {
    76         if (value != modified) {
    77           modified = value;
    78           OnModifiedChanged();
    79           RaisePropertyChanged("Modified");
    80           //OnItemImageChanged();             ??
    81           //RaisePropertyChanged("ItemImage");  ??
    82         }
    83       }
    84     }
    85 
     104    #region Event handler
    86105    public event EventHandler ItemImageChanged;
    87106    protected virtual void OnItemImageChanged() {
     
    99118      if (handler != null) handler(this, EventArgs.Empty);
    100119    }
     120    #endregion
     121
    101122    public override string ToString() {
    102123      return ItemName;
    103124    }
    104     #endregion
    105125  }
    106126}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveServiceClient.cs

    r5786 r5955  
    549549       
    550550        [System.Runtime.Serialization.OptionalFieldAttribute()]
     551        private int CalculatingCountField;
     552       
     553        [System.Runtime.Serialization.OptionalFieldAttribute()]
    551554        private System.DateTime DateCreatedField;
    552555       
    553556        [System.Runtime.Serialization.OptionalFieldAttribute()]
     557        private int FinishedCountField;
     558       
     559        [System.Runtime.Serialization.OptionalFieldAttribute()]
     560        private int JobCountField;
     561       
     562        [System.Runtime.Serialization.OptionalFieldAttribute()]
    554563        private System.Nullable<System.DateTime> LastAccessedField;
    555564       
     
    562571        [System.Runtime.Serialization.OptionalFieldAttribute()]
    563572        private System.Guid RootJobIdField;
     573       
     574        [System.Runtime.Serialization.DataMemberAttribute()]
     575        public int CalculatingCount
     576        {
     577            get
     578            {
     579                return this.CalculatingCountField;
     580            }
     581            set
     582            {
     583                if ((this.CalculatingCountField.Equals(value) != true))
     584                {
     585                    this.CalculatingCountField = value;
     586                    this.RaisePropertyChanged("CalculatingCount");
     587                }
     588            }
     589        }
    564590       
    565591        [System.Runtime.Serialization.DataMemberAttribute()]
     
    576602                    this.DateCreatedField = value;
    577603                    this.RaisePropertyChanged("DateCreated");
     604                }
     605            }
     606        }
     607       
     608        [System.Runtime.Serialization.DataMemberAttribute()]
     609        public int FinishedCount
     610        {
     611            get
     612            {
     613                return this.FinishedCountField;
     614            }
     615            set
     616            {
     617                if ((this.FinishedCountField.Equals(value) != true))
     618                {
     619                    this.FinishedCountField = value;
     620                    this.RaisePropertyChanged("FinishedCount");
     621                }
     622            }
     623        }
     624       
     625        [System.Runtime.Serialization.DataMemberAttribute()]
     626        public int JobCount
     627        {
     628            get
     629            {
     630                return this.JobCountField;
     631            }
     632            set
     633            {
     634                if ((this.JobCountField.Equals(value) != true))
     635                {
     636                    this.JobCountField = value;
     637                    this.RaisePropertyChanged("JobCount");
    578638                }
    579639            }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Plugin.cs

    r5779 r5955  
    3636    }
    3737
    38     public IDeepCloneable Clone(Cloner cloner) {
     38    public override IDeepCloneable Clone(Cloner cloner) {
    3939      return new Plugin(this, cloner);
    40     }
    41 
    42     public object Clone() {
    43       return Clone(new Cloner());
    4440    }
    4541  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/PluginData.cs

    r5779 r5955  
    3838    }
    3939
    40     public IDeepCloneable Clone(Cloner cloner) {
     40    public override IDeepCloneable Clone(Cloner cloner) {
    4141      return new PluginData(this, cloner);
    42     }
    43 
    44     public object Clone() {
    45       return Clone(new Cloner());
    4642    }
    4743  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Resource.cs

    r5779 r5955  
    3333    }
    3434
    35     public IDeepCloneable Clone(Cloner cloner) {
     35    public override IDeepCloneable Clone(Cloner cloner) {
    3636      return new Resource(this, cloner);
    37     }
    38 
    39     public object Clone() {
    40       return Clone(new Cloner());
    4137    }
    4238  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Slave.cs

    r5614 r5955  
    4444    }
    4545
    46     public IDeepCloneable Clone(Cloner cloner) {
     46    public override IDeepCloneable Clone(Cloner cloner) {
    4747      return new Slave(this, cloner);
    4848    }
     
    5151      return string.Format("Cores: {0}, FreeCores: {1}", Cores, FreeCores);
    5252    }
    53 
    54     public object Clone() {
    55       return Clone(new Cloner());
    56     }
    5753  }
    5854}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/SlaveGroup.cs

    r5614 r5955  
    3030    protected SlaveGroup(SlaveGroup original, Cloner cloner) : base(original, cloner) { }
    3131
    32     public IDeepCloneable Clone(Cloner cloner) {
     32    public override IDeepCloneable Clone(Cloner cloner) {
    3333      return new SlaveGroup(this, cloner);
    34     }
    35 
    36     public object Clone() {
    37       return Clone(new Cloner());
    3834    }
    3935  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/StateLog.cs

    r5779 r5955  
    3838    }
    3939
    40     public IDeepCloneable Clone(Cloner cloner) {
     40    public override IDeepCloneable Clone(Cloner cloner) {
    4141      return new StateLog(this, cloner);
    42     }
    43 
    44     public object Clone() {
    45       return Clone(new Cloner());
    4642    }
    4743
Note: See TracChangeset for help on using the changeset viewer.