source: trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs @ 1589

Last change on this file since 1589 was 1589, checked in by kgrading, 12 years ago

refactoring (#547)

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using System.Threading;
27using HeuristicLab.Hive.JobBase;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Contracts;
30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
32
33namespace HeuristicLab.Hive.Engine {
34  /// <summary>
35  /// Represents an engine that executes its operator-graph on the hive.
36  /// in parallel.
37  /// </summary>
38  public class HiveEngine : ItemBase, IEngine, IEditable {
39    private Guid jobId;
40    private Job job;
41    public string HiveServerUrl { get; set; }
42
43    public HiveEngine() {
44      job = new Job();
45    }
46
47
48    #region IEngine Members
49
50    public IOperatorGraph OperatorGraph {
51      get { return job.Engine.OperatorGraph; }
52    }
53
54    public IScope GlobalScope {
55      get { return job.Engine.GlobalScope; }
56    }
57
58    public TimeSpan ExecutionTime {
59      get { return job.Engine.ExecutionTime; }
60    }
61
62    public bool Running {
63      get { return job.Engine.Running; }
64    }
65
66    public bool Canceled {
67      get { return job.Engine.Canceled; }
68    }
69
70    public bool Terminated {
71      get { return job.Engine.Terminated; }
72    }
73
74    public void Execute() {
75      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
76     
77      DiscoveryService dService = new DiscoveryService();
78      PluginInfo depInfo = dService.GetDeclaringPlugin(typeof(HiveEngine));
79      List<PluginInfo> dependentPlugins = PluginManager.Manager.GetDependentPluginsRec(depInfo);
80
81      HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
82      jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
83      jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
84
85      List<HivePluginInfo> pluginsNeeded =
86        new List<HivePluginInfo>();
87
88      foreach (PluginInfo info in dependentPlugins) {
89        HivePluginInfo pluginInfo =
90          new HivePluginInfo();
91        pluginInfo.Name = info.Name;
92        pluginInfo.Version = info.Version.ToString();
93        pluginInfo.BuildDate = info.BuildDate.ToString();
94
95
96
97        pluginsNeeded.Add(pluginInfo);
98      }
99
100      jobObj.PluginsNeeded = pluginsNeeded;
101      ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
102      jobId = res.Obj.Id;
103    }
104
105    public void ExecuteStep() {
106      throw new NotSupportedException();
107    }
108
109    public void ExecuteSteps(int steps) {
110      throw new NotSupportedException();
111    }
112
113    public void Abort() {
114      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
115     
116     
117      //This are just Stubs on the server right now. There won't be any effect right now...
118      executionEngineFacade.AbortJob(jobId);     
119      executionEngineFacade.RequestSnapshot(Guid);
120     
121      //Requests the last result.
122      //false: There will always be a result that is been sent back
123      //true: if you hit "requestsnapshot" before - it won't send you the job back if
124      //      the snapshot hasn't been submitted to the server (because the client needs
125      //      more time).
126      executionEngineFacade.GetLastResult(jobId, false);
127
128      throw new NotImplementedException();
129    }
130
131    public void Reset() {
132      throw new NotImplementedException();
133    }
134
135    public event EventHandler Initialized;
136
137    public event EventHandler<OperationEventArgs> OperationExecuted;
138
139    public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
140
141    public event EventHandler ExecutionTimeChanged;
142
143    public event EventHandler Finished;
144
145    #endregion
146
147    public void RequestSnapshot() {
148      throw new NotImplementedException();
149    }
150
151    public override IView CreateView() {
152      return new HiveEngineEditor(this);
153    }
154
155    #region IEditable Members
156
157    public IEditor CreateEditor() {
158      return new HiveEngineEditor(this);
159    }
160    #endregion
161  }
162}
Note: See TracBrowser for help on using the repository browser.