Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/ConfigurationManager/ConfigManager.cs @ 4333

Last change on this file since 4333 was 4333, checked in by cneumuel, 14 years ago

added authorizationManager which checks for permission to specific jobs (#1168)

File size: 5.0 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.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.BusinessObjects;
27using HeuristicLab.Hive.Slave.ExecutionEngine;
28using HeuristicLab.Hive.Slave.Core.SlaveConsoleService;
29using HeuristicLab.Hive.Slave.Communication;
30using HeuristicLab.Hive.Slave.Core.Properties;
31using HeuristicLab.Hive.Contracts;
32
33namespace HeuristicLab.Hive.Slave.Core.ConfigurationManager {
34  /// <summary>
35  /// accesses the Server and sends his data (uuid, uptimes, hardware config)
36  /// </summary>
37  public class ConfigManager {
38    private static ConfigManager instance = null;
39    public static ConfigManager Instance {
40      get {
41        if (instance == null) {
42          instance = new ConfigManager();
43        }
44        return instance;
45      }
46    }
47
48    public Core Core { get; set; }
49    private SlaveDto hardwareInfo;
50
51    /// <summary>
52    /// Constructor for the singleton, must recover Guid, Calendar, ...
53    /// </summary>
54    private ConfigManager() {
55      hardwareInfo = new SlaveDto();
56
57      if (Settings.Default.Guid == Guid.Empty) {
58        hardwareInfo.Id = Guid.NewGuid();
59        Settings.Default.Guid = hardwareInfo.Id;
60        Settings.Default.Save();
61      } else
62        hardwareInfo.Id = Settings.Default.Guid;
63
64      hardwareInfo.NrOfCores = Environment.ProcessorCount;
65      hardwareInfo.Memory = 1024;
66      hardwareInfo.Name = Environment.MachineName;
67    }
68
69    /// <summary>
70    /// Get all the Information about the client
71    /// </summary>
72    /// <returns>the ClientInfo object</returns>
73    public SlaveDto GetClientInfo() {
74      hardwareInfo.Login = WcfService.Instance.ConnectedSince;
75      return hardwareInfo;
76    }
77
78    /// <summary>
79    /// Returns the connectioncontainer with the IP and Port, storred in the Settings framework
80    /// </summary>
81    /// <returns>The IP and Port of the server</returns>
82    public ConnectionContainer GetServerIP() {
83      ConnectionContainer cc = new ConnectionContainer();
84      cc.IPAdress = Settings.Default.ServerIP;
85      return cc;
86    }
87
88    /// <summary>
89    /// Sets and saves IP in the Settings framework
90    /// </summary>
91    /// <param name="cc"></param>
92    public void SetServerIP(ConnectionContainer cc) {
93      Settings.Default.ServerIP = cc.IPAdress;
94      Settings.Default.Save();
95    }
96
97    /// <summary>
98    /// collects and returns information that get displayed by the Client Console
99    /// </summary>
100    /// <returns></returns>
101    public StatusCommons GetStatusForClientConsole() {
102      //Todo: Locking
103      StatusCommons st = new StatusCommons();
104      st.ClientGuid = hardwareInfo.Id;
105
106      st.Status = WcfService.Instance.ConnState;
107      st.ConnectedSince = WcfService.Instance.ConnectedSince;
108
109      st.TotalCores = hardwareInfo.NrOfCores;
110      st.FreeCores = hardwareInfo.NrOfCores - GetUsedCores();
111
112      st.JobsAborted = SlaveStatusInfo.JobsAborted;
113      st.JobsDone = SlaveStatusInfo.JobsProcessed;
114      st.JobsFetched = SlaveStatusInfo.JobsFetched;
115
116      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
117      st.Jobs = new List<JobStatus>();
118
119      lock (engines) {
120        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
121          Executor e = kvp.Value;
122          st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
123        }
124      }
125      return st;
126    }
127
128    public Dictionary<Guid, double> GetProgressOfAllJobs() {
129      Dictionary<Guid, double> prog = new Dictionary<Guid, double>();
130      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
131      lock (engines) {
132        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
133          Executor e = kvp.Value;
134          //if (!e.JobIsFinished)
135          prog[e.JobId] = e.Progress;
136        }
137      }
138      return prog;
139    }
140
141    public int GetUsedCores() {
142      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
143      Dictionary<Guid, JobDto> jobs = Core.Jobs;
144      int usedCores = 0;
145      lock (engines) {
146        foreach (KeyValuePair<Guid, JobDto> kvp in jobs)
147          usedCores += kvp.Value.CoresNeeded;
148      }
149      return usedCores;
150    }
151
152  }
153}
Note: See TracBrowser for help on using the repository browser.