Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/Server.cs @ 2066

Last change on this file since 2066 was 2058, checked in by gkronber, 15 years ago

Refactored JobManager and added a plugin that contains a bridge between grid and hive. The bridge allows to use the execution engine service of Hive as a grid server. This way CEDMA job execution and DistributedEngine job execution can either use Hive or Grid as backend. #642 (Hive backend for CEDMA)

File size: 4.3 KB
RevLine 
[1044]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 System.Windows.Forms;
26using HeuristicLab.PluginInfrastructure;
27using System.Net;
28using System.ServiceModel;
29using HeuristicLab.CEDMA.DB.Interfaces;
30using HeuristicLab.CEDMA.DB;
31using System.ServiceModel.Description;
[2058]32using HeuristicLab.Grid;
33using HeuristicLab.Grid.HiveBridge;
[1044]34
35namespace HeuristicLab.CEDMA.Server {
36  public class Server {
[2050]37    private static readonly string rdfFile = AppDomain.CurrentDomain.BaseDirectory + "rdf_store.db3";
38    private static readonly string rdfConnectionString = "sqlite:rdf:Data Source=\"" + rdfFile + "\"";
39
[1044]40    private ServiceHost host;
[2050]41    private Store store;
42    private IDispatcher dispatcher;
43    private IExecuter executer;
[1044]44
45    private string gridServiceUrl;
46    public string GridServiceUrl {
47      get { return gridServiceUrl; }
48      set { gridServiceUrl = value; }
49    }
50
51    private string cedmaServiceUrl;
52    public string CedmaServiceUrl {
53      get { return cedmaServiceUrl; }
54      set { cedmaServiceUrl = value; }
55    }
56
[2050]57    private int maxActiveJobs;
58    public int MaxActiveJobs {
59      get { return maxActiveJobs; }
60      set {
61        if (value > 0 && value <= 64) {
62          maxActiveJobs = value;
63        }
64      }
65    }
66
67    public Server() {
[1287]68      IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
69      // windows XP returns the external ip on index 0 while windows vista returns the external ip as one of the last entries
70      // also if IPv6 protocol is installed we want to find an entry that is IPv4
71      int index = 0;
[1044]72      if (System.Environment.OSVersion.Version.Major >= 6) {
[1287]73        for (index = addresses.Length - 1; index >= 0; index--)
74          if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
75            break;
[1044]76      }
[1287]77      cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA";
[2050]78      store = new Store(rdfConnectionString);
79      maxActiveJobs = 10;
[1044]80    }
81
82    public void Start() {
83      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
84      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
85      throttlingBehavior.MaxConcurrentSessions = 20;
86      host.Description.Behaviors.Add(throttlingBehavior);
87      try {
88        NetTcpBinding binding = new NetTcpBinding();
[1417]89        binding.SendTimeout = new TimeSpan(10, 0, 0);
90        binding.MaxReceivedMessageSize = int.MaxValue;
91        binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
92        binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
[1044]93        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
94        host.Open();
95      }
96      catch (CommunicationException ex) {
97        MessageBox.Show("An exception occurred: " + ex.Message);
98        host.Abort();
99      }
100    }
[2050]101
102    internal string[] GetActiveJobDescriptions() {
103      if (executer != null) return executer.GetJobs();
104      else return new string[] { };
105    }
106
107    internal void Connect(string serverUrl) {
108      dispatcher = new SimpleDispatcher(store);
[2058]109      IGridServer gridServer = null;
[2050]110      if (serverUrl.Contains("ExecutionEngine")) {
[2058]111        gridServer = new HiveGridServerWrapper(serverUrl);
[2050]112      } else {
113        // default is grid backend
[2058]114        gridServer = new GridServerProxy(serverUrl);
[2050]115      }
[2058]116      executer = new GridExecuter(dispatcher, store, gridServer);
[2050]117      executer.Start();
118    }
[1044]119  }
120}
Note: See TracBrowser for help on using the repository browser.