Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/12/11 13:43:05 (13 years ago)
Author:
cneumuel
Message:

#1233

  • changed relationship between Job and HiveExperiment. There is no more HiveExperiment.RootJobId, instead there is Job.HiveExperimentId.
  • One HiveExperiment can now have multiple Experiments.
  • TreeView supports multiple root nodes
  • HiveEngine creates a HiveExperiment for each set of jobs, so jobs cannot be without an parent experiment anymore (no more loose jobs)
  • updated ExperimentManager binaries
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources

    • Property svn:ignore
      •  

        old new  
        44PrecompiledWeb
        55CreateEventLogSources
         6WindowsFormsTestProject
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs

    r5955 r6006  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Optimization;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.Clients.Hive {
    32 
     33  [StorableClass]
    3334  public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
    3435    private JobResultPoller jobResultPoller;
    3536
     37    [Storable]
    3638    private bool useLocalPlugins;
    3739    public bool UseLocalPlugins {
     
    4042    }
    4143
     44    [Storable]
    4245    private ExecutionState executionState;
    4346    public ExecutionState ExecutionState {
     
    5154    }
    5255
     56    [Storable]
    5357    private TimeSpan executionTime;
    5458    public TimeSpan ExecutionTime {
     
    6266    }
    6367
    64     private HiveJob hiveJob;
    65     public HiveJob HiveJob {
    66       get { return hiveJob; }
     68    [Storable]
     69    private ItemCollection<HiveJob> hiveJobs;
     70    public ItemCollection<HiveJob> HiveJobs {
     71      get { return hiveJobs; }
    6772      set {
    68         DeregisterHiveJobEvents();
    69         if (hiveJob != value) {
    70           hiveJob = value;
    71           RegisterHiveJobEvents();
    72           OnHiveJobChanged();
    73         }
    74       }
    75     }
    76 
     73        DeregisterHiveJobsEvents();
     74        if (hiveJobs != value) {
     75          hiveJobs = value;
     76          RegisterHiveJobsEvents();
     77          OnHiveJobsChanged();
     78        }
     79      }
     80    }
     81
     82    [Storable]
    7783    private bool isProgressing;
    7884    public bool IsProgressing {
     
    8793
    8894    /** include jobs when refreshing **/
     95    [Storable]
    8996    private bool includeJobs;
    9097    public bool IncludeJobs {
     
    93100    }
    94101
     102    [Storable]
    95103    private bool refreshAutomatically;
    96104    public bool RefreshAutomatically {
     
    109117    }
    110118
     119    [Storable]
    111120    private IProgress progress;
    112121    public IProgress Progress {
     
    124133    protected HiveExperiment(HiveExperiment original, Cloner cloner) {
    125134      cloner.RegisterClonedObject(original, this);
    126       this.RootJobId = original.RootJobId;
    127135      this.OwnerUserId = original.OwnerUserId;
    128136      this.DateCreated = original.DateCreated;
     
    158166    }
    159167
    160     public event EventHandler HiveJobChanged;
    161     private void OnHiveJobChanged() {
     168    public event EventHandler HiveJobsChanged;
     169    private void OnHiveJobsChanged() {
    162170      if (jobResultPoller != null && jobResultPoller.IsPolling) {
    163171        jobResultPoller.Stop();
    164172        DeregisterResultPollingEvents();
    165173      }
    166       if (HiveJob != null && HiveJob.Job.Id != Guid.Empty) {
     174      if (HiveJobs != null && HiveJobs.Count > 0 && GetAllHiveJobs().All(x => x.Job.Id != Guid.Empty)) {
    167175        if (this.RefreshAutomatically)
    168176          StartResultPolling();
    169177      }
    170       EventHandler handler = HiveJobChanged;
     178      EventHandler handler = HiveJobsChanged;
    171179      if (handler != null) handler(this, EventArgs.Empty);
    172180    }
     
    185193    #endregion
    186194
    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       }
     195    private void RegisterHiveJobsEvents() {
     196      //if (HiveJobs != null) {
     197      //  HiveJobs.JobStateChanged += new EventHandler(HiveJob_JobStateChanged);
     198      //}
     199    }
     200
     201    private void DeregisterHiveJobsEvents() {
     202      //if (HiveJobs != null) {
     203      //  HiveJobs.JobStateChanged -= new EventHandler(HiveJob_JobStateChanged);
     204      //}
    197205    }
    198206
    199207    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      //if (this.HiveJobs != null) {
     209      //  this.RootJobId = HiveJobs.Job.Id;
     210      //}
     211    }
     212
     213    public Experiment GetExperiment(int idx) {
     214      if (this.HiveJobs != null) {
     215        var hj = HiveJobs.ElementAtOrDefault(idx);
     216        if (hj != null)
     217          return hj.OptimizerJob.OptimizerAsExperiment;
    208218      }
    209219      return null;
    210220    }
    211221
     222    public void AddExperiment(Experiment experiment) {
     223      if (this.HiveJobs == null)
     224        this.HiveJobs = new ItemCollection<HiveJob>();
     225      this.HiveJobs.Add(new HiveJob(experiment));
     226    }
     227
    212228    public void SetExperiment(Experiment experiment) {
    213       this.HiveJob = new HiveJob(experiment);
     229      if (this.HiveJobs == null)
     230        this.HiveJobs = new ItemCollection<HiveJob>();
     231      else
     232        this.HiveJobs.Clear();
     233      this.HiveJobs.Add(new HiveJob(experiment));
    214234    }
    215235
     
    225245    public void StartResultPolling() {
    226246      if (jobResultPoller == null) {
    227         jobResultPoller = new JobResultPoller(HiveJob, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants
     247        jobResultPoller = new JobResultPoller(HiveJobs, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants
    228248        RegisterResultPollingEvents();
    229249      }
     
    235255
    236256    public void StopResultPolling() {
    237       if (jobResultPoller.IsPolling) {
     257      if (jobResultPoller != null && jobResultPoller.IsPolling) {
    238258        jobResultPoller.Stop();
    239259      }
     
    256276    private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) {
    257277      foreach (LightweightJob lightweightJob in e.Value) {
    258         HiveJob hj = hiveJob.GetHiveJobByJobId(lightweightJob.Id);
     278        HiveJob hj = GetHiveJobById(lightweightJob.Id);
    259279        if (hj != null) {
    260280          DateTime lastJobDataUpdate = hj.Job.LastJobDataUpdate;
     
    272292              } else {
    273293                if (lightweightJob.ParentJobId.HasValue) {
    274                   HiveJob parentHiveJob = HiveJob.GetHiveJobByJobId(lightweightJob.ParentJobId.Value);
     294                  HiveJob parentHiveJob = GetHiveJobById(lightweightJob.ParentJobId.Value);
    275295                  parentHiveJob.UpdateChildOptimizer(optimizerJob, hj.Job.Id);
    276296                }
     
    290310    }
    291311
     312    public HiveJob GetHiveJobById(Guid jobId) {
     313      foreach (HiveJob job in HiveJobs) {
     314        HiveJob hj = job.GetHiveJobByJobId(jobId);
     315        if (hj != null)
     316          return hj;
     317      }
     318      return null;
     319    }
     320
    292321    private void UpdateStats() {
    293       var jobs = HiveJob.GetAllHiveJobs();
     322      var jobs = GetAllHiveJobs();
    294323      this.JobCount = jobs.Count();
    295324      this.CalculatingCount = jobs.Count(j => j.Job.State == JobState.Calculating);
     
    297326    }
    298327
    299     private bool AllJobsFinished() {
    300       return HiveJob.GetAllHiveJobs().All(j => j.Job.State == JobState.Finished
     328    public IEnumerable<HiveJob> GetAllHiveJobs() {
     329      var jobs = new List<HiveJob>();
     330      foreach (HiveJob job in HiveJobs) {
     331        jobs.AddRange(job.GetAllHiveJobs());
     332      }
     333      return jobs;
     334    }
     335
     336    public bool AllJobsFinished() {
     337      return GetAllHiveJobs().All(j => j.Job.State == JobState.Finished
    301338                                            || j.Job.State == JobState.Aborted
    302339                                            || j.Job.State == JobState.Failed);
     
    308345
    309346    public void UpdateTotalExecutionTime() {
    310       this.ExecutionTime = TimeSpan.FromMilliseconds(HiveJob.GetAllHiveJobs().Sum(x => x.Job.ExecutionTime.HasValue ? x.Job.ExecutionTime.Value.TotalMilliseconds : 0));
     347      this.ExecutionTime = TimeSpan.FromMilliseconds(GetAllHiveJobs().Sum(x => x.Job.ExecutionTime.HasValue ? x.Job.ExecutionTime.Value.TotalMilliseconds : 0));
    311348    }
    312349    #endregion
     
    320357      }
    321358    }
     359
     360    public bool IsFinished() {
     361      return HiveJobs != null
     362        && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);
     363    }
    322364  }
    323365}
Note: See TracChangeset for help on using the changeset viewer.