Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs @ 5314

Last change on this file since 5314 was 5314, checked in by ascheibe, 13 years ago

#1233

  • added ItemView and Item for the Slave
  • added a Tray Icon App for data visualization and control of the slave windows service
  • added control methods to SlaveCommunication for controlling the slave core
  • fixed typo in namespace
File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Services.Hive.Common;
25using HeuristicLab.Clients.Hive.Slave;
26using HeuristicLab.Services.Hive.Common.DataTransfer;
27using HeuristicLab.Clients.Hive.Slave.Properties;
28
29
30namespace HeuristicLab.Clients.Hive.Slave {
31  /// <summary>
32  /// accesses the Server and sends his data (uuid, uptimes, hardware config)
33  /// </summary>
34  public class ConfigManager {
35    private static ConfigManager instance = null;
36    public static ConfigManager Instance {
37      get {
38        if (instance == null) {
39          instance = new ConfigManager();
40        }
41        return instance;
42      }
43    }
44
45    public Core Core { get; set; }
46    private HeuristicLab.Services.Hive.Common.DataTransfer.Slave hardwareInfo;
47
48    /// <summary>
49    /// Constructor for the singleton, must recover Guid, Calendar, ...
50    /// </summary>
51    private ConfigManager() {
52      hardwareInfo = new HeuristicLab.Services.Hive.Common.DataTransfer.Slave();
53
54      if (Settings.Default.Guid == Guid.Empty) {
55        hardwareInfo.Id = Guid.NewGuid();
56        Settings.Default.Guid = hardwareInfo.Id;
57        Settings.Default.Save();
58      } else
59        hardwareInfo.Id = Settings.Default.Guid;
60
61      hardwareInfo.Cores = Environment.ProcessorCount;
62      hardwareInfo.Memory = 1024;
63      hardwareInfo.Name = Environment.MachineName;
64    }
65
66    /// <summary>
67    /// Get all the Information about the client
68    /// </summary>
69    /// <returns>the ClientInfo object</returns>
70    public HeuristicLab.Services.Hive.Common.DataTransfer.Slave GetClientInfo() {
71      //TODO: how to display connectedsince in gui?
72      //hardwareInfo.Login = WcfService.Instance.ConnectedSince;
73      return hardwareInfo;
74    }
75
76    /// <summary>
77    /// collects and returns information that get displayed by the Client Console
78    /// </summary>
79    /// <returns></returns>
80    public StatusCommons GetStatusForClientConsole() {
81      //Todo: Locking
82      StatusCommons st = new StatusCommons();
83      st.ClientGuid = hardwareInfo.Id;
84
85      st.Status = WcfService.Instance.ConnState;
86      st.ConnectedSince = WcfService.Instance.ConnectedSince;
87
88      st.TotalCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value : 0;
89      st.FreeCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value - GetUsedCores() : 0;
90
91      st.JobsAborted = SlaveStatusInfo.JobsAborted;
92      st.JobsDone = SlaveStatusInfo.JobsProcessed;
93      st.JobsFetched = SlaveStatusInfo.JobsFetched;
94
95      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
96      st.Jobs = new List<JobStatus>();
97
98      lock (engines) {
99        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
100          Executor e = kvp.Value;
101          st.Jobs.Add(new JobStatus { JobId = e.JobId, ExecutionTime = e.ExecutionTime, Since = e.CreationTime });
102        }
103      }
104      return st;
105    }
106
107    public Dictionary<Guid, TimeSpan> GetExecutionTimeOfAllJobs() {
108      Dictionary<Guid, TimeSpan> prog = new Dictionary<Guid, TimeSpan>();
109      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
110      lock (engines) {
111        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
112          Executor e = kvp.Value;
113          prog[e.JobId] = e.ExecutionTime;
114        }
115      }
116      return prog;
117    }
118
119    public int GetUsedCores() {
120      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
121      Dictionary<Guid, Job> jobs = Core.Jobs;
122      int usedCores = 0;
123      lock (engines) {
124        foreach (KeyValuePair<Guid, Job> kvp in jobs)
125          usedCores += kvp.Value.CoresNeeded;
126      }
127      return usedCores;
128    }
129
130  }
131}
Note: See TracBrowser for help on using the repository browser.