Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6357


Ignore:
Timestamp:
06/05/11 22:35:40 (13 years ago)
Author:
cneumuel
Message:

#1233

  • refactoring of slave core
  • created JobManager, which is responsible for managing jobs without knowing anything about the service. this class is easier testable than slave core
  • lots of cleanup
  • created console test project for slave
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
24 added
7 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.LifecycleClient/app.config

    r5593 r6357  
    3333    </services>
    3434    <client>
    35       <endpoint address="http://localhost/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="HeuristicLab.Services.Hive.Common.ServiceContracts.IHiveService" name="wsHttpBinding_IHiveService">
     35      <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="HeuristicLab.Services.Hive.Common.ServiceContracts.IHiveService" name="wsHttpBinding_IHiveService">
    3636        <identity>
    37           <certificate encodedValue="AwAAAAEAAAAUAAAAfEKvcVixnJay+q4hCPFuO0JL5TQgAAAAAQAAAPIBAAAwggHuMIIBW6ADAgECAhCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQAwFDESMBAGA1UEAxMJbG9jYWxob3N0MB4XDTEwMTAxOTEwNTMxNVoXDTM5MTIzMTIzNTk1OVowFDESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXwC5TGcAffd/0oAWHtm0s6YXVXEgXgb1AYmBkkkhkKIFJG/e/Z0KSYbJepmSJD44W3oOAVm+x1DAsZxU79HahDYgWCuHLMm1TLpwSmYOQ0kV3pGHWHhiWV7h7oGLds/eqZ2EOpaNGryfEPnrA4VmxY91vV5/2BTeVSWG6F8lRKQIDAQABo0kwRzBFBgNVHQEEPjA8gBAR7kBnMRHO5gzThEqda0wWoRYwFDESMBAGA1UEAxMJbG9jYWxob3N0ghCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQADgYEAoPwEG4QTDXhlxERNDfsZmM2IhEpV42ppz1kEah2oYKDa/ElIMVtvqLv6flVtg18ENN/mEJWiHZ3NyP3qr2Pip+sh+/2WBiSbOaukES/CM7OJn9kJCImH7M/xqM8pxqY8IfgM6iBVrVj9uHqj3j2BBck+cYY8fKyh3CFifMIp6ac="/>
     37          <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ=="/>
    3838        </identity>
    3939      </endpoint>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/SlaveCommListener.cs

    r6101 r6357  
    2121
    2222using System;
     23using System.IO;
    2324using System.ServiceModel;
    2425using System.Threading;
     
    3233  [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    3334  public class SlaveCommListener : ISlaveCommunicationCallbacks, IDisposable {
    34     ISlaveCommunication pipeProxy;
    35     DuplexChannelFactory<ISlaveCommunication> pipeFactory;
     35    private ISlaveCommunication pipeProxy;
     36    private DuplexChannelFactory<ISlaveCommunication> pipeFactory;
     37    private StreamWriter debugOutput;
    3638
    3739    public void Open() {
    3840      pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
     41      debugOutput = new StreamWriter("slave-debug.txt");
     42      debugOutput.AutoFlush = true;
    3943
    4044      while (!ReconnectToSlaveCore()) {
     
    4953        return true;
    5054      }
    51       catch (Exception e) {
     55      catch (Exception) {
    5256        OnMessageLogged("Couldn't connect to Slave Core. Waiting for the Core to start.");
    5357        return false;
     
    6771        pipeFactory.Abort();
    6872      }
     73      debugOutput.Close();
    6974    }
    7075
    71     public void OnStatusChanged(SlaveCore.StatusCommons status) {
    72       System.Console.WriteLine("SlaveCommListener: " + status);
     76    public void OnStatusChanged(StatusCommons status) {
     77      string msg = string.Format( "{0}: {1}", DateTime.Now.ToString("HH:mm:ss"), status);
     78      Console.WriteLine(msg);
     79      debugOutput.WriteLine(msg);
    7380    }
    7481
    7582    public void OnMessageLogged(string message) {
    76       System.Console.WriteLine("SlaveCommListener: " + message);
     83      string msg = string.Format("{0}: {1}", DateTime.Now.ToString("HH:mm:ss"), message);
     84      Console.WriteLine(msg);
     85      debugOutput.WriteLine(msg);
    7786    }
    7887
    7988    public void OnShutdown() {
    80       System.Console.WriteLine("SlaveCommListner: Slave quit");
     89      Console.WriteLine("SlaveCommListner: Slave quit");
    8190    }
    8291
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/app.config

    r5402 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3    
     3  <runtime>
     4    <gcServer enabled="true" />
     5  </runtime>
     6 
    47  <system.serviceModel>
    58    <bindings>
    69      <wsHttpBinding>
    7         <binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    8           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
     10        <binding name="wsHttpBinding_Hive" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
     11          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/>
    912          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
    1013          <security mode="Message">
     
    1720   
    1821    <services>
    19       <service name="HeuristicLab.Clients.Hive.Slave.SlaveCommunicationService">       
    20         <endpoint address="net.pipe://localhost/HeuristicLabSlaveCom" binding="netNamedPipeBinding" contract="HeuristicLab.Clients.Hive.Slave.ServiceContracts.ISlaveCommunication"/>
     22      <service name="HeuristicLab.Clients.Hive.SlaveCore.SlaveCommunicationService">       
     23        <endpoint address="net.pipe://localhost/HeuristicLabSlaveCom" binding="netNamedPipeBinding" contract="HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts.ISlaveCommunication"/>
    2124      </service>
    2225    </services>
    23 
     26 
    2427   <client>
    25      <!--http://localhost:9000/Hive-3.4-->
    26     <endpoint address="http://localhost/Hive-3.4/HiveService.svc"
     28     <endpoint name="SlaveCommunicationServiceEndpoint" address="net.pipe://localhost/HeuristicLabSlaveCom" binding="netNamedPipeBinding" contract="HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts.ISlaveCommunication"/>
     29    <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc"
    2730              binding="wsHttpBinding"
    28               bindingConfiguration="wsHttpBinding"
    29               contract="HeuristicLab.Services.Hive.Common.ServiceContracts.IHiveService"
     31              bindingConfiguration="wsHttpBinding_Hive"
     32              contract="HeuristicLab.Clients.Hive.IHiveService"
    3033              name="wsHttpBinding_IHiveService">
    31               <identity>
    32                 <certificate encodedValue="AwAAAAEAAAAUAAAAiQt8DnyaI8rYHhLNyW62i58+eG8gAAAAAQAAAPIBAAAwggHuMIIBW6ADAgECAhAFNFYz6Srdmk3PZJ/mka5sMAkGBSsOAwIdBQAwFDESMBAGA1UEAxMJbG9jYWxob3N0MB4XDTEwMTIwNjE0MTc0M1oXDTM5MTIzMTIzNTk1OVowFDESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCueTMWJzOZ1IBacG40aWdr3qDWijEO4VwhgtNr+WNFsRG+qW2rTZZFtaC0U028aj3MX13mr+pzpcPJMes2rr38PuxhN6BhdzgRfyEy/eHk4iKqZztuJSXgNAyfyjhovTchLitT2lilddTRFj2PlLYv+PUu+QhQNTm2iW4UDljS9wIDAQABo0kwRzBFBgNVHQEEPjA8gBBeipmIklE3kPz7i+AdKqAgoRYwFDESMBAGA1UEAxMJbG9jYWxob3N0ghAFNFYz6Srdmk3PZJ/mka5sMAkGBSsOAwIdBQADgYEAGnxEaFT8QKKk1DtJ8/+TOBxSo0UkBlNiTY0HKkA3w/2DOPZKybhslm8gqJic8ZPsk5YgEibrdQqB0AnNG983RAlFqgGvsAbQAMXTDJ5GoTgHaxk/T+7a7Sk4xJALUL/vWuPGbA354RVoKA4gV3gJzU+Fj3/fLACf0+D/nR9B5nw=" />
    33               </identity>
    34 
     34      <identity>
     35        <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ==" />
     36      </identity>
    3537    </endpoint>
    3638   </client>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/app_ascheibe.config

    r6167 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3    
     3  <runtime>
     4    <gcServer enabled="true" />
     5  </runtime>
     6 
    47  <system.serviceModel>
    58    <bindings>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/app_f005pc.config

    r6167 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3    
     3  <runtime>
     4    <gcServer enabled="true" />
     5  </runtime>
     6 
    47  <system.serviceModel>
    58    <bindings>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/app_services.config

    r6167 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3    
     3  <runtime>
     4    <gcServer enabled="true" />
     5  </runtime>
     6 
    47  <system.serviceModel>
    58    <bindings>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockHiveService.cs

    r6006 r6357  
    8787
    8888    private static List<Plugin> ReadPluginsFromServerCache() {
    89       PluginManager pm = new PluginManager(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginCacheServer"));
     89      var pm = new HeuristicLab.PluginInfrastructure.Manager.PluginManager(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginCacheServer"));
    9090      pm.DiscoverAndCheckPlugins();
    9191      pDescs = pm.Plugins.ToList();
     
    376376    }
    377377    #endregion
     378
     379
     380    public List<Job> GetJobsByResourceId(Guid resourceId) {
     381      throw new NotImplementedException();
     382    }
    378383  }
    379384}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs

    r6101 r6357  
    3434    [ClassInitialize]
    3535    public static void MyClassInitialize(TestContext testContext) {
    36       PluginLoader.pluginAssemblies.Any();
    3736      ServiceLocator.Instance = new MockServiceLocator();
    3837      /* listener = new SlaveCommListener();
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs

    r6263 r6357  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Diagnostics;
    2524using System.ServiceModel;
     
    2928using HeuristicLab.Common;
    3029using HeuristicLab.Core;
     30using HeuristicLab.Hive;
    3131
    3232
     
    3737  /// </summary>
    3838  public class Core : MarshalByRefObject {
    39     public static ILog Log { get; set; }
    40     public static bool AbortRequested { get; set; }
    41 
    4239    private static HeartbeatManager heartbeatManager;
    4340    public static HeartbeatManager HeartbeatManager {
     
    4542    }
    4643
     44    private Semaphore waitShutdownSem = new Semaphore(0, 1);
     45    private bool abortRequested;
    4746    private ISlaveCommunication clientCom;
    4847    private ServiceHost slaveComm;
    49     private Semaphore waitShutdownSem = new Semaphore(0, 1);
    50     private Dictionary<Guid, SlaveJob> slaveJobs = new Dictionary<Guid, SlaveJob>();
    5148    private WcfService wcfService;
     49    private JobManager jobManager;
     50    private ConfigManager configManager;
     51    private PluginManager pluginManager;
    5252
    5353    public EventLog ServiceEventLog { get; set; }
    54     public Dictionary<Guid, SlaveJob> SlaveJobs { get { return slaveJobs; } }
    55 
    56     public Core() { }
     54
     55    public Core() {
     56      var log = new ThreadSafeLog(new Log());
     57      this.pluginManager = new PluginManager(WcfService.Instance, log);
     58      this.jobManager = new JobManager(pluginManager, log);
     59      log.MessageAdded += new EventHandler<EventArgs<string>>(log_MessageAdded);
     60
     61      RegisterJobManagerEvents();
     62
     63      this.configManager = new ConfigManager(jobManager);
     64      ConfigManager.Instance = this.configManager;
     65    }
    5766
    5867    /// <summary>
     
    6069    /// </summary>
    6170    public void Start() {
    62       AbortRequested = false;
    63 
    64       try {
    65         ConfigManager manager = ConfigManager.Instance;
    66         manager.Core = this;
     71      abortRequested = false;
     72
     73      try {
     74        //manager.Core = this;
    6775
    6876        //start the client communication service (pipe between slave and slave gui)
     
    7280
    7381        // delete all left over job directories
    74         PluginCache.Instance.CleanPluginTemp();
     82        pluginManager.CleanPluginTemp();
    7583        clientCom.LogMessage("Hive Slave started");
    7684
     
    110118    private void DispatchMessageQueue() {
    111119      MessageQueue queue = MessageQueue.GetInstance();
    112       while (!AbortRequested) {
     120      while (!abortRequested) {
    113121        MessageContainer container = queue.GetMessage();
    114122        DetermineAction(container);
    115         if (!AbortRequested) {
    116           clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
     123        if (!abortRequested) {
     124          clientCom.StatusChanged(configManager.GetStatusForClientConsole());
    117125        }
    118126      }
     
    150158        switch (container.Message) {
    151159          case MessageContainer.MessageType.CalculateJob:
    152             Task.Factory.StartNew(HandleCalculateJob, container.JobId)
    153             .ContinueWith((t) => {
    154               // handle exception of task
    155               clientCom.LogMessage(t.Exception.ToString());
    156               if (t.Exception.GetType() != typeof(JobNotFoundException)) {
    157                 wcfService.UpdateJobState(container.JobId, JobState.Waiting, t.Exception.ToString());
    158                 SlaveStatusInfo.IncrementJobsFailed();
    159               }
    160             }, TaskContinuationOptions.OnlyOnFaulted);
     160            CalculateJobAsync(container.JobId);
     161            break;
     162          case MessageContainer.MessageType.AbortJob:
     163            AbortJobAsync(container.JobId);
     164            break;
     165          case MessageContainer.MessageType.StopJob:
     166            StopJobAsync(container.JobId);
     167            break;
     168          case MessageContainer.MessageType.PauseJob:
     169            PauseJobAsync(container.JobId);
     170            break;
     171          case MessageContainer.MessageType.StopAll:
     172            DoStopAll();
     173            break;
     174          case MessageContainer.MessageType.PauseAll:
     175            DoPauseAll();
     176            break;
     177          case MessageContainer.MessageType.AbortAll:
     178            DoAbortAll();
    161179            break;
    162180          case MessageContainer.MessageType.ShutdownSlave:
    163181            ShutdownCore();
    164182            break;
    165           case MessageContainer.MessageType.StopAll:
    166             DoStopAll();
    167             break;
    168           case MessageContainer.MessageType.PauseAll:
    169             DoPauseAll();
    170             break;
    171           case MessageContainer.MessageType.AbortAll:
    172             DoAbortAll();
    173             break;
    174           case MessageContainer.MessageType.AbortJob:
    175             SlaveStatusInfo.IncrementJobsAborted(); //TODO: move to a sane place
    176 
    177             Task.Factory.StartNew(HandleAbortJob, container.JobId)
    178              .ContinueWith((t) => {
    179                clientCom.LogMessage(t.Exception.ToString());
    180              }, TaskContinuationOptions.OnlyOnFaulted);
    181             break;
    182           case MessageContainer.MessageType.StopJob:
    183             Task.Factory.StartNew(HandleStopJob, container.JobId)
    184              .ContinueWith((t) => {
    185                clientCom.LogMessage(t.Exception.ToString());
    186              }, TaskContinuationOptions.OnlyOnFaulted);
    187             break;
    188           case MessageContainer.MessageType.PauseJob:
    189             Task.Factory.StartNew(HandlePauseJob, container.JobId)
    190              .ContinueWith((t) => {
    191                clientCom.LogMessage(t.Exception.ToString());
    192              }, TaskContinuationOptions.OnlyOnFaulted);
    193             break;
    194183          case MessageContainer.MessageType.Restart:
    195184            DoStartSlave();
     
    199188            break;
    200189          case MessageContainer.MessageType.SayHello:
    201             wcfService.Connect(ConfigManager.Instance.GetClientInfo());
     190            wcfService.Connect(configManager.GetClientInfo());
    202191            break;
    203192        }
     
    207196    }
    208197
     198    private void CalculateJobAsync(Guid jobId) {
     199      Task.Factory.StartNew(HandleCalculateJob, jobId)
     200      .ContinueWith((t) => {
     201        SlaveStatusInfo.IncrementExceptionOccured();
     202        clientCom.LogMessage(t.Exception.ToString());
     203      }, TaskContinuationOptions.OnlyOnFaulted);
     204    }
     205
     206    private void StopJobAsync(Guid jobId) {
     207      Task.Factory.StartNew(HandleStopJob, jobId)
     208       .ContinueWith((t) => {
     209         SlaveStatusInfo.IncrementExceptionOccured();
     210         clientCom.LogMessage(t.Exception.ToString());
     211       }, TaskContinuationOptions.OnlyOnFaulted);
     212    }
     213
     214    private void PauseJobAsync(Guid jobId) {
     215      Task.Factory.StartNew(HandlePauseJob, jobId)
     216       .ContinueWith((t) => {
     217         SlaveStatusInfo.IncrementExceptionOccured();
     218         clientCom.LogMessage(t.Exception.ToString());
     219       }, TaskContinuationOptions.OnlyOnFaulted);
     220    }
     221
     222    private void AbortJobAsync(Guid jobId) {
     223      Task.Factory.StartNew(HandleAbortJob, jobId)
     224       .ContinueWith((t) => {
     225         SlaveStatusInfo.IncrementExceptionOccured();
     226         clientCom.LogMessage(t.Exception.ToString());
     227       }, TaskContinuationOptions.OnlyOnFaulted);
     228    }
     229
    209230    private void HandleCalculateJob(object jobIdObj) {
    210231      Guid jobId = (Guid)jobIdObj;
    211       SlaveJob newJob = new SlaveJob(this);
    212       bool start = true;
    213 
    214       lock (slaveJobs) {
    215         if (ConfigManager.Instance.GetFreeCores() < 1) {
    216           wcfService.UpdateJobState(jobId, JobState.Waiting, "Slave set status waiting because no cores were available");
    217           clientCom.LogMessage(string.Format("Setting job with id {0} to waiting, all cores are used", jobId));
    218           start = false;
    219         } else {
    220           if (slaveJobs.ContainsKey(jobId)) {
    221             start = false;
    222             clientCom.LogMessage(string.Format("Job with id {0} already exists. Start aborted.", jobId));
    223           } else {
    224             slaveJobs.Add(jobId, newJob);
    225             newJob.PrepareJob(jobId);
    226           }
    227         }
    228       }
    229 
    230       if (start) {
    231         newJob.CalculateJob();
     232      Job job = null;
     233      bool usedCoresIncremented = false;
     234      try {
     235        job = wcfService.GetJob(jobId);
     236        if (job == null) throw new JobNotFoundException(jobId);
     237        if (ConfigManager.Instance.GetFreeCores() < job.CoresNeeded) throw new OutOfCoresException();
     238        if (ConfigManager.GetFreeMemory() < job.MemoryNeeded) throw new OutOfMemoryException();
     239        SlaveStatusInfo.IncrementUsedCores(job.CoresNeeded); usedCoresIncremented = true;
     240        JobData jobData = wcfService.GetJobData(jobId);
     241        if (jobData == null) throw new JobDataNotFoundException(jobId);
     242        job = wcfService.UpdateJobState(jobId, JobState.Calculating, null);
     243        if (job == null) throw new JobNotFoundException(jobId);
     244        jobManager.StartJobAsync(job, jobData);
     245      }
     246      catch (JobNotFoundException) {
     247        if (usedCoresIncremented) SlaveStatusInfo.DecrementUsedCores(job.CoresNeeded);
     248        throw;
     249      }
     250      catch (JobDataNotFoundException) {
     251        SlaveStatusInfo.DecrementUsedCores(job.CoresNeeded);
     252        throw;
     253      }
     254      catch (JobAlreadyRunningException) {
     255        SlaveStatusInfo.DecrementUsedCores(job.CoresNeeded);
     256        throw;
     257      }
     258      catch (OutOfCoresException) {
     259        wcfService.UpdateJobState(jobId, JobState.Waiting, "No more cores available");
     260        throw;
     261      }
     262      catch (OutOfMemoryException) {
     263        wcfService.UpdateJobState(jobId, JobState.Waiting, "No more memory available");
     264        throw;
     265      }
     266      catch (Exception) {
     267        if (usedCoresIncremented) SlaveStatusInfo.DecrementUsedCores(job.CoresNeeded);
     268        throw;
     269      }
     270    }
     271
     272    private void HandleStopJob(object jobIdObj) {
     273      Guid jobId = (Guid)jobIdObj;
     274      try {
     275        Job job = wcfService.GetJob(jobId);
     276        if (job == null) throw new JobNotFoundException(jobId);
     277        jobManager.StopJobAsync(jobId);
     278      }
     279      catch (JobNotFoundException) {
     280        throw;
     281      }
     282      catch (JobNotRunningException) {
     283        throw;
     284      }
     285      catch (AppDomainNotCreatedException) {
     286        throw;
     287      }
     288    }
     289
     290    private void HandlePauseJob(object jobIdObj) {
     291      Guid jobId = (Guid)jobIdObj;
     292      try {
     293        Job job = wcfService.GetJob(jobId);
     294        if (job == null) throw new JobNotFoundException(jobId);
     295        jobManager.PauseJobAsync(jobId);
     296      }
     297      catch (JobNotFoundException) {
     298        throw;
     299      }
     300      catch (JobNotRunningException) {
     301        throw;
    232302      }
    233303    }
     
    235305    private void HandleAbortJob(object jobIdObj) {
    236306      Guid jobId = (Guid)jobIdObj;
    237       bool abort = true;
    238       SlaveJob sj = null;
    239 
    240       lock (slaveJobs) {
    241         if (!slaveJobs.ContainsKey(jobId)) {
    242           clientCom.LogMessage(string.Format("Job with id {0} doesn't exist. Abort aborted.", jobId));
    243           abort = false;
     307      try {
     308        jobManager.AbortJob(jobId);
     309      }
     310      catch (JobNotFoundException) {
     311        throw;
     312      }
     313    }
     314
     315    #region JobManager Events
     316    private void RegisterJobManagerEvents() {
     317      this.jobManager.JobStarted += new EventHandler<EventArgs<SlaveJob>>(jobManager_JobStarted);
     318      this.jobManager.JobPaused += new EventHandler<EventArgs<SlaveJob, JobData>>(jobManager_JobPaused);
     319      this.jobManager.JobStopped += new EventHandler<EventArgs<SlaveJob, JobData>>(jobManager_JobStopped);
     320      this.jobManager.JobFailed += new EventHandler<EventArgs<Tuple<SlaveJob, JobData, Exception>>>(jobManager_JobFailed);
     321      this.jobManager.ExceptionOccured += new EventHandler<EventArgs<SlaveJob, Exception>>(jobManager_ExceptionOccured);
     322      this.jobManager.JobAborted += new EventHandler<EventArgs<SlaveJob>>(jobManager_JobAborted);
     323      this.jobManager.NewChildJob += new EventHandler<EventArgs<SlaveJob, IJob>>(jobManager_NewChildJob);
     324      this.jobManager.WaitForChildJobs += new EventHandler<EventArgs<SlaveJob, JobData>>(jobManager_WaitForChildJobs);
     325      this.jobManager.DeleteChildJobs += new EventHandler<EventArgs<SlaveJob>>(jobManager_DeleteChildJobs);
     326    }
     327
     328    private void jobManager_JobStarted(object sender, EventArgs<SlaveJob> e) {
     329      // successfully started, everything is good
     330    }
     331
     332    private void jobManager_JobPaused(object sender, EventArgs<SlaveJob, JobData> e) {
     333      try {
     334        SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
     335        heartbeatManager.AwakeHeartBeatThread();
     336        Job job = wcfService.GetJob(e.Value.JobId);
     337        if (job == null) throw new JobNotFoundException(e.Value.JobId);
     338        job.ExecutionTime = e.Value.ExecutionTime;
     339        JobData jobData = e.Value.GetJobData();
     340        wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, JobState.Paused);
     341      }
     342      catch (JobNotFoundException ex) {
     343        clientCom.LogMessage(ex.ToString());
     344      }
     345      catch (Exception ex) {
     346        clientCom.LogMessage(ex.ToString());
     347      }
     348    }
     349
     350    private void jobManager_JobStopped(object sender, EventArgs<SlaveJob, JobData> e) {
     351      try {
     352        SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
     353        heartbeatManager.AwakeHeartBeatThread();
     354        Job job = wcfService.GetJob(e.Value.JobId);
     355        if (job == null) throw new JobNotFoundException(e.Value.JobId);
     356        job.ExecutionTime = e.Value.ExecutionTime;
     357        JobData jobData = e.Value.GetJobData();
     358        wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, JobState.Finished);
     359      }
     360      catch (JobNotFoundException ex) {
     361        clientCom.LogMessage(ex.ToString());
     362      }
     363      catch (Exception ex) {
     364        clientCom.LogMessage(ex.ToString());
     365      }
     366    }
     367
     368    private void jobManager_JobFailed(object sender, EventArgs<Tuple<SlaveJob, JobData, Exception>> e) {
     369      try {
     370        SlaveStatusInfo.DecrementUsedCores(e.Value.Item1.CoresNeeded);
     371        heartbeatManager.AwakeHeartBeatThread();
     372        SlaveJob slaveJob = e.Value.Item1;
     373        JobData jobData = e.Value.Item2;
     374        Exception exception = e.Value.Item3;
     375
     376        Job job = wcfService.GetJob(slaveJob.JobId);
     377        if (job == null) throw new JobNotFoundException(slaveJob.JobId);
     378        job.ExecutionTime = slaveJob.ExecutionTime;
     379        if (jobData != null) {
     380          wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, JobState.Failed);
    244381        } else {
    245           sj = slaveJobs[jobId];
     382          wcfService.UpdateJobState(job.Id, JobState.Failed, exception.ToString());
    246383        }
    247       }
    248 
    249       if (abort && !sj.Finished) {
    250         sj.KillAppDomain();
    251       }
    252     }
    253 
    254     private void HandleStopJob(object jobIdObj) {
    255       Guid jobId = (Guid)jobIdObj;
    256       bool stop = true;
    257       SlaveJob sj = null;
    258 
    259       lock (slaveJobs) {
    260         if (!slaveJobs.ContainsKey(jobId)) {
    261           clientCom.LogMessage(string.Format("Job with id {0} doesn't exist. Stop aborted.", jobId));
    262           stop = false;
    263         } else {
    264           sj = slaveJobs[jobId];
    265         }
    266       }
    267 
    268       if (stop && !sj.Finished) {
    269         sj.StopJob();
    270       }
    271     }
    272 
    273     private void HandlePauseJob(object jobIdObj) {
    274       Guid jobId = (Guid)jobIdObj;
    275       bool pause = true;
    276       SlaveJob sj = null;
    277 
    278       lock (slaveJobs) {
    279         if (!slaveJobs.ContainsKey(jobId)) {
    280           clientCom.LogMessage(string.Format("Job with id {0} doesn't exist. Pause aborted.", jobId));
    281           pause = false;
    282         } else {
    283           sj = slaveJobs[jobId];
    284         }
    285       }
    286 
    287       if (pause && !sj.Finished) {
    288         sj.PauseJob();
    289       }
    290     }
     384        clientCom.LogMessage(exception.Message);
     385      }
     386      catch (JobNotFoundException ex) {
     387        SlaveStatusInfo.IncrementExceptionOccured();
     388        clientCom.LogMessage(ex.ToString());
     389      }
     390      catch (Exception ex) {
     391        SlaveStatusInfo.IncrementExceptionOccured();
     392        clientCom.LogMessage(ex.ToString());
     393      }
     394    }
     395
     396    private void jobManager_ExceptionOccured(object sender, EventArgs<SlaveJob, Exception> e) {
     397      SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
     398      SlaveStatusInfo.IncrementExceptionOccured();
     399      heartbeatManager.AwakeHeartBeatThread();
     400      clientCom.LogMessage(string.Format("Exception occured for job {0}: {1}", e.Value.JobId, e.Value2.ToString()));
     401    }
     402
     403    private void jobManager_JobAborted(object sender, EventArgs<SlaveJob> e) {
     404      SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
     405    }
     406
     407    private void jobManager_NewChildJob(object sender, EventArgs<SlaveJob, IJob> e) {
     408      var job = new Job() { CoresNeeded = 1, MemoryNeeded = 0 };
     409      WcfService.Instance.AddChildJob(e.Value.JobId, job, e.Value2);
     410    }
     411
     412    private void jobManager_WaitForChildJobs(object sender, EventArgs<SlaveJob, JobData> e) {
     413      try {
     414        SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
     415        heartbeatManager.AwakeHeartBeatThread();
     416        Job job = wcfService.GetJob(e.Value.JobId);
     417        if (job == null) throw new JobNotFoundException(e.Value.JobId);
     418        job.ExecutionTime = e.Value.ExecutionTime;
     419        job.IsParentJob = true;
     420        job.FinishWhenChildJobsFinished = false;
     421        JobData jobData = e.Value.GetJobData();
     422        wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, JobState.Waiting);
     423      }
     424      catch (JobNotFoundException ex) {
     425        clientCom.LogMessage(ex.ToString());
     426      }
     427      catch (Exception ex) {
     428        clientCom.LogMessage(ex.ToString());
     429      }
     430    }
     431
     432    private void jobManager_DeleteChildJobs(object sender, EventArgs<SlaveJob> e) {
     433      try {
     434        WcfService.Instance.DeleteChildJobs(e.Value.JobId);
     435      }
     436      catch (Exception ex) {
     437        clientCom.LogMessage(ex.ToString());
     438      }
     439    }
     440    #endregion
     441
     442    #region Log Events
     443    private void log_MessageAdded(object sender, EventArgs<string> e) {
     444      clientCom.LogMessage(e.Value.Split('\t')[1]);
     445      ((ILog)sender).Clear(); // don't let the log take up memory
     446    }
     447    #endregion
    291448
    292449    /// <summary>
     
    294451    /// </summary>
    295452    private void DoAbortAll() {
    296       lock (slaveJobs) {
    297         foreach (SlaveJob sj in new List<SlaveJob>(slaveJobs.Values)) {
    298           if (!sj.Finished) {
    299             sj.KillAppDomain();
    300           }
    301         }
    302       }
    303       clientCom.LogMessage("Aborted all jobs!");
     453      clientCom.LogMessage("Aborting all jobs.");
     454      foreach (Guid jobId in jobManager.JobIds) {
     455        AbortJobAsync(jobId);
     456      }
    304457    }
    305458
     
    308461    /// </summary>
    309462    private void DoPauseAll() {
    310       clientCom.LogMessage("Pause all received");
    311 
    312       lock (slaveJobs) {
    313         foreach (SlaveJob sj in new List<SlaveJob>(slaveJobs.Values)) {
    314           if (!sj.Finished) {
    315             sj.PauseJob();
    316           }
    317         }
     463      clientCom.LogMessage("Pausing all jobs.");
     464      foreach (Guid jobId in jobManager.JobIds) {
     465        PauseJobAsync(jobId);
    318466      }
    319467    }
     
    323471    /// </summary>
    324472    private void DoStopAll() {
    325       clientCom.LogMessage("Stop all received");
    326 
    327       lock (slaveJobs) {
    328         foreach (SlaveJob sj in new List<SlaveJob>(slaveJobs.Values)) {
    329           if (!sj.Finished) {
    330             sj.StopJob();
    331           }
    332         }
    333       }
    334     }
    335 
     473      clientCom.LogMessage("Stopping all jobs.");
     474      foreach (Guid jobId in jobManager.JobIds) {
     475        StopJobAsync(jobId);
     476      }
     477    }
     478
     479    #region Slave Lifecycle Methods
    336480    /// <summary>
    337481    /// completly shudown slave
     
    350494      clientCom.LogMessage("Stopping heartbeat");
    351495      heartbeatManager.StopHeartBeat();
    352       AbortRequested = true;
     496      abortRequested = true;
    353497      clientCom.LogMessage("Logging out");
    354498
     
    369513    private void DoStartSlave() {
    370514      clientCom.LogMessage("Restart received");
    371       ConfigManager.Instance.Asleep = false;
     515      configManager.Asleep = false;
    372516      clientCom.LogMessage("Restart done");
    373517    }
     
    379523    private void Sleep() {
    380524      clientCom.LogMessage("Sleep received - not accepting any new jobs");
    381       ConfigManager.Instance.Asleep = true;
    382       DoPauseAll(); //TODO: or stop? can't decide...     
    383     }
    384 
    385     public void RemoveSlaveJobFromList(Guid jobId) {
    386       lock (slaveJobs) {
    387         if (slaveJobs.ContainsKey(jobId)) {
    388           slaveJobs.Remove(jobId);
    389         }
    390       }
    391     }
     525      configManager.Asleep = true;
     526      DoPauseAll();   
     527    }
     528    #endregion
    392529  }
    393530}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Exceptions/JobNotDataFoundException.cs

    r5786 r6357  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223
    324namespace HeuristicLab.Clients.Hive.SlaveCore {
    425  public class JobDataNotFoundException : Exception {
    5     public JobDataNotFoundException(Guid jobId) : base(string.Format("Job with Id {0} was not found.", jobId)) { }
     26    public JobDataNotFoundException(Guid jobId) : base(string.Format("JobData with JobId {0} was not found on server.", jobId)) { }
    627  }
    728}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Exceptions/JobNotFoundException.cs

    r5786 r6357  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223
    324namespace HeuristicLab.Clients.Hive.SlaveCore {
    425  public class JobNotFoundException : Exception {
    5     public JobNotFoundException(Guid jobId) : base (string.Format("Job with Id {0} was not found.", jobId)) { }
     26    public JobNotFoundException(Guid jobId) : base (string.Format("Job with Id {0} was not found on server.", jobId)) { }
    627  }
    728}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs

    r6203 r6357  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Hive;
    29 using HeuristicLab.PluginInfrastructure;
    3029
    3130
     
    4544    public ExecutorQueue executorQueue;
    4645
    47     public bool SendHeartbeatForExecutor { get; set; }
    48 
    49     public bool Aborted { get; set; }
     46    public bool SendHeartbeatForExecutor { get; set; } // Todo: get rid of??
     47    public bool IsStopping { get; set; }
     48    public bool IsPausing { get; set; }
    5049
    5150    public DateTime CreationTime { get; set; }
     
    7675    public Executor() {
    7776      SendHeartbeatForExecutor = true;
     77      IsStopping = false;
     78      IsPausing = false;
    7879      executorQueue = new ExecutorQueue();
    7980    }
     
    8485      try {
    8586        CreationTime = DateTime.Now;
    86         Aborted = false;
    8787        Job = PersistenceUtil.Deserialize<IJob>(serializedJob);
    8888
     
    107107
    108108    public void Pause() {
     109      IsPausing = true;
    109110      SendHeartbeatForExecutor = false;
    110111      // wait until job is started. if this does not happen, the Job is null an we give up
    111112      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    112113      if (Job == null) {
    113         currentException = new Exception("Pausing job " + this.JobId + ": Job is null");
     114        currentException = new Exception("Pausing job " + this.JobId + ": Job is null"); // Todo: use more specific exception
    114115        return;
    115116      }
    116117
    117       if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
     118      if (Job.ExecutionState == ExecutionState.Started) {
    118119        try {
    119120          Job.Pause();
     
    122123        }
    123124        catch (Exception ex) {
    124           currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString());
     125          currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception
    125126        }
    126127      }
     
    128129
    129130    public void Stop() {
     131      IsStopping = true;
    130132      SendHeartbeatForExecutor = false;
    131133      // wait until job is started. if this does not happen, the Job is null an we give up
    132134      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    133135      if (Job == null) {
    134         currentException = new Exception("Stopping job " + this.JobId + ": Job is null");
     136        currentException = new Exception("Stopping job " + this.JobId + ": Job is null"); // Todo: use more specific exception
    135137      }
    136138      wasJobAborted = true;
     
    142144        }
    143145        catch (Exception ex) {
    144           currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString());
     146          currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception
    145147        }
    146148      }
     
    167169    }
    168170
    169     private List<Guid> FindPluginsNeeded(IJob obj) {
    170       List<Guid> guids = new List<Guid>();
    171       foreach (IPluginDescription desc in PluginUtil.GetDeclaringPlugins(obj)) {
    172       }
    173       throw new NotImplementedException("FindPluginsNeeded for Job_NewChildJob");
    174 
    175       return guids;
    176     }
    177 
     171    #region Job Events
    178172    private void Job_NewChildJob(object sender, EventArgs<IJob> e) {
    179       JobData childJobData = new JobData();
    180       childJobData.Data = PersistenceUtil.Serialize(e.Value);
    181 
    182       Job childJob = new Job();
    183       childJob.CoresNeeded = 1;
    184       childJob.MemoryNeeded = 0;
    185       childJob.PluginsNeededIds = FindPluginsNeeded(e.Value);
    186 
    187       ExecutorMessage msg = new ExecutorMessage(ExecutorMessageType.NewChildJob);
    188       msg.MsgData = childJobData;
    189       msg.MsgJob = childJob;
    190 
    191       executorQueue.AddMessage(msg);
     173      //JobData childJobData = new JobData();
     174      //IEnumerable<Type> types;
     175      //childJobData.Data = PersistenceUtil.Serialize(e.Value, out types);
     176      //IEnumerable<Plugin> plugins;
     177      //PluginUtil.CollectDeclaringPlugins
     178
     179      //Job childJob = new Job();
     180      //childJob.CoresNeeded = 1;
     181      //childJob.MemoryNeeded = 0;
     182      //childJob.PluginsNeededIds = FindPluginsNeeded(e.Value);
     183
     184      //ExecutorMessage msg = new ExecutorMessage(ExecutorMessageType.NewChildJob);
     185      //msg.MsgData = childJobData;
     186      //msg.MsgJob = childJob;
     187
     188      //executorQueue.AddMessage(msg);
     189     
     190      executorQueue.AddMessage(new JobExecutorMessage(ExecutorMessageType.NewChildJob, e.Value));
    192191    }
    193192
     
    196195      this.Job.CollectChildJobs = true;
    197196
    198       JobData jdata = new JobData();
    199       jdata.Data = PersistenceUtil.Serialize(Job);
    200       jdata.JobId = this.JobId;
    201 
    202       ExecutorMessage msg = new ExecutorMessage(ExecutorMessageType.WaitForChildJobs);
    203       msg.MsgData = jdata;
    204       executorQueue.AddMessage(msg);
     197      //JobData jdata = new JobData();
     198      //jdata.Data = PersistenceUtil.Serialize(Job);
     199      //jdata.JobId = this.JobId;
     200
     201      //ExecutorMessage msg = new ExecutorMessage(ExecutorMessageType.WaitForChildJobs);
     202      //msg.MsgData = jdata;
     203      //executorQueue.AddMessage(msg);
     204
     205      executorQueue.AddMessage(new ExecutorMessage(ExecutorMessageType.WaitForChildJobs));
    205206    }
    206207
     
    210211
    211212    private void Job_JobFailed(object sender, EventArgs e) {
    212       HeuristicLab.Common.EventArgs<Exception> ex = (HeuristicLab.Common.EventArgs<Exception>)e;
     213      EventArgs<Exception> ex = (EventArgs<Exception>)e;
    213214      currentException = ex.Value;
    214       Aborted = true;
    215215
    216216      executorQueue.AddMessage(ExecutorMessageType.JobFailed);
     
    218218
    219219    private void Job_JobStopped(object sender, EventArgs e) {
    220       if (wasJobAborted) {
     220      if (wasJobAborted)
    221221        pauseStopSem.Release();
    222         Aborted = true;
    223       } else {
    224         //it's a clean and finished job, so send it
    225         executorQueue.AddMessage(ExecutorMessageType.JobStopped);
    226       }
    227     }
    228 
    229     public JobData GetFinishedJob() {
    230       if (Job == null) {
    231         if (currentException == null) {
    232           currentException = new Exception("Getting finished job " + this.JobId + ": Job is null");
    233           return GetJob();
    234         }
    235       }
    236 
    237       if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
    238         try {
    239           Job.Stop();
    240           wasJobAborted = true;
    241           pauseStopSem.WaitOne();
    242         }
    243         catch (Exception ex) {
    244           currentException = new Exception("Error getting finished job " + this.JobId + ": " + ex.ToString());
    245         }
    246       }
    247 
    248       return GetJob();
    249     }
    250 
    251     public JobData GetPausedJob() {
    252       if (Job.ExecutionState != HeuristicLab.Core.ExecutionState.Paused) {
    253         throw new Exception("Executor: Job has to be paused before fetching results.");
    254       }
    255       return GetJob();
     222
     223      executorQueue.AddMessage(ExecutorMessageType.JobStopped);
    256224    }
    257225
    258226    private void Job_JobPaused(object sender, EventArgs e) {
    259227      pauseStopSem.Release();
    260     }
    261 
    262     void Job_JobStarted(object sender, EventArgs e) {
     228      executorQueue.AddMessage(ExecutorMessageType.JobPaused);
     229    }
     230
     231    private void Job_JobStarted(object sender, EventArgs e) {
    263232      jobStartedSem.Release();
    264     }
    265 
    266     private JobData GetJob() {
    267       if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
     233      executorQueue.AddMessage(ExecutorMessageType.JobStarted);
     234    }
     235    #endregion
     236
     237    public JobData GetJobData() {
     238      if (Job.ExecutionState == ExecutionState.Started) {
    268239        throw new InvalidStateException("Job is still running");
    269240      } else {
    270         JobData jdata = new JobData();
     241        JobData jobData = new JobData();
    271242        if (Job == null) {
    272243          //send empty job and save exception
    273           jdata.Data = PersistenceUtil.Serialize(new JobData());
     244          jobData.Data = PersistenceUtil.Serialize(new JobData());
    274245          if (currentException == null) {
    275246            currentException = new Exception("Job with id " + this.JobId + " is null, sending empty job");
    276247          }
    277248        } else {
    278           jdata.Data = PersistenceUtil.Serialize(Job);
    279         }
    280         jdata.JobId = JobId;
    281         return jdata;
     249          jobData.Data = PersistenceUtil.Serialize(Job);
     250        }
     251        jobData.JobId = JobId;
     252        return jobData;
    282253      }
    283254    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ExecutorMessage.cs

    r6203 r6357  
    11
    22using System;
     3using HeuristicLab.Hive;
    34namespace HeuristicLab.Clients.Hive.SlaveCore {
    45  [Serializable]
    56  public enum ExecutorMessageType {
     7    JobStarted,
     8    JobPaused,
    69    JobStopped,
    710    JobFailed,
     
    1922      MessageType = messageType;
    2023    }
     24  }
    2125
    22     public JobData MsgData { get; set; }
    23     public Job MsgJob { get; set; }
     26  [Serializable]
     27  public class JobExecutorMessage : ExecutorMessage {
     28    public IJob Job { get; private set; }
     29
     30    public JobExecutorMessage(ExecutorMessageType messageType, IJob job) : base(messageType) {
     31      this.Job = job;
     32    }
    2433  }
    2534}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj

    r6203 r6357  
    7777      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
    7878    </Reference>
     79    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     80      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     81    </Reference>
    7982    <Reference Include="HeuristicLab.Core-3.3">
    8083      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
     
    8891    <Reference Include="System" />
    8992    <Reference Include="System.Core" />
     93    <Reference Include="System.Drawing" />
    9094    <Reference Include="System.Management" />
    9195    <Reference Include="System.Runtime.Serialization" />
     
    97101  </ItemGroup>
    98102  <ItemGroup>
    99     <Compile Include="ConfigManager.cs" />
    100     <Compile Include="Exceptions\JobAlreadyExistsException.cs" />
     103    <Compile Include="Exceptions\JobFailedException.cs" />
     104    <Compile Include="Manager\ConfigManager.cs" />
     105    <Compile Include="Exceptions\SerializationException.cs" />
     106    <Compile Include="Exceptions\OutOfMemoryException.cs" />
     107    <Compile Include="Exceptions\JobNotRunningException.cs" />
     108    <Compile Include="Exceptions\JobAlreadyRunningException.cs" />
    101109    <Compile Include="Exceptions\JobNotFoundException.cs" />
    102110    <Compile Include="Exceptions\JobNotDataFoundException.cs" />
    103111    <Compile Include="ExecutorMessage.cs" />
    104112    <Compile Include="ExecutorQueue.cs" />
     113    <Compile Include="IPluginProvider.cs" />
     114    <Compile Include="Manager\JobManager.cs" />
     115    <Compile Include="Exceptions\OutOfCoresException.cs" />
     116    <Compile Include="Exceptions\JobNotStartedException.cs" />
    105117    <Compile Include="SlaveClientCom.cs" />
    106118    <Compile Include="Core.cs" />
    107119    <Compile Include="DummyListener.cs" />
    108120    <Compile Include="Executor.cs" />
    109     <Compile Include="HeartbeatManager.cs" />
     121    <Compile Include="Manager\HeartbeatManager.cs" />
    110122    <Compile Include="Exceptions\InvalidStateException.cs" />
    111123    <Compile Include="JobStatus.cs" />
    112124    <Compile Include="MessageQueue.cs" />
    113125    <Compile Include="NetworkEnum.cs" />
    114     <Compile Include="PluginCache.cs" />
    115     <Compile Include="PluginUtil.cs" />
     126    <Compile Include="Manager\PluginManager.cs" />
    116127    <Compile Include="Properties\Settings.Designer.cs">
    117128      <AutoGen>True</AutoGen>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/JobStatus.cs

    r5599 r6357  
    3232    public Guid JobId { get; set; }
    3333    /// <summary>
    34     /// When has the calculation of the Job begun?
    35     /// </summary>
    36     [DataMember]
    37     public DateTime Since { get; set; }
    38     /// <summary>
    3934    /// Current progress
    4035    /// </summary>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveCommunicationService.cs

    r6263 r6357  
    6565    }
    6666
    67     public void StatusChanged(SlaveCore.StatusCommons status) {
     67    public void StatusChanged(StatusCommons status) {
    6868      subscribers.ForEach(delegate(ISlaveCommunicationCallbacks callback) {
    6969        if (((ICommunicationObject)callback).State == CommunicationState.Opened) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveJob.cs

    r6258 r6357  
    33using System.IO;
    44using System.Threading;
    5 using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
     5using HeuristicLab.Common;
     6using HeuristicLab.Core;
     7using HeuristicLab.Hive;
     8using HeuristicLab.PluginInfrastructure.Sandboxing;
    69
    710namespace HeuristicLab.Clients.Hive.SlaveCore {
     
    1316    private bool executorMonitoringRun;
    1417    private Thread executorMonitoringThread;
    15     private Core core;
    16     private bool finished;
     18    private PluginManager pluginManager;
     19    private ILog log;
     20
     21    public Guid JobId { get; private set; }
     22    public bool IsPrepared { get; private set; }
     23
    1724    private int coresNeeded;
    18 
    19     private ISlaveCommunication clientCom;
    20     private WcfService wcfService;
    21 
    22     public Guid JobId;
    23     public Executor JobExecutor { get { return executor; } }
    24     public bool Finished { get { return finished; } }
    25 
    26 
    27     public SlaveJob(Core core) {
    28       clientCom = SlaveClientCom.Instance.ClientCom;
    29       wcfService = WcfService.Instance;
     25    public int CoresNeeded {
     26      get { return coresNeeded; }
     27      set { this.coresNeeded = value; }
     28    }
     29
     30    public TimeSpan ExecutionTime {
     31      get { return executor != null ? executor.ExecutionTime : TimeSpan.Zero; }
     32    }
     33
     34    public SlaveJob(PluginManager pluginManager, int coresNeeded, ILog log) {
     35      this.pluginManager = pluginManager;
     36      this.coresNeeded = coresNeeded;
     37      this.log = log;
    3038      waitForStartBeforeKillSem = new Semaphore(0, 1);
    3139      executorMonitoringRun = true;
    32       this.core = core;
    33       finished = false;
    34     }
    35 
    36     public void PrepareJob(Guid jobId) {
    37       JobId = jobId;
    38       Job job = wcfService.GetJob(jobId);
    39       if (job == null) throw new JobNotFoundException(jobId);
    40       coresNeeded = job.CoresNeeded;
    41       SlaveStatusInfo.IncrementUsedCores(coresNeeded);
    42     }
    43 
    44     public void CalculateJob() {
    45       Job job = wcfService.GetJob(JobId);
    46       if (job == null) throw new JobNotFoundException(JobId);
    47 
    48       JobData jobData = wcfService.GetJobData(job.Id);
    49       if (jobData == null) throw new JobDataNotFoundException(JobId);
    50       SlaveStatusInfo.IncrementJobsFetched();
    51       job = wcfService.UpdateJobState(job.Id, JobState.Calculating, null);
    52       if (job == null) throw new JobNotFoundException(JobId);
    53       StartJobInAppDomain(job, jobData);
     40      IsPrepared = false;
     41    }
     42
     43    public void StartJobAsync(Job job, JobData jobData) {
     44      try {
     45        this.JobId = job.Id;
     46        Prepare(job);
     47        StartJobInAppDomain(jobData);
     48      }
     49      catch (Exception) {
     50        DisposeAppDomain(); // make sure to clean up if something went wrong
     51        throw;
     52      }
     53    }
     54
     55    public void PauseJob() {
     56      if (!IsPrepared) throw new AppDomainNotCreatedException();
     57      if (!executor.IsPausing && !executor.IsStopping) executor.Pause();
    5458    }
    5559
    5660    public void StopJob() {
    57       if (executor == null) {
    58         clientCom.LogMessage(string.Format("StopJob: job with id {0} is missing the executor", JobId));
    59       } else {
    60         Job job = wcfService.GetJob(JobId);
    61 
    62         if (job != null) {
    63           executor.Stop();
    64 
    65           try {
    66             JobData sJob = executor.GetFinishedJob();
    67             job.ExecutionTime = executor.ExecutionTime;
    68 
    69             if (executor.CurrentException != string.Empty) {
    70               wcfService.UpdateJobState(job.Id, JobState.Failed, executor.CurrentException);
    71             }
    72             SlaveStatusInfo.IncrementJobsAborted();
    73 
    74             clientCom.LogMessage(string.Format("Sending the stopped job with id: {0}", job.Id));
    75             wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Aborted);
    76           }
    77           catch (Exception e) {
    78             clientCom.LogMessage(string.Format("Transmitting the stopped job with id {0} to server failed. Exception is: {1}", job.Id, e.ToString()));
    79           }
    80           finally {
    81             KillAppDomain(); // kill appdomain in every case         
    82           }
    83         }
    84       }
    85     }
    86 
    87     public void PauseJob() {
    88       if (executor == null) {
    89         clientCom.LogMessage("PauseJob: Can't pause job with uninitialized executor");
    90       } else {
    91         Job job = wcfService.GetJob(JobId);
    92 
    93         if (job != null) {
    94           executor.Pause();
    95           JobData sJob = executor.GetPausedJob();
    96           job.ExecutionTime = executor.ExecutionTime;
    97 
    98           try {
    99             if (executor.CurrentException != string.Empty) {
    100               wcfService.UpdateJobState(job.Id, JobState.Failed, executor.CurrentException);
    101               SlaveStatusInfo.IncrementJobsFailed();
    102             } else {
    103               SlaveStatusInfo.IncrementJobsFinished();
    104             }
    105             clientCom.LogMessage("Sending the paused job with id: " + job.Id);
    106             wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Paused);
    107           }
    108           catch (Exception e) {
    109             clientCom.LogMessage(string.Format("Transmitting the paused job with id {0} to server failed. Exception is: {1}", job.Id, e.ToString()));
    110           }
    111           finally {
    112             KillAppDomain(); // kill appdomain in every case         
    113           }
    114         }
    115       }
    116     }
    117 
    118     /// <summary>
    119     /// Pauses a job, which means sending it to the server and killing it locally;
    120     /// atm only used when executor is waiting for child jobs
    121     /// </summary>
    122     public void PauseWaitJob(JobData data) {
    123       try {
    124         if (executor == null) {
    125           clientCom.LogMessage(string.Format("PauseWaitJob: Can't pause job with id {0} with uninitialized executor", JobId));
    126         } else {
    127           Job job = wcfService.GetJob(data.JobId);
    128           wcfService.UpdateJobData(job, data, ConfigManager.Instance.GetClientInfo().Id, JobState.Paused);
    129           wcfService.UpdateJobState(job.Id, JobState.Waiting, null);
    130         }
    131       }
    132       catch (Exception ex) {
    133         clientCom.LogMessage(string.Format("Pausing job with id {0} failed. Exception: {1}", JobId, ex.ToString()));
    134       }
    135       finally {
    136         KillAppDomain();
    137       }
    138     }
    139 
    140     /// <summary>
    141     /// serializes the finished job and submits it to the server. If, at the time, a network connection is unavailable, the Job gets stored on the disk.
    142     /// once the connection gets reestablished, the job gets submitted
    143     /// </summary>
    144     public void SendFinishedJob() {
    145       try {
    146         clientCom.LogMessage(string.Format("Getting the finished job with id: {0} ", JobId));
    147         if (executor == null) {
    148           clientCom.LogMessage(string.Format("SendFinishedJob: Can't pause job with id {0} with uninitialized executor", JobId));
    149           return;
    150         }
    151 
    152         Job job = wcfService.GetJob(JobId);
    153         job.ExecutionTime = executor.ExecutionTime;
    154 
    155         if (executor.Aborted) {
    156           SlaveStatusInfo.IncrementJobsAborted();
    157         } else {
    158           SlaveStatusInfo.IncrementJobsFinished();
    159         }
    160 
    161         if (executor.CurrentException != string.Empty) {
    162           wcfService.UpdateJobState(JobId, JobState.Failed, executor.CurrentException);
    163         }
    164 
    165         try {
    166           JobData sJob = executor.GetFinishedJob();
    167           if (sJob != null) {
    168             clientCom.LogMessage(string.Format("Sending the finished job with id: {0}", JobId));
    169             wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Finished);
    170           }
    171         }
    172         catch (Exception e) {
    173           clientCom.LogMessage(string.Format("Transmitting the job with id {0} to server failed. Exception is: {1}", job.Id, e.ToString()));
    174         }
    175         finally {
    176           KillAppDomain();
    177           Core.HeartbeatManager.AwakeHeartBeatThread();
    178         }
    179       }
    180       catch (Exception e) {
    181         clientCom.LogMessage(string.Format("SendFinishedJob: The following exception has been thrown: {0}", e.ToString()));
    182       }
    183     }
    184 
    185     /// <summary>
    186     /// A new Job from the wcfService has been received and will be started within a AppDomain.
    187     /// </summary>   
    188     private void StartJobInAppDomain(Job job, JobData jobData) {
    189       JobId = job.Id;
    190 
    191       clientCom.LogMessage(string.Format("Received new job with id {0}", job.Id));
    192       clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    193 
    194       String pluginDir = Path.Combine(PluginCache.Instance.PluginTempBaseDir, job.Id.ToString());
    195       bool pluginsPrepared = false;
    196       string configFileName = string.Empty;
    197 
    198       try {
    199         PluginCache.Instance.PreparePlugins(job, out configFileName);
    200         clientCom.LogMessage(string.Format("Plugins fetched for job {0}", job.Id));
    201         pluginsPrepared = true;
    202       }
    203       catch (Exception exception) {
    204         clientCom.LogMessage(string.Format("Copying plugins for job {0} failed: {1}", job.Id, exception));
    205         wcfService.UpdateJobState(job.Id, JobState.Failed, exception.ToString());
    206         SlaveStatusInfo.IncrementJobsFailed();
    207         core.RemoveSlaveJobFromList(JobId);
    208         finished = true;
    209         SlaveStatusInfo.DecrementUsedCores(coresNeeded);
    210       }
    211 
    212       if (pluginsPrepared) {
    213         try {
    214           appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    215           appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
    216 
    217           clientCom.LogMessage("Creating AppDomain");
    218           executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    219           clientCom.LogMessage("Created AppDomain");
    220 
    221           executor.JobId = job.Id;
    222           executor.CoresNeeded = job.CoresNeeded;
    223           executor.MemoryNeeded = job.MemoryNeeded;
    224           clientCom.LogMessage(string.Format("Starting Executor for job {0}", job.Id));
    225 
    226           executor.Start(jobData.Data);
    227           waitForStartBeforeKillSem.Release();
    228 
    229           StartExecutorMonitoringThread();
    230         }
    231         catch (Exception exception) {
    232           clientCom.LogMessage(string.Format("Creating the Appdomain and loading the job failed for job {0}", job.Id));
    233           clientCom.LogMessage(string.Format("Error thrown is: {0}", exception.ToString()));
    234 
    235           if (executor != null && executor.CurrentException != string.Empty) {
    236             wcfService.UpdateJobState(job.Id, JobState.Failed, executor.CurrentException);
    237           } else {
    238             wcfService.UpdateJobState(job.Id, JobState.Failed, exception.ToString());
    239           }
    240           SlaveStatusInfo.IncrementJobsFailed();
    241 
    242           KillAppDomain();
    243         }
    244       }
    245       Core.HeartbeatManager.AwakeHeartBeatThread();
     61      if (!IsPrepared) throw new AppDomainNotCreatedException();
     62      if (!executor.IsPausing && !executor.IsStopping) executor.Stop();
     63    }
     64
     65    private void Prepare(Job job) {
     66      string pluginDir = Path.Combine(pluginManager.PluginTempBaseDir, job.Id.ToString());
     67      string configFileName;
     68      pluginManager.PreparePlugins(job, out configFileName);
     69      appDomain = CreateAppDomain(job, pluginDir, configFileName);
     70      IsPrepared = true;
     71    }
     72
     73    private AppDomain CreateAppDomain(Job job, String pluginDir, string configFileName) {
     74      appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
     75      appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
     76
     77      log.LogMessage("Creating AppDomain");
     78      executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
     79
     80      executor.JobId = job.Id;
     81      executor.CoresNeeded = job.CoresNeeded;
     82      executor.MemoryNeeded = job.MemoryNeeded;
     83      return appDomain;
     84    }
     85
     86    private void StartJobInAppDomain(JobData jobData) {
     87      executor.Start(jobData.Data);
     88      waitForStartBeforeKillSem.Release();
     89      StartExecutorMonitoringThread();
    24690    }
    24791
     
    25094    /// </summary>
    25195    /// <param name="JobId">the GUID of the job</param>   
    252     public void KillAppDomain() {
    253       clientCom.LogMessage(string.Format("Shutting down Appdomain for Job {0}", JobId));
    254 
    255       try {
    256         StopExecutorMonitoringThread();
    257         finished = true;
    258         SlaveStatusInfo.DecrementUsedCores(coresNeeded);
    259 
    260         if (executor != null) {
    261           executor.Dispose();
    262         }
    263 
    264         if (appDomain != null) {
    265           appDomain.UnhandledException -= new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
    266           int repeat = 5;
    267           while (repeat > 0) {
    268             try {
    269               waitForStartBeforeKillSem.WaitOne();
    270               AppDomain.Unload(appDomain);
    271               waitForStartBeforeKillSem.Dispose();
    272               repeat = 0;
    273             }
    274             catch (CannotUnloadAppDomainException) {
    275               clientCom.LogMessage("Could not unload AppDomain, will try again in 1 sec.");
    276               Thread.Sleep(1000);
    277               repeat--;
    278               if (repeat == 0) {
    279                 clientCom.LogMessage("Could not unload AppDomain, shutting down core...");
    280                 throw; // rethrow and let app crash
    281               }
     96    public void DisposeAppDomain() {
     97      log.LogMessage(string.Format("Shutting down Appdomain for Job {0}", JobId));
     98      StopExecutorMonitoringThread();
     99
     100      if (executor != null) {
     101        executor.Dispose();
     102      }
     103
     104      if (appDomain != null) {
     105        appDomain.UnhandledException -= new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
     106        int repeat = 5;
     107        while (repeat > 0) {
     108          try {
     109            waitForStartBeforeKillSem.WaitOne();
     110            AppDomain.Unload(appDomain);
     111            waitForStartBeforeKillSem.Dispose();
     112            repeat = 0;
     113          }
     114          catch (CannotUnloadAppDomainException) {
     115            log.LogMessage("Could not unload AppDomain, will try again in 1 sec.");
     116            Thread.Sleep(1000);
     117            repeat--;
     118            if (repeat == 0) {
     119              throw; // rethrow and let app crash
    282120            }
    283121          }
    284122        }
    285 
    286         PluginCache.Instance.DeletePluginsForJob(JobId);
    287         GC.Collect();
    288       }
    289       catch (Exception ex) {
    290         clientCom.LogMessage(string.Format("Exception when unloading the appdomain: {0}", ex.ToString()));
    291       }
    292       finally {
    293         core.RemoveSlaveJobFromList(JobId);
    294       }
    295 
     123      }
     124      pluginManager.DeletePluginsForJob(JobId);
    296125      GC.Collect();
    297       clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    298126    }
    299127
    300128    private void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
    301       clientCom.LogMessage(string.Format("Exception in AppDomain: ", e.ExceptionObject.ToString()));
    302       KillAppDomain();
    303     }
    304 
     129      DisposeAppDomain();
     130      OnExceptionOccured(new Exception("Unhandled exception: " +e.ExceptionObject.ToString()));
     131    }
     132
     133    public JobData GetJobData() {
     134      return executor.GetJobData();
     135    }
    305136
    306137    #region ExecutorMonitorThread
    307 
    308138    private void StartExecutorMonitoringThread() {
    309139      executorMonitoringThread = new Thread(MonitorExecutor);
     
    331161
    332162        switch (message.MessageType) {
     163          case ExecutorMessageType.JobStarted:
     164            OnJobStarted();
     165            break;
     166
     167          case ExecutorMessageType.JobPaused:
     168            executorMonitoringRun = false;
     169            OnJobPaused();
     170            DisposeAppDomain();
     171            break;
     172
    333173          case ExecutorMessageType.JobStopped:
    334174            executorMonitoringRun = false;
    335             SendFinishedJob();
     175            OnJobStopped();
     176            DisposeAppDomain();
    336177            break;
    337178
    338179          case ExecutorMessageType.JobFailed:
    339180            executorMonitoringRun = false;
    340             SendFinishedJob();
     181            OnJobFailed(new JobFailedException(executor.CurrentException));
     182            DisposeAppDomain();
    341183            break;
    342184
    343185          case ExecutorMessageType.NewChildJob:
    344             WcfService.Instance.AddChildJob(JobId, message.MsgJob, message.MsgData);
     186            OnNewChildJob(((JobExecutorMessage)message).Job);
    345187            break;
    346188
    347189          case ExecutorMessageType.WaitForChildJobs:
    348190            executorMonitoringRun = false;
    349             PauseWaitJob(message.MsgData);
     191            OnWaitForChildJobs();
     192            DisposeAppDomain();
    350193            break;
    351194
    352195          case ExecutorMessageType.DeleteChildJobs:
    353             WcfService.Instance.DeleteChildJobs(JobId);
     196            OnDeleteChildJobs();
    354197            break;
    355198
     
    361204    }
    362205    #endregion
     206
     207    public event EventHandler<EventArgs<Guid>> JobStarted;
     208    private void OnJobStarted() {
     209      var handler = JobStarted;
     210      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     211    }
     212
     213    public event EventHandler<EventArgs<Guid>> JobStopped;
     214    private void OnJobStopped() {
     215      var handler = JobStopped;
     216      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     217    }
     218
     219    public event EventHandler<EventArgs<Guid>> JobPaused;
     220    private void OnJobPaused() {
     221      var handler = JobPaused;
     222      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     223    }
     224
     225    public event EventHandler<EventArgs<Guid>> JobAborted;
     226    private void OnJobAborted() {
     227      var handler = JobAborted;
     228      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     229    }
     230
     231    public event EventHandler<EventArgs<Guid, Exception>> JobFailed;
     232    private void OnJobFailed(Exception exception) {
     233      var handler = JobFailed;
     234      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     235    }
     236
     237    public event EventHandler<EventArgs<Guid, Exception>> ExceptionOccured;
     238    private void OnExceptionOccured(Exception exception) {
     239      var handler = ExceptionOccured;
     240      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     241    }
     242
     243    public event EventHandler<EventArgs<Guid, IJob>> NewChildJob;
     244    private void OnNewChildJob(IJob job) {
     245      var handler = NewChildJob;
     246      if (handler != null) handler(this, new EventArgs<Guid, IJob>(this.JobId, job));
     247    }
     248
     249    public event EventHandler<EventArgs<Guid>> WaitForChildJobs;
     250    private void OnWaitForChildJobs() {
     251      var handler = WaitForChildJobs;
     252      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     253    }
     254
     255    public event EventHandler<EventArgs<Guid>> DeleteChildJobs;
     256    private void OnDeleteChildJobs() {
     257      var handler = DeleteChildJobs;
     258      if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
     259    }
    363260  }
    364261}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveStatusInfo.cs

    r6203 r6357  
    2121
    2222using System;
     23using System.Threading;
    2324
    2425namespace HeuristicLab.Clients.Hive.SlaveCore {
    2526  public class SlaveStatusInfo {
    26     static private int jobsFinished; // everything went fine
    27     static private int jobsAborted;  // server sent stop or abort
    28     static private int jobsFetched;  // number of fetched jobs
    29     static private int jobsFailed;   // jobs that failed in the sandbox
    30     static private int usedCores;    // number of cores currently used
     27    private static object coreLock = new object();
     28    private static int jobsFetched;  // number of fetched jobs
     29    private static int jobsStarted;  // number of started jobs
     30    private static int jobsFinished; // everything went fine
     31    private static int jobsAborted;  // server sent abort
     32    private static int jobsFailed;   // jobs that failed in the sandbox
     33    private static int exceptionsOccured; // number jobs failed caused by the business logic, not a faulted job
     34    private static int usedCores;    // number of cores currently used
    3135
    32     static public DateTime LoginTime { get; set; }
    33     static private Object jobStatLock = new Object();
    34     static private Object coreLock = new Object();
     36    public static DateTime LoginTime { get; set; }
    3537
    36     static public int UsedCores {
    37       get {
    38         lock (coreLock) {
    39           return usedCores;
    40         }
    41       }
     38    public static int UsedCores {
     39      get { return usedCores; }
    4240    }
    4341
    44     static public int JobsFinished {
    45       get {
    46         lock (jobStatLock) {
    47           return jobsFinished;
    48         }
    49       }
     42    public static int JobsStarted {
     43      get { return jobsStarted; }
    5044    }
    5145
    52     static public int JobsAborted {
    53       get {
    54         lock (jobStatLock) {
    55           return jobsAborted;
    56         }
    57       }
     46    public static int JobsFinished {
     47      get { return jobsFinished; }
    5848    }
    5949
    60     static public int JobsFetched {
    61       get {
    62         lock (jobStatLock) {
    63           return jobsFetched;
    64         }
    65       }
     50    public static int JobsAborted {
     51      get { return jobsAborted; }
    6652    }
    6753
    68     static public int JobsFailed {
    69       get {
    70         lock (jobStatLock) {
    71           return jobsFailed;
    72         }
    73       }
     54    public static int JobsFetched {
     55      get { return jobsFetched; }
     56    }
     57
     58    public static int JobsFailed {
     59      get { return jobsFailed; }
     60    }
     61
     62    public static int ExceptionsOccured {
     63      get { return exceptionsOccured; }
     64    }
     65
     66    public static void IncrementJobsStarted() {
     67      Interlocked.Increment(ref jobsStarted);
    7468    }
    7569
    7670    public static void IncrementJobsFinished() {
    77       lock (jobStatLock) {
    78         jobsFinished++;
    79       }
     71      Interlocked.Increment(ref jobsFinished);
    8072    }
    8173
    8274    public static void IncrementJobsFailed() {
    83       lock (jobStatLock) {
    84         jobsFailed++;
    85       }
     75      Interlocked.Increment(ref jobsFailed);
    8676    }
    8777
    8878    public static void IncrementJobsAborted() {
    89       lock (jobStatLock) {
    90         jobsAborted++;
    91       }
     79      Interlocked.Increment(ref jobsAborted);
    9280    }
    9381
    9482    public static void IncrementJobsFetched() {
    95       lock (jobStatLock) {
    96         jobsFetched++;
    97       }
     83      Interlocked.Increment(ref jobsFetched);
     84    }
     85
     86    public static void IncrementExceptionOccured() {
     87      Interlocked.Increment(ref exceptionsOccured);
    9888    }
    9989
    10090    public static void IncrementUsedCores(int val) {
    101       lock (coreLock) {
    102         usedCores += val;
    103       }
     91      Interlocked.Add(ref usedCores, val);
    10492    }
    10593
    10694    public static void DecrementUsedCores(int val) {
    107       lock (coreLock) {
    108         usedCores -= val;
    109       }
     95      Interlocked.Add(ref usedCores, -val);
    11096    }
    11197  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.cs

    r6257 r6357  
    4343    public int JobsFetched { get; set; }
    4444    [DataMember]
     45    public int JobsStarted { get; set; }
     46    [DataMember]
    4547    public int JobsFinished { get; set; }
    4648    [DataMember]
     
    4951    public int JobsFailed { get; set; }
    5052    [DataMember]
     53    public int ExceptionsOccured { get; set; }
     54    [DataMember]
    5155    public List<JobStatus> Jobs { get; set; }
    5256    [DataMember]
     
    5458
    5559    public override string ToString() {
    56       return string.Format("Status: {0}, Fetched/Finished/Aborted/Failed: {1},{2},{3},{4}", Status, JobsFetched, JobsFinished, JobsAborted, JobsFailed);
     60      return string.Format("Status: {0}, Fetc,Start,Fin,Abor,Fail,Exc: {1},{2},{3},{4},{5},{6}",
     61        Status, JobsFetched, JobsStarted, JobsFinished, JobsAborted, JobsFailed, ExceptionsOccured);
    5762    }
    5863
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs

    r6004 r6357  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Common;
     25using HeuristicLab.Hive;
     26using HeuristicLab.PluginInfrastructure;
    2527
    2628namespace HeuristicLab.Clients.Hive.SlaveCore {
     
    2931  /// WcfService class is implemented as a Singleton and works as a communication Layer with the Server
    3032  /// </summary>
    31   public class WcfService : MarshalByRefObject {
     33  public class WcfService : MarshalByRefObject, IPluginProvider {
    3234    private static WcfService instance;
    3335    /// <summary>
     
    6264    }
    6365
    64     public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
    65       return CallHiveService(s => s.AddChildJob(parentJobId, job, jobData));
     66    public Guid AddChildJob(Guid parentJobId, Job job, IJob jobDataObject) {
     67      return CallHiveService(s => {
     68        JobData jobData = new JobData();
     69        IEnumerable<Type> types;
     70        jobData.Data = PersistenceUtil.Serialize(jobDataObject, out types);
     71        var plugins = new List<IPluginDescription>();
     72        PluginUtil.CollectDeclaringPlugins(plugins, types);
     73        job.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, new List<Plugin>(), new List<Plugin>(), plugins, false);
     74        return s.AddChildJob(parentJobId, job, jobData);
     75      });
    6676    }
    6777
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/app.config

    r6039 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3     <configSections>
    4         <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    5             <section name="HeuristicLab.Clients.Hive.Slave.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    6         </sectionGroup>
    7     </configSections>
    8     <userSettings>
    9         <HeuristicLab.Clients.Hive.Slave.Properties.Settings>
    10             <setting name="Guid" serializeAs="String">
    11                 <value>00000000-0000-0000-0000-000000000000</value>
    12             </setting>
    13         </HeuristicLab.Clients.Hive.Slave.Properties.Settings>
    14     </userSettings>
     3  <runtime>
     4    <gcServer enabled="true" />
     5  </runtime>
     6
     7  <configSections>
     8    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     9      <section name="HeuristicLab.Clients.Hive.Slave.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
     10    </sectionGroup>
     11  </configSections>
     12  <userSettings>
     13    <HeuristicLab.Clients.Hive.Slave.Properties.Settings>
     14      <setting name="Guid" serializeAs="String">
     15        <value>00000000-0000-0000-0000-000000000000</value>
     16      </setting>
     17    </HeuristicLab.Clients.Hive.Slave.Properties.Settings>
     18  </userSettings>
    1519
    1620  <system.serviceModel>
    1721    <bindings>
    1822      <wsHttpBinding>
    19         <binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
     23        <binding name="wsHttpBinding_Hive" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    2024          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
    2125          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
     
    2832    </bindings>
    2933    <services>
    30       <service name="HeuristicLab.Clients.Hive.SlaveCore.SlaveCommunicationService">       
     34      <service name="HeuristicLab.Clients.Hive.SlaveCore.SlaveCommunicationService">
    3135        <endpoint address="net.pipe://localhost/HeuristicLabSlaveCom" binding="netNamedPipeBinding" contract="HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts.ISlaveCommunication"/>
    3236      </service>
     
    3438    <client>
    3539      <endpoint name="SlaveCommunicationServiceEndpoint" address="net.pipe://localhost/HeuristicLabSlaveCom" binding="netNamedPipeBinding" contract="HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts.ISlaveCommunication"/>
    36       <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
     40      <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_Hive" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
    3741        <identity>
    3842          <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ=="/>
     
    4246  </system.serviceModel>
    4347
    44 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
     48  <startup>
     49    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     50  </startup>
     51</configuration>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj

    r6200 r6357  
    112112  </ItemGroup>
    113113  <ItemGroup>
     114    <Compile Include="ThreadSafeLog.cs" />
    114115    <None Include="app_f005pc.config" />
    115116    <None Include="app_services.config" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/app.config

    r5537 r6357  
    11<?xml version="1.0"?>
    22<configuration>
    3     <system.serviceModel>
    4         <bindings>
    5             <wsHttpBinding>
    6                 <binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    7                   <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
    8                   <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
    9                   <security mode="Message">
    10                     <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
    11                     <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/>
    12                   </security>
    13                 </binding>
    14               </wsHttpBinding>
    15             </bindings>
    16         <client>
    17             <endpoint address="http://localhost/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="HeuristicLab.Services.Hive.Common.ServiceContracts.IHiveService" name="wsHttpBinding_IHiveService">
    18               <identity>
    19                 <certificate encodedValue="AwAAAAEAAAAUAAAAfEKvcVixnJay+q4hCPFuO0JL5TQgAAAAAQAAAPIBAAAwggHuMIIBW6ADAgECAhCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQAwFDESMBAGA1UEAxMJbG9jYWxob3N0MB4XDTEwMTAxOTEwNTMxNVoXDTM5MTIzMTIzNTk1OVowFDESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXwC5TGcAffd/0oAWHtm0s6YXVXEgXgb1AYmBkkkhkKIFJG/e/Z0KSYbJepmSJD44W3oOAVm+x1DAsZxU79HahDYgWCuHLMm1TLpwSmYOQ0kV3pGHWHhiWV7h7oGLds/eqZ2EOpaNGryfEPnrA4VmxY91vV5/2BTeVSWG6F8lRKQIDAQABo0kwRzBFBgNVHQEEPjA8gBAR7kBnMRHO5gzThEqda0wWoRYwFDESMBAGA1UEAxMJbG9jYWxob3N0ghCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQADgYEAoPwEG4QTDXhlxERNDfsZmM2IhEpV42ppz1kEah2oYKDa/ElIMVtvqLv6flVtg18ENN/mEJWiHZ3NyP3qr2Pip+sh+/2WBiSbOaukES/CM7OJn9kJCImH7M/xqM8pxqY8IfgM6iBVrVj9uHqj3j2BBck+cYY8fKyh3CFifMIp6ac="/>
    20               </identity>
    21             </endpoint>
    22         </client>
    23     </system.serviceModel>
    24 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
     3  <system.serviceModel>
     4    <bindings>
     5      <wsHttpBinding>
     6        <binding name="wsHttpBinding_IHiveService"
     7                 closeTimeout="00:01:00"
     8                 openTimeout="00:01:00"
     9                 receiveTimeout="00:20:00"
     10                 sendTimeout="00:20:00"
     11                 bypassProxyOnLocal="false"
     12                 transactionFlow="false"
     13                 hostNameComparisonMode="StrongWildcard"
     14                 maxBufferPoolSize="2147483647"
     15                 maxReceivedMessageSize="2147483647"
     16                 messageEncoding="Text"
     17                 textEncoding="utf-8"
     18                 useDefaultWebProxy="true"
     19                 allowCookies="false">
     20
     21          <readerQuotas maxDepth="2147483647"
     22                        maxStringContentLength="2147483647"
     23                        maxArrayLength="2147483647"
     24                        maxBytesPerRead="2147483647"
     25                        maxNameTableCharCount="2147483647"/>
     26          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
     27          <security mode="Message">
     28            <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
     29            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/>
     30          </security>
     31        </binding>
     32      </wsHttpBinding>
     33    </bindings>
     34    <client>
     35      <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IHiveService" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
     36        <identity>
     37          <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ=="/>
     38        </identity>
     39      </endpoint>
     40    </client>
     41  </system.serviceModel>
     42  <startup>
     43    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     44  </startup>
     45</configuration>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive 3.4.sln

    r6215 r6357  
    5353  EndProjectSection
    5454EndProject
    55 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Slave.Tests-3.4", "HeuristicLab.Clients.Hive.Slave.Tests\HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj", "{C4CBD11E-1B83-464A-B0AD-0DC0FF7E57AA}"
    56 EndProject
    57 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Services.Hive.Tests-3.4", "HeuristicLab.Services.Hive.Tests\HeuristicLab.Services.Hive.Tests-3.4.csproj", "{17187EAC-5D8C-4B11-9CEA-D88F71B59658}"
     55Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Slave-3.4.Tests", "HeuristicLab.Clients.Hive.Slave.Tests\HeuristicLab.Clients.Hive.Slave-3.4.Tests.csproj", "{C4CBD11E-1B83-464A-B0AD-0DC0FF7E57AA}"
     56EndProject
     57Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Services.Hive-3.4.Tests", "HeuristicLab.Services.Hive.Tests\HeuristicLab.Services.Hive-3.4.Tests.csproj", "{17187EAC-5D8C-4B11-9CEA-D88F71B59658}"
    5858EndProject
    5959Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4", "HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4\HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4.csproj", "{464D70B8-2D91-485C-B622-22E4A4891C68}"
     
    9393Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.HiveEngine-3.4", "HeuristicLab.HiveEngine\3.4\HeuristicLab.HiveEngine-3.4.csproj", "{2C036542-5451-4A23-AFF6-87575C7BAFE7}"
    9494EndProject
    95 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.HiveEngine.Test", "HeuristicLab.HiveEngine.Test\HeuristicLab.HiveEngine.Test.csproj", "{87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}"
     95Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.HiveEngine-3.4.Tests", "HeuristicLab.HiveEngine.Test\HeuristicLab.HiveEngine-3.4.Tests.csproj", "{87D9FBB9-8E54-4770-9C84-B4B571D9EDD5}"
    9696EndProject
    9797Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "HeuristicLab.Clients.Hive.Slave.TrayIconSetup", "HeuristicLab.Clients.Hive.Slave.TrayIconSetup\HeuristicLab.Clients.Hive.Slave.TrayIconSetup.vdproj", "{542AD827-817C-44E9-AD28-D6607BC4FA10}"
    9898EndProject
    9999Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.HiveEngine.Views-3.4", "HeuristicLab.HiveEngine.Views\3.4\HeuristicLab.HiveEngine.Views-3.4.csproj", "{E37F15E0-D0D6-4C6E-AD22-0DA514C943A3}"
     100EndProject
     101Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Clients.Hive.Slave-3.4.ConsoleTests", "HeuristicLab.Clients.Hive.Slave\3.4\ConsoleTests\HeuristicLab.Clients.Hive.Slave-3.4.ConsoleTests.csproj", "{B09E8C65-8D4D-48B3-8E9A-F6FC52107261}"
    100102EndProject
    101103Global
     
    441443    {E37F15E0-D0D6-4C6E-AD22-0DA514C943A3}.Release|x86.ActiveCfg = Release|x86
    442444    {E37F15E0-D0D6-4C6E-AD22-0DA514C943A3}.Release|x86.Build.0 = Release|x86
     445    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     446    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|Any CPU.Build.0 = Debug|Any CPU
     447    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
     448    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
     449    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|x64.ActiveCfg = Debug|x86
     450    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|x86.ActiveCfg = Debug|x86
     451    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Debug|x86.Build.0 = Debug|x86
     452    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|Any CPU.ActiveCfg = Release|Any CPU
     453    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|Any CPU.Build.0 = Release|Any CPU
     454    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
     455    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|Mixed Platforms.Build.0 = Release|Any CPU
     456    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|x64.ActiveCfg = Release|x86
     457    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|x86.ActiveCfg = Release|x86
     458    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261}.Release|x86.Build.0 = Release|x86
    443459  EndGlobalSection
    444460  GlobalSection(SolutionProperties) = preSolution
     
    455471    {989FE92B-484E-41EE-87E2-6A24AF0381D8} = {622F8E95-CDFC-4B4E-BBA7-3EE4E47DB52A}
    456472    {542AD827-817C-44E9-AD28-D6607BC4FA10} = {622F8E95-CDFC-4B4E-BBA7-3EE4E47DB52A}
     473    {B09E8C65-8D4D-48B3-8E9A-F6FC52107261} = {622F8E95-CDFC-4B4E-BBA7-3EE4E47DB52A}
    457474    {EC2C8109-6E1E-4C88-9A2B-908CFF2EF4AC} = {E69A1E5F-63F7-493F-BBA2-163D6E321D44}
    458475    {CF9DA321-AC1B-4FD3-9EC3-67BC6B861BDE} = {E69A1E5F-63F7-493F-BBA2-163D6E321D44}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive/3.4/ItemJob.cs

    r6219 r6357  
    2828
    2929namespace HeuristicLab.Hive {
    30   [Item("Abstract Job", "Represents a executable hive job.")]
     30  [Item("Item Job", "Represents a executable hive job which contains a HeuristicLab Item.")]
    3131  [StorableClass]
    3232  public abstract class ItemJob : DeepCloneable, IJob {
     
    8686    #endregion
    8787
    88     #region Optimizer Events
     88    #region Item Events
    8989    protected virtual void RegisterItemEvents() {
    9090      item.ItemImageChanged += new EventHandler(item_ItemImageChanged);
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/Program.cs

    r6219 r6357  
    3636      job.IndexInParentOptimizerList = 15;
    3737
    38       byte[] data = PersistenceUtil.Serialize(job);
     38      //byte[] data = PersistenceUtil.Serialize(job);
    3939
    40       var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
     40      //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
    4141     
    4242      #region Credentials
    4343      ServiceLocator.Instance.Username = "cneumuel";
    44       ServiceLocator.Instance.Password = "YouWillNeverKnow";
     44      ServiceLocator.Instance.Password = "Stormlord105.";
    4545      #endregion
    4646
    47       GeneticAlgorithm ga = new GeneticAlgorithm();
    48       ga.Problem = new SingleObjectiveTestFunctionProblem();
    49       ga.Engine = new HiveEngine();
    50       ga.Elites.Value = 0;
    51       ga.PopulationSize.Value = 4;
    52       ga.MaximumGenerations.Value = 3;
     47      GeneticAlgorithm alg = new GeneticAlgorithm();
     48      alg.Problem = new SingleObjectiveTestFunctionProblem();
     49      alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
     50      alg.Elites.Value = 0;
     51      alg.PopulationSize.Value = 10;
     52      alg.MaximumGenerations.Value = 3;
    5353
    54       //var plugins = new List<IPluginDescription>();
    55       //IEnumerable<Type> types;
    56       //PersistenceUtil.Serialize(ga, out types);
    57       //PluginUtil.CollectDeclaringPlugins(plugins, types);
     54      //var alg = ContentManager.Load("Meta-GA - Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled)_small.hl") as GeneticAlgorithm;
     55      //alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
     56      //alg.PopulationSize.Value = 2;
     57      //((MetaOptimizationProblem)alg.Problem).Repetitions.Value = 5;
    5858
     59      alg.Start();
    5960
    60       ga.Start();
    61 
    62       while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
     61      while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) {
    6362        Thread.Sleep(2000);
    6463        Console.Clear();
    65         Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
     64        Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray()));
    6665        Console.WriteLine("---");
    6766        Console.WriteLine("Log:");
    68         Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
     67        Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray()));
     68        var exps = ((HiveEngine)alg.Engine).HiveExperiments;
     69        foreach (var exp in exps) {
     70          Console.WriteLine("# " + exp.ToString());
     71          Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray()));
     72        }
    6973      }
    70       Console.WriteLine("finished: " + ga.ExecutionState);
     74      Console.WriteLine("finished: " + alg.ExecutionState);
    7175
    7276      Console.WriteLine("Storing...");
    73       ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
     77      ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
    7478      Console.WriteLine("Finished");
    7579
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/app.config

    r6033 r6357  
    1 <?xml version="1.0" encoding="utf-8"?>
     1<?xml version="1.0" encoding="utf-8"?>
    22<configuration>
    33  <configSections>
     
    5252          </security>
    5353        </binding>
    54         <binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    55           <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    56           <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
     54        <binding name="wsHttpBinding_IHiveService"
     55                 closeTimeout="00:01:00"
     56                 openTimeout="00:01:00"
     57                 receiveTimeout="00:20:00"
     58                 sendTimeout="00:20:00"
     59                 bypassProxyOnLocal="false"
     60                 transactionFlow="false"
     61                 hostNameComparisonMode="StrongWildcard"
     62                 maxBufferPoolSize="2147483647"
     63                 maxReceivedMessageSize="2147483647"
     64                 messageEncoding="Text"
     65                 textEncoding="utf-8"
     66                 useDefaultWebProxy="true"
     67                 allowCookies="false">
     68
     69          <readerQuotas maxDepth="2147483647"
     70                        maxStringContentLength="2147483647"
     71                        maxArrayLength="2147483647"
     72                        maxBytesPerRead="2147483647"
     73                        maxNameTableCharCount="2147483647"/>
     74          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
    5775          <security mode="Message">
    58             <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    59             <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" />
     76            <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
     77            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/>
    6078          </security>
    6179        </binding>
     
    7391        </identity>
    7492      </endpoint>
    75       <endpoint address="http://localhost/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
     93      <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IHiveService" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
    7694        <identity>
    77           <certificate encodedValue="AwAAAAEAAAAUAAAAfEKvcVixnJay+q4hCPFuO0JL5TQgAAAAAQAAAPIBAAAwggHuMIIBW6ADAgECAhCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQAwFDESMBAGA1UEAxMJbG9jYWxob3N0MB4XDTEwMTAxOTEwNTMxNVoXDTM5MTIzMTIzNTk1OVowFDESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXwC5TGcAffd/0oAWHtm0s6YXVXEgXgb1AYmBkkkhkKIFJG/e/Z0KSYbJepmSJD44W3oOAVm+x1DAsZxU79HahDYgWCuHLMm1TLpwSmYOQ0kV3pGHWHhiWV7h7oGLds/eqZ2EOpaNGryfEPnrA4VmxY91vV5/2BTeVSWG6F8lRKQIDAQABo0kwRzBFBgNVHQEEPjA8gBAR7kBnMRHO5gzThEqda0wWoRYwFDESMBAGA1UEAxMJbG9jYWxob3N0ghCNN5wrUcXMmE/9xwp4TYa9MAkGBSsOAwIdBQADgYEAoPwEG4QTDXhlxERNDfsZmM2IhEpV42ppz1kEah2oYKDa/ElIMVtvqLv6flVtg18ENN/mEJWiHZ3NyP3qr2Pip+sh+/2WBiSbOaukES/CM7OJn9kJCImH7M/xqM8pxqY8IfgM6iBVrVj9uHqj3j2BBck+cYY8fKyh3CFifMIp6ac=" />
     95          <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ=="/>
    7896        </identity>
    7997      </endpoint>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/app_services.config

    r6198 r6357  
    5252          </security>
    5353        </binding>
    54         <binding name="wsHttpBinding_IHiveService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    55           <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    56           <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
     54        <binding name="wsHttpBinding_IHiveService"
     55                 closeTimeout="00:01:00"
     56                 openTimeout="00:01:00"
     57                 receiveTimeout="00:20:00"
     58                 sendTimeout="00:20:00"
     59                 bypassProxyOnLocal="false"
     60                 transactionFlow="false"
     61                 hostNameComparisonMode="StrongWildcard"
     62                 maxBufferPoolSize="2147483647"
     63                 maxReceivedMessageSize="2147483647"
     64                 messageEncoding="Text"
     65                 textEncoding="utf-8"
     66                 useDefaultWebProxy="true"
     67                 allowCookies="false">
     68
     69          <readerQuotas maxDepth="2147483647"
     70                        maxStringContentLength="2147483647"
     71                        maxArrayLength="2147483647"
     72                        maxBytesPerRead="2147483647"
     73                        maxNameTableCharCount="2147483647"/>
     74          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
    5775          <security mode="Message">
    58             <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    59             <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" />
     76            <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
     77            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/>
    6078          </security>
    6179        </binding>
     
    7593      <endpoint address="http://services.heuristiclab.com/Hive-3.4/HiveService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IHiveService" contract="HeuristicLab.Clients.Hive.IHiveService" name="wsHttpBinding_IHiveService">
    7694        <identity>
    77           <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ==" />
     95          <certificate encodedValue="AwAAAAEAAAAUAAAAwK1+2oAmcy/mI2P2QjyiJRh0y60gAAAAAQAAACoCAAAwggImMIIBj6ADAgECAhAIkseQ2EEhgU720qJA61gqMA0GCSqGSIb3DQEBBAUAMCQxIjAgBgNVBAMTGXNlcnZpY2VzLmhldXJpc3RpY2xhYi5jb20wHhcNMTAwNTExMTExNDAyWhcNMzkxMjMxMjM1OTU5WjAkMSIwIAYDVQQDExlzZXJ2aWNlcy5oZXVyaXN0aWNsYWIuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq26Bwmwc7k+4W30qLQ2j+FInEL5BuH6opDY6CSlrtt3xQS/anrhvpbf3QghLDVINzcHkzbPmm/SguG4F85QLB6xO+tJaOvRo0iEK5g3c307vMIru7FJwk/OhplEQ5J1hbDgL3zOJlrWlgtqRVxCtVdF3XroI9BctOt1NkeKv9ewIDAQABo1kwVzBVBgNVHQEETjBMgBCjbgdYd4j5JgUuJ1Wo/GxroSYwJDEiMCAGA1UEAxMZc2VydmljZXMuaGV1cmlzdGljbGFiLmNvbYIQCJLHkNhBIYFO9tKiQOtYKjANBgkqhkiG9w0BAQQFAAOBgQAb/2xk2uQad68shSPl/uixWgvFI8WkxOTBopOLaLtDxwCeZ3mWVHdV9VnixHtThubnEBXAhYOCQSIXWtQuXFWO+gH3YyjTRJY5kTmXyuvBRTn3/so5SrQ7Rdlm9hf6E5YVX3tCjAy7ybUyaDUkQfmH5vmvgvpMzRfsJ1qhnUpJiQ=="/>
    7896        </identity>
    7997      </endpoint>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Views/3.4/HeuristicLab.HiveEngine.Views-3.4.csproj

    r6217 r6357  
    103103  <ItemGroup>
    104104    <Reference Include="HeuristicLab.Collections-3.3">
    105       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath>
     105      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath>
    106106    </Reference>
    107107    <Reference Include="HeuristicLab.Common-3.3">
    108       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
     108      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
    109109    </Reference>
    110110    <Reference Include="HeuristicLab.Core-3.3">
    111       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
     111      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
    112112    </Reference>
    113113    <Reference Include="HeuristicLab.Core.Views-3.3">
    114       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core.Views-3.3.dll</HintPath>
     114      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Core.Views-3.3.dll</HintPath>
    115115    </Reference>
    116116    <Reference Include="HeuristicLab.MainForm-3.3">
    117       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm-3.3.dll</HintPath>
     117      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm-3.3.dll</HintPath>
    118118    </Reference>
    119119    <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3">
    120       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
     120      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
    121121    </Reference>
    122122    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    123       <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     123      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    124124    </Reference>
    125125    <Reference Include="System" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.4/HiveEngine.cs

    r6219 r6357  
    3737  [Item("Hive Engine", "Engine for parallel execution on the hive. You need enable `Parallel` for at least one operator in your operator graph to have all childoperations parallelized. Also those childoperations must not have sideeffects on a higher scope.")]
    3838  public class HiveEngine : Engine {
     39    private static object locker = new object();
    3940    private static object logLocker = new object();
    4041    private CancellationToken cancellationToken;
    41    
     42    private bool firstRun = true;
     43
    4244    [Storable]
    4345    private IOperator currentOperator;
     
    136138      OperationCollection coll;
    137139      IAtomicOperation operation;
    138       TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
    139 
    140       this.OnlinePlugins = ServiceLocator.Instance.CallHiveService(s => s.GetPlugins()).Where(x => x.IsLocal == false).ToList();
    141       this.AlreadyUploadedPlugins = new List<Plugin>();
    142 
    143       while (ExecutionStack.Count > 0) {
     140
     141      if (firstRun) {
     142        TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
     143        this.OnlinePlugins = ServiceLocator.Instance.CallHiveService(s => s.GetPlugins()).Where(x => x.IsLocal == false).ToList();
     144        this.AlreadyUploadedPlugins = new List<Plugin>();
     145        firstRun = false;
     146      }
     147
     148      while (executionStack.Count > 0) {
    144149        cancellationToken.ThrowIfCancellationRequested();
    145150
    146         next = ExecutionStack.Pop();
     151        next = executionStack.Pop();
     152        bool isOpCollection = next is OperationCollection;
     153        int collCount = isOpCollection ? ((OperationCollection)next).Count : 0;
     154        string opName = !isOpCollection ? ((IAtomicOperation)next).Operator.Name : "OpCollection";
     155
    147156        if (next is OperationCollection) {
    148157          coll = (OperationCollection)next;
    149           if (coll.Parallel) {
     158
     159          bool isPMOEvaluator = coll.Count > 0 && coll.First() is HeuristicLab.Core.ExecutionContext && ((HeuristicLab.Core.ExecutionContext)coll.First()).Operator.GetType().Name == "PMOEvaluator";
     160          bool isAlgorithmEvaluator = coll.Count > 0 && coll.First() is HeuristicLab.Core.ExecutionContext && ((HeuristicLab.Core.ExecutionContext)coll.First()).Operator.GetType().Name == "AlgorithmEvaluator";
     161
     162          if (coll.Parallel && isPMOEvaluator) {
     163            Task[] tasks = new Task[coll.Count];
     164            Stack<IOperation>[] stacks = new Stack<IOperation>[coll.Count];
     165            for (int i = 0; i < coll.Count; i++) {
     166              stacks[i] = new Stack<IOperation>();
     167              stacks[i].Push(coll[i]);
     168              tasks[i] = Task.Factory.StartNew(Run, stacks[i], cancellationToken);
     169            }
     170            try {
     171              Task.WaitAll(tasks);
     172            }
     173            catch (AggregateException ex) {
     174              OperationCollection remaining = new OperationCollection() { Parallel = true };
     175              for (int i = 0; i < stacks.Length; i++) {
     176                if (stacks[i].Count == 1)
     177                  remaining.Add(stacks[i].Pop());
     178                if (stacks[i].Count > 1) {
     179                  OperationCollection ops = new OperationCollection();
     180                  while (stacks[i].Count > 0)
     181                    ops.Add(stacks[i].Pop());
     182                  remaining.Add(ops);
     183                }
     184              }
     185              if (remaining.Count > 0) executionStack.Push(remaining);
     186              throw ex;
     187            }
     188          } else if (coll.Parallel) {
    150189            // clone the parent scope here and reuse it for each operation. otherwise for each job the whole scope-tree first needs to be copied and then cleaned, which causes a lot of work for the Garbage Collector
    151190            IScope parentScopeClone = (IScope)((IAtomicOperation)coll.First()).Scope.Parent.Clone();
     
    158197            }
    159198
    160             IScope[] scopes = ExecuteOnHive(jobs, parentScopeClone, cancellationToken);
    161             //IScope[] scopes = ExecuteLocally(jobs, parentScopeClone, cancellationToken);
     199            var experiment = CreateHiveExperiment();
     200            IScope[] scopes = ExecuteOnHive(experiment, jobs, parentScopeClone, cancellationToken);
     201            DisposeHiveExperiment(experiment);
    162202
    163203            for (int i = 0; i < coll.Count; i++) {
     
    178218          }
    179219          catch (Exception ex) {
    180             ExecutionStack.Push(operation);
     220            executionStack.Push(operation);
    181221            if (ex is OperationCanceledException) throw ex;
    182222            else throw new OperatorExecutionException(operation.Operator, ex);
    183223          }
    184           if (next != null) ExecutionStack.Push(next);
     224          if (next != null) executionStack.Push(next);
    185225
    186226          if (operation.Operator.Breakpoint) {
     
    227267    /// </summary>
    228268    /// <param name="jobs"></param>
    229     private IScope[] ExecuteOnHive(EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) {
     269    private IScope[] ExecuteOnHive(RefreshableHiveExperiment refreshableHiveExperiment, EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) {
    230270      LogMessage(string.Format("Executing {0} operations on the hive.", jobs.Length));
    231271      IScope[] scopes = new Scope[jobs.Length];
    232272      object locker = new object();
    233273      IDictionary<Guid, int> jobIndices = new Dictionary<Guid, int>();
    234       var hiveExperiment = new HiveExperiment();
     274      var hiveExperiment = refreshableHiveExperiment.HiveExperiment;
    235275
    236276      try {
    237277        List<Guid> remainingJobIds = new List<Guid>();
    238278
    239         // create hive experiment
     279        // create upload-tasks
     280        var uploadTasks = new List<Task<Job>>();
     281        for (int i = 0; i < jobs.Length; i++) {
     282          hiveExperiment.HiveJobs.Add(new EngineHiveJob(jobs[i], parentScopeClone));
     283
     284          // shuffle random variable to avoid the same random sequence in each operation; todo: does not yet work (it cannot find the random variable)
     285          IRandom random = FindRandomParameter(jobs[i].InitialOperation as IExecutionContext);
     286          if (random != null)
     287            random.Reset(random.Next());
     288        }
     289        ExperimentManagerClient.StartExperiment((e) => {
     290          LogException(e);
     291        }, refreshableHiveExperiment);
     292
     293        // do polling until experiment is finished and all jobs are downloaded
     294        while (!refreshableHiveExperiment.AllJobsFinished()) {
     295          Thread.Sleep(500);
     296          this.ExecutionTimeOnHive = TimeSpan.FromMilliseconds(hiveExperiments.Sum(x => x.HiveExperiment.ExecutionTime.TotalMilliseconds));
     297          cancellationToken.ThrowIfCancellationRequested();
     298        }
     299        LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableHiveExperiment.ToString(), refreshableHiveExperiment.HiveExperiment.ExecutionTime));
     300
     301        // get scopes
     302        int j = 0;
     303        foreach (var hiveJob in hiveExperiment.HiveJobs) {
     304          if (hiveJob.Job.State != JobState.Finished)
     305            throw new HiveEngineException("Job failed: " + hiveJob.Job.StateLog.Last().Exception);
     306
     307          var scope = ((IAtomicOperation)((EngineJob)hiveJob.ItemJob).InitialOperation).Scope;
     308          scopes[j++] = scope;
     309        }
     310        return scopes;
     311      }
     312      catch (OperationCanceledException e) {
     313        lock (locker) {
     314          if (jobIndices != null) DeleteHiveExperiment(hiveExperiment.Id);
     315        }
     316        throw e;
     317      }
     318      catch (Exception e) {
     319        lock (locker) {
     320          if (jobIndices != null) DeleteHiveExperiment(hiveExperiment.Id);
     321        }
     322        LogException(e);
     323        throw e;
     324      }
     325    }
     326
     327    private RefreshableHiveExperiment CreateHiveExperiment() {
     328      lock (locker) {
     329        var hiveExperiment = new HiveExperiment();
    240330        hiveExperiment.Name = "HiveEngine Run " + hiveExperiments.Count;
    241331        hiveExperiment.DateCreated = DateTime.Now;
     
    245335        refreshableHiveExperiment.IsControllable = false;
    246336        hiveExperiments.Add(refreshableHiveExperiment);
    247 
    248         // create upload-tasks
    249         var uploadTasks = new List<Task<Job>>();
    250         for (int i = 0; i < jobs.Length; i++) {
    251           hiveExperiment.HiveJobs.Add(new EngineHiveJob(jobs[i], parentScopeClone));
    252 
    253           // shuffle random variable to avoid the same random sequence in each operation; todo: does not yet work (it cannot find the random variable)
    254           IRandom random = FindRandomParameter(jobs[i].InitialOperation as IExecutionContext);
    255           if (random != null)
    256             random.Reset(random.Next());
    257         }
    258         ExperimentManagerClient.StartExperiment((e) => {
    259           LogException(e);
    260         }, refreshableHiveExperiment);
    261 
    262         // do polling until experiment is finished and all jobs are downloaded
    263         while (!refreshableHiveExperiment.AllJobsFinished()) {
    264           Thread.Sleep(500);
    265           this.ExecutionTimeOnHive = TimeSpan.FromMilliseconds(hiveExperiments.Sum(x => x.HiveExperiment.ExecutionTime.TotalMilliseconds));
    266           cancellationToken.ThrowIfCancellationRequested();
    267         }
    268         LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableHiveExperiment.ToString(), refreshableHiveExperiment.HiveExperiment.ExecutionTime));
    269 
    270         // get scopes
    271         int j = 0;
    272         foreach (var hiveJob in hiveExperiment.HiveJobs) {
    273           var scope = ((IAtomicOperation) ((EngineJob)hiveJob.ItemJob).InitialOperation).Scope;
    274           scopes[j++] = scope;
    275         }
    276         refreshableHiveExperiment.RefreshAutomatically = false;
    277         DeleteHiveExperiment(hiveExperiment.Id);
    278         ClearData(refreshableHiveExperiment);
    279         return scopes;
    280       }
    281       catch (OperationCanceledException e) {
    282         lock (locker) {
    283           if (jobIndices != null) DeleteHiveExperiment(hiveExperiment.Id);
    284         }
    285         throw e;
    286       }
    287       catch (Exception e) {
    288         lock (locker) {
    289           if (jobIndices != null) DeleteHiveExperiment(hiveExperiment.Id);
    290         }
    291         LogException(e);
    292         throw e;
    293       }
     337        return refreshableHiveExperiment;
     338      }
     339    }
     340
     341    private void DisposeHiveExperiment(RefreshableHiveExperiment refreshableHiveExperiment) {
     342      refreshableHiveExperiment.RefreshAutomatically = false;
     343      DeleteHiveExperiment(refreshableHiveExperiment.HiveExperiment.Id);
     344      ClearData(refreshableHiveExperiment);
    294345    }
    295346
     
    306357      }, 5, string.Format("Could not delete jobs"));
    307358    }
    308    
     359
    309360    private List<Guid> GetResourceIds() {
    310361      return ServiceLocator.Instance.CallHiveService(service => {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs

    r6267 r6357  
    103103                           where child.ParentJobId == ar.Job.JobId
    104104                           select child).Count() > 0
    105                     orderby ar.Job.Priority descending
     105                    orderby ar.Job.Priority, db.Random() descending
    106106                    select Convert.ToDto(ar.Job);
    107107        return count == 0 ? query.ToArray() : query.Take(count).ToArray();
     
    121121                       && ar.Job.CoresNeeded <= slave.FreeCores
    122122                       && ar.Job.MemoryNeeded <= slave.FreeMemory
    123                     orderby ar.Job.Priority descending
     123                    orderby ar.Job.Priority, db.Random() descending // take random job to avoid the race condition that occurs when this method is called concurrently (the same job would be returned)
    124124                    select Convert.ToDto(ar.Job);
    125125        var waitingJobs = (count == 0 ? query : query.Take(count)).ToArray();
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.cs

    r6229 r6357  
     1using System;
     2using System.Data.Linq.Mapping;
    13namespace HeuristicLab.Services.Hive.DataAccess {
    24  partial class SlaveStatistics {
     
    46
    57  partial class HiveDataContext {
     8    // source: http://stackoverflow.com/questions/648196/random-row-from-linq-to-sql
     9    [Function(Name = "NEWID", IsComposable = true)]
     10    public Guid Random() {
     11      // to prove not used by our C# code...
     12      throw new NotImplementedException();
     13    }
    614  }
    715}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs

    r6267 r6357  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Services.Hive.Common;
    26 using HeuristicLab.Services.Hive.Common.DataTransfer;
    27 using HeuristicLab.Services.Hive.Common.ServiceContracts;
    2825using Microsoft.VisualStudio.TestTools.UnitTesting;
    2926
    3027namespace HeuristicLab.Services.Hive.Tests {
    3128
     29  using HeuristicLab.Services.Hive.Common;
     30  using HeuristicLab.Services.Hive.Common.DataTransfer;
     31  using HeuristicLab.Services.Hive.Common.ServiceContracts;
    3232  using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
    3333
     
    304304    //      Name = "Slave " + i,
    305305    //      IsAllowedToCalculate = true,
    306     //      SlaveState = SlaveState.Idle,
     306    //      SlaveState = DT.SlaveState.Idle,
    307307    //      CpuSpeed = 2800,
    308308    //      FreeCores = 2,
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeartbeatManager.cs

    r6269 r6357  
    4141        // assign new job
    4242        if (heartbeat.AssignJob && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) {
    43           var availableJobs = dao.GetWaitingJobs(slave, 1);
    44           if (availableJobs.Count() > 0) {
    45             var job = availableJobs.First();
    46             actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob, job.Id));
    47             AssignJob(slave, job);
    48           }
     43          // this part needs to be in a serializable transaction to avoid race conditions
     44          //trans.UseTransaction(() => {
     45            var availableJobs = dao.GetWaitingJobs(slave, 1);
     46            if (availableJobs.Count() > 0) {
     47              var job = availableJobs.First();
     48              actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateJob, job.Id));
     49              AssignJob(slave, job);
     50            }
     51          //}, true);
    4952        }
    5053      }
Note: See TracChangeset for help on using the changeset viewer.