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 |
|
---|
82 | HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
|
---|
83 | jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
|
---|
84 | jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
|
---|
85 |
|
---|
86 | List<HivePluginInfo> pluginsNeeded =
|
---|
87 | new List<HivePluginInfo>();
|
---|
88 |
|
---|
89 | foreach (PluginInfo info in dependentPlugins) {
|
---|
90 | HivePluginInfo pluginInfo =
|
---|
91 | new HivePluginInfo();
|
---|
92 | pluginInfo.Name = info.Name;
|
---|
93 | pluginInfo.Version = info.Version.ToString();
|
---|
94 | pluginInfo.BuildDate = info.BuildDate;
|
---|
95 | pluginsNeeded.Add(pluginInfo);
|
---|
96 | }
|
---|
97 |
|
---|
98 | jobObj.PluginsNeeded = pluginsNeeded;
|
---|
99 | ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
|
---|
100 | jobId = res.Obj.Id;
|
---|
101 | }
|
---|
102 |
|
---|
103 | public void ExecuteStep() {
|
---|
104 | throw new NotSupportedException();
|
---|
105 | }
|
---|
106 |
|
---|
107 | public void ExecuteSteps(int steps) {
|
---|
108 | throw new NotSupportedException();
|
---|
109 | }
|
---|
110 |
|
---|
111 | public void Abort() {
|
---|
112 | IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
|
---|
113 |
|
---|
114 |
|
---|
115 | //This are just Stubs on the server right now. There won't be any effect right now...
|
---|
116 | executionEngineFacade.AbortJob(jobId);
|
---|
117 | executionEngineFacade.RequestSnapshot(Guid);
|
---|
118 |
|
---|
119 | //Requests the last result.
|
---|
120 | //false: There will always be a result that is been sent back
|
---|
121 | //true: if you hit "requestsnapshot" before - it won't send you the job back if
|
---|
122 | // the snapshot hasn't been submitted to the server (because the client needs
|
---|
123 | // more time).
|
---|
124 | executionEngineFacade.GetLastResult(jobId, false);
|
---|
125 |
|
---|
126 | throw new NotImplementedException();
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void Reset() {
|
---|
130 | throw new NotImplementedException();
|
---|
131 | }
|
---|
132 |
|
---|
133 | public event EventHandler Initialized;
|
---|
134 |
|
---|
135 | public event EventHandler<OperationEventArgs> OperationExecuted;
|
---|
136 |
|
---|
137 | public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
|
---|
138 |
|
---|
139 | public event EventHandler ExecutionTimeChanged;
|
---|
140 |
|
---|
141 | public event EventHandler Finished;
|
---|
142 |
|
---|
143 | #endregion
|
---|
144 |
|
---|
145 | public void RequestSnapshot() {
|
---|
146 | throw new NotImplementedException();
|
---|
147 | }
|
---|
148 |
|
---|
149 | public override IView CreateView() {
|
---|
150 | return new HiveEngineEditor(this);
|
---|
151 | }
|
---|
152 |
|
---|
153 | #region IEditable Members
|
---|
154 |
|
---|
155 | public IEditor CreateEditor() {
|
---|
156 | return new HiveEngineEditor(this);
|
---|
157 | }
|
---|
158 | #endregion
|
---|
159 | }
|
---|
160 | }
|
---|