Changeset 5526
- Timestamp:
- 02/21/11 17:35:42 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Calendar/3.3/HeuristicLab.Calendar-3.3.csproj
r5457 r5526 96 96 <None Include="HeuristicLabCalendarPlugin.cs.frame" /> 97 97 <Compile Include="HeuristicLabCalendarPlugin.cs" /> 98 <Compile Include="Properties\AssemblyInfo.cs" /> 98 99 <Compile Include="Properties\CalendarResources.Designer.cs"> 99 100 <AutoGen>True</AutoGen> … … 117 118 <SubType>Code</SubType> 118 119 </Compile> 119 <Compile Include="Properties\AssemblyInfo.cs" />120 120 <Compile Include="Appointment\ResolveAppointmentsEvent.cs" /> 121 121 <Compile Include="ViewTools\SelectionType.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockServiceLocator.cs
r5405 r5526 20 20 #endregion 21 21 22 using HeuristicLab.Clients.Common;22 using System; 23 23 using HeuristicLab.Services.Hive.Common.ServiceContracts; 24 24 25 25 namespace HeuristicLab.Clients.Hive.Slave.Tests { 26 26 public class MockServiceLocator : IServiceLocator { 27 28 27 private MockHiveService service; 29 28 30 public Disposable<IHiveService> GetService() { 29 private string username; 30 public string Username { 31 get { return username; } 32 set { username = value; } 33 } 34 35 private string password; 36 public string Password { 37 get { return password; } 38 set { password = value; } 39 } 40 41 public IHiveService GetService() { 31 42 if (service == null) 32 43 service = new MockHiveService(); 33 34 return new Disposable<IHiveService>(service); 44 return service; 35 45 } 36 46 37 public Disposable<IHiveService> GetService(string username, string password) { 38 return GetService(); 47 public void CallHiveService(Action<IHiveService> call) { 48 call(GetService()); 49 } 50 51 public T CallHiveService<T>(Func<IHiveService, T> call) { 52 return call(GetService()); 39 53 } 40 54 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs
r5511 r5526 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Clients.Common;26 25 using HeuristicLab.Services.Hive.Common; 27 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 28 using HeuristicLab.Services.Hive.Common.ServiceContracts;29 27 using Microsoft.VisualStudio.TestTools.UnitTesting; 30 28 … … 82 80 MockJob job = new MockJob(300, false); 83 81 84 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){85 MockHiveService ms = (MockHiveService)service .Obj;86 ((MockHiveService)service .Obj).Messages = CreateMsgsForSingleJob();87 ((MockHiveService)service .Obj).updateJobs(jobList, job);82 ServiceLocator.Instance.CallHiveService(service => { 83 MockHiveService ms = (MockHiveService)service; 84 ((MockHiveService)service).Messages = CreateMsgsForSingleJob(); 85 ((MockHiveService)service).updateJobs(jobList, job); 88 86 89 87 HeuristicLab.Clients.Hive.Slave.Core core = new Slave.Core(); … … 93 91 Assert.AreEqual<Guid>(testJob.Id, ms.ResultJobs[0].Id); 94 92 core.Shutdown(); 95 } 93 }); 96 94 } 97 95 … … 120 118 MockJob job = new MockJob(10000, false); 121 119 122 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){123 MockHiveService ms = (MockHiveService)service .Obj;124 ((MockHiveService)service .Obj).Messages = CreateMsgsForShutdownSlaveWhileJobRunning();125 ((MockHiveService)service .Obj).updateJobs(jobList, job);120 ServiceLocator.Instance.CallHiveService(service => { 121 MockHiveService ms = (MockHiveService)service; 122 ((MockHiveService)service).Messages = CreateMsgsForShutdownSlaveWhileJobRunning(); 123 ((MockHiveService)service).updateJobs(jobList, job); 126 124 127 125 128 126 HeuristicLab.Clients.Hive.Slave.Core core = new Slave.Core(); 129 127 core.Start(); 130 } 128 }); 131 129 } 132 130 … … 184 182 MockJob job = new MockJob(2000, false); 185 183 186 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){187 MockHiveService ms = (MockHiveService)service .Obj;188 ((MockHiveService)service .Obj).Messages = CreateMsgsForTwoJobs();189 ((MockHiveService)service .Obj).updateJobs(jobList, job);184 ServiceLocator.Instance.CallHiveService(service => { 185 MockHiveService ms = (MockHiveService)service; 186 ((MockHiveService)service).Messages = CreateMsgsForTwoJobs(); 187 ((MockHiveService)service).updateJobs(jobList, job); 190 188 191 189 … … 194 192 Assert.AreEqual<int>(2, ms.ResultJobs.Count); 195 193 core.Shutdown(); 196 } 194 }); 197 195 } 198 196 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
r5512 r5526 371 371 } 372 372 Job cJob = jobs[jobId]; 373 cJob.State = JobState.Finished; //TODO: what if failed?373 cJob.State = JobState.Finished; // TODO: what if failed? 374 374 cJob.ExecutionTime = engines[jobId].ExecutionTime; 375 375 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs
r5511 r5526 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Clients.Common;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Services.Hive.Common; … … 43 42 if (instance == null) { 44 43 instance = new WcfService(); 44 ServiceLocator.Instance.Username = "hiveslave"; 45 ServiceLocator.Instance.Password = "hiveslave"; 45 46 } 46 47 return instance; … … 74 75 /// </summary> 75 76 public void Connect(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) { 76 using (Disposable<IHiveService> service = GetSlaveService()) { 77 try { 78 ConnState = NetworkEnum.WcfConnState.Connected; 79 ConnectedSince = DateTime.Now; 80 service.Obj.Hello(slaveInfo); 81 OnConnected(); 82 } 83 catch (Exception ex) { 84 HandleNetworkError(ex); 85 } 86 } 77 CallHiveService(service => { 78 ConnState = NetworkEnum.WcfConnState.Connected; 79 ConnectedSince = DateTime.Now; 80 service.Hello(slaveInfo); 81 OnConnected(); 82 }); 87 83 } 88 84 … … 91 87 /// </summary> 92 88 public void Disconnect() { 93 using (Disposable<IHiveService> service = GetSlaveService()) { 94 try { 95 service.Obj.GoodBye(ConfigManager.Instance.GetClientInfo().Id); 96 ConnState = NetworkEnum.WcfConnState.Disconnected; 97 } 98 catch (Exception ex) { 99 HandleNetworkError(ex); 100 } 101 } 89 CallHiveService(service => { 90 service.GoodBye(ConfigManager.Instance.GetClientInfo().Id); 91 ConnState = NetworkEnum.WcfConnState.Disconnected; 92 }); 102 93 } 103 94 … … 115 106 /// </summary> 116 107 public Job GetJob(Guid jobId) { 117 using (Disposable<IHiveService> service = GetSlaveService()) { 118 try { 119 Job job = service.Obj.GetJob(jobId); 120 return job; 121 } 122 catch (Exception ex) { 123 HandleNetworkError(ex); 124 return null; 125 } 126 } 108 return CallHiveService(s => s.GetJob(jobId)); 127 109 } 128 110 129 111 public JobData GetJobData(Guid jobId) { 130 using (Disposable<IHiveService> service = GetSlaveService()) { 131 try { 132 JobData jobData = service.Obj.GetJobData(jobId); 133 return jobData; 134 } 135 catch (Exception ex) { 136 HandleNetworkError(ex); 137 return null; 138 } 139 } 112 return CallHiveService(s => s.GetJobData(jobId)); 140 113 } 141 114 142 115 public void UpdateJob(Job job) { 143 using (Disposable<IHiveService> service = GetSlaveService()) { 144 try { 145 service.Obj.UpdateJob(job); 146 } 147 catch (Exception ex) { 148 HandleNetworkError(ex); 149 } 150 } 116 CallHiveService(s => s.UpdateJob(job)); 151 117 } 152 118 … … 157 123 /// <param name="jobData"></param> 158 124 public void UpdateJobData(Job job, JobData jobData, Guid slaveId) { 159 using (Disposable<IHiveService> service = GetSlaveService()) { 160 try { 161 JobState before = job.State; 162 job.SetState(JobState.Transferring, slaveId, ""); 163 service.Obj.UpdateJob(job); 125 CallHiveService(service => { 126 JobState before = job.State; 127 job.SetState(JobState.Transferring, slaveId, ""); 128 service.UpdateJob(job); 164 129 165 service.Obj.UpdateJobData(job, jobData);130 service.UpdateJobData(job, jobData); 166 131 167 job.SetState(before, slaveId, ""); 168 service.Obj.UpdateJob(job); 169 } 170 catch (Exception ex) { 171 HandleNetworkError(ex); 172 } 132 job.SetState(before, slaveId, ""); 133 service.UpdateJob(job); 134 }); 135 } 136 137 public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) { 138 return CallHiveService(s => s.Heartbeat(heartbeat)); 139 } 140 141 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 142 return CallHiveService(s => s.GetPluginDatas(pluginIds)); 143 } 144 145 public IEnumerable<Plugin> GetPlugins() { 146 return CallHiveService(s => s.GetPlugins()); 147 } 148 149 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) { 150 return CallHiveService(s => s.AddChildJob(parentJobId, job, jobData)); 151 } 152 153 public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) { 154 return CallHiveService(service => { 155 IEnumerable<LightweightJob> msg = service.GetLightweightChildJobs(parentJobId, false, false); 156 157 List<JobData> jobs = new List<JobData>(); 158 foreach (LightweightJob ljob in msg) 159 jobs.Add(service.GetJobData(ljob.Id)); 160 161 return jobs; 162 }); 163 } 164 165 public void DeleteChildJobs(Guid jobId) { 166 CallHiveService(s => s.DeleteChildJobs(jobId)); 167 } 168 169 public void CallHiveService(Action<IHiveService> call) { 170 try { 171 ServiceLocator.Instance.CallHiveService(call); 173 172 } 174 } 175 176 public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) { 177 using (Disposable<IHiveService> service = GetSlaveService()) { 178 try { 179 List<MessageContainer> msg = service.Obj.Heartbeat(heartbeat); 180 return msg; 181 } 182 catch (Exception ex) { 183 HandleNetworkError(ex); 184 return null; 185 } 173 catch (Exception ex) { 174 HandleNetworkError(ex); 186 175 } 187 176 } 188 177 189 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 190 using (Disposable<IHiveService> service = GetSlaveService()) { 191 try { 192 IEnumerable<PluginData> msg = service.Obj.GetPluginDatas(pluginIds); 193 return msg; 194 } 195 catch (Exception ex) { 196 HandleNetworkError(ex); 197 return null; 198 } 178 private T CallHiveService<T>(Func<IHiveService, T> call) { 179 try { 180 return ServiceLocator.Instance.CallHiveService(call); 199 181 } 200 } 201 202 public IEnumerable<Plugin> GetPlugins() { 203 using (Disposable<IHiveService> service = GetSlaveService()) { 204 try { 205 IEnumerable<Plugin> msg = service.Obj.GetPlugins(); 206 return msg; 207 } 208 catch (Exception ex) { 209 HandleNetworkError(ex); 210 return null; 211 } 182 catch (Exception ex) { 183 HandleNetworkError(ex); 184 return default(T); 212 185 } 213 }214 215 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {216 using (Disposable<IHiveService> service = GetSlaveService()) {217 try {218 Guid msg = service.Obj.AddChildJob(parentJobId, job, jobData);219 return msg;220 }221 catch (Exception ex) {222 HandleNetworkError(ex);223 return new Guid();224 }225 }226 }227 228 public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) {229 using (Disposable<IHiveService> service = GetSlaveService()) {230 try {231 IEnumerable<LightweightJob> msg = service.Obj.GetLightweightChildJobs(parentJobId, false, false);232 233 List<JobData> jobs = new List<JobData>();234 foreach (LightweightJob ljob in msg)235 jobs.Add(service.Obj.GetJobData(ljob.Id));236 237 return jobs;238 }239 catch (Exception ex) {240 HandleNetworkError(ex);241 return null;242 }243 }244 }245 246 public void DeleteChildJobs(Guid jobId) {247 using (Disposable<IHiveService> service = GetSlaveService()) {248 try {249 service.Obj.DeleteChildJobs(jobId);250 }251 catch (Exception ex) {252 HandleNetworkError(ex);253 }254 }255 }256 257 private static Disposable<IHiveService> GetSlaveService() {258 return ServiceLocator.Instance.GetService("hiveslave", "hiveslave");259 186 } 260 187 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Tests/Mocks/MockServiceLocator.cs
r5405 r5526 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using HeuristicLab.Clients.Common; 2 using HeuristicLab.Services.Hive; 6 3 using HeuristicLab.Services.Hive.Common.ServiceContracts; 7 using HeuristicLab.Services.Hive;8 4 9 5 namespace HeuristicLab.Clients.Hive.Tests { 10 6 public class MockServiceLocator : IServiceLocator { 11 public Disposable<IHiveService> GetService() { 12 return new Disposable<IHiveService>(new HiveService()); 7 private string username; 8 public string Username { 9 get { return username; } 10 set { username = value; } 13 11 } 14 12 15 public Disposable<IHiveService> GetService(string username, string password) { 16 return GetService(); 13 private string password; 14 public string Password { 15 get { return password; } 16 set { password = value; } 17 } 18 19 public IHiveService GetService() { 20 return new HiveService(); 21 } 22 23 public void CallHiveService(Action<IHiveService> call) { 24 call(GetService()); 25 } 26 27 public T CallHiveService<T>(Func<IHiveService, T> call) { 28 return call(GetService()); 17 29 } 18 30 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Administration/HiveAdministrationClient.cs
r5525 r5526 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 27 using HeuristicLab.Services.Hive.Common.ServiceContracts;28 27 29 28 namespace HeuristicLab.Clients.Hive.Administration { … … 51 50 52 51 public void UpdateSlaveGroups() { 53 using (HeuristicLab.Clients.Common.Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) { 54 52 ServiceLocator.Instance.CallHiveService(service => { 55 53 /*SlaveGroup sg = new SlaveGroup(); 56 54 sg.Name = "Test" + Guid.NewGuid(); … … 59 57 service.Obj.AddSlaveGroup(sg);*/ 60 58 61 SlaveGroups = new List<SlaveGroup>(service. Obj.GetSlaveGroups());62 Slaves = new List<Slave>(service. Obj.GetSlaves());59 SlaveGroups = new List<SlaveGroup>(service.GetSlaveGroups()); 60 Slaves = new List<Slave>(service.GetSlaves()); 63 61 OnItemImageChanged(); 64 } 62 }); 65 63 } 66 64 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentClient.cs
r5511 r5526 24 24 using System.Linq; 25 25 using System.Threading; 26 using HeuristicLab.Clients.Common;27 26 using HeuristicLab.Clients.Hive.Jobs; 28 27 using HeuristicLab.Common; … … 249 248 this.progress = new Progress("Connecting to server..."); 250 249 IsProgressing = true; 251 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){250 ServiceLocator.Instance.CallHiveService(service => { 252 251 IEnumerable<string> resourceNames = ToResourceNameList(this.ResourceNames); 253 252 var resourceIds = new List<Guid>(); 254 253 foreach (var resourceName in resourceNames) { 255 Guid resourceId = service. Obj.GetResourceId(resourceName);254 Guid resourceId = service.GetResourceId(resourceName); 256 255 if (resourceId == Guid.Empty) { 257 256 throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName)); … … 266 265 267 266 this.progress.Status = "Uploading plugins..."; 268 this.OnlinePlugins = service. Obj.GetPlugins();267 this.OnlinePlugins = service.GetPlugins(); 269 268 this.AlreadyUploadedPlugins = new List<Plugin>(); 270 Plugin configFilePlugin = UploadConfigurationFile(service .Obj);269 Plugin configFilePlugin = UploadConfigurationFile(service); 271 270 this.alreadyUploadedPlugins.Add(configFilePlugin); 272 271 273 272 this.progress.Status = "Uploading jobs..."; 274 UploadJobWithChildren(service .Obj, this.HiveJob, null, resourceIds, ref jobCount, totalJobCount, configFilePlugin.Id);273 UploadJobWithChildren(service, this.HiveJob, null, resourceIds, ref jobCount, totalJobCount, configFilePlugin.Id); 275 274 this.rootJobId = this.HiveJob.Job.Id; 276 275 LogMessage("Finished sending jobs to hive"); … … 279 278 this.progress.Status = "Uploading HiveExperiment..."; 280 279 281 DT.HiveExperiment he = service. Obj.GetHiveExperiment(service.Obj.AddHiveExperiment(this.ToHiveExperimentDto()));280 DT.HiveExperiment he = service.GetHiveExperiment(service.AddHiveExperiment(this.ToHiveExperimentDto())); 282 281 this.UpdateFromDto(he); 283 282 284 283 StartResultPolling(); 285 } 284 }); 286 285 } 287 286 catch (Exception e) { … … 316 315 /// <summary> 317 316 /// Uploads the given job and all its child-jobs while setting the proper parentJobId values for the childs 318 ///319 317 /// </summary> 320 318 /// <param name="service"></param> … … 327 325 JobData jobData; 328 326 List<IPluginDescription> plugins; 327 329 328 if (hiveJob.OptimizerJob.ComputeInParallel && 330 329 (hiveJob.OptimizerJob.Optimizer is Optimization.Experiment || hiveJob.OptimizerJob.Optimizer is Optimization.BatchRun)) { 331 hiveJob.Job.SetState(JobState.FinishOnChildJobsFinished); 330 hiveJob.Job.IsParentJob = true; 331 hiveJob.Job.FinishWhenChildJobsFinished = true; 332 332 hiveJob.OptimizerJob.CollectChildJobs = false; // don't collect child-jobs on slaves 333 333 jobData = hiveJob.GetAsJobData(true, out plugins); 334 334 } else { 335 hiveJob.Job.IsParentJob = false; 336 hiveJob.Job.FinishWhenChildJobsFinished = false; 335 337 jobData = hiveJob.GetAsJobData(false, out plugins); 336 338 } … … 342 344 this.progress.ProgressValue = (double)jobCount / totalJobCount; 343 345 346 hiveJob.Job.SetState(JobState.Transferring); 344 347 if (parentHiveJob != null) { 345 348 hiveJob.Job.Id = service.AddChildJob(parentHiveJob.Job.Id, hiveJob.Job, jobData); … … 367 370 368 371 public void Stop() { 369 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){372 ServiceLocator.Instance.CallHiveService(service => { 370 373 foreach (HiveJob hj in HiveJob.GetAllHiveJobs()) { 371 service. Obj.StopJob(hj.Job.Id);372 } 373 } 374 service.StopJob(hj.Job.Id); 375 } 376 }); 374 377 } 375 378 … … 598 601 int jobCount = 0; 599 602 progress.Status = "Connecting to Server..."; 600 using (var service = ServiceLocator.Instance.GetService()){603 ServiceLocator.Instance.CallHiveService(service => { 601 604 // fetch all Job objects to create the full tree of tree of HiveJob objects 602 605 progress.Status = "Downloading list of jobs..."; 603 IEnumerable<LightweightJob> allResults = service. Obj.GetLightweightChildJobs(rootJobId, true, true);606 IEnumerable<LightweightJob> allResults = service.GetLightweightChildJobs(rootJobId, true, true); 604 607 totalJobCount = allResults.Count(); 605 608 … … 610 613 jobCount++; 611 614 progress.Status = string.Format("Downloading {0} of {1} jobs...", jobCount, totalJobCount); 612 allJobs.Add(lightweightJob.Id, service. Obj.GetJob(lightweightJob.Id));613 allJobDatas.Add(lightweightJob.Id, service. Obj.GetJobData(lightweightJob.Id));615 allJobs.Add(lightweightJob.Id, service.GetJob(lightweightJob.Id)); 616 allJobDatas.Add(lightweightJob.Id, service.GetJobData(lightweightJob.Id)); 614 617 progress.ProgressValue = (double)jobCount / totalJobCount; 615 618 } … … 635 638 636 639 // build child-job tree 637 LoadChildResults(service .Obj, this.HiveJob, allResults, allJobs, allJobDatas, progress, totalJobCount, ref jobCount);640 LoadChildResults(service, this.HiveJob, allResults, allJobs, allJobDatas, progress, totalJobCount, ref jobCount); 638 641 StartResultPolling(); 639 } 642 }); 640 643 } 641 644 catch (Exception e) { … … 674 677 675 678 private OptimizerJob LoadOptimizerJob(Guid jobId) { 676 using (var service = ServiceLocator.Instance.GetService()){677 JobData jobData = service. Obj.GetJobData(jobId);679 return ServiceLocator.Instance.CallHiveService(service => { 680 JobData jobData = service.GetJobData(jobId); 678 681 try { 679 682 return PersistenceUtil.Deserialize<OptimizerJob>(jobData.Data); … … 682 685 return null; 683 686 } 684 } 687 }); 685 688 } 686 689 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentManagerClient.cs
r5402 r5526 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Collections; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Services.Hive.Common.ServiceContracts;27 using HeuristicLab.Services.Hive.Common;28 using System.Collections.Generic;29 27 30 28 namespace HeuristicLab.Clients.Hive { 29 using HeuristicLab.Common; 31 30 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; 32 using HeuristicLab.Common;33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;34 using HeuristicLab.Clients.Common;35 31 36 32 [Item("Hive Client", "Connects to Hive and lists all submitted experiments by the current user.")] … … 97 93 this.HiveExperiments = new ItemList<HiveExperimentClient>(); 98 94 } 99 using (var service = ServiceLocator.Instance.GetService()) { 100 currentlyUpdating = true; 101 IEnumerable<DT.HiveExperiment> response = service.Obj.GetHiveExperiments(); 102 progress.Status = "Populating HiveExperiment list..."; 103 RefreshExperimentList(response); 104 currentlyUpdating = false; 105 } 95 currentlyUpdating = true; 96 IEnumerable<DT.HiveExperiment> response = ServiceLocator.Instance.CallHiveService(s => s.GetHiveExperiments()); 97 progress.Status = "Populating HiveExperiment list..."; 98 RefreshExperimentList(response); 99 currentlyUpdating = false; 106 100 } 107 101 catch (Exception) { … … 137 131 } 138 132 139 void hiveExperiments_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<HiveExperimentClient>> e) {133 private void hiveExperiments_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<HiveExperimentClient>> e) { 140 134 if (!currentlyUpdating) { 141 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){135 ServiceLocator.Instance.CallHiveService(service => { 142 136 foreach (IndexedItem<HiveExperimentClient> item in e.Items) { 143 137 if (item.Value.HiveExperimentId != Guid.Empty) { 144 service. Obj.DeleteHiveExperiment(item.Value.HiveExperimentId);138 service.DeleteHiveExperiment(item.Value.HiveExperimentId); 145 139 } 146 140 } 147 } 141 }); 148 142 } 149 143 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobClient.cs
r5511 r5526 44 44 } else { 45 45 if (job.State == JobState.Waiting) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutablePrepared; 46 else if (job.State == JobState.FinishOnChildJobsFinished) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutablePrepared;47 46 else if (job.State == JobState.Calculating) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStarted; 47 else if (job.State == JobState.Transferring) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStarted; 48 48 else if (job.State == JobState.Aborted) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStopped; 49 49 else if (job.State == JobState.Failed) return HeuristicLab.Common.Resources.VSImageLibrary.Error; … … 114 114 } 115 115 116 public HiveJob(Job jobDto)117 : this() {118 this.Job = jobDto;119 }120 121 public HiveJob(LightweightJob lightweightJob)122 : this() {123 UpdateFromLightweightJob(lightweightJob);124 }116 //public HiveJob(Job jobDto) 117 // : this() { 118 // this.Job = jobDto; 119 //} 120 121 //public HiveJob(LightweightJob lightweightJob) 122 // : this() { 123 // UpdateFromLightweightJob(lightweightJob); 124 //} 125 125 126 126 public HiveJob(OptimizerJob optimizerJob, bool autoCreateChildHiveJobs) … … 136 136 } 137 137 138 public HiveJob(Job job, JobData jobData, bool autoCreateChildHiveJobs) 139 : this() { 138 public HiveJob(Job job, JobData jobData, bool autoCreateChildHiveJobs) { 140 139 this.syncJobsWithOptimizers = autoCreateChildHiveJobs; 141 140 this.Job = job; … … 405 404 job.Id = lightweightJob.Id; 406 405 job.ExecutionTime = lightweightJob.ExecutionTime; 406 job.State = lightweightJob.State; 407 407 job.StateLog = new List<StateLog>(lightweightJob.StateLog); 408 408 // what about parentJob -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/JobResultPoller.cs
r5055 r5526 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 using HeuristicLab.Services.Hive.Common;26 using HeuristicLab.Services.Hive.Common.ServiceContracts;27 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 28 using System.Collections.Generic;29 using HeuristicLab.Clients.Common;30 27 31 28 namespace HeuristicLab.Clients.Hive { … … 96 93 97 94 private void FetchJobResults() { 98 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()){99 IEnumerable<LightweightJob> response = service. Obj.GetLightweightChildJobs(hiveJob.Job.Id, true, true);95 ServiceLocator.Instance.CallHiveService(service => { 96 IEnumerable<LightweightJob> response = service.GetLightweightChildJobs(hiveJob.Job.Id, true, true); 100 97 OnJobResultsReceived(response); 101 } 98 }); 102 99 } 103 100 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/PluginClient.cs
r5095 r5526 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 1 using System.Collections.Generic; 5 2 using HeuristicLab.Services.Hive.Common.DataTransfer; 6 3 … … 16 13 17 14 public void Load() { 18 using (var service = ServiceLocator.Instance.GetService()) {19 20 }21 15 } 22 16 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/IServiceLocator.cs
r5405 r5526 20 20 #endregion 21 21 22 using HeuristicLab.Clients.Common;22 using System; 23 23 using HeuristicLab.Services.Hive.Common.ServiceContracts; 24 24 25 25 namespace HeuristicLab.Clients.Hive { 26 26 public interface IServiceLocator { 27 Disposable<IHiveService> GetService(); 28 Disposable<IHiveService> GetService(string username, string password); 27 string Username { get; set; } 28 string Password { get; set; } 29 void CallHiveService(Action<IHiveService> call); 30 T CallHiveService<T>(Func<IHiveService, T> call); 29 31 } 30 32 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs
r5405 r5526 20 20 #endregion 21 21 22 using System; 23 using System.ServiceModel; 22 24 using HeuristicLab.Clients.Common; 23 25 using HeuristicLab.Services.Hive.Common.ServiceContracts; … … 38 40 } 39 41 40 public Disposable<IHiveService> GetService() { 41 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService"); 42 private string username; 43 public string Username { 44 get { return username; } 45 set { username = value; } 42 46 } 43 47 44 public Disposable<IHiveService> GetService(string username, string password) { 45 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService", null, username, password); 48 private string password; 49 public string Password { 50 get { return password; } 51 set { password = value; } 52 } 53 54 public Disposable<ChannelFactory<IHiveService>> GetService() { 55 if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password)) { 56 return ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService"); 57 } else { 58 return ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService", null, username, password); 59 } 60 } 61 62 public void CallHiveService(Action<IHiveService> call) { 63 using (var channelFactory = this.GetService()) { 64 var service = channelFactory.Obj.CreateChannel(); 65 call(service); 66 } // disposing the channelfactory is done by the disposable object; the channel gets disposed when the channelfactory is disposed 67 } 68 69 private T CallHiveService<T>(Func<IHiveService, T> call) { 70 using (var channelFactory = this.GetService()) { 71 var service = channelFactory.Obj.CreateChannel(); 72 return call(service); 73 } // disposing the channelfactory is done by the disposable object; the channel gets disposed when the channelfactory is disposed 74 } 75 76 T IServiceLocator.CallHiveService<T>(Func<IHiveService, T> call) { 77 return CallHiveService<T>(call); 46 78 } 47 79 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Job.cs
r5511 r5526 39 39 [DataMember] 40 40 public DateTime? LastHeartbeat { get; set; } 41 [DataMember] 42 public bool IsParentJob { get; set; } 43 [DataMember] 44 public bool FinishWhenChildJobsFinished { get; set; } 41 45 42 46 public Job() { … … 49 53 this.PluginsNeededIds = new List<Guid>(original.PluginsNeededIds); 50 54 this.LastHeartbeat = original.LastHeartbeat; 55 this.IsParentJob = original.IsParentJob; 56 this.FinishWhenChildJobsFinished = original.FinishWhenChildJobsFinished; 51 57 } 52 58 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/JobState.cs
r5511 r5526 33 33 Waiting, 34 34 35 /// <summary>36 /// The job is set to Finished when all child jobs are Finished.37 /// </summary>38 FinishOnChildJobsFinished,35 ///// <summary> 36 ///// The job is set to Finished when all child jobs are Finished. 37 ///// </summary> 38 //FinishOnChildJobsFinished, 39 39 40 /// <summary>41 /// The job is paused and waits on the server to be sent back to a Slave when all of its child jobs are Finished.42 /// </summary>43 ResumeOnChildJobsFinished,40 ///// <summary> 41 ///// The job is paused and waits on the server to be sent back to a Slave when all of its child jobs are Finished. 42 ///// </summary> 43 //ResumeOnChildJobsFinished, 44 44 45 45 /// <summary> … … 81 81 /// </summary> 82 82 public static bool IsWaiting(this JobState jobState) { 83 return jobState == JobState.Waiting || 84 jobState == JobState.FinishOnChildJobsFinished; 83 return jobState == JobState.Waiting; 85 84 } 86 85 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/LightweightJob.cs
r5511 r5526 48 48 49 49 public LightweightJob(Job job) { 50 this.Id = job.Id; 50 51 this.ExecutionTime = job.ExecutionTime; 51 52 this.ParentJobId = job.ParentJobId; 52 this.StateLog = new List<StateLog>(); 53 this.StateLog = new List<StateLog>(job.StateLog); 54 this.State = job.State; 53 55 } 54 56 protected LightweightJob(LightweightJob original, Cloner cloner) … … 57 59 this.ParentJobId = original.ParentJobId; 58 60 this.StateLog = new List<StateLog>(original.StateLog); 61 this.State = original.State; 59 62 } 60 63 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/ServiceContracts/IHiveService.cs
r5511 r5526 43 43 [OperationContract] 44 44 void DeleteChildJobs(Guid parentJobId); 45 46 45 #endregion 47 46 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs
r5511 r5526 40 40 LastHeartbeat = source.LastHeartbeat, 41 41 State = source.State, 42 StateLog = source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList() 42 StateLog = source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(), 43 IsParentJob = source.IsParentJob, 44 FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished 43 45 }; 44 46 } … … 59 61 target.State = source.State; 60 62 if (target.StateLogs == null) target.StateLogs = new EntitySet<StateLog>(); 61 target.StateLogs.AddRange(source.StateLog.Select(x => Convert.ToEntity(x)).OrderBy(x => x.DateTime)); 63 foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) { 64 target.StateLogs.Add(Convert.ToEntity(sl)); 65 } 66 67 //target.StateLogs.AddRange(source.StateLog.Select(x => Convert.ToEntity(x)).OrderBy(x => x.DateTime)); 68 target.IsParentJob = source.IsParentJob; 69 target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished; 62 70 // RequiredPlugins are added by Dao 63 71 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
r5511 r5526 82 82 } 83 83 84 public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) { 84 /// <summary> 85 /// returns all parent jobs which are waiting for their child jobs to finish 86 /// </summary> 87 /// <param name="resourceIds">list of resourceids which for which the jobs should be valid</param> 88 /// <param name="count">maximum number of jobs to return</param> 89 /// <param name="finished">if true, all parent jobs which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param> 90 /// <returns></returns> 91 public IEnumerable<DT.Job> GetParentJobs(IEnumerable<Guid> resourceIds, int count, bool finished) { 85 92 using (var db = CreateContext()) { 86 93 var query = from ar in db.AssignedResources 87 join sl in db.StateLogs on ar.JobId equals sl.JobId88 94 where resourceIds.Contains(ar.ResourceId) 89 && ar.Job.State == JobState.FinishOnChildJobsFinished 95 && ar.Job.State == JobState.Waiting 96 && ar.Job.IsParentJob 97 && (finished ? ar.Job.FinishWhenChildJobsFinished : !ar.Job.FinishWhenChildJobsFinished) 90 98 && (from child in db.Jobs 91 99 where child.ParentJobId == ar.Job.JobId … … 103 111 using (var db = CreateContext()) { 104 112 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); 105 var waitingParentJobs = Get WaitingParentJobs(resourceIds, count);113 var waitingParentJobs = GetParentJobs(resourceIds, count, false); 106 114 if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray(); 107 115 108 116 var query = from ar in db.AssignedResources 109 117 where resourceIds.Contains(ar.ResourceId) 118 && !(ar.Job.IsParentJob && ar.Job.FinishWhenChildJobsFinished) 110 119 && ar.Job.State == JobState.Waiting 111 120 && ar.Job.CoresNeeded <= slave.FreeCores … … 160 169 #endregion 161 170 171 #region StateLog Methods 172 173 public DT.StateLog GetStateLog(Guid id) { 174 using (var db = CreateContext()) { 175 return Convert.ToDto(db.StateLogs.SingleOrDefault(x => x.StateLogId == id)); 176 } 177 } 178 179 public IEnumerable<DT.StateLog> GetStateLogs(Expression<Func<StateLog, bool>> predicate) { 180 using (var db = CreateContext()) { 181 return db.StateLogs.Where(predicate).Select(x => Convert.ToDto(x)).ToArray(); 182 } 183 } 184 185 public Guid AddStateLog(DT.StateLog dto) { 186 using (var db = CreateContext()) { 187 var entity = Convert.ToEntity(dto); 188 db.StateLogs.InsertOnSubmit(entity); 189 db.SubmitChanges(); 190 return entity.StateLogId; 191 } 192 } 193 194 public void UpdateStateLog(DT.StateLog dto) { 195 using (var db = CreateContext()) { 196 var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == dto.Id); 197 if (entity == null) db.StateLogs.InsertOnSubmit(Convert.ToEntity(dto)); 198 else Convert.ToEntity(dto, entity); 199 db.SubmitChanges(); 200 } 201 } 202 203 public void DeleteStateLog(Guid id) { 204 using (var db = CreateContext()) { 205 var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == id); 206 if (entity != null) db.StateLogs.DeleteOnSubmit(entity); 207 db.SubmitChanges(); 208 } 209 } 210 #endregion 211 162 212 #region HiveExperiment Methods 163 213 public DT.HiveExperiment GetHiveExperiment(Guid id) { … … 507 557 508 558 #endregion 559 509 560 } 510 561 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml
r5511 r5526 60 60 <Type Name="Job"> 61 61 <Column Name="JobId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> 62 <Column Name="JobState" Member="State" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState" DbType="VarChar(30)" CanBeNull="false" /> 63 <Column Name="ExecutionTime" Type="System.String" DbType="VarChar(30)" CanBeNull="true" /> 64 <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" /> 62 65 <Column Name="ParentJobId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" /> 63 <Column Name="ExecutionTime" Type="System.String" DbType="VarChar(30)" CanBeNull="true" />64 66 <Column Name="Priority" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 65 67 <Column Name="CoresNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 66 68 <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 67 <Column Name=" LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />68 <Column Name=" JobState" Member="State" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState" DbType="VarChar(30)" CanBeNull="false" />69 <Column Name="IsParentJob" Type="System.Boolean" DbType="Bit" CanBeNull="false" /> 70 <Column Name="FinishWhenChildJobsFinished" Type="System.Boolean" DbType="Bit" CanBeNull="false" /> 69 71 <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" /> 70 72 <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
r5511 r5526 27 27 </nestedChildShapes> 28 28 </classShape> 29 <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 2. 3478011067708335">29 <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 2.7324039713541666"> 30 30 <DataClassMoniker Name="/HiveDataContext/Job" /> 31 31 <nestedChildShapes> 32 <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />32 <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 33 33 </nestedChildShapes> 34 34 </classShape> … … 76 76 </nodes> 77 77 </associationConnector> 78 <associationConnector edgePoints="[(8.5 : 3. 34780110677083); (8.875 : 3.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">78 <associationConnector edgePoints="[(8.5 : 3.73240397135417); (8.875 : 3.875)]" 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.4687475 : 3. 34780110677083); (7.4687475 : 5.5)]" fixedFrom="Algorithm" fixedTo="Algorithm">85 <associationConnector edgePoints="[(7.4687475 : 3.73240397135417); (7.4687475 : 5.5)]" fixedFrom="Algorithm" fixedTo="Algorithm"> 86 86 <AssociationMoniker Name="/HiveDataContext/Job/Job_RequiredPlugin" /> 87 87 <nodes> … … 104 104 </nodes> 105 105 </associationConnector> 106 <associationConnector edgePoints="[(6.5 : 2.98640055338542); (6.125 : 2.98640055338542)]" fixedFrom="Algorithm" fixedTo="Algorithm">106 <associationConnector edgePoints="[(6.5 : 3.17870198567708); (6.125 : 3.17870198567708)]" fixedFrom="Algorithm" fixedTo="Algorithm"> 107 107 <AssociationMoniker Name="/HiveDataContext/Job/Job_HiveExperiment" /> 108 108 <nodes> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs
r5511 r5526 1393 1393 private System.Guid _JobId; 1394 1394 1395 private global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState _State; 1396 1397 private string _ExecutionTime; 1398 1399 private System.Nullable<System.DateTime> _LastHeartbeat; 1400 1395 1401 private System.Nullable<System.Guid> _ParentJobId; 1396 1402 1397 private string _ExecutionTime;1398 1399 1403 private int _Priority; 1400 1404 … … 1403 1407 private int _MemoryNeeded; 1404 1408 1405 private System.Nullable<System.DateTime> _LastHeartbeat;1406 1407 private global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState _State;1409 private bool _IsParentJob; 1410 1411 private bool _FinishWhenChildJobsFinished; 1408 1412 1409 1413 private EntitySet<AssignedResource> _AssignedResources; … … 1425 1429 partial void OnJobIdChanging(System.Guid value); 1426 1430 partial void OnJobIdChanged(); 1431 partial void OnStateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState value); 1432 partial void OnStateChanged(); 1433 partial void OnExecutionTimeChanging(string value); 1434 partial void OnExecutionTimeChanged(); 1435 partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value); 1436 partial void OnLastHeartbeatChanged(); 1427 1437 partial void OnParentJobIdChanging(System.Nullable<System.Guid> value); 1428 1438 partial void OnParentJobIdChanged(); 1429 partial void OnExecutionTimeChanging(string value);1430 partial void OnExecutionTimeChanged();1431 1439 partial void OnPriorityChanging(int value); 1432 1440 partial void OnPriorityChanged(); … … 1435 1443 partial void OnMemoryNeededChanging(int value); 1436 1444 partial void OnMemoryNeededChanged(); 1437 partial void On LastHeartbeatChanging(System.Nullable<System.DateTime>value);1438 partial void On LastHeartbeatChanged();1439 partial void On StateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.JobStatevalue);1440 partial void On StateChanged();1445 partial void OnIsParentJobChanging(bool value); 1446 partial void OnIsParentJobChanged(); 1447 partial void OnFinishWhenChildJobsFinishedChanging(bool value); 1448 partial void OnFinishWhenChildJobsFinishedChanged(); 1441 1449 #endregion 1442 1450 … … 1472 1480 } 1473 1481 1482 [global::System.Data.Linq.Mapping.ColumnAttribute(Name="JobState", Storage="_State", DbType="VarChar(30)", CanBeNull=false)] 1483 public global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState State 1484 { 1485 get 1486 { 1487 return this._State; 1488 } 1489 set 1490 { 1491 if ((this._State != value)) 1492 { 1493 this.OnStateChanging(value); 1494 this.SendPropertyChanging(); 1495 this._State = value; 1496 this.SendPropertyChanged("State"); 1497 this.OnStateChanged(); 1498 } 1499 } 1500 } 1501 1502 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ExecutionTime", DbType="VarChar(30)")] 1503 public string ExecutionTime 1504 { 1505 get 1506 { 1507 return this._ExecutionTime; 1508 } 1509 set 1510 { 1511 if ((this._ExecutionTime != value)) 1512 { 1513 this.OnExecutionTimeChanging(value); 1514 this.SendPropertyChanging(); 1515 this._ExecutionTime = value; 1516 this.SendPropertyChanged("ExecutionTime"); 1517 this.OnExecutionTimeChanged(); 1518 } 1519 } 1520 } 1521 1522 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastHeartbeat", DbType="DateTime")] 1523 public System.Nullable<System.DateTime> LastHeartbeat 1524 { 1525 get 1526 { 1527 return this._LastHeartbeat; 1528 } 1529 set 1530 { 1531 if ((this._LastHeartbeat != value)) 1532 { 1533 this.OnLastHeartbeatChanging(value); 1534 this.SendPropertyChanging(); 1535 this._LastHeartbeat = value; 1536 this.SendPropertyChanged("LastHeartbeat"); 1537 this.OnLastHeartbeatChanged(); 1538 } 1539 } 1540 } 1541 1474 1542 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ParentJobId", DbType="UniqueIdentifier")] 1475 1543 public System.Nullable<System.Guid> ParentJobId … … 1496 1564 } 1497 1565 1498 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ExecutionTime", DbType="VarChar(30)")]1499 public string ExecutionTime1500 {1501 get1502 {1503 return this._ExecutionTime;1504 }1505 set1506 {1507 if ((this._ExecutionTime != value))1508 {1509 this.OnExecutionTimeChanging(value);1510 this.SendPropertyChanging();1511 this._ExecutionTime = value;1512 this.SendPropertyChanged("ExecutionTime");1513 this.OnExecutionTimeChanged();1514 }1515 }1516 }1517 1518 1566 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Priority", DbType="Int NOT NULL")] 1519 1567 public int Priority … … 1576 1624 } 1577 1625 1578 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ LastHeartbeat", DbType="DateTime")]1579 public System.Nullable<System.DateTime> LastHeartbeat1580 { 1581 get 1582 { 1583 return this._ LastHeartbeat;1584 } 1585 set 1586 { 1587 if ((this._ LastHeartbeat!= value))1588 { 1589 this.On LastHeartbeatChanging(value);1590 this.SendPropertyChanging(); 1591 this._ LastHeartbeat= value;1592 this.SendPropertyChanged(" LastHeartbeat");1593 this.On LastHeartbeatChanged();1594 } 1595 } 1596 } 1597 1598 [global::System.Data.Linq.Mapping.ColumnAttribute( Name="JobState", Storage="_State", DbType="VarChar(30)", CanBeNull=false)]1599 public global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState State1600 { 1601 get 1602 { 1603 return this._ State;1604 } 1605 set 1606 { 1607 if ((this._ State!= value))1608 { 1609 this.On StateChanging(value);1610 this.SendPropertyChanging(); 1611 this._ State= value;1612 this.SendPropertyChanged(" State");1613 this.On StateChanged();1626 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsParentJob", DbType="Bit")] 1627 public bool IsParentJob 1628 { 1629 get 1630 { 1631 return this._IsParentJob; 1632 } 1633 set 1634 { 1635 if ((this._IsParentJob != value)) 1636 { 1637 this.OnIsParentJobChanging(value); 1638 this.SendPropertyChanging(); 1639 this._IsParentJob = value; 1640 this.SendPropertyChanged("IsParentJob"); 1641 this.OnIsParentJobChanged(); 1642 } 1643 } 1644 } 1645 1646 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FinishWhenChildJobsFinished", DbType="Bit")] 1647 public bool FinishWhenChildJobsFinished 1648 { 1649 get 1650 { 1651 return this._FinishWhenChildJobsFinished; 1652 } 1653 set 1654 { 1655 if ((this._FinishWhenChildJobsFinished != value)) 1656 { 1657 this.OnFinishWhenChildJobsFinishedChanging(value); 1658 this.SendPropertyChanging(); 1659 this._FinishWhenChildJobsFinished = value; 1660 this.SendPropertyChanged("FinishWhenChildJobsFinished"); 1661 this.OnFinishWhenChildJobsFinishedChanged(); 1614 1662 } 1615 1663 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs
r5511 r5526 15 15 void DeleteJob(Guid id); 16 16 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count); 17 IEnumerable<DT.Job> GetParentJobs(IEnumerable<Guid> resourceIds, int count, bool finished); 17 18 #endregion 18 19 … … 23 24 void UpdateJobData(DT.JobData dto); 24 25 void DeleteJobData(Guid id); 26 #endregion 27 28 #region StateLog Methods 29 DT.StateLog GetStateLog(Guid id); 30 IEnumerable<DT.StateLog> GetStateLogs(Expression<Func<StateLog, bool>> predicate); 31 Guid AddStateLog(DT.StateLog dto); 32 void UpdateStateLog(DT.StateLog dto); 33 void DeleteStateLog(Guid id); 25 34 #endregion 26 35 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs
r5511 r5526 7 7 8 8 namespace HeuristicLab.Services.Hive.Tests { 9 using System.Threading; 9 10 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; 10 11 … … 17 18 ServiceLocator.Instance = new MockServiceLocator(ServiceLocator.Instance); 18 19 } 19 20 20 21 private IHiveService GetLocalService() { 21 22 return new HiveService(); … … 25 26 public void TestJobDao() { 26 27 IHiveDao dao = ServiceLocator.Instance.HiveDao; 27 28 28 29 DT.Job job1 = new DT.Job(); 29 30 job1.SetState(JobState.Offline, Guid.NewGuid()); … … 64 65 Assert.IsTrue(Math.Abs((job1.StateLog[i].DateTime - job1loaded.StateLog[i].DateTime).TotalSeconds) < 1); 65 66 } 67 68 job1 = job1loaded; 69 70 // test jobstates 71 job1.SetState(JobState.Transferring); Thread.Sleep(10); 72 job1.SetState(JobState.Calculating); Thread.Sleep(10); 73 job1.SetState(JobState.Transferring); Thread.Sleep(10); 74 job1.SetState(JobState.Finished); Thread.Sleep(10); 75 dao.UpdateJob(job1); 76 77 job1loaded = dao.GetJob(job1.Id); 78 for (int i = 0; i < job1.StateLog.Count; i++) { 79 Assert.AreEqual(job1.Id, job1loaded.StateLog[i].JobId); 80 Assert.AreEqual(job1.StateLog[i].State, job1loaded.StateLog[i].State); 81 Assert.AreEqual(job1.StateLog[i].SlaveId, job1loaded.StateLog[i].SlaveId); 82 Assert.AreEqual(job1.StateLog[i].UserId, job1loaded.StateLog[i].UserId); 83 Assert.AreEqual(job1.StateLog[i].Exception, job1loaded.StateLog[i].Exception); 84 Assert.IsTrue(Math.Abs((job1.StateLog[i].DateTime - job1loaded.StateLog[i].DateTime).TotalSeconds) < 1); 85 } 66 86 67 87 dao.DeleteJob(job1.Id); … … 175 195 //Assert.AreEqual(he.LastAccessed, heLoaded.LastAccessed); 176 196 //Assert.AreEqual(he.DateCreated, heLoaded.DateCreated); 177 197 178 198 DT.Job jobLoaded = dao.GetJob(he.RootJobId); 179 199 Assert.AreEqual(job.Id, jobLoaded.Id); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/HeuristicLab 3.3.exe.config
r5095 r5526 27 27 </roleManager> 28 28 </system.web> 29 29 30 <system.serviceModel> 30 31 <behaviors> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/HeuristicLab.Services.Hive.Tests-3.4.csproj
r5402 r5526 333 333 <Reference Include="System.Drawing" /> 334 334 <Reference Include="System.Runtime.Serialization" /> 335 <Reference Include="System.Security" /> 335 336 <Reference Include="System.ServiceModel" /> 336 337 <Reference Include="System.ServiceProcess" /> 338 <Reference Include="System.Web" /> 339 <Reference Include="System.Web.ApplicationServices" /> 337 340 <Reference Include="System.Windows.Forms" /> 338 341 <Reference Include="System.Xml" /> … … 397 400 <None Include="HeuristicLab 3.3.exe.config"> 398 401 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 402 <SubType>Designer</SubType> 399 403 </None> 400 404 <Shadow Include="Test References\HeuristicLab.Clients.Hive.Views-3.4.accessor" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs
r5511 r5526 24 24 using System.Linq; 25 25 using System.Threading; 26 using HeuristicLab.Clients.Hive;27 using HeuristicLab.Clients.Hive.Slave.Tests;28 using HeuristicLab.Hive;29 26 using HeuristicLab.Services.Hive.Common; 30 27 using HeuristicLab.Services.Hive.Common.DataTransfer; … … 34 31 namespace HeuristicLab.Services.Hive.Tests { 35 32 36 using System.Diagnostics;37 33 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; 38 34 … … 70 66 DT.JobData jobData = new DT.JobData() { 71 67 //Data = PersistenceUtil.Serialize(new MockJob(500, true)) 72 Data = new byte[10000 000]68 Data = new byte[10000] 73 69 }; 74 70 … … 119 115 Assert.AreEqual(JobState.Waiting, jobLoaded.State); 120 116 Assert.IsTrue(job.PluginsNeededIds.SequenceEqual(jobLoaded.PluginsNeededIds)); 121 117 122 118 DT.JobData jobDataLoaded = service.GetJobData(job.Id); 123 119 Assert.AreEqual(job.Id, jobDataLoaded.JobId); … … 132 128 133 129 // test assigned ressources 134 var actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() });130 var actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 135 131 Assert.AreEqual(1, actions.Count); 136 132 Assert.AreEqual(MessageContainer.MessageType.CalculateJob, actions[0].Message); … … 169 165 List<DT.Job> jobs = new List<DT.Job>(); 170 166 167 171 168 [TestMethod] 172 public void Test Heartbeats() {169 public void TestParentJobs() { 173 170 var service = GetLocalService(); 174 // check if group already exists and delete 175 var existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "TestGroup"); 176 if (existingSlaveGroup != null) { 177 var slavesToDelete = service.GetSlaves().Where(s => s.ParentResourceId == existingSlaveGroup.Id); 178 foreach (var slave in slavesToDelete) service.DeleteSlave(slave.Id); 179 service.DeleteSlaveGroup(existingSlaveGroup.Id); 180 } 181 182 Guid groupId = service.AddSlaveGroup(new SlaveGroup() { Name = "TestGroup", Description = "Used for unit tests" }); 183 184 // create slaves 185 var slaves = new List<DT.Slave>(); 186 for (int i = 0; i < 1; i++) { 187 DT.Slave slave = new DT.Slave() { 188 Cores = 2, 189 Memory = 4096, 190 Name = "Slave " + i, 191 IsAllowedToCalculate = true, 192 SlaveState = SlaveState.Idle, 193 CpuSpeed = 2800, 194 FreeCores = 2, 195 FreeMemory = 3000 196 }; 197 // check if slave with this name already exists and delete 198 var existingSlave = service.GetSlaves().Where(s => s.Name == slave.Name).SingleOrDefault(); 199 if (existingSlave != null) service.DeleteSlave(existingSlave.Id); 200 201 slave.Id = service.AddSlave(slave); 202 service.AddResourceToGroup(groupId, slave.Id); 203 slaves.Add(slave); 204 } 205 206 // create jobs with different group, they should not be assigned 207 existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "DummyGroup"); 208 if (existingSlaveGroup != null) service.DeleteSlaveGroup(existingSlaveGroup.Id); 209 210 Guid dummyGroupId = service.AddSlaveGroup(new SlaveGroup() { Name = "DummyGroup", Description = "Used for unit tests; jobs from this group shall not be calculated" }); 211 // create dummy jobs 212 var dummyJobs = new List<Job>(); 213 for (int i = 0; i < 2; i++) { 214 Job job = new Job() { 215 CoresNeeded = 1, MemoryNeeded = 0 216 }; 217 JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 218 job.Id = service.AddJob(job, jobData, new List<Guid> { dummyGroupId }); 219 dummyJobs.Add(job); 220 } 221 222 // create jobs 223 for (int i = 0; i < 2; i++) { 224 Job job = new Job() { 225 CoresNeeded = 1, MemoryNeeded = 0 226 }; 227 JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 228 job.Id = service.AddJob(job, jobData, new List<Guid> { groupId }); 229 jobs.Add(job); 230 } 231 232 // send heartbeats 233 foreach (var slave in slaves) { 234 new Thread(new ParameterizedThreadStart(RunSlaveThread)).Start(slave); 235 } 236 237 IEnumerable<LightweightJob> lightweightJobs; 238 do { 239 Thread.Sleep(500); 240 lightweightJobs = service.GetLightweightJobs(jobs.Select(x => x.Id)); 241 } while (!lightweightJobs.All(x => x.State == JobState.Finished)); 242 243 // delete slaves 244 foreach (var slave in slaves) { 245 service.DeleteSlave(slave.Id); 246 Assert.AreEqual(null, service.GetSlave(slave.Id)); 247 } 248 249 // delete groups 250 service.DeleteSlaveGroup(groupId); 251 service.DeleteSlaveGroup(dummyGroupId); 252 253 // delete jobs 254 foreach (var job in jobs) { 255 service.DeleteJob(job.Id); 256 } 257 258 // delete dummy jobs 259 foreach (var job in dummyJobs) { 260 service.DeleteJob(job.Id); 261 } 171 172 // create hive experiment 173 DT.HiveExperiment experiment = new DT.HiveExperiment() { 174 Name = "TestExperiment", 175 Description = "" 176 }; 177 178 // create parent job 179 DT.Job parentJob = new DT.Job() { 180 CoresNeeded = 1, 181 MemoryNeeded = 0, 182 Priority = 0, 183 IsParentJob = true, 184 FinishWhenChildJobsFinished = true 185 }; 186 parentJob.SetState(JobState.Offline); 187 188 DT.JobData parentJobData = new DT.JobData() { Data = new byte[0] }; 189 190 // create child job 191 DT.Job childJob = new DT.Job() { 192 CoresNeeded = 1, 193 MemoryNeeded = 0, 194 Priority = 0 195 }; 196 parentJob.SetState(JobState.Offline); 197 198 DT.JobData childJobData = new DT.JobData() { Data = new byte[1000] }; 199 200 // create slave 201 DT.Slave slave = new Slave(); 202 slave.Id = Guid.NewGuid(); 203 slave.Name = "TestSlave"; 204 slave.Memory = 1024; 205 slave.Cores = 4; 206 slave.CpuSpeed = 2800; 207 slave.OperatingSystem = "Windows 3.11"; 208 slave.CpuArchitecture = CpuArchitecture.x64; 209 210 // add slave 211 service.AddSlave(slave); 212 213 // add parent job 214 parentJob.Id = service.AddJob(parentJob, parentJobData, new List<Guid> { slave.Id }); 215 experiment.RootJobId = parentJob.Id; 216 217 // add child job 218 childJob.Id = service.AddChildJob(parentJob.Id, childJob, childJobData); 219 childJob.ParentJobId = parentJob.Id; 220 221 // add hive experiment 222 experiment.Id = service.AddHiveExperiment(experiment); 223 224 // test child job 225 var childJobLoaded = service.GetJob(childJob.Id); 226 Assert.AreEqual(childJob.ParentJobId, childJobLoaded.ParentJobId); 227 Assert.AreEqual(JobState.Waiting, childJobLoaded.State); 228 Assert.AreEqual(false, childJobLoaded.FinishWhenChildJobsFinished); 229 Assert.AreEqual(false, childJobLoaded.IsParentJob); 230 231 // test parent job 232 var parentJobLoaded = service.GetJob(parentJob.Id); 233 Assert.AreEqual(JobState.Waiting, parentJobLoaded.State); 234 Assert.AreEqual(true, parentJobLoaded.FinishWhenChildJobsFinished); 235 Assert.AreEqual(true, parentJobLoaded.IsParentJob); 236 237 // test heartbeat 238 var actions = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, AssignJob = true, FreeCores = 4, FreeMemory = 1024, JobProgress = new Dictionary<Guid, TimeSpan>() }); 239 Assert.AreEqual(1, actions.Count); // only the child job should be assigned 240 Assert.AreEqual(MessageContainer.MessageType.CalculateJob, actions[0].Message); 241 Assert.AreEqual(childJob.Id, actions[0].JobId); 242 243 // lifecycle - let it process one server-heartbeat; the parent job must NOT be set to finished 244 var lifecycleManager = new LifecycleManager(); 245 lifecycleManager.Start(); 246 Thread.Sleep(1000); 247 lifecycleManager.Stop(); 248 249 parentJobLoaded = service.GetJob(parentJob.Id); 250 Assert.AreEqual(JobState.Waiting, parentJobLoaded.State); 251 252 // set child job to finished 253 childJobLoaded.SetState(JobState.Finished, slave.Id, ""); 254 service.UpdateJob(childJobLoaded); 255 256 // lifecycle - let it process one server-heartbeat; this should set the parent job to finished 257 lifecycleManager.Start(); 258 Thread.Sleep(1000); 259 lifecycleManager.Stop(); 260 261 // test if parent job is finished 262 parentJobLoaded = service.GetJob(parentJob.Id); 263 Assert.AreEqual(JobState.Finished, parentJobLoaded.State); 264 265 // delete experiment 266 service.DeleteHiveExperiment(experiment.Id); 267 Assert.AreEqual(null, service.GetJob(parentJob.Id)); 268 Assert.AreEqual(null, service.GetJob(childJob.Id)); 269 270 service.DeleteSlave(slave.Id); 262 271 } 263 272 264 public void RunSlaveThread(object slaveobj) { 265 try { 266 var service = GetLocalService(); 267 Slave slave = (Slave)slaveobj; 268 int freeCores = slave.Cores.Value; 269 270 for (int i = 0; i < 10; i++) { 271 272 var messages = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, FreeMemory = 2423, FreeCores = freeCores, JobProgress = new Dictionary<Guid, TimeSpan>() }); 273 if (messages.Count == 0) { 274 Debug.WriteLine("No job available"); 275 return; // no more jobs 276 } 277 278 Debug.WriteLine("Messages: {0}", string.Join(", ", messages.Select(m => m.Message))); 279 280 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.AbortJob).Count() == 0); 281 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.SayHello).Count() == 0); 282 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.PauseJob).Count() == 0); 283 284 var calculateJobMessage = messages.Where(x => x.Message == MessageContainer.MessageType.CalculateJob).SingleOrDefault(); 285 if (calculateJobMessage != null) { 286 if (!jobs.Select(j => j.Id).Contains(calculateJobMessage.JobId)) 287 Assert.Fail("Got job which was not assigned to the slavegroup"); 288 289 Debug.WriteLine("Job available, calculating"); 290 Job job = service.GetJob(calculateJobMessage.JobId); 291 292 JobData jobData = service.GetJobData(job.Id); 293 IJob deserializedJob = PersistenceUtil.Deserialize<IJob>(jobData.Data); 294 deserializedJob.Start(); 295 job.SetState(JobState.Finished); 296 jobs.Where(x => x.Id == job.Id).Single().SetState(JobState.Finished); 297 jobData.Data = PersistenceUtil.Serialize(deserializedJob); 298 service.UpdateJobData(job, jobData); 299 Debug.WriteLine("finished calculating"); 300 } 301 } 302 } 303 catch (Exception e) { 304 Assert.Fail(e.Message, e); 305 } 306 } 273 //[TestMethod] 274 //public void TestHeartbeats() { 275 // var service = GetLocalService(); 276 // // check if group already exists and delete 277 // var existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "TestGroup"); 278 // if (existingSlaveGroup != null) { 279 // var slavesToDelete = service.GetSlaves().Where(s => s.ParentResourceId == existingSlaveGroup.Id); 280 // foreach (var slave in slavesToDelete) service.DeleteSlave(slave.Id); 281 // service.DeleteSlaveGroup(existingSlaveGroup.Id); 282 // } 283 284 // Guid groupId = service.AddSlaveGroup(new SlaveGroup() { Name = "TestGroup", Description = "Used for unit tests" }); 285 286 // // create slaves 287 // var slaves = new List<DT.Slave>(); 288 // for (int i = 0; i < 1; i++) { 289 // DT.Slave slave = new DT.Slave() { 290 // Cores = 2, 291 // Memory = 4096, 292 // Name = "Slave " + i, 293 // IsAllowedToCalculate = true, 294 // SlaveState = SlaveState.Idle, 295 // CpuSpeed = 2800, 296 // FreeCores = 2, 297 // FreeMemory = 3000 298 // }; 299 // // check if slave with this name already exists and delete 300 // var existingSlave = service.GetSlaves().Where(s => s.Name == slave.Name).SingleOrDefault(); 301 // if (existingSlave != null) service.DeleteSlave(existingSlave.Id); 302 303 // slave.Id = service.AddSlave(slave); 304 // service.AddResourceToGroup(groupId, slave.Id); 305 // slaves.Add(slave); 306 // } 307 308 // // create jobs with different group, they should not be assigned 309 // existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "DummyGroup"); 310 // if (existingSlaveGroup != null) service.DeleteSlaveGroup(existingSlaveGroup.Id); 311 312 // Guid dummyGroupId = service.AddSlaveGroup(new SlaveGroup() { Name = "DummyGroup", Description = "Used for unit tests; jobs from this group shall not be calculated" }); 313 // // create dummy jobs 314 // var dummyJobs = new List<Job>(); 315 // for (int i = 0; i < 2; i++) { 316 // Job job = new Job() { 317 // CoresNeeded = 1, MemoryNeeded = 0 318 // }; 319 // JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 320 // job.Id = service.AddJob(job, jobData, new List<Guid> { dummyGroupId }); 321 // dummyJobs.Add(job); 322 // } 323 324 // // create jobs 325 // for (int i = 0; i < 2; i++) { 326 // Job job = new Job() { 327 // CoresNeeded = 1, MemoryNeeded = 0 328 // }; 329 // JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 330 // job.Id = service.AddJob(job, jobData, new List<Guid> { groupId }); 331 // jobs.Add(job); 332 // } 333 334 // // send heartbeats 335 // foreach (var slave in slaves) { 336 // new Thread(new ParameterizedThreadStart(RunSlaveThread)).Start(slave); 337 // } 338 339 // IEnumerable<LightweightJob> lightweightJobs; 340 // do { 341 // Thread.Sleep(500); 342 // lightweightJobs = service.GetLightweightJobs(jobs.Select(x => x.Id)); 343 // } while (!lightweightJobs.All(x => x.State == JobState.Finished)); 344 345 // // delete slaves 346 // foreach (var slave in slaves) { 347 // service.DeleteSlave(slave.Id); 348 // Assert.AreEqual(null, service.GetSlave(slave.Id)); 349 // } 350 351 // // delete groups 352 // service.DeleteSlaveGroup(groupId); 353 // service.DeleteSlaveGroup(dummyGroupId); 354 355 // // delete jobs 356 // foreach (var job in jobs) { 357 // service.DeleteJob(job.Id); 358 // } 359 360 // // delete dummy jobs 361 // foreach (var job in dummyJobs) { 362 // service.DeleteJob(job.Id); 363 // } 364 //} 365 366 //public void RunSlaveThread(object slaveobj) { 367 // try { 368 // var service = GetLocalService(); 369 // Slave slave = (Slave)slaveobj; 370 // int freeCores = slave.Cores.Value; 371 372 // for (int i = 0; i < 10; i++) { 373 374 // var messages = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, FreeMemory = 2423, FreeCores = freeCores, JobProgress = new Dictionary<Guid, TimeSpan>() }); 375 // if (messages.Count == 0) { 376 // Debug.WriteLine("No job available"); 377 // return; // no more jobs 378 // } 379 380 // Debug.WriteLine("Messages: {0}", string.Join(", ", messages.Select(m => m.Message))); 381 382 // Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.AbortJob).Count() == 0); 383 // Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.SayHello).Count() == 0); 384 // Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.PauseJob).Count() == 0); 385 386 // var calculateJobMessage = messages.Where(x => x.Message == MessageContainer.MessageType.CalculateJob).SingleOrDefault(); 387 // if (calculateJobMessage != null) { 388 // if (!jobs.Select(j => j.Id).Contains(calculateJobMessage.JobId)) 389 // Assert.Fail("Got job which was not assigned to the slavegroup"); 390 391 // Debug.WriteLine("Job available, calculating"); 392 // Job job = service.GetJob(calculateJobMessage.JobId); 393 394 // JobData jobData = service.GetJobData(job.Id); 395 // IJob deserializedJob = PersistenceUtil.Deserialize<IJob>(jobData.Data); 396 // deserializedJob.Start(); 397 // job.SetState(JobState.Finished); 398 // jobs.Where(x => x.Id == job.Id).Single().SetState(JobState.Finished); 399 // jobData.Data = PersistenceUtil.Serialize(deserializedJob); 400 // service.UpdateJobData(job, jobData); 401 // Debug.WriteLine("finished calculating"); 402 // } 403 // } 404 // } 405 // catch (Exception e) { 406 // Assert.Fail(e.Message, e); 407 // } 408 //} 307 409 } 308 410 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r5511 r5526 31 31 32 32 #region Job Methods 33 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]34 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]33 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 34 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 35 35 public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) { 36 36 using (trans.OpenTransaction()) { … … 51 51 } 52 52 53 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 54 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 53 55 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) { 54 56 using (trans.OpenTransaction()) { … … 58 60 } 59 61 62 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 63 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 64 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 60 65 public Job GetJob(Guid jobId) { 61 66 return dao.GetJob(jobId); 62 67 } 63 68 69 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 70 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 64 71 public IEnumerable<Job> GetJobs() { 65 72 return dao.GetJobs(x => true); 66 73 } 67 74 75 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 76 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 68 77 public IEnumerable<LightweightJob> GetLightweightJobs(IEnumerable<Guid> jobIds) { 69 78 return dao.GetJobs(x => jobIds.Contains(x.JobId)).Select(x => new LightweightJob(x)).ToArray(); 70 79 } 71 80 81 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 82 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 72 83 public IEnumerable<LightweightJob> GetLightweightChildJobs(Guid? parentJobId, bool recursive, bool includeParent) { 73 84 return GetChildJobs(parentJobId, recursive, includeParent).Select(x => new LightweightJob(x)).ToArray(); 74 85 } 75 86 87 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 88 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 89 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 76 90 public JobData GetJobData(Guid jobId) { 77 91 return dao.GetJobData(jobId); 78 92 } 79 93 94 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 95 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 96 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 80 97 public void UpdateJob(Job job) { 81 98 using (trans.OpenTransaction()) { … … 84 101 } 85 102 103 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 104 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 105 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 86 106 public void UpdateJobData(Job job, JobData jobData) { 87 107 using (trans.OpenTransaction()) { … … 92 112 } 93 113 114 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 115 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 116 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 94 117 public void DeleteJob(Guid jobId) { 95 118 using (trans.OpenTransaction()) { … … 98 121 } 99 122 123 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 124 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 125 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 100 126 public void DeleteChildJobs(Guid parentJobId) { 101 127 using (trans.OpenTransaction()) { … … 111 137 112 138 #region Job Control Methods 139 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 140 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 141 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 113 142 public void StopJob(Guid jobId) { 114 143 using (trans.OpenTransaction()) { … … 116 145 } 117 146 } 147 148 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 149 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 150 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 118 151 public void PauseJob(Guid jobId) { 119 152 using (trans.OpenTransaction()) { … … 124 157 125 158 #region HiveExperiment Methods 126 159 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 160 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 127 161 public HiveExperiment GetHiveExperiment(Guid id) { 128 162 return dao.GetHiveExperiments(x => … … 132 166 } 133 167 168 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 169 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 134 170 public IEnumerable<HiveExperiment> GetHiveExperiments() { 135 171 return dao.GetHiveExperiments(x => x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0); 136 172 } 137 173 174 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 175 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 138 176 public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) { 139 177 using (trans.OpenTransaction()) { … … 144 182 } 145 183 184 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 185 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 146 186 public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) { 147 187 using (trans.OpenTransaction()) { … … 150 190 } 151 191 192 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 193 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 152 194 public void DeleteHiveExperiment(Guid hiveExperimentId) { 153 195 using (trans.OpenTransaction()) { … … 159 201 160 202 #region Login Methods 203 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 161 204 public void Hello(Slave slaveInfo) { 162 205 using (trans.OpenTransaction()) { … … 171 214 } 172 215 216 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 173 217 public void GoodBye(Guid slaveId) { 174 218 using (trans.OpenTransaction()) { … … 183 227 184 228 #region Heartbeat Methods 229 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 185 230 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 186 231 using (trans.OpenTransaction()) { … … 191 236 192 237 #region Plugin Methods 238 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 239 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 193 240 public Guid AddPlugin(Plugin plugin, List<PluginData> pluginDatas) { 194 241 using (trans.OpenTransaction()) { … … 203 250 } 204 251 } 252 253 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 254 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 255 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 205 256 public IEnumerable<Plugin> GetPlugins() { 206 257 return dao.GetPlugins(x => true); 207 258 } 208 259 260 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 261 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 262 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 209 263 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 210 264 List<PluginData> pluginDatas = new List<PluginData>(); … … 226 280 227 281 #region Slave Methods 282 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 283 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 228 284 public Guid AddSlave(Slave slave) { 229 285 using (trans.OpenTransaction()) { … … 232 288 } 233 289 290 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 291 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 234 292 public Guid AddSlaveGroup(SlaveGroup slaveGroup) { 235 293 using (trans.OpenTransaction()) { … … 238 296 } 239 297 298 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 299 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 240 300 public Slave GetSlave(Guid slaveId) { 241 301 return dao.GetSlave(slaveId); … … 246 306 } 247 307 308 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 309 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 248 310 public IEnumerable<Slave> GetSlaves() { 249 311 return dao.GetSlaves(x => true); 250 312 } 251 313 314 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 315 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 252 316 public IEnumerable<SlaveGroup> GetSlaveGroups() { 253 317 return dao.GetSlaveGroups(x => true); 254 318 } 255 319 320 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 321 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 256 322 public void UpdateSlave(Slave slave) { 257 323 using (trans.OpenTransaction()) { … … 260 326 } 261 327 328 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 329 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 262 330 public void UpdateSlaveGroup(SlaveGroup slaveGroup) { 263 331 using (trans.OpenTransaction()) { … … 266 334 } 267 335 336 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 337 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 268 338 public void DeleteSlave(Guid slaveId) { 269 339 using (trans.OpenTransaction()) { … … 272 342 } 273 343 344 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 345 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 274 346 public void DeleteSlaveGroup(Guid slaveGroupId) { 275 347 using (trans.OpenTransaction()) { … … 278 350 } 279 351 352 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 353 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 280 354 public void AddResourceToGroup(Guid slaveGroupId, Guid resourceId) { 281 355 using (trans.OpenTransaction()) { … … 286 360 } 287 361 362 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 363 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 288 364 public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) { 289 365 using (trans.OpenTransaction()) { … … 294 370 } 295 371 372 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 373 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 296 374 public Guid GetResourceId(string resourceName) { 297 375 using (trans.OpenTransaction()) { … … 325 403 326 404 #endregion 327 328 329 405 } 330 406 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs
r5511 r5526 36 36 public void Start() { 37 37 if (ExecutionState == Core.ExecutionState.Stopped) { 38 // kick off the event immediately 39 timer_Tick(this, EventArgs.Empty); 40 41 // start the timer 38 42 this.timer.Interval = (int)new TimeSpan(0, 0, 30).TotalMilliseconds; 39 43 this.timer.Start(); … … 54 58 lock (locker) { 55 59 using (trans.OpenTransaction()) { 56 var slaves = dao.GetSlaves(x => x.SlaveState != SlaveState.Offline); 57 foreach (Slave slave in slaves) { 58 if (!slave.LastHeartbeat.HasValue || (DateTime.Now - slave.LastHeartbeat.Value).TotalSeconds > ApplicationConstants.HeartbeatTimeout) { 59 slave.SlaveState = SlaveState.Offline; 60 AbortJobs(slave.Id); 61 dao.UpdateSlave(slave); 62 } 63 } 60 SetTimeoutSlavesOffline(); 61 FinishParentJobs(); 64 62 } 65 63 } 66 64 } 67 65 68 private void AbortJobs(Guid slaveId) { 69 var jobs = dao.GetJobs(x => x.StateLogs.Last().SlaveId == slaveId); 66 /// <summary> 67 /// Searches for slaves which are timed out, puts them and their jobs offline 68 /// </summary> 69 private void SetTimeoutSlavesOffline() { 70 var slaves = dao.GetSlaves(x => x.SlaveState != SlaveState.Offline); 71 foreach (Slave slave in slaves) { 72 if (!slave.LastHeartbeat.HasValue || (DateTime.Now - slave.LastHeartbeat.Value).TotalSeconds > ApplicationConstants.HeartbeatTimeout) { 73 slave.SlaveState = SlaveState.Offline; 74 SetJobsWaiting(slave.Id); 75 dao.UpdateSlave(slave); 76 } 77 } 78 } 79 80 /// <summary> 81 /// Looks for parent jobs which have FinishWhenChildJobsFinished and set their state to finished 82 /// </summary> 83 private void FinishParentJobs() { 84 var parentJobsToFinish = dao.GetParentJobs(dao.GetResources(x => true).Select(x => x.Id), 0, true); 85 foreach (var job in parentJobsToFinish) { 86 job.SetState(JobState.Finished); 87 dao.UpdateJob(job); 88 } 89 } 90 91 private void SetJobsWaiting(Guid slaveId) { 92 var jobs = dao.GetJobs(x => x.State == JobState.Calculating).Where(x => x.StateLog.Last().SlaveId == slaveId); 70 93 foreach (var j in jobs) { 71 94 j.StateLog.Add(new StateLog() { 72 UserId = auth.UserId,73 95 State = JobState.Waiting, 74 96 JobId = j.Id,
Note: See TracChangeset
for help on using the changeset viewer.