Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1260

  • refined job-downloads for limited resources
  • fixed minor bugs
File size: 4.7 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.Hive.Contracts.BusinessObjects;
25using HeuristicLab.Hive.Slave.Communication;
26using HeuristicLab.Hive.Slave.Core.Properties;
27using HeuristicLab.Hive.Slave.Core.SlaveConsoleService;
28using HeuristicLab.Hive.Slave.ExecutionEngine;
29
30namespace HeuristicLab.Hive.Slave.Core.ConfigurationManager {
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 SlaveDto hardwareInfo;
47
48    /// <summary>
49    /// Constructor for the singleton, must recover Guid, Calendar, ...
50    /// </summary>
51    private ConfigManager() {
52      hardwareInfo = new SlaveDto();
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.NrOfCores = 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 SlaveDto GetClientInfo() {
71      hardwareInfo.Login = WcfService.Instance.ConnectedSince;
72      return hardwareInfo;
73    }
74
75    /// <summary>
76    /// collects and returns information that get displayed by the Client Console
77    /// </summary>
78    /// <returns></returns>
79    public StatusCommons GetStatusForClientConsole() {
80      //Todo: Locking
81      StatusCommons st = new StatusCommons();
82      st.ClientGuid = hardwareInfo.Id;
83
84      st.Status = WcfService.Instance.ConnState;
85      st.ConnectedSince = WcfService.Instance.ConnectedSince;
86
87      st.TotalCores = hardwareInfo.NrOfCores.HasValue ? hardwareInfo.NrOfCores.Value : 0;
88      st.FreeCores = hardwareInfo.NrOfCores.HasValue ? hardwareInfo.NrOfCores.Value - GetUsedCores() : 0;
89
90      st.JobsAborted = SlaveStatusInfo.JobsAborted;
91      st.JobsDone = SlaveStatusInfo.JobsProcessed;
92      st.JobsFetched = SlaveStatusInfo.JobsFetched;
93
94      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
95      st.Jobs = new List<JobStatus>();
96
97      lock (engines) {
98        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
99          Executor e = kvp.Value;
100          st.Jobs.Add(new JobStatus { JobId = e.JobId, ExecutionTime = e.ExecutionTime, Since = e.CreationTime });
101        }
102      }
103      return st;
104    }
105
106    public Dictionary<Guid, TimeSpan> GetExecutionTimeOfRunningJobs() {
107      Dictionary<Guid, TimeSpan> prog = new Dictionary<Guid, TimeSpan>();
108      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
109      lock (engines) {
110        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
111          if (kvp.Value.ExecutionState == HeuristicLab.Core.ExecutionState.Started) { // only report from started jobs. this ensures that hung jobs will get an abort after some timeout. also if a job is already prepared (after it stopped), the executionTime would be 00:00:00
112            Executor e = kvp.Value;
113            prog[e.JobId] = e.ExecutionTime;
114          }
115        }
116      }
117      return prog;
118    }
119
120    public int GetUsedCores() {
121      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
122      Dictionary<Guid, JobDto> jobs = Core.Jobs;
123      int usedCores = 0;
124      lock (engines) {
125        foreach (KeyValuePair<Guid, JobDto> kvp in jobs)
126          usedCores += kvp.Value.CoresNeeded;
127      }
128      return usedCores;
129    }
130
131  }
132}
Note: See TracBrowser for help on using the repository browser.