Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/08/11 16:38:28 (13 years ago)
Author:
ascheibe
Message:

#1233 more renaming for more consistency

Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3
Files:
10 edited
9 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Core.cs

    r6721 r6725  
    5050    private ServiceHost slaveComm;
    5151    private WcfService wcfService;
    52     private JobManager jobManager;
     52    private TaskManager taskManager;
    5353    private ConfigManager configManager;
    5454    private PluginManager pluginManager;
     
    5757      var log = new ThreadSafeLog(new Log(Settings.Default.MaxLogCount));
    5858      this.pluginManager = new PluginManager(WcfService.Instance, log);
    59       this.jobManager = new JobManager(pluginManager, log);
     59      this.taskManager = new TaskManager(pluginManager, log);
    6060      log.MessageAdded += new EventHandler<EventArgs<string>>(log_MessageAdded);
    6161
    62       RegisterJobManagerEvents();
    63 
    64       this.configManager = new ConfigManager(jobManager);
     62      RegisterTaskManagerEvents();
     63
     64      this.configManager = new ConfigManager(taskManager);
    6565      ConfigManager.Instance = this.configManager;
    6666    }
     
    7878        clientCom = SlaveClientCom.Instance.ClientCom;
    7979
    80         // delete all left over job directories
     80        // delete all left over task directories
    8181        pluginManager.CleanPluginTemp();
    8282        clientCom.LogMessage("Hive Slave started");
     
    149149    /// <param name="container">The container, containing the message</param>
    150150    private void DetermineAction(MessageContainer container) {
    151       clientCom.LogMessage(string.Format("Message: {0} for job: {1} ", container.Message.ToString(), container.TaskId));
     151      clientCom.LogMessage(string.Format("Message: {0} for task: {1} ", container.Message.ToString(), container.TaskId));
    152152
    153153      if (container is ExecutorMessageContainer<Guid>) {
     
    156156      } else if (container is MessageContainer) {
    157157        switch (container.Message) {
    158           case MessageContainer.MessageType.CalculateJob:
    159             CalculateJobAsync(container.TaskId);
    160             break;
    161           case MessageContainer.MessageType.AbortJob:
    162             AbortJobAsync(container.TaskId);
    163             break;
    164           case MessageContainer.MessageType.StopJob:
    165             StopJobAsync(container.TaskId);
    166             break;
    167           case MessageContainer.MessageType.PauseJob:
    168             PauseJobAsync(container.TaskId);
     158          case MessageContainer.MessageType.CalculateTask:
     159            CalculateTaskAsync(container.TaskId);
     160            break;
     161          case MessageContainer.MessageType.AbortTask:
     162            AbortTaskAsync(container.TaskId);
     163            break;
     164          case MessageContainer.MessageType.StopTask:
     165            StopTaskAsync(container.TaskId);
     166            break;
     167          case MessageContainer.MessageType.PauseTask:
     168            PauseTaskAsync(container.TaskId);
    169169            break;
    170170          case MessageContainer.MessageType.StopAll:
     
    195195    }
    196196
    197     private void CalculateJobAsync(Guid jobId) {
    198       TS.Task.Factory.StartNew(HandleCalculateJob, jobId)
     197    private void CalculateTaskAsync(Guid jobId) {
     198      TS.Task.Factory.StartNew(HandleCalculateTask, jobId)
    199199      .ContinueWith((t) => {
    200200        SlaveStatusInfo.IncrementExceptionOccured();
     
    203203    }
    204204
    205     private void StopJobAsync(Guid jobId) {
    206       TS.Task.Factory.StartNew(HandleStopJob, jobId)
     205    private void StopTaskAsync(Guid jobId) {
     206      TS.Task.Factory.StartNew(HandleStopTask, jobId)
    207207       .ContinueWith((t) => {
    208208         SlaveStatusInfo.IncrementExceptionOccured();
     
    211211    }
    212212
    213     private void PauseJobAsync(Guid jobId) {
    214       TS.Task.Factory.StartNew(HandlePauseJob, jobId)
     213    private void PauseTaskAsync(Guid jobId) {
     214      TS.Task.Factory.StartNew(HandlePauseTask, jobId)
    215215       .ContinueWith((t) => {
    216216         SlaveStatusInfo.IncrementExceptionOccured();
     
    219219    }
    220220
    221     private void AbortJobAsync(Guid jobId) {
    222       TS.Task.Factory.StartNew(HandleAbortJob, jobId)
     221    private void AbortTaskAsync(Guid jobId) {
     222      TS.Task.Factory.StartNew(HandleAbortTask, jobId)
    223223       .ContinueWith((t) => {
    224224         SlaveStatusInfo.IncrementExceptionOccured();
     
    227227    }
    228228
    229     private void HandleCalculateJob(object jobIdObj) {
    230       Guid jobId = (Guid)jobIdObj;
    231       Task job = null;
     229    private void HandleCalculateTask(object taskIdObj) {
     230      Guid taskId = (Guid)taskIdObj;
     231      Task task = null;
    232232      int usedCores = 0;
    233233      try {
    234         job = wcfService.GetJob(jobId);
    235         if (job == null) throw new JobNotFoundException(jobId);
    236         if (ConfigManager.Instance.GetFreeCores() < job.CoresNeeded) throw new OutOfCoresException();
    237         if (ConfigManager.GetFreeMemory() < job.MemoryNeeded) throw new OutOfMemoryException();
    238         SlaveStatusInfo.IncrementUsedCores(job.CoresNeeded); usedCores = job.CoresNeeded;
    239         TaskData jobData = wcfService.GetJobData(jobId);
    240         if (jobData == null) throw new JobDataNotFoundException(jobId);
    241         job = wcfService.UpdateJobState(jobId, TaskState.Calculating, null);
    242         if (job == null) throw new JobNotFoundException(jobId);
    243         jobManager.StartJobAsync(job, jobData);
    244       }
    245       catch (JobNotFoundException) {
     234        task = wcfService.GetJob(taskId);
     235        if (task == null) throw new TaskNotFoundException(taskId);
     236        if (ConfigManager.Instance.GetFreeCores() < task.CoresNeeded) throw new OutOfCoresException();
     237        if (ConfigManager.GetFreeMemory() < task.MemoryNeeded) throw new OutOfMemoryException();
     238        SlaveStatusInfo.IncrementUsedCores(task.CoresNeeded); usedCores = task.CoresNeeded;
     239        TaskData taskData = wcfService.GetJobData(taskId);
     240        if (taskData == null) throw new TaskDataNotFoundException(taskId);
     241        task = wcfService.UpdateJobState(taskId, TaskState.Calculating, null);
     242        if (task == null) throw new TaskNotFoundException(taskId);
     243        taskManager.StartTaskAsync(task, taskData);
     244      }
     245      catch (TaskNotFoundException) {
    246246        SlaveStatusInfo.DecrementUsedCores(usedCores);
    247247        throw;
    248248      }
    249       catch (JobDataNotFoundException) {
     249      catch (TaskDataNotFoundException) {
    250250        SlaveStatusInfo.DecrementUsedCores(usedCores);
    251251        throw;
    252252      }
    253       catch (JobAlreadyRunningException) {
     253      catch (TaskAlreadyRunningException) {
    254254        SlaveStatusInfo.DecrementUsedCores(usedCores);
    255255        throw;
    256256      }
    257257      catch (OutOfCoresException) {
    258         wcfService.UpdateJobState(jobId, TaskState.Waiting, "No more cores available");
     258        wcfService.UpdateJobState(taskId, TaskState.Waiting, "No more cores available");
    259259        throw;
    260260      }
    261261      catch (OutOfMemoryException) {
    262         wcfService.UpdateJobState(jobId, TaskState.Waiting, "No more memory available");
     262        wcfService.UpdateJobState(taskId, TaskState.Waiting, "No more memory available");
    263263        throw;
    264264      }
    265265      catch (Exception e) {
    266266        SlaveStatusInfo.DecrementUsedCores(usedCores);
    267         wcfService.UpdateJobState(jobId, TaskState.Waiting, e.ToString()); // unknown internal error - report and set waiting again
    268         throw;
    269       }
    270     }
    271 
    272     private void HandleStopJob(object jobIdObj) {
    273       Guid jobId = (Guid)jobIdObj;
    274       try {
    275         Task 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) {
     267        wcfService.UpdateJobState(taskId, TaskState.Waiting, e.ToString()); // unknown internal error - report and set waiting again
     268        throw;
     269      }
     270    }
     271
     272    private void HandleStopTask(object taskIdObj) {
     273      Guid taskId = (Guid)taskIdObj;
     274      try {
     275        Task task = wcfService.GetJob(taskId);
     276        if (task == null) throw new TaskNotFoundException(taskId);
     277        taskManager.StopTaskAsync(taskId);
     278      }
     279      catch (TaskNotFoundException) {
     280        throw;
     281      }
     282      catch (TaskNotRunningException) {
    283283        throw;
    284284      }
     
    288288    }
    289289
    290     private void HandlePauseJob(object jobIdObj) {
    291       Guid jobId = (Guid)jobIdObj;
    292       try {
    293         Task 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) {
     290    private void HandlePauseTask(object taskIdObj) {
     291      Guid taskId = (Guid)taskIdObj;
     292      try {
     293        Task task = wcfService.GetJob(taskId);
     294        if (task == null) throw new TaskNotFoundException(taskId);
     295        taskManager.PauseTaskAsync(taskId);
     296      }
     297      catch (TaskNotFoundException) {
     298        throw;
     299      }
     300      catch (TaskNotRunningException) {
    301301        throw;
    302302      }
     
    306306    }
    307307
    308     private void HandleAbortJob(object jobIdObj) {
    309       Guid jobId = (Guid)jobIdObj;
    310       try {
    311         jobManager.AbortJob(jobId);
    312       }
    313       catch (JobNotFoundException) {
    314         throw;
    315       }
    316     }
    317 
    318     #region JobManager Events
    319     private void RegisterJobManagerEvents() {
    320       this.jobManager.JobStarted += new EventHandler<EventArgs<SlaveJob>>(jobManager_JobStarted);
    321       this.jobManager.JobPaused += new EventHandler<EventArgs<SlaveJob, TaskData>>(jobManager_JobPaused);
    322       this.jobManager.JobStopped += new EventHandler<EventArgs<SlaveJob, TaskData>>(jobManager_JobStopped);
    323       this.jobManager.JobFailed += new EventHandler<EventArgs<Tuple<SlaveJob, TaskData, Exception>>>(jobManager_JobFailed);
    324       this.jobManager.ExceptionOccured += new EventHandler<EventArgs<SlaveJob, Exception>>(jobManager_ExceptionOccured);
    325       this.jobManager.JobAborted += new EventHandler<EventArgs<SlaveJob>>(jobManager_JobAborted);
    326     }
    327 
    328     private void jobManager_JobStarted(object sender, EventArgs<SlaveJob> e) {
     308    private void HandleAbortTask(object taskIdObj) {
     309      Guid taskId = (Guid)taskIdObj;
     310      try {
     311        taskManager.AbortTask(taskId);
     312      }
     313      catch (TaskNotFoundException) {
     314        throw;
     315      }
     316    }
     317
     318    #region TaskManager Events
     319    private void RegisterTaskManagerEvents() {
     320      this.taskManager.TaskStarted += new EventHandler<EventArgs<SlaveTask>>(taskManager_TaskStarted);
     321      this.taskManager.TaskPaused += new EventHandler<EventArgs<SlaveTask, TaskData>>(taskManager_TaskPaused);
     322      this.taskManager.TaskStopped += new EventHandler<EventArgs<SlaveTask, TaskData>>(taskManager_TaskStopped);
     323      this.taskManager.TaskFailed += new EventHandler<EventArgs<Tuple<SlaveTask, TaskData, Exception>>>(taskManager_TaskFailed);
     324      this.taskManager.ExceptionOccured += new EventHandler<EventArgs<SlaveTask, Exception>>(taskManager_ExceptionOccured);
     325      this.taskManager.TaskAborted += new EventHandler<EventArgs<SlaveTask>>(taskManager_TaskAborted);
     326    }
     327
     328    private void taskManager_TaskStarted(object sender, EventArgs<SlaveTask> e) {
    329329      // successfully started, everything is good
    330330    }
    331331
    332     private void jobManager_JobPaused(object sender, EventArgs<SlaveJob, TaskData> e) {
     332    private void taskManager_TaskPaused(object sender, EventArgs<SlaveTask, TaskData> e) {
    333333      try {
    334334        SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
    335335        heartbeatManager.AwakeHeartBeatThread();
    336         Task job = wcfService.GetJob(e.Value.JobId);
    337         if (job == null) throw new JobNotFoundException(e.Value.JobId);
    338         job.ExecutionTime = e.Value.ExecutionTime;
    339         TaskData jobData = e.Value.GetJobData();
    340         wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, TaskState.Paused);
    341       }
    342       catch (JobNotFoundException ex) {
     336        Task task = wcfService.GetJob(e.Value.TaskId);
     337        if (task == null) throw new TaskNotFoundException(e.Value.TaskId);
     338        task.ExecutionTime = e.Value.ExecutionTime;
     339        TaskData taskData = e.Value.GetTaskData();
     340        wcfService.UpdateJobData(task, taskData, configManager.GetClientInfo().Id, TaskState.Paused);
     341      }
     342      catch (TaskNotFoundException ex) {
    343343        clientCom.LogMessage(ex.ToString());
    344344      }
     
    348348    }
    349349
    350     private void jobManager_JobStopped(object sender, EventArgs<SlaveJob, TaskData> e) {
     350    private void taskManager_TaskStopped(object sender, EventArgs<SlaveTask, TaskData> e) {
    351351      try {
    352352        SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
    353353        heartbeatManager.AwakeHeartBeatThread();
    354         Task job = wcfService.GetJob(e.Value.JobId);
    355         if (job == null) throw new JobNotFoundException(e.Value.JobId);
    356         job.ExecutionTime = e.Value.ExecutionTime;
    357         TaskData jobData = e.Value.GetJobData();
    358         wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, TaskState.Finished);
    359       }
    360       catch (JobNotFoundException ex) {
     354        Task task = wcfService.GetJob(e.Value.TaskId);
     355        if (task == null) throw new TaskNotFoundException(e.Value.TaskId);
     356        task.ExecutionTime = e.Value.ExecutionTime;
     357        TaskData taskData = e.Value.GetTaskData();
     358        wcfService.UpdateJobData(task, taskData, configManager.GetClientInfo().Id, TaskState.Finished);
     359      }
     360      catch (TaskNotFoundException ex) {
    361361        clientCom.LogMessage(ex.ToString());
    362362      }
     
    366366    }
    367367
    368     private void jobManager_JobFailed(object sender, EventArgs<Tuple<SlaveJob, TaskData, Exception>> e) {
     368    private void taskManager_TaskFailed(object sender, EventArgs<Tuple<SlaveTask, TaskData, Exception>> e) {
    369369      try {
    370370        SlaveStatusInfo.DecrementUsedCores(e.Value.Item1.CoresNeeded);
    371371        heartbeatManager.AwakeHeartBeatThread();
    372         SlaveJob slaveJob = e.Value.Item1;
    373         TaskData jobData = e.Value.Item2;
     372        SlaveTask slaveTask = e.Value.Item1;
     373        TaskData taskData = e.Value.Item2;
    374374        Exception exception = e.Value.Item3;
    375375
    376         Task 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, TaskState.Failed, exception.ToString());
     376        Task task = wcfService.GetJob(slaveTask.TaskId);
     377        if (task == null) throw new TaskNotFoundException(slaveTask.TaskId);
     378        task.ExecutionTime = slaveTask.ExecutionTime;
     379        if (taskData != null) {
     380          wcfService.UpdateJobData(task, taskData, configManager.GetClientInfo().Id, TaskState.Failed, exception.ToString());
    381381        } else {
    382           wcfService.UpdateJobState(job.Id, TaskState.Failed, exception.ToString());
     382          wcfService.UpdateJobState(task.Id, TaskState.Failed, exception.ToString());
    383383        }
    384384        clientCom.LogMessage(exception.Message);
    385385      }
    386       catch (JobNotFoundException ex) {
     386      catch (TaskNotFoundException ex) {
    387387        SlaveStatusInfo.IncrementExceptionOccured();
    388388        clientCom.LogMessage(ex.ToString());
     
    394394    }
    395395
    396     private void jobManager_ExceptionOccured(object sender, EventArgs<SlaveJob, Exception> e) {
     396    private void taskManager_ExceptionOccured(object sender, EventArgs<SlaveTask, Exception> e) {
    397397      SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
    398398      SlaveStatusInfo.IncrementExceptionOccured();
    399399      heartbeatManager.AwakeHeartBeatThread();
    400       clientCom.LogMessage(string.Format("Exception occured for job {0}: {1}", e.Value.JobId, e.Value2.ToString()));
    401       wcfService.UpdateJobState(e.Value.JobId, TaskState.Waiting, e.Value2.ToString());
    402     }
    403 
    404     private void jobManager_JobAborted(object sender, EventArgs<SlaveJob> e) {
     400      clientCom.LogMessage(string.Format("Exception occured for task {0}: {1}", e.Value.TaskId, e.Value2.ToString()));
     401      wcfService.UpdateJobState(e.Value.TaskId, TaskState.Waiting, e.Value2.ToString());
     402    }
     403
     404    private void taskManager_TaskAborted(object sender, EventArgs<SlaveTask> e) {
    405405      SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
    406406    }
     
    418418    private void DoAbortAll() {
    419419      clientCom.LogMessage("Aborting all jobs.");
    420       foreach (Guid jobId in jobManager.JobIds) {
    421         AbortJobAsync(jobId);
     420      foreach (Guid taskId in taskManager.TaskIds) {
     421        AbortTaskAsync(taskId);
    422422      }
    423423    }
     
    428428    private void DoPauseAll() {
    429429      clientCom.LogMessage("Pausing all jobs.");
    430       foreach (Guid jobId in jobManager.JobIds) {
    431         PauseJobAsync(jobId);
     430      foreach (Guid taskId in taskManager.TaskIds) {
     431        PauseTaskAsync(taskId);
    432432      }
    433433    }
     
    438438    private void DoStopAll() {
    439439      clientCom.LogMessage("Stopping all jobs.");
    440       foreach (Guid jobId in jobManager.JobIds) {
    441         StopJobAsync(jobId);
     440      foreach (Guid taskId in taskManager.TaskIds) {
     441        StopTaskAsync(taskId);
    442442      }
    443443    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/SerializationException.cs

    r6357 r6725  
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    2525  public class SerializationException : Exception {
    26     public SerializationException() : base("Serializing job failed.") { }
     26    public SerializationException() : base("Serializing task failed.") { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/TaskAlreadyRunningException.cs

    r6721 r6725  
    2323
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    25   public class JobAlreadyRunningException : Exception {
    26     public JobAlreadyRunningException(Guid jobId) : base(string.Format("Task with Id {0} is already running.", jobId)) { }
     25  public class TaskAlreadyRunningException : Exception {
     26    public TaskAlreadyRunningException(Guid jobId) : base(string.Format("Task with Id {0} is already running.", jobId)) { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/TaskFailedException.cs

    r6721 r6725  
    2323
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    25   public class JobFailedException : Exception {
    26     public JobFailedException(string reason) : base(string.Format("Task failed with reason: {0}", reason)) { }
     25  public class TaskFailedException : Exception {
     26    public TaskFailedException(string reason) : base(string.Format("Task failed with reason: {0}", reason)) { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/TaskNotDataFoundException.cs

    r6721 r6725  
    2323
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    25   public class JobDataNotFoundException : Exception {
    26     public JobDataNotFoundException(Guid jobId) : base(string.Format("TaskData with TaskId {0} was not found on server.", jobId)) { }
     25  public class TaskDataNotFoundException : Exception {
     26    public TaskDataNotFoundException(Guid jobId) : base(string.Format("TaskData with TaskId {0} was not found on server.", jobId)) { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/TaskNotFoundException.cs

    r6721 r6725  
    2323
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    25   public class JobNotFoundException : Exception {
    26     public JobNotFoundException(Guid jobId) : base (string.Format("Task with Id {0} was not found on server.", jobId)) { }
     25  public class TaskNotFoundException : Exception {
     26    public TaskNotFoundException(Guid jobId) : base (string.Format("Task with Id {0} was not found on server.", jobId)) { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Exceptions/TaskNotRunningException.cs

    r6721 r6725  
    2323
    2424namespace HeuristicLab.Clients.Hive.SlaveCore {
    25   public class JobNotRunningException : Exception {
    26     public JobNotRunningException(Guid jobId) : base(string.Format("Task with Id {0} is not running.", jobId)) { }
     25  public class TaskNotRunningException : Exception {
     26    public TaskNotRunningException(Guid jobId) : base(string.Format("Task with Id {0} is not running.", jobId)) { }
    2727  }
    2828}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Executor.cs

    r6721 r6725  
    2929namespace HeuristicLab.Clients.Hive.SlaveCore {
    3030  /// <summary>
    31   /// The executor runs in the appdomain and handles the execution of an Hive job.
     31  /// The executor runs in the appdomain and handles the execution of an Hive task.
    3232  /// </summary>
    3333  public class Executor : MarshalByRefObject, IDisposable {
    34     private bool wasJobAborted = false;
     34    private bool wasTaskAborted = false;
    3535    private AutoResetEvent pauseStopSem = new AutoResetEvent(false);
    36     private AutoResetEvent startJobSem = new AutoResetEvent(false); // block start method call
    37     private AutoResetEvent jobStartedSem = new AutoResetEvent(false); // make pause or stop wait until start is finished
     36    private AutoResetEvent startTaskSem = new AutoResetEvent(false); // block start method call
     37    private AutoResetEvent taskStartedSem = new AutoResetEvent(false); // make pause or stop wait until start is finished
    3838    private ExecutorQueue executorQueue;
    39     private bool jobDataInvalid = false; // if true, the jobdata is not sent when the job is failed
    40     private IJob job;
     39    private bool taskDataInvalid = false; // if true, the jobdata is not sent when the task is failed
     40    private ITask task;
    4141    private DateTime creationTime;
    4242
    43     public Guid JobId { get; set; }
     43    public Guid TaskId { get; set; }
    4444    public int CoresNeeded { get; set; }
    4545    public int MemoryNeeded { get; set; }
     
    6363
    6464    private ExecutionState ExecutionState {
    65       get { return job != null ? job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; }
     65      get { return task != null ? task.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; }
    6666    }
    6767
    6868    public TimeSpan ExecutionTime {
    69       get { return job != null ? job.ExecutionTime : new TimeSpan(0, 0, 0); }
     69      get { return task != null ? task.ExecutionTime : new TimeSpan(0, 0, 0); }
    7070    }
    7171
     
    7979      try {
    8080        creationTime = DateTime.Now;
    81         job = PersistenceUtil.Deserialize<IJob>(serializedJob);
     81        task = PersistenceUtil.Deserialize<ITask>(serializedJob);
    8282
    8383        RegisterJobEvents();
    8484
    85         job.Start();
    86         if (!startJobSem.WaitOne(Settings.Default.ExecutorSemTimeouts)) {
    87           jobDataInvalid = true;
    88           throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired.");
     85        task.Start();
     86        if (!startTaskSem.WaitOne(Settings.Default.ExecutorSemTimeouts)) {
     87          taskDataInvalid = true;
     88          throw new TimeoutException("Timeout when starting the task. TaskStarted event was not fired.");
    8989        }
    9090      }
    9191      catch (Exception e) {
    9292        this.CurrentException = e;
    93         Job_JobFailed(this, new EventArgs<Exception>(e));
     93        Task_TaskFailed(this, new EventArgs<Exception>(e));
    9494      }
    9595      finally {
    96         jobStartedSem.Set();
     96        taskStartedSem.Set();
    9797      }
    9898    }
     
    100100    public void Pause() {
    101101      IsPausing = true;
    102       // wait until job is started. if this does not happen, the Task is null an we give up
    103       jobStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
    104       if (job == null) {
    105         CurrentException = new Exception("Pausing job " + this.JobId + ": Task is null");
     102      // wait until task is started. if this does not happen, the Task is null an we give up
     103      taskStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
     104      if (task == null) {
     105        CurrentException = new Exception("Pausing task " + this.TaskId + ": Task is null");
    106106        executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    107107        return;
    108108      }
    109109
    110       if (job.ExecutionState == ExecutionState.Started) {
     110      if (task.ExecutionState == ExecutionState.Started) {
    111111        try {
    112           job.Pause();
     112          task.Pause();
    113113          //we need to block the pause...
    114114          pauseStopSem.WaitOne();
    115115        }
    116116        catch (Exception ex) {
    117           CurrentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString());
     117          CurrentException = new Exception("Error pausing task " + this.TaskId + ": " + ex.ToString());
    118118          executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    119119        }
     
    123123    public void Stop() {
    124124      IsStopping = true;
    125       // wait until job is started. if this does not happen, the Task is null an we give up
    126       jobStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
    127       if (job == null) {
    128         CurrentException = new Exception("Stopping job " + this.JobId + ": Task is null");
     125      // wait until task is started. if this does not happen, the Task is null an we give up
     126      taskStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
     127      if (task == null) {
     128        CurrentException = new Exception("Stopping task " + this.TaskId + ": Task is null");
    129129        executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    130130      }
    131       wasJobAborted = true;
     131      wasTaskAborted = true;
    132132
    133133      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
    134134        try {
    135           job.Stop();
     135          task.Stop();
    136136          pauseStopSem.WaitOne();
    137137        }
    138138        catch (Exception ex) {
    139           CurrentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString());
     139          CurrentException = new Exception("Error stopping task " + this.TaskId + ": " + ex.ToString());
    140140          executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    141141        }
     
    144144
    145145    private void RegisterJobEvents() {
    146       job.JobStopped += new EventHandler(Job_JobStopped);
    147       job.JobFailed += new EventHandler(Job_JobFailed);
    148       job.JobPaused += new EventHandler(Job_JobPaused);
    149       job.JobStarted += new EventHandler(Job_JobStarted);
     146      task.TaskStopped += new EventHandler(Task_TaskStopped);
     147      task.TaskFailed += new EventHandler(Task_TaskFailed);
     148      task.TaskPaused += new EventHandler(Task_TaskPaused);
     149      task.TaskStarted += new EventHandler(Task_TaskStarted);
    150150    }
    151151
    152152    private void DeregisterJobEvents() {
    153       job.JobStopped -= new EventHandler(Job_JobStopped);
    154       job.JobFailed -= new EventHandler(Job_JobFailed);
    155       job.JobPaused -= new EventHandler(Job_JobPaused);
    156       job.JobStarted -= new EventHandler(Job_JobStarted);
     153      task.TaskStopped -= new EventHandler(Task_TaskStopped);
     154      task.TaskFailed -= new EventHandler(Task_TaskFailed);
     155      task.TaskPaused -= new EventHandler(Task_TaskPaused);
     156      task.TaskStarted -= new EventHandler(Task_TaskStarted);
    157157    }
    158158
    159159    #region Task Events
    160     private void Job_JobFailed(object sender, EventArgs e) {
     160    private void Task_TaskFailed(object sender, EventArgs e) {
    161161      IsStopping = true;
    162162      EventArgs<Exception> ex = (EventArgs<Exception>)e;
    163163      CurrentException = ex.Value;
    164       executorQueue.AddMessage(ExecutorMessageType.JobFailed);
    165     }
    166 
    167     private void Job_JobStopped(object sender, EventArgs e) {
     164      executorQueue.AddMessage(ExecutorMessageType.TaskFailed);
     165    }
     166
     167    private void Task_TaskStopped(object sender, EventArgs e) {
    168168      IsStopping = true;
    169       if (wasJobAborted) {
     169      if (wasTaskAborted) {
    170170        pauseStopSem.Set();
    171171      }
    172       executorQueue.AddMessage(ExecutorMessageType.JobStopped);
    173     }
    174 
    175     private void Job_JobPaused(object sender, EventArgs e) {
     172      executorQueue.AddMessage(ExecutorMessageType.TaskStopped);
     173    }
     174
     175    private void Task_TaskPaused(object sender, EventArgs e) {
    176176      IsPausing = true;
    177177      pauseStopSem.Set();
    178       executorQueue.AddMessage(ExecutorMessageType.JobPaused);
    179     }
    180 
    181     private void Job_JobStarted(object sender, EventArgs e) {
    182       startJobSem.Set();
    183       executorQueue.AddMessage(ExecutorMessageType.JobStarted);
     178      executorQueue.AddMessage(ExecutorMessageType.TaskPaused);
     179    }
     180
     181    private void Task_TaskStarted(object sender, EventArgs e) {
     182      startTaskSem.Set();
     183      executorQueue.AddMessage(ExecutorMessageType.TaskStarted);
    184184    }
    185185    #endregion
    186186
    187     public TaskData GetJobData() {
    188       if (jobDataInvalid) return null;
    189 
    190       if (job.ExecutionState == ExecutionState.Started) {
     187    public TaskData GetTaskData() {
     188      if (taskDataInvalid) return null;
     189
     190      if (task.ExecutionState == ExecutionState.Started) {
    191191        throw new InvalidStateException("Task is still running");
    192192      } else {
    193         TaskData jobData = new TaskData();
    194         if (job == null) {
    195           //send empty job and save exception
    196           jobData.Data = PersistenceUtil.Serialize(new TaskData());
     193        TaskData taskData = new TaskData();
     194        if (task == null) {
     195          //send empty task and save exception
     196          taskData.Data = PersistenceUtil.Serialize(new TaskData());
    197197          if (CurrentException == null) {
    198             CurrentException = new Exception("Task with id " + this.JobId + " is null, sending empty job");
     198            CurrentException = new Exception("Task with id " + this.TaskId + " is null, sending empty task");
    199199          }
    200200        } else {
    201           jobData.Data = PersistenceUtil.Serialize(job);
    202         }
    203         jobData.TaskId = JobId;
    204         return jobData;
     201          taskData.Data = PersistenceUtil.Serialize(task);
     202        }
     203        taskData.TaskId = TaskId;
     204        return taskData;
    205205      }
    206206    }
    207207
    208208    public void Dispose() {
    209       if (job != null)
     209      if (task != null)
    210210        DeregisterJobEvents();
    211       job = null;
     211      task = null;
    212212    }
    213213  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/ExecutorMessage.cs

    r6464 r6725  
    2626  [Serializable]
    2727  public enum ExecutorMessageType {
    28     JobStarted,
    29     JobPaused,
    30     JobStopped,
    31     JobFailed,
     28    TaskStarted,
     29    TaskPaused,
     30    TaskStopped,
     31    TaskFailed,
    3232    StopExecutorMonitoringThread,
    3333    ExceptionOccured
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/HeuristicLab.Clients.Hive.Slave-3.3.csproj

    r6701 r6725  
    101101  </ItemGroup>
    102102  <ItemGroup>
    103     <Compile Include="Exceptions\JobFailedException.cs" />
     103    <Compile Include="Exceptions\TaskFailedException.cs" />
    104104    <Compile Include="Manager\ConfigManager.cs" />
    105105    <Compile Include="Exceptions\SerializationException.cs" />
    106106    <Compile Include="Exceptions\OutOfMemoryException.cs" />
    107     <Compile Include="Exceptions\JobNotRunningException.cs" />
    108     <Compile Include="Exceptions\JobAlreadyRunningException.cs" />
    109     <Compile Include="Exceptions\JobNotFoundException.cs" />
    110     <Compile Include="Exceptions\JobNotDataFoundException.cs" />
     107    <Compile Include="Exceptions\TaskNotRunningException.cs" />
     108    <Compile Include="Exceptions\TaskAlreadyRunningException.cs" />
     109    <Compile Include="Exceptions\TaskNotFoundException.cs" />
     110    <Compile Include="Exceptions\TaskNotDataFoundException.cs" />
    111111    <Compile Include="ExecutorMessage.cs" />
    112112    <Compile Include="ExecutorQueue.cs" />
    113113    <Compile Include="IPluginProvider.cs" />
    114     <Compile Include="Manager\JobManager.cs" />
     114    <Compile Include="Manager\TaskManager.cs" />
    115115    <Compile Include="Exceptions\OutOfCoresException.cs" />
    116     <Compile Include="Exceptions\JobNotStartedException.cs" />
     116    <Compile Include="Exceptions\AppDomainNotCreatedException.cs" />
    117117    <Compile Include="SlaveClientCom.cs" />
    118118    <Compile Include="Core.cs" />
     
    121121    <Compile Include="Manager\HeartbeatManager.cs" />
    122122    <Compile Include="Exceptions\InvalidStateException.cs" />
    123     <Compile Include="JobStatus.cs" />
     123    <Compile Include="TaskStatus.cs" />
    124124    <Compile Include="MessageQueue.cs" />
    125125    <Compile Include="NetworkEnum.cs" />
     
    133133    <Compile Include="ServiceContracts\ISlaveCommunicationCallbacks.cs" />
    134134    <Compile Include="SlaveCommunicationService.cs" />
    135     <Compile Include="SlaveJob.cs" />
     135    <Compile Include="SlaveTask.cs" />
    136136    <Compile Include="SlaveStatusInfo.cs" />
    137137    <Compile Include="StatusCommons.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs

    r6521 r6725  
    4242    /// </summary>
    4343    public bool Asleep { get; set; }
    44     private JobManager jobManager;
     44    private TaskManager jobManager;
    4545    private Slave slave;
    4646    private PerformanceCounter cpuCounter;
     
    4949    /// Constructor for the singleton, must recover Guid, Calendar, ...
    5050    /// </summary>
    51     public ConfigManager(JobManager jobManager) {
     51    public ConfigManager(TaskManager jobManager) {
    5252      this.jobManager = jobManager;
    5353      cpuCounter = new PerformanceCounter();
     
    9595      st.Asleep = this.Asleep;
    9696
    97       st.JobsStarted = SlaveStatusInfo.JobsStarted;
    98       st.JobsAborted = SlaveStatusInfo.JobsAborted;
    99       st.JobsFinished = SlaveStatusInfo.JobsFinished;
    100       st.JobsFetched = SlaveStatusInfo.JobsFetched;
    101       st.JobsFailed = SlaveStatusInfo.JobsFailed;
     97      st.JobsStarted = SlaveStatusInfo.TasksStarted;
     98      st.JobsAborted = SlaveStatusInfo.TasksAborted;
     99      st.JobsFinished = SlaveStatusInfo.TasksFinished;
     100      st.JobsFetched = SlaveStatusInfo.TasksFetched;
     101      st.JobsFailed = SlaveStatusInfo.TasksFailed;
    102102      st.ExceptionsOccured = SlaveStatusInfo.ExceptionsOccured;
    103103
    104       st.Jobs = jobManager.GetExecutionTimes().Select(x => new JobStatus { JobId = x.Key, ExecutionTime = x.Value }).ToList();
     104      st.Jobs = jobManager.GetExecutionTimes().Select(x => new TaskStatus { TaskId = x.Key, ExecutionTime = x.Value }).ToList();
    105105
    106106      return st;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Manager/PluginManager.cs

    r6721 r6725  
    133133    /// <summary>
    134134    /// Updates the plugin cache with missing plugins and
    135     /// then copies the required plugins for the job.
     135    /// then copies the required plugins for the task.
    136136    /// </summary>       
    137     public void PreparePlugins(Task job, out string configFileName) {
     137    public void PreparePlugins(Task task, out string configFileName) {
    138138      lock (locker) {
    139         log.LogMessage("Fetching plugins for job " + job.Id);
     139        log.LogMessage("Fetching plugins for task " + task.Id);
    140140
    141141        List<Guid> missingGuids = new List<Guid>();
    142142        List<Plugin> neededPlugins = new List<Plugin>();
    143143        lock (cachedPluginsGuids) {
    144           foreach (Guid pluginId in job.PluginsNeededIds) {
     144          foreach (Guid pluginId in task.PluginsNeededIds) {
    145145            Plugin plugin = pluginService.GetPlugin(pluginId);
    146146            if (plugin != null) {
     
    168168            DoUpdateRun();
    169169          }
    170           CopyPluginsForJob(neededPlugins, job.Id, out configFileName);
     170          CopyPluginsForJob(neededPlugins, task.Id, out configFileName);
    171171        } else {
    172172          configFileName = "";
    173173        }
    174         log.LogMessage(string.Format("Fetched {0} plugins for job {1}", missingGuids.Count, job.Id));
     174        log.LogMessage(string.Format("Fetched {0} plugins for task {1}", missingGuids.Count, task.Id));
    175175      }
    176176    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/Manager/TaskManager.cs

    r6721 r6725  
    3030
    3131  /// <summary>
    32   /// Holds a list of slave jobs and manages access to this list.
    33   /// Forwards events from SlaveJob and forwards commands to SlaveJob.
     32  /// Holds a list of slave tasks and manages access to this list.
     33  /// Forwards events from SlaveTask and forwards commands to SlaveTask.
    3434  /// </summary>
    35   public class JobManager {
    36     private static ReaderWriterLockSlim slaveJobsLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
    37     private Dictionary<Guid, SlaveJob> slaveJobs;
     35  public class TaskManager {
     36    private static ReaderWriterLockSlim slaveTasksLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
     37    private Dictionary<Guid, SlaveTask> slaveTasks;
    3838    private ILog log;
    3939    private PluginManager pluginManager;
    4040
    41     public int JobCount {
     41    public int TaskCount {
    4242      get {
    43         slaveJobsLocker.EnterReadLock();
     43        slaveTasksLocker.EnterReadLock();
    4444        try {
    45           return slaveJobs.Count;
    46         }
    47         finally { slaveJobsLocker.ExitReadLock(); }
    48       }
    49     }
    50 
    51     public Guid[] JobIds {
     45          return slaveTasks.Count;
     46        }
     47        finally { slaveTasksLocker.ExitReadLock(); }
     48      }
     49    }
     50
     51    public Guid[] TaskIds {
    5252      get {
    53         slaveJobsLocker.EnterReadLock();
     53        slaveTasksLocker.EnterReadLock();
    5454        try {
    55           return slaveJobs.Keys.ToArray();
    56         }
    57         finally { slaveJobsLocker.ExitReadLock(); }
    58       }
    59     }
    60 
    61     public JobManager(PluginManager pluginCache, ILog log) {
     55          return slaveTasks.Keys.ToArray();
     56        }
     57        finally { slaveTasksLocker.ExitReadLock(); }
     58      }
     59    }
     60
     61    public TaskManager(PluginManager pluginCache, ILog log) {
    6262      this.pluginManager = pluginCache;
    6363      this.log = log;
    64       this.slaveJobs = new Dictionary<Guid, SlaveJob>();
     64      this.slaveTasks = new Dictionary<Guid, SlaveTask>();
    6565    }
    6666
    6767    #region Task Control methods
    68     public void StartJobAsync(Task job, TaskData jobData) {
    69       SlaveJob slaveJob = null;
    70       slaveJobsLocker.EnterUpgradeableReadLock();
    71       try {
    72         if (slaveJobs.ContainsKey(job.Id)) {
     68    public void StartTaskAsync(Task task, TaskData taskData) {
     69      SlaveTask slaveTask = null;
     70      slaveTasksLocker.EnterUpgradeableReadLock();
     71      try {
     72        if (slaveTasks.ContainsKey(task.Id)) {
    7373          SlaveStatusInfo.IncrementExceptionOccured();
    74           throw new JobAlreadyRunningException(job.Id);
     74          throw new TaskAlreadyRunningException(task.Id);
    7575        } else {
    76           slaveJob = new SlaveJob(pluginManager, job.CoresNeeded, log);
    77           AddSlaveJob(job, slaveJob);
    78           SlaveStatusInfo.IncrementJobsFetched();
    79         }
    80       }
    81       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    82 
    83       if (slaveJob != null) {
     76          slaveTask = new SlaveTask(pluginManager, task.CoresNeeded, log);
     77          AddSlaveTask(task, slaveTask);
     78          SlaveStatusInfo.IncrementTasksFetched();
     79        }
     80      }
     81      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     82
     83      if (slaveTask != null) {
    8484        try {
    85           slaveJob.StartJobAsync(job, jobData);
     85          slaveTask.StartJobAsync(task, taskData);
    8686        }
    8787        catch (Exception) {
    88           RemoveSlaveJob(job.Id, slaveJob); // clean up and rethrow
    89           slaveJob.DisposeAppDomain();
     88          RemoveSlaveTask(task.Id, slaveTask); // clean up and rethrow
     89          slaveTask.DisposeAppDomain();
    9090          throw;
    9191        }
     
    9393    }
    9494
    95     public void PauseJobAsync(Guid jobId) {
    96       slaveJobsLocker.EnterUpgradeableReadLock();
    97       try {
    98         if (!slaveJobs.ContainsKey(jobId)) throw new JobNotRunningException(jobId);
    99         SlaveJob slaveJob = slaveJobs[jobId];
    100         slaveJob.PauseJob();
    101       }
    102       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    103     }
    104 
    105     public void StopJobAsync(Guid jobId) {
    106       slaveJobsLocker.EnterUpgradeableReadLock();
    107       try {
    108         if (!slaveJobs.ContainsKey(jobId)) throw new JobNotRunningException(jobId);
    109         SlaveJob slaveJob = slaveJobs[jobId];
    110         slaveJob.StopJob();
    111       }
    112       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    113     }
    114 
    115     public void AbortJob(Guid jobId) {
    116       SlaveJob slaveJob = null;
    117       slaveJobsLocker.EnterUpgradeableReadLock();
    118       try {
    119         if (!slaveJobs.ContainsKey(jobId)) throw new JobNotRunningException(jobId);
    120         slaveJob = slaveJobs[jobId];
    121         if (!slaveJob.IsPrepared) throw new AppDomainNotCreatedException();
    122         RemoveSlaveJob(jobId, slaveJob);
    123       }
    124       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    125       slaveJob.DisposeAppDomain();
    126       SlaveStatusInfo.IncrementJobsAborted();
    127       OnJobAborted(slaveJob);
    128     }
    129 
    130     public void PauseAllJobsAsync() {
    131       slaveJobsLocker.EnterUpgradeableReadLock();
    132       try {
    133         foreach (var slaveJob in slaveJobs.Values) {
    134           slaveJob.PauseJob();
    135         }
    136       }
    137       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    138     }
    139 
    140     public void StopAllJobsAsync() {
    141       slaveJobsLocker.EnterUpgradeableReadLock();
    142       try {
    143         foreach (var slaveJob in slaveJobs.Values) {
    144           slaveJob.StopJob();
    145         }
    146       }
    147       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    148     }
    149 
    150     public void AbortAllJobs() {
    151       slaveJobsLocker.EnterUpgradeableReadLock();
    152       try {
    153         foreach (var slaveJob in slaveJobs.Values.ToArray()) {
    154           AbortJob(slaveJob.JobId);
    155         }
    156       }
    157       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
     95    public void PauseTaskAsync(Guid taskId) {
     96      slaveTasksLocker.EnterUpgradeableReadLock();
     97      try {
     98        if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId);
     99        SlaveTask slaveTask = slaveTasks[taskId];
     100        slaveTask.PauseTask();
     101      }
     102      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     103    }
     104
     105    public void StopTaskAsync(Guid taskId) {
     106      slaveTasksLocker.EnterUpgradeableReadLock();
     107      try {
     108        if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId);
     109        SlaveTask slaveTask = slaveTasks[taskId];
     110        slaveTask.StopTask();
     111      }
     112      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     113    }
     114
     115    public void AbortTask(Guid taskId) {
     116      SlaveTask slaveTask = null;
     117      slaveTasksLocker.EnterUpgradeableReadLock();
     118      try {
     119        if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId);
     120        slaveTask = slaveTasks[taskId];
     121        if (!slaveTask.IsPrepared) throw new AppDomainNotCreatedException();
     122        RemoveSlaveTask(taskId, slaveTask);
     123      }
     124      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     125      slaveTask.DisposeAppDomain();
     126      SlaveStatusInfo.IncrementTasksAborted();
     127      OnTaskAborted(slaveTask);
     128    }
     129
     130    public void PauseAllTasksAsync() {
     131      slaveTasksLocker.EnterUpgradeableReadLock();
     132      try {
     133        foreach (var slaveTask in slaveTasks.Values) {
     134          slaveTask.PauseTask();
     135        }
     136      }
     137      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     138    }
     139
     140    public void StopAllTasksAsync() {
     141      slaveTasksLocker.EnterUpgradeableReadLock();
     142      try {
     143        foreach (var slaveTask in slaveTasks.Values) {
     144          slaveTask.StopTask();
     145        }
     146      }
     147      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     148    }
     149
     150    public void AbortAllTasks() {
     151      slaveTasksLocker.EnterUpgradeableReadLock();
     152      try {
     153        foreach (var slaveTask in slaveTasks.Values.ToArray()) {
     154          AbortTask(slaveTask.TaskId);
     155        }
     156      }
     157      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
    158158    }
    159159    #endregion
    160160
    161     #region Add/Remove SlaveJob
    162     private void AddSlaveJob(Task job, SlaveJob slaveJob) {
    163       slaveJobsLocker.EnterWriteLock();
    164       try {
    165         slaveJobs.Add(job.Id, slaveJob);
    166         RegisterSlaveJobEvents(slaveJob);
    167       }
    168       finally { slaveJobsLocker.ExitWriteLock(); }
    169     }
    170 
    171     private void RemoveSlaveJob(Guid jobId, SlaveJob slaveJob) {
    172       slaveJobsLocker.EnterWriteLock();
    173       try {
    174         slaveJobs.Remove(jobId);
    175         DeregisterSlaveJobEvents(slaveJob);
    176       }
    177       finally { slaveJobsLocker.ExitWriteLock(); }
     161    #region Add/Remove SlaveTask
     162    private void AddSlaveTask(Task task, SlaveTask slaveTask) {
     163      slaveTasksLocker.EnterWriteLock();
     164      try {
     165        slaveTasks.Add(task.Id, slaveTask);
     166        RegisterSlaveTaskEvents(slaveTask);
     167      }
     168      finally { slaveTasksLocker.ExitWriteLock(); }
     169    }
     170
     171    private void RemoveSlaveTask(Guid taskId, SlaveTask slaveTask) {
     172      slaveTasksLocker.EnterWriteLock();
     173      try {
     174        slaveTasks.Remove(taskId);
     175        DeregisterSlaveTaskEvents(slaveTask);
     176      }
     177      finally { slaveTasksLocker.ExitWriteLock(); }
    178178    }
    179179    #endregion
    180180
    181     #region SlaveJob Events
    182     private void RegisterSlaveJobEvents(SlaveJob slaveJob) {
    183       slaveJob.JobStarted += new EventHandler<EventArgs<Guid>>(slaveJob_JobStarted);
    184       slaveJob.JobPaused += new EventHandler<EventArgs<Guid>>(slaveJob_JobPaused);
    185       slaveJob.JobStopped += new EventHandler<EventArgs<Guid>>(slaveJob_JobStopped);
    186       slaveJob.JobFailed += new EventHandler<EventArgs<Guid, Exception>>(slaveJob_JobFailed);
    187       slaveJob.ExceptionOccured += new EventHandler<EventArgs<Guid, Exception>>(slaveJob_ExceptionOccured);
    188     }
    189 
    190     private void DeregisterSlaveJobEvents(SlaveJob slaveJob) {
    191       slaveJob.JobStarted -= new EventHandler<EventArgs<Guid>>(slaveJob_JobStarted);
    192       slaveJob.JobPaused -= new EventHandler<EventArgs<Guid>>(slaveJob_JobPaused);
    193       slaveJob.JobStopped -= new EventHandler<EventArgs<Guid>>(slaveJob_JobStopped);
    194       slaveJob.JobFailed -= new EventHandler<EventArgs<Guid, Exception>>(slaveJob_JobFailed);
    195       slaveJob.ExceptionOccured -= new EventHandler<EventArgs<Guid, Exception>>(slaveJob_ExceptionOccured);
    196     }
    197 
    198     private void slaveJob_JobStarted(object sender, EventArgs<Guid> e) {
    199       SlaveJob slaveJob;
    200       slaveJobsLocker.EnterUpgradeableReadLock();
    201       try {
    202         slaveJob = slaveJobs[e.Value];
    203       }
    204       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    205 
    206       SlaveStatusInfo.IncrementJobsStarted();
    207       OnJobStarted(slaveJob);
    208     }
    209 
    210     private void slaveJob_JobPaused(object sender, EventArgs<Guid> e) {
    211       SlaveJob slaveJob;
    212       slaveJobsLocker.EnterUpgradeableReadLock();
    213       try {
    214         slaveJob = slaveJobs[e.Value];
    215         RemoveSlaveJob(e.Value, slaveJob);
    216       }
    217       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    218 
    219       TaskData jobData = null;
    220       try {
    221         jobData = slaveJob.GetJobData();
    222         if (jobData == null) throw new SerializationException();
    223         SlaveStatusInfo.IncrementJobsFinished();
    224         OnJobPaused(slaveJob, jobData);
     181    #region SlaveTask Events
     182    private void RegisterSlaveTaskEvents(SlaveTask slaveTask) {
     183      slaveTask.TaskStarted += new EventHandler<EventArgs<Guid>>(slaveTask_TaskStarted);
     184      slaveTask.TaskPaused += new EventHandler<EventArgs<Guid>>(slaveTask_TaskPaused);
     185      slaveTask.TaskStopped += new EventHandler<EventArgs<Guid>>(slaveTask_TaskStopped);
     186      slaveTask.TaskFailed += new EventHandler<EventArgs<Guid, Exception>>(slaveTask_TaskFailed);
     187      slaveTask.ExceptionOccured += new EventHandler<EventArgs<Guid, Exception>>(slaveTask_ExceptionOccured);
     188    }
     189
     190    private void DeregisterSlaveTaskEvents(SlaveTask slaveTask) {
     191      slaveTask.TaskStarted -= new EventHandler<EventArgs<Guid>>(slaveTask_TaskStarted);
     192      slaveTask.TaskPaused -= new EventHandler<EventArgs<Guid>>(slaveTask_TaskPaused);
     193      slaveTask.TaskStopped -= new EventHandler<EventArgs<Guid>>(slaveTask_TaskStopped);
     194      slaveTask.TaskFailed -= new EventHandler<EventArgs<Guid, Exception>>(slaveTask_TaskFailed);
     195      slaveTask.ExceptionOccured -= new EventHandler<EventArgs<Guid, Exception>>(slaveTask_ExceptionOccured);
     196    }
     197
     198    private void slaveTask_TaskStarted(object sender, EventArgs<Guid> e) {
     199      SlaveTask slaveTask;
     200      slaveTasksLocker.EnterUpgradeableReadLock();
     201      try {
     202        slaveTask = slaveTasks[e.Value];
     203      }
     204      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     205
     206      SlaveStatusInfo.IncrementTasksStarted();
     207      OnTaskStarted(slaveTask);
     208    }
     209
     210    private void slaveTask_TaskPaused(object sender, EventArgs<Guid> e) {
     211      SlaveTask slaveTask;
     212      slaveTasksLocker.EnterUpgradeableReadLock();
     213      try {
     214        slaveTask = slaveTasks[e.Value];
     215        RemoveSlaveTask(e.Value, slaveTask);
     216      }
     217      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     218
     219      TaskData taskData = null;
     220      try {
     221        taskData = slaveTask.GetTaskData();
     222        if (taskData == null) throw new SerializationException();
     223        SlaveStatusInfo.IncrementTasksFinished();
     224        OnTaskPaused(slaveTask, taskData);
    225225      }
    226226      catch (Exception ex) {
    227         RemoveSlaveJob(e.Value, slaveJob);
    228         SlaveStatusInfo.IncrementJobsFailed();
    229         OnJobFailed(slaveJob, jobData, ex);
    230       }
    231     }
    232 
    233     private void slaveJob_JobStopped(object sender, EventArgs<Guid> e) {
    234       SlaveJob slaveJob;
    235       slaveJobsLocker.EnterUpgradeableReadLock();
    236       try {
    237         slaveJob = slaveJobs[e.Value];
    238         RemoveSlaveJob(e.Value, slaveJob);
    239       }
    240       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    241 
    242       TaskData jobData = null;
    243       try {
    244         jobData = slaveJob.GetJobData();
    245         if (jobData == null) throw new SerializationException();
    246         SlaveStatusInfo.IncrementJobsFinished();
    247         OnJobStopped(slaveJob, jobData);
     227        RemoveSlaveTask(e.Value, slaveTask);
     228        SlaveStatusInfo.IncrementTasksFailed();
     229        OnTaskFailed(slaveTask, taskData, ex);
     230      }
     231    }
     232
     233    private void slaveTask_TaskStopped(object sender, EventArgs<Guid> e) {
     234      SlaveTask slaveTask;
     235      slaveTasksLocker.EnterUpgradeableReadLock();
     236      try {
     237        slaveTask = slaveTasks[e.Value];
     238        RemoveSlaveTask(e.Value, slaveTask);
     239      }
     240      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     241
     242      TaskData taskData = null;
     243      try {
     244        taskData = slaveTask.GetTaskData();
     245        if (taskData == null) throw new SerializationException();
     246        SlaveStatusInfo.IncrementTasksFinished();
     247        OnTaskStopped(slaveTask, taskData);
    248248      }
    249249      catch (Exception ex) {
    250         RemoveSlaveJob(e.Value, slaveJob);
    251         SlaveStatusInfo.IncrementJobsFailed();
    252         OnJobFailed(slaveJob, jobData, ex);
    253       }
    254     }
    255 
    256     private void slaveJob_JobFailed(object sender, EventArgs<Guid, Exception> e) {
    257       SlaveJob slaveJob;
    258       slaveJobsLocker.EnterUpgradeableReadLock();
    259       try {
    260         slaveJob = slaveJobs[e.Value];
    261         RemoveSlaveJob(e.Value, slaveJob);
    262       }
    263       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
    264 
    265       TaskData jobData = null;
    266       try {
    267         jobData = slaveJob.GetJobData();
    268         if (jobData == null) throw new SerializationException();
    269       }
    270       catch { /* jobData will be null */ }
    271       SlaveStatusInfo.IncrementJobsFailed();
    272       OnJobFailed(slaveJob, jobData, e.Value2);
    273     }
    274 
    275     private void slaveJob_ExceptionOccured(object sender, EventArgs<Guid, Exception> e) {
    276       SlaveJob slaveJob;
    277       slaveJobsLocker.EnterUpgradeableReadLock();
    278       try {
    279         slaveJob = slaveJobs[e.Value];
    280         RemoveSlaveJob(e.Value, slaveJob);
    281       }
    282       finally { slaveJobsLocker.ExitUpgradeableReadLock(); }
     250        RemoveSlaveTask(e.Value, slaveTask);
     251        SlaveStatusInfo.IncrementTasksFailed();
     252        OnTaskFailed(slaveTask, taskData, ex);
     253      }
     254    }
     255
     256    private void slaveTask_TaskFailed(object sender, EventArgs<Guid, Exception> e) {
     257      SlaveTask slaveTask;
     258      slaveTasksLocker.EnterUpgradeableReadLock();
     259      try {
     260        slaveTask = slaveTasks[e.Value];
     261        RemoveSlaveTask(e.Value, slaveTask);
     262      }
     263      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
     264
     265      TaskData taskData = null;
     266      try {
     267        taskData = slaveTask.GetTaskData();
     268        if (taskData == null) throw new SerializationException();
     269      }
     270      catch { /* taskData will be null */ }
     271      SlaveStatusInfo.IncrementTasksFailed();
     272      OnTaskFailed(slaveTask, taskData, e.Value2);
     273    }
     274
     275    private void slaveTask_ExceptionOccured(object sender, EventArgs<Guid, Exception> e) {
     276      SlaveTask slaveTask;
     277      slaveTasksLocker.EnterUpgradeableReadLock();
     278      try {
     279        slaveTask = slaveTasks[e.Value];
     280        RemoveSlaveTask(e.Value, slaveTask);
     281      }
     282      finally { slaveTasksLocker.ExitUpgradeableReadLock(); }
    283283
    284284      SlaveStatusInfo.IncrementExceptionOccured();
    285       OnExceptionOccured(slaveJob, e.Value2);
     285      OnExceptionOccured(slaveTask, e.Value2);
    286286    }
    287287    #endregion
    288288
    289289    #region EventHandler
    290     public event EventHandler<EventArgs<SlaveJob>> JobStarted;
    291     private void OnJobStarted(SlaveJob slaveJob) {
    292       var handler = JobStarted;
    293       if (handler != null) handler(this, new EventArgs<SlaveJob>(slaveJob));
    294     }
    295 
    296     public event EventHandler<EventArgs<SlaveJob, TaskData>> JobStopped;
    297     private void OnJobStopped(SlaveJob slaveJob, TaskData jobData) {
    298       var handler = JobStopped;
    299       if (handler != null) handler(this, new EventArgs<SlaveJob, TaskData>(slaveJob, jobData));
    300     }
    301 
    302     public event EventHandler<EventArgs<SlaveJob, TaskData>> JobPaused;
    303     private void OnJobPaused(SlaveJob slaveJob, TaskData jobData) {
    304       var handler = JobPaused;
    305       if (handler != null) handler(this, new EventArgs<SlaveJob, TaskData>(slaveJob, jobData));
    306     }
    307 
    308     public event EventHandler<EventArgs<Tuple<SlaveJob, TaskData, Exception>>> JobFailed;
    309     private void OnJobFailed(SlaveJob slaveJob, TaskData jobData, Exception exception) {
    310       var handler = JobFailed;
    311       if (handler != null) handler(this, new EventArgs<Tuple<SlaveJob, TaskData, Exception>>(new Tuple<SlaveJob, TaskData, Exception>(slaveJob, jobData, exception)));
    312     }
    313 
    314     public event EventHandler<EventArgs<SlaveJob, Exception>> ExceptionOccured;
    315     private void OnExceptionOccured(SlaveJob slaveJob, Exception exception) {
     290    public event EventHandler<EventArgs<SlaveTask>> TaskStarted;
     291    private void OnTaskStarted(SlaveTask slaveTask) {
     292      var handler = TaskStarted;
     293      if (handler != null) handler(this, new EventArgs<SlaveTask>(slaveTask));
     294    }
     295
     296    public event EventHandler<EventArgs<SlaveTask, TaskData>> TaskStopped;
     297    private void OnTaskStopped(SlaveTask slaveTask, TaskData taskData) {
     298      var handler = TaskStopped;
     299      if (handler != null) handler(this, new EventArgs<SlaveTask, TaskData>(slaveTask, taskData));
     300    }
     301
     302    public event EventHandler<EventArgs<SlaveTask, TaskData>> TaskPaused;
     303    private void OnTaskPaused(SlaveTask slaveTask, TaskData taskData) {
     304      var handler = TaskPaused;
     305      if (handler != null) handler(this, new EventArgs<SlaveTask, TaskData>(slaveTask, taskData));
     306    }
     307
     308    public event EventHandler<EventArgs<Tuple<SlaveTask, TaskData, Exception>>> TaskFailed;
     309    private void OnTaskFailed(SlaveTask slaveTask, TaskData taskData, Exception exception) {
     310      var handler = TaskFailed;
     311      if (handler != null) handler(this, new EventArgs<Tuple<SlaveTask, TaskData, Exception>>(new Tuple<SlaveTask, TaskData, Exception>(slaveTask, taskData, exception)));
     312    }
     313
     314    public event EventHandler<EventArgs<SlaveTask, Exception>> ExceptionOccured;
     315    private void OnExceptionOccured(SlaveTask slaveTask, Exception exception) {
    316316      var handler = ExceptionOccured;
    317       if (handler != null) handler(this, new EventArgs<SlaveJob, Exception>(slaveJob, exception));
    318     }
    319 
    320     public event EventHandler<EventArgs<SlaveJob>> JobAborted;
    321     private void OnJobAborted(SlaveJob slaveJob) {
    322       var handler = JobAborted;
    323       if (handler != null) handler(this, new EventArgs<SlaveJob>(slaveJob));
     317      if (handler != null) handler(this, new EventArgs<SlaveTask, Exception>(slaveTask, exception));
     318    }
     319
     320    public event EventHandler<EventArgs<SlaveTask>> TaskAborted;
     321    private void OnTaskAborted(SlaveTask slaveTask) {
     322      var handler = TaskAborted;
     323      if (handler != null) handler(this, new EventArgs<SlaveTask>(slaveTask));
    324324    }
    325325    #endregion
    326326
    327327    public Dictionary<Guid, TimeSpan> GetExecutionTimes() {
    328       slaveJobsLocker.EnterReadLock();
    329       try {
    330         return slaveJobs.ToDictionary(x => x.Key, x => x.Value.ExecutionTime);
    331       }
    332       finally { slaveJobsLocker.ExitReadLock(); }
     328      slaveTasksLocker.EnterReadLock();
     329      try {
     330        return slaveTasks.ToDictionary(x => x.Key, x => x.Value.ExecutionTime);
     331      }
     332      finally { slaveTasksLocker.ExitReadLock(); }
    333333    }
    334334  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/SlaveStatusInfo.cs

    r6371 r6725  
    2626  public class SlaveStatusInfo {
    2727    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
     28    private static int tasksFetched;  // number of fetched jobs
     29    private static int tasksStarted;  // number of started jobs
     30    private static int tasksFinished; // everything went fine
     31    private static int tasksAborted;  // server sent abort
     32    private static int tasksFailed;   // tasks that failed in the sandbox
     33    private static int exceptionsOccured; // number jobs failed caused by the business logic, not a faulted task
    3434    private static int usedCores;    // number of cores currently used
    3535
     
    4040    }
    4141
    42     public static int JobsStarted {
    43       get { return jobsStarted; }
     42    public static int TasksStarted {
     43      get { return tasksStarted; }
    4444    }
    4545
    46     public static int JobsFinished {
    47       get { return jobsFinished; }
     46    public static int TasksFinished {
     47      get { return tasksFinished; }
    4848    }
    4949
    50     public static int JobsAborted {
    51       get { return jobsAborted; }
     50    public static int TasksAborted {
     51      get { return tasksAborted; }
    5252    }
    5353
    54     public static int JobsFetched {
    55       get { return jobsFetched; }
     54    public static int TasksFetched {
     55      get { return tasksFetched; }
    5656    }
    5757
    58     public static int JobsFailed {
    59       get { return jobsFailed; }
     58    public static int TasksFailed {
     59      get { return tasksFailed; }
    6060    }
    6161
     
    6464    }
    6565
    66     public static void IncrementJobsStarted() {
    67       Interlocked.Increment(ref jobsStarted);
     66    public static void IncrementTasksStarted() {
     67      Interlocked.Increment(ref tasksStarted);
    6868    }
    6969
    70     public static void IncrementJobsFinished() {
    71       Interlocked.Increment(ref jobsFinished);
     70    public static void IncrementTasksFinished() {
     71      Interlocked.Increment(ref tasksFinished);
    7272    }
    7373
    74     public static void IncrementJobsFailed() {
    75       Interlocked.Increment(ref jobsFailed);
     74    public static void IncrementTasksFailed() {
     75      Interlocked.Increment(ref tasksFailed);
    7676    }
    7777
    78     public static void IncrementJobsAborted() {
    79       Interlocked.Increment(ref jobsAborted);
     78    public static void IncrementTasksAborted() {
     79      Interlocked.Increment(ref tasksAborted);
    8080    }
    8181
    82     public static void IncrementJobsFetched() {
    83       Interlocked.Increment(ref jobsFetched);
     82    public static void IncrementTasksFetched() {
     83      Interlocked.Increment(ref tasksFetched);
    8484    }
    8585
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/SlaveTask.cs

    r6721 r6725  
    3131
    3232  /// <summary>
    33   ///  Manages a single job and it's appdomain.
     33  ///  Manages a single task and it's appdomain.
    3434  /// </summary>
    35   public class SlaveJob : MarshalByRefObject {
     35  public class SlaveTask : MarshalByRefObject {
    3636    private Executor executor;
    3737    private AppDomain appDomain;
     
    4141    private PluginManager pluginManager;
    4242    private ILog log;
    43     public Guid JobId { get; private set; }
     43    public Guid TaskId { get; private set; }
    4444    public bool IsPrepared { get; private set; }
    4545
     
    5454    }
    5555
    56     public SlaveJob(PluginManager pluginManager, int coresNeeded, ILog log) {
     56    public SlaveTask(PluginManager pluginManager, int coresNeeded, ILog log) {
    5757      this.pluginManager = pluginManager;
    5858      this.coresNeeded = coresNeeded;
     
    6363    }
    6464
    65     public void StartJobAsync(Task job, TaskData jobData) {
     65    public void StartJobAsync(Task task, TaskData taskData) {
    6666      try {
    67         this.JobId = job.Id;
    68         Prepare(job);
    69         StartJobInAppDomain(jobData);
     67        this.TaskId = task.Id;
     68        Prepare(task);
     69        StartTaskInAppDomain(taskData);
    7070      }
    7171      catch (Exception) {
     
    7676    }
    7777
    78     public void PauseJob() {
     78    public void PauseTask() {
    7979      if (!IsPrepared) throw new AppDomainNotCreatedException();
    8080      if (!executor.IsPausing && !executor.IsStopping) executor.Pause();
    8181    }
    8282
    83     public void StopJob() {
     83    public void StopTask() {
    8484      if (!IsPrepared) throw new AppDomainNotCreatedException();
    8585      if (!executor.IsPausing && !executor.IsStopping) executor.Stop();
    8686    }
    8787
    88     private void Prepare(Task job) {
    89       string pluginDir = Path.Combine(pluginManager.PluginTempBaseDir, job.Id.ToString());
     88    private void Prepare(Task task) {
     89      string pluginDir = Path.Combine(pluginManager.PluginTempBaseDir, task.Id.ToString());
    9090      string configFileName;
    91       pluginManager.PreparePlugins(job, out configFileName);
    92       appDomain = CreateAppDomain(job, pluginDir, configFileName);
     91      pluginManager.PreparePlugins(task, out configFileName);
     92      appDomain = CreateAppDomain(task, pluginDir, configFileName);
    9393      IsPrepared = true;
    9494    }
    9595
    96     private AppDomain CreateAppDomain(Task job, String pluginDir, string configFileName) {
    97       if (job.IsPrivileged) {
    98         appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
     96    private AppDomain CreateAppDomain(Task task, String pluginDir, string configFileName) {
     97      if (task.IsPrivileged) {
     98        appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(task.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    9999      } else {
    100         appDomain = SandboxManager.CreateAndInitSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
     100        appDomain = SandboxManager.CreateAndInitSandbox(task.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    101101      }
    102102      appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
     
    105105      executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    106106
    107       executor.JobId = job.Id;
    108       executor.CoresNeeded = job.CoresNeeded;
    109       executor.MemoryNeeded = job.MemoryNeeded;
     107      executor.TaskId = task.Id;
     108      executor.CoresNeeded = task.CoresNeeded;
     109      executor.MemoryNeeded = task.MemoryNeeded;
    110110      return appDomain;
    111111    }
    112112
    113     private void StartJobInAppDomain(TaskData jobData) {
    114       executor.Start(jobData.Data);
     113    private void StartTaskInAppDomain(TaskData taskData) {
     114      executor.Start(taskData.Data);
    115115      waitForStartBeforeKillSem.Release();
    116116      StartExecutorMonitoringThread();
     
    118118
    119119    public void DisposeAppDomain() {
    120       log.LogMessage(string.Format("Shutting down Appdomain for Task {0}", JobId));
     120      log.LogMessage(string.Format("Shutting down Appdomain for Task {0}", TaskId));
    121121      StopExecutorMonitoringThread();
    122122
     
    145145        }
    146146      }
    147       pluginManager.DeletePluginsForJob(JobId);
     147      pluginManager.DeletePluginsForJob(TaskId);
    148148      GC.Collect();
    149149    }
     
    154154    }
    155155
    156     public TaskData GetJobData() {
    157       return executor.GetJobData();
     156    public TaskData GetTaskData() {
     157      return executor.GetTaskData();
    158158    }
    159159
     
    176176    /// Because the executor is in an appdomain and is not able to call back
    177177    /// (because of security -> lease time for marshall-by-ref object is 5 min),
    178     /// we have to poll the executor for events we have to react to (e.g. job finished...)   
     178    /// we have to poll the executor for events we have to react to (e.g. task finished...)   
    179179    /// </summary>
    180180    private void MonitorExecutor() {
     
    184184
    185185        switch (message.MessageType) {
    186           case ExecutorMessageType.JobStarted:
    187             OnJobStarted();
    188             break;
    189 
    190           case ExecutorMessageType.JobPaused:
    191             executorMonitoringRun = false;
    192             OnJobPaused();
    193             DisposeAppDomain();
    194             break;
    195 
    196           case ExecutorMessageType.JobStopped:
    197             executorMonitoringRun = false;
    198             OnJobStopped();
    199             DisposeAppDomain();
    200             break;
    201 
    202           case ExecutorMessageType.JobFailed:
    203             executorMonitoringRun = false;
    204             OnJobFailed(new JobFailedException(executor.CurrentExceptionStr));
     186          case ExecutorMessageType.TaskStarted:
     187            OnTaskStarted();
     188            break;
     189
     190          case ExecutorMessageType.TaskPaused:
     191            executorMonitoringRun = false;
     192            OnTaskPaused();
     193            DisposeAppDomain();
     194            break;
     195
     196          case ExecutorMessageType.TaskStopped:
     197            executorMonitoringRun = false;
     198            OnTaskStopped();
     199            DisposeAppDomain();
     200            break;
     201
     202          case ExecutorMessageType.TaskFailed:
     203            executorMonitoringRun = false;
     204            OnTaskFailed(new TaskFailedException(executor.CurrentExceptionStr));
    205205            DisposeAppDomain();
    206206            break;
     
    216216              OnExceptionOccured(executor.CurrentException);
    217217            } else {
    218               OnExceptionOccured(new Exception(string.Format("Unknow exception occured in Executor for job {0}", JobId)));
     218              OnExceptionOccured(new Exception(string.Format("Unknow exception occured in Executor for task {0}", TaskId)));
    219219            }
    220220            break;
     
    224224    #endregion
    225225
    226     public event EventHandler<EventArgs<Guid>> JobStarted;
    227     private void OnJobStarted() {
    228       var handler = JobStarted;
    229       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    230     }
    231 
    232     public event EventHandler<EventArgs<Guid>> JobStopped;
    233     private void OnJobStopped() {
    234       var handler = JobStopped;
    235       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    236     }
    237 
    238     public event EventHandler<EventArgs<Guid>> JobPaused;
    239     private void OnJobPaused() {
    240       var handler = JobPaused;
    241       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    242     }
    243 
    244     public event EventHandler<EventArgs<Guid>> JobAborted;
    245     private void OnJobAborted() {
    246       var handler = JobAborted;
    247       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    248     }
    249 
    250     public event EventHandler<EventArgs<Guid, Exception>> JobFailed;
    251     private void OnJobFailed(Exception exception) {
    252       var handler = JobFailed;
    253       if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     226    public event EventHandler<EventArgs<Guid>> TaskStarted;
     227    private void OnTaskStarted() {
     228      var handler = TaskStarted;
     229      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     230    }
     231
     232    public event EventHandler<EventArgs<Guid>> TaskStopped;
     233    private void OnTaskStopped() {
     234      var handler = TaskStopped;
     235      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     236    }
     237
     238    public event EventHandler<EventArgs<Guid>> TaskPaused;
     239    private void OnTaskPaused() {
     240      var handler = TaskPaused;
     241      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     242    }
     243
     244    public event EventHandler<EventArgs<Guid>> TaskAborted;
     245    private void OnTaskAborted() {
     246      var handler = TaskAborted;
     247      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     248    }
     249
     250    public event EventHandler<EventArgs<Guid, Exception>> TaskFailed;
     251    private void OnTaskFailed(Exception exception) {
     252      var handler = TaskFailed;
     253      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.TaskId, exception));
    254254    }
    255255
     
    257257    private void OnExceptionOccured(Exception exception) {
    258258      var handler = ExceptionOccured;
    259       if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     259      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.TaskId, exception));
    260260    }
    261261  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/StatusCommons.cs

    r6371 r6725  
    5353    public int ExceptionsOccured { get; set; }
    5454    [DataMember]
    55     public List<JobStatus> Jobs { get; set; }
     55    public List<TaskStatus> Jobs { get; set; }
    5656    [DataMember]
    5757    public bool Asleep { get; set; }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/TaskStatus.cs

    r6721 r6725  
    2525namespace HeuristicLab.Clients.Hive.SlaveCore {
    2626  [DataContract]
    27   public class JobStatus {
     27  public class TaskStatus {
    2828    /// <summary>
    2929    /// Id of the Task
    3030    /// </summary>
    3131    [DataMember]
    32     public Guid JobId { get; set; }
     32    public Guid TaskId { get; set; }
    3333    /// <summary>
    3434    /// Current progress
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/WcfService.cs

    r6721 r6725  
    7070
    7171    /// <summary>
    72     /// Uploads the jobData and sets a new jobState (while correctly setting Transferring state)
     72    /// Uploads the taskData and sets a new jobState (while correctly setting Transferring state)
    7373    /// </summary>
    7474    public void UpdateJobData(Task job, TaskData jobData, Guid slaveId, TaskState state, string exception = "") {
Note: See TracChangeset for help on using the changeset viewer.