Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/11 17:08:54 (13 years ago)
Author:
cneumuel
Message:

#1233

  • renamed engines to executors
  • changed locking in StartJobInAppDomain
  • avoid destruction of proxy object after 5 minutes for Slave.Core
  • added JobStarted event and fixed ExecutionStateChanged and ExecutionTimeChanged
  • slaves which are moved to another slavegroup will pause their jobs now, if they must not calculate them
File:
1 edited

Legend:

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

    r6107 r6110  
    4444    public static ILog Log { get; set; }
    4545
    46     private Dictionary<Guid, Executor> engines = new Dictionary<Guid, Executor>();
     46    private Dictionary<Guid, Executor> executors = new Dictionary<Guid, Executor>();
    4747    private Dictionary<Guid, AppDomain> appDomains = new Dictionary<Guid, AppDomain>();
    4848    private Dictionary<Guid, Job> jobs = new Dictionary<Guid, Job>();
     
    5555    private ServiceHost slaveComm;
    5656
    57     public Dictionary<Guid, Executor> ExecutionEngines {
    58       get { return engines; }
     57    public Dictionary<Guid, Executor> Executors {
     58      get { return executors; }
    5959    }
    6060
     
    162162              Job job = wcfService.GetJob(jobId);
    163163              if (job == null) throw new JobNotFoundException(jobId);
    164               lock (engines) {
     164              lock (executors) {
    165165                if (!jobs.ContainsKey(job.Id)) {
    166166                  jobs.Add(job.Id, job);
     
    177177              // handle exception of task
    178178              clientCom.LogMessage(t.Exception.ToString());
    179               wcfService.UpdateJobState(container.JobId, JobState.Failed, t.Exception.ToString());
    180               SlaveStatusInfo.JobsAborted++;
    181179            }, TaskContinuationOptions.OnlyOnFaulted);
    182180            break;
     
    225223
    226224        if (job != null) {
    227           engines[job.Id].Pause();
    228           JobData sJob = engines[job.Id].GetPausedJob();
    229           job.ExecutionTime = engines[job.Id].ExecutionTime;
     225          executors[job.Id].Pause();
     226          JobData sJob = executors[job.Id].GetPausedJob();
     227          job.ExecutionTime = executors[job.Id].ExecutionTime;
    230228
    231229          try {
    232             if (engines[job.Id].CurrentException != string.Empty) {
    233               wcfService.UpdateJobState(job.Id, JobState.Failed, engines[job.Id].CurrentException);
     230            if (executors[job.Id].CurrentException != string.Empty) {
     231              wcfService.UpdateJobState(job.Id, JobState.Failed, executors[job.Id].CurrentException);
    234232              SlaveStatusInfo.JobsAborted++;
    235233            } else {
     
    256254
    257255        if (job != null) {
    258           engines[job.Id].Stop();
    259           JobData sJob = engines[job.Id].GetFinishedJob();
    260           job.ExecutionTime = engines[job.Id].ExecutionTime;
     256          executors[job.Id].Stop();
     257          JobData sJob = executors[job.Id].GetFinishedJob();
     258          job.ExecutionTime = executors[job.Id].ExecutionTime;
    261259
    262260
    263261          try {
    264             if (engines[job.Id].CurrentException != string.Empty) {
    265               wcfService.UpdateJobState(job.Id, JobState.Failed, engines[job.Id].CurrentException);
     262            if (executors[job.Id].CurrentException != string.Empty) {
     263              wcfService.UpdateJobState(job.Id, JobState.Failed, executors[job.Id].CurrentException);
    266264            }
    267265            SlaveStatusInfo.JobsAborted++;
     
    350348
    351349
    352       lock (engines) {
    353         clientCom.LogMessage("engines locked");
     350      lock (executors) {
     351        clientCom.LogMessage("executors locked");
    354352        foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) {
    355353          clientCom.LogMessage("Shutting down Appdomain for " + kvp.Key);
     
    411409      try {
    412410        clientCom.LogMessage("Getting the finished job with id: " + jobId);
    413         if (!engines.ContainsKey(jobId)) {
    414           clientCom.LogMessage("Engine doesn't exist");
     411        if (!executors.ContainsKey(jobId)) {
     412          clientCom.LogMessage("Executor doesn't exist");
    415413          return;
    416414        }
     
    420418        }
    421419        Job cJob = jobs[jobId];
    422         cJob.ExecutionTime = engines[jobId].ExecutionTime;
    423 
    424         if (engines[jobId].Aborted) {
     420        cJob.ExecutionTime = executors[jobId].ExecutionTime;
     421
     422        if (executors[jobId].Aborted) {
    425423          SlaveStatusInfo.JobsAborted++;
    426424        } else {
     
    428426        }
    429427
    430         if (engines[jobId].CurrentException != string.Empty) {
    431           wcfService.UpdateJobState(jobId, JobState.Failed, engines[jobId].CurrentException);
    432         }
    433 
    434         JobData sJob = engines[jobId].GetFinishedJob();
     428        if (executors[jobId].CurrentException != string.Empty) {
     429          wcfService.UpdateJobState(jobId, JobState.Failed, executors[jobId].CurrentException);
     430        }
     431
     432        JobData sJob = executors[jobId].GetFinishedJob();
    435433        try {
    436434          clientCom.LogMessage("Sending the finished job with id: " + jobId);
     
    450448    }
    451449
    452     private static object locker = new object();
     450    private static object startInAppDomainLocker = new object();
    453451
    454452    /// <summary>
     
    459457      clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    460458
    461       lock (locker) {
    462         if (engines.ContainsKey(myJob.Id)) {
     459      lock (startInAppDomainLocker) {
     460        if (executors.ContainsKey(myJob.Id)) {
    463461          clientCom.LogMessage("Job with key " + myJob.Id + " already exists. Job will be ignored.");
    464462          return;
     
    476474        catch (Exception exception) {
    477475          clientCom.LogMessage(string.Format("Copying plugins for job {0} failed: {1}", myJob.Id, exception));
    478           wcfService.UpdateJobState(myJob.Id, JobState.Failed, exception.ToString());
    479           SlaveStatusInfo.JobsAborted++;
    480 
    481           lock (engines) {
     476          lock (executors) {
    482477            if (jobs.ContainsKey(myJob.Id)) {
    483478              jobs.Remove(myJob.Id);
     
    490485            AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(myJob.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    491486            appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
    492             Executor engine;
    493             lock (engines) {
    494               appDomains.Add(myJob.Id, appDomain);
    495               clientCom.LogMessage("Creating AppDomain");
    496               engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    497               clientCom.LogMessage("Created AppDomain");
    498               engine.JobId = myJob.Id;
    499               engine.Core = this;
    500               clientCom.LogMessage("Starting Engine for job " + myJob.Id);
    501               engines.Add(myJob.Id, engine);
     487            Executor executor;
     488            appDomains.Add(myJob.Id, appDomain);
     489            clientCom.LogMessage("Creating AppDomain");
     490            executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
     491            clientCom.LogMessage("Created AppDomain");
     492            executor.JobId = myJob.Id;
     493            executor.Core = this;
     494            clientCom.LogMessage("Starting Executor for job " + myJob.Id);
     495
     496            executor.Start(jobData.Data);
     497           
     498            lock (executors) {
     499              executors.Add(myJob.Id, executor);
    502500            }
    503             engine.Start(jobData.Data);
    504501          }
    505502          catch (Exception exception) {
    506503            clientCom.LogMessage("Creating the Appdomain and loading the job failed for job " + myJob.Id);
    507504            clientCom.LogMessage("Error thrown is: " + exception.ToString());
    508 
    509             if (engines.ContainsKey(myJob.Id) && engines[myJob.Id].CurrentException != string.Empty) {
    510               wcfService.UpdateJobState(myJob.Id, JobState.Failed, engines[myJob.Id].CurrentException);
    511             } else {
    512               wcfService.UpdateJobState(myJob.Id, JobState.Failed, exception.ToString());
    513             }
    514             SlaveStatusInfo.JobsAborted++;
    515 
    516505            KillAppDomain(myJob.Id);
    517506          }
     
    557546
    558547      clientCom.LogMessage("Shutting down Appdomain for Job " + id);
    559       lock (engines) {
     548      lock (executors) {
    560549        try {
    561           if (engines.ContainsKey(id)) {
    562             engines[id].Dispose();
    563             engines.Remove(id);
     550          if (executors.ContainsKey(id)) {
     551            executors[id].Dispose();
     552            executors.Remove(id);
    564553          }
    565554
     
    597586      clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    598587    }
     588
     589    public override object InitializeLifetimeService() {
     590      return null; // avoid destruction of proxy object after 5 minutes
     591    }
    599592  }
    600593}
Note: See TracChangeset for help on using the changeset viewer.