Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5404


Ignore:
Timestamp:
02/01/11 15:51:11 (13 years ago)
Author:
cneumuel
Message:

#1233

  • changed the workflow of aquireing a new job from server.
    • if a job is available for calculation, the slave receives the jobId already with the heartbeats. The job is then exclusively assigned to this slave.
  • extended the metainfo for a slave by OperatingSystem and CpuArchitecture
  • enhanced the way plugin-dependencies are discovered by using the types used by XmlGenerator. Now only mimimum amount of plugins are transferred.
  • selection of waiting jobs now consideres assigned slave-group
  • more unit tests for service
  • added unit tests for experiment manager
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  
    366366      <Name>HeuristicLab.Services.Hive.Common-3.4</Name>
    367367    </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>
    368372  </ItemGroup>
    369373  <ItemGroup>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs

    r5325 r5404  
    5353      //get slave to fetch job
    5454      List<MessageContainer> msg = new List<MessageContainer>();
    55       msg.Add(new MessageContainer(MessageContainer.MessageType.AquireJob));
     55      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
    5656      allMsgs.Add(msg);
    5757
     
    9999      //get slave to fetch job
    100100      List<MessageContainer> msg = new List<MessageContainer>();
    101       msg.Add(new MessageContainer(MessageContainer.MessageType.AquireJob));
     101      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
    102102      allMsgs.Add(msg);
    103103
     
    135135      //get slave to fetch jobs
    136136      List<MessageContainer> msg = new List<MessageContainer>();
    137       msg.Add(new MessageContainer(MessageContainer.MessageType.AquireJob));
     137      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
    138138      allMsgs.Add(msg);
    139139
     
    142142
    143143      msg = new List<MessageContainer>();
    144       msg.Add(new MessageContainer(MessageContainer.MessageType.AquireJob));
     144      msg.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob));
    145145      allMsgs.Add(msg);
    146146
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs

    r5314 r5404  
    2626using HeuristicLab.Services.Hive.Common.DataTransfer;
    2727using HeuristicLab.Clients.Hive.Slave.Properties;
     28using System.Management;
     29using System.Diagnostics;
    2830
    2931
     
    4446
    4547    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   
    4850    /// <summary>
    4951    /// Constructor for the singleton, must recover Guid, Calendar, ...
    5052    /// </summary>
    5153    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;
    6461    }
    6562
     
    7168      //TODO: how to display connectedsince in gui?
    7269      //hardwareInfo.Login = WcfService.Instance.ConnectedSince;
    73       return hardwareInfo;
     70      return slave;
    7471    }
    7572
     
    8178      //Todo: Locking
    8279      StatusCommons st = new StatusCommons();
    83       st.ClientGuid = hardwareInfo.Id;
     80      st.ClientGuid = slave.Id;
    8481
    8582      st.Status = WcfService.Instance.ConnState;
    8683      st.ConnectedSince = WcfService.Instance.ConnectedSince;
    8784
    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;
    9087
    9188      st.JobsAborted = SlaveStatusInfo.JobsAborted;
     
    128125    }
    129126
     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    }
    130147  }
    131148}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs

    r5402 r5404  
    153153
    154154          //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);
    157157            //TODO: handle in own thread!!
    158158            JobData jobData = wcfService.GetJobData(myJob.Id);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs

    r5375 r5404  
    9393                SlaveId = info.Id, /*Settings.Default.Guid*/
    9494                FreeCores = info.Cores.HasValue ? info.Cores.Value - ConfigManager.Instance.GetUsedCores() : 0,
    95                 FreeMemory = GetFreeMemory(),
     95                FreeMemory = ConfigManager.GetFreeMemory(),
    9696                JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs()
    9797              };
     
    129129    }
    130130    #endregion
    131 
    132     #region Helpers
    133     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     #endregion
    139131  }
    140132}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj

    r5402 r5404  
    8888    <Reference Include="System" />
    8989    <Reference Include="System.Core" />
     90    <Reference Include="System.Management" />
    9091    <Reference Include="System.Runtime.Serialization" />
    9192    <Reference Include="System.ServiceModel" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs

    r5375 r5404  
    113113
    114114    /// <summary>
    115     /// Aquire a Job from the Server, return the Job
    116     /// </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);
    121121          return job;
    122122        }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveExperimentClient.cs

    r5402 r5404  
    114114    }
    115115
    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; }
    120126    }
    121127
     
    247253
    248254          this.progress.Status = "Uploading plugins...";
    249           this.PluginsNeededIds = GetPluginsNeededIds(this.useLocalPlugins);
     255          this.OnlinePlugins = service.Obj.GetPlugins();
     256          this.AlreadyUploadedPlugins = new List<Plugin>();
    250257
    251258          this.progress.Status = "Uploading jobs...";
     
    269276        IsProgressing = false;
    270277      }
    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; reuse
    290             pluginsNeededIds.Add(found.Id);
    291           } else {
    292             // upload the plugin
    293             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;
    307278    }
    308279
     
    319290      this.progress.Status = string.Format("Serializing job {0} of {1}", jobCount, totalJobCount);
    320291      JobData jobData;
     292      List<IPluginDescription> plugins;
    321293      if (hiveJob.OptimizerJob.ComputeInParallel &&
    322294        (hiveJob.OptimizerJob.Optimizer is Optimization.Experiment || hiveJob.OptimizerJob.Optimizer is Optimization.BatchRun)) {
    323295        hiveJob.Job.JobState = JobState.WaitingForChildJobs;
    324296        hiveJob.OptimizerJob.CollectChildJobs = false; // don't collect child-jobs on slaves
    325         jobData = hiveJob.GetAsJobData(true);
     297        jobData = hiveJob.GetAsJobData(true, out plugins);
    326298      } 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);
    331303
    332304      this.progress.Status = string.Format("Uploading job {0} of {1} ({2} kb)", jobCount, totalJobCount, jobData.Data.Count() / 1024);
     
    347319      }
    348320    }
    349 
     321   
    350322    /// <summary>
    351323    /// Converts a string which can contain Ids separated by ';' to a enumerable
     
    369341    #endregion
    370342
    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     }
    386343
    387344    #region HiveJob Events
     
    483440
    484441    #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
    485459    private void RegisterResultPollingEvents() {
    486460      jobResultPoller.ExceptionOccured += new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured);
     
    497471      jobResultPoller.IsPollingChanged -= new EventHandler(jobResultPoller_IsPollingChanged);
    498472    }
    499     void jobResultPoller_IsPollingChanged(object sender, EventArgs e) {
     473    private void jobResultPoller_IsPollingChanged(object sender, EventArgs e) {
    500474      this.IsPollingResults = jobResultPoller.IsPolling;
    501475    }
    502     void jobResultPoller_PollingFinished(object sender, EventArgs e) {
     476    private void jobResultPoller_PollingFinished(object sender, EventArgs e) {
    503477      LogMessage("Polling results finished");
    504478    }
    505     void jobResultPoller_PollingStarted(object sender, EventArgs e) {
     479    private void jobResultPoller_PollingStarted(object sender, EventArgs e) {
    506480      LogMessage("Polling results started");
    507481    }
    508     void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) {
     482    private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) {
    509483      foreach (LightweightJob lightweightJob in e.Value) {
    510484        HiveJob hj = hiveJob.GetHiveJobByJobId(lightweightJob.Id);
     
    543517    }
    544518
    545     void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) {
     519    private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) {
    546520      OnExceptionOccured(e.Value);
    547521    }
     
    578552    #endregion
    579553
     554    #region Job Loading
    580555    /// <summary>
    581556    /// Downloads the root job from hive and sets the experiment, rootJob and rootJobItem
     
    674649      }
    675650    }
    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
    677737  }
    678738}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobClient.cs

    r5402 r5404  
    3232using HeuristicLab.PluginInfrastructure;
    3333using HeuristicLab.Services.Hive.Common.DataTransfer;
     34using HeuristicLab.PluginInfrastructure.Manager;
    3435
    3536namespace HeuristicLab.Clients.Hive {
     
    425426    ///   if true the Child-Optimizers will not be serialized (if the job contains an Experiment)
    426427    /// </param>
    427     public JobData GetAsJobData(bool withoutChildOptimizers) {
     428    public JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) {
     429      plugins = new List<IPluginDescription>();
    428430      if (this.optimizerJob == null || this.optimizerJob.Optimizer == null)
    429431        return null;
    430432
     433      IEnumerable<Type> usedTypes;
    431434      byte[] jobByteArray;
    432435      if (withoutChildOptimizers && this.OptimizerJob.Optimizer is Optimization.Experiment) {
    433436        OptimizerJob clonedJob = (OptimizerJob)this.OptimizerJob.Clone(); // use a cloned job, so that the childHiveJob don't get confused
    434437        clonedJob.OptimizerAsExperiment.Optimizers.Clear();
    435         jobByteArray = PersistenceUtil.Serialize(clonedJob);
     438        jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes);
    436439      } else if (withoutChildOptimizers && this.OptimizerJob.Optimizer is Optimization.BatchRun) {
    437440        OptimizerJob clonedJob = (OptimizerJob)this.OptimizerJob.Clone();
    438441        clonedJob.OptimizerAsBatchRun.Optimizer = null;
    439         jobByteArray = PersistenceUtil.Serialize(clonedJob);
     442        jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes);
    440443      } else if (this.OptimizerJob.Optimizer is IAlgorithm) {
    441444        ((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);
    443446      } else {
    444         jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob);
     447        jobByteArray = PersistenceUtil.Serialize(this.OptimizerJob, out usedTypes);
    445448      }
    446449
     
    450453      };
    451454
     455      CollectDeclaringPlugins(plugins, usedTypes);
     456
    452457      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      }
    453478    }
    454479
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/PersistenceUtil.cs

    r5156 r5404  
    2222using System.IO;
    2323using HeuristicLab.Persistence.Default.Xml;
     24using System.Collections.Generic;
     25using HeuristicLab.PluginInfrastructure;
     26using System;
     27using HeuristicLab.Persistence.Core;
    2428
    2529namespace HeuristicLab.Clients.Hive {
    2630  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
    2739    public static byte[] Serialize(object obj) {
    2840      MemoryStream memStream = new MemoryStream();
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs

    r5375 r5404  
    3939
    4040    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");
    4342    }
    4443  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive 3.4.sln

    r5402 r5404  
    3131Project("{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}"
    3232EndProject
    33 Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Hive-3.4", "HeuristicLab.Services.Hive.Web\Hive-3.4\", "{0CA6706D-A569-45DE-A85C-4158891CC1BC}"
     33Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Hive-3.4", "HeuristicLab.Services.Hive.Web\Hive-3.4", "{0CA6706D-A569-45DE-A85C-4158891CC1BC}"
    3434  ProjectSection(WebsiteProperties) = preProject
    3535    TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
     
    6464EndProject
    6565Project("{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}"
     66EndProject
     67Project("{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}"
    6668EndProject
    6769Global
     
    241243    {7C4B1DE4-FC9A-4448-BCF8-3CB3FA3CB8FA}.Release|x86.ActiveCfg = Release|x86
    242244    {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
    243255  EndGlobalSection
    244256  GlobalSection(SolutionProperties) = preSolution
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/DataTransfer/Slave.cs

    r5106 r5404  
    2525
    2626namespace HeuristicLab.Services.Hive.Common.DataTransfer {
     27  public enum CpuArchitecture {
     28    x86, x64
     29  }
     30
    2731  [DataContract]
    2832  [Serializable]
     
    3539    public int? CpuSpeed { get; set; } // MHz
    3640    [DataMember]
     41    public CpuArchitecture CpuArchitecture { get; set; }
     42    [DataMember]
    3743    public int? Memory { get; set; } // MB
    3844    [DataMember]
    3945    public int? FreeMemory { get; set; } // MB
     46    [DataMember]
     47    public string OperatingSystem { get; set; }
    4048    [DataMember]
    4149    public SlaveState SlaveState { get; set; }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Common/3.4/MessageContainer.cs

    r5314 r5404  
    3535    public enum MessageType {
    3636      // *** 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
    3838      StopJob,   // slave should stop the job and submit results
    3939      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  
    4040    [OperationContract]
    4141    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 job
    44     Job AquireJob(Guid slaveId);
    4542
    4643    [OperationContract]
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs

    r5402 r5404  
    143143    public static DT.Slave ToDto(Slave source) {
    144144      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 };
    146146    }
    147147    public static Slave ToEntity(DT.Slave source) {
     
    152152    public static void ToEntity(DT.Slave source, Slave target) {
    153153      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;
    155155      }
    156156    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj

    r5402 r5404  
    103103    <Compile Include="Convert.cs" />
    104104    <None Include="HeuristicLabServicesHiveDataAccessPlugin.cs.frame" />
     105    <Compile Include="Exceptions\DaoException.cs" />
    105106    <Compile Include="HeuristicLabServicesHiveDataAccessPlugin.cs" />
    106107    <Compile Include="HiveDao.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs

    r5402 r5404  
    8282    }
    8383
    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()) {
    8786        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
    9595                    orderby ar.Job.Priority descending
    9696                    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();
    109115        return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority);
    110116      }
     
    350356      using (var db = CreateContext()) {
    351357        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        }
    353364        db.SubmitChanges();
    354365      }
     
    408419        return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray();
    409420      }
     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);
    410438    }
    411439    #endregion
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml

    r5402 r5404  
    4949        <Column Name="FreeMemory" Type="System.Int32" DbType="Int" CanBeNull="true" />
    5050        <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" />
    5153        <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" />
    5254      </Type>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout

    r5402 r5404  
    4545      </nestedChildShapes>
    4646    </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">
    4848      <DataClassMoniker Name="/HiveDataContext/Slave" />
    4949      <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" />
    5151      </nestedChildShapes>
    5252    </classShape>
     
    6969      </nodes>
    7070    </inheritanceConnector>
    71     <associationConnector edgePoints="[(12.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">
    7272      <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedResource" />
    7373      <nodes>
     
    9797      </nodes>
    9898    </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">
    100100      <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" />
    101101      <nodes>
     
    130130      </nestedChildShapes>
    131131    </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">
    133133      <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_PluginData" />
    134134      <nodes>
     
    144144      </nodes>
    145145    </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">
    147147      <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" />
    148148      <nodes>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs

    r5402 r5404  
    33// <auto-generated>
    44//     This code was generated by a tool.
    5 //     Runtime Version:4.0.30319.1
     5//     Runtime Version:4.0.30319.208
    66//
    77//     Changes to this file may cause incorrect behavior and will be lost if
     
    10601060    private bool _IsAllowedToCalculate;
    10611061   
     1062    private global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture _CpuArchitecture;
     1063   
     1064    private string _OperatingSystem;
     1065   
    10621066    private EntitySet<Job> _Jobs;
    10631067   
     
    10821086    partial void OnIsAllowedToCalculateChanging(bool value);
    10831087    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();
    10841092    #endregion
    10851093   
     
    12461254          this.SendPropertyChanged("IsAllowedToCalculate");
    12471255          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();
    12481296        }
    12491297      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs

    r5155 r5404  
    1515    void UpdateJob(DT.Job dto);
    1616    void DeleteJob(Guid id);
    17     IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave);
     17    IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count);
    1818    #endregion
    1919
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql

    r5402 r5404  
    4040ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
    4141ALTER 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
    4249
    4350ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs

    r5402 r5404  
    7676
    7777      DT.Slave slave = new DT.Slave() {
    78         Name = "Test"
     78        Name = "Test",
     79        OperatingSystem = Environment.OSVersion.VersionString,
     80        Cores = 2,
     81        Memory = 1024
    7982      };
    8083      slave.Id= dao.AddSlave(slave);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs

    r5156 r5404  
    2828using HeuristicLab.Services.Hive.Common.ServiceContracts;
    2929using Microsoft.VisualStudio.TestTools.UnitTesting;
     30using System.Threading;
     31using HeuristicLab.Hive;
     32using HeuristicLab.Services.Hive.Common;
    3033
    3134namespace HeuristicLab.Services.Hive.Tests {
    32   using System.Threading;
    33   using HeuristicLab.Hive;
    34   using HeuristicLab.Services.Hive.Common;
     35
    3536  using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
     37  using System.Diagnostics;
    3638
    3739  [TestClass]
     
    6668        Data = PersistenceUtil.Serialize(new MockJob(500, true))
    6769      };
     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);
    6884
    6985      job.Id = service.AddJob(job, jobData, null);
     
    7793      Assert.AreEqual(JobState.Waiting, jobLoaded.JobState);
    7894      Assert.AreEqual(ServiceLocator.Instance.AuthorizationManager.UserId, job.UserId);
     95      Assert.IsTrue(job.PluginsNeededIds.SequenceEqual(jobLoaded.PluginsNeededIds));
    7996
    8097      DT.JobData jobDataLoaded = service.GetJobData(job.Id);
     
    101118    public void TestHeartbeats() {
    102119      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
    103128      Guid groupId = service.AddSlaveGroup(new SlaveGroup() { Name = "TestGroup", Description = "Used for unit tests" });
    104129
    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
    114131      var slaves = new List<DT.Slave>();
    115132      for (int i = 0; i < 1; i++) {
     
    124141          FreeMemory = 3000
    125142        };
     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
    126147        slave.Id = service.AddSlave(slave);
    127148        service.AddResourceToGroup(groupId, slave.Id);
     
    129150      }
    130151
     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
    131179      foreach (var slave in slaves) {
    132180        new Thread(new ParameterizedThreadStart(RunSlaveThread)).Start(slave);
    133181      }
    134182
    135       // send heartbeats
    136183      IEnumerable<LightweightJob> lightweightJobs;
    137184      do {
     
    146193      }
    147194
    148       // delete group
     195      // delete groups
    149196      service.DeleteSlaveGroup(groupId);
     197      service.DeleteSlaveGroup(dummyGroupId);
    150198
    151199      // delete jobs
    152200      foreach (var job in jobs) {
     201        service.DeleteJob(job.Id);
     202      }
     203
     204      // delete dummy jobs
     205      foreach (var job in dummyJobs) {
    153206        service.DeleteJob(job.Id);
    154207      }
     
    161214        int freeCores = slave.Cores.Value;
    162215
    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          }
    182247        }
    183248      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs

    r5402 r5404  
    100100      }
    101101    }
    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   
    117103    public PluginData GetConfigurationFile() {
    118104      using (trans.OpenTransaction()) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs

    r5095 r5404  
    9494    /// if not -> set them offline and check if they where calculating a job
    9595    /// </summary>
    96     void timer_Tick(object sender, EventArgs e) {
     96    private void timer_Tick(object sender, EventArgs e) {
    9797      lock (locker) {
    9898        using (trans.OpenTransaction()) {
     
    146146
    147147        if (this.IsAllowedToSendJobs() && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) {
    148           var availableJobs = dao.GetWaitingJobs(slave);
     148          var availableJobs = dao.GetWaitingJobs(slave, 1);
    149149          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);
    151153          }
    152154        }
     
    164166      }
    165167      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);
    166176    }
    167177
Note: See TracChangeset for help on using the changeset viewer.