Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/07/10 10:22:27 (14 years ago)
Author:
cneumuel
Message:
  • created HiveClient which shows an overview over all submitted HiveExperiments
  • its possible to download all submitted HiveExperiments including results
  • Experiments are now sent as a whole to the Hive and the Hive-Slaves take care of creating child-jobs (if necessary). The parent job is then paused and will be reactivated when all child-jobs are finished
  • WcfService-Clients are now consistently managed by WcfServicePool which allows to use IDisposable-Pattern and always keeps exactly one proxy-object until all callers disposed them.
  • created ProgressView which is able to lock a View and display progress of an action. It also allows to simulate progress if no progress-information is available so that users don't get too nervous while waiting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/JobItem.cs

    r4264 r4368  
    1212using HeuristicLab.Optimization;
    1313using HeuristicLab.Hive.Contracts.ResponseObjects;
     14using HeuristicLab.Hive.JobBase;
     15using System.IO;
     16using HeuristicLab.Persistence.Default.Xml;
     17using HeuristicLab.PluginInfrastructure;
     18using System.Reflection;
     19using HeuristicLab.Hive.Experiment.Jobs;
    1420
    1521namespace HeuristicLab.Hive.Experiment {
     
    2228    public override Image ItemImage {
    2329      get {
    24         if (State == JobState.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
    25         else if (State == JobState.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
    26         else if (State == JobState.Aborted) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
    27         else if (State == JobState.Failed) return HeuristicLab.Common.Resources.VS2008ImageLibrary.Error;
    28         else if (State == JobState.Finished) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
     30        if (jobDto.State == JobState.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
     31        else if (jobDto.State == JobState.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
     32        else if (jobDto.State == JobState.Aborted) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
     33        else if (jobDto.State == JobState.Failed) return HeuristicLab.Common.Resources.VS2008ImageLibrary.Error;
     34        else if (jobDto.State == JobState.Finished) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
    2935        else return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event;
    3036      }
     
    3339    [Storable]
    3440    private JobDto jobDto;
    35     /// <summary>
    36     /// Some static information about the job. Don't use State-Information out of there
    37     /// </summary>
    3841    public JobDto JobDto {
    3942      get { return jobDto; }
     
    4952
    5053    [Storable]
    51     private JobResult jobResult;
    52     public JobResult JobResult {
    53       private get { return jobResult; }
     54    private IJob job;
     55    public IJob Job {
     56      get { return job; }
    5457      set {
    55         if (jobResult != value) {
    56           jobResult = value;
    57           OnJobStateChanged();
    58           OnToStringChanged();
    59           OnItemImageChanged();
    60         }
    61       }
    62     }
    63 
    64     public JobState State {
    65       get { return jobResult != null ? JobResult.State : JobDto.State; }
    66     }
    67 
    68     public double? Percentage {
    69       get { return jobResult != null ? JobResult.Percentage : JobDto.Percentage; }
    70     }
    71 
    72     public string Exception {
    73       get { return jobResult != null ? JobResult.Exception : JobDto.Exception; }
    74     }
    75 
    76     public DateTime? DateCalculated {
    77       get { return jobResult != null ? JobResult.DateCalculated : JobDto.DateCalculated; }
    78     }
    79 
    80     public DateTime? DateFinished {
    81       get { return jobResult != null ? JobResult.DateFinished : JobDto.DateFinished; }
    82     }
    83    
    84     [Storable]
    85     private ResponseObject<SerializedJob> latestSnapshot;
    86     public ResponseObject<SerializedJob> LatestSnapshot {
    87       get { return latestSnapshot; }
     58        if (job != value) {
     59          job = value;
     60          IsFinalResultAvailable = job.ExecutionState == ExecutionState.Stopped;
     61          OnJobChanged();
     62        }
     63      }
     64    }
     65
     66    [Storable]
     67    private ICollection<JobItem> childJobItems;
     68    public IEnumerable<JobItem> ChildJobItems {
     69      get { return childJobItems; }
     70    }
     71
     72    [Storable]
     73    private bool isFinalResultAvailable;
     74    public bool IsFinalResultAvailable {
     75      get { return isFinalResultAvailable; }
    8876      set {
    89         if (latestSnapshot != value) {
    90           latestSnapshot = value;
    91           if (value != null) {
    92             latestSnapshotTime = DateTime.Now;
    93           }
    94           SnapshotRequestedState = Experiment.SnapshotRequestedState.Idle;
    95           OnLatestSnapshotChanged();
    96         }
    97       }
    98     }
    99 
    100     [Storable]
    101     private DateTime latestSnapshotTime;
    102     public DateTime LatestSnapshotTime {
    103       get { return latestSnapshotTime; }
    104     }
    105 
    106     [Storable]
    107     private ILog log;
    108     public ILog Log {
    109       get { return log; }
    110     }
    111 
    112     [Storable]
    113     private IOptimizer optimizer;
    114     public IOptimizer Optimizer {
    115       get { return optimizer; }
    116       set { this.optimizer = value; }
    117     }
    118 
    119     [Storable]
    120     private SnapshotRequestedState snapshotRequestedState;
    121     public SnapshotRequestedState SnapshotRequestedState {
    122       get { return snapshotRequestedState; }
    123       private set {
    124         this.snapshotRequestedState = value;
    125         OnSnapshotRequestedStateChanged();
    126       }
    127     }
    128 
     77        if (isFinalResultAvailable != value) {
     78          isFinalResultAvailable = value;
     79          if (isFinalResultAvailable)
     80            OnFinalResultAvailable();
     81        }
     82      }
     83    }
     84   
    12985    public JobItem() {
    130       log = new Log();
     86      childJobItems = new List<JobItem>();
     87    }
     88
     89    public JobItem(JobResult jobResult) : this() {
     90      this.jobDto = new JobDto();
     91      UpdateJob(jobResult);
    13192    }
    13293
    13394    public override string ToString() {
    13495      if (jobDto != null) {
    135         return optimizer.Name;
     96        return job.Name;
    13697      } else {
    13798        return base.ToString();
     
    139100    }
    140101
    141     public event EventHandler LatestSnapshotChanged;
    142     private void OnLatestSnapshotChanged() {
    143       LogMessage("LatestSnapshotChanged");
    144       EventHandler handler = LatestSnapshotChanged;
    145       if (handler != null) handler(this, EventArgs.Empty);
    146     }
    147 
     102    public void UpdateJob(JobResult jobResult) {
     103      if (jobResult != null) {
     104        jobDto.Id = jobResult.Id;
     105        jobDto.DateCreated = jobResult.DateCreated;
     106        jobDto.DateCalculated = jobResult.DateCalculated;
     107        jobDto.DateFinished = jobResult.DateFinished;
     108        jobDto.Exception = jobResult.Exception;
     109        jobDto.Id = jobResult.Id;
     110        jobDto.Percentage = jobResult.Percentage;
     111        jobDto.State = jobResult.State;
     112        // what about parentJob
     113        OnJobStateChanged();
     114        OnToStringChanged();
     115        OnItemImageChanged();
     116      }
     117    }
     118
     119    public void AddChildJob(JobItem child) {
     120      this.childJobItems.Add(child);
     121      OnChildJobAdded();
     122    }
     123
     124    //public IEnumerable<JobItem> GetChildJobItems() {
     125    //  if (childJobItems == null)
     126    //    childJobItems = CreateChildJobItems();
     127    //  return childJobItems;
     128    //}
     129
     130    //protected IEnumerable<JobItem> CreateChildJobItems() {
     131    //  return (from j in Job.ChildJobs
     132    //          select new JobItem() {
     133    //            Job = j,
     134    //            JobDto = new JobDto() {
     135    //              State = JobState.Offline
     136    //            }
     137    //          }).ToList();
     138    //}
     139
     140    public SerializedJob ToSerializedJob() {
     141      MemoryStream memStream = new MemoryStream();
     142      XmlGenerator.Serialize(job, memStream);
     143      byte[] jobByteArray = memStream.ToArray();
     144      memStream.Dispose();
     145
     146      UpdateRequiredPlugins();
     147
     148      this.JobDto.CoresNeeded = job.CoresNeeded;
     149      this.JobDto.MemoryNeeded = job.MemoryNeeded;
     150
     151      SerializedJob serializedJob = new SerializedJob() {
     152        JobInfo = jobDto,
     153        SerializedJobData = jobByteArray
     154      };
     155
     156      return serializedJob;
     157    }
     158
     159    private void UpdateRequiredPlugins() {
     160      // find out which which plugins are needed for the given object
     161      this.JobDto.PluginsNeeded = HivePluginInfoDto.FindPluginsNeeded(job.GetType());
     162    }
     163   
    148164    public event EventHandler JobDtoChanged;
    149165    private void OnJobDtoChanged() {
     
    155171    public event EventHandler JobStateChanged;
    156172    private void OnJobStateChanged() {
    157       LogMessage("JobStateChanged (State: " + this.State + ", Percentage: " + this.Percentage + ")");
     173      LogMessage("JobStateChanged (State: " + this.JobDto.State + ", Percentage: " + this.JobDto.Percentage + ")");
    158174      EventHandler handler = JobStateChanged;
     175      if (handler != null) handler(this, EventArgs.Empty);
     176    }
     177   
     178    public event EventHandler ChildJobAdded;
     179    private void OnChildJobAdded() {
     180      var handler = ChildJobAdded;
     181      if (handler != null) handler(this, EventArgs.Empty);
     182    }
     183   
     184    public event EventHandler JobChanged;
     185    private void OnJobChanged() {
     186      var handler = JobChanged;
     187      if (handler != null) handler(this, EventArgs.Empty);
     188    }
     189
     190    public event EventHandler FinalResultAvailable;
     191    private void OnFinalResultAvailable() {
     192      var handler = FinalResultAvailable;
    159193      if (handler != null) handler(this, EventArgs.Empty);
    160194    }
     
    162196    public void LogMessage(string message) {
    163197      lock (locker) {
    164         log.LogMessage(message);
     198        if (job != null) {
     199          job.Log.LogMessage(message);
     200        }
    165201      }
    166202    }
     
    169205      LogMessage("I am beeing cloned");
    170206      JobItem clone = (JobItem)base.Clone(cloner);
    171       clone.latestSnapshotTime = this.latestSnapshotTime;
    172207      clone.jobDto = (JobDto)cloner.Clone(this.jobDto);
    173       clone.latestSnapshot = (ResponseObject<SerializedJob>)cloner.Clone(this.latestSnapshot);
    174       clone.log = (ILog)cloner.Clone(this.log);
    175       clone.optimizer = (IOptimizer)cloner.Clone(this.optimizer);
    176       clone.jobResult = (JobResult)cloner.Clone(this.jobResult);
     208      clone.job = (IJob)cloner.Clone(this.job);
    177209      return clone;
    178210    }
    179211
    180 
    181     public event EventHandler SnapshotRequestedStateChanged;
    182     private void OnSnapshotRequestedStateChanged() {
    183       EventHandler handler = SnapshotRequestedStateChanged;
    184       if (handler != null) handler(this, EventArgs.Empty);
    185     }
    186 
    187     public void RequestSnapshot() {
    188       this.SnapshotRequestedState = Experiment.SnapshotRequestedState.Requested;
    189     }
    190 
    191 
     212    public void UpdateFinalResults(IJob j) {
     213      if (this.Job is OptimizerJob && j is OptimizerJob) {
     214        ((OptimizerJob)this.Job).Optimizer.Runs.AddRange(((OptimizerJob)j).Optimizer.Runs);
     215        IsFinalResultAvailable = true; //job.ExecutionState == ExecutionState.Stopped; //??
     216      } else {
     217        throw new NotSupportedException();
     218      }
     219    }
     220
     221    internal bool ReplaceChildJob(IJob job) {
     222      var matches = this.childJobItems.Where(child => child.Job.InternalId == job.InternalId);
     223      if (matches.Count() > 0) {
     224        matches.First().job = job;
     225        return true;
     226      }
     227      return false;
     228    }
    192229  }
    193230}
Note: See TracChangeset for help on using the changeset viewer.