Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5405 for branches


Ignore:
Timestamp:
02/01/11 18:12:46 (14 years ago)
Author:
cneumuel
Message:

#1233

  • moved heartbeat timestamps of slaves and jobs into database to make server stateless
  • made slave use the right authentication ("hiveslave" instead of HL username/password)
  • moved heartbeat related methods into HeartbeatManager
  • changed signature of Service.Hello method, so all hardware related information is transferred in that method withing the Slave-object
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
1 added
26 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockHiveService.cs

    r5375 r5405  
    215215
    216216    #region Login Methods
    217     public void Hello(Guid slaveId, string name, int cores, int memory) {
     217    public void Hello(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) {
    218218      // do nothing
    219219    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockServiceLocator.cs

    r5156 r5405  
    3434      return new Disposable<IHiveService>(service);
    3535    }
     36
     37    public Disposable<IHiveService> GetService(string username, string password) {
     38      return GetService();
     39    }
    3640  }
    3741}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs

    r5404 r5405  
    7575    /// </summary>
    7676    public void Connect(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) {
    77       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     77      using (Disposable<IHiveService> service = GetSlaveService()) {
    7878        try {
    7979          ConnState = NetworkEnum.WcfConnState.Connected;
    8080          ConnectedSince = DateTime.Now;
    81           service.Obj.Hello(slaveInfo.Id/*Settings.Default.Guid*/, slaveInfo.Name, slaveInfo.Cores.Value, slaveInfo.Memory.Value);
     81          service.Obj.Hello(slaveInfo);
    8282          OnConnected();
    8383        }
     
    9292    /// </summary>
    9393    public void Disconnect() {
    94       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     94      using (Disposable<IHiveService> service = GetSlaveService()) {
    9595        try {
    9696          service.Obj.GoodBye(ConfigManager.Instance.GetClientInfo().Id);
     
    116116    /// </summary>
    117117    public Job GetJob(Guid jobId) {
    118       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     118      using (Disposable<IHiveService> service = GetSlaveService()) {
    119119        try {
    120120          Job job = service.Obj.GetJob(jobId);
     
    129129
    130130    public JobData GetJobData(Guid jobId) {
    131       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     131      using (Disposable<IHiveService> service = GetSlaveService()) {
    132132        try {
    133133          JobData jobData = service.Obj.GetJobData(jobId);
     
    147147    /// <param name="jobData"></param>   
    148148    public void UpdateJob(Job job, JobData jobData) {
    149       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     149      using (Disposable<IHiveService> service = GetSlaveService()) {
    150150        try {
    151151          service.Obj.UpdateJob(job, jobData);
     
    158158
    159159    public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) {
    160       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     160      using (Disposable<IHiveService> service = GetSlaveService()) {
    161161        try {
    162162          List<MessageContainer> msg = service.Obj.Heartbeat(heartbeat);
     
    171171
    172172    public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
    173       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     173      using (Disposable<IHiveService> service = GetSlaveService()) {
    174174        try {
    175175          IEnumerable<PluginData> msg = service.Obj.GetPluginDatas(pluginIds);
     
    184184
    185185    public IEnumerable<Plugin> GetPlugins() {
    186       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     186      using (Disposable<IHiveService> service = GetSlaveService()) {
    187187        try {
    188188          IEnumerable<Plugin> msg = service.Obj.GetPlugins();
     
    197197
    198198    public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
    199       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     199      using (Disposable<IHiveService> service = GetSlaveService()) {
    200200        try {
    201201          Guid msg = service.Obj.AddChildJob(parentJobId, job, jobData);
     
    210210
    211211    public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) {
    212       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     212      using (Disposable<IHiveService> service = GetSlaveService()) {
    213213        try {
    214214          IEnumerable<LightweightJob> msg = service.Obj.GetLightweightChildJobs(parentJobId, false, false);
     
    228228
    229229    public void DeleteChildJobs(Guid jobId) {
    230       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     230      using (Disposable<IHiveService> service = GetSlaveService()) {
    231231        try {
    232232          service.Obj.DeleteChildJobs(jobId);
     
    239239
    240240    public PluginData GetConfigurationFile() {
    241       using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
     241      using (Disposable<IHiveService> service = GetSlaveService()) {
    242242        try {
    243243          PluginData msg = service.Obj.GetConfigurationFile();
     
    249249        }
    250250      }
     251    }
     252
     253    private static Disposable<IHiveService> GetSlaveService() {
     254      return ServiceLocator.Instance.GetService("hiveslave", "hiveslave");
    251255    }
    252256  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Tests

    • Property svn:ignore set to
      bin
      obj
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Tests/Mocks/MockServiceLocator.cs

    r5404 r5405  
    1212      return new Disposable<IHiveService>(new HiveService());
    1313    }
     14
     15    public Disposable<IHiveService> GetService(string username, string password) {
     16      return GetService();
     17    }
    1418  }
    1519}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/IServiceLocator.cs

    r5156 r5405  
    2626  public interface IServiceLocator {
    2727    Disposable<IHiveService> GetService();
     28    Disposable<IHiveService> GetService(string username, string password);
    2829  }
    2930}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs

    r5404 r5405  
    4141      return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService");
    4242    }
     43
     44    public Disposable<IHiveService> GetService(string username, string password) {
     45      return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService", null, username, password);
     46    }
    4347  }
    4448}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Heartbeat.cs

    r5092 r5405  
    3737    public Dictionary<Guid, TimeSpan> JobProgress { get; set; } // TODO: define Type
    3838    [DataMember]
    39     public bool IsAllowedToCalculate { get; set; } // this is true if slave is allowed to work according to calendar
     39    public bool AssignJob { get; set; } // if false, the server will not assign a new job
    4040
    4141    public override string ToString() {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Job.cs

    r5402 r5405  
    4040    [DataMember]
    4141    public List<Guid> PluginsNeededIds { get; set; }
     42    [DataMember]
     43    public DateTime? LastHeartbeat { get; set; }
    4244
    4345    public Job() {
     
    5052      this.MemoryNeeded = original.MemoryNeeded;
    5153      this.PluginsNeededIds = new List<Guid>(original.PluginsNeededIds);
     54      this.LastHeartbeat = original.LastHeartbeat;
    5255    }
    5356    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Slave.cs

    r5404 r5405  
    5050    [DataMember]
    5151    public bool IsAllowedToCalculate { get; set; }
     52    [DataMember]
     53    public DateTime? LastHeartbeat { get; set; }
    5254
    5355    public Slave() {
     
    6264      this.SlaveState = original.SlaveState;
    6365      this.IsAllowedToCalculate = original.IsAllowedToCalculate;
     66      this.OperatingSystem = original.OperatingSystem;
     67      this.CpuArchitecture = original.CpuArchitecture;
     68      this.LastHeartbeat = original.LastHeartbeat;
    6469    }
    6570    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/ServiceContracts/IHiveService.cs

    r5404 r5405  
    7676    #region Login Methods
    7777    [OperationContract]
    78     void Hello(Guid slaveId, string name, int cores, int memory);
     78    void Hello(Slave slave);
    7979
    8080    [OperationContract]
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs

    r5404 r5405  
    4444        JobState = source.JobState,
    4545        UserId = source.UserId,
    46         PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList()
     46        PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList(),
     47        LastHeartbeat = source.LastHeartbeat       
    4748      };
    4849    }
     
    6768        target.JobState = source.JobState;
    6869        target.UserId = source.UserId;
    69         // RequiredPlugins need to be added by Dao
     70        target.LastHeartbeat = source.LastHeartbeat;
     71        // RequiredPlugins are added by Dao
    7072      }
    7173    }
     
    143145    public static DT.Slave ToDto(Slave source) {
    144146      if (source == null) return null;
    145       return new DT.Slave { Id = source.ResourceId, ParentResourceId = source.ParentResourceId, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveState = source.SlaveState, CpuArchitecture = source.CpuArchitecture, OperatingSystem = source.OperatingSystem };
     147      return new DT.Slave {
     148        Id = source.ResourceId,
     149        ParentResourceId = source.ParentResourceId,
     150        Cores = source.Cores,
     151        CpuSpeed = source.CpuSpeed,
     152        FreeCores = source.FreeCores,
     153        FreeMemory = source.FreeMemory,
     154        IsAllowedToCalculate = source.IsAllowedToCalculate,
     155        Memory = source.Memory,
     156        Name = source.Name,
     157        SlaveState = source.SlaveState,
     158        CpuArchitecture = source.CpuArchitecture,
     159        OperatingSystem = source.OperatingSystem,
     160        LastHeartbeat = source.LastHeartbeat
     161      };
    146162    }
    147163    public static Slave ToEntity(DT.Slave source) {
     
    152168    public static void ToEntity(DT.Slave source, Slave target) {
    153169      if ((source != null) && (target != null)) {
    154         target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = source.SlaveState; target.CpuArchitecture = source.CpuArchitecture; target.OperatingSystem = source.OperatingSystem;
     170        target.ResourceId = source.Id;
     171        target.ParentResourceId = source.ParentResourceId;
     172        target.Cores = source.Cores;
     173        target.CpuSpeed = source.CpuSpeed;
     174        target.FreeCores = source.FreeCores;
     175        target.FreeMemory = source.FreeMemory;
     176        target.IsAllowedToCalculate = source.IsAllowedToCalculate;
     177        target.Memory = source.Memory;
     178        target.Name = source.Name;
     179        target.SlaveState = source.SlaveState;
     180        target.CpuArchitecture = source.CpuArchitecture;
     181        target.OperatingSystem = source.OperatingSystem;
     182        target.LastHeartbeat = source.LastHeartbeat;
    155183      }
    156184    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml

    r5404 r5405  
    5050        <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" />
    5151        <Column Name="CpuArchitecture" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture" DbType="VarChar(3)" CanBeNull="false" />
    52         <Column Name="OperatingSystem" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" />
     52        <Column Name="OperatingSystem" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" UpdateCheck="Never" />
     53        <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    5354        <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" />
    5455      </Type>
     
    7273      <Column Name="CoresNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    7374      <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
     75      <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    7476      <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" />
    7577      <Association Name="Job_RequiredPlugin" Member="RequiredPlugins" ThisKey="JobId" OtherKey="JobId" Type="RequiredPlugin" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout

    r5404 r5405  
    2727      </nestedChildShapes>
    2828    </classShape>
    29     <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 3.5016097005208326">
     29    <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 3.6939111328124996">
    3030      <DataClassMoniker Name="/HiveDataContext/Job" />
    3131      <nestedChildShapes>
    32         <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 2.941609700520833" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
     32        <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 3.1339111328125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
    3333      </nestedChildShapes>
    3434    </classShape>
     
    4545      </nestedChildShapes>
    4646    </classShape>
    47     <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2.7324039713541666">
     47    <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 0.75, 2, 2.9247054036458331">
    4848      <DataClassMoniker Name="/HiveDataContext/Slave" />
    4949      <nestedChildShapes>
    50         <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
     50        <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.21, 1.9700000000000002, 2.364705403645833" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
    5151      </nestedChildShapes>
    5252    </classShape>
     
    7676      </nodes>
    7777    </associationConnector>
    78     <associationConnector edgePoints="[(8.5 : 4.12580485026042); (8.875 : 4.12580485026042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     78    <associationConnector edgePoints="[(8.5 : 4.22195556640625); (8.875 : 4.22195556640625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    7979      <AssociationMoniker Name="/HiveDataContext/Job/Job_AssignedResource" />
    8080      <nodes>
     
    8383      </nodes>
    8484    </associationConnector>
    85     <associationConnector edgePoints="[(7.1210551923077 : 4.50160970052083); (7.1210551923077 : 5.5)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     85    <associationConnector edgePoints="[(7.0898076923077 : 4.6939111328125); (7.0898076923077 : 5.5)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    8686      <AssociationMoniker Name="/HiveDataContext/Job/Job_RequiredPlugin" />
    8787      <nodes>
     
    9090      </nodes>
    9191    </associationConnector>
    92     <associationConnector edgePoints="[(8.3334359271285 : 4.50160970052083); (8.3334359271285 : 4.58410970052083); (8.4156121961154 : 4.58410970052083); (8.4156121961154 : 4.75160970052083); (7.8046153846154 : 4.75160970052083); (7.8046153846154 : 4.50160970052083)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
     92    <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.75); (7.80461538461539 : 0.75); (7.80461538461539 : 1)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
    9393      <AssociationMoniker Name="/HiveDataContext/Job/Job_Job" />
    9494      <nodes>
     
    9797      </nodes>
    9898    </associationConnector>
    99     <associationConnector edgePoints="[(8.875 : 2.36620198567708); (8.5 : 2.36620198567708)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     99    <associationConnector edgePoints="[(8.875 : 2.33735270182292); (8.5 : 2.33735270182292)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    100100      <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" />
    101101      <nodes>
     
    111111      </nodes>
    112112    </associationConnector>
    113     <associationConnector edgePoints="[(6.5 : 3.56330485026042); (6.125 : 3.56330485026042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     113    <associationConnector edgePoints="[(6.5 : 3.65945556640625); (6.125 : 3.65945556640625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    114114      <AssociationMoniker Name="/HiveDataContext/Job/Job_HiveExperiment" />
    115115      <nodes>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs

    r5404 r5405  
    10641064    private string _OperatingSystem;
    10651065   
     1066    private System.Nullable<System.DateTime> _LastHeartbeat;
     1067   
    10661068    private EntitySet<Job> _Jobs;
    10671069   
     
    10901092    partial void OnOperatingSystemChanging(string value);
    10911093    partial void OnOperatingSystemChanged();
     1094    partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value);
     1095    partial void OnLastHeartbeatChanged();
    10921096    #endregion
    10931097   
     
    12781282    }
    12791283   
    1280     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OperatingSystem", DbType="VarChar(MAX)", CanBeNull=false)]
     1284    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OperatingSystem", DbType="VarChar(MAX)", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    12811285    public string OperatingSystem
    12821286    {
     
    12941298          this.SendPropertyChanged("OperatingSystem");
    12951299          this.OnOperatingSystemChanged();
     1300        }
     1301      }
     1302    }
     1303   
     1304    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastHeartbeat", DbType="DateTime")]
     1305    public System.Nullable<System.DateTime> LastHeartbeat
     1306    {
     1307      get
     1308      {
     1309        return this._LastHeartbeat;
     1310      }
     1311      set
     1312      {
     1313        if ((this._LastHeartbeat != value))
     1314        {
     1315          this.OnLastHeartbeatChanging(value);
     1316          this.SendPropertyChanging();
     1317          this._LastHeartbeat = value;
     1318          this.SendPropertyChanged("LastHeartbeat");
     1319          this.OnLastHeartbeatChanged();
    12961320        }
    12971321      }
     
    13721396   
    13731397    private int _MemoryNeeded;
     1398   
     1399    private System.Nullable<System.DateTime> _LastHeartbeat;
    13741400   
    13751401    private EntitySet<AssignedResource> _AssignedResources;
     
    14171443    partial void OnMemoryNeededChanging(int value);
    14181444    partial void OnMemoryNeededChanged();
     1445    partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value);
     1446    partial void OnLastHeartbeatChanged();
    14191447    #endregion
    14201448   
     
    17101738          this.SendPropertyChanged("MemoryNeeded");
    17111739          this.OnMemoryNeededChanged();
     1740        }
     1741      }
     1742    }
     1743   
     1744    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastHeartbeat", DbType="DateTime")]
     1745    public System.Nullable<System.DateTime> LastHeartbeat
     1746    {
     1747      get
     1748      {
     1749        return this._LastHeartbeat;
     1750      }
     1751      set
     1752      {
     1753        if ((this._LastHeartbeat != value))
     1754        {
     1755          this.OnLastHeartbeatChanging(value);
     1756          this.SendPropertyChanging();
     1757          this._LastHeartbeat = value;
     1758          this.SendPropertyChanged("LastHeartbeat");
     1759          this.OnLastHeartbeatChanged();
    17121760        }
    17131761      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs

    r5404 r5405  
    7676
    7777      DT.Slave slave = new DT.Slave() {
     78        Id = Guid.NewGuid(),
    7879        Name = "Test",
    79         OperatingSystem = Environment.OSVersion.VersionString,
     80        OperatingSystem = null, //"Windows 3.11",
    8081        Cores = 2,
    81         Memory = 1024
     82        Memory = 1024,
     83        FreeMemory = 512
    8284      };
    83       slave.Id= dao.AddSlave(slave);
     85
     86      Assert.AreEqual(slave.Id, dao.AddSlave(slave));
     87
     88      // update
     89      slave.FreeMemory = 255;
     90      slave.OperatingSystem = Environment.OSVersion.VersionString;
     91      dao.UpdateSlave(slave);
     92
     93      DT.Slave slaveLoaded = dao.GetSlave(slave.Id);
     94      Assert.AreEqual(slave.FreeMemory, slaveLoaded.FreeMemory);
    8495
    8596      dao.DeleteSlave(slave.Id);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/Mocks/MockLifecycleManager.cs

    r5156 r5405  
    2828  public class MockLifecycleManager : ILifecycleManager {
    2929
    30     public void Start() {
     30    public void Start() { }
    3131
    32     }
    33 
    34     public void Stop() {
    35 
    36     }
    37 
    38     public List<MessageContainer> ProcessHeartbeat(Heartbeat heartbeat) {
    39       throw new NotImplementedException();
    40     }
     32    public void Stop() { }
    4133  }
    4234}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/Mocks/MockServiceLocator.cs

    r5156 r5405  
    3939    }
    4040
    41     private ILifecycleManager lifecycleManager;
    4241    public ILifecycleManager LifecycleManager {
    4342      get {
     
    5049    }
    5150
     51    public HeartbeatManager HeartbeatManager {
     52      get {
     53        return defaultServiceLocator.HeartbeatManager;
     54      }
     55    }
    5256  }
    5357}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/App_Code/HiveServerModule.cs

    r5375 r5405  
    2727using HeuristicLab.Services.Hive.Common.ServiceContracts;
    2828using HeuristicLab.Services.Hive;
     29using HeuristicLab.Tracing;
    2930
    3031namespace HeuristicLab.Hive.Server.Core.IISModules {
     
    3738      if (lifecycleManager == null)
    3839        lifecycleManager = new LifecycleManager();
     40      lifecycleManager.Start();
    3941    }
    4042
    4143    public void Dispose() {
    42      
     44      lifecycleManager.Stop();
    4345    }
    4446  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/Web.config

    r5402 r5405  
    7070
    7171  <system.webServer>
    72     <!--<modules runAllManagedModulesForAllRequests="true">
     72    <modules runAllManagedModulesForAllRequests="true">
    7373      <add name="HiveServerModule" type="HeuristicLab.Hive.Server.Core.IISModules.HiveServerModule"/>
    74     </modules>-->
     74    </modules>
    7575    <directoryBrowse enabled="true"/>
    7676  </system.webServer>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeuristicLab.Services.Hive-3.4.csproj

    r5402 r5405  
    112112    <None Include="HeuristicLabServicesHivePlugin.cs.frame" />
    113113    <None Include="Properties\AssemblyInfo.cs.frame" />
     114    <Compile Include="HeartbeatManager.cs" />
    114115    <Compile Include="Interfaces\ILifecycleManager.cs" />
    115116    <Compile Include="Interfaces\IServiceLocator.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs

    r5404 r5405  
    2525    private ILifecycleManager lifecycleManager {
    2626      get { return ServiceLocator.Instance.LifecycleManager; }
     27    }
     28    private HeartbeatManager heartbeatManager {
     29      get { return ServiceLocator.Instance.HeartbeatManager; }
    2730    }
    2831
     
    162165
    163166    #region Login Methods
    164     public void Hello(Guid slaveId, string name, int cores, int memory) {
    165       using (trans.OpenTransaction()) {
    166         var slave = dao.GetSlave(slaveId);
     167    public void Hello(Slave slaveInfo) {
     168      using (trans.OpenTransaction()) {
     169        var slave = dao.GetSlave(slaveInfo.Id);
    167170
    168171        if (slave == null) {
    169           slave = new Slave { Id = slaveId, Name = name, Cores = cores, Memory = memory };
    170           slave.IsAllowedToCalculate = true; //a little bit to optimistic?
    171           slave.SlaveState = SlaveState.Idle;
    172           dao.AddSlave(slave);
     172          dao.AddSlave(slaveInfo);
    173173        } else {
    174           //TODO: error handling?
     174          dao.UpdateSlave(slaveInfo);
    175175        }
    176176      }
     
    191191    public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
    192192      using (trans.OpenTransaction()) {
    193         return lifecycleManager.ProcessHeartbeat(heartbeat);
     193        return heartbeatManager.ProcessHeartbeat(heartbeat);
    194194      }
    195195    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/ILifecycleManager.cs

    r5095 r5405  
    1414
    1515    void Stop();
    16 
    17     List<MessageContainer> ProcessHeartbeat(Heartbeat heartbeat);
    1816  }
    1917}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/IServiceLocator.cs

    r5095 r5405  
    1212    ILifecycleManager LifecycleManager { get; }
    1313    TransactionManager TransactionManager { get; }
     14    HeartbeatManager HeartbeatManager { get; }
    1415  }
    1516}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs

    r5404 r5405  
    2525
    2626    private static object locker = new object();
    27     private Dictionary<Guid, DateTime> heartbeats = new Dictionary<Guid, DateTime>();
    2827
    2928    // Windows-Forms timer is single threaded, so callbacks will be synchron
    30     System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
     29    System.Windows.Forms.Timer timer;
    3130
    32     /// <summary>
    33     /// Contains a list job JobIds which have been sent to a slave, but the slave has not yet sent
    34     /// a jobProgress of the job with a heartbeat, because he has not finished downloading/deserializing it.
    35     /// The number value indicates a TimeToLive count that is decremented with each server-heartbeat.
    36     /// When the number reaches zero, the jobs is assumed to be lost and is set Offline again.
    37     /// </summary>
    38     private Dictionary<Guid, int> newlyAssignedJobs = new Dictionary<Guid, int>();
    39 
    40     /// <summary>
    41     /// Counts how many jobs are currently beeing transferred.
    42     /// </summary>
    43     private int jobsCurrentlyTransfering = 0;
    44     public int JobsCurrentlyTransferring {
    45       get { return jobsCurrentlyTransfering; }
    46       set {
    47         if (jobsCurrentlyTransfering != value) {
    48           jobsCurrentlyTransfering = value;
    49           Logger.Info("JobsCurrentlyTransfering: " + jobsCurrentlyTransfering);
    50         }
    51       }
     31    public ExecutionState ExecutionState {
     32      get { return timer.Enabled ? ExecutionState.Started : Core.ExecutionState.Stopped; }
    5233    }
    5334
    54     public ExecutionState ExecutionState {
    55       get { return timer.Enabled ? ExecutionState.Started : Core.ExecutionState.Stopped;  }
     35    public LifecycleManager() {
     36      this.timer = new System.Windows.Forms.Timer();
     37      this.timer.Tick += new EventHandler(timer_Tick);
    5638    }
    57 
    58     public LifecycleManager() { }
    5939
    6040    public void Start() {
    6141      if (ExecutionState == Core.ExecutionState.Stopped) {
    6242        this.timer.Interval = (int)new TimeSpan(0, 0, 10).TotalMilliseconds;
    63         this.timer.Tick += new EventHandler(timer_Tick);
    6443        this.timer.Start();
    65         AddAllSlavesToHeartbeats();
    6644      }
    6745    }
     
    7452
    7553    /// <summary>
    76     // add all slaves to hearbeats-collection and give them some time to say hello (HEARTBEAT_TIMEOUT)
    77     // otherwise alls the slaves jobs would be aborted immediately, which is not desirable if the server has just been restarted
    78     /// </summary>
    79     private void AddAllSlavesToHeartbeats() {
    80       lock (locker) {
    81         using (trans.OpenTransaction()) {
    82           Guid[] slaveIds = dao.GetSlaves(x => true).Select(s => s.Id).ToArray();
    83           foreach (Guid slaveId in slaveIds) {
    84             if (!heartbeats.ContainsKey(slaveId)) {
    85               heartbeats.Add(slaveId, DateTime.Now);
    86             }
    87           }
    88         }
    89       }
    90     }
    91 
    92     /// <summary>
    9354    /// This method is supposed to check if slaves are online
    9455    /// if not -> set them offline and check if they where calculating a job
     
    9758      lock (locker) {
    9859        using (trans.OpenTransaction()) {
    99           Guid[] slaveIds = dao.GetSlaves(x => true).Select(s => s.Id).ToArray();
    100           foreach (Guid slaveId in slaveIds) {
    101             if (SlaveTimedOut(slaveId)) {
    102               var slave = dao.GetSlave(slaveId);
    103               if (slave.SlaveState != SlaveState.Offline) {
    104                 AbortJobs(slaveId);
    105                 slave.SlaveState = SlaveState.Offline;
    106                 dao.UpdateSlave(slave);
    107               }
    108               heartbeats.Remove(slaveId);
     60          var slaves = dao.GetSlaves(x => x.SlaveState != SlaveState.Offline);
     61          foreach (Slave slave in slaves) {
     62            if (!slave.LastHeartbeat.HasValue || (DateTime.Now - slave.LastHeartbeat.Value).TotalSeconds > ApplicationConstants.HeartbeatTimeout) {
     63              slave.SlaveState = SlaveState.Offline;
     64              AbortJobs(slave.Id);
     65              dao.UpdateSlave(slave);
    10966            }
    11067          }
    11168        }
    11269      }
    113     }
    114 
    115     private bool SlaveTimedOut(Guid slaveId) {
    116       if (!heartbeats.ContainsKey(slaveId))
    117         return true;
    118 
    119       if ((DateTime.Now - heartbeats[slaveId]).TotalSeconds > ApplicationConstants.HeartbeatTimeout) {
    120         return true;
    121       }
    122 
    123       return false;
    12470    }
    12571
     
    13177      }
    13278    }
    133 
    134     /// <summary>
    135     /// This method will be called every time a slave sends a heartbeat (-> very often; concurrency is important!)
    136     /// </summary>
    137     /// <returns>a list of actions the slave should do</returns>
    138     public List<MessageContainer> ProcessHeartbeat(Heartbeat heartbeat) {
    139       List<MessageContainer> actions = new List<MessageContainer>();
    140       Slave slave = dao.GetSlave(heartbeat.SlaveId);
    141       if (slave == null) {
    142         actions.Add(new MessageContainer(MessageContainer.MessageType.SayHello));
    143       } else {
    144         heartbeats[heartbeat.SlaveId] = DateTime.Now;
    145         actions.AddRange(UpdateJobs(heartbeat));
    146 
    147         if (this.IsAllowedToSendJobs() && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) {
    148           var availableJobs = dao.GetWaitingJobs(slave, 1);
    149           if (availableJobs.Count() > 0) {
    150             var job = availableJobs.First();
    151             actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob, job.Id));
    152             AssignJob(slave, job);
    153           }
    154         }
    155 
    156         if (slave.FreeCores != heartbeat.FreeCores ||
    157             slave.FreeMemory != heartbeat.FreeMemory ||
    158             slave.IsAllowedToCalculate != heartbeat.IsAllowedToCalculate ||
    159             slave.SlaveState != (heartbeat.JobProgress.Count > 0 ? SlaveState.Calculating : SlaveState.Idle)) { // only update slave when something changed, to avoid unnecessary updates
    160           slave.FreeCores = heartbeat.FreeCores;
    161           slave.FreeMemory = heartbeat.FreeMemory;
    162           slave.IsAllowedToCalculate = heartbeat.IsAllowedToCalculate;
    163           slave.SlaveState = (heartbeat.JobProgress != null && heartbeat.JobProgress.Count > 0) ? SlaveState.Calculating : SlaveState.Idle;
    164           dao.UpdateSlave(slave);
    165         }
    166       }
    167       return actions;
    168     }
    169 
    170     private void AssignJob(Slave slave, Job job) {
    171       job.SlaveId = slave.Id;
    172       job.JobState = JobState.Calculating; // Todo: Maybe use State = Transferring (?)
    173       job.DateCalculated = DateTime.Now; // Todo: use statelog instead
    174       dao.UpdateJob(job);
    175       dao.UpdateSlave(slave);
    176     }
    177 
    178     /// <summary>
    179     /// Update the progress of each job
    180     /// Checks if all the jobs sent by heartbeat are supposed to be calculated by this slave
    181     /// </summary>
    182     private IEnumerable<MessageContainer> UpdateJobs(Heartbeat heartbeat) {
    183       List<MessageContainer> actions = new List<MessageContainer>();
    184 
    185       if (heartbeat.JobProgress == null)
    186         return actions;
    187 
    188       // process the jobProgresses
    189       foreach (var jobProgress in heartbeat.JobProgress) {
    190         Job curJob = dao.GetJob(jobProgress.Key);
    191         if (curJob == null) {
    192           // job does not exist in db
    193           actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, jobProgress.Key));
    194           Logger.Error("Job does not exist in DB: " + jobProgress.Key);
    195         } else {
    196           if (curJob.SlaveId == Guid.Empty || curJob.SlaveId != heartbeat.SlaveId) {
    197             // assigned slave does not match heartbeat
    198             actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
    199             Logger.Error("The slave " + heartbeat.SlaveId + " is not supposed to calculate Job: " + curJob);
    200           } else {
    201             // save job execution time
    202             curJob.ExecutionTime = jobProgress.Value;
    203 
    204             if (curJob.JobState == JobState.Aborted) {
    205               // a request to abort the job has been set
    206               actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
    207             }
    208             dao.UpdateJob(curJob);
    209           }
    210         }
    211       }
    212       return actions;
    213     }
    214 
    215     /// <summary>
    216     /// Returns true if there are enough resources to send a job
    217     /// There should not be too many jobs sent simultaniously
    218     /// </summary>
    219     private bool IsAllowedToSendJobs() {
    220       return JobsCurrentlyTransferring < ApplicationConstants.MaxJobTransferCount;
    221     }
    22279  }
    22380}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/ServiceLocator.cs

    r5095 r5405  
    4848      }
    4949    }
     50
     51    private HeartbeatManager heartbeatManager;
     52    public HeartbeatManager HeartbeatManager {
     53      get {
     54        if(heartbeatManager == null) heartbeatManager = new HeartbeatManager();
     55        return heartbeatManager;
     56      }
     57    }
    5058  }
    5159}
Note: See TracChangeset for help on using the changeset viewer.