Changeset 5404
- Timestamp:
- 02/01/11 15:51:11 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 9 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj
r5402 r5404 366 366 <Name>HeuristicLab.Services.Hive.Common-3.4</Name> 367 367 </ProjectReference> 368 <ProjectReference Include="..\HeuristicLab.Services.Hive\3.4\HeuristicLab.Services.Hive-3.4.csproj"> 369 <Project>{CF9DA321-AC1B-4FD3-9EC3-67BC6B861BDE}</Project> 370 <Name>HeuristicLab.Services.Hive-3.4</Name> 371 </ProjectReference> 368 372 </ItemGroup> 369 373 <ItemGroup> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs
r5325 r5404 53 53 //get slave to fetch job 54 54 List<MessageContainer> msg = new List<MessageContainer>(); 55 msg.Add(new MessageContainer(MessageContainer.MessageType. AquireJob));55 msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob)); 56 56 allMsgs.Add(msg); 57 57 … … 99 99 //get slave to fetch job 100 100 List<MessageContainer> msg = new List<MessageContainer>(); 101 msg.Add(new MessageContainer(MessageContainer.MessageType. AquireJob));101 msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob)); 102 102 allMsgs.Add(msg); 103 103 … … 135 135 //get slave to fetch jobs 136 136 List<MessageContainer> msg = new List<MessageContainer>(); 137 msg.Add(new MessageContainer(MessageContainer.MessageType. AquireJob));137 msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob)); 138 138 allMsgs.Add(msg); 139 139 … … 142 142 143 143 msg = new List<MessageContainer>(); 144 msg.Add(new MessageContainer(MessageContainer.MessageType. AquireJob));144 msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob)); 145 145 allMsgs.Add(msg); 146 146 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs
r5314 r5404 26 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 27 27 using HeuristicLab.Clients.Hive.Slave.Properties; 28 using System.Management; 29 using System.Diagnostics; 28 30 29 31 … … 44 46 45 47 public Core Core { get; set; } 46 private HeuristicLab.Services.Hive.Common.DataTransfer.Slave hardwareInfo;47 48 private HeuristicLab.Services.Hive.Common.DataTransfer.Slave slave; 49 48 50 /// <summary> 49 51 /// Constructor for the singleton, must recover Guid, Calendar, ... 50 52 /// </summary> 51 53 private ConfigManager() { 52 hardwareInfo = new HeuristicLab.Services.Hive.Common.DataTransfer.Slave(); 53 54 if (Settings.Default.Guid == Guid.Empty) { 55 hardwareInfo.Id = Guid.NewGuid(); 56 Settings.Default.Guid = hardwareInfo.Id; 57 Settings.Default.Save(); 58 } else 59 hardwareInfo.Id = Settings.Default.Guid; 60 61 hardwareInfo.Cores = Environment.ProcessorCount; 62 hardwareInfo.Memory = 1024; 63 hardwareInfo.Name = Environment.MachineName; 54 slave = new HeuristicLab.Services.Hive.Common.DataTransfer.Slave(); 55 slave.Id = GetUniqueMachineId(); 56 slave.Name = Environment.MachineName; 57 slave.Cores = Environment.ProcessorCount; 58 slave.Memory = GetPhysicalMemory(); 59 slave.CpuArchitecture = Environment.Is64BitOperatingSystem ? CpuArchitecture.x64 : CpuArchitecture.x86; 60 slave.OperatingSystem = Environment.OSVersion.VersionString; 64 61 } 65 62 … … 71 68 //TODO: how to display connectedsince in gui? 72 69 //hardwareInfo.Login = WcfService.Instance.ConnectedSince; 73 return hardwareInfo;70 return slave; 74 71 } 75 72 … … 81 78 //Todo: Locking 82 79 StatusCommons st = new StatusCommons(); 83 st.ClientGuid = hardwareInfo.Id;80 st.ClientGuid = slave.Id; 84 81 85 82 st.Status = WcfService.Instance.ConnState; 86 83 st.ConnectedSince = WcfService.Instance.ConnectedSince; 87 84 88 st.TotalCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value : 0;89 st.FreeCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value - GetUsedCores() : 0;85 st.TotalCores = slave.Cores.HasValue ? slave.Cores.Value : 0; 86 st.FreeCores = slave.Cores.HasValue ? slave.Cores.Value - GetUsedCores() : 0; 90 87 91 88 st.JobsAborted = SlaveStatusInfo.JobsAborted; … … 128 125 } 129 126 127 public static Guid GetUniqueMachineId() { 128 // todo: instead of creating a new id, generate an ID from hardware IDs which is always the same for one machine 129 if (Settings.Default.Guid == Guid.Empty) { 130 Guid id = Guid.NewGuid(); 131 Settings.Default.Guid = id; 132 Settings.Default.Save(); 133 return id; 134 } else 135 return Settings.Default.Guid; 136 } 137 138 public static int GetPhysicalMemory() { 139 return 1024; // todo 140 } 141 142 public static int GetFreeMemory() { 143 PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true); 144 int mb = (int)(counter.NextValue() / 1024 / 1024); 145 return mb; 146 } 130 147 } 131 148 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
r5402 r5404 153 153 154 154 //Pull a Job from the Server 155 case MessageContainer.MessageType. AquireJob:156 Job myJob = wcfService. AquireJob();155 case MessageContainer.MessageType.CalculateJob: 156 Job myJob = wcfService.GetJob(container.JobId); 157 157 //TODO: handle in own thread!! 158 158 JobData jobData = wcfService.GetJobData(myJob.Id); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs
r5375 r5404 93 93 SlaveId = info.Id, /*Settings.Default.Guid*/ 94 94 FreeCores = info.Cores.HasValue ? info.Cores.Value - ConfigManager.Instance.GetUsedCores() : 0, 95 FreeMemory = GetFreeMemory(),95 FreeMemory = ConfigManager.GetFreeMemory(), 96 96 JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs() 97 97 }; … … 129 129 } 130 130 #endregion 131 132 #region Helpers133 private int GetFreeMemory() {134 PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);135 int mb = (int)(counter.NextValue() / 1024 / 1024);136 return mb;137 }138 #endregion139 131 } 140 132 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj
r5402 r5404 88 88 <Reference Include="System" /> 89 89 <Reference Include="System.Core" /> 90 <Reference Include="System.Management" /> 90 91 <Reference Include="System.Runtime.Serialization" /> 91 92 <Reference Include="System.ServiceModel" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs
r5375 r5404 113 113 114 114 /// <summary> 115 /// Aquire a Job from the Server, return the Job116 /// </summary> 117 public Job AquireJob() {118 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) { 119 try { 120 Job job = service.Obj. AquireJob(Settings.Default.Guid);115 /// Get a Job from the Server 116 /// </summary> 117 public Job GetJob(Guid jobId) { 118 using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) { 119 try { 120 Job job = service.Obj.GetJob(jobId); 121 121 return job; 122 122 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentClient.cs
r5402 r5404 114 114 } 115 115 116 private List<Guid> pluginsNeededIds; 117 public List<Guid> PluginsNeededIds { 118 get { return pluginsNeededIds; } 119 set { pluginsNeededIds = value; } 116 private IEnumerable<Plugin> onlinePlugins; 117 public IEnumerable<Plugin> OnlinePlugins { 118 get { return onlinePlugins; } 119 set { onlinePlugins = value; } 120 } 121 122 private List<Plugin> alreadyUploadedPlugins; 123 public List<Plugin> AlreadyUploadedPlugins { 124 get { return alreadyUploadedPlugins; } 125 set { alreadyUploadedPlugins = value; } 120 126 } 121 127 … … 247 253 248 254 this.progress.Status = "Uploading plugins..."; 249 this.PluginsNeededIds = GetPluginsNeededIds(this.useLocalPlugins); 255 this.OnlinePlugins = service.Obj.GetPlugins(); 256 this.AlreadyUploadedPlugins = new List<Plugin>(); 250 257 251 258 this.progress.Status = "Uploading jobs..."; … … 269 276 IsProgressing = false; 270 277 } 271 }272 273 /// <summary>274 /// Gets the Ids of all plugins needed for executing the job.275 /// All loaded plugins are assumed to be necessary.276 /// If a plugin with the same name and version is already online, it is used. Otherwise the local plugin is uploaded.277 /// If useLocalPlugins is true, all local plugins are uploaded regardless of the existence of the same plugin online.278 /// </summary>279 public static List<Guid> GetPluginsNeededIds(bool useLocalPlugins) {280 IEnumerable<IPluginDescription> localPlugins = ApplicationManager.Manager.Plugins;281 List<Guid> pluginsNeededIds = new List<Guid>();282 283 using (var service = ServiceLocator.Instance.GetService()) {284 IEnumerable<Plugin> onlinePlugins = service.Obj.GetPlugins();285 286 foreach (IPluginDescription localPlugin in localPlugins) {287 Plugin found = onlinePlugins.Where(onlinePlugin => onlinePlugin.Name == localPlugin.Name && onlinePlugin.Version == localPlugin.Version).SingleOrDefault();288 if (!useLocalPlugins && found != null) {289 // plugin is available online; reuse290 pluginsNeededIds.Add(found.Id);291 } else {292 // upload the plugin293 Plugin p = new Plugin() { Name = localPlugin.Name, Version = localPlugin.Version, IsLocal = useLocalPlugins };294 List<PluginData> pluginDatas = new List<PluginData>();295 296 foreach (IPluginFile pf in localPlugin.Files) {297 PluginData pluginData = new PluginData();298 299 pluginData.Data = File.ReadAllBytes(pf.Name);300 pluginDatas.Add(pluginData);301 }302 pluginsNeededIds.Add(service.Obj.AddPlugin(p, pluginDatas));303 }304 }305 }306 return pluginsNeededIds;307 278 } 308 279 … … 319 290 this.progress.Status = string.Format("Serializing job {0} of {1}", jobCount, totalJobCount); 320 291 JobData jobData; 292 List<IPluginDescription> plugins; 321 293 if (hiveJob.OptimizerJob.ComputeInParallel && 322 294 (hiveJob.OptimizerJob.Optimizer is Optimization.Experiment || hiveJob.OptimizerJob.Optimizer is Optimization.BatchRun)) { 323 295 hiveJob.Job.JobState = JobState.WaitingForChildJobs; 324 296 hiveJob.OptimizerJob.CollectChildJobs = false; // don't collect child-jobs on slaves 325 jobData = hiveJob.GetAsJobData(true );297 jobData = hiveJob.GetAsJobData(true, out plugins); 326 298 } else { 327 jobData = hiveJob.GetAsJobData(false );328 } 329 330 hiveJob.Job.PluginsNeededIds = this.PluginsNeededIds;299 jobData = hiveJob.GetAsJobData(false, out plugins); 300 } 301 302 hiveJob.Job.PluginsNeededIds = GetPluginDependencies(service, onlinePlugins, alreadyUploadedPlugins, plugins, useLocalPlugins); 331 303 332 304 this.progress.Status = string.Format("Uploading job {0} of {1} ({2} kb)", jobCount, totalJobCount, jobData.Data.Count() / 1024); … … 347 319 } 348 320 } 349 321 350 322 /// <summary> 351 323 /// Converts a string which can contain Ids separated by ';' to a enumerable … … 369 341 #endregion 370 342 371 public void StartResultPolling() {372 if (!jobResultPoller.IsPolling) {373 jobResultPoller.Start();374 } else {375 throw new JobResultPollingException("Result polling already running");376 }377 }378 379 public void StopResultPolling() {380 if (jobResultPoller.IsPolling) {381 jobResultPoller.Stop();382 } else {383 throw new JobResultPollingException("Result polling not running");384 }385 }386 343 387 344 #region HiveJob Events … … 483 440 484 441 #region JobResultPoller Events 442 443 public void StartResultPolling() { 444 if (!jobResultPoller.IsPolling) { 445 jobResultPoller.Start(); 446 } else { 447 throw new JobResultPollingException("Result polling already running"); 448 } 449 } 450 451 public void StopResultPolling() { 452 if (jobResultPoller.IsPolling) { 453 jobResultPoller.Stop(); 454 } else { 455 throw new JobResultPollingException("Result polling not running"); 456 } 457 } 458 485 459 private void RegisterResultPollingEvents() { 486 460 jobResultPoller.ExceptionOccured += new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured); … … 497 471 jobResultPoller.IsPollingChanged -= new EventHandler(jobResultPoller_IsPollingChanged); 498 472 } 499 void jobResultPoller_IsPollingChanged(object sender, EventArgs e) {473 private void jobResultPoller_IsPollingChanged(object sender, EventArgs e) { 500 474 this.IsPollingResults = jobResultPoller.IsPolling; 501 475 } 502 void jobResultPoller_PollingFinished(object sender, EventArgs e) {476 private void jobResultPoller_PollingFinished(object sender, EventArgs e) { 503 477 LogMessage("Polling results finished"); 504 478 } 505 void jobResultPoller_PollingStarted(object sender, EventArgs e) {479 private void jobResultPoller_PollingStarted(object sender, EventArgs e) { 506 480 LogMessage("Polling results started"); 507 481 } 508 void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) {482 private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) { 509 483 foreach (LightweightJob lightweightJob in e.Value) { 510 484 HiveJob hj = hiveJob.GetHiveJobByJobId(lightweightJob.Id); … … 543 517 } 544 518 545 void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) {519 private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) { 546 520 OnExceptionOccured(e.Value); 547 521 } … … 578 552 #endregion 579 553 554 #region Job Loading 580 555 /// <summary> 581 556 /// Downloads the root job from hive and sets the experiment, rootJob and rootJobItem … … 674 649 } 675 650 } 676 651 #endregion 652 653 #region Plugin Management 654 /// <summary> 655 /// Checks if plugins are available on Hive Server. If not they are uploaded. Ids are returned. 656 /// </summary> 657 /// <param name="service">An active service-proxy</param> 658 /// <param name="onlinePlugins">List of plugins which are available online</param> 659 /// <param name="alreadyUploadedPlugins">List of plugins which have been uploaded from this HiveExperiment</param> 660 /// <param name="neededPlugins">List of plugins which need to be uploaded</param> 661 /// <param name="useLocalPlugins">If true, the plugins which are already online are ignored. All local plugins are uploaded, but only once.</param> 662 /// <returns></returns> 663 private static List<Guid> GetPluginDependencies(IHiveService service, IEnumerable<Plugin> onlinePlugins, List<Plugin> alreadyUploadedPlugins, IEnumerable<IPluginDescription> neededPlugins, bool useLocalPlugins) { 664 var pluginIds = new List<Guid>(); 665 foreach (var neededPlugin in neededPlugins) { 666 Plugin foundPlugin = alreadyUploadedPlugins.SingleOrDefault(p => p.Name == neededPlugin.Name && p.Version == neededPlugin.Version); 667 if (foundPlugin == null) { 668 foundPlugin = onlinePlugins.SingleOrDefault(p => p.Name == neededPlugin.Name && p.Version == neededPlugin.Version); 669 if (useLocalPlugins || foundPlugin == null) { 670 Plugin p = CreatePlugin(neededPlugin, useLocalPlugins); 671 List<PluginData> pd = CreatePluginDatas(neededPlugin); 672 p.Id = service.AddPlugin(p, pd); 673 alreadyUploadedPlugins.Add(p); 674 } else { 675 pluginIds.Add(foundPlugin.Id); 676 } 677 } else { 678 pluginIds.Add(foundPlugin.Id); 679 } 680 } 681 return pluginIds; 682 } 683 684 private static Plugin CreatePlugin(IPluginDescription plugin, bool useLocalPlugins) { 685 return new Plugin() { Name = plugin.Name, Version = plugin.Version, IsLocal = useLocalPlugins }; 686 } 687 688 private static List<PluginData> CreatePluginDatas(IPluginDescription plugin) { 689 List<PluginData> pluginDatas = new List<PluginData>(); 690 691 foreach (IPluginFile pf in plugin.Files) { 692 PluginData pluginData = new PluginData(); 693 694 pluginData.Data = File.ReadAllBytes(pf.Name); 695 pluginData.FileName = Path.GetFileName(pf.Name); 696 pluginDatas.Add(pluginData); 697 } 698 return pluginDatas; 699 } 700 701 /// <summary> 702 /// Gets the Ids of all plugins needed for executing the job. 703 /// All loaded plugins are assumed to be necessary. 704 /// If a plugin with the same name and version is already online, it is used. Otherwise the local plugin is uploaded. 705 /// If useLocalPlugins is true, all local plugins are uploaded regardless of the existence of the same plugin online. 706 /// </summary> 707 //public static List<Guid> GetPluginsNeededIds(bool useLocalPlugins) { 708 // IEnumerable<IPluginDescription> localPlugins = ApplicationManager.Manager.Plugins; 709 // List<Guid> pluginsNeededIds = new List<Guid>(); 710 711 // using (var service = ServiceLocator.Instance.GetService()) { 712 // IEnumerable<Plugin> onlinePlugins = service.Obj.GetPlugins(); 713 714 // foreach (IPluginDescription localPlugin in localPlugins) { 715 // Plugin found = onlinePlugins.Where(onlinePlugin => onlinePlugin.Name == localPlugin.Name && onlinePlugin.Version == localPlugin.Version).SingleOrDefault(); 716 // if (!useLocalPlugins && found != null) { 717 // // plugin is available online; reuse 718 // pluginsNeededIds.Add(found.Id); 719 // } else { 720 // // upload the plugin 721 // Plugin p = new Plugin() { Name = localPlugin.Name, Version = localPlugin.Version, IsLocal = useLocalPlugins }; 722 // List<PluginData> pluginDatas = new List<PluginData>(); 723 724 // foreach (IPluginFile pf in localPlugin.Files) { 725 // PluginData pluginData = new PluginData(); 726 727 // pluginData.Data = File.ReadAllBytes(pf.Name); 728 // pluginDatas.Add(pluginData); 729 // } 730 // pluginsNeededIds.Add(service.Obj.AddPlugin(p, pluginDatas)); 731 // } 732 // } 733 // } 734 // return pluginsNeededIds; 735 //} 736 #endregion 677 737 } 678 738 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobClient.cs
r5402 r5404 32 32 using HeuristicLab.PluginInfrastructure; 33 33 using HeuristicLab.Services.Hive.Common.DataTransfer; 34 using HeuristicLab.PluginInfrastructure.Manager; 34 35 35 36 namespace HeuristicLab.Clients.Hive { … … 425 426 /// if true the Child-Optimizers will not be serialized (if the job contains an Experiment) 426 427 /// </param> 427 public JobData GetAsJobData(bool withoutChildOptimizers) { 428 public JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) { 429 plugins = new List<IPluginDescription>(); 428 430 if (this.optimizerJob == null || this.optimizerJob.Optimizer == null) 429 431 return null; 430 432 433 IEnumerable<Type> usedTypes; 431 434 byte[] jobByteArray; 432 435 if (withoutChildOptimizers && this.OptimizerJob.Optimizer is Optimization.Experiment) { 433 436 OptimizerJob clonedJob = (OptimizerJob)this.OptimizerJob.Clone(); // use a cloned job, so that the childHiveJob don't get confused 434 437 clonedJob.OptimizerAsExperiment.Optimizers.Clear(); 435 jobByteArray = PersistenceUtil.Serialize(clonedJob );438 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 436 439 } else if (withoutChildOptimizers && this.OptimizerJob.Optimizer is Optimization.BatchRun) { 437 440 OptimizerJob clonedJob = (OptimizerJob)this.OptimizerJob.Clone(); 438 441 clonedJob.OptimizerAsBatchRun.Optimizer = null; 439 jobByteArray = PersistenceUtil.Serialize(clonedJob );442 jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes); 440 443 } else if (this.OptimizerJob.Optimizer is IAlgorithm) { 441 444 ((IAlgorithm)this.OptimizerJob.Optimizer).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size 442 jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob );445 jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob, out usedTypes); 443 446 } else { 444 jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob );447 jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob, out usedTypes); 445 448 } 446 449 … … 450 453 }; 451 454 455 CollectDeclaringPlugins(plugins, usedTypes); 456 452 457 return jobData; 458 } 459 460 private void CollectDeclaringPlugins(List<IPluginDescription> plugins, IEnumerable<Type> usedTypes) { 461 foreach (Type type in usedTypes) { 462 var plugin = ApplicationManager.Manager.GetDeclaringPlugin(type); 463 if (plugin != null && !plugins.Contains(plugin)) { 464 plugins.Add(plugin); 465 CollectPluginDependencies(plugins, plugin); 466 } 467 } 468 } 469 470 private void CollectPluginDependencies(List<IPluginDescription> plugins, IPluginDescription plugin) { 471 if (plugin == null) return; 472 foreach (var dependency in plugin.Dependencies) { 473 if (!plugins.Contains(dependency)) { 474 plugins.Add(dependency); 475 CollectPluginDependencies(plugins, dependency); 476 } 477 } 453 478 } 454 479 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/PersistenceUtil.cs
r5156 r5404 22 22 using System.IO; 23 23 using HeuristicLab.Persistence.Default.Xml; 24 using System.Collections.Generic; 25 using HeuristicLab.PluginInfrastructure; 26 using System; 27 using HeuristicLab.Persistence.Core; 24 28 25 29 namespace HeuristicLab.Clients.Hive { 26 30 public static class PersistenceUtil { 31 public static byte[] Serialize(object obj, out IEnumerable<Type> types) { 32 MemoryStream memStream = new MemoryStream(); 33 XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 34 byte[] jobByteArray = memStream.ToArray(); 35 memStream.Dispose(); 36 return jobByteArray; 37 } 38 27 39 public static byte[] Serialize(object obj) { 28 40 MemoryStream memStream = new MemoryStream(); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs
r5375 r5404 39 39 40 40 public Disposable<IHiveService> GetService() { 41 //TODO: move user config to app.config! 42 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService", null, "ascheibe", "ascheibe$4"); 41 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService"); 43 42 } 44 43 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive 3.4.sln
r5402 r5404 31 31 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Services.Hive-3.4", "HeuristicLab.Services.Hive\3.4\HeuristicLab.Services.Hive-3.4.csproj", "{CF9DA321-AC1B-4FD3-9EC3-67BC6B861BDE}" 32 32 EndProject 33 Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Hive-3.4", "HeuristicLab.Services.Hive.Web\Hive-3.4 \", "{0CA6706D-A569-45DE-A85C-4158891CC1BC}"33 Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Hive-3.4", "HeuristicLab.Services.Hive.Web\Hive-3.4", "{0CA6706D-A569-45DE-A85C-4158891CC1BC}" 34 34 ProjectSection(WebsiteProperties) = preProject 35 35 TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0" … … 64 64 EndProject 65 65 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon", "HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon\HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon.csproj", "{7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}" 66 EndProject 67 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Tests-3.4", "HeuristicLab.Clients.Hive.Tests\HeuristicLab.Clients.Hive.Tests-3.4.csproj", "{8D40A723-139D-40E4-8BBA-4CB309A9E4B9}" 66 68 EndProject 67 69 Global … … 241 243 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|x86.ActiveCfg = Release|x86 242 244 {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|x86.Build.0 = Release|x86 245 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 246 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Debug|Any CPU.Build.0 = Debug|Any CPU 247 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 248 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 249 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Debug|x86.ActiveCfg = Debug|Any CPU 250 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Release|Any CPU.ActiveCfg = Release|Any CPU 251 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Release|Any CPU.Build.0 = Release|Any CPU 252 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 253 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Release|Mixed Platforms.Build.0 = Release|Any CPU 254 {8D40A723-139D-40E4-8BBA-4CB309A9E4B9}.Release|x86.ActiveCfg = Release|Any CPU 243 255 EndGlobalSection 244 256 GlobalSection(SolutionProperties) = preSolution -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Slave.cs
r5106 r5404 25 25 26 26 namespace HeuristicLab.Services.Hive.Common.DataTransfer { 27 public enum CpuArchitecture { 28 x86, x64 29 } 30 27 31 [DataContract] 28 32 [Serializable] … … 35 39 public int? CpuSpeed { get; set; } // MHz 36 40 [DataMember] 41 public CpuArchitecture CpuArchitecture { get; set; } 42 [DataMember] 37 43 public int? Memory { get; set; } // MB 38 44 [DataMember] 39 45 public int? FreeMemory { get; set; } // MB 46 [DataMember] 47 public string OperatingSystem { get; set; } 40 48 [DataMember] 41 49 public SlaveState SlaveState { get; set; } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/MessageContainer.cs
r5314 r5404 35 35 public enum MessageType { 36 36 // *** commands from hive server *** 37 AquireJob, // slave should aquire a new job (formerly FetchJob)37 CalculateJob, // slave should calculate a job. the job is already assigned to the slave 38 38 StopJob, // slave should stop the job and submit results 39 39 AbortJob, // slave should shut the job down immediately without submitting results -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/ServiceContracts/IHiveService.cs
r5375 r5404 40 40 [OperationContract] 41 41 void DeleteChildJobs(Guid parentJobId); 42 43 [OperationContract] // new method: appropriate job is choosen and set to 'calculating'. the slave is responsible for requesting the jobData. Server should wait some timeout until he redistributes the job44 Job AquireJob(Guid slaveId);45 42 46 43 [OperationContract] -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs
r5402 r5404 143 143 public static DT.Slave ToDto(Slave source) { 144 144 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 };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 }; 146 146 } 147 147 public static Slave ToEntity(DT.Slave source) { … … 152 152 public static void ToEntity(DT.Slave source, Slave target) { 153 153 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; 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; 155 155 } 156 156 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj
r5402 r5404 103 103 <Compile Include="Convert.cs" /> 104 104 <None Include="HeuristicLabServicesHiveDataAccessPlugin.cs.frame" /> 105 <Compile Include="Exceptions\DaoException.cs" /> 105 106 <Compile Include="HeuristicLabServicesHiveDataAccessPlugin.cs" /> 106 107 <Compile Include="HiveDao.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
r5402 r5404 82 82 } 83 83 84 public IEnumerable<DT.Job> GetWaitingParentJobs(Guid slaveId) { 85 using (var db = CreateContext()) { 86 // todo: slaveId is unused! 84 public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) { 85 using (var db = CreateContext()) { 87 86 var query = from ar in db.AssignedResources 88 where ar.Job.JobState == JobState.WaitingForChildJobs && 89 (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) && 92 (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 87 where resourceIds.Contains(ar.ResourceId) 88 && ar.Job.JobState == JobState.WaitingForChildJobs 89 && (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) 92 && (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 95 95 orderby ar.Job.Priority descending 96 96 select Convert.ToDto(ar.Job); 97 return query.ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave) { 102 using (var db = CreateContext()) { 103 var query = from j in db.Jobs 104 where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory 105 orderby j.Priority descending 106 select Convert.ToDto(j); 107 var waitingJobs = query.ToArray(); 108 var waitingParentJobs = GetWaitingParentJobs(slave.Id); 97 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count) { 102 using (var db = CreateContext()) { 103 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); 104 var waitingParentJobs = GetWaitingParentJobs(resourceIds, count); 105 if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray(); 106 107 var query = from ar in db.AssignedResources 108 where resourceIds.Contains(ar.ResourceId) 109 && ar.Job.JobState == JobState.Waiting 110 && ar.Job.CoresNeeded <= slave.FreeCores 111 && ar.Job.MemoryNeeded <= slave.FreeMemory 112 orderby ar.Job.Priority descending 113 select Convert.ToDto(ar.Job); 114 var waitingJobs = (count == 0 ? query : query.Take(count)).ToArray(); 109 115 return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority); 110 116 } … … 350 356 using (var db = CreateContext()) { 351 357 var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id); 352 if (entity != null) db.Resources.DeleteOnSubmit(entity); 358 if (entity != null) { 359 if (db.Resources.Where(r => r.ParentResourceId == id).Count() > 0) { 360 throw new DaoException("Cannot delete SlaveGroup as long as there are Slaves in the group"); 361 } 362 db.Resources.DeleteOnSubmit(entity); 363 } 353 364 db.SubmitChanges(); 354 365 } … … 408 419 return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray(); 409 420 } 421 } 422 423 /// <summary> 424 /// Returns all parent resources of a resource (the given resource is also added) 425 /// </summary> 426 private IEnumerable<DT.Resource> GetParentResources(Guid resourceId) { 427 using (var db = CreateContext()) { 428 var resources = new List<Resource>(); 429 CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single()); 430 return resources.Select(r => Convert.ToDto(r)).ToArray(); 431 } 432 } 433 434 private void CollectParentResources(List<Resource> resources, Resource resource) { 435 if (resource == null) return; 436 resources.Add(resource); 437 CollectParentResources(resources, resource.ParentResource); 410 438 } 411 439 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml
r5402 r5404 49 49 <Column Name="FreeMemory" Type="System.Int32" DbType="Int" CanBeNull="true" /> 50 50 <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" /> 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" /> 51 53 <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" /> 52 54 </Type> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout
r5402 r5404 45 45 </nestedChildShapes> 46 46 </classShape> 47 <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2. 3478011067708335">47 <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2.7324039713541666"> 48 48 <DataClassMoniker Name="/HiveDataContext/Slave" /> 49 49 <nestedChildShapes> 50 <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />50 <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 51 51 </nestedChildShapes> 52 52 </classShape> … … 69 69 </nodes> 70 70 </inheritanceConnector> 71 <associationConnector edgePoints="[(1 2.25 : 2.57859537760417); (12.25 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">71 <associationConnector edgePoints="[(11.9843735 : 2.57859537760417); (11.9843735 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 72 72 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedResource" /> 73 73 <nodes> … … 97 97 </nodes> 98 98 </associationConnector> 99 <associationConnector edgePoints="[(8.875 : 2. 17390055338542); (8.5 : 2.17390055338542)]" fixedFrom="NotFixed" fixedTo="NotFixed">99 <associationConnector edgePoints="[(8.875 : 2.36620198567708); (8.5 : 2.36620198567708)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 100 100 <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" /> 101 101 <nodes> … … 130 130 </nestedChildShapes> 131 131 </classShape> 132 <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom=" Algorithm" fixedTo="Algorithm">132 <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 133 133 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_PluginData" /> 134 134 <nodes> … … 144 144 </nodes> 145 145 </associationConnector> 146 <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom=" Algorithm" fixedTo="Algorithm">146 <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 147 147 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" /> 148 148 <nodes> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs
r5402 r5404 3 3 // <auto-generated> 4 4 // This code was generated by a tool. 5 // Runtime Version:4.0.30319. 15 // Runtime Version:4.0.30319.208 6 6 // 7 7 // Changes to this file may cause incorrect behavior and will be lost if … … 1060 1060 private bool _IsAllowedToCalculate; 1061 1061 1062 private global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture _CpuArchitecture; 1063 1064 private string _OperatingSystem; 1065 1062 1066 private EntitySet<Job> _Jobs; 1063 1067 … … 1082 1086 partial void OnIsAllowedToCalculateChanging(bool value); 1083 1087 partial void OnIsAllowedToCalculateChanged(); 1088 partial void OnCpuArchitectureChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture value); 1089 partial void OnCpuArchitectureChanged(); 1090 partial void OnOperatingSystemChanging(string value); 1091 partial void OnOperatingSystemChanged(); 1084 1092 #endregion 1085 1093 … … 1246 1254 this.SendPropertyChanged("IsAllowedToCalculate"); 1247 1255 this.OnIsAllowedToCalculateChanged(); 1256 } 1257 } 1258 } 1259 1260 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CpuArchitecture", DbType="VarChar(3)", CanBeNull=false)] 1261 public global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture CpuArchitecture 1262 { 1263 get 1264 { 1265 return this._CpuArchitecture; 1266 } 1267 set 1268 { 1269 if ((this._CpuArchitecture != value)) 1270 { 1271 this.OnCpuArchitectureChanging(value); 1272 this.SendPropertyChanging(); 1273 this._CpuArchitecture = value; 1274 this.SendPropertyChanged("CpuArchitecture"); 1275 this.OnCpuArchitectureChanged(); 1276 } 1277 } 1278 } 1279 1280 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OperatingSystem", DbType="VarChar(MAX)", CanBeNull=false)] 1281 public string OperatingSystem 1282 { 1283 get 1284 { 1285 return this._OperatingSystem; 1286 } 1287 set 1288 { 1289 if ((this._OperatingSystem != value)) 1290 { 1291 this.OnOperatingSystemChanging(value); 1292 this.SendPropertyChanging(); 1293 this._OperatingSystem = value; 1294 this.SendPropertyChanged("OperatingSystem"); 1295 this.OnOperatingSystemChanged(); 1248 1296 } 1249 1297 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs
r5155 r5404 15 15 void UpdateJob(DT.Job dto); 16 16 void DeleteJob(Guid id); 17 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave );17 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count); 18 18 #endregion 19 19 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql
r5402 r5404 40 40 ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL; 41 41 ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (newid()) FOR JobId; 42 43 --ALTER TABLE [dbo].[Job] DROP CONSTRAINT [Slave_Job] 44 --ALTER TABLE [dbo].[Job] WITH CHECK ADD CONSTRAINT [Slave_Job] FOREIGN KEY([ResourceId]) 45 --REFERENCES [dbo].[Resource] ([ResourceId]) 46 --ON UPDATE CASCADE 47 --ON DELETE SET NULL 48 --GO 42 49 43 50 ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs
r5402 r5404 76 76 77 77 DT.Slave slave = new DT.Slave() { 78 Name = "Test" 78 Name = "Test", 79 OperatingSystem = Environment.OSVersion.VersionString, 80 Cores = 2, 81 Memory = 1024 79 82 }; 80 83 slave.Id= dao.AddSlave(slave); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs
r5156 r5404 28 28 using HeuristicLab.Services.Hive.Common.ServiceContracts; 29 29 using Microsoft.VisualStudio.TestTools.UnitTesting; 30 using System.Threading; 31 using HeuristicLab.Hive; 32 using HeuristicLab.Services.Hive.Common; 30 33 31 34 namespace HeuristicLab.Services.Hive.Tests { 32 using System.Threading; 33 using HeuristicLab.Hive; 34 using HeuristicLab.Services.Hive.Common; 35 35 36 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; 37 using System.Diagnostics; 36 38 37 39 [TestClass] … … 66 68 Data = PersistenceUtil.Serialize(new MockJob(500, true)) 67 69 }; 70 71 DT.Plugin plugin1 = new DT.Plugin(); 72 plugin1.Name = "Tests.MyPlugin"; 73 plugin1.Version = new Version("1.0.0.0"); 74 plugin1.UserId = Guid.Empty; 75 plugin1.IsLocal = true; 76 plugin1.DateCreated = DateTime.Now; 77 78 DT.PluginData pluginData1 = new DT.PluginData(); 79 pluginData1.PluginId = plugin1.Id; 80 pluginData1.FileName = "Tests.MyPlugin-1.0.dll"; 81 pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 }; 82 83 job.PluginsNeededIds.Add(plugin1.Id); 68 84 69 85 job.Id = service.AddJob(job, jobData, null); … … 77 93 Assert.AreEqual(JobState.Waiting, jobLoaded.JobState); 78 94 Assert.AreEqual(ServiceLocator.Instance.AuthorizationManager.UserId, job.UserId); 95 Assert.IsTrue(job.PluginsNeededIds.SequenceEqual(jobLoaded.PluginsNeededIds)); 79 96 80 97 DT.JobData jobDataLoaded = service.GetJobData(job.Id); … … 101 118 public void TestHeartbeats() { 102 119 var service = GetLocalService(); 120 // check if group already exists and delete 121 var existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "TestGroup"); 122 if (existingSlaveGroup != null) { 123 var slavesToDelete = service.GetSlaves().Where(s => s.ParentResourceId == existingSlaveGroup.Id); 124 foreach (var slave in slavesToDelete) service.DeleteSlave(slave.Id); 125 service.DeleteSlaveGroup(existingSlaveGroup.Id); 126 } 127 103 128 Guid groupId = service.AddSlaveGroup(new SlaveGroup() { Name = "TestGroup", Description = "Used for unit tests" }); 104 129 105 for (int i = 0; i < 2; i++) { 106 Job job = new Job() { 107 CoresNeeded = 1, MemoryNeeded = 0 108 }; 109 JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 110 job.Id = service.AddJob(job, jobData, null); 111 jobs.Add(job); 112 } 113 130 // create slaves 114 131 var slaves = new List<DT.Slave>(); 115 132 for (int i = 0; i < 1; i++) { … … 124 141 FreeMemory = 3000 125 142 }; 143 // check if slave with this name already exists and delete 144 var existingSlave = service.GetSlaves().Where(s => s.Name == slave.Name).SingleOrDefault(); 145 if (existingSlave != null) service.DeleteSlave(existingSlave.Id); 146 126 147 slave.Id = service.AddSlave(slave); 127 148 service.AddResourceToGroup(groupId, slave.Id); … … 129 150 } 130 151 152 // create jobs with different group, they should not be assigned 153 existingSlaveGroup = service.GetSlaveGroups().SingleOrDefault(g => g.Name == "DummyGroup"); 154 if (existingSlaveGroup != null) service.DeleteSlaveGroup(existingSlaveGroup.Id); 155 156 Guid dummyGroupId = service.AddSlaveGroup(new SlaveGroup() { Name = "DummyGroup", Description = "Used for unit tests; jobs from this group shall not be calculated" }); 157 // create dummy jobs 158 var dummyJobs = new List<Job>(); 159 for (int i = 0; i < 2; i++) { 160 Job job = new Job() { 161 CoresNeeded = 1, MemoryNeeded = 0 162 }; 163 JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 164 job.Id = service.AddJob(job, jobData, new List<Guid> { dummyGroupId }); 165 dummyJobs.Add(job); 166 } 167 168 // create jobs 169 for (int i = 0; i < 2; i++) { 170 Job job = new Job() { 171 CoresNeeded = 1, MemoryNeeded = 0 172 }; 173 JobData jobData = new JobData() { Data = PersistenceUtil.Serialize(new MockJob(500, false)) }; 174 job.Id = service.AddJob(job, jobData, new List<Guid> { groupId }); 175 jobs.Add(job); 176 } 177 178 // send heartbeats 131 179 foreach (var slave in slaves) { 132 180 new Thread(new ParameterizedThreadStart(RunSlaveThread)).Start(slave); 133 181 } 134 182 135 // send heartbeats136 183 IEnumerable<LightweightJob> lightweightJobs; 137 184 do { … … 146 193 } 147 194 148 // delete group 195 // delete groups 149 196 service.DeleteSlaveGroup(groupId); 197 service.DeleteSlaveGroup(dummyGroupId); 150 198 151 199 // delete jobs 152 200 foreach (var job in jobs) { 201 service.DeleteJob(job.Id); 202 } 203 204 // delete dummy jobs 205 foreach (var job in dummyJobs) { 153 206 service.DeleteJob(job.Id); 154 207 } … … 161 214 int freeCores = slave.Cores.Value; 162 215 163 var messages = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, FreeMemory = 2423, FreeCores = freeCores, JobProgress = new Dictionary<Guid, TimeSpan>() }); 164 if (messages.Count == 0) 165 return; // no more jobs 166 167 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.AbortJob).Count() == 0); 168 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.SayHello).Count() == 0); 169 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.PauseJob).Count() == 0); 170 171 if (messages.Where(x => x.Message == MessageContainer.MessageType.AquireJob).Count() > 0) { 172 Guid jobId = messages.Where(x => x.Message == MessageContainer.MessageType.AquireJob).SingleOrDefault().JobId; 173 service.AquireJob(jobId); 174 Job job = service.GetJob(jobId); 175 JobData jobData = service.GetJobData(jobId); 176 IJob deserializedJob = PersistenceUtil.Deserialize<IJob>(jobData.Data); 177 deserializedJob.Start(); 178 job.JobState = JobState.Finished; 179 jobs.Where(x => x.Id == jobId).Single().JobState = JobState.Finished; 180 jobData.Data = PersistenceUtil.Serialize(deserializedJob); 181 service.UpdateJob(job, jobData); 216 for (int i = 0; i < 10; i++) { 217 218 var messages = service.Heartbeat(new Heartbeat() { SlaveId = slave.Id, FreeMemory = 2423, FreeCores = freeCores, JobProgress = new Dictionary<Guid, TimeSpan>() }); 219 if (messages.Count == 0) { 220 Debug.WriteLine("No job available"); 221 return; // no more jobs 222 } 223 224 Debug.WriteLine("Messages: {0}", string.Join(", ", messages.Select(m => m.Message))); 225 226 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.AbortJob).Count() == 0); 227 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.SayHello).Count() == 0); 228 Assert.IsTrue(messages.Where(x => x.Message == MessageContainer.MessageType.PauseJob).Count() == 0); 229 230 var calculateJobMessage = messages.Where(x => x.Message == MessageContainer.MessageType.CalculateJob).SingleOrDefault(); 231 if (calculateJobMessage != null) { 232 if (!jobs.Select(j => j.Id).Contains(calculateJobMessage.JobId)) 233 Assert.Fail("Got job which was not assigned to the slavegroup"); 234 235 Debug.WriteLine("Job available, calculating"); 236 Job job = service.GetJob(calculateJobMessage.JobId); 237 238 JobData jobData = service.GetJobData(job.Id); 239 IJob deserializedJob = PersistenceUtil.Deserialize<IJob>(jobData.Data); 240 deserializedJob.Start(); 241 job.JobState = JobState.Finished; 242 jobs.Where(x => x.Id == job.Id).Single().JobState = JobState.Finished; 243 jobData.Data = PersistenceUtil.Serialize(deserializedJob); 244 service.UpdateJob(job, jobData); 245 Debug.WriteLine("finished calculating"); 246 } 182 247 } 183 248 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r5402 r5404 100 100 } 101 101 } 102 103 public Job AquireJob(Guid slaveId) { 104 using (trans.OpenTransaction()) { 105 var slave = dao.GetSlave(slaveId); 106 var availableJobs = dao.GetWaitingJobs(slave); 107 var job = availableJobs.FirstOrDefault(); 108 109 if (job != null) { 110 job.SlaveId = slaveId; 111 job.JobState = JobState.Calculating; 112 } 113 return job; 114 } 115 } 116 102 117 103 public PluginData GetConfigurationFile() { 118 104 using (trans.OpenTransaction()) { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs
r5095 r5404 94 94 /// if not -> set them offline and check if they where calculating a job 95 95 /// </summary> 96 void timer_Tick(object sender, EventArgs e) {96 private void timer_Tick(object sender, EventArgs e) { 97 97 lock (locker) { 98 98 using (trans.OpenTransaction()) { … … 146 146 147 147 if (this.IsAllowedToSendJobs() && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) { 148 var availableJobs = dao.GetWaitingJobs(slave );148 var availableJobs = dao.GetWaitingJobs(slave, 1); 149 149 if (availableJobs.Count() > 0) { 150 actions.Add(new MessageContainer(MessageContainer.MessageType.AquireJob)); 150 var job = availableJobs.First(); 151 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob, job.Id)); 152 AssignJob(slave, job); 151 153 } 152 154 } … … 164 166 } 165 167 return actions; 168 } 169 170 private void AssignJob(Slave slave, Job job) { 171 job.SlaveId = slave.Id; 172 job.JobState = JobState.Calculating; // Todo: Maybe use State = Transferring (?) 173 job.DateCalculated = DateTime.Now; // Todo: use statelog instead 174 dao.UpdateJob(job); 175 dao.UpdateSlave(slave); 166 176 } 167 177
Note: See TracChangeset
for help on using the changeset viewer.