Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17343


Ignore:
Timestamp:
10/23/19 12:39:59 (5 years ago)
Author:
jkarder
Message:

#3033: merged r17316 into stable

Location:
stable
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Clients.Hive.Slave

  • stable/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs

    r17181 r17343  
    2525using System.Linq;
    2626using System.Management;
    27 using System.Net.NetworkInformation;
    2827using HeuristicLab.Clients.Hive.SlaveCore.Properties;
    2928
     
    133132      try {
    134133        prog = jobManager.GetExecutionTimes();
    135       }
    136       catch (Exception ex) {
     134      } catch (Exception ex) {
    137135        SlaveClientCom.Instance.LogMessage(string.Format("Exception was thrown while trying to get execution times: {0}", ex.Message));
    138136      }
     
    140138    }
    141139
     140    /// <summary>
     141    /// Returns the unique machine id of the slave
     142    /// </summary>
     143    /// <returns><see cref="Guid"/></returns>
    142144    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;
    152154    }
    153155
     
    170172    }
    171173
    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.   D4
    178     /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    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 segment
    183     /// 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 one
    188       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 bytes               
    212       Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, addr);
    213       return guid;
    214     }
    215 
    216174    private static long? GetWMIValue(string clazz, string property) {
    217175      ManagementClass mgtClass = new ManagementClass(clazz);
     
    223181            try {
    224182              return long.Parse(prop.Value.ToString());
    225             }
    226             catch {
     183            } catch {
    227184              return null;
    228185            }
     
    241198      try {
    242199        mb = (int)(memCounter.NextValue() / 1024 / 1024);
    243       }
    244       catch { }
     200      } catch { }
    245201      return mb;
    246202    }
     
    251207      try {
    252208        return cpuCounter.NextValue();
    253       }
    254       catch { }
     209      } catch { }
    255210      return cpuVal;
    256211    }
  • stable/HeuristicLab.Clients.Hive.Slave/3.3/Properties/Settings.Designer.cs

    r12964 r17343  
    11//------------------------------------------------------------------------------
    22// <auto-generated>
    3 //     Dieser Code wurde von einem Tool generiert.
    4 //     Laufzeitversion:4.0.30319.42000
     3//     This code was generated by a tool.
     4//     Runtime Version:4.0.30319.42000
    55//
    6 //     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
    7 //     der Code erneut generiert wird.
     6//     Changes to this file may cause incorrect behavior and will be lost if
     7//     the code is regenerated.
    88// </auto-generated>
    99//------------------------------------------------------------------------------
     
    1313   
    1414    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    15     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
     15    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")]
    1616    public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    1717       
     
    323323            }
    324324        }
     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        }
    325337    }
    326338}
  • stable/HeuristicLab.Clients.Hive.Slave/3.3/Properties/Settings.settings

    r12964 r17343  
    7878      <Value Profile="(Default)">00:05:00</Value>
    7979    </Setting>
     80    <Setting Name="MachineId" Type="System.Guid" Scope="User">
     81      <Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
     82    </Setting>
    8083  </Settings>
    8184</SettingsFile>
  • stable/HeuristicLab.Clients.Hive.Slave/3.3/app.config

    r17059 r17343  
    8484      <setting name="CheckpointCheckInterval" serializeAs="String">
    8585        <value>00:05:00</value>
     86      </setting>
     87      <setting name="MachineId" serializeAs="String">
     88        <value>00000000-0000-0000-0000-000000000000</value>
    8689      </setting>
    8790    </HeuristicLab.Clients.Hive.SlaveCore.Properties.Settings>
Note: See TracChangeset for help on using the changeset viewer.