Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ConfigurationManager/ConfigManager.cs @ 1990

Last change on this file since 1990 was 1755, checked in by kgrading, 15 years ago

added the "coresNeeded" and made a fallback concerning dynamic plugin loading... (#467)

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