Changeset 17343 for stable/HeuristicLab.Clients.Hive.Slave/3.3/Manager
- Timestamp:
- 10/23/19 12:39:59 (5 years ago)
- Location:
- stable
- Files:
-
- 3 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 }
Note: See TracChangeset
for help on using the changeset viewer.