- Timestamp:
- 05/03/11 17:08:54 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockJob.cs
r5599 r6110 122 122 Stopwatch watch = new Stopwatch(); 123 123 watch.Start(); 124 OnJobStarted(); 124 125 do { 125 126 Thread.SpinWait(1000); … … 191 192 } 192 193 194 public event EventHandler JobStarted; 195 protected virtual void OnJobStarted() { 196 EventHandler handler = JobStarted; 197 if (handler != null) handler(this, EventArgs.Empty); 198 } 199 193 200 public event EventHandler JobFailed; 194 201 protected virtual void OnJobFailed(Exception e) { … … 210 217 } 211 218 #endregion 219 212 220 } 213 221 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs
r6004 r6110 85 85 st.JobsFetched = SlaveStatusInfo.JobsFetched; 86 86 87 Dictionary<Guid, Executor> engines = Core.Execut ionEngines;87 Dictionary<Guid, Executor> engines = Core.Executors; 88 88 st.Jobs = new List<JobStatus>(); 89 89 … … 99 99 public Dictionary<Guid, TimeSpan> GetExecutionTimeOfAllJobs() { 100 100 Dictionary<Guid, TimeSpan> prog = new Dictionary<Guid, TimeSpan>(); 101 Dictionary<Guid, Executor> engines = Core.Execut ionEngines;101 Dictionary<Guid, Executor> engines = Core.Executors; 102 102 lock (engines) { 103 103 foreach (KeyValuePair<Guid, Executor> kvp in engines) { … … 113 113 114 114 public int GetUsedCores() { 115 Dictionary<Guid, Executor> engines = Core.Execut ionEngines;115 Dictionary<Guid, Executor> engines = Core.Executors; 116 116 Dictionary<Guid, Job> jobs = Core.Jobs; 117 117 int usedCores = 0; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
r6107 r6110 44 44 public static ILog Log { get; set; } 45 45 46 private Dictionary<Guid, Executor> e ngines = new Dictionary<Guid, Executor>();46 private Dictionary<Guid, Executor> executors = new Dictionary<Guid, Executor>(); 47 47 private Dictionary<Guid, AppDomain> appDomains = new Dictionary<Guid, AppDomain>(); 48 48 private Dictionary<Guid, Job> jobs = new Dictionary<Guid, Job>(); … … 55 55 private ServiceHost slaveComm; 56 56 57 public Dictionary<Guid, Executor> Execut ionEngines {58 get { return e ngines; }57 public Dictionary<Guid, Executor> Executors { 58 get { return executors; } 59 59 } 60 60 … … 162 162 Job job = wcfService.GetJob(jobId); 163 163 if (job == null) throw new JobNotFoundException(jobId); 164 lock (e ngines) {164 lock (executors) { 165 165 if (!jobs.ContainsKey(job.Id)) { 166 166 jobs.Add(job.Id, job); … … 177 177 // handle exception of task 178 178 clientCom.LogMessage(t.Exception.ToString()); 179 wcfService.UpdateJobState(container.JobId, JobState.Failed, t.Exception.ToString());180 SlaveStatusInfo.JobsAborted++;181 179 }, TaskContinuationOptions.OnlyOnFaulted); 182 180 break; … … 225 223 226 224 if (job != null) { 227 e ngines[job.Id].Pause();228 JobData sJob = e ngines[job.Id].GetPausedJob();229 job.ExecutionTime = e ngines[job.Id].ExecutionTime;225 executors[job.Id].Pause(); 226 JobData sJob = executors[job.Id].GetPausedJob(); 227 job.ExecutionTime = executors[job.Id].ExecutionTime; 230 228 231 229 try { 232 if (e ngines[job.Id].CurrentException != string.Empty) {233 wcfService.UpdateJobState(job.Id, JobState.Failed, e ngines[job.Id].CurrentException);230 if (executors[job.Id].CurrentException != string.Empty) { 231 wcfService.UpdateJobState(job.Id, JobState.Failed, executors[job.Id].CurrentException); 234 232 SlaveStatusInfo.JobsAborted++; 235 233 } else { … … 256 254 257 255 if (job != null) { 258 e ngines[job.Id].Stop();259 JobData sJob = e ngines[job.Id].GetFinishedJob();260 job.ExecutionTime = e ngines[job.Id].ExecutionTime;256 executors[job.Id].Stop(); 257 JobData sJob = executors[job.Id].GetFinishedJob(); 258 job.ExecutionTime = executors[job.Id].ExecutionTime; 261 259 262 260 263 261 try { 264 if (e ngines[job.Id].CurrentException != string.Empty) {265 wcfService.UpdateJobState(job.Id, JobState.Failed, e ngines[job.Id].CurrentException);262 if (executors[job.Id].CurrentException != string.Empty) { 263 wcfService.UpdateJobState(job.Id, JobState.Failed, executors[job.Id].CurrentException); 266 264 } 267 265 SlaveStatusInfo.JobsAborted++; … … 350 348 351 349 352 lock (e ngines) {353 clientCom.LogMessage("e ngines locked");350 lock (executors) { 351 clientCom.LogMessage("executors locked"); 354 352 foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) { 355 353 clientCom.LogMessage("Shutting down Appdomain for " + kvp.Key); … … 411 409 try { 412 410 clientCom.LogMessage("Getting the finished job with id: " + jobId); 413 if (!e ngines.ContainsKey(jobId)) {414 clientCom.LogMessage("E nginedoesn't exist");411 if (!executors.ContainsKey(jobId)) { 412 clientCom.LogMessage("Executor doesn't exist"); 415 413 return; 416 414 } … … 420 418 } 421 419 Job cJob = jobs[jobId]; 422 cJob.ExecutionTime = e ngines[jobId].ExecutionTime;423 424 if (e ngines[jobId].Aborted) {420 cJob.ExecutionTime = executors[jobId].ExecutionTime; 421 422 if (executors[jobId].Aborted) { 425 423 SlaveStatusInfo.JobsAborted++; 426 424 } else { … … 428 426 } 429 427 430 if (e ngines[jobId].CurrentException != string.Empty) {431 wcfService.UpdateJobState(jobId, JobState.Failed, e ngines[jobId].CurrentException);432 } 433 434 JobData sJob = e ngines[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(); 435 433 try { 436 434 clientCom.LogMessage("Sending the finished job with id: " + jobId); … … 450 448 } 451 449 452 private static object locker = new object();450 private static object startInAppDomainLocker = new object(); 453 451 454 452 /// <summary> … … 459 457 clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole()); 460 458 461 lock ( locker) {462 if (e ngines.ContainsKey(myJob.Id)) {459 lock (startInAppDomainLocker) { 460 if (executors.ContainsKey(myJob.Id)) { 463 461 clientCom.LogMessage("Job with key " + myJob.Id + " already exists. Job will be ignored."); 464 462 return; … … 476 474 catch (Exception exception) { 477 475 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) { 482 477 if (jobs.ContainsKey(myJob.Id)) { 483 478 jobs.Remove(myJob.Id); … … 490 485 AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(myJob.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName)); 491 486 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); 502 500 } 503 engine.Start(jobData.Data);504 501 } 505 502 catch (Exception exception) { 506 503 clientCom.LogMessage("Creating the Appdomain and loading the job failed for job " + myJob.Id); 507 504 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 516 505 KillAppDomain(myJob.Id); 517 506 } … … 557 546 558 547 clientCom.LogMessage("Shutting down Appdomain for Job " + id); 559 lock (e ngines) {548 lock (executors) { 560 549 try { 561 if (e ngines.ContainsKey(id)) {562 e ngines[id].Dispose();563 e ngines.Remove(id);550 if (executors.ContainsKey(id)) { 551 executors[id].Dispose(); 552 executors.Remove(id); 564 553 } 565 554 … … 597 586 clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole()); 598 587 } 588 589 public override object InitializeLifetimeService() { 590 return null; // avoid destruction of proxy object after 5 minutes 591 } 599 592 } 600 593 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
r6100 r6110 85 85 Job.Resume(childjobs.Select(j => PersistenceUtil.Deserialize<IJob>(j.Data))); 86 86 } else { 87 // Job.Prepare(); // do NOT prepare here, otherwise paused jobs get restarted88 87 Job.Start(); 88 89 89 } 90 90 } … … 200 200 Aborted = true; 201 201 } else { 202 //it's a clean and finished job, so send it 202 //it's a clean and finished job, so send it 203 203 Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId); 204 204 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/RefreshableHiveExperiment.cs
r6033 r6110 25 25 using System.Drawing; 26 26 using System.Linq; 27 using HeuristicLab.Clients.Hive.ExperimentManager;28 using HeuristicLab.Clients.Hive.Jobs;29 27 using HeuristicLab.Common; 30 28 using HeuristicLab.Core; 29 using HeuristicLab.Hive; 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 31 … … 35 34 public class RefreshableHiveExperiment : IHiveItem, IDeepCloneable, IContent, IProgressReporter { 36 35 private JobResultPoller jobResultPoller; 36 private JobDownloader<ItemJob> jobDownloader = new JobDownloader<ItemJob>(2, 2); 37 37 38 38 [Storable] … … 69 69 refreshAutomatically = value; 70 70 OnRefreshAutomaticallyChanged(); 71 if (RefreshAutomatically) {72 StartResultPolling();73 } else {74 StopResultPolling();75 }71 } 72 if (RefreshAutomatically && hiveExperiment.HiveJobs != null && hiveExperiment.HiveJobs.Count > 0 && (jobResultPoller == null || !jobResultPoller.IsPolling)) { 73 StartResultPolling(); 74 } else { 75 StopResultPolling(); 76 76 } 77 77 } … … 103 103 #endregion 104 104 105 //public Experiment GetExperiment(int idx) {106 // if (hiveExperiment.HiveJobs != null) {107 // var hj = hiveExperiment.HiveJobs.ElementAtOrDefault(idx);108 // if (hj != null)109 // return ((OptimizerHiveJob)hj).JobItem.OptimizerAsExperiment;110 // }111 // return null;112 //}113 114 //public void AddExperiment(Experiment experiment) {115 // if (hiveExperiment.HiveJobs == null)116 // hiveExperiment.HiveJobs = new ItemCollection<HiveJob>();117 // hiveExperiment.HiveJobs.Add(new OptimizerHiveJob(experiment));118 //}119 120 //public void SetExperiment(Experiment experiment) {121 // if (hiveExperiment.HiveJobs == null)122 // hiveExperiment.HiveJobs = new ItemCollection<HiveJob>();123 // else124 // hiveExperiment.HiveJobs.Clear();125 // hiveExperiment.HiveJobs.Add(new OptimizerHiveJob(experiment));126 //}127 128 105 private void hiveExperiment_HiveJobsChanged(object sender, EventArgs e) { 129 106 if (jobResultPoller != null && jobResultPoller.IsPolling) { … … 141 118 public void StartResultPolling() { 142 119 if (jobResultPoller == null) { 143 jobResultPoller = new JobResultPoller(hiveExperiment. HiveJobs, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants120 jobResultPoller = new JobResultPoller(hiveExperiment.Id, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants 144 121 RegisterResultPollingEvents(); 145 122 } … … 172 149 private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) { 173 150 foreach (LightweightJob lightweightJob in e.Value) { 174 OptimizerHiveJob hj = GetHiveJobById(lightweightJob.Id);151 HiveJob hj = GetHiveJobById(lightweightJob.Id); 175 152 if (hj != null) { 176 153 DateTime lastJobDataUpdate = hj.Job.LastJobDataUpdate; … … 179 156 // lastJobDataUpdate equals DateTime.MinValue right after it was uploaded. When the first results are polled, this value is updated 180 157 if (lastJobDataUpdate != DateTime.MinValue && lastJobDataUpdate < hj.Job.LastJobDataUpdate) { 181 OptimizerJob optimizerJob = ExperimentManagerClient.LoadOptimizerJob(hj.Job.Id); 182 if (optimizerJob == null) { 183 // something bad happened to this job. bad job, BAAAD job! 184 } else { 185 // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare) 186 if (hj.Job.State == JobState.Paused) { 187 hj.JobItem = optimizerJob; 158 jobDownloader.DownloadJob(hj.Job.Id, (itemJob) => { 159 if (itemJob == null) { 160 // something bad happened to this job. bad job, BAAAD job! 188 161 } else { 189 if (lightweightJob.ParentJobId.HasValue) { 190 OptimizerHiveJob parentHiveJob = GetHiveJobById(lightweightJob.ParentJobId.Value); 191 parentHiveJob.UpdateChildOptimizer(optimizerJob, hj.Job.Id); 162 // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare) 163 if (hj.Job.State == JobState.Paused) { 164 hj.JobItem = itemJob; 165 } else { 166 if (lightweightJob.ParentJobId.HasValue) { 167 HiveJob parentHiveJob = GetHiveJobById(lightweightJob.ParentJobId.Value); 168 parentHiveJob.IntegrateChild(itemJob, hj.Job.Id); 169 } else { 170 hj.JobItem = itemJob; 171 } 192 172 } 193 173 } 194 } 174 }); 195 175 } 196 176 } … … 205 185 } 206 186 207 public OptimizerHiveJob GetHiveJobById(Guid jobId) {208 foreach ( OptimizerHiveJob job in hiveExperiment.HiveJobs) {209 var hj = job.GetHiveJobByJobId(jobId) as OptimizerHiveJob;187 public HiveJob GetHiveJobById(Guid jobId) { 188 foreach (HiveJob job in hiveExperiment.HiveJobs) { 189 var hj = job.GetHiveJobByJobId(jobId); 210 190 if (hj != null) 211 191 return hj; … … 226 206 || j.Job.State == JobState.Failed); 227 207 } 208 209 //public bool AllJobsFinishedAndDownloaded() { 210 // return this.AllJobsFinished() && hiveExperiment.GetAllHiveJobs().All(j => j.JobItem.; 211 //} 228 212 229 213 private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) { … … 261 245 hiveExperiment.IsProgressingChanged -= new EventHandler(hiveExperiment_IsProgressingChanged); 262 246 } 263 247 264 248 #region Events 265 249 public event EventHandler RefreshAutomaticallyChanged; … … 314 298 } 315 299 public void Store() { 316 hiveExperiment.Store() 300 hiveExperiment.Store(); 317 301 } 318 302 public string ItemDescription { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Heartbeat.cs
r6004 r6110 31 31 32 32 public override string ToString() { 33 String val = "SlaveId: " + SlaveId + ", FreeCores: " + FreeCores;33 string val = string.Format("SlaveId: {0}, FreeCores: {1}", SlaveId, FreeCores); 34 34 foreach (KeyValuePair<Guid, TimeSpan> kvp in JobProgress) { 35 val += Environment.NewLine + "Id" + kvp.Key + " ExecutionTime " + kvp.Value;35 val += Environment.NewLine + string.Format("Id: {0}, ExecutionTime {1}", kvp.Key, kvp.Value); 36 36 } 37 37 return val; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive/3.4/IJob.cs
r5450 r6110 70 70 event EventHandler JobPaused; 71 71 72 event EventHandler JobStarted; 73 72 74 /// <summary> 73 75 /// When this event occurs the job wants to sleep until all his child jobs are finished -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Hive/3.4/ItemJob.cs
r6033 r6110 122 122 public abstract void Resume(IEnumerable<IJob> childJobs); 123 123 124 public event EventHandler JobStarted; 125 protected virtual void OnJobStarted() { 126 EventHandler handler = JobStarted; 127 if (handler != null) handler(this, EventArgs.Empty); 128 } 129 124 130 public event EventHandler JobStopped; 125 131 protected virtual void OnJobStopped() { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/Program.cs
r6039 r6110 6 6 using HeuristicLab.Algorithms.GeneticAlgorithm; 7 7 using HeuristicLab.Clients.Hive; 8 using HeuristicLab.Clients.Hive.Jobs; 8 9 using HeuristicLab.Common; 9 10 using HeuristicLab.Core; 11 using HeuristicLab.Optimization; 10 12 using HeuristicLab.PluginInfrastructure; 11 13 using HeuristicLab.PluginInfrastructure.Manager; 12 14 using HeuristicLab.Problems.TestFunctions; 13 using HeuristicLab.Clients.Hive.Jobs;14 using HeuristicLab.Optimization;15 15 16 16 namespace HeuristicLab.HiveEngine.Test { … … 40 40 41 41 var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data); 42 43 44 42 45 43 #region Credentials 46 44 ServiceLocator.Instance.Username = "cneumuel"; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
r6006 r6110 546 546 /// Returns all parent resources of a resource (the given resource is also added) 547 547 /// </summary> 548 p rivateIEnumerable<DT.Resource> GetParentResources(Guid resourceId) {548 public IEnumerable<DT.Resource> GetParentResources(Guid resourceId) { 549 549 using (var db = CreateContext()) { 550 550 var resources = new List<Resource>(); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs
r5636 r6110 94 94 void AssignJobToResource(Guid jobId, Guid resourceId); 95 95 IEnumerable<DT.Resource> GetAssignedResources(Guid jobId); 96 IEnumerable<DT.Resource> GetParentResources(Guid resourceId); 96 97 #endregion 97 98 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HeartbeatManager.cs
r5786 r6110 82 82 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id)); 83 83 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate Job: " + curJob); 84 } else if (!JobIsAllowedToBeCalculatedBySlave(heartbeat.SlaveId, curJob)) { 85 // assigned resources ids of job do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group 86 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseJob, curJob.Id)); 84 87 } else { 85 88 // save job execution time … … 104 107 return actions; 105 108 } 109 110 private bool JobIsAllowedToBeCalculatedBySlave(Guid slaveId, Job curJob) { 111 var assignedResourceIds = dao.GetAssignedResources(curJob.Id).Select(x => x.Id); 112 var slaveResourceIds = dao.GetParentResources(slaveId).Select(x => x.Id); 113 return assignedResourceIds.Any(x => slaveResourceIds.Contains(x)); 114 } 106 115 } 107 116 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r6006 r6110 147 147 return trans.UseTransaction(() => { 148 148 Job job = dao.UpdateJobState(jobId, jobState, slaveId, userId, exception); 149 149 150 if (job.Command.HasValue && job.Command.Value == Command.Pause && job.State == JobState.Paused) { 150 151 job.Command = null; … … 153 154 } else if (job.Command.HasValue && job.Command.Value == Command.Stop && job.State == JobState.Aborted) { 154 155 job.Command = null; 155 } 156 } else if (jobState == JobState.Paused && !job.Command.HasValue) { 157 // job was paused and uploaded by slave without the user-command to pause it -> set waiting 158 job = dao.UpdateJobState(jobId, JobState.Waiting, slaveId, userId, exception); 159 } 160 156 161 dao.UpdateJob(job); 157 162 return job;
Note: See TracChangeset
for help on using the changeset viewer.