Changeset 3578 for trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
- Timestamp:
- 05/01/10 13:58:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
r3220 r3578 44 44 using HeuristicLab.Hive.JobBase; 45 45 using HeuristicLab.Hive.Client.Core.JobStorage; 46 using HeuristicLab.Tracing; 46 47 47 48 namespace HeuristicLab.Hive.Client.Core { … … 51 52 public class Core : MarshalByRefObject { 52 53 public static bool abortRequested { get; set; } 53 private bool currentlyFetching = false; 54 55 private bool _currentlyFetching; 56 private bool CurrentlyFetching { 57 get { 58 return _currentlyFetching; 59 } set { 60 _currentlyFetching = value; 61 Logger.Debug("Set CurrentlyFetching to " + _currentlyFetching); 62 } 63 } 54 64 55 65 private Dictionary<Guid, Executor> engines = new Dictionary<Guid, Executor>(); … … 65 75 public void Start() { 66 76 abortRequested = false; 67 Logg ing.Instance.Info(this.ToString(),"Hive Client started");77 Logger.Info("Hive Client started"); 68 78 ClientConsoleServer server = new ClientConsoleServer(); 69 79 server.StartClientConsoleServer(new Uri("net.tcp://127.0.0.1:8000/ClientConsole/")); … … 104 114 DetermineAction(container); 105 115 } 106 System.Console.WriteLine("ended");116 Logger.Info("Program shutdown"); 107 117 } 108 118 … … 112 122 /// <param name="container">The Container, containing the message</param> 113 123 private void DetermineAction(MessageContainer container) { 114 Logg ing.Instance.Info(this.ToString(),"Message: " + container.Message.ToString() + " for job: " + container.JobId);124 Logger.Info("Message: " + container.Message.ToString() + " for job: " + container.JobId); 115 125 switch (container.Message) { 116 126 //Server requests to abort a job … … 119 129 engines[container.JobId].Abort(); 120 130 else 121 Logg ing.Instance.Error(this.ToString(),"AbortJob: Engine doesn't exist");131 Logger.Error("AbortJob: Engine doesn't exist"); 122 132 break; 123 133 //Job has been successfully aborted … … 136 146 GC.Collect(); 137 147 } else 138 Logg ing.Instance.Error(this.ToString(),"JobAbort: Engine doesn't exist");148 Logger.Error("JobAbort: Engine doesn't exist"); 139 149 } 140 150 break; … … 146 156 engines[container.JobId].RequestSnapshot(); 147 157 else 148 Logg ing.Instance.Error(this.ToString(),"RequestSnapshot: Engine doesn't exist");158 Logger.Error("RequestSnapshot: Engine doesn't exist"); 149 159 break; 150 160 … … 158 168 //Pull a Job from the Server 159 169 case MessageContainer.MessageType.FetchJob: 160 if (! currentlyFetching) {170 if (!CurrentlyFetching) { 161 171 wcfService.SendJobAsync(ConfigManager.Instance.GetClientInfo().Id); 162 currentlyFetching = true;172 CurrentlyFetching = true; 163 173 } else 164 Logg ing.Instance.Info(this.ToString(),"Currently fetching, won't fetch this time!");174 Logger.Info("Currently fetching, won't fetch this time!"); 165 175 break; 166 176 … … 174 184 //When the timeslice is up 175 185 case MessageContainer.MessageType.UptimeLimitDisconnect: 176 Logg ing.Instance.Info(this.ToString(),"Uptime Limit reached, storing jobs and sending them back");186 Logger.Info("Uptime Limit reached, storing jobs and sending them back"); 177 187 178 188 //check if there are running jobs 179 189 if (engines.Count > 0) { 180 190 //make sure there is no more fetching of jobs while the snapshots get processed 181 currentlyFetching = true;191 CurrentlyFetching = true; 182 192 //request a snapshot of each running job 183 193 foreach (KeyValuePair<Guid, Executor> kvp in engines) { … … 193 203 //Fetch or Force Fetch Calendar! 194 204 case MessageContainer.MessageType.FetchOrForceFetchCalendar: 195 ResponseCalendar rescal = wcfService.GetCalendarSync(ConfigManager.Instance.GetClientInfo().Id); 196 if(rescal.Success) { 197 if(!UptimeManager.Instance.SetAppointments(false, rescal)) { 198 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 199 } else { 200 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.Fetched); 201 } 202 } else { 203 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 204 } 205 Logger.Info("Fetch Calendar from Server"); 206 FetchCalendarFromServer(); 205 207 break; 206 208 207 209 //Hard shutdown of the client 208 210 case MessageContainer.MessageType.Shutdown: 211 Logger.Info("Shutdown Signal received"); 209 212 lock (engines) { 213 Logger.Debug("engines locked"); 210 214 foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) { 215 Logger.Debug("Shutting down Appdomain for " + kvp.Key); 211 216 appDomains[kvp.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException); 212 217 AppDomain.Unload(kvp.Value); 213 218 } 214 219 } 220 Logger.Debug("Stopping heartbeat"); 215 221 abortRequested = true; 216 222 beat.StopHeartBeat(); 223 Logger.Debug("Logging out"); 217 224 WcfService.Instance.Logout(ConfigManager.Instance.GetClientInfo().Id); 218 225 break; … … 230 237 private void GetFinishedJob(object jobId) { 231 238 Guid jId = (Guid)jobId; 232 Logg ing.Instance.Info(this.ToString(),"Getting the finished job with id: " + jId);239 Logger.Info("Getting the finished job with id: " + jId); 233 240 try { 234 241 if (!engines.ContainsKey(jId)) { 235 Logg ing.Instance.Error(this.ToString(), "GetFinishedJob:Engine doesn't exist");242 Logger.Info("Engine doesn't exist"); 236 243 return; 237 244 } … … 240 247 241 248 if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) { 242 Logg ing.Instance.Info(this.ToString(),"Sending the finished job with id: " + jId);249 Logger.Info("Sending the finished job with id: " + jId); 243 250 wcfService.StoreFinishedJobResultAsync(ConfigManager.Instance.GetClientInfo().Id, 244 251 jId, … … 248 255 true); 249 256 } else { 250 Logg ing.Instance.Info(this.ToString(),"Storing the finished job with id: " + jId + " to hdd");257 Logger.Info("Storing the finished job with id: " + jId + " to hdd"); 251 258 JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob); 252 259 lock (engines) { 253 260 appDomains[jId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException); 254 261 AppDomain.Unload(appDomains[jId]); 255 appDomains.Remove(jId); 256 engines.Remove(jId); 262 Logger.Debug("Unloaded appdomain"); 263 appDomains.Remove(jId); 264 engines.Remove(jId); 257 265 jobs.Remove(jId); 266 Logger.Debug("Removed job from appDomains, Engines and Jobs"); 258 267 } 259 268 } 260 269 } 261 270 catch (InvalidStateException ise) { 262 Logg ing.Instance.Error(this.ToString(), "Exception:", ise);271 Logger.Error("Invalid State while Snapshoting:", ise); 263 272 } 264 273 } 265 274 266 275 private void GetSnapshot(object jobId) { 267 Logg ing.Instance.Info(this.ToString(),"Fetching a snapshot for job " + jobId);276 Logger.Info("Fetching a snapshot for job " + jobId); 268 277 Guid jId = (Guid)jobId; 269 278 byte[] obj = engines[jId].GetSnapshot(); 270 Logg ing.Instance.Info(this.ToString(),"BEGIN: Sending snapshot sync");279 Logger.Debug("BEGIN: Sending snapshot sync"); 271 280 wcfService.ProcessSnapshotSync(ConfigManager.Instance.GetClientInfo().Id, 272 281 jId, … … 274 283 engines[jId].Progress, 275 284 null); 276 Logg ing.Instance.Info(this.ToString(),"END: Sended snapshot sync");285 Logger.Debug("END: Sended snapshot sync"); 277 286 //Uptime Limit reached, now is a good time to destroy this jobs. 287 Logger.Debug("Checking if uptime limit is reached"); 278 288 if (!UptimeManager.Instance.IsOnline()) { 289 Logger.Debug("Uptime limit reached"); 290 Logger.Debug("Killing Appdomain"); 279 291 KillAppDomain(jId); 280 //Still anything running? 281 if (engines.Count == 0) 292 //Still anything running? 293 if (engines.Count == 0) { 294 Logger.Info("All jobs snapshotted and sent back, disconnecting"); 282 295 WcfService.Instance.Disconnect(); 296 } else { 297 Logger.Debug("There are still active Jobs in the Field, not disconnecting"); 298 } 283 299 284 300 } else { 285 Logg ing.Instance.Info(this.ToString(),"Restarting the job" + jobId);301 Logger.Debug("Restarting the job" + jobId); 286 302 engines[jId].StartOnlyJob(); 303 Logger.Info("Restarted the job" + jobId); 287 304 } 288 305 } … … 299 316 void wcfService_LoginCompleted(object sender, LoginCompletedEventArgs e) { 300 317 if (e.Result.Success) { 301 currentlyFetching = false;302 Logg ing.Instance.Info(this.ToString(),"Login completed to Hive Server @ " + DateTime.Now);318 CurrentlyFetching = false; 319 Logger.Info("Login completed to Hive Server @ " + DateTime.Now); 303 320 } else 304 Logg ing.Instance.Error(this.ToString(),e.Result.StatusMessage);321 Logger.Error("Error during login: " + e.Result.StatusMessage); 305 322 } 306 323 … … 312 329 void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) { 313 330 if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) { 314 Logg ing.Instance.Info(this.ToString(),"Received new job with id " + e.Result.Job.Id);331 Logger.Info("Received new job with id " + e.Result.Job.Id); 315 332 bool sandboxed = false; 316 333 List<byte[]> files = new List<byte[]>(); 317 Logg ing.Instance.Info(this.ToString(),"Fetching plugins for job " + e.Result.Job.Id);334 Logger.Debug("Fetching plugins for job " + e.Result.Job.Id); 318 335 foreach (CachedHivePluginInfoDto plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded)) 319 336 files.AddRange(plugininfo.PluginFiles); 320 Logg ing.Instance.Info(this.ToString(),"Plugins fetched for job " + e.Result.Job.Id);337 Logger.Debug("Plugins fetched for job " + e.Result.Job.Id); 321 338 AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(e.Result.Job.Id.ToString(), files); 322 339 appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException); … … 325 342 jobs.Add(e.Result.Job.Id, e.Result.Job); 326 343 appDomains.Add(e.Result.Job.Id, appDomain); 327 Logg ing.Instance.Info(this.ToString(),"Creating AppDomain");344 Logger.Debug("Creating AppDomain"); 328 345 Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName); 329 Logg ing.Instance.Info(this.ToString(),"Created AppDomain");346 Logger.Debug("Created AppDomain"); 330 347 engine.JobId = e.Result.Job.Id; 331 348 engine.Queue = MessageQueue.GetInstance(); 332 Logg ing.Instance.Info(this.ToString(),"Starting Engine for job " + e.Result.Job.Id);349 Logger.Debug("Starting Engine for job " + e.Result.Job.Id); 333 350 engine.Start(e.Data); 334 351 engines.Add(e.Result.Job.Id, engine); … … 336 353 ClientStatusInfo.JobsFetched++; 337 354 338 Debug.WriteLine("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched);355 Logger.Info("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched); 339 356 } 340 357 } 341 358 } else 342 Logg ing.Instance.Info(this.ToString(),"No more jobs left!");343 currentlyFetching = false;359 Logger.Info("No more jobs left!"); 360 CurrentlyFetching = false; 344 361 } 345 362 … … 350 367 /// <param name="e"></param> 351 368 void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) { 352 Logg ing.Instance.Info(this.ToString(),"Job submitted with id " + e.Result.JobId);369 Logger.Info("Job submitted with id " + e.Result.JobId); 353 370 KillAppDomain(e.Result.JobId); 354 371 if (e.Result.Success) { 355 372 ClientStatusInfo.JobsProcessed++; 356 Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);373 Logger.Info("Increased ProcessedJobs to:" + ClientStatusInfo.JobsProcessed); 357 374 } else { 358 Logg ing.Instance.Error(this.ToString(),"Sending of job " + e.Result.JobId + " failed, job has been wasted. Message: " + e.Result.StatusMessage);375 Logger.Error("Sending of job " + e.Result.JobId + " failed, job has been wasted. Message: " + e.Result.StatusMessage); 359 376 } 360 377 } … … 366 383 /// <param name="e"></param> 367 384 void wcfService_ProcessSnapshotCompleted(object sender, ProcessSnapshotCompletedEventArgs e) { 368 Logg ing.Instance.Info(this.ToString(),"Snapshot " + e.Result.JobId + " has been transmitted according to plan.");385 Logger.Info("Snapshot " + e.Result.JobId + " has been transmitted according to plan."); 369 386 } 370 387 … … 375 392 /// <param name="e"></param> 376 393 void wcfService_ServerChanged(object sender, EventArgs e) { 377 Logg ing.Instance.Info(this.ToString(),"ServerChanged has been called");394 Logger.Info("ServerChanged has been called"); 378 395 lock (engines) { 379 396 foreach (KeyValuePair<Guid, Executor> entries in engines) { … … 394 411 /// <param name="e"></param> 395 412 void wcfService_Connected(object sender, EventArgs e) { 413 Logger.Info("WCF Service got a connection"); 396 414 if (!UptimeManager.Instance.CalendarAvailable) { 397 ResponseCalendar calres = wcfService.GetCalendarSync(ConfigManager.Instance.GetClientInfo().Id); 398 if(calres.Success) { 399 if (UptimeManager.Instance.SetAppointments(false, calres)) 400 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.Fetched); 401 else 402 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 403 } 404 else { 405 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 406 } 415 Logger.Info("No local calendar available, fetch it"); 416 FetchCalendarFromServer(); 407 417 } 408 418 //if the fetching from the server failed - still set the client online... maybe we get 409 //a result within the next few heartbeats 419 //a result within the next few heartbeats 410 420 if (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline()) { 421 Logger.Info("CalendarAvailable is " + UptimeManager.Instance.CalendarAvailable + " and IsOnline is: " + UptimeManager.Instance.IsOnline()); 422 Logger.Info("Setting client online"); 411 423 wcfService.LoginSync(ConfigManager.Instance.GetClientInfo()); 412 424 JobStorageManager.CheckAndSubmitJobsFromDisc(); 413 currentlyFetching = false; 425 CurrentlyFetching = false; 426 } 427 } 428 429 private void FetchCalendarFromServer() { 430 ResponseCalendar calres = wcfService.GetCalendarSync(ConfigManager.Instance.GetClientInfo().Id); 431 if(calres.Success) { 432 if (UptimeManager.Instance.SetAppointments(false, calres)) { 433 Logger.Info("Remote calendar installed"); 434 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.Fetched); 435 } else { 436 Logger.Info("Remote calendar installation failed, setting state to " + CalendarState.NotAllowedToFetch); 437 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 438 } 439 } else { 440 Logger.Info("Remote calendar installation failed, setting state to " + CalendarState.NotAllowedToFetch); 441 wcfService.SetCalendarStatus(ConfigManager.Instance.GetClientInfo().Id, CalendarState.NotAllowedToFetch); 414 442 } 415 443 } … … 417 445 //this is a little bit tricky - 418 446 void wcfService_ConnectionRestored(object sender, EventArgs e) { 419 Logg ing.Instance.Info(this.ToString(),"Reconnected to old server - checking currently running appdomains");447 Logger.Info("Reconnected to old server - checking currently running appdomains"); 420 448 421 449 foreach (KeyValuePair<Guid, Executor> execKVP in engines) { 422 450 if (!execKVP.Value.Running && execKVP.Value.CurrentMessage == MessageContainer.MessageType.NoMessage) { 423 Logg ing.Instance.Info(this.ToString(),"Checking for JobId: " + execKVP.Value.JobId);451 Logger.Info("Checking for JobId: " + execKVP.Value.JobId); 424 452 Thread finThread = new Thread(new ParameterizedThreadStart(GetFinishedJob)); 425 453 finThread.Start(execKVP.Value.JobId); … … 435 463 436 464 void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { 437 Logg ing.Instance.Error(this.ToString(), "Exception in AppDomain: " + e.ExceptionObject.ToString());465 Logger.Error("Exception in AppDomain: " + e.ExceptionObject.ToString()); 438 466 } 439 467 … … 447 475 /// <param name="id">the GUID of the job</param> 448 476 private void KillAppDomain(Guid id) { 449 Logg ing.Instance.Info(this.ToString(),"Shutting down Appdomain for Job " + id);477 Logger.Debug("Shutting down Appdomain for Job " + id); 450 478 lock (engines) { 451 479 try { … … 457 485 } 458 486 catch (Exception ex) { 459 Logg ing.Instance.Error(this.ToString(),"Exception when unloading the appdomain: ", ex);487 Logger.Error("Exception when unloading the appdomain: ", ex); 460 488 } 461 489 }
Note: See TracChangeset
for help on using the changeset viewer.