- Timestamp:
- 03/22/11 11:36:53 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4
- Files:
-
- 4 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
r5780 r5786 57 57 private int coreThreadId; 58 58 59 private ISlaveCommunication ClientCom;59 private ISlaveCommunication clientCom; 60 60 private ServiceHost slaveComm; 61 61 … … 84 84 slaveComm.Open(); 85 85 86 ClientCom = SlaveClientCom.Instance.ClientCom;87 ClientCom.LogMessage("Hive Slave started");86 clientCom = SlaveClientCom.Instance.ClientCom; 87 clientCom.LogMessage("Hive Slave started"); 88 88 89 89 ConfigManager manager = ConfigManager.Instance; … … 139 139 140 140 void WcfService_ExceptionOccured(object sender, EventArgs<Exception> e) { 141 ClientCom.LogMessage("Connection to server interruped with exception: " + e.Value.Message);141 clientCom.LogMessage("Connection to server interruped with exception: " + e.Value.Message); 142 142 } 143 143 144 144 void WcfService_Connected(object sender, EventArgs e) { 145 ClientCom.LogMessage("Connected successfully to Hive server");145 clientCom.LogMessage("Connected successfully to Hive server"); 146 146 } 147 147 … … 151 151 /// <param name="container">The Container, containing the message</param> 152 152 private void DetermineAction(MessageContainer container) { 153 ClientCom.LogMessage("Message: " + container.Message.ToString() + " for job: " + container.JobId);153 clientCom.LogMessage("Message: " + container.Message.ToString() + " for job: " + container.JobId); 154 154 155 155 if (container is ExecutorMessageContainer<Guid>) { … … 159 159 switch (container.Message) { 160 160 case MessageContainer.MessageType.CalculateJob: 161 Task.Factory.StartNew(() => { 162 Job job = wcfService.GetJob(container.JobId); 161 clientCom.LogMessage("Task.StartNew[0]: jobId: " + container.JobId); 162 Task.Factory.StartNew((jobIdObj) => { 163 Guid jobId = (Guid)jobIdObj; 164 clientCom.LogMessage("Task.StartNew[1]: jobId: " + jobId); 165 Job job = wcfService.GetJob(jobId); 166 if (job == null) throw new JobNotFoundException(jobId); 163 167 lock (engines) { 164 168 if (!jobs.ContainsKey(job.Id)) { … … 167 171 } 168 172 JobData jobData = wcfService.GetJobData(job.Id); 173 if (job == null) throw new JobDataNotFoundException(jobId); 169 174 job = wcfService.UpdateJobState(job.Id, JobState.Calculating, null); 170 175 StartJobInAppDomain(job, jobData); 171 }); 176 }, container.JobId) 177 .ContinueWith((t) => { 178 // handle exception of task 179 clientCom.LogMessage(t.Exception.ToString()); 180 }, TaskContinuationOptions.OnlyOnFaulted); 172 181 break; 173 182 case MessageContainer.MessageType.ShutdownSlave: … … 203 212 } 204 213 } else { 205 ClientCom.LogMessage("Unknown MessageContainer: " + container);214 clientCom.LogMessage("Unknown MessageContainer: " + container); 206 215 } 207 216 } … … 217 226 218 227 try { 219 ClientCom.LogMessage("Sending the paused job with id: " + job.Id);228 clientCom.LogMessage("Sending the paused job with id: " + job.Id); 220 229 wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Paused); 221 230 SlaveStatusInfo.JobsProcessed++; //TODO: count or not count, thats the question 222 231 } 223 232 catch (Exception e) { 224 ClientCom.LogMessage("Transmitting to server failed. Storing the paused job with id: " + job.Id + " to hdd (" + e.ToString() + ")");233 clientCom.LogMessage("Transmitting to server failed. Storing the paused job with id: " + job.Id + " to hdd (" + e.ToString() + ")"); 225 234 } 226 235 finally { … … 240 249 241 250 try { 242 ClientCom.LogMessage("Sending the stoppped job with id: " + job.Id);251 clientCom.LogMessage("Sending the stoppped job with id: " + job.Id); 243 252 wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Paused); 244 253 SlaveStatusInfo.JobsProcessed++; //TODO: count or not count, thats the question 245 254 } 246 255 catch (Exception e) { 247 ClientCom.LogMessage("Transmitting to server failed. Storing the paused job with id: " + job.Id + " to hdd (" + e.ToString() + ")");256 clientCom.LogMessage("Transmitting to server failed. Storing the paused job with id: " + job.Id + " to hdd (" + e.ToString() + ")"); 248 257 } 249 258 finally { … … 266 275 } 267 276 268 ClientCom.LogMessage("Aborted all jobs!");277 clientCom.LogMessage("Aborted all jobs!"); 269 278 } 270 279 … … 273 282 /// </summary> 274 283 private void DoPauseAll() { 275 ClientCom.LogMessage("Pause all received");284 clientCom.LogMessage("Pause all received"); 276 285 277 286 //copy guids because there will be removed items from 'Jobs' … … 290 299 /// </summary> 291 300 private void DoStopAll() { 292 ClientCom.LogMessage("Stop all received");301 clientCom.LogMessage("Stop all received"); 293 302 294 303 //copy guids because there will be removed items from 'Jobs' … … 316 325 /// </summary> 317 326 private void ShutdownCore() { 318 ClientCom.LogMessage("Shutdown Signal received");319 ClientCom.LogMessage("Stopping heartbeat");327 clientCom.LogMessage("Shutdown Signal received"); 328 clientCom.LogMessage("Stopping heartbeat"); 320 329 heartbeatManager.StopHeartBeat(); 321 330 abortRequested = true; 322 ClientCom.LogMessage("Logging out");331 clientCom.LogMessage("Logging out"); 323 332 324 333 325 334 lock (engines) { 326 ClientCom.LogMessage("engines locked");335 clientCom.LogMessage("engines locked"); 327 336 foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) { 328 ClientCom.LogMessage("Shutting down Appdomain for " + kvp.Key);337 clientCom.LogMessage("Shutting down Appdomain for " + kvp.Key); 329 338 appDomains[kvp.Key].UnhandledException -= new UnhandledExceptionEventHandler(AppDomain_UnhandledException); 330 339 AppDomain.Unload(kvp.Value); … … 332 341 } 333 342 WcfService.Instance.Disconnect(); 334 ClientCom.Shutdown();343 clientCom.Shutdown(); 335 344 SlaveClientCom.Close(); 336 345 … … 344 353 /// </summary> 345 354 private void DoStartSlave() { 346 ClientCom.LogMessage("Restart received");355 clientCom.LogMessage("Restart received"); 347 356 StartHeartbeats(); 348 ClientCom.LogMessage("Restart done");357 clientCom.LogMessage("Restart done"); 349 358 } 350 359 … … 355 364 //TODO: do we need an AbortSleep? 356 365 private void Sleep() { 357 ClientCom.LogMessage("Sleep received");366 clientCom.LogMessage("Sleep received"); 358 367 heartbeatManager.StopHeartBeat(); 359 368 heartbeatManager = null; 360 369 DoStopAll(); 361 370 WcfService.Instance.Disconnect(); 362 ClientCom.LogMessage("Sleep done");371 clientCom.LogMessage("Sleep done"); 363 372 } 364 373 … … 371 380 public void PauseWaitJob(JobData data) { 372 381 if (!Jobs.ContainsKey(data.JobId)) { 373 ClientCom.LogMessage("Can't find job with id " + data.JobId);382 clientCom.LogMessage("Can't find job with id " + data.JobId); 374 383 } else { 375 384 Job job = Jobs[data.JobId]; … … 388 397 public void SendFinishedJob(Guid jobId) { 389 398 try { 390 ClientCom.LogMessage("Getting the finished job with id: " + jobId);399 clientCom.LogMessage("Getting the finished job with id: " + jobId); 391 400 if (!engines.ContainsKey(jobId)) { 392 ClientCom.LogMessage("Engine doesn't exist");401 clientCom.LogMessage("Engine doesn't exist"); 393 402 return; 394 403 } 395 404 if (!jobs.ContainsKey(jobId)) { 396 ClientCom.LogMessage("Job doesn't exist");405 clientCom.LogMessage("Job doesn't exist"); 397 406 return; 398 407 } … … 405 414 406 415 try { 407 ClientCom.LogMessage("Sending the finished job with id: " + jobId);416 clientCom.LogMessage("Sending the finished job with id: " + jobId); 408 417 wcfService.UpdateJobData(cJob, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Finished); 409 418 SlaveStatusInfo.JobsProcessed++; 410 419 } 411 420 catch (Exception e) { 412 ClientCom.LogMessage("Transmitting to server failed. Storing the finished job with id: " + jobId + " to hdd (" + e.ToString() + ")");421 clientCom.LogMessage("Transmitting to server failed. Storing the finished job with id: " + jobId + " to hdd (" + e.ToString() + ")"); 413 422 } 414 423 finally { … … 428 437 /// <param name="e"></param> 429 438 private void StartJobInAppDomain(Job myJob, JobData jobData) { 430 ClientCom.LogMessage("Received new job with id " + myJob.Id);439 clientCom.LogMessage("Received new job with id " + myJob.Id); 431 440 String pluginDir = Path.Combine(PluginCache.Instance.PluginTempBaseDir, myJob.Id.ToString()); 432 441 bool pluginsPrepared = false; … … 435 444 try { 436 445 PluginCache.Instance.PreparePlugins(myJob, out configFileName); 437 ClientCom.LogMessage("Plugins fetched for job " + myJob.Id);446 clientCom.LogMessage("Plugins fetched for job " + myJob.Id); 438 447 pluginsPrepared = true; 439 448 } 440 449 catch (Exception exception) { 441 ClientCom.LogMessage(string.Format("Copying plugins for job {0} failed: {1}", myJob.Id, exception));450 clientCom.LogMessage(string.Format("Copying plugins for job {0} failed: {1}", myJob.Id, exception)); 442 451 } 443 452 … … 448 457 lock (engines) { 449 458 appDomains.Add(myJob.Id, appDomain); 450 ClientCom.LogMessage("Creating AppDomain");459 clientCom.LogMessage("Creating AppDomain"); 451 460 Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName); 452 ClientCom.LogMessage("Created AppDomain");461 clientCom.LogMessage("Created AppDomain"); 453 462 engine.JobId = myJob.Id; 454 463 engine.Core = this; 455 ClientCom.LogMessage("Starting Engine for job " + myJob.Id);464 clientCom.LogMessage("Starting Engine for job " + myJob.Id); 456 465 engines.Add(myJob.Id, engine); 457 466 engine.Start(jobData.Data); 458 467 SlaveStatusInfo.JobsFetched++; 459 ClientCom.LogMessage("Increment FetchedJobs to:" + SlaveStatusInfo.JobsFetched);468 clientCom.LogMessage("Increment FetchedJobs to:" + SlaveStatusInfo.JobsFetched); 460 469 } 461 470 } 462 471 catch (Exception exception) { 463 ClientCom.LogMessage("Creating the Appdomain and loading the job failed for job " + myJob.Id);464 ClientCom.LogMessage("Error thrown is: " + exception.ToString());472 clientCom.LogMessage("Creating the Appdomain and loading the job failed for job " + myJob.Id); 473 clientCom.LogMessage("Error thrown is: " + exception.ToString()); 465 474 KillAppDomain(myJob.Id); 466 475 } … … 471 480 public event EventHandler<EventArgs<Exception>> ExceptionOccured; 472 481 private void OnExceptionOccured(Exception e) { 473 ClientCom.LogMessage("Error: " + e.ToString());482 clientCom.LogMessage("Error: " + e.ToString()); 474 483 var handler = ExceptionOccured; 475 484 if (handler != null) handler(this, new EventArgs<Exception>(e)); … … 477 486 478 487 private void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { 479 ClientCom.LogMessage("Exception in AppDomain: " + e.ExceptionObject.ToString());488 clientCom.LogMessage("Exception in AppDomain: " + e.ExceptionObject.ToString()); 480 489 KillAppDomain(new Guid(e.ExceptionObject.ToString())); 481 490 } … … 508 517 } 509 518 510 ClientCom.LogMessage("Shutting down Appdomain for Job " + id);519 clientCom.LogMessage("Shutting down Appdomain for Job " + id); 511 520 lock (engines) { 512 521 try { … … 526 535 } 527 536 catch (CannotUnloadAppDomainException) { 528 ClientCom.LogMessage("Could not unload AppDomain, will try again in 1 sec.");537 clientCom.LogMessage("Could not unload AppDomain, will try again in 1 sec."); 529 538 Thread.Sleep(1000); 530 539 repeat--; … … 542 551 } 543 552 catch (Exception ex) { 544 ClientCom.LogMessage("Exception when unloading the appdomain: " + ex.ToString());553 clientCom.LogMessage("Exception when unloading the appdomain: " + ex.ToString()); 545 554 } 546 555 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj
r5721 r5786 98 98 <ItemGroup> 99 99 <Compile Include="ConfigManager.cs" /> 100 <Compile Include="Exceptions\JobNotFoundException.cs" /> 101 <Compile Include="Exceptions\JobNotDataFoundException.cs" /> 100 102 <Compile Include="SlaveClientCom.cs" /> 101 103 <Compile Include="Core.cs" /> … … 103 105 <Compile Include="Executor.cs" /> 104 106 <Compile Include="HeartbeatManager.cs" /> 105 <Compile Include=" InvalidStateException.cs" />107 <Compile Include="Exceptions\InvalidStateException.cs" /> 106 108 <Compile Include="JobStatus.cs" /> 107 109 <Compile Include="MessageQueue.cs" />
Note: See TracChangeset
for help on using the changeset viewer.