Changeset 17343
- Timestamp:
- 10/23/19 12:39:59 (5 years ago)
- Location:
- stable
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
-
stable/HeuristicLab.Clients.Hive.Slave
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Clients.Hive.Slave merged: 17316
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs
r17181 r17343 25 25 using System.Linq; 26 26 using System.Management; 27 using System.Net.NetworkInformation;28 27 using HeuristicLab.Clients.Hive.SlaveCore.Properties; 29 28 … … 133 132 try { 134 133 prog = jobManager.GetExecutionTimes(); 135 } 136 catch (Exception ex) { 134 } catch (Exception ex) { 137 135 SlaveClientCom.Instance.LogMessage(string.Format("Exception was thrown while trying to get execution times: {0}", ex.Message)); 138 136 } … … 140 138 } 141 139 140 /// <summary> 141 /// Returns the unique machine id of the slave 142 /// </summary> 143 /// <returns><see cref="Guid"/></returns> 142 144 public static Guid GetUniqueMachineId() { 143 Guid id;144 try {145 id = GetUniqueMachineIdFromMac();146 }147 catch {148 // fallback if something goes wrong...149 id = new Guid(Environment.MachineName.GetHashCode(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);150 } 151 return id;145 // Due to the fact that repeated calculation of the machine ID can lead to a client registering at 146 // the Hive server multiple times with different IDs it's better to set the unique machine id only 147 // once, at first startup, and store it in core settings. 148 if (Settings.Default.MachineId == Guid.Empty) { 149 Settings.Default.MachineId = Guid.NewGuid(); 150 Settings.Default.Save(); 151 } 152 153 return Settings.Default.MachineId; 152 154 } 153 155 … … 170 172 } 171 173 172 /// <summary>173 /// Generate a guid based on mac address of the first found nic (yes, mac addresses are not unique...)174 /// and the machine name.175 /// Format:176 ///177 /// D1 D2 D3 Res. D4178 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+179 /// |n a m e|0 0|0 0|0 0 mac address|180 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+181 ///182 /// The mac address is saved in the last 48 bits of the Data 4 segment183 /// of the guid (first 2 bytes of Data 4 are reserved).184 /// D1 contains the hash of the machinename.185 /// </summary>186 private static Guid GetUniqueMachineIdFromMac() {187 //try to get a real network interface, not a virtual one188 NetworkInterface validNic = NetworkInterface.GetAllNetworkInterfaces()189 .FirstOrDefault(x =>190 !x.Name.Contains(vmwareNameString) &&191 !x.Name.Contains(virtualboxNameString) &&192 (x.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||193 x.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet));194 195 if (validNic == default(NetworkInterface)) {196 validNic = NetworkInterface.GetAllNetworkInterfaces().First();197 }198 199 byte[] addr = validNic.GetPhysicalAddress().GetAddressBytes();200 if (addr.Length < macLength || addr.Length > macLongLength) {201 throw new ArgumentException(string.Format("Error generating slave UID: MAC address has to have a length between {0} and {1} bytes. Actual MAC address is: {2}",202 macLength, macLongLength, addr));203 }204 205 if (addr.Length < macLongLength) {206 byte[] b = new byte[8];207 Array.Copy(addr, 0, b, 2, addr.Length);208 addr = b;209 }210 211 // also get machine name and save it to the first 4 bytes212 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, addr);213 return guid;214 }215 216 174 private static long? GetWMIValue(string clazz, string property) { 217 175 ManagementClass mgtClass = new ManagementClass(clazz); … … 223 181 try { 224 182 return long.Parse(prop.Value.ToString()); 225 } 226 catch { 183 } catch { 227 184 return null; 228 185 } … … 241 198 try { 242 199 mb = (int)(memCounter.NextValue() / 1024 / 1024); 243 } 244 catch { } 200 } catch { } 245 201 return mb; 246 202 } … … 251 207 try { 252 208 return cpuCounter.NextValue(); 253 } 254 catch { } 209 } catch { } 255 210 return cpuVal; 256 211 } -
stable/HeuristicLab.Clients.Hive.Slave/3.3/Properties/Settings.Designer.cs
r12964 r17343 1 1 //------------------------------------------------------------------------------ 2 2 // <auto-generated> 3 // Dieser Code wurde von einem Tool generiert.4 // Laufzeitversion:4.0.30319.420003 // This code was generated by a tool. 4 // Runtime Version:4.0.30319.42000 5 5 // 6 // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn7 // der Code erneut generiert wird.6 // Changes to this file may cause incorrect behavior and will be lost if 7 // the code is regenerated. 8 8 // </auto-generated> 9 9 //------------------------------------------------------------------------------ … … 13 13 14 14 [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "1 4.0.0.0")]15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")] 16 16 public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 17 … … 323 323 } 324 324 } 325 326 [global::System.Configuration.UserScopedSettingAttribute()] 327 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 328 [global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")] 329 public global::System.Guid MachineId { 330 get { 331 return ((global::System.Guid)(this["MachineId"])); 332 } 333 set { 334 this["MachineId"] = value; 335 } 336 } 325 337 } 326 338 } -
stable/HeuristicLab.Clients.Hive.Slave/3.3/Properties/Settings.settings
r12964 r17343 78 78 <Value Profile="(Default)">00:05:00</Value> 79 79 </Setting> 80 <Setting Name="MachineId" Type="System.Guid" Scope="User"> 81 <Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value> 82 </Setting> 80 83 </Settings> 81 84 </SettingsFile> -
stable/HeuristicLab.Clients.Hive.Slave/3.3/app.config
r17059 r17343 84 84 <setting name="CheckpointCheckInterval" serializeAs="String"> 85 85 <value>00:05:00</value> 86 </setting> 87 <setting name="MachineId" serializeAs="String"> 88 <value>00000000-0000-0000-0000-000000000000</value> 86 89 </setting> 87 90 </HeuristicLab.Clients.Hive.SlaveCore.Properties.Settings>
Note: See TracChangeset
for help on using the changeset viewer.