Changeset 6371 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
- Timestamp:
- 06/06/11 18:33:03 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
r6357 r6371 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 23 using System.Threading; 26 24 using HeuristicLab.Common; … … 28 26 using HeuristicLab.Hive; 29 27 30 31 28 namespace HeuristicLab.Clients.Hive.SlaveCore { 29 /// <summary> 30 /// The executor runs in the appdomain and handles the execution of an Hive job. 31 /// </summary> 32 32 public class Executor : MarshalByRefObject, IDisposable { 33 33 public Guid JobId { get; set; } 34 p ublicIJob Job { get; set; }34 private IJob Job { get; set; } 35 35 public int CoresNeeded { get; set; } 36 36 public int MemoryNeeded { get; set; } 37 37 private bool wasJobAborted = false; 38 public Core Core { get; set; }39 38 private Semaphore pauseStopSem = new Semaphore(0, 1); 40 39 private Semaphore startJobSem = new Semaphore(0, 1); 41 40 //make pause or stop wait until start is finished 42 41 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 } 47 48 public bool IsStopping { get; set; } 48 49 public bool IsPausing { get; set; } 49 50 public DateTime CreationTime { get; set; } 51 50 private DateTime CreationTime { get; set; } 52 51 private Exception currentException; 53 52 public String CurrentException { … … 61 60 } 62 61 63 p ublicExecutionState ExecutionState {62 private ExecutionState ExecutionState { 64 63 get { 65 64 return Job != null ? Job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; … … 74 73 75 74 public Executor() { 76 SendHeartbeatForExecutor = true;77 75 IsStopping = false; 78 76 IsPausing = false; … … 80 78 } 81 79 82 /// <param name="serializedJob"></param>83 /// <param name="collectChildJobs">if true, all child-jobs are downloaded and the job will be resumed.</param>84 80 public void Start(byte[] serializedJob) { 85 81 try { … … 89 85 RegisterJobEvents(); 90 86 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(); 101 92 } 102 93 catch (Exception e) { … … 108 99 public void Pause() { 109 100 IsPausing = true; 110 SendHeartbeatForExecutor = false;111 101 // wait until job is started. if this does not happen, the Job is null an we give up 112 102 jobStartedSem.WaitOne(TimeSpan.FromSeconds(15)); 113 103 if (Job == null) { 114 currentException = new Exception("Pausing job " + this.JobId + ": Job is null"); // Todo: use more specific exception104 currentException = new Exception("Pausing job " + this.JobId + ": Job is null"); 115 105 return; 116 106 } … … 123 113 } 124 114 catch (Exception ex) { 125 currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception115 currentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString()); 126 116 } 127 117 } … … 130 120 public void Stop() { 131 121 IsStopping = true; 132 SendHeartbeatForExecutor = false;133 122 // wait until job is started. if this does not happen, the Job is null an we give up 134 123 jobStartedSem.WaitOne(TimeSpan.FromSeconds(15)); 135 124 if (Job == null) { 136 currentException = new Exception("Stopping job " + this.JobId + ": Job is null"); // Todo: use more specific exception125 currentException = new Exception("Stopping job " + this.JobId + ": Job is null"); 137 126 } 138 127 wasJobAborted = true; … … 144 133 } 145 134 catch (Exception ex) { 146 currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString()); // Todo: use more specific exception135 currentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString()); 147 136 } 148 137 } … … 152 141 Job.JobStopped += new EventHandler(Job_JobStopped); 153 142 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);157 143 Job.JobPaused += new EventHandler(Job_JobPaused); 158 144 Job.JobStarted += new EventHandler(Job_JobStarted); … … 162 148 Job.JobStopped -= new EventHandler(Job_JobStopped); 163 149 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);167 150 Job.JobPaused -= new EventHandler(Job_JobPaused); 168 151 Job.JobStarted -= new EventHandler(Job_JobStarted); … … 170 153 171 154 #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.CollectDeclaringPlugins178 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 finished195 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 212 155 private void Job_JobFailed(object sender, EventArgs e) { 213 156 EventArgs<Exception> ex = (EventArgs<Exception>)e;
Note: See TracChangeset
for help on using the changeset viewer.