Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1133


Ignore:
Timestamp:
01/15/09 14:53:13 (16 years ago)
Author:
msteinbi
Message:

Implementing Lifecycle Management (#453)

Location:
trunk/sources
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/ApplicationConstants.cs

    r1121 r1133  
    6868    public static string RESPONSE_COMMUNICATOR_NO_JOBS_LEFT = "Communicator.NoJobsLeft";
    6969    public static string RESPONSE_COMMUNICATOR_ID_MUST_NOT_BE_SET = "Communicator.IdMustNotBeSet";
    70     public static string RESPONSE_COMMUNICATOR_NO_JO_WITH_THIS_ID = "Communicator.NoJobWithThisId";
     70    public static string RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID = "Communicator.NoJobWithThisId";
    7171    public static string RESPONSE_COMMUNICATOR_WRONG_JOB_STATE = "Communicator.WrongJobState";
    7272    public static string RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN = "Communicator.UserNotLoggedIn";
     73    public static string RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED = "Communicator.JobIsNotBeenigCalculated";
     74    public static string RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB = "Communicator.WrongClientForJob";
    7375
    7476    public static string RESPONSE_JOB_ALL_JOBS = "Job.AllJobs";
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/JobResult.cs

    r1103 r1133  
    3535    public Job Job { get; set; }
    3636    [DataMember]
    37     public byte[] Result { get; set; } // TODO DataStructure for Result needs to be defined
     37    public byte[] Result { get; set; }
     38    [DataMember]
     39    public double Percentage { get; set; }
     40    [DataMember]
     41    public DateTime timestamp { get; set; }
    3842    [DataMember]
    3943    public ClientInfo Client { get; set; }
  • trunk/sources/HeuristicLab.Hive.Contracts/HiveServerMessages.resx

    r1096 r1133  
    229229    <value>User is not logged in, you must login before sending Heartbeats</value>
    230230  </data>
     231  <data name="Communicator.JobIsNotBeenigCalculated" xml:space="preserve">
     232    <value>There is no client registered to calculate this job</value>
     233  </data>
     234  <data name="Communicator.WrongClientForJob" xml:space="preserve">
     235    <value>This client is not registered to calculate this job</value>
     236  </data>
    231237</root>
  • trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/IClientCommunicator.cs

    r1103 r1133  
    4343      long jobId,
    4444      byte[] result,
     45      double percentage,
    4546      Exception exception, 
    4647      bool finished);
  • trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/ILifecycleManager.cs

    r1088 r1133  
    3838    /// The server heartbeat
    3939    /// </summary>
    40     event EventHandler OnServerHeartbeat;
     40    void RegisterHeartbeat(EventHandler handler);
     41
     42    /// <summary>
     43    /// The startup event
     44    /// </summary>
     45    void RegisterStartup(EventHandler handler);
     46
     47    /// <summary>
     48    /// The shutdown event
     49    /// </summary>
     50    void RegisterShutdown(EventHandler handler);
    4151
    4252    /// <summary>
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1127 r1133  
    5858      lifecycleManager = ServiceLocator.GetLifecycleManager();
    5959
    60       lifecycleManager.OnServerHeartbeat +=
    61         new EventHandler(lifecycleManager_OnServerHeartbeat);
     60      lifecycleManager.RegisterHeartbeat(
     61        new EventHandler(lifecycleManager_OnServerHeartbeat));
    6262
    6363      lastHeartbeats = new Dictionary<Guid, DateTime>();
     
    9090                foreach (Job job in allJobs) {
    9191                  if (job.Client.ClientId == client.ClientId) {
    92                     // TODO check for job results
     92                    List<JobResult> allJobResults = new List<JobResult>(jobResultAdapter.GetAll());
     93                    foreach (JobResult jR in allJobResults) {
     94                      JobResult lastJobResult = null;
     95                      if (jR.Job != null && jR.Job.Id == job.Id) {
     96                        if (lastJobResult != null) {
     97
     98                        }
     99                      }
     100                    }
     101
     102
    93103                    job.Client = null;
    94104                    job.Percentage = 0;
     
    231241      long jobId,
    232242      byte[] result,
     243      double percentage,
    233244      Exception exception, 
    234245      bool finished) {
     
    239250      Job job =
    240251        jobAdapter.GetById(jobId);
     252
     253      if (job.Client == null)    {
     254        response.Success = false;
     255        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     256        return response;
     257      }
     258      if (job.Client.ClientId != clientId) {
     259        response.Success = false;
     260        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB;
     261        return response;
     262      }
    241263      if (job == null) {
    242264        response.Success = false;
    243         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JO_WITH_THIS_ID;
     265        response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID;
    244266        return response;
    245267      }
     
    249271        return response;
    250272      }
     273      job.SerializedJob = result;
     274      job.Percentage = percentage;
     275
    251276      if (finished) {
    252277        job.State = State.finished;
     
    263288      jobResult.Job = job;
    264289      jobResult.Result = result;
     290      jobResult.Percentage = percentage;
    265291      jobResult.Exception = exception;
    266292
    267       jobResultAdapter.Update(jobResult);   
     293      jobResultAdapter.Update(jobResult);
     294      jobAdapter.Update(job);
    268295
    269296      response.Success = true;
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientFacade.cs

    r1103 r1133  
    5151      long jobId,
    5252      byte[] result,
     53      double percentage,
    5354      Exception exception,
    5455      bool finished) {
    55       return clientCommunicator.SendJobResult(clientId, jobId, result, exception, finished);
     56      return clientCommunicator.SendJobResult(clientId, jobId, result, percentage, exception, finished);
    5657    }
    5758
  • trunk/sources/HeuristicLab.Hive.Server.Core/JobManager.cs

    r1121 r1133  
    3333
    3434    IJobAdapter jobAdapter;
     35    ILifecycleManager lifecycleManager;
    3536
    3637    #region IJobManager Members
     
    3839    public JobManager() {
    3940      jobAdapter = ServiceLocator.GetJobAdapter();
     41
     42      lifecycleManager = ServiceLocator.GetLifecycleManager();
     43
     44      lifecycleManager.RegisterStartup(new EventHandler(lifecycleManager_OnStartup));
     45      lifecycleManager.RegisterStartup(new EventHandler(lifecycleManager_OnShutdown));
     46    }
     47
     48    void checkForDeadJobs() {
     49      List<Job> allJobs = new List<Job>(jobAdapter.GetAll());
     50      foreach (Job curJob in allJobs) {
     51        if (curJob.State == State.calculating) {
     52          // TODO check for job results
     53          curJob.State = State.idle;
     54          curJob.Percentage = 0;
     55          curJob.Client = null;
     56        }
     57      }
     58    }
     59
     60    void lifecycleManager_OnStartup(object sender, EventArgs e) {
     61      checkForDeadJobs();
     62    }
     63
     64    void lifecycleManager_OnShutdown(object sender, EventArgs e) {
     65      checkForDeadJobs();
    4066    }
    4167
  • trunk/sources/HeuristicLab.Hive.Server.Core/LifecycleManager.cs

    r1088 r1133  
    3333      new Timer();
    3434
     35    private static event EventHandler OnServerHeartbeat;
     36    private static event EventHandler OnStartup;
     37    private static event EventHandler OnShutdown;
    3538    #region ILifecycleManager Members
    36     public event EventHandler OnServerHeartbeat;
    3739
    38     public LifecycleManager() {
    39       timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
     40    public void RegisterHeartbeat(EventHandler handler) {
     41      OnServerHeartbeat += handler;
     42    }
     43
     44    public void RegisterStartup(EventHandler handler) {
     45      OnStartup += handler;
     46    }
     47
     48    public void RegisterShutdown(EventHandler handler) {
     49      OnShutdown += handler;
    4050    }
    4151
    4252    public void Init() {
    4353      timer.Interval = new TimeSpan(0, 0, 10).TotalMilliseconds; // TODO: global constant needed
     54      timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
    4455      timer.Start();
     56
     57      if (OnStartup != null)
     58        OnStartup(this, null);
    4559    }
    4660
     
    5670    public void Shutdown() {
    5771      ServiceLocator.GetTransactionManager().UpdateDB();
     72
     73      if (OnShutdown != null)
     74        OnShutdown(this, null);
    5875    }
    5976
Note: See TracChangeset for help on using the changeset viewer.