Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/10 09:17:24 (14 years ago)
Author:
kgrading
Message:

added minor speedups and better transaction handling to the server (#828)

Location:
branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r3578 r3931  
    120120                Logger.Info("Client timed out and is on RESET");
    121121                foreach (JobDto job in DaoLocator.JobDao.FindActiveJobsOfClient(client)) {
    122                   jobManager.ResetJobsDependingOnResults(job);
     122                  DaoLocator.JobDao.SetJobOffline(job);
    123123                  lock (newAssignedJobs) {
    124124                    if (newAssignedJobs.ContainsKey(job.Id))
     
    149149              lastHeartbeats.Remove(client.Id);
    150150            foreach (JobDto job in DaoLocator.JobDao.FindActiveJobsOfClient(client)) {
    151               jobManager.ResetJobsDependingOnResults(job);
     151              DaoLocator.JobDao.SetJobOffline(job);
    152152            }
    153153            heartbeatLock.ExitWriteLock();
     
    428428      JobDto job2Calculate = scheduler.GetNextJobForClient(clientId);
    429429      if (job2Calculate != null) {
    430         response.Job = job2Calculate;
     430        response.Job = job2Calculate;       
    431431        response.Job.PluginsNeeded = DaoLocator.PluginInfoDao.GetPluginDependenciesForJob(response.Job);
    432432        response.Success = true;
     
    481481
    482482      if (response.Success) {
    483         jobStream = DaoLocator.JobDao.GetSerializedJobStream(result.JobId);
    484 
     483        Logger.Debug("Trying to aquire WCF Job Stream");
     484        //jobStream = DaoLocator.JobDao.GetSerializedJobStream(result.JobId);
     485        //Logger.Debug("Job Stream Aquired");
    485486        byte[] buffer = new byte[3024];
     487        List<byte> serializedJob = new List<byte>();
    486488        int read = 0;
    487         while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
    488           jobStream.Write(buffer, 0, read);
    489         }
    490         jobStream.Close();
     489        int i = 0;       
     490        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {         
     491          for (int j = 0; j < read; j++) {
     492            serializedJob.Add(buffer[j]);
     493          }
     494          if (i% 100 == 0)
     495            Logger.Debug("Writing to stream: " + i);         
     496          //jobStream.Write(buffer, 0, read);
     497          i++;
     498        }
     499        Logger.Debug("Done Writing, closing the stream!");               
     500        //jobStream.Close();
     501
     502        DaoLocator.JobDao.SetBinaryJobFile(result.JobId, serializedJob.ToArray());
    491503      }
    492504      Logger.Info("END Job received for Storage:");
     505      stream.Dispose();
    493506      return response;
    494507    }
     
    656669        foreach (JobDto job in jobsOfClient) {
    657670          if (job.State != State.finished)
    658             jobManager.ResetJobsDependingOnResults(job);
     671            DaoLocator.JobDao.SetJobOffline(job);
    659672        }
    660673      }
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/ClientFacade.cs

    r3220 r3931  
    114114      IJobManager jobManager =
    115115        ServiceLocator.GetJobManager();
    116 
     116      IInternalJobManager internalJobManager = (IInternalJobManager) jobManager;
     117     
    117118      //second stream the job binary data
    118      
     119      MemoryStream memoryStream = new MemoryStream();     
    119120      if(job.Job != null)
    120         stream.AddStream(
    121           ((IInternalJobManager) (jobManager)).
    122             GetJobStreamById(
    123             job.Job.Id));
     121        stream.AddStream(new MemoryStream(internalJobManager.GetSerializedJobDataById(job.Job.Id)));
    124122     
    125123      OperationContext clientContext = OperationContext.Current;
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/DbTestApp.cs

    r3220 r3931  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    3739using HeuristicLab.Hive.Server.LINQDataAccess;
    3840using System.Transactions;
     41using System.Threading;
     42using HeuristicLab.Tracing;
    3943
    4044namespace HeuristicLab.Hive.Server {
    4145  [Application("Hive DB Test App", "Test Application for the Hive DataAccess Layer")]
    42   class HiveDbTestApplication : ApplicationBase {
     46  internal class HiveDbTestApplication : ApplicationBase {
    4347    /*private void TestJobStreaming() {
    4448      ISessionFactory factory =
     
    111115    } */
    112116
    113     ClientDao clientDao = new ClientDao();
    114     ClientGroupDao cgd = new ClientGroupDao();
    115 
    116     private void TestLINQImplementation() {     
    117      
    118      
     117    private ClientDao clientDao = new ClientDao();
     118    private ClientGroupDao cgd = new ClientGroupDao();
     119
     120    private void TestLINQImplementation() {
    119121      ClientDto c1 = new ClientDto();
    120122      c1.Id = Guid.NewGuid();
     
    143145      c2 = clientDao.Insert(c2);
    144146
    145       //ClientDto info2 = clientDao.FindById(info.Id);
    146       //Console.WriteLine(info2);
    147      
    148147      ClientGroupDto tg = new ClientGroupDto();
    149148      tg.Name = "TopGroup";
     
    174173
    175174      List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients());
    176      
     175
    177176      cgd.RemoveRessourceFromClientGroup(sg.Id, tg.Id);
    178177
     
    181180      clientDao.Delete(c1);
    182181      clientDao.Delete(c2);
    183 
    184182    }
    185183
     
    220218        sg = cgd.Insert(sg);
    221219        cgd.AddRessourceToClientGroup(sg.Id, mg.Id);
    222         populateMainGroup(sg, p-1);
    223       }
    224 
    225      
    226     }
    227 
     220        populateMainGroup(sg, p - 1);
     221      }
     222    }
    228223
    229224
     
    235230      //TestJobResultDeserialization();
    236231
     232      //if (ContextFactory.Context.DatabaseExists())
     233      //  ContextFactory.Context.DeleteDatabase();
     234      //ContextFactory.Context.CreateDatabase();
    237235      //TestLINQImplementation();
     236      TestLinqFileHandling();
    238237      //StressTest();
    239238
    240239      //SpeedTest();
    241240      //TestJobBytearrFetching();
    242       TestJobStreamFetching();
    243 
    244     }
    245 
    246     private void TestJobStreamFetching() {
     241      //TestJobStreamFetching();
     242    }
     243
     244    private void WriteToJobWithByte(object jobid) {
     245      using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
     246                                                           new TransactionOptions
     247                                                           {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})
     248        ) {
     249        Logger.Info("starting bytestuff for job " + jobid);
     250        DaoLocator.JobDao.SetBinaryJobFile((Guid)jobid, jobmap[(Guid)jobid]);
     251        scope.Complete();
     252        Logger.Info("ended bytestuff for job " + jobid);
     253      }
     254    }
     255
     256    private void UpdateJobStatus(object jobid) {
     257      using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
     258                                                           new TransactionOptions
     259                                                           {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})
     260        ) {
     261        Thread.Sleep(1500);
     262        Logger.Info("starting now");
     263        JobDto job = DaoLocator.JobDao.FindById((Guid)jobid);
     264        job.Percentage = new Random().NextDouble();
     265        DaoLocator.JobDao.Update(job);
     266        scope.Complete();
     267        Logger.Info("ended");
     268      }
     269    }
     270
     271    Dictionary<Guid, byte[]> jobmap = new Dictionary<Guid, byte[]>();
     272
     273
     274    private void TestLinqFileHandling() {
     275      List<Thread> jobupdateThreads = new List<Thread>();
     276      List<Thread> jobProgressThreads = new List<Thread>();
     277     
     278      Random r = new Random();
     279      Stack<JobDto> jobs = new Stack<JobDto>(DaoLocator.JobDao.FindAll());
     280      Logger.Info("Fetched jobs");
     281      for (int x = 0; x < 10 && jobs.Count > 0; x++ ) {
     282        Logger.Info("Creating data for Job");
     283        JobDto job = jobs.Pop();
     284        byte[] jobarr = new byte[50*1024*1024];
     285        for (int i = 0; i < jobarr.Length; i++) {
     286          jobarr[i] = (byte) r.Next(255);
     287        }
     288        jobmap.Add(job.Id, jobarr);
     289      }
     290      Logger.Info("filled");
     291      foreach(KeyValuePair<Guid, byte[]> kvp in jobmap) {
     292        Thread tjob = new Thread(new ParameterizedThreadStart(WriteToJobWithByte));     
     293        Thread tupdate = new Thread(new ParameterizedThreadStart(UpdateJobStatus));
     294        jobupdateThreads.Add(tupdate);
     295        jobProgressThreads.Add(tjob);
     296        tupdate.Start(kvp.Key);
     297        tjob.Start(kvp.Key);
     298      }
     299      foreach (Thread t in jobupdateThreads) {
     300        t.Join();
     301      }
     302      foreach (Thread t in jobProgressThreads) {
     303        t.Join();
     304      }
     305    }
     306
     307
     308    private
     309      void TestJobStreamFetching() {
    247310      //using (TransactionScope scope = new TransactionScope()) {
     311
    248312      HiveDataContext context = ContextFactory.Context;
    249313
    250       ContextFactory.Context.Connection.Open();
    251       ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction();
    252      
     314      ContextFactory.Context.Connection.Open
     315        ();
     316      ContextFactory.Context.Transaction
     317        =
     318        ContextFactory.Context.Connection.BeginTransaction
     319          ();
     320
     321
    253322      ClientFacade facade = new ClientFacade();
     323
    254324      Stream stream = facade.SendStreamedJob(new Guid("F5CFB334-66A0-417C-A585-71711BA21D3F"));
    255      
     325
     326
    256327      byte[] buffer = new byte[3024];
     328
    257329      int read = 0;
    258      
    259       while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {}
    260      
    261       stream.Close();
     330
     331      while ((
     332               read
     333               =
     334               stream.Read
     335                 (
     336                 buffer
     337                 , 0,
     338                 buffer.Length
     339                 )) > 0) {}
     340
     341      stream.Close
     342        ();
    262343
    263344      //Stream stream = DaoLocator.JobDao.GetSerializedJobStream(new Guid("bbb51f87-4e2f-4499-a9b6-884e589c78b6"));
     
    265346    }
    266347
    267     private void TestJobBytearrFetching() {
     348    private
     349      void TestJobBytearrFetching() {
    268350      byte[] arr = DaoLocator.JobDao.GetBinaryJobFile(new Guid("A3386907-2B3C-4976-BE07-04D660D40A5B"));
    269       Console.WriteLine(arr);
    270     }
    271 
    272     private void SpeedTest() {
     351      Console.WriteLine
     352        (
     353        arr
     354        );
     355    }
     356
     357    private
     358      void SpeedTest() {
    273359      DateTime start = new DateTime();
     360
    274361      List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients());
     362
    275363      DateTime end = new DateTime();
     364
    276365      TimeSpan used = end - start;
    277       Console.WriteLine(used.TotalMilliseconds);
    278     }
    279 
    280 
     366      Console.WriteLine
     367        (
     368        used.TotalMilliseconds
     369        );
     370    }
    281371  }
    282372}
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/InternalInterfaces/IInternalJobManager.cs

    r3011 r3931  
    2828
    2929namespace HeuristicLab.Hive.Server.Core.InternalInterfaces {
    30   interface IInternalJobManager {
    31     void ResetJobsDependingOnResults(JobDto job);
    32 
     30  interface IInternalJobManager {   
    3331    Stream GetJobStreamById(Guid jobId);
     32    byte[] GetSerializedJobDataById(Guid jobId);
     33    void SetSerializedJobDataById(Guid jobId, byte[] data);
    3434  }
    3535}
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r3578 r3931  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    3840
    3941namespace HeuristicLab.Hive.Server.Core {
    40   class JobManager: IJobManager, IInternalJobManager {
    41 
     42  internal class JobManager : IJobManager, IInternalJobManager {
    4243    //ISessionFactory factory;
    43     ILifecycleManager lifecycleManager;
     44    private ILifecycleManager lifecycleManager;
    4445
    4546    #region IJobManager Members
     
    5354    }
    5455
    55     private JobDto GetLastJobResult(Guid jobId) {     
     56    private JobDto GetLastJobResult(Guid jobId) {
    5657      return DaoLocator.JobDao.FindById(jobId);
    5758    }
    5859
    59     public void ResetJobsDependingOnResults(JobDto job) {
    60       Logger.Info("Setting job " + job.Id + " offline");
    61       if (job != null) {
    62         DaoLocator.JobDao.SetJobOffline(job);
    63       }
    64     }
    65          
    66 
    67     void checkForDeadJobs() {
     60
     61    private void checkForDeadJobs() {
    6862      Logger.Info("Searching for dead Jobs");
    69       using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE })) {
     63      using (
     64        TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
     65                                                      new TransactionOptions
     66                                                      {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})) {
    7067        List<JobDto> allJobs = new List<JobDto>(DaoLocator.JobDao.FindAll());
    7168        foreach (JobDto curJob in allJobs) {
    72           if (curJob.State != State.calculating) {
    73             ResetJobsDependingOnResults(curJob);
     69          if (curJob.State != State.calculating && curJob.State != State.finished) {
     70            DaoLocator.JobDao.SetJobOffline(curJob);
    7471          }
    7572        }
     
    7976    }
    8077
    81     void lifecycleManager_OnStartup(object sender, EventArgs e) {
     78    private void lifecycleManager_OnStartup(object sender, EventArgs e) {
     79      Logger.Info("Startup Event Fired, Checking DB for consistency");
    8280      checkForDeadJobs();
    83     }
    84 
    85     void lifecycleManager_OnShutdown(object sender, EventArgs e) {
     81      Logger.Info("Startup Event Done");
     82    }
     83
     84    private void lifecycleManager_OnShutdown(object sender, EventArgs e) {
     85      Logger.Info("Startup Event Fired, Checking DB for consistency");
    8686      checkForDeadJobs();
     87      Logger.Info("Startup Event Done");
    8788    }
    8889
     
    9293    /// <returns></returns>
    9394    public ResponseList<JobDto> GetAllJobs() {
    94          ResponseList<JobDto> response = new ResponseList<JobDto>();
    95 
    96          response.List = new List<JobDto>(DaoLocator.JobDao.FindAll());
    97          response.Success = true;
    98          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ALL_JOBS;
    99 
    100          return response;
     95      ResponseList<JobDto> response = new ResponseList<JobDto>();
     96
     97      response.List = new List<JobDto>(DaoLocator.JobDao.FindAll());
     98      response.Success = true;
     99      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ALL_JOBS;
     100
     101      return response;
    101102    }
    102103
     
    105106      response.List = new List<JobDto>(DaoLocator.JobDao.FindWithLimitations(jobState, offset, count));
    106107      return response;
    107     } 
     108    }
    108109
    109110    /// <summary>
     
    112113    /// <param name="jobId"></param>
    113114    /// <returns></returns>
    114     public Stream GetJobStreamById(Guid jobId) {           
     115    public Stream GetJobStreamById(Guid jobId) {
    115116      return DaoLocator.JobDao.GetSerializedJobStream(jobId);
    116      
    117117    }
    118118
     
    122122    /// <returns></returns>
    123123    public ResponseObject<JobDto> GetJobById(Guid jobId) {
    124         ResponseObject<JobDto> response = new ResponseObject<JobDto>();
     124      ResponseObject<JobDto> response = new ResponseObject<JobDto>();
    125125
    126126      response.Obj = DaoLocator.JobDao.FindById(jobId);
    127         if (response.Obj != null) {
    128           response.Success = true;
    129           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_GET_JOB_BY_ID;
    130         } else {
    131           response.Success = false;
    132           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
    133         }
    134 
    135         return response;
    136       }
     127      if (response.Obj != null) {
     128        response.Success = true;
     129        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_GET_JOB_BY_ID;
     130      }
     131      else {
     132        response.Success = false;
     133        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
     134      }
     135
     136      return response;
     137    }
    137138
    138139    public ResponseObject<JobDto> GetJobByIdWithDetails(Guid jobId) {
     
    144145
    145146        job.Obj.Client = DaoLocator.ClientDao.GetClientForJob(jobId);
    146       } else {
     147      }
     148      else {
    147149        job.Success = false;
    148150        job.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
    149       }     
     151      }
    150152      return job;
    151153    }
     
    154156      IClientGroupDao cgd = DaoLocator.ClientGroupDao;
    155157      foreach (string res in resources) {
    156         foreach(ClientGroupDto cg in cgd.FindByName(res)) {
     158        foreach (ClientGroupDto cg in cgd.FindByName(res)) {
    157159          job.JobInfo.AssignedResourceIds.Add(cg.Id);
    158160        }
     
    167169    /// <returns></returns>
    168170    public ResponseObject<JobDto> AddNewJob(SerializedJob job) {
    169         ResponseObject<JobDto> response = new ResponseObject<JobDto>();
    170 
    171         if (job != null && job.JobInfo != null) {
    172           if (job.JobInfo.State != State.offline) {
    173             response.Success = false;
    174             response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
    175             return response;
    176           }
    177           if (job.JobInfo.Id != Guid.Empty) {
    178             response.Success = false;
    179             response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
    180             return response;
    181           }
    182           if (job.SerializedJobData == null) {
    183             response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL;
    184             response.Success = false;
    185             return response;
    186           }
    187 
    188           job.JobInfo.DateCreated = DateTime.Now;
    189           DaoLocator.JobDao.InsertWithAttachedJob(job);
    190           DaoLocator.PluginInfoDao.InsertPluginDependenciesForJob(job.JobInfo);
    191          
    192           response.Success = true;
    193           response.Obj = job.JobInfo;
    194           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
    195         } else {
     171      ResponseObject<JobDto> response = new ResponseObject<JobDto>();
     172
     173      if (job != null && job.JobInfo != null) {
     174        if (job.JobInfo.State != State.offline) {
    196175          response.Success = false;
     176          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
     177          return response;
     178        }
     179        if (job.JobInfo.Id != Guid.Empty) {
     180          response.Success = false;
     181          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
     182          return response;
     183        }
     184        if (job.SerializedJobData == null) {
    197185          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL;
    198         }
    199 
     186          response.Success = false;
     187          return response;
     188        }
     189
     190        job.JobInfo.DateCreated = DateTime.Now;
     191        DaoLocator.JobDao.InsertWithAttachedJob(job);
     192        DaoLocator.PluginInfoDao.InsertPluginDependenciesForJob(job.JobInfo);
     193
     194        response.Success = true;
     195        response.Obj = job.JobInfo;
     196        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
     197      }
     198      else {
     199        response.Success = false;
     200        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL;
     201      }
     202
     203      return response;
     204    }
     205
     206    /// <summary>
     207    /// Removes a job from the database
     208    /// </summary>
     209    /// <param name="jobId"></param>
     210    /// <returns></returns>
     211    public Response RemoveJob(Guid jobId) {
     212      Response response = new Response();
     213
     214      JobDto job = DaoLocator.JobDao.FindById(jobId);
     215      if (job == null) {
     216        response.Success = false;
     217        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
    200218        return response;
    201219      }
    202     /*  finally {
    203         if (session != null)
    204           session.EndSession();
    205       }
    206     } */
    207 
    208     /// <summary>
    209     /// Removes a job from the database
    210     /// </summary>
    211     /// <param name="jobId"></param>
    212     /// <returns></returns>
    213     public Response RemoveJob(Guid jobId) {
    214         Response response = new Response();
    215 
    216       JobDto job = DaoLocator.JobDao.FindById(jobId);
    217         if (job == null) {
    218           response.Success = false;
    219           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
    220           return response;
    221         }
    222         DaoLocator.JobDao.Delete(job);
    223         response.Success = false;
    224         response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_REMOVED;
    225 
    226         return response;
    227       }
     220      DaoLocator.JobDao.Delete(job);
     221      response.Success = false;
     222      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_REMOVED;
     223
     224      return response;
     225    }
    228226
    229227    public ResponseObject<JobDto> GetLastJobResultOf(Guid jobId) {
     
    231229        new ResponseObject<JobDto>();
    232230
    233        result.Obj =
    234          GetLastJobResult(jobId);
    235        result.Success =
    236          result.Obj != null;
    237 
    238        return result;
     231      result.Obj =
     232        GetLastJobResult(jobId);
     233      result.Success =
     234        result.Obj != null;
     235
     236      return result;
    239237    }
    240238
    241239    public ResponseObject<SerializedJob>
    242240      GetLastSerializedJobResultOf(Guid jobId, bool requested) {
    243 
    244         ResponseObject<SerializedJob> response =
    245           new ResponseObject<SerializedJob>();
     241      ResponseObject<SerializedJob> response =
     242        new ResponseObject<SerializedJob>();
    246243
    247244      JobDto job = DaoLocator.JobDao.FindById(jobId);
    248         if (requested && (job.State == State.requestSnapshot || job.State == State.requestSnapshotSent)) {
    249           response.Success = true;
    250           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE;
    251          
    252           //tx.Commit();
    253          
    254           return response;
    255         }
    256 
    257         /*JobResult lastResult =
    258           jobResultsAdapter.GetLastResultOf(job.Id);*/
    259 
    260         //if (lastResult != null) {
    261           response.Success = true;
    262           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT;
    263           response.Obj = new SerializedJob();
    264           response.Obj.JobInfo = job;
    265           response.Obj.SerializedJobData =
    266             DaoLocator.JobDao.GetBinaryJobFile(jobId);
    267         //} else {
    268         //  response.Success = false;
    269         //}
    270 
    271         //tx.Commit();
     245      if (requested && (job.State == State.requestSnapshot || job.State == State.requestSnapshotSent)) {
     246        response.Success = true;
     247        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE;
     248
    272249        return response;
    273250      }
    274       /*catch (Exception ex) {
    275         if (tx != null)
    276           tx.Rollback();
    277         throw ex;
    278       }
    279       finally {
    280         if (session != null)
    281           session.EndSession();
    282       }
    283     }    */
     251
     252      response.Success = true;
     253      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT;
     254      response.Obj = new SerializedJob();
     255      response.Obj.JobInfo = job;
     256      response.Obj.SerializedJobData =
     257        DaoLocator.JobDao.GetBinaryJobFile(jobId);
     258      return response;
     259    }
    284260
    285261
    286262    public Response RequestSnapshot(Guid jobId) {
    287      // ISession session = factory.GetSessionForCurrentThread();
    288263      Response response = new Response();
    289      
    290      /* try {
    291         IJobAdapter jobAdapter = session.GetDataAdapter<JobDto, IJobAdapter>();*/
    292 
    293         JobDto job = DaoLocator.JobDao.FindById(jobId);
    294         if (job.State == State.requestSnapshot || job.State == State.requestSnapshotSent) {
    295           response.Success = true;
    296           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_REQUEST_ALLREADY_SET;
    297           return response; // no commit needed
    298         }
    299         if (job.State != State.calculating) {
    300           response.Success = false;
    301           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED;
    302           return response; // no commit needed
    303         }
    304         // job is in correct state
    305         job.State = State.requestSnapshot;
    306         DaoLocator.JobDao.Update(job);
    307 
    308         response.Success = true;
    309         response.StatusMessage = ApplicationConstants.RESPONSE_JOB_REQUEST_SET;
    310 
     264
     265
     266      JobDto job = DaoLocator.JobDao.FindById(jobId);
     267      if (job.State == State.requestSnapshot || job.State == State.requestSnapshotSent) {
     268        response.Success = true;
     269        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_REQUEST_ALLREADY_SET;
    311270        return response;
    312271      }
    313     /*  finally {
    314         if (session != null)
    315           session.EndSession();
    316       }
    317     } */
     272      if (job.State != State.calculating) {
     273        response.Success = false;
     274        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED;
     275        return response;
     276      }
     277      // job is in correct state
     278      job.State = State.requestSnapshot;
     279      DaoLocator.JobDao.Update(job);
     280
     281      response.Success = true;
     282      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_REQUEST_SET;
     283
     284      return response;
     285    }
    318286
    319287    public Response AbortJob(Guid jobId) {
    320       //ISession session = factory.GetSessionForCurrentThread();
    321288      Response response = new Response();
    322289
    323     /*  try {
    324         IJobAdapter jobAdapter = session.GetDataAdapter<JobDto, IJobAdapter>();*/
    325 
    326 //        JobDto job = jobAdapter.GetById(jobId);
    327290      JobDto job = DaoLocator.JobDao.FindById(jobId);
    328         if (job == null) {
    329           response.Success = false;
    330           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
    331           return response; // no commit needed
    332         }
    333         if (job.State == State.abort) {
    334           response.Success = true;
    335           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ABORT_REQUEST_ALLREADY_SET;
    336           return response; // no commit needed
    337         }
    338         if (job.State != State.calculating && job.State != State.requestSnapshot && job.State != State.requestSnapshotSent) {
    339           response.Success = false;
    340           response.StatusMessage = ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED;
    341           return response; // no commit needed
    342         }
    343         // job is in correct state
    344         job.State = State.abort;
     291      if (job == null) {
     292        response.Success = false;
     293        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
     294        return response; // no commit needed
     295      }
     296      if (job.State == State.abort) {
     297        response.Success = true;
     298        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ABORT_REQUEST_ALLREADY_SET;
     299        return response; // no commit needed
     300      }
     301      if (job.State != State.calculating && job.State != State.requestSnapshot && job.State != State.requestSnapshotSent) {
     302        response.Success = false;
     303        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED;
     304        return response; // no commit needed
     305      }
     306      // job is in correct state
     307      job.State = State.abort;
    345308      DaoLocator.JobDao.Update(job);
    346309
    347         response.Success = true;
    348         response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ABORT_REQUEST_SET;
    349 
    350         return response;
    351       }
    352       /*finally {
    353         if (session != null)
    354           session.EndSession();
    355       }
    356     }   */
     310      response.Success = true;
     311      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ABORT_REQUEST_SET;
     312
     313      return response;
     314    }
    357315
    358316    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
     
    381339
    382340    public ResponseList<JobDto> GetJobsByProject(Guid projectId) {
    383       return null;     
    384     }
     341      return null;
     342    }
     343
     344    public byte[] GetSerializedJobDataById(Guid jobId) {
     345      return DaoLocator.JobDao.GetBinaryJobFile(jobId);
     346    }
     347
     348    public void SetSerializedJobDataById(Guid jobId, byte[] data) {
     349      DaoLocator.JobDao.SetBinaryJobFile(jobId, data);
     350    }
     351
    385352    #endregion
    386353  }
Note: See TracChangeset for help on using the changeset viewer.