- Timestamp:
- 02/01/11 18:12:46 (14 years ago)
- 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 215 215 216 216 #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) { 218 218 // do nothing 219 219 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockServiceLocator.cs
r5156 r5405 34 34 return new Disposable<IHiveService>(service); 35 35 } 36 37 public Disposable<IHiveService> GetService(string username, string password) { 38 return GetService(); 39 } 36 40 } 37 41 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs
r5404 r5405 75 75 /// </summary> 76 76 public void Connect(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) { 77 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {77 using (Disposable<IHiveService> service = GetSlaveService()) { 78 78 try { 79 79 ConnState = NetworkEnum.WcfConnState.Connected; 80 80 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); 82 82 OnConnected(); 83 83 } … … 92 92 /// </summary> 93 93 public void Disconnect() { 94 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {94 using (Disposable<IHiveService> service = GetSlaveService()) { 95 95 try { 96 96 service.Obj.GoodBye(ConfigManager.Instance.GetClientInfo().Id); … … 116 116 /// </summary> 117 117 public Job GetJob(Guid jobId) { 118 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {118 using (Disposable<IHiveService> service = GetSlaveService()) { 119 119 try { 120 120 Job job = service.Obj.GetJob(jobId); … … 129 129 130 130 public JobData GetJobData(Guid jobId) { 131 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {131 using (Disposable<IHiveService> service = GetSlaveService()) { 132 132 try { 133 133 JobData jobData = service.Obj.GetJobData(jobId); … … 147 147 /// <param name="jobData"></param> 148 148 public void UpdateJob(Job job, JobData jobData) { 149 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {149 using (Disposable<IHiveService> service = GetSlaveService()) { 150 150 try { 151 151 service.Obj.UpdateJob(job, jobData); … … 158 158 159 159 public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) { 160 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {160 using (Disposable<IHiveService> service = GetSlaveService()) { 161 161 try { 162 162 List<MessageContainer> msg = service.Obj.Heartbeat(heartbeat); … … 171 171 172 172 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 173 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {173 using (Disposable<IHiveService> service = GetSlaveService()) { 174 174 try { 175 175 IEnumerable<PluginData> msg = service.Obj.GetPluginDatas(pluginIds); … … 184 184 185 185 public IEnumerable<Plugin> GetPlugins() { 186 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {186 using (Disposable<IHiveService> service = GetSlaveService()) { 187 187 try { 188 188 IEnumerable<Plugin> msg = service.Obj.GetPlugins(); … … 197 197 198 198 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) { 199 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {199 using (Disposable<IHiveService> service = GetSlaveService()) { 200 200 try { 201 201 Guid msg = service.Obj.AddChildJob(parentJobId, job, jobData); … … 210 210 211 211 public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) { 212 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {212 using (Disposable<IHiveService> service = GetSlaveService()) { 213 213 try { 214 214 IEnumerable<LightweightJob> msg = service.Obj.GetLightweightChildJobs(parentJobId, false, false); … … 228 228 229 229 public void DeleteChildJobs(Guid jobId) { 230 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {230 using (Disposable<IHiveService> service = GetSlaveService()) { 231 231 try { 232 232 service.Obj.DeleteChildJobs(jobId); … … 239 239 240 240 public PluginData GetConfigurationFile() { 241 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {241 using (Disposable<IHiveService> service = GetSlaveService()) { 242 242 try { 243 243 PluginData msg = service.Obj.GetConfigurationFile(); … … 249 249 } 250 250 } 251 } 252 253 private static Disposable<IHiveService> GetSlaveService() { 254 return ServiceLocator.Instance.GetService("hiveslave", "hiveslave"); 251 255 } 252 256 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Tests
-
Property
svn:ignore
set to
bin
obj
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Tests/Mocks/MockServiceLocator.cs
r5404 r5405 12 12 return new Disposable<IHiveService>(new HiveService()); 13 13 } 14 15 public Disposable<IHiveService> GetService(string username, string password) { 16 return GetService(); 17 } 14 18 } 15 19 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/IServiceLocator.cs
r5156 r5405 26 26 public interface IServiceLocator { 27 27 Disposable<IHiveService> GetService(); 28 Disposable<IHiveService> GetService(string username, string password); 28 29 } 29 30 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs
r5404 r5405 41 41 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService"); 42 42 } 43 44 public Disposable<IHiveService> GetService(string username, string password) { 45 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService", null, username, password); 46 } 43 47 } 44 48 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Heartbeat.cs
r5092 r5405 37 37 public Dictionary<Guid, TimeSpan> JobProgress { get; set; } // TODO: define Type 38 38 [DataMember] 39 public bool IsAllowedToCalculate { get; set; } // this is true if slave is allowed to work according to calendar39 public bool AssignJob { get; set; } // if false, the server will not assign a new job 40 40 41 41 public override string ToString() { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Job.cs
r5402 r5405 40 40 [DataMember] 41 41 public List<Guid> PluginsNeededIds { get; set; } 42 [DataMember] 43 public DateTime? LastHeartbeat { get; set; } 42 44 43 45 public Job() { … … 50 52 this.MemoryNeeded = original.MemoryNeeded; 51 53 this.PluginsNeededIds = new List<Guid>(original.PluginsNeededIds); 54 this.LastHeartbeat = original.LastHeartbeat; 52 55 } 53 56 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Slave.cs
r5404 r5405 50 50 [DataMember] 51 51 public bool IsAllowedToCalculate { get; set; } 52 [DataMember] 53 public DateTime? LastHeartbeat { get; set; } 52 54 53 55 public Slave() { … … 62 64 this.SlaveState = original.SlaveState; 63 65 this.IsAllowedToCalculate = original.IsAllowedToCalculate; 66 this.OperatingSystem = original.OperatingSystem; 67 this.CpuArchitecture = original.CpuArchitecture; 68 this.LastHeartbeat = original.LastHeartbeat; 64 69 } 65 70 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/ServiceContracts/IHiveService.cs
r5404 r5405 76 76 #region Login Methods 77 77 [OperationContract] 78 void Hello( Guid slaveId, string name, int cores, int memory);78 void Hello(Slave slave); 79 79 80 80 [OperationContract] -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs
r5404 r5405 44 44 JobState = source.JobState, 45 45 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 47 48 }; 48 49 } … … 67 68 target.JobState = source.JobState; 68 69 target.UserId = source.UserId; 69 // RequiredPlugins need to be added by Dao 70 target.LastHeartbeat = source.LastHeartbeat; 71 // RequiredPlugins are added by Dao 70 72 } 71 73 } … … 143 145 public static DT.Slave ToDto(Slave source) { 144 146 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 }; 146 162 } 147 163 public static Slave ToEntity(DT.Slave source) { … … 152 168 public static void ToEntity(DT.Slave source, Slave target) { 153 169 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; 155 183 } 156 184 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml
r5404 r5405 50 50 <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" /> 51 51 <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" /> 53 54 <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" /> 54 55 </Type> … … 72 73 <Column Name="CoresNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 73 74 <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 75 <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" /> 74 76 <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" /> 75 77 <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 27 27 </nestedChildShapes> 28 28 </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"> 30 30 <DataClassMoniker Name="/HiveDataContext/Job" /> 31 31 <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" /> 33 33 </nestedChildShapes> 34 34 </classShape> … … 45 45 </nestedChildShapes> 46 46 </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"> 48 48 <DataClassMoniker Name="/HiveDataContext/Slave" /> 49 49 <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" /> 51 51 </nestedChildShapes> 52 52 </classShape> … … 76 76 </nodes> 77 77 </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"> 79 79 <AssociationMoniker Name="/HiveDataContext/Job/Job_AssignedResource" /> 80 80 <nodes> … … 83 83 </nodes> 84 84 </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"> 86 86 <AssociationMoniker Name="/HiveDataContext/Job/Job_RequiredPlugin" /> 87 87 <nodes> … … 90 90 </nodes> 91 91 </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"> 93 93 <AssociationMoniker Name="/HiveDataContext/Job/Job_Job" /> 94 94 <nodes> … … 97 97 </nodes> 98 98 </associationConnector> 99 <associationConnector edgePoints="[(8.875 : 2.3 6620198567708); (8.5 : 2.36620198567708)]" fixedFrom="NotFixed" fixedTo="NotFixed">99 <associationConnector edgePoints="[(8.875 : 2.33735270182292); (8.5 : 2.33735270182292)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 100 100 <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" /> 101 101 <nodes> … … 111 111 </nodes> 112 112 </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"> 114 114 <AssociationMoniker Name="/HiveDataContext/Job/Job_HiveExperiment" /> 115 115 <nodes> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs
r5404 r5405 1064 1064 private string _OperatingSystem; 1065 1065 1066 private System.Nullable<System.DateTime> _LastHeartbeat; 1067 1066 1068 private EntitySet<Job> _Jobs; 1067 1069 … … 1090 1092 partial void OnOperatingSystemChanging(string value); 1091 1093 partial void OnOperatingSystemChanged(); 1094 partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value); 1095 partial void OnLastHeartbeatChanged(); 1092 1096 #endregion 1093 1097 … … 1278 1282 } 1279 1283 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)] 1281 1285 public string OperatingSystem 1282 1286 { … … 1294 1298 this.SendPropertyChanged("OperatingSystem"); 1295 1299 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(); 1296 1320 } 1297 1321 } … … 1372 1396 1373 1397 private int _MemoryNeeded; 1398 1399 private System.Nullable<System.DateTime> _LastHeartbeat; 1374 1400 1375 1401 private EntitySet<AssignedResource> _AssignedResources; … … 1417 1443 partial void OnMemoryNeededChanging(int value); 1418 1444 partial void OnMemoryNeededChanged(); 1445 partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value); 1446 partial void OnLastHeartbeatChanged(); 1419 1447 #endregion 1420 1448 … … 1710 1738 this.SendPropertyChanged("MemoryNeeded"); 1711 1739 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(); 1712 1760 } 1713 1761 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs
r5404 r5405 76 76 77 77 DT.Slave slave = new DT.Slave() { 78 Id = Guid.NewGuid(), 78 79 Name = "Test", 79 OperatingSystem = Environment.OSVersion.VersionString,80 OperatingSystem = null, //"Windows 3.11", 80 81 Cores = 2, 81 Memory = 1024 82 Memory = 1024, 83 FreeMemory = 512 82 84 }; 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); 84 95 85 96 dao.DeleteSlave(slave.Id); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/Mocks/MockLifecycleManager.cs
r5156 r5405 28 28 public class MockLifecycleManager : ILifecycleManager { 29 29 30 public void Start() { 30 public void Start() { } 31 31 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() { } 41 33 } 42 34 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/Mocks/MockServiceLocator.cs
r5156 r5405 39 39 } 40 40 41 private ILifecycleManager lifecycleManager;42 41 public ILifecycleManager LifecycleManager { 43 42 get { … … 50 49 } 51 50 51 public HeartbeatManager HeartbeatManager { 52 get { 53 return defaultServiceLocator.HeartbeatManager; 54 } 55 } 52 56 } 53 57 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/App_Code/HiveServerModule.cs
r5375 r5405 27 27 using HeuristicLab.Services.Hive.Common.ServiceContracts; 28 28 using HeuristicLab.Services.Hive; 29 using HeuristicLab.Tracing; 29 30 30 31 namespace HeuristicLab.Hive.Server.Core.IISModules { … … 37 38 if (lifecycleManager == null) 38 39 lifecycleManager = new LifecycleManager(); 40 lifecycleManager.Start(); 39 41 } 40 42 41 43 public void Dispose() { 42 44 lifecycleManager.Stop(); 43 45 } 44 46 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/Web.config
r5402 r5405 70 70 71 71 <system.webServer> 72 < !--<modules runAllManagedModulesForAllRequests="true">72 <modules runAllManagedModulesForAllRequests="true"> 73 73 <add name="HiveServerModule" type="HeuristicLab.Hive.Server.Core.IISModules.HiveServerModule"/> 74 </modules> -->74 </modules> 75 75 <directoryBrowse enabled="true"/> 76 76 </system.webServer> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeuristicLab.Services.Hive-3.4.csproj
r5402 r5405 112 112 <None Include="HeuristicLabServicesHivePlugin.cs.frame" /> 113 113 <None Include="Properties\AssemblyInfo.cs.frame" /> 114 <Compile Include="HeartbeatManager.cs" /> 114 115 <Compile Include="Interfaces\ILifecycleManager.cs" /> 115 116 <Compile Include="Interfaces\IServiceLocator.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r5404 r5405 25 25 private ILifecycleManager lifecycleManager { 26 26 get { return ServiceLocator.Instance.LifecycleManager; } 27 } 28 private HeartbeatManager heartbeatManager { 29 get { return ServiceLocator.Instance.HeartbeatManager; } 27 30 } 28 31 … … 162 165 163 166 #region Login Methods 164 public void Hello( Guid slaveId, string name, int cores, int memory) {165 using (trans.OpenTransaction()) { 166 var slave = dao.GetSlave(slaveI d);167 public void Hello(Slave slaveInfo) { 168 using (trans.OpenTransaction()) { 169 var slave = dao.GetSlave(slaveInfo.Id); 167 170 168 171 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); 173 173 } else { 174 //TODO: error handling?174 dao.UpdateSlave(slaveInfo); 175 175 } 176 176 } … … 191 191 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 192 192 using (trans.OpenTransaction()) { 193 return lifecycleManager.ProcessHeartbeat(heartbeat);193 return heartbeatManager.ProcessHeartbeat(heartbeat); 194 194 } 195 195 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/ILifecycleManager.cs
r5095 r5405 14 14 15 15 void Stop(); 16 17 List<MessageContainer> ProcessHeartbeat(Heartbeat heartbeat);18 16 } 19 17 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Interfaces/IServiceLocator.cs
r5095 r5405 12 12 ILifecycleManager LifecycleManager { get; } 13 13 TransactionManager TransactionManager { get; } 14 HeartbeatManager HeartbeatManager { get; } 14 15 } 15 16 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs
r5404 r5405 25 25 26 26 private static object locker = new object(); 27 private Dictionary<Guid, DateTime> heartbeats = new Dictionary<Guid, DateTime>();28 27 29 28 // 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; 31 30 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; } 52 33 } 53 34 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); 56 38 } 57 58 public LifecycleManager() { }59 39 60 40 public void Start() { 61 41 if (ExecutionState == Core.ExecutionState.Stopped) { 62 42 this.timer.Interval = (int)new TimeSpan(0, 0, 10).TotalMilliseconds; 63 this.timer.Tick += new EventHandler(timer_Tick);64 43 this.timer.Start(); 65 AddAllSlavesToHeartbeats();66 44 } 67 45 } … … 74 52 75 53 /// <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 restarted78 /// </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>93 54 /// This method is supposed to check if slaves are online 94 55 /// if not -> set them offline and check if they where calculating a job … … 97 58 lock (locker) { 98 59 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); 109 66 } 110 67 } 111 68 } 112 69 } 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;124 70 } 125 71 … … 131 77 } 132 78 } 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 updates160 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 instead174 dao.UpdateJob(job);175 dao.UpdateSlave(slave);176 }177 178 /// <summary>179 /// Update the progress of each job180 /// Checks if all the jobs sent by heartbeat are supposed to be calculated by this slave181 /// </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 jobProgresses189 foreach (var jobProgress in heartbeat.JobProgress) {190 Job curJob = dao.GetJob(jobProgress.Key);191 if (curJob == null) {192 // job does not exist in db193 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 heartbeat198 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 time202 curJob.ExecutionTime = jobProgress.Value;203 204 if (curJob.JobState == JobState.Aborted) {205 // a request to abort the job has been set206 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 job217 /// There should not be too many jobs sent simultaniously218 /// </summary>219 private bool IsAllowedToSendJobs() {220 return JobsCurrentlyTransferring < ApplicationConstants.MaxJobTransferCount;221 }222 79 } 223 80 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/ServiceLocator.cs
r5095 r5405 48 48 } 49 49 } 50 51 private HeartbeatManager heartbeatManager; 52 public HeartbeatManager HeartbeatManager { 53 get { 54 if(heartbeatManager == null) heartbeatManager = new HeartbeatManager(); 55 return heartbeatManager; 56 } 57 } 50 58 } 51 59 }
Note: See TracChangeset
for help on using the changeset viewer.