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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using System.Threading;
|
---|
27 | using HeuristicLab.Hive.JobBase;
|
---|
28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
29 | using HeuristicLab.Hive.Contracts;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
32 | using System.IO;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Hive.Engine {
|
---|
35 | /// <summary>
|
---|
36 | /// Represents an engine that executes its operator-graph on the hive.
|
---|
37 | /// in parallel.
|
---|
38 | /// </summary>
|
---|
39 | public class HiveEngine : ItemBase, IEngine, IEditable {
|
---|
40 | private Guid jobId;
|
---|
41 | private Job job;
|
---|
42 | public string HiveServerUrl { get; set; }
|
---|
43 |
|
---|
44 | public HiveEngine() {
|
---|
45 | job = new Job();
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | #region IEngine Members
|
---|
50 |
|
---|
51 | public IOperatorGraph OperatorGraph {
|
---|
52 | get { return job.Engine.OperatorGraph; }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public IScope GlobalScope {
|
---|
56 | get { return job.Engine.GlobalScope; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public TimeSpan ExecutionTime {
|
---|
60 | get { return job.Engine.ExecutionTime; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public bool Running {
|
---|
64 | get { return job.Engine.Running; }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public bool Canceled {
|
---|
68 | get { return job.Engine.Canceled; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public bool Terminated {
|
---|
72 | get { return job.Engine.Terminated; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | public void Execute() {
|
---|
76 | IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
|
---|
77 |
|
---|
78 | DiscoveryService dService = new DiscoveryService();
|
---|
79 | PluginInfo depInfo = dService.GetDeclaringPlugin(typeof(HiveEngine));
|
---|
80 | List<PluginInfo> dependentPlugins = PluginManager.Manager.GetDependentPluginsRec(depInfo);
|
---|
81 | dependentPlugins.Add(depInfo);
|
---|
82 |
|
---|
83 | HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
|
---|
84 | jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
|
---|
85 | jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
|
---|
86 |
|
---|
87 | List<HivePluginInfo> pluginsNeeded =
|
---|
88 | new List<HivePluginInfo>();
|
---|
89 |
|
---|
90 | foreach (PluginInfo info in dependentPlugins) {
|
---|
91 | HivePluginInfo pluginInfo =
|
---|
92 | new HivePluginInfo();
|
---|
93 | pluginInfo.Name = info.Name;
|
---|
94 | pluginInfo.Version = info.Version.ToString();
|
---|
95 | pluginInfo.BuildDate = info.BuildDate;
|
---|
96 | pluginsNeeded.Add(pluginInfo);
|
---|
97 | }
|
---|
98 |
|
---|
99 | jobObj.PluginsNeeded = pluginsNeeded;
|
---|
100 | ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
|
---|
101 | jobId = res.Obj.Id;
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void ExecuteStep() {
|
---|
105 | throw new NotSupportedException();
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void ExecuteSteps(int steps) {
|
---|
109 | throw new NotSupportedException();
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void Abort() {
|
---|
113 | IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
|
---|
114 |
|
---|
115 |
|
---|
116 | //This are just Stubs on the server right now. There won't be any effect right now...
|
---|
117 | executionEngineFacade.AbortJob(jobId);
|
---|
118 | executionEngineFacade.RequestSnapshot(Guid);
|
---|
119 |
|
---|
120 | //Requests the last result.
|
---|
121 | //false: There will always be a result that is been sent back
|
---|
122 | //true: if you hit "requestsnapshot" before - it won't send you the job back if
|
---|
123 | // the snapshot hasn't been submitted to the server (because the client needs
|
---|
124 | // more time).
|
---|
125 | executionEngineFacade.GetLastResult(jobId, false);
|
---|
126 |
|
---|
127 | throw new NotImplementedException();
|
---|
128 | }
|
---|
129 |
|
---|
130 | public void Reset() {
|
---|
131 | throw new NotImplementedException();
|
---|
132 | }
|
---|
133 |
|
---|
134 | public event EventHandler Initialized;
|
---|
135 |
|
---|
136 | public event EventHandler<OperationEventArgs> OperationExecuted;
|
---|
137 |
|
---|
138 | public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
|
---|
139 |
|
---|
140 | public event EventHandler ExecutionTimeChanged;
|
---|
141 |
|
---|
142 | public event EventHandler Finished;
|
---|
143 |
|
---|
144 | #endregion
|
---|
145 |
|
---|
146 | public void RequestSnapshot() {
|
---|
147 | throw new NotImplementedException();
|
---|
148 | }
|
---|
149 |
|
---|
150 | public override IView CreateView() {
|
---|
151 | return new HiveEngineEditor(this);
|
---|
152 | }
|
---|
153 |
|
---|
154 | #region IEditable Members
|
---|
155 |
|
---|
156 | public IEditor CreateEditor() {
|
---|
157 | return new HiveEngineEditor(this);
|
---|
158 | }
|
---|
159 | #endregion
|
---|
160 | }
|
---|
161 | }
|
---|