[1432] | 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;
|
---|
[1440] | 27 | using HeuristicLab.Hive.JobBase;
|
---|
| 28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
[1487] | 29 | using HeuristicLab.Hive.Contracts;
|
---|
[1503] | 30 | using HeuristicLab.PluginInfrastructure;
|
---|
[1580] | 31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[1432] | 32 |
|
---|
| 33 | namespace HeuristicLab.Hive.Engine {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// Represents an engine that executes its operator-graph on the hive.
|
---|
| 36 | /// in parallel.
|
---|
| 37 | /// </summary>
|
---|
[1440] | 38 | public class HiveEngine : ItemBase, IEngine, IEditable {
|
---|
[1510] | 39 | private Guid jobId;
|
---|
[1440] | 40 | private Job job;
|
---|
| 41 | public string HiveServerUrl { get; set; }
|
---|
[1432] | 42 |
|
---|
[1440] | 43 | public HiveEngine() {
|
---|
| 44 | job = new Job();
|
---|
[1432] | 45 | }
|
---|
| 46 |
|
---|
[1440] | 47 |
|
---|
| 48 | #region IEngine Members
|
---|
| 49 |
|
---|
| 50 | public IOperatorGraph OperatorGraph {
|
---|
| 51 | get { return job.Engine.OperatorGraph; }
|
---|
[1432] | 52 | }
|
---|
| 53 |
|
---|
[1440] | 54 | public IScope GlobalScope {
|
---|
| 55 | get { return job.Engine.GlobalScope; }
|
---|
[1432] | 56 | }
|
---|
| 57 |
|
---|
[1440] | 58 | public TimeSpan ExecutionTime {
|
---|
| 59 | get { return job.Engine.ExecutionTime; }
|
---|
[1432] | 60 | }
|
---|
[1440] | 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);
|
---|
[1510] | 76 |
|
---|
[1503] | 77 | DiscoveryService dService = new DiscoveryService();
|
---|
| 78 | PluginInfo depInfo = dService.GetDeclaringPlugin(typeof(HiveEngine));
|
---|
| 79 | List<PluginInfo> dependentPlugins = PluginManager.Manager.GetDependentPluginsRec(depInfo);
|
---|
| 80 |
|
---|
[1440] | 81 | HeuristicLab.Hive.Contracts.BusinessObjects.Job jobObj = new HeuristicLab.Hive.Contracts.BusinessObjects.Job();
|
---|
| 82 | jobObj.SerializedJob = PersistenceManager.SaveToGZip(job);
|
---|
[1487] | 83 | jobObj.State = HeuristicLab.Hive.Contracts.BusinessObjects.State.offline;
|
---|
[1580] | 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 |
|
---|
[1589] | 95 |
|
---|
| 96 |
|
---|
[1580] | 97 | pluginsNeeded.Add(pluginInfo);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | jobObj.PluginsNeeded = pluginsNeeded;
|
---|
[1487] | 101 | ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
|
---|
[1510] | 102 | jobId = res.Obj.Id;
|
---|
[1440] | 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() {
|
---|
[1510] | 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 |
|
---|
[1440] | 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
|
---|
[1432] | 161 | }
|
---|
| 162 | }
|
---|