- Timestamp:
- 06/06/11 18:33:03 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.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. … … 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Hive;31 30 32 31 … … 34 33 /// <summary> 35 34 /// The core component of the Hive Slave. 36 /// Handles commands sent from the Hive Server .35 /// Handles commands sent from the Hive Server and does all webservice calls for jobs. 37 36 /// </summary> 38 37 public class Core : MarshalByRefObject { … … 41 40 get { return heartbeatManager; } 42 41 } 42 43 public EventLog ServiceEventLog { get; set; } 43 44 44 45 private Semaphore waitShutdownSem = new Semaphore(0, 1); … … 51 52 private PluginManager pluginManager; 52 53 53 public EventLog ServiceEventLog { get; set; }54 55 54 public Core() { 56 55 var log = new ThreadSafeLog(new Log()); … … 66 65 67 66 /// <summary> 68 /// Main Method for the client67 /// Main method for the client 69 68 /// </summary> 70 69 public void Start() { … … 72 71 73 72 try { 74 //manager.Core = this;75 76 73 //start the client communication service (pipe between slave and slave gui) 77 74 slaveComm = new ServiceHost(typeof(SlaveCommunicationService)); … … 321 318 this.jobManager.ExceptionOccured += new EventHandler<EventArgs<SlaveJob, Exception>>(jobManager_ExceptionOccured); 322 319 this.jobManager.JobAborted += new EventHandler<EventArgs<SlaveJob>>(jobManager_JobAborted); 323 this.jobManager.NewChildJob += new EventHandler<EventArgs<SlaveJob, IJob>>(jobManager_NewChildJob);324 this.jobManager.WaitForChildJobs += new EventHandler<EventArgs<SlaveJob, JobData>>(jobManager_WaitForChildJobs);325 this.jobManager.DeleteChildJobs += new EventHandler<EventArgs<SlaveJob>>(jobManager_DeleteChildJobs);326 320 } 327 321 … … 404 398 SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded); 405 399 } 406 407 private void jobManager_NewChildJob(object sender, EventArgs<SlaveJob, IJob> e) {408 var job = new Job() { CoresNeeded = 1, MemoryNeeded = 0 };409 WcfService.Instance.AddChildJob(e.Value.JobId, job, e.Value2);410 }411 412 private void jobManager_WaitForChildJobs(object sender, EventArgs<SlaveJob, JobData> e) {413 try {414 SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);415 heartbeatManager.AwakeHeartBeatThread();416 Job job = wcfService.GetJob(e.Value.JobId);417 if (job == null) throw new JobNotFoundException(e.Value.JobId);418 job.ExecutionTime = e.Value.ExecutionTime;419 job.IsParentJob = true;420 job.FinishWhenChildJobsFinished = false;421 JobData jobData = e.Value.GetJobData();422 wcfService.UpdateJobData(job, jobData, configManager.GetClientInfo().Id, JobState.Waiting);423 }424 catch (JobNotFoundException ex) {425 clientCom.LogMessage(ex.ToString());426 }427 catch (Exception ex) {428 clientCom.LogMessage(ex.ToString());429 }430 }431 432 private void jobManager_DeleteChildJobs(object sender, EventArgs<SlaveJob> e) {433 try {434 WcfService.Instance.DeleteChildJobs(e.Value.JobId);435 }436 catch (Exception ex) {437 clientCom.LogMessage(ex.ToString());438 }439 }440 400 #endregion 441 401 … … 491 451 /// </summary> 492 452 private void ShutdownCore() { 493 clientCom.LogMessage("Shutdown Signal received");453 clientCom.LogMessage("Shutdown signal received"); 494 454 clientCom.LogMessage("Stopping heartbeat"); 495 455 heartbeatManager.StopHeartBeat(); 496 456 abortRequested = true; 457 458 DoAbortAll(); 459 497 460 clientCom.LogMessage("Logging out"); 498 499 DoAbortAll();500 501 461 WcfService.Instance.Disconnect(); 502 462 clientCom.Shutdown(); … … 514 474 clientCom.LogMessage("Restart received"); 515 475 configManager.Asleep = false; 516 clientCom.LogMessage("Restart done");517 476 } 518 477 … … 524 483 clientCom.LogMessage("Sleep received - not accepting any new jobs"); 525 484 configManager.Asleep = true; 526 DoPauseAll(); 485 DoPauseAll(); 527 486 } 528 487 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/DummyListener.cs
r5599 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. -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Exceptions/InvalidStateException.cs
r5786 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. -
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; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ExecutorMessage.cs
r6357 r6371 1 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 2 22 using System; 3 using HeuristicLab.Hive; 23 4 24 namespace HeuristicLab.Clients.Hive.SlaveCore { 25 5 26 [Serializable] 6 27 public enum ExecutorMessageType { … … 9 30 JobStopped, 10 31 JobFailed, 11 NewChildJob,12 WaitForChildJobs,13 DeleteChildJobs,14 32 StopExecutorMonitoringThread 15 33 } … … 23 41 } 24 42 } 25 26 [Serializable]27 public class JobExecutorMessage : ExecutorMessage {28 public IJob Job { get; private set; }29 30 public JobExecutorMessage(ExecutorMessageType messageType, IJob job) : base(messageType) {31 this.Job = job;32 }33 }34 43 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ExecutorQueue.cs
r6203 r6371 1 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 2 22 using System; 3 23 using System.Collections.Generic; 4 24 using System.Threading; 25 5 26 namespace HeuristicLab.Clients.Hive.SlaveCore { 6 27 /// <summary> 28 /// Every Executor gets an ExecutorQueue in which it can push messages. 29 /// These messages are then read and processed from outside the appdomain. 30 /// </summary> 7 31 public class ExecutorQueue : MarshalByRefObject { 8 32 private Queue<ExecutorMessage> queue = null; 9 33 private Semaphore semaphore = null; 10 34 11 /// <summary>12 /// Creates a new MessageQueue Object.13 /// A new Queue and a Semaphore is created. The Semaphore is set to a max size of 5000.14 /// </summary>15 35 public ExecutorQueue() { 16 36 queue = new Queue<ExecutorMessage>(); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLabClientsHiveSlavePlugin.cs.frame
r6033 r6371 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 23 using System; 2 24 using System.Collections.Generic; 3 25 using System.Linq; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/IPluginProvider.cs
r6357 r6371 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/JobStatus.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. -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Manager/ConfigManager.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. … … 39 39 40 40 /// <summary> 41 /// if the Sleepingis true, the Slave won't accept any new jobs41 /// if Asleep is true, the Slave won't accept any new jobs 42 42 /// </summary> 43 43 public bool Asleep { get; set; } 44 45 //public Core Core { get; set; }46 44 private JobManager jobManager; 47 45 private Slave slave; … … 111 109 public Dictionary<Guid, TimeSpan> GetExecutionTimeOfAllJobs() { 112 110 Dictionary<Guid, TimeSpan> prog = new Dictionary<Guid, TimeSpan>(); 113 114 //lock (slaveJobs) {115 // foreach (KeyValuePair<Guid, SlaveJob> kvp in slaveJobs) {116 // Executor e = kvp.Value.JobExecutor;117 // if (e != null && !kvp.Value.Finished) {118 // //don't include jobs in hb's which are currently serializing119 // if (e.SendHeartbeatForExecutor) {120 // prog[e.JobId] = e.ExecutionTime;121 // }122 // }123 // }124 //}125 111 prog = jobManager.GetExecutionTimes(); 126 127 112 return prog; 128 113 } … … 159 144 160 145 /// <summary> 161 /// Generate a guid based on mac address of the first found nic (yes, mac addresses are not unique...). 146 /// Generate a guid based on mac address of the first found nic (yes, mac addresses are not unique...) 147 /// and the machine name. 162 148 /// Format: 163 149 /// … … 169 155 /// The mac address is saved in the last 48 bits of the Data 4 segment 170 156 /// of the guid (first 2 bytes of Data 4 are reserved). 171 /// D1 contains the name of the machine.157 /// D1 contains the hash of the machinename. 172 158 /// </summary> 173 159 private static Guid GetUniqueMachineIdFromMac() { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Manager/HeartbeatManager.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. … … 27 27 namespace HeuristicLab.Clients.Hive.SlaveCore { 28 28 /// <summary> 29 /// Heartbeat class. It sends every x ms a heartbeat to the server and receives a Message 29 /// Heartbeat Manager sends every x ms a heartbeat to the server and receives a message. 30 /// The message is added to the MessageQueue from where the Core pulls them and decides what to do. 30 31 /// </summary> 31 32 public class HeartbeatManager { … … 86 87 if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) { 87 88 Slave info = ConfigManager.Instance.GetClientInfo(); 88 89 89 90 Heartbeat heartBeatData = new Heartbeat { 90 91 SlaveId = info.Id, … … 120 121 } 121 122 122 123 123 #region Eventhandler 124 124 public event EventHandler<EventArgs<Exception>> ExceptionOccured; -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Manager/JobManager.cs
r6357 r6371 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Hive;29 28 30 29 namespace HeuristicLab.Clients.Hive.SlaveCore { 30 31 /// <summary> 32 /// Holds a list of slave jobs and manages access to this list. 33 /// Forwards events from SlaveJob and forwards commands to SlaveJob. 34 /// </summary> 31 35 public class JobManager { 32 36 private static ReaderWriterLockSlim slaveJobsLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); … … 164 168 finally { slaveJobsLocker.ExitWriteLock(); } 165 169 } 170 166 171 private void RemoveSlaveJob(Guid jobId, SlaveJob slaveJob) { 167 172 slaveJobsLocker.EnterWriteLock(); … … 181 186 slaveJob.JobFailed += new EventHandler<EventArgs<Guid, Exception>>(slaveJob_JobFailed); 182 187 slaveJob.ExceptionOccured += new EventHandler<EventArgs<Guid, Exception>>(slaveJob_ExceptionOccured); 183 slaveJob.NewChildJob += new EventHandler<EventArgs<Guid, HeuristicLab.Hive.IJob>>(slaveJob_NewChildJob);184 slaveJob.WaitForChildJobs += new EventHandler<EventArgs<Guid>>(slaveJob_WaitForChildJobs);185 slaveJob.DeleteChildJobs += new EventHandler<EventArgs<Guid>>(slaveJob_DeleteChildJobs);186 188 } 187 189 … … 192 194 slaveJob.JobFailed -= new EventHandler<EventArgs<Guid, Exception>>(slaveJob_JobFailed); 193 195 slaveJob.ExceptionOccured -= new EventHandler<EventArgs<Guid, Exception>>(slaveJob_ExceptionOccured); 194 slaveJob.NewChildJob -= new EventHandler<EventArgs<Guid, HeuristicLab.Hive.IJob>>(slaveJob_NewChildJob);195 slaveJob.WaitForChildJobs -= new EventHandler<EventArgs<Guid>>(slaveJob_WaitForChildJobs);196 slaveJob.DeleteChildJobs -= new EventHandler<EventArgs<Guid>>(slaveJob_DeleteChildJobs);197 196 } 198 197 … … 285 284 SlaveStatusInfo.IncrementExceptionOccured(); 286 285 OnExceptionOccured(slaveJob, e.Value2); 287 }288 289 private void slaveJob_NewChildJob(object sender, EventArgs<Guid, IJob> e) {290 var slaveJob = slaveJobs[e.Value];291 OnNewChildJob(slaveJob, e.Value2);292 }293 294 private void slaveJob_WaitForChildJobs(object sender, EventArgs<Guid> e) {295 SlaveJob slaveJob;296 slaveJobsLocker.EnterUpgradeableReadLock();297 try {298 slaveJob = slaveJobs[e.Value];299 RemoveSlaveJob(e.Value, slaveJob);300 }301 finally { slaveJobsLocker.ExitUpgradeableReadLock(); }302 303 JobData jobData = null;304 try {305 jobData = slaveJob.GetJobData();306 if (jobData == null) throw new SerializationException();307 SlaveStatusInfo.IncrementJobsFinished();308 OnWaitForChildJobs(slaveJob, jobData);309 }310 catch (Exception ex) {311 RemoveSlaveJob(e.Value, slaveJob);312 SlaveStatusInfo.IncrementJobsFailed();313 OnJobFailed(slaveJob, jobData, ex);314 }315 }316 317 private void slaveJob_DeleteChildJobs(object sender, EventArgs<Guid> e) {318 var slaveJob = slaveJobs[e.Value];319 OnDeleteChildJobs(slaveJob);320 286 } 321 287 #endregion … … 357 323 if (handler != null) handler(this, new EventArgs<SlaveJob>(slaveJob)); 358 324 } 359 360 public event EventHandler<EventArgs<SlaveJob, IJob>> NewChildJob;361 private void OnNewChildJob(SlaveJob slaveJob, IJob job) {362 var handler = NewChildJob;363 if (handler != null) handler(this, new EventArgs<SlaveJob, IJob>(slaveJob, job));364 }365 366 public event EventHandler<EventArgs<SlaveJob, JobData>> WaitForChildJobs;367 private void OnWaitForChildJobs(SlaveJob slaveJob, JobData jobData) {368 var handler = WaitForChildJobs;369 if (handler != null) handler(this, new EventArgs<SlaveJob, JobData>(slaveJob, jobData));370 }371 372 public event EventHandler<EventArgs<SlaveJob>> DeleteChildJobs;373 private void OnDeleteChildJobs(SlaveJob slaveJob) {374 var handler = DeleteChildJobs;375 if (handler != null) handler(this, new EventArgs<SlaveJob>(slaveJob));376 }377 325 #endregion 378 326 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Manager/PluginManager.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. … … 33 33 private static object locker = new object(); 34 34 private const string lastUsedFileName = "lastUsed.dat"; 35 36 35 //maximum number of days after which a plugin gets deleted if not used 37 36 private const int maxAge = 5; 38 37 38 private string PluginCacheDir { get; set; } 39 public string PluginTempBaseDir { get; set; } 39 40 private ILog log; 40 41 private IPluginProvider pluginService; 41 public string PluginCacheDir { get; set; }42 public string PluginTempBaseDir { get; set; }43 44 42 private List<Guid> cachedPluginsGuids = new List<Guid>(); 45 46 //public static PluginCache Instance {47 // get { return instance; }48 // set {}49 //}50 43 51 44 public PluginManager(IPluginProvider pluginService, ILog log) { … … 92 85 93 86 if (requestedPlugin.Name == "Configuration") { 94 configFileName = Path.Combine(targetDir, Path.GetFileName(filePaths.SingleOrDefault())); // configuration plugin consists only of 1 file (usually the "HeuristicLab X.X.exe.config") 87 // configuration plugin consists only of 1 file (usually the "HeuristicLab X.X.exe.config") 88 configFileName = Path.Combine(targetDir, Path.GetFileName(filePaths.SingleOrDefault())); 95 89 } 96 90 } … … 179 173 configFileName = ""; 180 174 } 181 log.LogMessage( "Fetched " + missingGuids.Count + " plugins for job " + job.Id);175 log.LogMessage(string.Format("Fetched {0} plugins for job {1}", missingGuids.Count, job.Id)); 182 176 } 183 177 } … … 290 284 while (tries > 0) { 291 285 try { 292 if (Directory.Exists(path)) Directory.Delete(path, true);286 if (Directory.Exists(path)) Directory.Delete(path, true); 293 287 tries = 0; 294 288 } 295 catch (Exception e) {289 catch (Exception) { 296 290 Thread.Sleep(1000); 297 291 tries--; 298 if (tries == 0) throw; // TODO: don't know what to do292 if (tries == 0) throw; 299 293 } 300 294 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/MessageQueue.cs
r6204 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. -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/NetworkEnum.cs
r5599 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. … … 20 20 #endregion 21 21 22 23 22 namespace HeuristicLab.Clients.Hive.SlaveCore { 24 23 public class NetworkEnum { 25 public enum WcfConnState { Connected, Disconnected, Failed } 24 public enum WcfConnState { Connected, Disconnected, Failed } 26 25 } 27 26 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/AssemblyInfo.cs.frame
r5043 r6371 11 11 [assembly: AssemblyCompany("")] 12 12 [assembly: AssemblyProduct("HeuristicLab")] 13 [assembly: AssemblyCopyright("(c) 2002-201 0HEAL")]13 [assembly: AssemblyCopyright("(c) 2002-2011 HEAL")] 14 14 [assembly: AssemblyTrademark("")] 15 15 [assembly: AssemblyCulture("")] -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ServiceContracts/ISlaveCommunication.cs
r6263 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. -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ServiceContracts/ISlaveCommunicationCallbacks.cs
r5599 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.ServiceModel; 23 using HeuristicLab.Clients.Hive.SlaveCore;24 23 25 24 namespace HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts { -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveClientCom.cs
r5795 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. … … 52 52 private void SetupClientCom() { 53 53 DummyListener dummy = new DummyListener(); 54 pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, "SlaveCommunicationServiceEndpoint"); 54 try { 55 pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, "SlaveCommunicationServiceEndpoint"); 56 } 57 catch { 58 pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom")); 59 } 55 60 56 61 ISlaveCommunication pipeProxy = pipeFactory.CreateChannel(); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveCommunicationService.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. … … 24 24 using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts; 25 25 26 27 26 namespace HeuristicLab.Clients.Hive.SlaveCore { 28 29 27 public class SlaveCommunicationService : ISlaveCommunication { 30 28 private static List<ISlaveCommunicationCallbacks> subscribers = new List<ISlaveCommunicationCallbacks>(); -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveJob.cs
r6357 r6371 1 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 2 22 using System; 3 23 using System.IO; … … 5 25 using HeuristicLab.Common; 6 26 using HeuristicLab.Core; 7 using HeuristicLab.Hive;8 27 using HeuristicLab.PluginInfrastructure.Sandboxing; 9 28 10 29 namespace HeuristicLab.Clients.Hive.SlaveCore { 11 30 31 /// <summary> 32 /// Manages a single job and it's appdomain. 33 /// </summary> 12 34 public class SlaveJob : MarshalByRefObject { 13 35 private Executor executor; … … 18 40 private PluginManager pluginManager; 19 41 private ILog log; 20 21 42 public Guid JobId { get; private set; } 22 43 public bool IsPrepared { get; private set; } … … 48 69 } 49 70 catch (Exception) { 50 DisposeAppDomain(); // make sure to clean up if something went wrong 71 // make sure to clean up if something went wrong 72 DisposeAppDomain(); 51 73 throw; 52 74 } … … 72 94 73 95 private AppDomain CreateAppDomain(Job job, String pluginDir, string configFileName) { 74 appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName)); 96 if (job.IsPrivileged) { 97 appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName)); 98 } else { 99 appDomain = SandboxManager.CreateAndInitSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName)); 100 } 75 101 appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException); 76 102 … … 90 116 } 91 117 92 /// <summary>93 /// Kill a appdomain with a specific id.94 /// </summary>95 /// <param name="JobId">the GUID of the job</param>96 118 public void DisposeAppDomain() { 97 119 log.LogMessage(string.Format("Shutting down Appdomain for Job {0}", JobId)); … … 128 150 private void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { 129 151 DisposeAppDomain(); 130 OnExceptionOccured(new Exception("Unhandled exception: " + e.ExceptionObject.ToString()));152 OnExceptionOccured(new Exception("Unhandled exception: " + e.ExceptionObject.ToString())); 131 153 } 132 154 … … 145 167 if (executorMonitoringRun) { 146 168 executorMonitoringRun = false; 147 executor. executorQueue.AddMessage(ExecutorMessageType.StopExecutorMonitoringThread);169 executor.ExecutorCommandQueue.AddMessage(ExecutorMessageType.StopExecutorMonitoringThread); 148 170 } 149 171 } … … 158 180 while (executorMonitoringRun) { 159 181 //this blocks through the appdomain border, that's why the lease gets renewed 160 ExecutorMessage message = executor. executorQueue.GetMessage();182 ExecutorMessage message = executor.ExecutorCommandQueue.GetMessage(); 161 183 162 184 switch (message.MessageType) { … … 181 203 OnJobFailed(new JobFailedException(executor.CurrentException)); 182 204 DisposeAppDomain(); 183 break;184 185 case ExecutorMessageType.NewChildJob:186 OnNewChildJob(((JobExecutorMessage)message).Job);187 break;188 189 case ExecutorMessageType.WaitForChildJobs:190 executorMonitoringRun = false;191 OnWaitForChildJobs();192 DisposeAppDomain();193 break;194 195 case ExecutorMessageType.DeleteChildJobs:196 OnDeleteChildJobs();197 205 break; 198 206 … … 240 248 if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception)); 241 249 } 242 243 public event EventHandler<EventArgs<Guid, IJob>> NewChildJob;244 private void OnNewChildJob(IJob job) {245 var handler = NewChildJob;246 if (handler != null) handler(this, new EventArgs<Guid, IJob>(this.JobId, job));247 }248 249 public event EventHandler<EventArgs<Guid>> WaitForChildJobs;250 private void OnWaitForChildJobs() {251 var handler = WaitForChildJobs;252 if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));253 }254 255 public event EventHandler<EventArgs<Guid>> DeleteChildJobs;256 private void OnDeleteChildJobs() {257 var handler = DeleteChildJobs;258 if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));259 }260 250 } 261 251 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveStatusInfo.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. -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.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. … … 58 58 59 59 public override string ToString() { 60 return string.Format("Status: {0}, Fetc,Start,Fin,Abor,Fail,Exc: {1},{2},{3},{4},{5},{6}", 60 return string.Format("Status: {0}, Fetc,Start,Fin,Abor,Fail,Exc: {1},{2},{3},{4},{5},{6}", 61 61 Status, JobsFetched, JobsStarted, JobsFinished, JobsAborted, JobsFailed, ExceptionsOccured); 62 62 } 63 64 65 63 } 66 64 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.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. … … 29 29 30 30 /// <summary> 31 /// WcfService class is implemented as a Singleton and works as a communication Layer with the Server31 /// WcfService class is implemented as a singleton and works as a communication layer with the Hive server 32 32 /// </summary> 33 33 public class WcfService : MarshalByRefObject, IPluginProvider { 34 34 private static WcfService instance; 35 public DateTime ConnectedSince { get; private set; } 36 public NetworkEnum.WcfConnState ConnState { get; private set; } 37 35 38 /// <summary> 36 39 /// Getter for the Instance of the WcfService … … 48 51 } 49 52 50 public DateTime ConnectedSince { get; private set; }51 public NetworkEnum.WcfConnState ConnState { get; private set; }52 53 53 private WcfService() { 54 54 ConnState = NetworkEnum.WcfConnState.Disconnected; … … 99 99 100 100 /// <summary> 101 /// Uploads the JobData and sets a new jobState (while correctly setting Transferring state)101 /// Uploads the jobData and sets a new jobState (while correctly setting Transferring state) 102 102 /// </summary> 103 103 public void UpdateJobData(Job job, JobData jobData, Guid slaveId, JobState state) { … … 122 122 123 123 #region Plugin Methods 124 125 124 public Plugin GetPlugin(Guid id) { 126 125 return CallHiveService(s => s.GetPlugin(id)); … … 152 151 #region Helpers 153 152 /// <summary> 154 /// Connects with the Server, registers the events and fires the Connected (and quiet possibly the ConnectionRestored) Event.153 /// Connects with the server, registers the events and fires the Connected event. 155 154 /// </summary> 156 155 public void Connect(Slave slaveInfo) { … … 164 163 165 164 /// <summary> 166 /// Disconnects the Slave from the Server165 /// Disconnects the slave from the server 167 166 /// </summary> 168 167 public void Disconnect() { … … 174 173 175 174 /// <summary> 176 /// Network communication Error Handler - Every network error gets logged and the connection switches to faulted state177 /// </summary>178 /// < param name="e">The Exception</param>175 /// Network communication error handler. 176 /// Every network error gets logged and the connection switches to faulted state 177 /// </summary> 179 178 private void HandleNetworkError(Exception e) { 180 179 ConnState = NetworkEnum.WcfConnState.Failed;
Note: See TracChangeset
for help on using the changeset viewer.