Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/01/10 13:58:24 (14 years ago)
Author:
kgrading
Message:

Removed References to HiveLogging and updated the default logging mechanism (#991)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs

    r3220 r3578  
    4444using HeuristicLab.Hive.JobBase;
    4545using HeuristicLab.Hive.Client.Core.JobStorage;
     46using HeuristicLab.Tracing;
    4647
    4748namespace HeuristicLab.Hive.Client.Core {
     
    5152  public class Core : MarshalByRefObject {
    5253    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    }
    5464
    5565    private Dictionary<Guid, Executor> engines = new Dictionary<Guid, Executor>();
     
    6575    public void Start() {
    6676      abortRequested = false;
    67       Logging.Instance.Info(this.ToString(), "Hive Client started");
     77      Logger.Info("Hive Client started");
    6878      ClientConsoleServer server = new ClientConsoleServer();
    6979      server.StartClientConsoleServer(new Uri("net.tcp://127.0.0.1:8000/ClientConsole/"));
     
    104114        DetermineAction(container);
    105115      }
    106       System.Console.WriteLine("ended");
     116      Logger.Info("Program shutdown");
    107117    }
    108118
     
    112122    /// <param name="container">The Container, containing the message</param>
    113123    private void DetermineAction(MessageContainer container) {
    114       Logging.Instance.Info(this.ToString(), "Message: " + container.Message.ToString() + " for job: " + container.JobId);       
     124      Logger.Info("Message: " + container.Message.ToString() + " for job: " + container.JobId);       
    115125      switch (container.Message) {
    116126        //Server requests to abort a job
     
    119129            engines[container.JobId].Abort();
    120130          else
    121             Logging.Instance.Error(this.ToString(), "AbortJob: Engine doesn't exist");
     131            Logger.Error("AbortJob: Engine doesn't exist");
    122132          break;
    123133        //Job has been successfully aborted
     
    136146              GC.Collect();
    137147            } else
    138               Logging.Instance.Error(this.ToString(), "JobAbort: Engine doesn't exist");
     148              Logger.Error("JobAbort: Engine doesn't exist");
    139149          }
    140150          break;
     
    146156            engines[container.JobId].RequestSnapshot();
    147157          else
    148             Logging.Instance.Error(this.ToString(), "RequestSnapshot: Engine doesn't exist");
     158            Logger.Error("RequestSnapshot: Engine doesn't exist");
    149159          break;
    150160
     
    158168        //Pull a Job from the Server
    159169        case MessageContainer.MessageType.FetchJob:         
    160           if (!currentlyFetching) {
     170          if (!CurrentlyFetching) {
    161171            wcfService.SendJobAsync(ConfigManager.Instance.GetClientInfo().Id);
    162             currentlyFetching = true;
     172            CurrentlyFetching = true;
    163173          } else
    164             Logging.Instance.Info(this.ToString(), "Currently fetching, won't fetch this time!");
     174            Logger.Info("Currently fetching, won't fetch this time!");
    165175          break;         
    166176       
     
    174184        //When the timeslice is up
    175185        case MessageContainer.MessageType.UptimeLimitDisconnect:
    176           Logging.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");
    177187
    178188          //check if there are running jobs
    179189          if (engines.Count > 0) {
    180190            //make sure there is no more fetching of jobs while the snapshots get processed
    181             currentlyFetching = true;
     191            CurrentlyFetching = true;
    182192            //request a snapshot of each running job
    183193            foreach (KeyValuePair<Guid, Executor> kvp in engines) {
     
    193203          //Fetch or Force Fetch Calendar!
    194204        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(); 
    205207        break;
    206208
    207209        //Hard shutdown of the client
    208210        case MessageContainer.MessageType.Shutdown:
     211          Logger.Info("Shutdown Signal received");
    209212          lock (engines) {
     213            Logger.Debug("engines locked");
    210214            foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) {
     215              Logger.Debug("Shutting down Appdomain for " + kvp.Key);
    211216              appDomains[kvp.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    212217              AppDomain.Unload(kvp.Value);
    213218            }
    214219          }
     220          Logger.Debug("Stopping heartbeat");
    215221          abortRequested = true;
    216222          beat.StopHeartBeat();
     223          Logger.Debug("Logging out");
    217224          WcfService.Instance.Logout(ConfigManager.Instance.GetClientInfo().Id);
    218225          break;
     
    230237    private void GetFinishedJob(object jobId) {
    231238      Guid jId = (Guid)jobId;
    232       Logging.Instance.Info(this.ToString(), "Getting the finished job with id: " + jId);
     239      Logger.Info("Getting the finished job with id: " + jId);
    233240      try {
    234241        if (!engines.ContainsKey(jId)) {
    235           Logging.Instance.Error(this.ToString(), "GetFinishedJob: Engine doesn't exist");
     242          Logger.Info("Engine doesn't exist");
    236243          return;
    237244        }
     
    240247
    241248        if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) {
    242           Logging.Instance.Info(this.ToString(), "Sending the finished job with id: " + jId);
     249          Logger.Info("Sending the finished job with id: " + jId);
    243250          wcfService.StoreFinishedJobResultAsync(ConfigManager.Instance.GetClientInfo().Id,
    244251            jId,
     
    248255            true);
    249256        } else {
    250           Logging.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");
    251258          JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob);
    252259          lock (engines) {
    253260            appDomains[jId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    254261            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);           
    257265            jobs.Remove(jId);
     266            Logger.Debug("Removed job from appDomains, Engines and Jobs");
    258267          }
    259268        }
    260269      }
    261270      catch (InvalidStateException ise) {
    262         Logging.Instance.Error(this.ToString(), "Exception: ", ise);
     271        Logger.Error("Invalid State while Snapshoting:", ise);
    263272      }
    264273    }
    265274
    266275    private void GetSnapshot(object jobId) {
    267       Logging.Instance.Info(this.ToString(), "Fetching a snapshot for job " + jobId);
     276      Logger.Info("Fetching a snapshot for job " + jobId);
    268277      Guid jId = (Guid)jobId;
    269278      byte[] obj = engines[jId].GetSnapshot();
    270       Logging.Instance.Info(this.ToString(), "BEGIN: Sending snapshot sync");
     279      Logger.Debug("BEGIN: Sending snapshot sync");
    271280      wcfService.ProcessSnapshotSync(ConfigManager.Instance.GetClientInfo().Id,
    272281        jId,
     
    274283        engines[jId].Progress,
    275284        null);
    276       Logging.Instance.Info(this.ToString(), "END: Sended snapshot sync");
     285      Logger.Debug("END: Sended snapshot sync");
    277286      //Uptime Limit reached, now is a good time to destroy this jobs.
     287      Logger.Debug("Checking if uptime limit is reached");
    278288      if (!UptimeManager.Instance.IsOnline()) {
     289        Logger.Debug("Uptime limit reached");
     290        Logger.Debug("Killing Appdomain");
    279291        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");         
    282295          WcfService.Instance.Disconnect();
     296        } else {
     297          Logger.Debug("There are still active Jobs in the Field, not disconnecting");
     298        }
    283299
    284300      } else {
    285         Logging.Instance.Info(this.ToString(), "Restarting the job" + jobId);
     301        Logger.Debug("Restarting the job" + jobId);
    286302        engines[jId].StartOnlyJob();
     303        Logger.Info("Restarted the job" + jobId);
    287304      }
    288305    }
     
    299316    void wcfService_LoginCompleted(object sender, LoginCompletedEventArgs e) {
    300317      if (e.Result.Success) {
    301         currentlyFetching = false;
    302         Logging.Instance.Info(this.ToString(), "Login completed to Hive Server @ " + DateTime.Now);
     318        CurrentlyFetching = false;
     319        Logger.Info("Login completed to Hive Server @ " + DateTime.Now);
    303320      } else
    304         Logging.Instance.Error(this.ToString(), e.Result.StatusMessage);
     321        Logger.Error("Error during login: " + e.Result.StatusMessage);
    305322    }
    306323
     
    312329    void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) {
    313330      if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) {
    314         Logging.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);     
    315332        bool sandboxed = false;
    316333        List<byte[]> files = new List<byte[]>();
    317         Logging.Instance.Info(this.ToString(), "Fetching plugins for job " + e.Result.Job.Id);
     334        Logger.Debug("Fetching plugins for job " + e.Result.Job.Id);
    318335        foreach (CachedHivePluginInfoDto plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded))
    319336          files.AddRange(plugininfo.PluginFiles);
    320         Logging.Instance.Info(this.ToString(), "Plugins fetched for job " + e.Result.Job.Id);
     337        Logger.Debug("Plugins fetched for job " + e.Result.Job.Id);
    321338        AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(e.Result.Job.Id.ToString(), files);
    322339        appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException);
     
    325342            jobs.Add(e.Result.Job.Id, e.Result.Job);
    326343            appDomains.Add(e.Result.Job.Id, appDomain);
    327             Logging.Instance.Info(this.ToString(), "Creating AppDomain");
     344            Logger.Debug("Creating AppDomain");
    328345            Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    329             Logging.Instance.Info(this.ToString(), "Created AppDomain");
     346            Logger.Debug("Created AppDomain");
    330347            engine.JobId = e.Result.Job.Id;
    331348            engine.Queue = MessageQueue.GetInstance();
    332             Logging.Instance.Info(this.ToString(), "Starting Engine for job " + e.Result.Job.Id);
     349            Logger.Debug("Starting Engine for job " + e.Result.Job.Id);
    333350            engine.Start(e.Data);
    334351            engines.Add(e.Result.Job.Id, engine);
     
    336353            ClientStatusInfo.JobsFetched++;
    337354
    338             Debug.WriteLine("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched);
     355            Logger.Info("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched);
    339356          }
    340357        }
    341358      } else
    342         Logging.Instance.Info(this.ToString(), "No more jobs left!");
    343       currentlyFetching = false;
     359        Logger.Info("No more jobs left!");
     360      CurrentlyFetching = false;
    344361    }
    345362
     
    350367    /// <param name="e"></param>
    351368    void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) {
    352       Logging.Instance.Info(this.ToString(), "Job submitted with id " + e.Result.JobId);
     369      Logger.Info("Job submitted with id " + e.Result.JobId);
    353370      KillAppDomain(e.Result.JobId);
    354371      if (e.Result.Success) {
    355372        ClientStatusInfo.JobsProcessed++;
    356         Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);
     373        Logger.Info("Increased ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);
    357374      } else {
    358         Logging.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);
    359376      }
    360377    }
     
    366383    /// <param name="e"></param>
    367384    void wcfService_ProcessSnapshotCompleted(object sender, ProcessSnapshotCompletedEventArgs e) {
    368       Logging.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.");
    369386    }
    370387
     
    375392    /// <param name="e"></param>
    376393    void wcfService_ServerChanged(object sender, EventArgs e) {
    377       Logging.Instance.Info(this.ToString(), "ServerChanged has been called");
     394      Logger.Info("ServerChanged has been called");
    378395      lock (engines) {
    379396        foreach (KeyValuePair<Guid, Executor> entries in engines) {
     
    394411    /// <param name="e"></param>
    395412    void wcfService_Connected(object sender, EventArgs e) {
     413      Logger.Info("WCF Service got a connection");
    396414      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();
    407417      }
    408418      //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     
    410420      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");
    411423        wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());
    412424        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);
    414442      }
    415443    }
     
    417445    //this is a little bit tricky -
    418446    void wcfService_ConnectionRestored(object sender, EventArgs e) {
    419       Logging.Instance.Info(this.ToString(), "Reconnected to old server - checking currently running appdomains");
     447      Logger.Info("Reconnected to old server - checking currently running appdomains");
    420448
    421449      foreach (KeyValuePair<Guid, Executor> execKVP in engines) {
    422450        if (!execKVP.Value.Running && execKVP.Value.CurrentMessage == MessageContainer.MessageType.NoMessage) {
    423           Logging.Instance.Info(this.ToString(), "Checking for JobId: " + execKVP.Value.JobId);
     451          Logger.Info("Checking for JobId: " + execKVP.Value.JobId);
    424452          Thread finThread = new Thread(new ParameterizedThreadStart(GetFinishedJob));
    425453          finThread.Start(execKVP.Value.JobId);
     
    435463
    436464    void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
    437       Logging.Instance.Error(this.ToString(), "Exception in AppDomain: " + e.ExceptionObject.ToString());
     465      Logger.Error("Exception in AppDomain: " + e.ExceptionObject.ToString());   
    438466    }
    439467
     
    447475    /// <param name="id">the GUID of the job</param>
    448476    private void KillAppDomain(Guid id) {
    449       Logging.Instance.Info(this.ToString(), "Shutting down Appdomain for Job " + id);
     477      Logger.Debug("Shutting down Appdomain for Job " + id);
    450478      lock (engines) {
    451479        try {
     
    457485        }
    458486        catch (Exception ex) {
    459           Logging.Instance.Error(this.ToString(), "Exception when unloading the appdomain: ", ex);
     487          Logger.Error("Exception when unloading the appdomain: ", ex);
    460488        }
    461489      }
Note: See TracChangeset for help on using the changeset viewer.