Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/06/11 18:33:03 (13 years ago)
Author:
ascheibe
Message:

#1233

  • code cleanups for slave review
  • added switch between privileged and unprivileged sandbox
  • removed childjob management because it's not used
File:
1 edited

Legend:

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

    r6357 r6371  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523using System.Threading;
    2624using HeuristicLab.Common;
     
    2826using HeuristicLab.Hive;
    2927
    30 
    3128namespace HeuristicLab.Clients.Hive.SlaveCore {
     29  /// <summary>
     30  /// The executor runs in the appdomain and handles the execution of an Hive job.
     31  /// </summary>
    3232  public class Executor : MarshalByRefObject, IDisposable {
    3333    public Guid JobId { get; set; }
    34     public IJob Job { get; set; }
     34    private IJob Job { get; set; }
    3535    public int CoresNeeded { get; set; }
    3636    public int MemoryNeeded { get; set; }
    3737    private bool wasJobAborted = false;
    38     public Core Core { get; set; }
    3938    private Semaphore pauseStopSem = new Semaphore(0, 1);
    4039    private Semaphore startJobSem = new Semaphore(0, 1);
    4140    //make pause or stop wait until start is finished
    4241    private Semaphore jobStartedSem = new Semaphore(0, 1);
    43 
    44     public ExecutorQueue executorQueue;
    45 
    46     public bool SendHeartbeatForExecutor { get; set; } // Todo: get rid of??
     42    private ExecutorQueue executorQueue;
     43    public ExecutorQueue ExecutorCommandQueue {
     44      get {
     45        return executorQueue;
     46      }
     47    }
    4748    public bool IsStopping { get; set; }
    4849    public bool IsPausing { get; set; }
    49 
    50     public DateTime CreationTime { get; set; }
    51 
     50    private DateTime CreationTime { get; set; }
    5251    private Exception currentException;
    5352    public String CurrentException {
     
    6160    }
    6261
    63     public ExecutionState ExecutionState {
     62    private ExecutionState ExecutionState {
    6463      get {
    6564        return Job != null ? Job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped;
     
    7473
    7574    public Executor() {
    76       SendHeartbeatForExecutor = true;
    7775      IsStopping = false;
    7876      IsPausing = false;
     
    8078    }
    8179
    82     /// <param name="serializedJob"></param>
    83     /// <param name="collectChildJobs">if true, all child-jobs are downloaded and the job will be resumed.</param>
    8480    public void Start(byte[] serializedJob) {
    8581      try {
     
    8985        RegisterJobEvents();
    9086
    91         if (Job.CollectChildJobs) {
    92           IEnumerable<JobData> childjobs = WcfService.Instance.GetChildJobs(JobId);
    93           Job.Resume(childjobs.Select(j => PersistenceUtil.Deserialize<IJob>(j.Data)));
    94         } else {
    95           Job.Start();
    96           if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(15))) {
    97             throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired.");
    98           }
    99           jobStartedSem.Release();
    100         }
     87        Job.Start();
     88        if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(15))) {
     89          throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired.");
     90        }
     91        jobStartedSem.Release();
    10192      }
    10293      catch (Exception e) {
     
    10899    public void Pause() {
    109100      IsPausing = true;
    110       SendHeartbeatForExecutor = false;
    111101      // wait until job is started. if this does not happen, the Job is null an we give up
    112102      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    113103      if (Job == null) {
    114         currentException = new Exception("Pausing job " + this.JobId + ": Job is null"); // Todo: use more specific exception
     104        currentException = new Exception("Pausing job " + this.JobId + ": Job is null");
    115105        return;
    116106      }
     
    123113        }
    124114        catch (Exception ex) {
    125           currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception
     115          currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString());
    126116        }
    127117      }
     
    130120    public void Stop() {
    131121      IsStopping = true;
    132       SendHeartbeatForExecutor = false;
    133122      // wait until job is started. if this does not happen, the Job is null an we give up
    134123      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    135124      if (Job == null) {
    136         currentException = new Exception("Stopping job " + this.JobId + ": Job is null"); // Todo: use more specific exception
     125        currentException = new Exception("Stopping job " + this.JobId + ": Job is null");
    137126      }
    138127      wasJobAborted = true;
     
    144133        }
    145134        catch (Exception ex) {
    146           currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception
     135          currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString());
    147136        }
    148137      }
     
    152141      Job.JobStopped += new EventHandler(Job_JobStopped);
    153142      Job.JobFailed += new EventHandler(Job_JobFailed);
    154       Job.NewChildJob += new EventHandler<EventArgs<IJob>>(Job_NewChildJob);
    155       Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs);
    156       Job.DeleteChildJobs += new EventHandler(Job_DeleteChildJobs);
    157143      Job.JobPaused += new EventHandler(Job_JobPaused);
    158144      Job.JobStarted += new EventHandler(Job_JobStarted);
     
    162148      Job.JobStopped -= new EventHandler(Job_JobStopped);
    163149      Job.JobFailed -= new EventHandler(Job_JobFailed);
    164       Job.NewChildJob -= new EventHandler<EventArgs<IJob>>(Job_NewChildJob);
    165       Job.WaitForChildJobs -= new EventHandler(Job_WaitForChildJobs);
    166       Job.DeleteChildJobs -= new EventHandler(Job_DeleteChildJobs);
    167150      Job.JobPaused -= new EventHandler(Job_JobPaused);
    168151      Job.JobStarted -= new EventHandler(Job_JobStarted);
     
    170153
    171154    #region Job Events
    172     private void Job_NewChildJob(object sender, EventArgs<IJob> e) {
    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));
    191     }
    192 
    193     private void Job_WaitForChildJobs(object sender, EventArgs e) {
    194       // Pause the job and send it back to the hive. The server will awake it when all child-jobs are finished
    195       this.Job.CollectChildJobs = true;
    196 
    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));
    206     }
    207 
    208     private void Job_DeleteChildJobs(object sender, EventArgs e) {
    209       executorQueue.AddMessage(ExecutorMessageType.DeleteChildJobs);
    210     }
    211 
    212155    private void Job_JobFailed(object sender, EventArgs e) {
    213156      EventArgs<Exception> ex = (EventArgs<Exception>)e;
Note: See TracChangeset for help on using the changeset viewer.